]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/pcmdec.c
avutil/pixdesc: Remove deprecated off-by-one fields from pix fmt descs
[ffmpeg] / libavformat / pcmdec.c
index 9895af03a43e490a248b477905a23a35149b39b6..9b552936acfd8072ac5a4f3265638eb424d3218e 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avstring.h"
 #include "avformat.h"
 #include "internal.h"
 #include "pcm.h"
@@ -35,36 +36,33 @@ typedef struct PCMAudioDemuxerContext {
 static int pcm_read_header(AVFormatContext *s)
 {
     PCMAudioDemuxerContext *s1 = s->priv_data;
+    AVCodecParameters *par;
     AVStream *st;
     uint8_t *mime_type = NULL;
 
     st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
+    par = st->codecpar;
 
-
-    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->codec_id    = s->iformat->raw_codec_id;
-    st->codecpar->sample_rate = s1->sample_rate;
-    st->codecpar->channels    = s1->channels;
+    par->codec_type  = AVMEDIA_TYPE_AUDIO;
+    par->codec_id    = s->iformat->raw_codec_id;
+    par->sample_rate = s1->sample_rate;
+    par->channels    = s1->channels;
 
     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, little_endian = 0;
-        size_t len = strlen(s->iformat->mime_type);
-        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) {
-                options = strstr(options, ";");
-                if (!options++)
-                    break;
+        const char *options;
+        if (av_stristart(mime_type, s->iformat->mime_type, &options)) { /* audio/L16 */
+            while (options = strchr(options, ';')) {
+                options++;
                 if (!rate)
                     sscanf(options, " rate=%d",     &rate);
                 if (!channels)
                     sscanf(options, " channels=%d", &channels);
                 if (!little_endian) {
-                     char val[14]; /* sizeof("little-endian") == 14 */
+                     char val[sizeof("little-endian")];
                      if (sscanf(options, " endianness=%13s", val) == 1) {
                          little_endian = strcmp(val, "little-endian") == 0;
                      }
@@ -77,24 +75,22 @@ static int pcm_read_header(AVFormatContext *s)
                 av_freep(&mime_type);
                 return AVERROR_INVALIDDATA;
             }
-            st->codecpar->sample_rate = rate;
+            par->sample_rate = rate;
             if (channels > 0)
-                st->codecpar->channels = channels;
+                par->channels = channels;
             if (little_endian)
-                st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+                par->codec_id = AV_CODEC_ID_PCM_S16LE;
         }
     }
     av_freep(&mime_type);
 
-    st->codecpar->bits_per_coded_sample =
-        av_get_bits_per_sample(st->codecpar->codec_id);
+    par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
 
-    av_assert0(st->codecpar->bits_per_coded_sample > 0);
+    av_assert0(par->bits_per_coded_sample > 0);
 
-    st->codecpar->block_align =
-        st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8;
+    par->block_align = par->bits_per_coded_sample * par->channels / 8;
 
-    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
+    avpriv_set_pts_info(st, 64, 1, par->sample_rate);
     return 0;
 }
 
@@ -104,7 +100,8 @@ static const AVOption pcm_options[] = {
     { NULL },
 };
 
-#define PCMDEF(name_, long_name_, ext, codec, ...)          \
+#define PCMDEF_0(name_, long_name_, ext, codec, ...)
+#define PCMDEF_1(name_, long_name_, ext, codec, ...)        \
 static const AVClass name_ ## _demuxer_class = {            \
     .class_name = #name_ " demuxer",                        \
     .item_name  = av_default_item_name,                     \
@@ -124,70 +121,40 @@ AVInputFormat ff_pcm_ ## name_ ## _demuxer = {              \
     .priv_class     = &name_ ## _demuxer_class,             \
     __VA_ARGS__                                             \
 };
