[FFmpeg-devel,4/5] avformat/rawdec: Make the raw packet size configurable

Submitted by Michael Niedermayer on July 6, 2019, 10:57 a.m.

Details

Message ID 20190706105749.11410-4-michael@niedermayer.cc
State Accepted
Commit f6d1b18b3d58cd8f06eea653c4a6e22e4b9245e6
Headers show

Commit Message

Michael Niedermayer July 6, 2019, 10:57 a.m.
This allows testing parsers with a wider range of input packet sizes.
Which is important and usefull for regression testing, some of our
parsers in fact to not work if the packet size is changed from 1024

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/ac3dec.c     |  6 ++++++
 libavformat/acm.c        |  3 +++
 libavformat/dtsdec.c     |  4 +++-
 libavformat/flacdec.c    |  4 ++++
 libavformat/g722.c       |  4 +++-
 libavformat/loasdec.c    |  3 +++
 libavformat/mlpdec.c     |  6 ++++++
 libavformat/rawdec.c     | 12 +++++++++++-
 libavformat/rawdec.h     | 19 +++++++++++++++++--
 libavformat/sbcdec.c     |  3 +++
 libavformat/shortendec.c |  3 +++
 libavformat/takdec.c     |  4 ++++
 libavformat/wsddec.c     |  3 +++
 13 files changed, 69 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 3736b118d3..1f87939388 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -102,6 +102,7 @@  static int ac3_probe(const AVProbeData *p)
     return ac3_eac3_probe(p, AV_CODEC_ID_AC3);
 }
 
+FF_RAW_DEMUXER_CLASS(ac3)
 AVInputFormat ff_ac3_demuxer = {
     .name           = "ac3",
     .long_name      = NULL_IF_CONFIG_SMALL("raw AC-3"),
@@ -111,6 +112,8 @@  AVInputFormat ff_ac3_demuxer = {
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "ac3",
     .raw_codec_id   = AV_CODEC_ID_AC3,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &ac3_demuxer_class,
 };
 #endif
 
@@ -120,6 +123,7 @@  static int eac3_probe(const AVProbeData *p)
     return ac3_eac3_probe(p, AV_CODEC_ID_EAC3);
 }
 
+FF_RAW_DEMUXER_CLASS(eac3)
 AVInputFormat ff_eac3_demuxer = {
     .name           = "eac3",
     .long_name      = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
@@ -129,5 +133,7 @@  AVInputFormat ff_eac3_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "eac3",
     .raw_codec_id   = AV_CODEC_ID_EAC3,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &eac3_demuxer_class,
 };
 #endif
diff --git a/libavformat/acm.c b/libavformat/acm.c
index 125352a8f6..5e03cf8bff 100644
--- a/libavformat/acm.c
+++ b/libavformat/acm.c
@@ -60,6 +60,7 @@  static int acm_read_header(AVFormatContext *s)
     return 0;
 }
 
+FF_RAW_DEMUXER_CLASS(acm)
 AVInputFormat ff_acm_demuxer = {
     .name           = "acm",
     .long_name      = NULL_IF_CONFIG_SMALL("Interplay ACM"),
@@ -69,4 +70,6 @@  AVInputFormat ff_acm_demuxer = {
     .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
     .extensions     = "acm",
     .raw_codec_id   = AV_CODEC_ID_INTERPLAY_ACM,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &acm_demuxer_class,
 };
diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 8ec7925c59..ab59a56dfc 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -127,6 +127,7 @@  static int dts_probe(const AVProbeData *p)
     return 0;
 }
 
+FF_RAW_DEMUXER_CLASS(dts)
 AVInputFormat ff_dts_demuxer = {
     .name           = "dts",
     .long_name      = NULL_IF_CONFIG_SMALL("raw DTS"),
@@ -136,4 +137,5 @@  AVInputFormat ff_dts_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "dts",
     .raw_codec_id   = AV_CODEC_ID_DTS,
-};
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &dts_demuxer_class,};
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index ea803f57dd..8394e47483 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -31,6 +31,8 @@ 
 #define SEEKPOINT_SIZE 18
 
 typedef struct FLACDecContext {
+    AVClass *class;
+    int raw_packet_size;
     int found_seektable;
 } FLACDecContext;
 
