Hello!
A little bunch of fixes for audio/L16 mime type handling:
0001 - RFC 2045 says MIME type should be case insensitive;
0002 - RFC 2586 says audio/L16 should be in network byte order (aka big
endian);
0003 - though "endiannes" parameter not in RFC it is widely used;
From e40e9567995042d75f8070daaa2efde46409f877 Mon Sep 17 00:00:00 2001
From: Igor Derzhavin <igor.derzhavin@gmail.com>
Date: Thu, 22 Nov 2018 10:38:20 +0300
Subject: [PATCH 1/3] avformat/pcmdec: mime-type should be case insensitive
 (audio/L16)

---
 libavformat/pcmdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index bd2a0384f8..0d146a46a0 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -52,7 +52,7 @@ static int pcm_read_header(AVFormatContext *s)
     if (mime_type && s->iformat->mime_type) {
         int rate = 0, channels = 0;
         size_t len = strlen(s->iformat->mime_type);
-        if (!strncmp(s->iformat->mime_type, mime_type, len)) {
+        if (!av_strncasecmp(s->iformat->mime_type, mime_type, len)) {
             uint8_t *options = mime_type + len;
             len = strlen(mime_type);
             while (options < mime_type + len) {
-- 
2.17.1

From 4aa886c8941086d5290c10439a4a822538ec61e8 Mon Sep 17 00:00:00 2001
From: Igor Derzhavin <igor.derzhavin@gmail.com>
Date: Thu, 22 Nov 2018 10:54:42 +0300
Subject: [PATCH 3/3] avformat/pcmdec: endianness for audio/L16 mime type

---
 libavformat/pcmdec.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 8530dbc1e3..9895af03a4 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -50,9 +50,9 @@ static int pcm_read_header(AVFormatContext *s)
 
     av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type);
     if (mime_type && s->iformat->mime_type) {
-        int rate = 0, channels = 0;
+        int rate = 0, channels = 0, little_endian = 0;
         size_t len = strlen(s->iformat->mime_type);
-        if (!av_strncasecmp(s->iformat->mime_type, mime_type, len)) {
+        if (!av_strncasecmp(s->iformat->mime_type, mime_type, len)) { /* audio/L16 */
             uint8_t *options = mime_type + len;
             len = strlen(mime_type);
             while (options < mime_type + len) {
@@ -63,6 +63,12 @@ static int pcm_read_header(AVFormatContext *s)
                     sscanf(options, " rate=%d",     &rate);
                 if (!channels)
                     sscanf(options, " channels=%d", &channels);
+                if (!little_endian) {
+                     char val[14]; /* sizeof("little-endian") == 14 */
+                     if (sscanf(options, " endianness=%13s", val) == 1) {
+                         little_endian = strcmp(val, "little-endian") == 0;
+                     }
+                }
             }
             if (rate <= 0) {
                 av_log(s, AV_LOG_ERROR,
@@ -74,6 +80,8 @@ static int pcm_read_header(AVFormatContext *s)
             st->codecpar->sample_rate = rate;
             if (channels > 0)
                 st->codecpar->channels = channels;
+            if (little_endian)
+                st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
         }
     }
     av_freep(&mime_type);
-- 
2.17.1

From 817fd71b9c87d019996d711d47517994c55636b1 Mon Sep 17 00:00:00 2001
From: Igor Derzhavin <igor.derzhavin@gmail.com>
Date: Thu, 22 Nov 2018 10:39:57 +0300
Subject: [PATCH 2/3] avformat/pcmdec: audio/L16 should be in network byte
 order by default (rfc 2586)

---
 libavformat/pcmdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 0d146a46a0..8530dbc1e3 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -142,10 +142,10 @@ PCMDEF(s24le, "PCM signed 24-bit little-endian",
        NULL, AV_CODEC_ID_PCM_S24LE)
 
 PCMDEF(s16be, "PCM signed 16-bit big-endian",
-       AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE)
+       AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE, .mime_type = "audio/L16")
 
 PCMDEF(s16le, "PCM signed 16-bit little-endian",
-       AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE, .mime_type = "audio/L16",)
+       AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE)
 
 PCMDEF(s8, "PCM signed 8-bit",
        "sb", AV_CODEC_ID_PCM_S8)
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to