[FFmpeg-cvslog] avcodec/bitstream: Remove outdated comment
ffmpeg | branch: master | Andreas Rheinhardt | Sat Aug 29 18:23:02 2020 +0200| [6fad76b51d24aba31abd35533ee747e6c4df8ec1] | committer: Andreas Rheinhardt avcodec/bitstream: Remove outdated comment The comment referred to the INIT_VLC_USE_STATIC flag which has been removed in 2009 in 595324e143b57a52e2329eb47b84395c70f93087; the function it referred to was removed even earlier in commit 83422c1940d963d395a64bee0cbb9c637192ce8c in 2008. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6fad76b51d24aba31abd35533ee747e6c4df8ec1 --- libavcodec/bitstream.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index d379dbc0e8..95e5092b44 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -266,9 +266,6 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, 'wrap' and 'size' make it possible to use any memory configuration and types (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. - - 'use_static' should be set to 1 for tables, which should be freed - with av_free_static(), 0 if ff_free_vlc() will be used. */ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avdevice/lavfi: Use av_packet_move_ref() for packet ownership transfer
ffmpeg | branch: master | Andreas Rheinhardt | Sun Aug 30 05:45:47 2020 +0200| [e4a650b61ab8b52230ff7fd63823d1a34706d51a] | committer: Andreas Rheinhardt avdevice/lavfi: Use av_packet_move_ref() for packet ownership transfer Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e4a650b61ab8b52230ff7fd63823d1a34706d51a --- libavdevice/lavfi.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index c949ff7e12..2a95cb013c 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -392,10 +392,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) int size = 0; if (lavfi->subcc_packet.size) { -*pkt = lavfi->subcc_packet; -av_init_packet(&lavfi->subcc_packet); -lavfi->subcc_packet.size = 0; -lavfi->subcc_packet.data = NULL; +av_packet_move_ref(pkt, &lavfi->subcc_packet); return pkt->size; } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avdevice/lavfi: Don't set pkt->size to the value it already has
ffmpeg | branch: master | Andreas Rheinhardt | Sun Aug 30 07:32:48 2020 +0200| [901251d59bd287954f334bc153a0d71853debb92] | committer: Andreas Rheinhardt avdevice/lavfi: Don't set pkt->size to the value it already has av_new_packet() already sets the size. And if the packet is not allocated by av_new_packet() (which seems to be impossible atm), both pkt->size as well as size are 0, so setting it again is unnecessary in this scenario, too. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=901251d59bd287954f334bc153a0d71853debb92 --- libavdevice/lavfi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 5e814eada8..72ec1bb9b7 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -474,7 +474,6 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) pkt->stream_index = stream_idx; pkt->pts = frame->pts; pkt->pos = frame->pkt_pos; -pkt->size = size; av_frame_unref(frame); return size; } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avdevice/lavfi: Don't reimplement av_frame_get_side_data()
ffmpeg | branch: master | Andreas Rheinhardt | Sun Aug 30 05:49:46 2020 +0200| [ebd485db926889b5686cab440a6f514d6831209f] | committer: Andreas Rheinhardt avdevice/lavfi: Don't reimplement av_frame_get_side_data() Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ebd485db926889b5686cab440a6f514d6831209f --- libavdevice/lavfi.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 2a95cb013c..5e814eada8 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -362,16 +362,12 @@ static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame, { LavfiContext *lavfi = avctx->priv_data; AVFrameSideData *sd; -int stream_idx, i, ret; +int stream_idx, ret; if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0) return 0; -for (i = 0; i < frame->nb_side_data; i++) -if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC) -break; -if (i >= frame->nb_side_data) +if (!(sd = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC))) return 0; -sd = frame->side_data[i]; if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0) return ret; memcpy(lavfi->subcc_packet.data, sd->data, sd->size); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/wavdec: allow to change max size of single demuxed packet
ffmpeg | branch: master | Paul B Mahol | Fri Aug 28 02:02:41 2020 +0200| [809d6aeffc5d6975156f1a791f5bed25622538ca] | committer: Paul B Mahol avformat/wavdec: allow to change max size of single demuxed packet Can make demuxing much faster, expecially for files with huge number of channels. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=809d6aeffc5d6975156f1a791f5bed25622538ca --- libavformat/wavdec.c | 21 ++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index e1b2115434..4be0ed7b31 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -56,6 +56,7 @@ typedef struct WAVDemuxContext { int smv_eof; int audio_eof; int ignore_length; +int max_size; int spdif; int smv_cur_pt; int smv_given_first; @@ -628,8 +629,6 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16]) return AVERROR_EOF; } -#define MAX_SIZE 4096 - static int wav_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size; @@ -706,7 +705,7 @@ smv_out: wav->data_end = avio_tell(s->pb) + left; } -size = MAX_SIZE; +size = wav->max_size; if (st->codecpar->block_align > 1) { if (size < st->codecpar->block_align) size = st->codecpar->block_align; @@ -759,6 +758,7 @@ static int wav_read_seek(AVFormatContext *s, #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption demux_options[] = { { "ignore_length", "Ignore length", OFFSET(ignore_length), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, DEC }, +{ "max_size", "max size of single packet", OFFSET(max_size), AV_OPT_TYPE_INT, { .i64 = 4096 }, 1024, 1 << 22, DEC }, { NULL }, }; @@ -906,6 +906,20 @@ static int w64_read_header(AVFormatContext *s) return 0; } +#define OFFSET(x) offsetof(WAVDemuxContext, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption w64_demux_options[] = { +{ "max_size", "max size of single packet", OFFSET(max_size), AV_OPT_TYPE_INT, { .i64 = 4096 }, 1024, 1 << 22, DEC }, +{ NULL } +}; + +static const AVClass w64_demuxer_class = { +.class_name = "W64 demuxer", +.item_name = av_default_item_name, +.option = w64_demux_options, +.version= LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_w64_demuxer = { .name = "w64", .long_name = NULL_IF_CONFIG_SMALL("Sony Wave64"), @@ -916,5 +930,6 @@ AVInputFormat ff_w64_demuxer = { .read_seek = wav_read_seek, .flags = AVFMT_GENERIC_INDEX, .codec_tag = (const AVCodecTag * const []) { ff_codec_wav_tags, 0 }, +.priv_class = &w64_demuxer_class, }; #endif /* CONFIG_W64_DEMUXER */ ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/wavdec: add support for demuxing Broadcast Wave 64Bit
ffmpeg | branch: master | Paul B Mahol | Fri Aug 28 00:34:06 2020 +0200| [93aa0bec84c54cf3135e0023c3c8c223bbf66f08] | committer: Paul B Mahol avformat/wavdec: add support for demuxing Broadcast Wave 64Bit > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=93aa0bec84c54cf3135e0023c3c8c223bbf66f08 --- libavformat/wavdec.c | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index c35966f970..e1b2115434 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -6,6 +6,8 @@ * RF64 demuxer * Copyright (c) 2009 Daniel Verkamp * + * BW64 demuxer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -140,7 +142,8 @@ static int wav_probe(const AVProbeData *p) * its own, the returned score is decreased to avoid a probe * conflict between ACT and WAV. */ return AVPROBE_SCORE_MAX - 1; -else if (!memcmp(p->buf, "RF64", 4) && +else if ((!memcmp(p->buf, "RF64", 4) || + !memcmp(p->buf, "BW64", 4)) && !memcmp(p->buf + 12, "ds64", 4)) return AVPROBE_SCORE_MAX; } @@ -330,7 +333,7 @@ static int wav_read_header(AVFormatContext *s) { int64_t size, av_uninit(data_size); int64_t sample_count = 0; -int rf64 = 0; +int rf64 = 0, bw64 = 0; uint32_t tag; AVIOContext *pb = s->pb; AVStream *st = NULL; @@ -353,6 +356,9 @@ static int wav_read_header(AVFormatContext *s) case MKTAG('R', 'F', '6', '4'): rf64 = 1; break; +case MKTAG('B', 'W', '6', '4'): +bw64 = 1; +break; default: av_log(s, AV_LOG_ERROR, "invalid start code %s in RIFF header\n", av_fourcc2str(tag)); @@ -368,7 +374,7 @@ static int wav_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } -if (rf64) { +if (rf64 || bw64) { if (avio_rl32(pb) != MKTAG('d', 's', '6', '4')) return AVERROR_INVALIDDATA; size = avio_rl32(pb); @@ -423,7 +429,7 @@ static int wav_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } -if (rf64) { +if (rf64 || bw64) { next_tag_ofs = wav->data_end = avio_tell(pb) + data_size; } else if (size != 0x) { data_size= size; @@ -440,7 +446,7 @@ static int wav_read_header(AVFormatContext *s) /* don't look for footer metadata if we can't seek or if we don't * know where the data tag ends */ -if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || (!rf64 && !size)) +if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || (!(rf64 && !bw64) && !size)) goto break_loop; break; case MKTAG('f', 'a', 'c', 't'): ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Avoid copying values around pointlessly
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 18:55:19 2020 +0200| [d0b0fc7cb94f02a7de0d67cb3ba06a243b323a1d] | committer: Andreas Rheinhardt avcodec/magicyuv: Avoid copying values around pointlessly When parsing Huffman tables, an array of HuffEntries (a struct containing a code's bitlength, its bits and its symbol) is used as intermediate tables in order to sort the entries (the order depends on both the length of the entries as well as on their symbols). After sorting them, the symbol and len components are copied into other arrays (the HuffEntries' code has never been set or used, despite using quite a lot of stack space) and the codes are generated. Afterwards, the VLC is created. Yet ff_init_vlc_sparse() can handle non-continuous arrays as input; there is no need to copy the entries at all. This commit implements this. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d0b0fc7cb94f02a7de0d67cb3ba06a243b323a1d --- libavcodec/magicyuv.c | 39 --- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 32d744add2..f630464162 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -97,9 +97,6 @@ static int huff_cmp_len12(const void *a, const void *b) static int huff_build10(VLC *vlc, uint8_t *len) { HuffEntry he[1024]; -uint32_t codes[1024]; -uint8_t bits[1024]; -uint16_t syms[1024]; uint32_t code; int i; @@ -113,25 +110,20 @@ static int huff_build10(VLC *vlc, uint8_t *len) code = 1; for (i = 1023; i >= 0; i--) { -codes[i] = code >> (32 - he[i].len); -bits[i] = he[i].len; -syms[i] = he[i].sym; +he[i].code = code >> (32 - he[i].len); code += 0x8000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[1023].len, 12), 1024, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static int huff_build12(VLC *vlc, uint8_t *len) { HuffEntry he[4096]; -uint32_t codes[4096]; -uint8_t bits[4096]; -uint16_t syms[4096]; uint32_t code; int i; @@ -145,25 +137,20 @@ static int huff_build12(VLC *vlc, uint8_t *len) code = 1; for (i = 4095; i >= 0; i--) { -codes[i] = code >> (32 - he[i].len); -bits[i] = he[i].len; -syms[i] = he[i].sym; +he[i].code = code >> (32 - he[i].len); code += 0x8000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[4095].len, 12), 4096, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static int huff_build(VLC *vlc, uint8_t *len) { HuffEntry he[256]; -uint32_t codes[256]; -uint8_t bits[256]; -uint8_t syms[256]; uint32_t code; int i; @@ -177,17 +164,15 @@ static int huff_build(VLC *vlc, uint8_t *len) code = 1; for (i = 255; i >= 0; i--) { -codes[i] = code >> (32 - he[i].len); -bits[i] = he[i].len; -syms[i] = he[i].sym; +he[i].code = code >> (32 - he[i].len); code += 0x8000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[255].len, 12), 256, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Don't invert Huffman table symbols twice
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 20:30:34 2020 +0200| [7332a23b848555780f3d24370c8314dd9f348a35] | committer: Andreas Rheinhardt avcodec/magicyuv: Don't invert Huffman table symbols twice When the MagicYUV decoder builds Huffman tables from an array of code lengths, it proceeds as follows: First it copies the entries of the array of lengths into an array of HuffEntries (a struct which contains a length and a symbol field); it also sets the symbol field in descending order from nb_elem - 1 to 0, where nb_elem is the common number of elements of the length and HuffEntry arrays. Then the HuffEntry array is sorted lexicographically: a > b iff a.len > b.len or a.len == b.len and a.sym > b.sym. Afterwards the symbols of the so sorted array are inverted again (i.e. each symbol sym is replaced by nb_elem - sym). Yet inverting can easily be avoided altogether: Just modify the order so that smaller symbols correspond to bigger HuffEntries. This leads to the same permutation as the current code does and given that the two inversions just cancel each other out, the result is the same. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7332a23b848555780f3d24370c8314dd9f348a35 --- libavcodec/magicyuv.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index a255f82d9c..32d744add2 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -79,19 +79,19 @@ typedef struct MagicYUVContext { static int huff_cmp_len(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; -return (aa->len - bb->len) * 256 + aa->sym - bb->sym; +return (aa->len - bb->len) * 256 + bb->sym - aa->sym; } static int huff_cmp_len10(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; -return (aa->len - bb->len) * 1024 + aa->sym - bb->sym; +return (aa->len - bb->len) * 1024 + bb->sym - aa->sym; } static int huff_cmp_len12(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; -return (aa->len - bb->len) * 4096 + aa->sym - bb->sym; +return (aa->len - bb->len) * 4096 + bb->sym - aa->sym; } static int huff_build10(VLC *vlc, uint8_t *len) @@ -104,7 +104,7 @@ static int huff_build10(VLC *vlc, uint8_t *len) int i; for (i = 0; i < 1024; i++) { -he[i].sym = 1023 - i; +he[i].sym = i; he[i].len = len[i]; if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; @@ -115,7 +115,7 @@ static int huff_build10(VLC *vlc, uint8_t *len) for (i = 1023; i >= 0; i--) { codes[i] = code >> (32 - he[i].len); bits[i] = he[i].len; -syms[i] = 1023 - he[i].sym; +syms[i] = he[i].sym; code += 0x8000u >> (he[i].len - 1); } @@ -136,7 +136,7 @@ static int huff_build12(VLC *vlc, uint8_t *len) int i; for (i = 0; i < 4096; i++) { -he[i].sym = 4095 - i; +he[i].sym = i; he[i].len = len[i]; if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; @@ -147,7 +147,7 @@ static int huff_build12(VLC *vlc, uint8_t *len) for (i = 4095; i >= 0; i--) { codes[i] = code >> (32 - he[i].len); bits[i] = he[i].len; -syms[i] = 4095 - he[i].sym; +syms[i] = he[i].sym; code += 0x8000u >> (he[i].len - 1); } @@ -168,7 +168,7 @@ static int huff_build(VLC *vlc, uint8_t *len) int i; for (i = 0; i < 256; i++) { -he[i].sym = 255 - i; +he[i].sym = i; he[i].len = len[i]; if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; @@ -179,7 +179,7 @@ static int huff_build(VLC *vlc, uint8_t *len) for (i = 255; i >= 0; i--) { codes[i] = code >> (32 - he[i].len); bits[i] = he[i].len; -syms[i] = 255 - he[i].sym; +syms[i] = he[i].sym; code += 0x8000u >> (he[i].len - 1); } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Avoid intermediate array when parsing Huffman tables
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 21:14:54 2020 +0200| [a13a23bdf2049d7ae439a5ee73cfdd1e223c32d8] | committer: Andreas Rheinhardt avcodec/magicyuv: Avoid intermediate array when parsing Huffman tables Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a13a23bdf2049d7ae439a5ee73cfdd1e223c32d8 --- libavcodec/magicyuv.c | 21 - 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index d2656427b9..eed5ad1b40 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -68,7 +68,6 @@ typedef struct MagicYUVContext { int vshift[4]; Slice*slices[4]; // slice bitstream positions for each plane unsigned int slices_size[4]; // slice sizes for each plane -uint8_t len[4096]; // scratch table of code lengths VLC vlc[4]; // VLC for each plane int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata, int j, int threadnr); @@ -81,18 +80,11 @@ static int huff_cmp_len(const void *a, const void *b) return (aa->len - bb->len) * 4096 + bb->sym - aa->sym; } -static int huff_build(VLC *vlc, uint8_t *len, int nb_elems) +static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems) { -HuffEntry he[4096]; uint32_t code; int i; -for (i = 0; i < nb_elems; i++) { -he[i].sym = i; -he[i].len = len[i]; -if (len[i] == 0 || len[i] > 32) -return AVERROR_INVALIDDATA; -} AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); code = 1; @@ -396,6 +388,7 @@ static int magy_decode_slice(AVCodecContext *avctx, void *tdata, static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) { MagicYUVContext *s = avctx->priv_data; +HuffEntry he[4096]; int i = 0, j = 0, k; while (get_bits_left(gbit) >= 8) { @@ -404,17 +397,19 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) int l = get_bitsz(gbit, b * 8) + 1; k = j + l; -if (k > max) { +if (k > max || x == 0 || x > 32) { av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n"); return AVERROR_INVALIDDATA; } -for (; j < k; j++) -s->len[j] = x; +for (; j < k; j++) { +he[j].sym = j; +he[j].len = x; +} if (j == max) { j = 0; -if (huff_build(&s->vlc[i], s->len, max)) { +if (huff_build(he, &s->vlc[i], max)) { av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Don't zero unnecessarily
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 19:51:03 2020 +0200| [7f452c099a47eb54131f4a36e6078471e24c39b4] | committer: Andreas Rheinhardt avcodec/magicyuv: Don't zero unnecessarily The code already checks that exactly the expected amount of entries are read and set. Ergo it is unnecessary to zero them at the beginning. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7f452c099a47eb54131f4a36e6078471e24c39b4 --- libavcodec/magicyuv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index f2204f3401..9282b39723 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -453,7 +453,6 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) MagicYUVContext *s = avctx->priv_data; int i = 0, j = 0, k; -memset(s->len, 0, sizeof(s->len)); while (get_bits_left(gbit) >= 8) { int b = get_bits(gbit, 1); int x = get_bits(gbit, 7); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Reuse array instead of using multiple arrays
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 19:55:28 2020 +0200| [aae499f77a1d9f9083486fc7d98baf63e0ab917f] | committer: Andreas Rheinhardt avcodec/magicyuv: Reuse array instead of using multiple arrays The lengths of the VLC codes are implicitly contained in the VLC tables itself; apart from that they are not used lateron. So it is unnecessary to store them and the very same array can be reused to parse the Huffman table for the next plane. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aae499f77a1d9f9083486fc7d98baf63e0ab917f --- libavcodec/magicyuv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 9282b39723..a16135e683 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -68,7 +68,7 @@ typedef struct MagicYUVContext { int vshift[4]; Slice*slices[4]; // slice bitstream positions for each plane unsigned int slices_size[4]; // slice sizes for each plane -uint8_t len[4][4096]; // table of code lengths for each plane +uint8_t len[4096]; // scratch table of code lengths VLC vlc[4]; // VLC for each plane int (*huff_build)(VLC *vlc, uint8_t *len); int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata, @@ -465,11 +465,11 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) } for (; j < k; j++) -s->len[i][j] = x; +s->len[j] = x; if (j == max) { j = 0; -if (s->huff_build(&s->vlc[i], s->len[i])) { +if (s->huff_build(&s->vlc[i], s->len)) { av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Simplify check for invalid Huffman codes
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 19:47:50 2020 +0200| [e8716b7e4c600577f43bd8519dfb30b214830fde] | committer: Andreas Rheinhardt avcodec/magicyuv: Simplify check for invalid Huffman codes Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e8716b7e4c600577f43bd8519dfb30b214830fde --- libavcodec/magicyuv.c | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 5578374429..f2204f3401 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -459,11 +459,15 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) int x = get_bits(gbit, 7); int l = get_bitsz(gbit, b * 8) + 1; -for (k = 0; k < l; k++) -if (j + k < max) -s->len[i][j + k] = x; +k = j + l; +if (k > max) { +av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n"); +return AVERROR_INVALIDDATA; +} + +for (; j < k; j++) +s->len[i][j] = x; -j += l; if (j == max) { j = 0; if (s->huff_build(&s->vlc[i], s->len[i])) { @@ -474,9 +478,6 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) if (i == s->planes) { break; } -} else if (j > max) { -av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n"); -return AVERROR_INVALIDDATA; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Unify qsort comparison functions
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 19:18:03 2020 +0200| [18dbbff525dd03ed4faefadbe08f5916b9e23666] | committer: Andreas Rheinhardt avcodec/magicyuv: Unify qsort comparison functions Up until now, there were three comparison functions depending upon bitness. But they all are actually the same, namely a lexical ordering: entry a > entry b iff a.len > b.len or a.len == b.len and a.sym < b.sym. So they can be easily unified. Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=18dbbff525dd03ed4faefadbe08f5916b9e23666 --- libavcodec/magicyuv.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index f630464162..5578374429 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -77,18 +77,6 @@ typedef struct MagicYUVContext { } MagicYUVContext; static int huff_cmp_len(const void *a, const void *b) -{ -const HuffEntry *aa = a, *bb = b; -return (aa->len - bb->len) * 256 + bb->sym - aa->sym; -} - -static int huff_cmp_len10(const void *a, const void *b) -{ -const HuffEntry *aa = a, *bb = b; -return (aa->len - bb->len) * 1024 + bb->sym - aa->sym; -} - -static int huff_cmp_len12(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; return (aa->len - bb->len) * 4096 + bb->sym - aa->sym; @@ -106,7 +94,7 @@ static int huff_build10(VLC *vlc, uint8_t *len) if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; } -AV_QSORT(he, 1024, HuffEntry, huff_cmp_len10); +AV_QSORT(he, 1024, HuffEntry, huff_cmp_len); code = 1; for (i = 1023; i >= 0; i--) { @@ -133,7 +121,7 @@ static int huff_build12(VLC *vlc, uint8_t *len) if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; } -AV_QSORT(he, 4096, HuffEntry, huff_cmp_len12); +AV_QSORT(he, 4096, HuffEntry, huff_cmp_len); code = 1; for (i = 4095; i >= 0; i--) { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/magicyuv: Unify creating Huffman tables
ffmpeg | branch: master | Andreas Rheinhardt | Mon Aug 31 20:49:13 2020 +0200| [61499c6456387101e2103e475434752a441c3072] | committer: Andreas Rheinhardt avcodec/magicyuv: Unify creating Huffman tables Reviewed-by: Paul B Mahol Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=61499c6456387101e2103e475434752a441c3072 --- libavcodec/magicyuv.c | 71 +-- 1 file changed, 6 insertions(+), 65 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index a16135e683..d2656427b9 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -70,7 +70,6 @@ typedef struct MagicYUVContext { unsigned int slices_size[4]; // slice sizes for each plane uint8_t len[4096]; // scratch table of code lengths VLC vlc[4]; // VLC for each plane -int (*huff_build)(VLC *vlc, uint8_t *len); int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata, int j, int threadnr); LLVidDSPContext llviddsp; @@ -82,82 +81,28 @@ static int huff_cmp_len(const void *a, const void *b) return (aa->len - bb->len) * 4096 + bb->sym - aa->sym; } -static int huff_build10(VLC *vlc, uint8_t *len) -{ -HuffEntry he[1024]; -uint32_t code; -int i; - -for (i = 0; i < 1024; i++) { -he[i].sym = i; -he[i].len = len[i]; -if (len[i] == 0 || len[i] > 32) -return AVERROR_INVALIDDATA; -} -AV_QSORT(he, 1024, HuffEntry, huff_cmp_len); - -code = 1; -for (i = 1023; i >= 0; i--) { -he[i].code = code >> (32 - he[i].len); -code += 0x8000u >> (he[i].len - 1); -} - -ff_free_vlc(vlc); -return ff_init_vlc_sparse(vlc, FFMIN(he[1023].len, 12), 1024, - &he[0].len, sizeof(he[0]), sizeof(he[0].len), - &he[0].code, sizeof(he[0]), sizeof(he[0].code), - &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); -} - -static int huff_build12(VLC *vlc, uint8_t *len) +static int huff_build(VLC *vlc, uint8_t *len, int nb_elems) { HuffEntry he[4096]; uint32_t code; int i; -for (i = 0; i < 4096; i++) { -he[i].sym = i; -he[i].len = len[i]; -if (len[i] == 0 || len[i] > 32) -return AVERROR_INVALIDDATA; -} -AV_QSORT(he, 4096, HuffEntry, huff_cmp_len); - -code = 1; -for (i = 4095; i >= 0; i--) { -he[i].code = code >> (32 - he[i].len); -code += 0x8000u >> (he[i].len - 1); -} - -ff_free_vlc(vlc); -return ff_init_vlc_sparse(vlc, FFMIN(he[4095].len, 12), 4096, - &he[0].len, sizeof(he[0]), sizeof(he[0].len), - &he[0].code, sizeof(he[0]), sizeof(he[0].code), - &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); -} - -static int huff_build(VLC *vlc, uint8_t *len) -{ -HuffEntry he[256]; -uint32_t code; -int i; - -for (i = 0; i < 256; i++) { +for (i = 0; i < nb_elems; i++) { he[i].sym = i; he[i].len = len[i]; if (len[i] == 0 || len[i] > 32) return AVERROR_INVALIDDATA; } -AV_QSORT(he, 256, HuffEntry, huff_cmp_len); +AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); code = 1; -for (i = 255; i >= 0; i--) { +for (i = nb_elems - 1; i >= 0; i--) { he[i].code = code >> (32 - he[i].len); code += 0x8000u >> (he[i].len - 1); } ff_free_vlc(vlc); -return ff_init_vlc_sparse(vlc, FFMIN(he[255].len, 12), 256, +return ff_init_vlc_sparse(vlc, FFMIN(he[nb_elems - 1].len, 12), nb_elems, &he[0].len, sizeof(he[0]), sizeof(he[0].len), &he[0].code, sizeof(he[0]), sizeof(he[0].code), &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); @@ -469,7 +414,7 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) if (j == max) { j = 0; -if (s->huff_build(&s->vlc[i], s->len)) { +if (huff_build(&s->vlc[i], s->len, max)) { av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } @@ -595,10 +540,6 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, } s->max = 1 << s->bps; s->magy_decode_slice = s->bps == 8 ? magy_decode_slice : magy_decode_slice10; -if ( s->bps == 8) -s->huff_build = huff_build; -else -s->huff_build = s->bps == 10 ? huff_build10 : huff_build12; s->planes = av_pix_fmt_count_planes(avctx->pix_fmt); bytestream2_skip(&gbyte, 1); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscri
[FFmpeg-cvslog] avcodec/qpeg: speed-up copy of bytes
ffmpeg | branch: master | Paul B Mahol | Mon Aug 31 23:25:22 2020 +0200| [97c73ba56505e180f6ab8f49b7b5642e0c09fa09] | committer: Paul B Mahol avcodec/qpeg: speed-up copy of bytes > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=97c73ba56505e180f6ab8f49b7b5642e0c09fa09 --- libavcodec/qpeg.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c index 40931e3bdc..8bc710acfd 100644 --- a/libavcodec/qpeg.c +++ b/libavcodec/qpeg.c @@ -101,8 +101,11 @@ static void qpeg_decode_intra(QpegContext *qctx, uint8_t *dst, } else { if (bytestream2_get_bytes_left(&qctx->buffer) < copy) copy = bytestream2_get_bytes_left(&qctx->buffer); -for(i = 0; i < copy; i++) { -dst[filled++] = bytestream2_get_byte(&qctx->buffer); +while (copy > 0) { +int step = FFMIN(copy, width - filled); +bytestream2_get_bufferu(&qctx->buffer, dst + filled, step); +filled += step; +copy -= step; if (filled >= width) { filled = 0; dst -= stride; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/wavdec: add support for chapters
ffmpeg | branch: master | Paul B Mahol | Mon Aug 31 14:18:37 2020 +0200| [2a14d55a7c41ba8665cfd17b82d96e669ecd0e4c] | committer: Paul B Mahol avformat/wavdec: add support for chapters Support parsing 'cue ' and 'adtl' chunks. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2a14d55a7c41ba8665cfd17b82d96e669ecd0e4c --- libavformat/wavdec.c | 46 ++ 1 file changed, 46 insertions(+) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 4be0ed7b31..d6ab0dde35 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -500,6 +500,7 @@ static int wav_read_header(AVFormatContext *s) wav->smv_cur_pt = 0; goto break_loop; case MKTAG('L', 'I', 'S', 'T'): +case MKTAG('l', 'i', 's', 't'): if (size < 4) { av_log(s, AV_LOG_ERROR, "too short LIST tag\n"); return AVERROR_INVALIDDATA; @@ -507,6 +508,33 @@ static int wav_read_header(AVFormatContext *s) switch (avio_rl32(pb)) { case MKTAG('I', 'N', 'F', 'O'): ff_read_riff_info(s, size - 4); +break; +case MKTAG('a', 'd', 't', 'l'): +if (s->nb_chapters > 0) { +while (avio_tell(pb) < next_tag_ofs && + !avio_feof(pb)) { +char cue_label[512]; +unsigned id, sub_size; + +if (avio_rl32(pb) != MKTAG('l', 'a', 'b', 'l')) +break; + +sub_size = avio_rl32(pb); +if (sub_size < 5) +break; +id = avio_rl32(pb); +avio_get_str(pb, sub_size - 4, cue_label, sizeof(cue_label)); +avio_skip(pb, avio_tell(pb) & 1); + +for (int i = 0; i < s->nb_chapters; i++) { +if (s->chapters[i]->id == id) { +av_dict_set(&s->chapters[i]->metadata, "title", cue_label, 0); +break; +} +} +} +} +break; } break; case MKTAG('I', 'D', '3', ' '): @@ -521,6 +549,24 @@ static int wav_read_header(AVFormatContext *s) ff_id3v2_free_extra_meta(&id3v2_extra_meta); } break; +case MKTAG('c', 'u', 'e', ' '): +if (size >= 4 && got_fmt && st->codecpar->sample_rate > 0) { +AVRational tb = {1, st->codecpar->sample_rate}; +unsigned nb_cues = avio_rl32(pb); + +if (size >= nb_cues * 24LL + 4LL) { +for (int i = 0; i < nb_cues; i++) { +unsigned offset, id = avio_rl32(pb); + +avio_skip(pb, 16); +offset = avio_rl32(pb); + +if (!avpriv_new_chapter(s, id, tb, offset, AV_NOPTS_VALUE, NULL)) +return AVERROR(ENOMEM); +} +} +} +break; } /* seek to next tag unless we know that we'll run into EOF */ ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avcodec/encode: unref the packet on AVCodec.receive_packet() failure
ffmpeg | branch: master | James Almer | Sun Aug 30 23:57:23 2020 -0300| [0271098e6c9ff8f2a97d65087e424f6d547e53f9] | committer: James Almer avcodec/encode: unref the packet on AVCodec.receive_packet() failure Fixes memleaks with some encoders that don't unref the packet before returning. This is consistent with the behavior of AVCodec.encode() implementations in encode_simple_internal(). Found-by: mkver Reviewed-by: Anton Khirnov Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0271098e6c9ff8f2a97d65087e424f6d547e53f9 --- libavcodec/encode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 8bc10c4abb..2e540baf37 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -242,7 +242,9 @@ static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt if (avctx->codec->receive_packet) { ret = avctx->codec->receive_packet(avctx, avpkt); -if (!ret) +if (ret < 0) +av_packet_unref(avpkt); +else // Encoders must always return ref-counted buffers. // Side-data only packets have no data and can be not ref-counted. av_assert0(!avpkt->data || avpkt->buf); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_av1: Fill tile width/height values when uniform_tile_spacing_flag is set
ffmpeg | branch: master | Mark Thompson | Mon Aug 31 22:00:57 2020 +0100| [2a19232c1996fee52a3f4201fa379001627dcc89] | committer: Mark Thompson cbs_av1: Fill tile width/height values when uniform_tile_spacing_flag is set They are not explicitly in the bitstream in this case, but it is helpful to be able to use these values without always needing to check the flag beforehand. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2a19232c1996fee52a3f4201fa379001627dcc89 --- libavcodec/cbs_av1_syntax_template.c | 9 + 1 file changed, 9 insertions(+) diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c index 19b82bc3f8..2d2e240e3e 100644 --- a/libavcodec/cbs_av1_syntax_template.c +++ b/libavcodec/cbs_av1_syntax_template.c @@ -636,6 +636,15 @@ static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw, current->tile_rows_log2; current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb; +for (i = 0; i < current->tile_cols - 1; i++) +infer(width_in_sbs_minus_1[i], tile_width_sb - 1); +infer(width_in_sbs_minus_1[i], + sb_cols - (current->tile_cols - 1) * tile_width_sb - 1); +for (i = 0; i < current->tile_rows - 1; i++) +infer(height_in_sbs_minus_1[i], tile_height_sb - 1); +infer(height_in_sbs_minus_1[i], + sb_rows - (current->tile_rows - 1) * tile_height_sb - 1); + } else { int widest_tile_sb, start_sb, size_sb, max_width, max_height; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs: Describe allocate/free methods in tabular form
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:18 2020 +0100| [bc7a7e0d65bd72b317b2c4b84fac505ba3db7556] | committer: Mark Thompson cbs: Describe allocate/free methods in tabular form Unit types are split into three categories, depending on how their content is managed: * POD structure - these require no special treatment. * Structure containing references to refcounted buffers - these can use a common free function when the offsets of all the internal references are known. * More complex structures - these still require ad-hoc treatment. For each codec we can then maintain a table of descriptors for each set of equivalent unit types, defining the mechanism needed to allocate/free that unit content. This is not required to be used immediately - a new alloc function supports this, but does not replace the old one which works without referring to these tables. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bc7a7e0d65bd72b317b2c4b84fac505ba3db7556 --- libavcodec/cbs.c | 69 +++ libavcodec/cbs.h | 9 +++ libavcodec/cbs_internal.h | 61 + 3 files changed, 139 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 6464980c8e..61cf8e3466 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -802,3 +802,72 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, frag->units + position + 1, (frag->nb_units - position) * sizeof(*frag->units)); } + +static void cbs_default_free_unit_content(void *opaque, uint8_t *data) +{ +const CodedBitstreamUnitTypeDescriptor *desc = opaque; +if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) { +int i; +for (i = 0; i < desc->nb_ref_offsets; i++) { +void **ptr = (void**)(data + desc->ref_offsets[i]); +av_buffer_unref((AVBufferRef**)(ptr + 1)); +} +} +av_free(data); +} + +static const CodedBitstreamUnitTypeDescriptor +*cbs_find_unit_type_desc(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ +const CodedBitstreamUnitTypeDescriptor *desc; +int i, j; + +if (!ctx->codec->unit_types) +return NULL; + +for (i = 0;; i++) { +desc = &ctx->codec->unit_types[i]; +if (desc->nb_unit_types == 0) +break; +if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) { +if (unit->type >= desc->unit_type_range_start && +unit->type <= desc->unit_type_range_end) +return desc; +} else { +for (j = 0; j < desc->nb_unit_types; j++) { +if (desc->unit_types[j] == unit->type) +return desc; +} +} +} +return NULL; +} + +int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ +const CodedBitstreamUnitTypeDescriptor *desc; + +av_assert0(!unit->content && !unit->content_ref); + +desc = cbs_find_unit_type_desc(ctx, unit); +if (!desc) +return AVERROR(ENOSYS); + +unit->content = av_mallocz(desc->content_size); +if (!unit->content) +return AVERROR(ENOMEM); + +unit->content_ref = +av_buffer_create(unit->content, desc->content_size, + desc->content_free ? desc->content_free +: cbs_default_free_unit_content, + (void*)desc, 0); +if (!unit->content_ref) { +av_freep(&unit->content); +return AVERROR(ENOMEM); +} + +return 0; +} diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 07faf18c5b..ea8d942894 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -349,6 +349,15 @@ int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit, size_t size, void (*free)(void *opaque, uint8_t *content)); +/** + * Allocate a new internal content buffer matching the type of the unit. + * + * The content will be zeroed. + */ +int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit); + + /** * Allocate a new internal data buffer of the given size in the unit. * diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 4c5a535ca6..282492bc88 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -25,11 +25,72 @@ #include "put_bits.h" +enum CBSContentType { +// Unit content is a simple structure. +CBS_CONTENT_TYPE_POD, +// Unit content contains some references to other structures, but all +// managed via buffer reference counting. The descriptor defines the +// structure offsets of every buffer reference. +CBS_CONTENT_TYPE_INTERNAL_REFS, +// Unit content is something more complex. The descriptor defines +// special functions to manage the co
[FFmpeg-cvslog] cbs: Add macros to support defining unit type tables
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:19 2020 +0100| [225f2878853e1e4980d55707c68a14595a639ad3] | committer: Mark Thompson cbs: Add macros to support defining unit type tables > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=225f2878853e1e4980d55707c68a14595a639ad3 --- libavcodec/cbs_internal.h | 24 1 file changed, 24 insertions(+) diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 282492bc88..35159f9c5f 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -167,6 +167,30 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1))) +#define CBS_UNIT_TYPE_POD(type, structure) { \ +.nb_unit_types = 1, \ +.unit_types = { type }, \ +.content_type = CBS_CONTENT_TYPE_POD, \ +.content_size = sizeof(structure), \ +} +#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \ +.nb_unit_types = 1, \ +.unit_types = { type }, \ +.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \ +.content_size = sizeof(structure), \ +.nb_ref_offsets = 1, \ +.ref_offsets= { offsetof(structure, ref_field) }, \ +} +#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \ +.nb_unit_types = 1, \ +.unit_types = { type }, \ +.content_type = CBS_CONTENT_TYPE_COMPLEX, \ +.content_size = sizeof(structure), \ +.content_free = free_func, \ +} +#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 } + + extern const CodedBitstreamType ff_cbs_type_av1; extern const CodedBitstreamType ff_cbs_type_h264; extern const CodedBitstreamType ff_cbs_type_h265; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_h265: Use table-based alloc/free
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:24 2020 +0100| [e38646de1cef80ebf451402ddaf15941f2b60522] | committer: Mark Thompson cbs_h265: Use table-based alloc/free > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e38646de1cef80ebf451402ddaf15941f2b60522 --- libavcodec/cbs_h2645.c | 198 +++-- 1 file changed, 93 insertions(+), 105 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e19fa5249d..b9233f4df7 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -454,72 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #undef allocate -static void cbs_h265_free_vps(void *opaque, uint8_t *content) -{ -H265RawVPS *vps = (H265RawVPS*)content; -av_buffer_unref(&vps->extension_data.data_ref); -av_freep(&content); -} - -static void cbs_h265_free_sps(void *opaque, uint8_t *content) -{ -H265RawSPS *sps = (H265RawSPS*)content; -av_buffer_unref(&sps->extension_data.data_ref); -av_freep(&content); -} - -static void cbs_h265_free_pps(void *opaque, uint8_t *content) -{ -H265RawPPS *pps = (H265RawPPS*)content; -av_buffer_unref(&pps->extension_data.data_ref); -av_freep(&content); -} - -static void cbs_h265_free_slice(void *opaque, uint8_t *content) -{ -H265RawSlice *slice = (H265RawSlice*)content; -av_buffer_unref(&slice->data_ref); -av_freep(&content); -} - -static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload) -{ -switch (payload->payload_type) { -case HEVC_SEI_TYPE_BUFFERING_PERIOD: -case HEVC_SEI_TYPE_PICTURE_TIMING: -case HEVC_SEI_TYPE_PAN_SCAN_RECT: -case HEVC_SEI_TYPE_RECOVERY_POINT: -case HEVC_SEI_TYPE_DISPLAY_ORIENTATION: -case HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS: -case HEVC_SEI_TYPE_DECODED_PICTURE_HASH: -case HEVC_SEI_TYPE_TIME_CODE: -case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO: -case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: -case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: -case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO: -break; -case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: -av_buffer_unref(&payload->payload.user_data_registered.data_ref); -break; -case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED: -av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); -break; -default: -av_buffer_unref(&payload->payload.other.data_ref); -break; -} -av_buffer_unref(&payload->extension_data.data_ref); -} - -static void cbs_h265_free_sei(void *opaque, uint8_t *content) -{ -H265RawSEI *sei = (H265RawSEI*)content; -int i; -for (i = 0; i < sei->payload_count; i++) -cbs_h265_free_sei_payload(&sei->payload[i]); -av_freep(&content); -} - static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet) @@ -877,16 +811,14 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, if (err < 0) return err; +err = ff_cbs_alloc_unit_content2(ctx, unit); +if (err < 0) +return err; + switch (unit->type) { case HEVC_NAL_VPS: { -H265RawVPS *vps; - -err = ff_cbs_alloc_unit_content(unit, sizeof(*vps), -&cbs_h265_free_vps); -if (err < 0) -return err; -vps = unit->content; +H265RawVPS *vps = unit->content; err = cbs_h265_read_vps(ctx, &gbc, vps); if (err < 0) @@ -899,13 +831,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, break; case HEVC_NAL_SPS: { -H265RawSPS *sps; - -err = ff_cbs_alloc_unit_content(unit, sizeof(*sps), -&cbs_h265_free_sps); -if (err < 0) -return err; -sps = unit->content; +H265RawSPS *sps = unit->content; err = cbs_h265_read_sps(ctx, &gbc, sps); if (err < 0) @@ -919,13 +845,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_PPS: { -H265RawPPS *pps; - -err = ff_cbs_alloc_unit_content(unit, sizeof(*pps), -&cbs_h265_free_pps); -if (err < 0) -return err; -pps = unit->content; +H265RawPPS *pps = unit->content; err = cbs_h265_read_pps(ctx, &gbc, pps); if (err < 0) @@ -954,15 +874,9 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_IDR_N_LP: case HEVC_NAL_CRA_NUT: { -H265RawSlice *slice; +H265RawSlice *slice = unit->content; int pos, len; -err = ff_cbs_alloc_unit_
[FFmpeg-cvslog] cbs_mpeg2: Use table-based alloc/free
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:27 2020 +0100| [cf6af829c2db8a8c55f49526f73e37b9da772c30] | committer: Mark Thompson cbs_mpeg2: Use table-based alloc/free > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf6af829c2db8a8c55f49526f73e37b9da772c30 --- libavcodec/cbs_mpeg2.c | 70 +- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 8b6e5a9852..26400f279f 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -140,28 +140,6 @@ #undef infer -static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content) -{ -MPEG2RawPictureHeader *picture = (MPEG2RawPictureHeader*)content; -av_buffer_unref(&picture->extra_information_picture.extra_information_ref); -av_freep(&content); -} - -static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content) -{ -MPEG2RawUserData *user = (MPEG2RawUserData*)content; -av_buffer_unref(&user->user_data_ref); -av_freep(&content); -} - -static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content) -{ -MPEG2RawSlice *slice = (MPEG2RawSlice*)content; - av_buffer_unref(&slice->header.extra_information_slice.extra_information_ref); -av_buffer_unref(&slice->data_ref); -av_freep(&content); -} - static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) @@ -231,16 +209,14 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; +err = ff_cbs_alloc_unit_content2(ctx, unit); +if (err < 0) +return err; + if (MPEG2_START_IS_SLICE(unit->type)) { -MPEG2RawSlice *slice; +MPEG2RawSlice *slice = unit->content; int pos, len; -err = ff_cbs_alloc_unit_content(unit, sizeof(*slice), -&cbs_mpeg2_free_slice); -if (err < 0) -return err; -slice = unit->content; - err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -264,12 +240,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, #define START(start_code, type, read_func, free_func) \ case start_code: \ { \ -type *header; \ -err = ff_cbs_alloc_unit_content(unit, \ -sizeof(*header), free_func); \ -if (err < 0) \ -return err; \ -header = unit->content; \ +type *header = unit->content; \ err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \ if (err < 0) \ return err; \ @@ -420,11 +391,40 @@ static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx, return 0; } +static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = { +CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_PICTURE, MPEG2RawPictureHeader, + extra_information_picture.extra_information), + +{ +.nb_unit_types = CBS_UNIT_TYPE_RANGE, +.unit_type_range_start = 0x01, +.unit_type_range_end = 0xaf, + +.content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, +.content_size = sizeof(MPEG2RawSlice), +.nb_ref_offsets = 2, +.ref_offsets= { offsetof(MPEG2RawSlice, header.extra_information_slice.extra_information), +offsetof(MPEG2RawSlice, data) }, +}, + +CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData, + user_data), + +CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader), +CBS_UNIT_TYPE_POD(MPEG2_START_EXTENSION, MPEG2RawExtensionData), +CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_END,MPEG2RawSequenceEnd), +CBS_UNIT_TYPE_POD(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader), + +CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_mpeg2 = { .codec_id = AV_CODEC_ID_MPEG2VIDEO, .priv_data_size= sizeof(CodedBitstreamMPEG2Context), +.unit_types= cbs_mpeg2_unit_types, + .split_fragment= &cbs_mpeg2_split_fragment, .read_unit = &cbs_mpeg2_read_unit, .write_unit= &cbs_mpeg2_write_unit, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_h264: Use table-based alloc/free
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:20 2020 +0100| [2cb152d52f28081acf3c2306557944105af8374f] | committer: Mark Thompson cbs_h264: Use table-based alloc/free > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2cb152d52f28081acf3c2306557944105af8374f --- libavcodec/cbs_h2645.c | 163 + 1 file changed, 70 insertions(+), 93 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e5c8012d39..5725539e60 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -454,52 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #undef allocate -static void cbs_h264_free_pps(void *opaque, uint8_t *content) -{ -H264RawPPS *pps = (H264RawPPS*)content; -av_buffer_unref(&pps->slice_group_id_ref); -av_freep(&content); -} - -static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) -{ -switch (payload->payload_type) { -case H264_SEI_TYPE_BUFFERING_PERIOD: -case H264_SEI_TYPE_PIC_TIMING: -case H264_SEI_TYPE_PAN_SCAN_RECT: -case H264_SEI_TYPE_RECOVERY_POINT: -case H264_SEI_TYPE_DISPLAY_ORIENTATION: -case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: -case H264_SEI_TYPE_ALTERNATIVE_TRANSFER: -break; -case H264_SEI_TYPE_USER_DATA_REGISTERED: -av_buffer_unref(&payload->payload.user_data_registered.data_ref); -break; -case H264_SEI_TYPE_USER_DATA_UNREGISTERED: -av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); -break; -default: -av_buffer_unref(&payload->payload.other.data_ref); -break; -} -} - -static void cbs_h264_free_sei(void *opaque, uint8_t *content) -{ -H264RawSEI *sei = (H264RawSEI*)content; -int i; -for (i = 0; i < sei->payload_count; i++) -cbs_h264_free_sei_payload(&sei->payload[i]); -av_freep(&content); -} - -static void cbs_h264_free_slice(void *opaque, uint8_t *content) -{ -H264RawSlice *slice = (H264RawSlice*)content; -av_buffer_unref(&slice->data_ref); -av_freep(&content); -} - static void cbs_h265_free_vps(void *opaque, uint8_t *content) { H265RawVPS *vps = (H265RawVPS*)content; @@ -802,15 +756,14 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, if (err < 0) return err; +err = ff_cbs_alloc_unit_content2(ctx, unit); +if (err < 0) +return err; + switch (unit->type) { case H264_NAL_SPS: { -H264RawSPS *sps; - -err = ff_cbs_alloc_unit_content(unit, sizeof(*sps), NULL); -if (err < 0) -return err; -sps = unit->content; +H264RawSPS *sps = unit->content; err = cbs_h264_read_sps(ctx, &gbc, sps); if (err < 0) @@ -824,12 +777,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SPS_EXT: { -err = ff_cbs_alloc_unit_content(unit, -sizeof(H264RawSPSExtension), -NULL); -if (err < 0) -return err; - err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content); if (err < 0) return err; @@ -838,13 +785,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_PPS: { -H264RawPPS *pps; - -err = ff_cbs_alloc_unit_content(unit, sizeof(*pps), -&cbs_h264_free_pps); -if (err < 0) -return err; -pps = unit->content; +H264RawPPS *pps = unit->content; err = cbs_h264_read_pps(ctx, &gbc, pps); if (err < 0) @@ -860,15 +801,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_IDR_SLICE: case H264_NAL_AUXILIARY_SLICE: { -H264RawSlice *slice; +H264RawSlice *slice = unit->content; int pos, len; -err = ff_cbs_alloc_unit_content(unit, sizeof(*slice), -&cbs_h264_free_slice); -if (err < 0) -return err; -slice = unit->content; - err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -890,11 +825,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_AUD: { -err = ff_cbs_alloc_unit_content(unit, -sizeof(H264RawAUD), NULL); -if (err < 0) -return err; - err = cbs_h264_read_aud(ctx, &gbc, unit->content); if (err < 0) return err; @@ -903,11 +833,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SEI: { -
[FFmpeg-cvslog] h264_redundant_pps: Make it reference-compatible
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jul 27 17:32:23 2020 +0100| [d1c6e09d09f530a1f103a5dbdf06f69f42611974] | committer: Mark Thompson h264_redundant_pps: Make it reference-compatible Since c6a63e11092c975b89d824f08682fe31948d3686, the parameter sets modified as content of PPS units were references shared with the CodedBitstreamH264Context, so modifying them alters the parsing process of future access units which meant that frames often got discarded because invalid values were parsed. This patch makes h264_redundant_pps compatible with the reality of reference-counted parameter sets. Fixes #7807. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d1c6e09d09f530a1f103a5dbdf06f69f42611974 --- libavcodec/h264_redundant_pps_bsf.c | 17 ++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index a8af4105cf..cf41abe96c 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -41,8 +41,19 @@ typedef struct H264RedundantPPSContext { static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx, -H264RawPPS *pps) +CodedBitstreamUnit *unit) { +H264RawPPS *pps; +int err; + +// The changes we are about to perform affect the parsing process, +// so we must make sure that the PPS is writable, otherwise the +// parsing of future slices will be incorrect and even raise errors. +err = ff_cbs_make_unit_writable(ctx->input, unit); +if (err < 0) +return err; +pps = unit->content; + // Record the current value of pic_init_qp in order to fix up // following slices, then overwrite with the global value. ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26; @@ -89,7 +100,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt) if (nal->type == H264_NAL_SPS) au_has_sps = 1; if (nal->type == H264_NAL_PPS) { -err = h264_redundant_pps_fixup_pps(ctx, nal->content); +err = h264_redundant_pps_fixup_pps(ctx, nal); if (err < 0) goto fail; if (!au_has_sps) { @@ -145,7 +156,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == H264_NAL_PPS) { -err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content); +err = h264_redundant_pps_fixup_pps(ctx, &au->units[i]); if (err < 0) goto fail; } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_av1: Use table-based alloc/free
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:26 2020 +0100| [ae7686a64fea5e70e315a02c0f680b2cc04cc188] | committer: Mark Thompson cbs_av1: Use table-based alloc/free > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ae7686a64fea5e70e315a02c0f680b2cc04cc188 --- libavcodec/cbs_av1.c | 85 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 72ad18151e..dcf6c140ae 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -809,50 +809,6 @@ fail: return err; } -static void cbs_av1_free_tile_data(AV1RawTileData *td) -{ -av_buffer_unref(&td->data_ref); -} - -static void cbs_av1_free_padding(AV1RawPadding *pd) -{ -av_buffer_unref(&pd->payload_ref); -} - -static void cbs_av1_free_metadata(AV1RawMetadata *md) -{ -switch (md->metadata_type) { -case AV1_METADATA_TYPE_ITUT_T35: -av_buffer_unref(&md->metadata.itut_t35.payload_ref); -break; -} -} - -static void cbs_av1_free_obu(void *opaque, uint8_t *content) -{ -AV1RawOBU *obu = (AV1RawOBU*)content; - -switch (obu->header.obu_type) { -case AV1_OBU_TILE_GROUP: -cbs_av1_free_tile_data(&obu->obu.tile_group.tile_data); -break; -case AV1_OBU_FRAME: -cbs_av1_free_tile_data(&obu->obu.frame.tile_group.tile_data); -break; -case AV1_OBU_TILE_LIST: -cbs_av1_free_tile_data(&obu->obu.tile_list.tile_data); -break; -case AV1_OBU_METADATA: -cbs_av1_free_metadata(&obu->obu.metadata); -break; -case AV1_OBU_PADDING: -cbs_av1_free_padding(&obu->obu.padding); -break; -} - -av_freep(&obu); -} - static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, GetBitContext *gbc, @@ -887,8 +843,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, GetBitContext gbc; int err, start_pos, end_pos; -err = ff_cbs_alloc_unit_content(unit, sizeof(*obu), -&cbs_av1_free_obu); +err = ff_cbs_alloc_unit_content2(ctx, unit); if (err < 0) return err; obu = unit->content; @@ -1247,11 +1202,49 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) av_buffer_unref(&priv->frame_header_ref); } +static void cbs_av1_free_metadata(void *unit, uint8_t *content) +{ +AV1RawOBU *obu = (AV1RawOBU*)content; +AV1RawMetadata *md; + +av_assert0(obu->header.obu_type == AV1_OBU_METADATA); +md = &obu->obu.metadata; + +switch (md->metadata_type) { +case AV1_METADATA_TYPE_ITUT_T35: +av_buffer_unref(&md->metadata.itut_t35.payload_ref); +break; +} +} + +static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { +CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER,AV1RawOBU), +CBS_UNIT_TYPE_POD(AV1_OBU_TEMPORAL_DELIMITER, AV1RawOBU), +CBS_UNIT_TYPE_POD(AV1_OBU_FRAME_HEADER, AV1RawOBU), +CBS_UNIT_TYPE_POD(AV1_OBU_REDUNDANT_FRAME_HEADER, AV1RawOBU), + +CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_GROUP, AV1RawOBU, + obu.tile_group.tile_data.data), +CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_FRAME, AV1RawOBU, + obu.frame.tile_group.tile_data.data), +CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU, + obu.tile_list.tile_data.data), +CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING,AV1RawOBU, + obu.padding.payload), + +CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU, + &cbs_av1_free_metadata), + +CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_av1 = { .codec_id = AV_CODEC_ID_AV1, .priv_data_size= sizeof(CodedBitstreamAV1Context), +.unit_types= cbs_av1_unit_types, + .split_fragment= &cbs_av1_split_fragment, .read_unit = &cbs_av1_read_unit, .write_unit= &cbs_av1_write_obu, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_h2645: Ensure that non-refcounted parameter sets are fully copied
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:22 2020 +0100| [0720e15c0330f0f101c02d5c2c6548e964079f6d] | committer: Mark Thompson cbs_h2645: Ensure that non-refcounted parameter sets are fully copied Only copying the main structure is not necessarily sufficient - there could be references to substructures. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0720e15c0330f0f101c02d5c2c6548e964079f6d --- libavcodec/cbs_h2645.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 5725539e60..e19fa5249d 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -720,18 +720,20 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \ H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \ unsigned int id = ps_var->id_element; \ +int err; \ if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \ " id : %d.\n", id); \ return AVERROR_INVALIDDATA; \ } \ +err = ff_cbs_make_unit_refcounted(ctx, unit); \ +if (err < 0) \ +return err; \ if (priv->ps_var[id] == priv->active_ ## ps_var) \ priv->active_ ## ps_var = NULL ; \ av_buffer_unref(&priv->ps_var ## _ref[id]); \ -if (unit->content_ref) \ -priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ -else \ -priv->ps_var ## _ref[id] = av_buffer_alloc(sizeof(*ps_var)); \ +av_assert0(unit->content_ref); \ +priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ if (!priv->ps_var ## _ref[id]) \ return AVERROR(ENOMEM); \ priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \ ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs_vp9: Use table-based alloc/free
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:25 2020 +0100| [f643f9bd6d6c954717cd8e607034b0dd25156244] | committer: Mark Thompson cbs_vp9: Use table-based alloc/free > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f643f9bd6d6c954717cd8e607034b0dd25156244 --- libavcodec/cbs_vp9.c | 17 - 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c index 6e0a7dcbea..6a480b4ce3 100644 --- a/libavcodec/cbs_vp9.c +++ b/libavcodec/cbs_vp9.c @@ -479,13 +479,6 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx, return 0; } -static void cbs_vp9_free_frame(void *opaque, uint8_t *content) -{ -VP9RawFrame *frame = (VP9RawFrame*)content; -av_buffer_unref(&frame->data_ref); -av_freep(&frame); -} - static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { @@ -497,8 +490,7 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; -err = ff_cbs_alloc_unit_content(unit, sizeof(*frame), -&cbs_vp9_free_frame); +err = ff_cbs_alloc_unit_content2(ctx, unit); if (err < 0) return err; frame = unit->content; @@ -642,11 +634,18 @@ static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx, return 0; } +static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = { +CBS_UNIT_TYPE_INTERNAL_REF(0, VP9RawFrame, data), +CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_vp9 = { .codec_id = AV_CODEC_ID_VP9, .priv_data_size= sizeof(CodedBitstreamVP9Context), +.unit_types= cbs_vp9_unit_types, + .split_fragment= &cbs_vp9_split_fragment, .read_unit = &cbs_vp9_read_unit, .write_unit= &cbs_vp9_write_unit, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] cbs: Ensure that reference fields always follow the associated pointer
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:17 2020 +0100| [1fe77d4a637c4033180a35b6ebf13b5a4707d2a4] | committer: Mark Thompson cbs: Ensure that reference fields always follow the associated pointer Having these together allows us to find both pointers given the address of only one of them. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1fe77d4a637c4033180a35b6ebf13b5a4707d2a4 --- libavcodec/cbs_av1.h | 6 +++--- libavcodec/cbs_h264.h | 18 +- libavcodec/cbs_h265.h | 18 +- libavcodec/cbs_jpeg.h | 2 +- libavcodec/cbs_mpeg2.h | 10 +- libavcodec/cbs_vp9.h | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 913a6e5dea..7a0c08c596 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -284,8 +284,8 @@ typedef struct AV1RawFrameHeader { typedef struct AV1RawTileData { uint8_t *data; -size_t data_size; AVBufferRef *data_ref; +size_t data_size; } AV1RawTileData; typedef struct AV1RawTileGroup { @@ -346,8 +346,8 @@ typedef struct AV1RawMetadataITUTT35 { uint8_t itu_t_t35_country_code_extension_byte; uint8_t *payload; -size_t payload_size; AVBufferRef *payload_ref; +size_t payload_size; } AV1RawMetadataITUTT35; typedef struct AV1RawMetadataTimecode { @@ -379,8 +379,8 @@ typedef struct AV1RawMetadata { typedef struct AV1RawPadding { uint8_t *payload; -size_t payload_size; AVBufferRef *payload_ref; +size_t payload_size; } AV1RawPadding; diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index f54ccd3b36..a6fe0a6af2 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -277,16 +277,16 @@ typedef struct H264RawSEIPanScanRect { typedef struct H264RawSEIUserDataRegistered { uint8_t itu_t_t35_country_code; uint8_t itu_t_t35_country_code_extension_byte; -uint8_t *data; -size_t data_length; +uint8_t *data; AVBufferRef *data_ref; +size_t data_length; } H264RawSEIUserDataRegistered; typedef struct H264RawSEIUserDataUnregistered { uint8_t uuid_iso_iec_11578[16]; -uint8_t *data; -size_t data_length; +uint8_t *data; AVBufferRef *data_ref; +size_t data_length; } H264RawSEIUserDataUnregistered; typedef struct H264RawSEIRecoveryPoint { @@ -334,9 +334,9 @@ typedef struct H264RawSEIPayload { H264RawSEIAlternativeTransferCharacteristics alternative_transfer_characteristics; struct { -uint8_t *data; -size_t data_length; +uint8_t *data; AVBufferRef *data_ref; +size_t data_length; } other; } payload; } H264RawSEIPayload; @@ -429,10 +429,10 @@ typedef struct H264RawSliceHeader { typedef struct H264RawSlice { H264RawSliceHeader header; -uint8_t *data; -size_t data_size; -int data_bit_start; +uint8_t *data; AVBufferRef *data_ref; +size_t data_size; +int data_bit_start; } H264RawSlice; typedef struct H264RawFiller { diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index 73897f77a4..15b22bbfd4 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -183,9 +183,9 @@ typedef struct H265RawVUI { } H265RawVUI; typedef struct H265RawExtensionData { -uint8_t *data; -size_t bit_length; +uint8_t *data; AVBufferRef *data_ref; +size_t bit_length; } H265RawExtensionData; typedef struct H265RawVPS { @@ -541,10 +541,10 @@ typedef struct H265RawSliceHeader { typedef struct H265RawSlice { H265RawSliceHeader header; -uint8_t *data; -size_t data_size; -int data_bit_start; +uint8_t *data; AVBufferRef *data_ref; +size_t data_size; +int data_bit_start; } H265RawSlice; @@ -600,15 +600,15 @@ typedef struct H265RawSEIUserDataRegistered { uint8_t itu_t_t35_country_code; uint8_t itu_t_t35_country_code_extension_byte; uint8_t *data; -size_t data_length; AVBufferRef *data_ref; +size_t data_length; } H265RawSEIUserDataRegistered; typedef struct H265RawSEIUserDataUnregistered { uint8_t uuid_iso_iec_11578[16]; uint8_t *data; -size_t data_length; AVBufferRef *data_ref; +size_t data_length; } H265RawSEIUserDataUnregistered; typedef struct H265RawSEIRecoveryPoint { @@ -710,9 +710,9 @@ typedef struct H265RawSEIPayload { alternative_transfer_characteristics; H265RawSEIAlphaChannelInfo alpha_channel_info; struct { -uint8_t *data; -size_t data_length; +uint8_t *data; AVBufferRef *data_ref; +size_t data_length; } other; } payload; H265RawExtensionData extension_data; dif
[FFmpeg-cvslog] cbs: Add support functions for handling unit content references
ffmpeg | branch: master | Mark Thompson | Mon Jul 27 17:32:21 2020 +0100| [42daac1c74169ec4373b5199932c5f3176a2e897] | committer: Mark Thompson cbs: Add support functions for handling unit content references Use the unit type table to determine what we need to do to clone the internals of the unit content when making copies for refcounting or writeability. (This will still fail for units with complex content if they do not have a defined clone function.) Setup and naming from a patch by Andreas Rheinhardt , but with the implementation changed to use the unit type information if possible rather than requiring a codec-specific function. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=42daac1c74169ec4373b5199932c5f3176a2e897 --- libavcodec/cbs.c | 163 ++ libavcodec/cbs.h | 29 + libavcodec/cbs_internal.h | 1 + 3 files changed, 193 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 61cf8e3466..7c1aa005c2 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -871,3 +871,166 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, return 0; } + +static int cbs_clone_unit_content(AVBufferRef **clone_ref, + CodedBitstreamUnit *unit, + const CodedBitstreamUnitTypeDescriptor *desc) +{ +uint8_t *src, *copy; +uint8_t **src_ptr, **copy_ptr; +AVBufferRef **src_buf, **copy_buf; +int err, i; + +av_assert0(unit->content); +src = unit->content; + +copy = av_memdup(src, desc->content_size); +if (!copy) +return AVERROR(ENOMEM); + +for (i = 0; i < desc->nb_ref_offsets; i++) { +src_ptr = (uint8_t**)(src + desc->ref_offsets[i]); +src_buf = (AVBufferRef**)(src_ptr + 1); +copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]); +copy_buf = (AVBufferRef**)(copy_ptr + 1); + +if (!*src_ptr) { +av_assert0(!*src_buf); +continue; +} +if (!*src_buf) { +// We can't handle a non-refcounted pointer here - we don't +// have enough information to handle whatever structure lies +// at the other end of it. +err = AVERROR(EINVAL); +goto fail; +} + +// src_ptr is required to point somewhere inside src_buf. If it +// doesn't, there is a bug somewhere. +av_assert0(*src_ptr >= (*src_buf)->data && + *src_ptr < (*src_buf)->data + (*src_buf)->size); + +*copy_buf = av_buffer_ref(*src_buf); +if (!*copy_buf) { +err = AVERROR(ENOMEM); +goto fail; +} +*copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data); +} + +*clone_ref = av_buffer_create(copy, desc->content_size, + desc->content_free ? desc->content_free : + cbs_default_free_unit_content, + (void*)desc, 0); +if (!*clone_ref) { +err = AVERROR(ENOMEM); +goto fail; +} + +return 0; + +fail: +for (--i; i >= 0; i--) +av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i])); +av_freep(©); +*clone_ref = NULL; +return err; +} + +int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, +CodedBitstreamUnit *unit) +{ +const CodedBitstreamUnitTypeDescriptor *desc; +AVBufferRef *ref; +int err; + +av_assert0(unit->content); +if (unit->content_ref) { +// Already refcounted, nothing to do. +return 0; +} + +desc = cbs_find_unit_type_desc(ctx, unit); +if (!desc) +return AVERROR(ENOSYS); + +switch (desc->content_type) { +case CBS_CONTENT_TYPE_POD: +ref = av_buffer_alloc(desc->content_size); +if (!ref) +return AVERROR(ENOMEM); +memcpy(ref->data, unit->content, desc->content_size); +err = 0; +break; + +case CBS_CONTENT_TYPE_INTERNAL_REFS: +err = cbs_clone_unit_content(&ref, unit, desc); +break; + +case CBS_CONTENT_TYPE_COMPLEX: +if (!desc->content_clone) +return AVERROR_PATCHWELCOME; +err = desc->content_clone(&ref, unit); +break; + +default: +av_assert0(0 && "Invalid content type."); +} + +if (err < 0) +return err; + +unit->content_ref = ref; +unit->content = ref->data; +return 0; +} + +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ +const CodedBitstreamUnitTypeDescriptor *desc; +AVBufferRef *ref; +int err; + +// This can only be applied to refcounted units. +err = ff_cbs_make_unit_refcounted(ctx, unit); +if (err < 0) +return err; +av_assert0(unit->content && unit->content_ref); + +if (av_buffer_is_writable(unit->conten