@@ -327,6 +329,7 @@  static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
     return -1;
 }
 
+FF_RAW_DEMUXER_CLASS(flac)
 AVInputFormat ff_flac_demuxer = {
     .name           = "flac",
     .long_name      = NULL_IF_CONFIG_SMALL("raw FLAC"),
@@ -339,4 +342,5 @@  AVInputFormat ff_flac_demuxer = {
     .extensions     = "flac",
     .raw_codec_id   = AV_CODEC_ID_FLAC,
     .priv_data_size = sizeof(FLACDecContext),
+    .priv_class     = &flac_demuxer_class,
 };
diff --git a/libavformat/g722.c b/libavformat/g722.c
index 2feec01211..fe8c4ae7bb 100644
--- a/libavformat/g722.c
+++ b/libavformat/g722.c
@@ -46,6 +46,7 @@  static int g722_read_header(AVFormatContext *s)
     return 0;
 }
 
+FF_RAW_DEMUXER_CLASS(g722)
 AVInputFormat ff_g722_demuxer = {
     .name           = "g722",
     .long_name      = NULL_IF_CONFIG_SMALL("raw G.722"),
@@ -54,4 +55,5 @@  AVInputFormat ff_g722_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "g722,722",
     .raw_codec_id   = AV_CODEC_ID_ADPCM_G722,
-};
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &g722_demuxer_class,};
diff --git a/libavformat/loasdec.c b/libavformat/loasdec.c
index c7e124e340..e166a5928a 100644
--- a/libavformat/loasdec.c
+++ b/libavformat/loasdec.c
@@ -83,6 +83,7 @@  static int loas_read_header(AVFormatContext *s)
     return 0;
 }
 
+FF_RAW_DEMUXER_CLASS(loas)
 AVInputFormat ff_loas_demuxer = {
     .name           = "loas",
     .long_name      = NULL_IF_CONFIG_SMALL("LOAS AudioSyncStream"),
@@ -91,4 +92,6 @@  AVInputFormat ff_loas_demuxer = {
     .read_packet    = ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .raw_codec_id = AV_CODEC_ID_AAC_LATM,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &loas_demuxer_class,
 };
diff --git a/libavformat/mlpdec.c b/libavformat/mlpdec.c
index e210d7d52e..40b1833761 100644
--- a/libavformat/mlpdec.c
+++ b/libavformat/mlpdec.c
@@ -56,6 +56,7 @@  static int mlp_probe(const AVProbeData *p)
     return mlp_thd_probe(p, 0xf8726fbb);
 }
 
+FF_RAW_DEMUXER_CLASS(mlp)
 AVInputFormat ff_mlp_demuxer = {
     .name           = "mlp",
     .long_name      = NULL_IF_CONFIG_SMALL("raw MLP"),
@@ -65,6 +66,8 @@  AVInputFormat ff_mlp_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
     .extensions     = "mlp",
     .raw_codec_id   = AV_CODEC_ID_MLP,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &mlp_demuxer_class,
 };
 #endif
 
@@ -74,6 +77,7 @@  static int thd_probe(const AVProbeData *p)
     return mlp_thd_probe(p, 0xf8726fba);
 }
 
+FF_RAW_DEMUXER_CLASS(truehd)
 AVInputFormat ff_truehd_demuxer = {
     .name           = "truehd",
     .long_name      = NULL_IF_CONFIG_SMALL("raw TrueHD"),
@@ -83,6 +87,8 @@  AVInputFormat ff_truehd_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
     .extensions     = "thd",
     .raw_codec_id   = AV_CODEC_ID_TRUEHD,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &truehd_demuxer_class,
 };
 #endif
 
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index c602e539f5..59b49e3f77 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -34,9 +34,10 @@ 
 
 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    FFRawDemuxerContext *raw = s->priv_data;
     int ret, size;
 
