Asterisk - The Open Source Telephony Project
18.5.0
|
Sound file format and description indexer. More...
#include "asterisk.h"
#include <dirent.h>
#include <sys/stat.h>
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
#include "asterisk/media_index.h"
#include "asterisk/file.h"
Go to the source code of this file.
Data Structures | |
struct | ast_media_index |
struct | media_info |
Structure to hold information about a media file. More... | |
struct | media_variant |
Structure to hold a list of the format variations for a media file for a specific variant. More... | |
struct | read_dirs_data |
Macros | |
#define | INDEX_BUCKETS 157 |
The number of buckets to be used for storing media filename-keyed objects. More... | |
#define | VARIANT_BUCKETS 7 |
The number of buckets to be used for storing variant-keyed objects. More... | |
Functions | |
static int | add_media_cb (void *obj, void *arg, int flags) |
Add the media_info's filename to the container of filenames requested. More... | |
static int | add_variant_cb (void *obj, void *arg, int flags) |
Add the variant to the list of variants requested. More... | |
static struct media_variant * | alloc_variant (struct ast_media_index *index, const char *filename, const char *variant_str) |
create the appropriate media_variant and any necessary structures More... | |
const char * | ast_media_get_description (struct ast_media_index *index, const char *filename, const char *variant_str) |
Get the description for a media file. More... | |
struct ast_format_cap * | ast_media_get_format_cap (struct ast_media_index *index, const char *filename, const char *variant_str) |
Get the ast_format_cap for a media file. More... | |
struct ao2_container * | ast_media_get_media (struct ast_media_index *index) |
Get the a container of all media available on the system. More... | |
struct ao2_container * | ast_media_get_variants (struct ast_media_index *index, const char *filename) |
Get the languages in which a media file is available. More... | |
struct ast_media_index * | ast_media_index_create (const char *base_dir) |
Creates a new media index. More... | |
int | ast_media_index_update_for_file (struct ast_media_index *index, const char *variant, const char *filename) |
Update a media index for a specific sound file. More... | |
static struct media_variant * | find_variant (struct ast_media_index *index, const char *filename, const char *variant) |
static void | media_index_dtor (void *obj) |
static struct media_info * | media_info_alloc (const char *name) |
static int | media_info_cmp (void *obj, void *arg, int flags) |
static void | media_info_destroy (void *obj) |
static int | media_info_hash (const void *obj, const int flags) |
static struct media_variant * | media_variant_alloc (const char *variant_str) |
static int | media_variant_cmp (void *obj, void *arg, int flags) |
static void | media_variant_destroy (void *obj) |
static int | media_variant_hash (const void *obj, const int flags) |
static int | process_description_file (struct ast_media_index *index, const char *subdir, const char *variant_str, const char *filename, const char *match_filename) |
Process a media description text file. More... | |
static int | process_media_file (struct ast_media_index *index, const char *variant, const char *subdir, const char *filename_stripped, const char *ext) |
Process a media file into the index. More... | |
static int | read_dirs_cb (const char *dir_name, const char *filename, void *obj) |
static int | update_file_format_info (struct ast_media_index *index, const char *filename, const char *variant_str, struct ast_format *file_format) |
Update an index with new format/variant information. More... | |
Sound file format and description indexer.
Definition in file media_index.c.
#define INDEX_BUCKETS 157 |
The number of buckets to be used for storing media filename-keyed objects.
Definition at line 43 of file media_index.c.
Referenced by ast_media_get_media(), and ast_media_index_create().
#define VARIANT_BUCKETS 7 |
The number of buckets to be used for storing variant-keyed objects.
Definition at line 40 of file media_index.c.
Referenced by ast_media_get_variants(), and media_info_alloc().
|
static |
Add the media_info's filename to the container of filenames requested.
Definition at line 299 of file media_index.c.
References ast_str_container_add(), sip_to_pjsip::info(), and media_info::name.
Referenced by ast_media_get_media().
|
static |
Add the variant to the list of variants requested.
Definition at line 266 of file media_index.c.
References ast_str_container_add(), and media_variant::variant.
Referenced by ast_media_get_variants().
|
static |
create the appropriate media_variant and any necessary structures
Definition at line 197 of file media_index.c.
References ao2_find, ao2_link, ao2_ref, ast_media_index::index, sip_to_pjsip::info(), media_info_alloc(), media_variant_alloc(), NULL, OBJ_KEY, media_variant::variant, and media_info::variants.
Referenced by process_description_file(), and update_file_format_info().
const char* ast_media_get_description | ( | struct ast_media_index * | index, |
const char * | filename, | ||
const char * | variant | ||
) |
Get the description for a media file.
index | Media index in which to query information |
filename | Name of the file for which to get the description |
variant | Media variant for which to get the description |
NULL | if not found |
Definition at line 230 of file media_index.c.
References ao2_cleanup, ast_strlen_zero, find_variant(), NULL, RAII_VAR, and media_variant::variant.
Referenced by create_sound_blob(), and show_sound_info_cb().
struct ast_format_cap* ast_media_get_format_cap | ( | struct ast_media_index * | index, |
const char * | filename, | ||
const char * | variant | ||
) |
Get the ast_format_cap for a media file.
index | Media index in which to query information |
filename | Name of the file for which to get the description |
variant | Media variant for which to get the description |
NULL | if not found |
Definition at line 245 of file media_index.c.
References ao2_cleanup, ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, AST_MEDIA_TYPE_UNKNOWN, ast_strlen_zero, find_variant(), NULL, RAII_VAR, and media_variant::variant.
Referenced by add_format_information_cb(), and show_sound_info_cb().
struct ao2_container* ast_media_get_media | ( | struct ast_media_index * | index | ) |
Get the a container of all media available on the system.
index | Media index in which to query information |
NULL | on error |
Definition at line 307 of file media_index.c.
References add_media_cb(), ao2_callback, ao2_cleanup, ao2_ref, ast_str_container_alloc, ast_media_index::index, INDEX_BUCKETS, ast_media_index::media_list_cache, NULL, OBJ_NODATA, and RAII_VAR.
Referenced by ast_ari_sounds_list(), handle_cli_sound_show(), and handle_cli_sounds_show().
struct ao2_container* ast_media_get_variants | ( | struct ast_media_index * | index, |
const char * | filename | ||
) |
Get the languages in which a media file is available.
index | Media index in which to query information |
filename | Name of the file for which to get available languages |
NULL | on error |
Definition at line 274 of file media_index.c.
References add_variant_cb(), ao2_callback, ao2_cleanup, ao2_find, ao2_ref, ast_str_container_alloc, ast_media_index::index, sip_to_pjsip::info(), NULL, OBJ_KEY, OBJ_NODATA, RAII_VAR, and VARIANT_BUCKETS.
Referenced by create_sound_blob(), and handle_cli_sound_show().
struct ast_media_index* ast_media_index_create | ( | const char * | base_dir | ) |
Creates a new media index.
base_dir | Base directory for indexing |
NULL | on error |
A | new AO2 refcounted media index |
Definition at line 162 of file media_index.c.
References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_media_index::base_dir, ast_media_index::index, INDEX_BUCKETS, media_index_dtor(), media_info_cmp(), media_info_hash(), and NULL.
Referenced by ast_sounds_get_index_for_file().
int ast_media_index_update_for_file | ( | struct ast_media_index * | index, |
const char * | variant, | ||
const char * | filename | ||
) |
Update a media index for a specific sound file.
index | Media index in which to query information |
variant | Media variant for which to get the description |
filename | Sound file name without extension |
non-zero | on error |
Definition at line 587 of file media_index.c.
References ast_alloca, ast_debug, ast_file_read_dirs(), ast_strlen_zero, ast_tvdiff_us(), ast_media_index::base_dir, read_dirs_data::dirname_len, read_dirs_data::index, NULL, read_dirs_cb(), S_OR, read_dirs_data::search_filename, and read_dirs_data::search_variant.
Referenced by update_index_cb().
|
static |
Definition at line 184 of file media_index.c.
References ao2_cleanup, ao2_find, ast_media_index::index, sip_to_pjsip::info(), NULL, OBJ_KEY, and RAII_VAR.
Referenced by ast_media_get_description(), and ast_media_get_format_cap().
|
static |
Definition at line 154 of file media_index.c.
References ao2_cleanup, ast_media_index::index, and ast_media_index::media_list_cache.
Referenced by ast_media_index_create().
|
static |
Definition at line 111 of file media_index.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_container_alloc_hash, ao2_ref, sip_to_pjsip::info(), media_info_destroy(), media_variant_cmp(), media_variant_hash(), media_info::name, NULL, VARIANT_BUCKETS, and media_info::variants.
Referenced by alloc_variant().
|
static |
Definition at line 141 of file media_index.c.
References CMP_MATCH, CMP_STOP, name, media_info::name, and OBJ_KEY.
Referenced by ast_media_index_create().
|
static |
Definition at line 104 of file media_index.c.
References ao2_cleanup, sip_to_pjsip::info(), and media_info::variants.
Referenced by media_info_alloc().
|
static |
Definition at line 135 of file media_index.c.
References ast_str_case_hash(), name, and OBJ_KEY.
Referenced by ast_media_index_create().
|
static |
Definition at line 62 of file media_index.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_string_field_init, media_variant::formats, media_variant_destroy(), NULL, and media_variant::variant.
Referenced by alloc_variant().
|
static |
Definition at line 91 of file media_index.c.
References CMP_MATCH, CMP_STOP, OBJ_KEY, and media_variant::variant.
Referenced by media_info_alloc().
|
static |
Definition at line 54 of file media_index.c.
References ao2_cleanup, ast_string_field_free_memory, media_variant::formats, and media_variant::variant.
Referenced by media_variant_alloc().
|
static |
Definition at line 85 of file media_index.c.
References ast_str_case_hash(), OBJ_KEY, and media_variant::variant.
Referenced by media_info_alloc().
|
static |
Process a media description text file.
This currently processes core-sounds-*.txt and extra-sounds-*.txt, but will process others if present.
Definition at line 380 of file media_index.c.
References alloc_variant(), ao2_ref, ast_free, ast_log, ast_skip_blanks(), ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_reset(), ast_str_set(), ast_strdup, ast_string_field_set, ast_strlen_zero, ast_trim_blanks(), ast_media_index::base_dir, buf, media_variant::description, errno, LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, strsep(), and media_variant::variant.
Referenced by read_dirs_cb().
|
static |
Process a media file into the index.
Definition at line 346 of file media_index.c.
References ast_asprintf, ast_free, ast_get_format_for_file_ext(), NULL, and update_file_format_info().
Referenced by read_dirs_cb().
|
static |
Definition at line 510 of file media_index.c.
References ast_alloca, ast_strlen_zero, read_dirs_data::dirname_len, ext, if(), read_dirs_data::index, match(), NULL, process_description_file(), process_media_file(), read_dirs_data::search_filename, read_dirs_data::search_filename_len, and read_dirs_data::search_variant.
Referenced by ast_media_index_update_for_file().
|
static |
Update an index with new format/variant information.
Definition at line 330 of file media_index.c.
References alloc_variant(), ao2_ref, ast_format_cap_append, media_variant::formats, and media_variant::variant.
Referenced by process_media_file().