Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
An in-memory media cache. More...
Go to the source code of this file.
Functions | |
int | ast_media_cache_create_or_update (const char *uri, const char *file_path, struct ast_variable *metadata) |
Create/update a cached media item. More... | |
int | ast_media_cache_delete (const char *uri) |
Remove an item from the media cache. More... | |
int | ast_media_cache_exists (const char *uri) |
Check if an item exists in the cache. More... | |
int | ast_media_cache_init (void) |
Initialize the media cache. More... | |
int | ast_media_cache_retrieve (const char *uri, const char *preferred_file_name, char *file_path, size_t len) |
Retrieve an item from the cache. More... | |
int | ast_media_cache_retrieve_metadata (const char *uri, const char *key, char *value, size_t len) |
Retrieve metadata from an item in the cache. More... | |
An in-memory media cache.
Definition in file media_cache.h.
int ast_media_cache_create_or_update | ( | const char * | uri, |
const char * | file_path, | ||
struct ast_variable * | metadata | ||
) |
Create/update a cached media item.
uri | The unique URI for the media item to store in the cache |
file_path | Full path to the media file to be cached |
metadata | Metadata to store with the cached item |
0 | The item was cached |
-1 | An error occurred when creating/updating the item |
Example Usage:
While ast_media_cache_retrieve is used to retrieve media from some Bucket File API provider, this method allows for overwriting what is provided by a backend with some local media. This is useful for reconstructing or otherwise associating local media with a remote URI, deferring updating of the media from the backend to some later retrieval.
Definition at line 268 of file media_cache.c.
References ao2_find, ao2_link_flags, ao2_ref, ao2_unlink_flags, ast_bucket_file_alloc(), ast_bucket_file_clone(), ast_bucket_file_create(), ast_bucket_file_metadata_set(), ast_log, ast_strdupa, ast_strlen_zero(), ast_bucket_file::created, ext, LOG_WARNING, media_cache, media_cache_item_sync_to_astdb(), ast_bucket_file::metadata, ast_bucket_file::modified, ast_variable::name, ast_variable::next, OBJ_NOLOCK, OBJ_SEARCH_KEY, ast_bucket_file::path, SCOPED_AO2LOCK, tmp(), and ast_variable::value.
Referenced by AST_TEST_DEFINE(), and media_cache_handle_create_item().
int ast_media_cache_delete | ( | const char * | uri | ) |
Remove an item from the media cache.
uri | The unique URI for the media item to store in the cache |
0 | success |
-1 | error |
Example Usage:
This removes an item completely from the media cache. Any files local on disk associated with the item are deleted as well.
Definition at line 347 of file media_cache.c.
References ao2_find, ao2_ref, ast_bucket_file_delete(), ast_strlen_zero(), media_cache, media_cache_item_del_from_astdb(), OBJ_SEARCH_KEY, and OBJ_UNLINK.
Referenced by AST_TEST_DEFINE(), bucket_http_test_wizard_delete(), and media_cache_handle_delete_item().
int ast_media_cache_exists | ( | const char * | uri | ) |
Check if an item exists in the cache.
uri | The unique URI for the media item |
0 | uri does not exist in cache |
1 | uri does exist in cache |
Definition at line 53 of file media_cache.c.
References ao2_find, ao2_ref, ast_bucket_file_retrieve(), ast_strlen_zero(), media_cache, and OBJ_SEARCH_KEY.
Referenced by AST_TEST_DEFINE().
int ast_media_cache_init | ( | void | ) |
Initialize the media cache.
0 | success |
-1 | error |
Definition at line 671 of file media_cache.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, AO2_BUCKETS, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), ast_sorcery_object_id_compare(), ast_sorcery_object_id_hash(), cli_media_cache, media_cache, media_cache_populate_from_astdb(), media_cache_shutdown(), and NULL.
Referenced by asterisk_daemon().
int ast_media_cache_retrieve | ( | const char * | uri, |
const char * | preferred_file_name, | ||
char * | file_path, | ||
size_t | len | ||
) |
Retrieve an item from the cache.
uri | The unique URI for the media item |
preferred_file_name | The preferred name for the file storing the media once it is retrieved. Can be NULL. |
file_path | Buffer to store the full path to the media in the cache |
len | The length of the buffer pointed to by file_path |
0 | The item was retrieved successfully |
-1 | The item could not be retrieved |
Example Usage:
Retrieving an item will cause the Bucket File API Bucket backend associated with the URI scheme in uri
to be queried. If the Bucket backend does not require an update, the cached information is used to find the file associated with uri
, and file_path
is populated with the location of the media file associated with uri
.
If the item is not in the cache, the item will be retrieved using the Bucket File API backend. When this occurs, if preferred_file_name
is given, it will be used as the destination file for the retrieval. When retrieval of the media from the backend is complete, file_path
is then populated as before.
Definition at line 157 of file media_cache.c.
References ao2_find, ao2_link_flags, ao2_lock, ao2_ref, ao2_unlink_flags, ao2_unlock, ast_bucket_file_delete(), ast_bucket_file_is_stale(), ast_bucket_file_retrieve(), ast_copy_string(), ast_debug, ast_file_is_readable(), ast_strlen_zero(), bucket_file_update_path(), ext, len(), media_cache, media_cache_item_sync_to_astdb(), OBJ_NOLOCK, OBJ_SEARCH_KEY, and ast_bucket_file::path.
Referenced by AST_TEST_DEFINE(), fileexists_test(), and media_cache_handle_refresh_item().
int ast_media_cache_retrieve_metadata | ( | const char * | uri, |
const char * | key, | ||
char * | value, | ||
size_t | len | ||
) |
Retrieve metadata from an item in the cache.
uri | The unique URI for the media item |
key | The key of the metadata to retrieve |
value | Buffer to store the value in |
len | The length of the buffer pointed to by value |
0 | The metadata was retrieved successfully |
-1 | The metadata could not be retrieved |
Example Usage:
Definition at line 241 of file media_cache.c.
References ao2_find, ao2_ref, ast_copy_string(), ast_strlen_zero(), len(), media_cache, ast_bucket_file::metadata, OBJ_SEARCH_KEY, ast_bucket_metadata::value, and value.
Referenced by AST_TEST_DEFINE().