-    size = RAW_PACKET_SIZE;
+    size = raw->raw_packet_size;
 
     if (av_new_packet(pkt, size) < 0)
         return AVERROR(ENOMEM);
@@ -119,10 +120,17 @@  int ff_raw_data_read_header(AVFormatContext *s)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 const AVOption ff_rawvideo_options[] = {
     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
+    { "raw_packet_size", "", OFFSET(raw_packet_size), AV_OPT_TYPE_INT, {.i64 = RAW_PACKET_SIZE }, 1, INT_MAX, DEC},
+    { NULL },
+};
+const AVOption ff_raw_options[] = {
+    { "raw_packet_size", "", OFFSET(raw_packet_size), AV_OPT_TYPE_INT, {.i64 = RAW_PACKET_SIZE }, 1, INT_MAX, DEC},
     { NULL },
 };
 
 #if CONFIG_DATA_DEMUXER
+FF_RAW_DEMUXER_CLASS(raw_data)
+
 AVInputFormat ff_data_demuxer = {
     .name           = "data",
     .long_name      = NULL_IF_CONFIG_SMALL("raw data"),
@@ -130,6 +138,8 @@  AVInputFormat ff_data_demuxer = {
     .read_packet    = ff_raw_read_partial_packet,
     .raw_codec_id   = AV_CODEC_ID_NONE,
     .flags          = AVFMT_NOTIMESTAMPS,
+    .priv_data_size = sizeof(FFRawDemuxerContext),\
+    .priv_class     = &raw_data_demuxer_class,\
 };
 #endif
 
diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h
index 3eb416b8ee..85e0790c86 100644
--- a/libavformat/rawdec.h
+++ b/libavformat/rawdec.h
@@ -28,12 +28,19 @@ 
 
 typedef struct FFRawVideoDemuxerContext {
     const AVClass *class;     /**< Class for private options. */
+    int raw_packet_size;
     char *video_size;         /**< String describing video size, set by a private option. */
     char *pixel_format;       /**< Set by a private option. */
     AVRational framerate;     /**< AVRational describing framerate, set by a private option. */
 } FFRawVideoDemuxerContext;
 
+typedef struct FFRawDemuxerContext {
+    const AVClass *class;     /**< Class for private options. */
+    int raw_packet_size;
+} FFRawDemuxerContext;
+
 extern const AVOption ff_rawvideo_options[];
+extern const AVOption ff_raw_options[];
 
 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt);
 
@@ -45,6 +52,14 @@  int ff_raw_subtitle_read_header(AVFormatContext *s);
 
 int ff_raw_data_read_header(AVFormatContext *s);
 
+#define FF_RAW_DEMUXER_CLASS(name)\
+static const AVClass name ## _demuxer_class = {\
+    .class_name = #name " demuxer",\
+    .item_name  = av_default_item_name,\
+    .option     = ff_raw_options,\
+    .version    = LIBAVUTIL_VERSION_INT,\
+};
+
 #define FF_RAWVIDEO_DEMUXER_CLASS(name)\
 static const AVClass name ## _demuxer_class = {\
     .class_name = #name " demuxer",\
@@ -75,7 +90,7 @@  FF_DEF_RAWVIDEO_DEMUXER2(shortname, longname, probe, ext, id, AVFMT_GENERIC_INDE
 static const AVClass name ## _demuxer_class = {\
     .class_name = #name " demuxer",\
     .item_name  = av_default_item_name,\
-    .option     = NULL,\
+    .option     = ff_raw_options,\
     .version    = LIBAVUTIL_VERSION_INT,\
 };
 
@@ -90,7 +105,7 @@  AVInputFormat ff_ ## shortname ## _demuxer = {\
     .extensions     = ext,\
     .flags          = flag,\
     .raw_codec_id   = id,\
