[FFmpeg-devel] [PATCH]lavf/pcmdec: Map mime_type audio/L16 to the s16le demuxer
Carl Eugen Hoyos
ceffmpeg at gmail.com
Tue Aug 9 01:51:30 EEST 2016
Hi!
2016-08-05 12:44 GMT+02:00 Nicolas George <george at nsup.org>:
> Le nonidi 19 thermidor, an CCXXIV, Carl Eugen Hoyos a écrit :
>> Hi!
>>
>> Attached patch implements RFC 2586.
>>
>> Please comment, Carl Eugen
>
>> From ba470c643c836826d75854e3e3539eb09ddd288a Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos at ag.or.at>
>> Date: Fri, 5 Aug 2016 12:22:17 +0200
>> Subject: [PATCH] lavf/pcmdec: Map mime_type audio/L16 to s16le as specified
>> in RFC 2586.
>>
>> ---
>> libavformat/pcmdec.c | 63 +++++++++++++++++++++++++++++++++-----------------
>> 1 file changed, 42 insertions(+), 21 deletions(-)
>>
>> diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
>> index df94345..36ef2c2 100644
>> --- a/libavformat/pcmdec.c
>> +++ b/libavformat/pcmdec.c
>> @@ -36,6 +36,7 @@ static int pcm_read_header(AVFormatContext *s)
>> {
>> PCMAudioDemuxerContext *s1 = s->priv_data;
>> AVStream *st;
>> + uint8_t *mime_type_opt = NULL;
>>
>> st = avformat_new_stream(s, NULL);
>> if (!st)
>> @@ -47,6 +48,25 @@ static int pcm_read_header(AVFormatContext *s)
>> st->codecpar->sample_rate = s1->sample_rate;
>> st->codecpar->channels = s1->channels;
>>
>> + av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type_opt);
>> + if (mime_type_opt) {
>
>> + const char *mime_type = mime_type_opt;
>
> I do not understand the need for that line.
Removed.
>> + size_t len = strlen(s->iformat->mime_type);
>
> Maybe I am missing something obvious, but I think s->iformat->mime_type is
> NULL for all the other formats. It needs to be checked.
Added the check.
>> + int rate, channels = 0;
>> + if (!av_strncasecmp(s->iformat->mime_type, mime_type, len)) {
>
>> + if ( !sscanf(mime_type + len, ";rate=%d;channels=%d", &rate, &channels)
>
> If I understand the way MIME type works, ";channels=2;rate=48000" would be
> exactly as valid, and spaces can surround the semicolons.
I changed this hunk.
>> + || !rate) {
>> + av_log(s, AV_LOG_ERROR,
>> + "Invalid sample_rate found in mime_type \"%s\"\n",
>> + mime_type);
>> + return AVERROR_INVALIDDATA;
>> + }
>> + st->codecpar->sample_rate = rate;
>> + if (channels)
>> + st->codecpar->channels = channels;
>> + }
>> + }
>> +
>> st->codecpar->bits_per_coded_sample =
>> av_get_bits_per_sample(st->codecpar->codec_id);
>>
>> @@ -65,7 +85,7 @@ static const AVOption pcm_options[] = {
>> { NULL },
>> };
>>
>> -#define PCMDEF(name_, long_name_, ext, codec) \
>
>> +#define PCMDEF(name_, long_name_, ext, codec, mime_type_) \
>
> Instead of changing PCMDEF and all the subsequent declarations, you can
> create a new macro PCMDEF_WITH_MIME.
>
> Even simpler: make PCMDEF varadic, add __ARGS__ in the structure definition.
> Then, adding the MIME type is just a matter of adding ".mime_type = ..." in
> the macro call.
Yes, much simpler.
New patch attached.
Thank you, Carl Eugen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavf-pcmdec-Map-mime_type-audio-L16-to-the-s16le-dem.patch
Type: text/x-patch
Size: 3873 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160809/30bfbfe0/attachment.bin>
More information about the ffmpeg-devel
mailing list