-
-PCMDEF(f64be, "PCM 64-bit floating-point big-endian",
-       NULL, AV_CODEC_ID_PCM_F64BE)
-
-PCMDEF(f64le, "PCM 64-bit floating-point little-endian",
-       NULL, AV_CODEC_ID_PCM_F64LE)
-
-PCMDEF(f32be, "PCM 32-bit floating-point big-endian",
-       NULL, AV_CODEC_ID_PCM_F32BE)
-
-PCMDEF(f32le, "PCM 32-bit floating-point little-endian",
-       NULL, AV_CODEC_ID_PCM_F32LE)
-
-PCMDEF(s32be, "PCM signed 32-bit big-endian",
-       NULL, AV_CODEC_ID_PCM_S32BE)
-
-PCMDEF(s32le, "PCM signed 32-bit little-endian",
-       NULL, AV_CODEC_ID_PCM_S32LE)
-
-PCMDEF(s24be, "PCM signed 24-bit big-endian",
-       NULL, AV_CODEC_ID_PCM_S24BE)
-
-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, .mime_type = "audio/L16")
-
-PCMDEF(s16le, "PCM signed 16-bit little-endian",
-       AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE)
-
-PCMDEF(s8, "PCM signed 8-bit",
-       "sb", AV_CODEC_ID_PCM_S8)
-
-PCMDEF(u32be, "PCM unsigned 32-bit big-endian",
-       NULL, AV_CODEC_ID_PCM_U32BE)
-
-PCMDEF(u32le, "PCM unsigned 32-bit little-endian",
-       NULL, AV_CODEC_ID_PCM_U32LE)
-
-PCMDEF(u24be, "PCM unsigned 24-bit big-endian",
-       NULL, AV_CODEC_ID_PCM_U24BE)
-
-PCMDEF(u24le, "PCM unsigned 24-bit little-endian",
-       NULL, AV_CODEC_ID_PCM_U24LE)
-
-PCMDEF(u16be, "PCM unsigned 16-bit big-endian",
-       AV_NE("uw", NULL), AV_CODEC_ID_PCM_U16BE)
-
-PCMDEF(u16le, "PCM unsigned 16-bit little-endian",
-       AV_NE(NULL, "uw"), AV_CODEC_ID_PCM_U16LE)
-
-PCMDEF(u8, "PCM unsigned 8-bit",
-       "ub", AV_CODEC_ID_PCM_U8)
-
-PCMDEF(alaw, "PCM A-law",
-       "al", AV_CODEC_ID_PCM_ALAW)
-
-PCMDEF(mulaw, "PCM mu-law",
-       "ul", AV_CODEC_ID_PCM_MULAW)
-
-PCMDEF(vidc, "PCM Archimedes VIDC",
-       NULL, AV_CODEC_ID_PCM_VIDC)
-
+#define PCMDEF_2(name, long_name, ext, codec, enabled, ...) \
+    PCMDEF_ ## enabled(name, long_name, ext, codec, __VA_ARGS__)
+#define PCMDEF_3(name, long_name, ext, codec, config, ...)  \
+    PCMDEF_2(name, long_name, ext, codec, config,   __VA_ARGS__)
+#define PCMDEF_EXT(name, long_name, ext, uppercase, ...)    \
+    PCMDEF_3(name, long_name, ext, AV_CODEC_ID_PCM_ ## uppercase, \
+             CONFIG_PCM_ ## uppercase ## _DEMUXER,  __VA_ARGS__)
+#define PCMDEF(name, long_name, ext, uppercase)             \
+    PCMDEF_EXT(name, long_name, ext, uppercase, )
+
+PCMDEF(f64be, "PCM 64-bit floating-point big-endian",           NULL, F64BE)
+PCMDEF(f64le, "PCM 64-bit floating-point little-endian",        NULL, F64LE)
+PCMDEF(f32be, "PCM 32-bit floating-point big-endian",           NULL, F32BE)
+PCMDEF(f32le, "PCM 32-bit floating-point little-endian",        NULL, F32LE)
+PCMDEF(s32be, "PCM signed 32-bit big-endian",                   NULL, S32BE)
+PCMDEF(s32le, "PCM signed 32-bit little-endian",                NULL, S32LE)
+PCMDEF(s24be, "PCM signed 24-bit big-endian",                   NULL, S24BE)
+PCMDEF(s24le, "PCM signed 24-bit little-endian",                NULL, S24LE)
+PCMDEF_EXT(s16be, "PCM signed 16-bit big-endian",
+           AV_NE("sw", NULL), S16BE, .mime_type = "audio/L16")
+PCMDEF(s16le, "PCM signed 16-bit little-endian",   AV_NE(NULL, "sw"), S16LE)
+PCMDEF(s8,    "PCM signed 8-bit",                               "sb",    S8)
+PCMDEF(u32be, "PCM unsigned 32-bit big-endian",                 NULL, U32BE)
+PCMDEF(u32le, "PCM unsigned 32-bit little-endian",              NULL, U32LE)
+PCMDEF(u24be, "PCM unsigned 24-bit big-endian",                 NULL, U24BE)
+PCMDEF(u24le, "PCM unsigned 24-bit little-endian",              NULL, U24LE)
+PCMDEF(u16be, "PCM unsigned 16-bit big-endian",    AV_NE("uw", NULL), U16BE)
+PCMDEF(u16le, "PCM unsigned 16-bit little-endian", AV_NE(NULL, "uw"), U16LE)
+PCMDEF(u8,    "PCM unsigned 8-bit",                             "ub",    U8)
+PCMDEF(alaw,  "PCM A-law",                                      "al",  ALAW)
+PCMDEF(mulaw, "PCM mu-law",                                     "ul", MULAW)
+PCMDEF(vidc,  "PCM Archimedes VIDC",                            NULL,  VIDC)
+
+#if CONFIG_SLN_DEMUXER
 static const AVOption sln_options[] = {
     { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 8000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { "channels",    "", offsetof(PCMAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
@@ -213,3 +180,4 @@ AVInputFormat ff_sln_demuxer = {
     .raw_codec_id   = AV_CODEC_ID_PCM_S16LE,
     .priv_class     = &sln_demuxer_class,
 };
+#endif