-    .priv_data_size = 0,\
+    .priv_data_size = sizeof(FFRawDemuxerContext),\
     .priv_class     = &shortname ## _demuxer_class,\
 };
 
diff --git a/libavformat/sbcdec.c b/libavformat/sbcdec.c
index ae74a220dc..7a455ce123 100644
--- a/libavformat/sbcdec.c
+++ b/libavformat/sbcdec.c
@@ -22,6 +22,7 @@ 
 #include "avformat.h"
 #include "rawdec.h"
 
+FF_RAW_DEMUXER_CLASS(sbc)
 AVInputFormat ff_sbc_demuxer = {
     .name           = "sbc",
     .long_name      = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity subband codec)"),
@@ -30,4 +31,6 @@  AVInputFormat ff_sbc_demuxer = {
     .read_header    = ff_raw_audio_read_header,
     .read_packet    = ff_raw_read_partial_packet,
     .flags          = AVFMT_GENERIC_INDEX,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &sbc_demuxer_class,
 };
diff --git a/libavformat/shortendec.c b/libavformat/shortendec.c
index b02984a3f7..a2879dc5a3 100644
--- a/libavformat/shortendec.c
+++ b/libavformat/shortendec.c
@@ -59,6 +59,7 @@  static int shn_probe(const AVProbeData *p)
     return AVPROBE_SCORE_EXTENSION + 1;
 }
 
+FF_RAW_DEMUXER_CLASS(shorten)
 AVInputFormat ff_shorten_demuxer = {
     .name           = "shn",
     .long_name      = NULL_IF_CONFIG_SMALL("raw Shorten"),
@@ -68,4 +69,6 @@  AVInputFormat ff_shorten_demuxer = {
     .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
     .extensions     = "shn",
     .raw_codec_id   = AV_CODEC_ID_SHORTEN,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &shorten_demuxer_class,
 };
diff --git a/libavformat/takdec.c b/libavformat/takdec.c
index ee96c27992..2db8ff3ee4 100644
--- a/libavformat/takdec.c
+++ b/libavformat/takdec.c
@@ -31,6 +31,8 @@ 
 #include "rawdec.h"
 
 typedef struct TAKDemuxContext {
+    AVClass *class;
+    int     raw_packet_size;
     int     mlast_frame;
     int64_t data_end;
 } TAKDemuxContext;
@@ -204,6 +206,7 @@  static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
     return ret;
 }
 
+FF_RAW_DEMUXER_CLASS(tak)
 AVInputFormat ff_tak_demuxer = {
     .name           = "tak",
     .long_name      = NULL_IF_CONFIG_SMALL("raw TAK"),
@@ -214,4 +217,5 @@  AVInputFormat ff_tak_demuxer = {
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "tak",
     .raw_codec_id   = AV_CODEC_ID_TAK,
+    .priv_class     = &tak_demuxer_class,
 };
diff --git a/libavformat/wsddec.c b/libavformat/wsddec.c
index 574addf620..2313b0ec4b 100644
--- a/libavformat/wsddec.c
+++ b/libavformat/wsddec.c
@@ -161,6 +161,7 @@  static int wsd_read_header(AVFormatContext *s)
     return avio_seek(pb, data_offset, SEEK_SET);
 }
 
+FF_RAW_DEMUXER_CLASS(wsd)
 AVInputFormat ff_wsd_demuxer = {
     .name         = "wsd",
     .long_name    = NULL_IF_CONFIG_SMALL("Wideband Single-bit Data (WSD)"),
@@ -170,4 +171,6 @@  AVInputFormat ff_wsd_demuxer = {
     .extensions   = "wsd",
     .flags        = AVFMT_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK,
     .raw_codec_id = AV_CODEC_ID_DSD_MSBF,
+    .priv_data_size = sizeof(FFRawDemuxerContext),
+    .priv_class     = &wsd_demuxer_class,
 };