Asterisk - The Open Source Telephony Project
21.4.1
|
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. | |
#define | VARIANT_BUCKETS 7 |
The number of buckets to be used for storing variant-keyed objects. | |
Functions | |
static int | add_media_cb (void *obj, void *arg, int flags) |
Add the media_info's filename to the container of filenames requested. | |
static int | add_variant_cb (void *obj, void *arg, int flags) |
Add the variant to the list of variants requested. | |
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 | |
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. | |
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. | |
Sound file format and description indexer.
Definition in file media_index.c.
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 RAII_VAR.
Referenced by create_sound_blob().
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 ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap::formats, and RAII_VAR.
Referenced by add_format_information_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_ref, ast_str_container_alloc, ast_media_index::index, INDEX_BUCKETS, ast_media_index::media_list_cache, 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_ref, ast_str_container_alloc, ast_media_index::index, OBJ_KEY, OBJ_NODATA, RAII_VAR, VARIANT_BUCKETS, and media_info::variants.
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_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_media_index::base_dir, ast_media_index::index, and INDEX_BUCKETS.
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_tvdiff_us(), ast_media_index::base_dir, and S_OR.
Referenced by update_index_cb().
|
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_skip_blanks(), ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_reset(), ast_str_set(), ast_strdup, ast_string_field_set, ast_trim_blanks(), ast_media_index::base_dir, media_variant::description, RAII_VAR, and media_variant::variant.