mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +00:00
Add the ability to read the media file type from HTTP header for playback
How it works today: media_cache tries to parse out the extension of the media file to be played from the URI provided to Asterisk while caching the file. What's expected: Better will be to have Asterisk get extension from other ways too. One of the common ways is to get the type of content from the CONTENT-TYPE header in the HTTP response for fetching the media file using the URI provided. Steps to Reproduce: Provide a URL of the form: http://host/media/1234 to Asterisk for media playback. It fails to play and logs show the following error line: [Sep 15 15:48:05] WARNING [29148] [C-00000092] file.c: File http://host/media/1234 does not exist in any format Scenario this issue is blocking: In the case where the media files are stored in some cloud object store, following can block the media being played via Asterisk: Cloud storage generally needs authenticated access to the storage. The way to do that is by using signed URIs. With the signed URIs there's no way to preserve the name of the file. In most cases Cloud storage returns a key to access the object and preserving file name is also not a thing there ASTERISK-27286 Reporter: Gaurav Khurana Change-Id: I1b14692a49b2c1ac67688f58757184122e92ba89
This commit is contained in:
committed by
Sean Bright
parent
f633af89c1
commit
0827d5cc53
34
main/file.c
34
main/file.c
@@ -333,20 +333,21 @@ static char *build_filename(const char *filename, const char *ext)
|
||||
|
||||
/* compare type against the list 'exts' */
|
||||
/* XXX need a better algorithm */
|
||||
static int exts_compare(const char *exts, const char *type)
|
||||
static int type_in_list(const char *list, const char *type, int (*cmp)(const char *s1, const char *s2))
|
||||
{
|
||||
char tmp[256];
|
||||
char *stringp = tmp, *ext;
|
||||
char *stringp = ast_strdupa(list), *item;
|
||||
|
||||
ast_copy_string(tmp, exts, sizeof(tmp));
|
||||
while ((ext = strsep(&stringp, "|"))) {
|
||||
if (!strcmp(ext, type))
|
||||
while ((item = strsep(&stringp, "|"))) {
|
||||
if (!cmp(item, type)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define exts_compare(list, type) (type_in_list((list), (type), strcmp))
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
* \brief Close the file stream by canceling any pending read / write callbacks
|
||||
@@ -1926,6 +1927,27 @@ struct ast_format *ast_get_format_for_file_ext(const char *file_ext)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ast_get_extension_for_mime_type(const char *mime_type, char *buffer, size_t capacity)
|
||||
{
|
||||
struct ast_format_def *f;
|
||||
SCOPED_RDLOCK(lock, &formats.lock);
|
||||
|
||||
ast_assert(buffer && capacity);
|
||||
|
||||
AST_RWLIST_TRAVERSE(&formats, f, list) {
|
||||
if (type_in_list(f->mime_types, mime_type, strcasecmp)) {
|
||||
size_t item_len = strcspn(f->exts, "|");
|
||||
size_t bytes_written = snprintf(buffer, capacity, ".%.*s", (int) item_len, f->exts);
|
||||
if (bytes_written < capacity) {
|
||||
/* Only return success if we didn't truncate */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ast_cli_entry cli_file[] = {
|
||||
AST_CLI_DEFINE(handle_cli_core_show_file_formats, "Displays file formats")
|
||||
};
|
||||
|
Reference in New Issue
Block a user