diff options
author | Matthew Jordan <mjordan@digium.com> | 2014-07-20 22:06:33 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2014-07-20 22:06:33 +0000 |
commit | a2c912e9972c91973ea66902d217746133f96026 (patch) | |
tree | 50e01d14ba62950e3f78766d5ba435ba51ca327d /main/file.c | |
parent | b299052e203807c9a2111eb2cd919246d7589cb3 (diff) |
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/file.c')
-rw-r--r-- | main/file.c | 123 |
1 files changed, 68 insertions, 55 deletions
diff --git a/main/file.c b/main/file.c index df67fbf43..fa4c63bd9 100644 --- a/main/file.c +++ b/main/file.c @@ -189,8 +189,8 @@ int ast_stopstream(struct ast_channel *tmp) if (ast_channel_stream(tmp)) { ast_closestream(ast_channel_stream(tmp)); ast_channel_stream_set(tmp, NULL); - if (ast_channel_oldwriteformat(tmp)->id && ast_set_write_format(tmp, ast_channel_oldwriteformat(tmp))) - ast_log(LOG_WARNING, "Unable to restore format back to %s\n", ast_getformatname(ast_channel_oldwriteformat(tmp))); + if (ast_channel_oldwriteformat(tmp) && ast_set_write_format(tmp, ast_channel_oldwriteformat(tmp))) + ast_log(LOG_WARNING, "Unable to restore format back to %s\n", ast_format_get_name(ast_channel_oldwriteformat(tmp))); } /* Stop the video stream too */ if (ast_channel_vstream(tmp) != NULL) { @@ -207,10 +207,10 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) { int res = -1; if (f->frametype == AST_FRAME_VIDEO) { - if (AST_FORMAT_GET_TYPE(fs->fmt->format.id) == AST_FORMAT_TYPE_AUDIO) { + if (ast_format_get_type(fs->fmt->format) == AST_MEDIA_TYPE_AUDIO) { /* This is the audio portion. Call the video one... */ if (!fs->vfs && fs->filename) { - const char *type = ast_getformatname(&f->subclass.format); + const char *type = ast_format_get_name(f->subclass.format); fs->vfs = ast_writefile(fs->filename, type, NULL, fs->flags, 0, fs->mode); ast_debug(1, "Opened video output file\n"); } @@ -223,7 +223,7 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) ast_log(LOG_WARNING, "Tried to write non-voice frame\n"); return -1; } - if (ast_format_cmp(&f->subclass.format, &fs->fmt->format) != AST_FORMAT_CMP_NOT_EQUAL) { + if (ast_format_cmp(f->subclass.format, fs->fmt->format) != AST_FORMAT_CMP_NOT_EQUAL) { res = fs->fmt->write(fs, f); if (res < 0) ast_log(LOG_WARNING, "Natural write failed\n"); @@ -232,18 +232,19 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) } else { /* XXX If they try to send us a type of frame that isn't the normal frame, and isn't the one we've setup a translator for, we do the "wrong thing" XXX */ - if (fs->trans && (ast_format_cmp(&f->subclass.format, &fs->lastwriteformat) != AST_FORMAT_CMP_EQUAL)) { + if (fs->trans && (ast_format_cmp(f->subclass.format, fs->lastwriteformat) != AST_FORMAT_CMP_EQUAL)) { ast_translator_free_path(fs->trans); fs->trans = NULL; } - if (!fs->trans) - fs->trans = ast_translator_build_path(&fs->fmt->format, &f->subclass.format); - if (!fs->trans) + if (!fs->trans) { + fs->trans = ast_translator_build_path(fs->fmt->format, f->subclass.format); + } + if (!fs->trans) { ast_log(LOG_WARNING, "Unable to translate to format %s, source format %s\n", - fs->fmt->name, ast_getformatname(&f->subclass.format)); - else { + fs->fmt->name, ast_format_get_name(f->subclass.format)); + } else { struct ast_frame *trf; - ast_format_copy(&fs->lastwriteformat, &f->subclass.format); + ao2_replace(fs->lastwriteformat, f->subclass.format); /* Get the translated frame but don't consume the original in case they're using it on another stream */ if ((trf = ast_translate(fs->trans, f, 0))) { struct ast_frame *cur; @@ -349,7 +350,7 @@ static int exts_compare(const char *exts, const char *type) */ static void filestream_close(struct ast_filestream *f) { - enum ast_format_type format_type = AST_FORMAT_GET_TYPE(f->fmt->format.id); + enum ast_media_type format_type = ast_format_get_type(f->fmt->format); if (!f->owner) { return; @@ -358,12 +359,12 @@ static void filestream_close(struct ast_filestream *f) /* Stop a running stream if there is one */ switch (format_type) { - case AST_FORMAT_TYPE_AUDIO: + case AST_MEDIA_TYPE_AUDIO: ast_channel_stream_set(f->owner, NULL); AST_SCHED_DEL_ACCESSOR(ast_channel_sched(f->owner), f->owner, ast_channel_streamid, ast_channel_streamid_set); ast_settimeout(f->owner, 0, NULL, NULL); break; - case AST_FORMAT_TYPE_VIDEO: + case AST_MEDIA_TYPE_VIDEO: ast_channel_vstream_set(f->owner, NULL); AST_SCHED_DEL_ACCESSOR(ast_channel_sched(f->owner), f->owner, ast_channel_vstreamid, ast_channel_vstreamid_set); break; @@ -418,6 +419,8 @@ static void filestream_destructor(void *arg) } if (f->orig_chan_name) free((void *) f->orig_chan_name); + ao2_cleanup(f->lastwriteformat); + ao2_cleanup(f->fr.subclass.format); ast_module_unref(f->fmt->module); } @@ -436,6 +439,15 @@ static struct ast_filestream *get_filestream(struct ast_format_def *fmt, FILE *b if (fmt->buf_size) s->buf = (char *)(s + 1); s->fr.src = fmt->name; + + if (ast_format_get_type(fmt->format) == AST_MEDIA_TYPE_AUDIO) { + s->fr.frametype = AST_FRAME_VOICE; + } else if (ast_format_get_type(fmt->format) == AST_MEDIA_TYPE_VIDEO) { + s->fr.frametype = AST_FRAME_VIDEO; + } + s->fr.mallocd = 0; + s->fr.subclass.format = ao2_bump(fmt->format); + return s; } @@ -529,9 +541,9 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c FILE *bfile; struct ast_filestream *s; - if ((ast_format_cmp(ast_channel_writeformat(chan), &f->format) == AST_FORMAT_CMP_NOT_EQUAL) && - !(((AST_FORMAT_GET_TYPE(f->format.id) == AST_FORMAT_TYPE_AUDIO) && fmt) || - ((AST_FORMAT_GET_TYPE(f->format.id) == AST_FORMAT_TYPE_VIDEO) && fmt))) { + if ((ast_format_cmp(ast_channel_writeformat(chan), f->format) == AST_FORMAT_CMP_NOT_EQUAL) && + !(((ast_format_get_type(f->format) == AST_MEDIA_TYPE_AUDIO) && fmt) || + ((ast_format_get_type(f->format) == AST_MEDIA_TYPE_VIDEO) && fmt))) { ast_free(fn); continue; /* not a supported format */ } @@ -559,7 +571,7 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c s->fmt = f; s->trans = NULL; s->filename = NULL; - if (AST_FORMAT_GET_TYPE(s->fmt->format.id) == AST_FORMAT_TYPE_AUDIO) { + if (ast_format_get_type(s->fmt->format) == AST_MEDIA_TYPE_AUDIO) { if (ast_channel_stream(chan)) ast_closestream(ast_channel_stream(chan)); ast_channel_stream_set(chan, s); @@ -579,7 +591,7 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c /* if arg2 is present, it is a format capabilities structure. * Add this format to the set of formats this file can be played in */ if (arg2) { - ast_format_cap_add((struct ast_format_cap *) arg2, &f->format); + ast_format_cap_append((struct ast_format_cap *) arg2, f->format, 0); } res = 1; /* file does exist and format it exists in is returned in arg2 */ break; @@ -749,23 +761,23 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char buflen = strlen(preflang) + strlen(filename) + 4; buf = ast_alloca(buflen); - if (!(file_fmt_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) { + if (!(file_fmt_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) { return NULL; } if (!fileexists_core(filename, NULL, preflang, buf, buflen, file_fmt_cap) || - !ast_format_cap_has_type(file_fmt_cap, AST_FORMAT_TYPE_AUDIO)) { + !ast_format_cap_has_type(file_fmt_cap, AST_MEDIA_TYPE_AUDIO)) { ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename); - file_fmt_cap = ast_format_cap_destroy(file_fmt_cap); + ao2_ref(file_fmt_cap, -1); return NULL; } /* Set the channel to a format we can work with and save off the previous format. */ - ast_format_copy(ast_channel_oldwriteformat(chan), ast_channel_writeformat(chan)); + ast_channel_set_oldwriteformat(chan, ast_channel_writeformat(chan)); /* Set the channel to the best format that exists for the file. */ res = ast_set_write_format_from_cap(chan, file_fmt_cap); /* don't need this anymore now that the channel's write format is set. */ - file_fmt_cap = ast_format_cap_destroy(file_fmt_cap); + ao2_ref(file_fmt_cap, -1); if (res == -1) { /* No format available that works with this channel */ return NULL; @@ -781,50 +793,50 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *fil /* As above, but for video. But here we don't have translators * so we must enforce a format. */ - struct ast_format tmp_fmt; struct ast_format_cap *tmp_cap; char *buf; int buflen; - const char *fmt; - int fd; + int i, fd; - if (preflang == NULL) + if (preflang == NULL) { preflang = ""; + } buflen = strlen(preflang) + strlen(filename) + 4; buf = ast_alloca(buflen); /* is the channel capable of video without translation ?*/ - if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO)) { + if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_MEDIA_TYPE_VIDEO)) { return NULL; } - if (!(tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) { + if (!(tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) { return NULL; } /* Video is supported, so see what video formats exist for this file */ if (!fileexists_core(filename, NULL, preflang, buf, buflen, tmp_cap)) { - tmp_cap = ast_format_cap_destroy(tmp_cap); + ao2_ref(tmp_cap, -1); return NULL; } /* iterate over file formats and pick the first one compatible with the channel's native formats */ - ast_format_cap_iter_start(tmp_cap); - while (!ast_format_cap_iter_next(tmp_cap, &tmp_fmt)) { - fmt = ast_getformatname(&tmp_fmt); - if ((AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_VIDEO) || - !ast_format_cap_iscompatible(ast_channel_nativeformats(chan), &tmp_fmt)) { + for (i = 0; i < ast_format_cap_count(tmp_cap); ++i) { + struct ast_format *format = ast_format_cap_get_format(tmp_cap, i); + + if ((ast_format_get_type(format) != AST_MEDIA_TYPE_VIDEO) || + !ast_format_cap_iscompatible(ast_channel_nativeformats(chan), tmp_cap)) { + ao2_ref(format, -1); continue; } - fd = filehelper(buf, chan, fmt, ACTION_OPEN); + fd = filehelper(buf, chan, ast_format_get_name(format), ACTION_OPEN); if (fd >= 0) { - ast_format_cap_iter_end(tmp_cap); - tmp_cap = ast_format_cap_destroy(tmp_cap); + ao2_ref(format, -1); + ao2_ref(tmp_cap, -1); return ast_channel_vstream(chan); } ast_log(LOG_WARNING, "File %s has video but couldn't be opened\n", filename); + ao2_ref(format, -1); } - ast_format_cap_iter_end(tmp_cap); - tmp_cap = ast_format_cap_destroy(tmp_cap); + ao2_ref(tmp_cap, -1); return NULL; } @@ -897,14 +909,14 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s) if (whennext != s->lasttimeout) { if (ast_channel_timingfd(s->owner) > -1) { - float samp_rate = (float) ast_format_rate(&s->fmt->format); + float samp_rate = (float) ast_format_get_sample_rate(s->fmt->format); unsigned int rate; rate = (unsigned int) roundf(samp_rate / ((float) whennext)); ast_settimeout_full(s->owner, rate, ast_fsread_audio, s, 1); } else { - ast_channel_streamid_set(s->owner, ast_sched_add(ast_channel_sched(s->owner), whennext / (ast_format_rate(&s->fmt->format) / 1000), ast_fsread_audio, s)); + ast_channel_streamid_set(s->owner, ast_sched_add(ast_channel_sched(s->owner), whennext / (ast_format_get_sample_rate(s->fmt->format) / 1000), ast_fsread_audio, s)); } s->lasttimeout = whennext; return FSREAD_SUCCESS_NOSCHED; @@ -954,7 +966,7 @@ static enum fsread_res ast_readvideo_callback(struct ast_filestream *s) } if (whennext != s->lasttimeout) { - ast_channel_vstreamid_set(s->owner, ast_sched_add(ast_channel_sched(s->owner), whennext / (ast_format_rate(&s->fmt->format) / 1000), ast_fsread_video, s)); + ast_channel_vstreamid_set(s->owner, ast_sched_add(ast_channel_sched(s->owner), whennext / (ast_format_get_sample_rate(s->fmt->format) / 1000), ast_fsread_video, s)); s->lasttimeout = whennext; return FSREAD_SUCCESS_NOSCHED; } @@ -985,7 +997,7 @@ int ast_playstream(struct ast_filestream *s) { enum fsread_res res; - if (AST_FORMAT_GET_TYPE(s->fmt->format.id) == AST_FORMAT_TYPE_AUDIO) + if (ast_format_get_type(s->fmt->format) == AST_MEDIA_TYPE_AUDIO) res = ast_readaudio_callback(s); else res = ast_readvideo_callback(s); @@ -1067,14 +1079,15 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p { struct ast_filestream *fs; struct ast_filestream *vfs=NULL; - char fmt[256]; off_t pos; int seekattempt; int res; fs = ast_openstream(chan, filename, preflang); if (!fs) { - ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", filename, ast_getformatname_multiple(fmt, sizeof(fmt), ast_channel_nativeformats(chan)), strerror(errno)); + struct ast_str *codec_buf = ast_str_alloca(64); + ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", + filename, ast_format_cap_get_names(ast_channel_nativeformats(chan), &codec_buf), strerror(errno)); return -1; } @@ -1096,7 +1109,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p vfs = ast_openvstream(chan, filename, preflang); if (vfs) { - ast_debug(1, "Ooh, found a video stream, too, format %s\n", ast_getformatname(&vfs->fmt->format)); + ast_debug(1, "Ooh, found a video stream, too, format %s\n", ast_format_get_name(vfs->fmt->format)); } if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MASQ_NOSTREAM)) @@ -1108,7 +1121,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p res = ast_playstream(fs); if (!res && vfs) res = ast_playstream(vfs); - ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), filename, ast_getformatname(ast_channel_writeformat(chan)), preflang ? preflang : "default"); + ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), filename, ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang : "default"); return res; } @@ -1330,7 +1343,7 @@ static void waitstream_control(struct ast_channel *c, } if (cb) { - long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_rate(&ast_channel_stream(c)->fmt->format) / 1000); + long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_get_sample_rate(ast_channel_stream(c)->fmt->format) / 1000); cb(c, ms_len, type); } @@ -1373,7 +1386,7 @@ static int waitstream_core(struct ast_channel *c, orig_chan_name = ast_strdupa(ast_channel_name(c)); if (ast_channel_stream(c) && cb) { - long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_rate(&ast_channel_stream(c)->fmt->format) / 1000); + long ms_len = ast_tellstream(ast_channel_stream(c)) / (ast_format_get_sample_rate(ast_channel_stream(c)->fmt->format) / 1000); cb(c, ms_len, AST_WAITSTREAM_CB_START); } @@ -1722,7 +1735,7 @@ static char *handle_cli_core_show_file_formats(struct ast_cli_entry *e, int cmd, AST_RWLIST_RDLOCK(&formats); AST_RWLIST_TRAVERSE(&formats, f, list) { - ast_cli(a->fd, FORMAT2, ast_getformatname(&f->format), f->name, f->exts); + ast_cli(a->fd, FORMAT2, ast_format_get_name(f->format), f->name, f->exts); count_fmt++; } AST_RWLIST_UNLOCK(&formats); @@ -1732,13 +1745,13 @@ static char *handle_cli_core_show_file_formats(struct ast_cli_entry *e, int cmd, #undef FORMAT2 } -const struct ast_format *ast_get_format_for_file_ext(const char *file_ext) +struct ast_format *ast_get_format_for_file_ext(const char *file_ext) { struct ast_format_def *f; SCOPED_RDLOCK(lock, &formats.lock); AST_RWLIST_TRAVERSE(&formats, f, list) { if (exts_compare(f->exts, file_ext)) { - return &f->format; + return f->format; } } |