Unified · Split
| @@ -29,6 +29,14 @@ · 28 unmodified lines | ||
| 29 | 29 | #include "avio_internal.h" |
| 30 | 30 | #include "internal.h" |
| 31 | 31 | |
| 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 | + | |
| 32 | 40 | //return < 0 if we need more data |
| 33 | 41 | static int get_score(int type, int *seq) |
| 34 | 42 | { |
| @@ -48,14 +56,15 @@ static int get_score(int type, int *seq) · 13 unmodified lines | ||
| 48 | 56 | return 0; |
| 49 | 57 | } |
| 50 | 58 | |
| 51 | −static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFContext **bsf, void *logctx) | |
| 59 | +static int av1_read_header(AVFormatContext *s) | |
| 52 | 60 | { |
| 61 | + AV1DemuxContext *const c = s->priv_data; | |
| 53 | 62 | const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge"); |
| 54 | 63 | AVStream *st; |
| 55 | 64 | int ret; |
| 56 | 65 | |
| 57 | 66 | 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 " | |
| 59 | 68 | "not found. This is a bug, please report it.\n"); |
| 60 | 69 | return AVERROR_BUG; |
| 61 | 70 | } |
| @@ -68,35 +77,49 @@ static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon · 6 unmodified lines | ||
| 68 | 77 | st->codecpar->codec_id = AV_CODEC_ID_AV1; |
| 69 | 78 | st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; |
| 70 | 79 | |
| 71 | − st->internal->avctx->framerate = *framerate; | |
| 80 | + st->internal->avctx->framerate = c->framerate; | |
| 72 | 81 | // taken from rawvideo demuxers |
| 73 | 82 | avpriv_set_pts_info(st, 64, 1, 1200000); |
| 74 | 83 | |
| 75 | − ret = av_bsf_alloc(filter, bsf); | |
| 84 | + ret = av_bsf_alloc(filter, &c->bsf); | |
| 76 | 85 | if (ret < 0) |
| 77 | 86 | return ret; |
| 78 | 87 | |
| 79 | − ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar); | |
| 88 | + ret = avcodec_parameters_copy(c->bsf->par_in, st->codecpar); | |
| 80 | 89 | if (ret < 0) |
| 81 | 90 | return ret; |
| 82 | 91 | |
| 83 | − ret = av_bsf_init(*bsf); | |
| 92 | + ret = av_bsf_init(c->bsf); | |
| 84 | 93 | if (ret < 0) |
| 85 | 94 | return ret; |
| 86 | 95 | |
| 87 | 96 | return 0; |
| 88 | 97 | } |
| 89 | 98 | |
| 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 | + | |
| 90 | 107 | #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 | +}; | |
| 91 | 121 | |
| 92 | 122 | #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; | |
| 100 | 123 | |
| 101 | 124 | static int leb(AVIOContext *pb, uint32_t *len) { |
| 102 | 125 | int more, i = 0; |
| @@ -193,15 +216,9 @@ static int annexb_probe(const AVProbeData *p) · 90 unmodified lines | ||
| 193 | 216 | return 0; |
| 194 | 217 | } |
| 195 | 218 | |
| 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 | − | |
| 202 | 219 | static int annexb_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 203 | 220 | { |
| 204 | − AnnexBContext *c = s->priv_data; | |
| 221 | + AV1DemuxContext *const c = s->priv_data; | |
| 205 | 222 | uint32_t obu_unit_size; |
| 206 | 223 | int ret, len; |
| 207 | 224 | |
| @@ -256,50 +273,22 @@ end: · 48 unmodified lines | ||
| 256 | 273 | return ret; |
| 257 | 274 | } |
| 258 | 275 | |
| 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 | − | |
| 281 | 276 | const AVInputFormat ff_av1_demuxer = { |
| 282 | 277 | .name = "av1", |
| 283 | 278 | .long_name = NULL_IF_CONFIG_SMALL("AV1 Annex B"), |
| 284 | − .priv_data_size = sizeof(AnnexBContext), | |
| 279 | + .priv_data_size = sizeof(AV1DemuxContext), | |
| 285 | 280 | .flags_internal = FF_FMT_INIT_CLEANUP, |
| 286 | 281 | .read_probe = annexb_probe, |
| 287 | − .read_header = annexb_read_header, | |
| 282 | + .read_header = av1_read_header, | |
| 288 | 283 | .read_packet = annexb_read_packet, |
| 289 | − .read_close = annexb_read_close, | |
| 284 | + .read_close = av1_read_close, | |
| 290 | 285 | .extensions = "obu", |
| 291 | 286 | .flags = AVFMT_GENERIC_INDEX, |
| 292 | − .priv_class = &annexb_demuxer_class, | |
| 287 | + .priv_class = &av1_demuxer_class, | |
| 293 | 288 | }; |
| 294 | 289 | #endif |
| 295 | 290 | |
| 296 | 291 | #if CONFIG_OBU_DEMUXER |
| 297 | −typedef struct ObuContext { | |
| 298 | − const AVClass *class; | |
| 299 | − AVBSFContext *bsf; | |
| 300 | − AVRational framerate; | |
| 301 | −} ObuContext; | |
| 302 | − | |
| 303 | 292 | //For low overhead obu, we can't foresee the obu size before we parsed the header. |
| 304 | 293 | //So, we can't use parse_obu_header here, since it will check size <= buf_size |
| 305 | 294 | //see c27c7b49dc for more details |
| @@ -367,15 +356,9 @@ static int obu_probe(const AVProbeData *p) · 61 unmodified lines | ||
| 367 | 356 | return 0; |
| 368 | 357 | } |
| 369 | 358 | |
| 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 | − | |
| 376 | 359 | static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) |
| 377 | 360 | { |
| 378 | − ObuContext *c = s->priv_data; | |
| 361 | + AV1DemuxContext *const c = s->priv_data; | |
| 379 | 362 | uint8_t header[MAX_OBU_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; |
| 380 | 363 | int64_t obu_size; |
| 381 | 364 | int size; |
| @@ -404,7 +387,7 @@ static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) · 22 unmodified lines | ||
| 404 | 387 | |
| 405 | 388 | static int obu_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 406 | 389 | { |
| 407 | − ObuContext *c = s->priv_data; | |
| 390 | + AV1DemuxContext *const c = s->priv_data; | |
| 408 | 391 | int ret; |
| 409 | 392 | |
| 410 | 393 | while (1) { |
| @@ -431,39 +414,17 @@ static int obu_read_packet(AVFormatContext *s, AVPacket *pkt) · 20 unmodified lines | ||
| 431 | 414 | return ret; |
| 432 | 415 | } |
| 433 | 416 | |
| 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 | − | |
| 456 | 417 | const AVInputFormat ff_obu_demuxer = { |
| 457 | 418 | .name = "obu", |
| 458 | 419 | .long_name = NULL_IF_CONFIG_SMALL("AV1 low overhead OBU"), |
| 459 | − .priv_data_size = sizeof(ObuContext), | |
| 420 | + .priv_data_size = sizeof(AV1DemuxContext), | |
| 460 | 421 | .flags_internal = FF_FMT_INIT_CLEANUP, |
| 461 | 422 | .read_probe = obu_probe, |
| 462 | − .read_header = obu_read_header, | |
| 423 | + .read_header = av1_read_header, | |
| 463 | 424 | .read_packet = obu_read_packet, |
| 464 | − .read_close = obu_read_close, | |
| 425 | + .read_close = av1_read_close, | |
| 465 | 426 | .extensions = "obu", |
| 466 | 427 | .flags = AVFMT_GENERIC_INDEX, |
| 467 | − .priv_class = &obu_demuxer_class, | |
| 428 | + .priv_class = &av1_demuxer_class, | |
| 468 | 429 | }; |
| 469 | 430 | #endif |