Asterisk - The Open Source Telephony Project
21.4.1
|
An in-memory media cache. More...
#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/config.h"
#include "asterisk/bucket.h"
#include "asterisk/astdb.h"
#include "asterisk/cli.h"
#include "asterisk/file.h"
#include "asterisk/media_cache.h"
Go to the source code of this file.
Macros | |
#define | AO2_BUCKETS 61 |
#define | AST_DB_FAMILY "MediaCache" |
#define | AST_DB_FAMILY_LEN 12 |
#define | FORMAT_ROW "%-40s\n\t%-40s\n" |
#define | FORMAT_ROW "\t%20s: %-40.40s\n" |
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... | |
static void | bucket_file_update_path (struct ast_bucket_file *bucket_file, const char *preferred_file_name) |
static char * | cli_complete_uri (const char *word) |
static char * | media_cache_handle_create_item (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | media_cache_handle_delete_item (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | media_cache_handle_refresh_item (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | media_cache_handle_show_all (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | media_cache_handle_show_item (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | media_cache_item_del_from_astdb (struct ast_bucket_file *bucket_file) |
static int | media_cache_item_populate_from_astdb (const char *uri, const char *hash) |
static void | media_cache_item_sync_to_astdb (struct ast_bucket_file *bucket_file) |
static void | media_cache_populate_from_astdb (void) |
static int | media_cache_prnt_summary (void *obj, void *arg, int flags) |
static void | media_cache_remove_from_astdb (const char *uri, const char *hash) |
static void | media_cache_shutdown (void) |
static int | metadata_sync_to_astdb (void *obj, void *arg, int flags) |
Variables | |
static struct ast_cli_entry | cli_media_cache [] |
static struct ao2_container * | media_cache |
An in-memory media cache.
Definition in file media_cache.c.
#define AO2_BUCKETS 61 |
Number of buckets in the ao2 container holding our media items
Definition at line 48 of file media_cache.c.
Referenced by ast_media_cache_init().
#define AST_DB_FAMILY "MediaCache" |
The name of the AstDB family holding items in the cache.
Definition at line 42 of file media_cache.c.
#define AST_DB_FAMILY_LEN 12 |
Length of 'MediaCache' + 2 '/' characters
Definition at line 45 of file media_cache.c.
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_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_strdupa, ast_bucket_file::created, ast_bucket_file::modified, ast_variable::name, ast_variable::next, OBJ_NOLOCK, OBJ_SEARCH_KEY, ast_bucket_file::path, SCOPED_AO2LOCK, and ast_variable::value.
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_ref, ast_bucket_file_delete(), OBJ_SEARCH_KEY, and OBJ_UNLINK.
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_ref, ast_bucket_file_retrieve(), and OBJ_SEARCH_KEY.
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, ast_cli_register_multiple, ast_register_cleanup(), ast_sorcery_object_id_compare(), and ast_sorcery_object_id_hash().
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_link_flags, ao2_ref, ao2_unlink_flags, ast_bucket_file_delete(), ast_bucket_file_is_stale(), ast_bucket_file_retrieve(), ast_copy_string(), ast_debug, ast_file_is_readable(), OBJ_NOLOCK, OBJ_SEARCH_KEY, and ast_bucket_file::path.
Referenced by fileexists_test().
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_ref, ast_copy_string(), ast_bucket_file::metadata, OBJ_SEARCH_KEY, and ast_bucket_metadata::value.
|
static |
Our one and only container holding media items
Definition at line 51 of file media_cache.c.