History

avformat/av1dec: Deduplicate Annex B and low overhead OBU AV1 demuxer

Andreas Rheinhardt committed 5 years ago

Commit 172116f1 parent 8a805091 file · +47 −86Browse files

Unified · Split

libavformat/av1dec.c+47−86
@@ -29,6 +29,14 @@ · 28 unmodified lines
2929 #include "avio_internal.h"
3030 #include "internal.h"
3131
32+typedef struct AV1DemuxContext {
33+ const AVClass *class;
34+ AVBSFContext *bsf;
35+ AVRational framerate;
36+ uint32_t temporal_unit_size;
37+ uint32_t frame_unit_size;
38+} AV1DemuxContext;
39+
3240 //return < 0 if we need more data
3341 static int get_score(int type, int *seq)
3442 {
@@ -48,14 +56,15 @@ static int get_score(int type, int *seq) · 13 unmodified lines
4856 return 0;
4957 }
5058
51−static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFContext **bsf, void *logctx)
59+static int av1_read_header(AVFormatContext *s)
5260 {
61+ AV1DemuxContext *const c = s->priv_data;
5362 const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge");
5463 AVStream *st;
5564 int ret;
5665
5766 if (!filter) {
58− av_log(logctx, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
67+ av_log(s, AV_LOG_ERROR, "av1_frame_merge bitstream filter "
5968 "not found. This is a bug, please report it.\n");
6069 return AVERROR_BUG;
6170 }
@@ -68,35 +77,49 @@ static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon · 6 unmodified lines
6877 st->codecpar->codec_id = AV_CODEC_ID_AV1;
6978 st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
7079
71− st->internal->avctx->framerate = *framerate;
80+ st->internal->avctx->framerate = c->framerate;
7281 // taken from rawvideo demuxers
7382 avpriv_set_pts_info(st, 64, 1, 1200000);
7483
75− ret = av_bsf_alloc(filter, bsf);
84+ ret = av_bsf_alloc(filter, &c->bsf);
7685 if (ret < 0)
7786 return ret;
7887
79− ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
88+ ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar);
8089 if (ret < 0)
8190 return ret;
8291
83− ret = av_bsf_init(*bsf);
92+ ret = av_bsf_init(c->bsf);
8493 if (ret < 0)
8594 return ret;
8695
8796 return 0;
8897 }
8998
99+static int av1_read_close(AVFormatContext *s)
100+{
101+ AV1DemuxContext *const c = s->priv_data;
102+
103+ av_bsf_free(&c->bsf);
104+ return 0;
105+}
106+
90107 #define DEC AV_OPT_FLAG_DECODING_PARAM
108+#define OFFSET(x) offsetof(AV1DemuxContext, x)
109+static const AVOption av1_options[] = {
110+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
111+ { NULL },
112+};
113+#undef OFFSET
114+
115+static const AVClass av1_demuxer_class = {
116+ .class_name = "AV1 Annex B/low overhead OBU demuxer",
117+ .item_name = av_default_item_name,
118+ .option = av1_options,
119+ .version = LIBAVUTIL_VERSION_INT,
120+};
91121
92122 #if CONFIG_AV1_DEMUXER
93−typedef struct AnnexBContext {
94− const AVClass *class;
95− AVBSFContext *bsf;
96− uint32_t temporal_unit_size;
97− uint32_t frame_unit_size;
98− AVRational framerate;
99−} AnnexBContext;
100123
101124 static int leb(AVIOContext *pb, uint32_t *len) {
102125 int more, i = 0;
@@ -193,15 +216,9 @@ static int annexb_probe(const AVProbeData *p) · 90 unmodified lines
193216 return 0;
194217 }
195218
196−static int annexb_read_header(AVFormatContext *s)
197−{
198− AnnexBContext *c = s->priv_data;
199− return read_header(s, &c->framerate, &c->bsf, c);
200−}
201−
202219 static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt)
203220 {
204− AnnexBContext *c = s->priv_data;
221+ AV1DemuxContext *const c = s->priv_data;
205222 uint32_t obu_unit_size;
206223 int ret, len;
207224
@@ -256,50 +273,22 @@ end: · 48 unmodified lines
256273 return ret;
257274 }
258275
259−static int annexb_read_close(AVFormatContext *s)
260−{
261− AnnexBContext *c = s->priv_data;
262−
263− av_bsf_free(&c->bsf);
264− return 0;
265−}
266−
267−#define OFFSET(x) offsetof(AnnexBContext, x)
268−static const AVOption annexb_options[] = {
269− { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
270− { NULL },
271−};
272−#undef OFFSET
273−
274−static const AVClass annexb_demuxer_class = {
275− .class_name = "AV1 Annex B demuxer",
276− .item_name = av_default_item_name,
277− .option = annexb_options,
278− .version = LIBAVUTIL_VERSION_INT,
279−};
280−
281276 const AVInputFormat ff_av1_demuxer = {
282277 .name = "av1",
283278 .long_name = NULL_IF_CONFIG_SMALL("AV1 Annex B"),
284− .priv_data_size = sizeof(AnnexBContext),
279+ .priv_data_size = sizeof(AV1DemuxContext),
285280 .flags_internal = FF_FMT_INIT_CLEANUP,
286281 .read_probe = annexb_probe,
287− .read_header = annexb_read_header,
282+ .read_header = av1_read_header,
288283 .read_packet = annexb_read_packet,
289− .read_close = annexb_read_close,
284+ .read_close = av1_read_close,
290285 .extensions = "obu",
291286 .flags = AVFMT_GENERIC_INDEX,
292− .priv_class = &annexb_demuxer_class,
287+ .priv_class = &av1_demuxer_class,
293288 };
294289 #endif
295290
296291 #if CONFIG_OBU_DEMUXER
297−typedef struct ObuContext {
298− const AVClass *class;
299− AVBSFContext *bsf;
300− AVRational framerate;
301−} ObuContext;
302−
303292 //For low overhead obu, we can't foresee the obu size before we parsed the header.
304293 //So, we can't use parse_obu_header here, since it will check size <= buf_size
305294 //see c27c7b49dc for more details
@@ -367,15 +356,9 @@ static int obu_probe(const AVProbeData *p) · 61 unmodified lines
367356 return 0;
368357 }
369358
370−static int obu_read_header(AVFormatContext *s)
371−{
372− ObuContext *c = s->priv_data;
373− return read_header(s, &c->framerate, &c->bsf, c);
374−}
375−
376359 static int obu_get_packet(AVFormatContext *s, AVPacket *pkt)
377360 {
378− ObuContext *c = s->priv_data;
361+ AV1DemuxContext *const c = s->priv_data;
379362 uint8_t header[MAX_OBU_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
380363 int64_t obu_size;
381364 int size;
@@ -404,7 +387,7 @@ static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) · 22 unmodified lines
404387
405388 static int obu_read_packet(AVFormatContext *s, AVPacket *pkt)
406389 {
407− ObuContext *c = s->priv_data;
390+ AV1DemuxContext *const c = s->priv_data;
408391 int ret;
409392
410393 while (1) {
@@ -431,39 +414,17 @@ static int obu_read_packet(AVFormatContext *s, AVPacket *pkt) · 20 unmodified lines
431414 return ret;
432415 }
433416
434−static int obu_read_close(AVFormatContext *s)
435−{
436− ObuContext *c = s->priv_data;
437−
438− av_bsf_free(&c->bsf);
439− return 0;
440−}
441−
442−#define OFFSET(x) offsetof(ObuContext, x)
443−static const AVOption obu_options[] = {
444− { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
445− { NULL },
446−};
447−#undef OFFSET
448−
449−static const AVClass obu_demuxer_class = {
450− .class_name = "AV1 low overhead OBU demuxer",
451− .item_name = av_default_item_name,
452− .option = obu_options,
453− .version = LIBAVUTIL_VERSION_INT,
454−};
455−
456417 const AVInputFormat ff_obu_demuxer = {
457418 .name = "obu",
458419 .long_name = NULL_IF_CONFIG_SMALL("AV1 low overhead OBU"),
459− .priv_data_size = sizeof(ObuContext),
420+ .priv_data_size = sizeof(AV1DemuxContext),
460421 .flags_internal = FF_FMT_INIT_CLEANUP,
461422 .read_probe = obu_probe,
462− .read_header = obu_read_header,
423+ .read_header = av1_read_header,
463424 .read_packet = obu_read_packet,
464− .read_close = obu_read_close,
425+ .read_close = av1_read_close,
465426 .extensions = "obu",
466427 .flags = AVFMT_GENERIC_INDEX,
467− .priv_class = &obu_demuxer_class,
428+ .priv_class = &av1_demuxer_class,
468429 };
469430 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t