diff options
author | Mark Thompson <sw@jkqxz.net> | 2020-11-23 17:53:57 +0000 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2020-11-24 10:13:55 +0200 |
commit | 7bacf60ae5df75954a538563d19f6001aa598b3f (patch) | |
tree | 427140162bd5a0c14bd1abff745c910524425a73 /libavcodec/cbs.c | |
parent | 01eb05207cbbe44e4c58a15894d49ff81a465a37 (diff) | |
download | ffmpeg-7bacf60ae5df75954a538563d19f6001aa598b3f.tar.gz |
cbs: Add function to read extradata from an AVCodecContext
This is useful in decoders and parsers, matching the way that bitstream
filters read extradata from AVCodecParameters.
Diffstat (limited to 'libavcodec/cbs.c')
-rw-r--r-- | libavcodec/cbs.c | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index c8c526ab12..f98531e131 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -223,66 +223,67 @@ static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, return 0; } -int ff_cbs_read_extradata(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - const AVCodecParameters *par) +static int cbs_read_data(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + AVBufferRef *buf, + const uint8_t *data, size_t size, + int header) { int err; - err = cbs_fill_fragment_data(frag, par->extradata, - par->extradata_size); - if (err < 0) - return err; - - err = ctx->codec->split_fragment(ctx, frag, 1); - if (err < 0) - return err; - - return cbs_read_fragment_content(ctx, frag); -} - -int ff_cbs_read_packet(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - const AVPacket *pkt) -{ - int err; - - if (pkt->buf) { - frag->data_ref = av_buffer_ref(pkt->buf); + if (buf) { + frag->data_ref = av_buffer_ref(buf); if (!frag->data_ref) return AVERROR(ENOMEM); - frag->data = pkt->data; - frag->data_size = pkt->size; + frag->data = (uint8_t *)data; + frag->data_size = size; } else { - err = cbs_fill_fragment_data(frag, pkt->data, pkt->size); + err = cbs_fill_fragment_data(frag, data, size); if (err < 0) return err; } - err = ctx->codec->split_fragment(ctx, frag, 0); + err = ctx->codec->split_fragment(ctx, frag, header); if (err < 0) return err; return cbs_read_fragment_content(ctx, frag); } -int ff_cbs_read(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - const uint8_t *data, size_t size) +int ff_cbs_read_extradata(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + const AVCodecParameters *par) { - int err; + return cbs_read_data(ctx, frag, NULL, + par->extradata, + par->extradata_size, 1); +} - err = cbs_fill_fragment_data(frag, data, size); - if (err < 0) - return err; +int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + const AVCodecContext *avctx) +{ + return cbs_read_data(ctx, frag, NULL, + avctx->extradata, + avctx->extradata_size, 1); +} - err = ctx->codec->split_fragment(ctx, frag, 0); - if (err < 0) - return err; +int ff_cbs_read_packet(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + const AVPacket *pkt) +{ + return cbs_read_data(ctx, frag, pkt->buf, + pkt->data, pkt->size, 0); +} - return cbs_read_fragment_content(ctx, frag); +int ff_cbs_read(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + const uint8_t *data, size_t size) +{ + return cbs_read_data(ctx, frag, NULL, + data, size, 0); } static int cbs_write_unit_data(CodedBitstreamContext *ctx, |