[FFmpeg-cvslog] cbs_h264: Fix handling of auxiliary pictures
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 7 04:47:51 2018 +0100| [8d1cf2d89481ca986af893425188d065c0f8f857] | committer: Mark Thompson cbs_h264: Fix handling of auxiliary pictures The earlier code used the most recent non-auxiliary slice to determine whether an auxiliary slice has the syntax of an IDR slice, even when the most recent slice was from a slice of a redundant frame. Now only slices of the primary coded picture are used, as the specifications mandate. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8d1cf2d89481ca986af893425188d065c0f8f857 --- libavcodec/cbs_h264_syntax_template.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c index dbf9ff1268..4da4c5da67 100644 --- a/libavcodec/cbs_h264_syntax_template.c +++ b/libavcodec/cbs_h264_syntax_template.c @@ -1190,11 +1190,10 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw, "in the same access unit.\n"); return AVERROR_INVALIDDATA; } +idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE; } else { -h264->last_slice_nal_unit_type = -current->nal_unit_header.nal_unit_type; +idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE; } -idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE; ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1); ue(slice_type, 0, 9); @@ -1272,6 +1271,13 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw, if (pps->redundant_pic_cnt_present_flag) ue(redundant_pic_cnt, 0, 127); +else +infer(redundant_pic_cnt, 0); + +if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE +&& !current->redundant_pic_cnt) +h264->last_slice_nal_unit_type = +current->nal_unit_header.nal_unit_type; if (slice_type_b) flag(direct_spatial_mv_pred_flag); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h264_redundant_pps: Fix logging context
ffmpeg | branch: master | Andreas Rheinhardt | Fri Nov 9 06:31:38 2018 +0100| [6dafcb6fdb6271d35220b889833561705c2b366f] | committer: Michael Niedermayer h264_redundant_pps: Fix logging context The first element of H264RedundantPPSContext is not a pointer to an AVClass as required. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6dafcb6fdb6271d35220b889833561705c2b366f --- libavcodec/h264_redundant_pps_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index cc5a3060f5..af247eef21 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -91,7 +91,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) if (nal->type == H264_NAL_PPS) { h264_redundant_pps_fixup_pps(ctx, nal->content); if (!au_has_sps) { -av_log(ctx, AV_LOG_VERBOSE, "Deleting redundant PPS " +av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS " "at %"PRId64".\n", in->pts); ff_cbs_delete_unit(ctx->input, au, i); } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] cbs_h2645: Improve performance of writing slices
ffmpeg | branch: master | Andreas Rheinhardt | Sun Nov 11 23:43:05 2018 +0100| [ee47ac97d7938fc221d1d386e3e520a5521cddfd] | committer: Mark Thompson cbs_h2645: Improve performance of writing slices Instead of using a combination of bitreader and -writer for copying data, one can byte-align the (obsolete and removed) bitreader to improve performance. With the right alignment one can even use memcpy. The right alignment normally exists for CABAC and hence for H.265 in general. For aligned data this reduced the time to copy the slicedata from 776520 decicycles to 33889 with 262144 runs and a 6.5mb/s H.264 video. For unaligned data the number went down from 279196 to 97739 decicycles. Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ee47ac97d7938fc221d1d386e3e520a5521cddfd --- libavcodec/cbs_h2645.c | 118 - 1 file changed, 68 insertions(+), 50 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e55bd00183..53d9bfed79 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1050,6 +1050,64 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, return 0; } +static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, + PutBitContext *pbc, const uint8_t *data, + size_t data_size, int data_bit_start) +{ +size_t rest = data_size - (data_bit_start + 7) / 8; +const uint8_t *pos = data + data_bit_start / 8; + +av_assert0(data_bit_start >= 0 && + 8 * data_size > data_bit_start); + +if (data_size * 8 + 8 > put_bits_left(pbc)) +return AVERROR(ENOSPC); + +if (!rest) +goto rbsp_stop_one_bit; + +// First copy the remaining bits of the first byte +// The above check ensures that we do not accidentally +// copy beyond the rbsp_stop_one_bit. +if (data_bit_start % 8) +put_bits(pbc, 8 - data_bit_start % 8, + *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8)); + +if (put_bits_count(pbc) % 8 == 0) { +// If the writer is aligned at this point, +// memcpy can be used to improve performance. +// This happens normally for CABAC. +flush_put_bits(pbc); +memcpy(put_bits_ptr(pbc), pos, rest); +skip_put_bytes(pbc, rest); +} else { +// If not, we have to copy manually. +// rbsp_stop_one_bit forces us to special-case +// the last byte. +uint8_t temp; +int i; + +for (; rest > 4; rest -= 4, pos += 4) +put_bits32(pbc, AV_RB32(pos)); + +for (; rest > 1; rest--, pos++) +put_bits(pbc, 8, *pos); + +rbsp_stop_one_bit: +temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8); + +av_assert0(temp); +i = ff_ctz(*pos); +temp = temp >> i; +i = rest ? (8 - i) : (8 - i - data_bit_start % 8); +put_bits(pbc, i, temp); +if (put_bits_count(pbc) % 8) +put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0); +} + +return 0; +} + static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc) @@ -1100,37 +1158,17 @@ static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_AUXILIARY_SLICE: { H264RawSlice *slice = unit->content; -GetBitContext gbc; -int bits_left, end, zeroes; err = cbs_h264_write_slice_header(ctx, pbc, >header); if (err < 0) return err; if (slice->data) { -if (slice->data_size * 8 + 8 > put_bits_left(pbc)) -return AVERROR(ENOSPC); - -init_get_bits(, slice->data, slice->data_size * 8); -skip_bits_long(, slice->data_bit_start); - -// Copy in two-byte blocks, but stop before copying the -// rbsp_stop_one_bit in the final byte. -while (get_bits_left() > 23) -put_bits(pbc, 16, get_bits(, 16)); - -bits_left = get_bits_left(); -end = get_bits(, bits_left); - -// rbsp_stop_one_bit must be present here. -av_assert0(end); -zeroes = ff_ctz(end); -if (bits_left > zeroes + 1) -put_bits(pbc, bits_left - zeroes - 1, - end >> (zeroes + 1)); -put_bits(pbc, 1, 1); -while (put_bits_count(pbc) % 8 != 0) -put_bits(pbc, 1, 0); +err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, + slice->data_size, +
[FFmpeg-cvslog] cbs_mpeg2: Improve performance of writing slices
ffmpeg | branch: master | Andreas Rheinhardt | Sun Nov 4 05:48:40 2018 +0100| [6df9020f45eaff66ba2c2bac98cda9ddaacb03f3] | committer: Mark Thompson cbs_mpeg2: Improve performance of writing slices Instead of using a combination of bitreader and -writer for copying data, one can byte-align the (obsolete and removed) bitreader to improve performance. One can even use memcpy in the normal case. This improved the time needed for writing the slicedata from 33618 to 2370 decicycles when tested on a video originating from a DVD (4194394 runs). Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6df9020f45eaff66ba2c2bac98cda9ddaacb03f3 --- libavcodec/cbs_mpeg2.c | 39 +++ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 0df4234b12..8b8b266563 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -264,8 +264,6 @@ static int cbs_mpeg2_write_slice(CodedBitstreamContext *ctx, PutBitContext *pbc) { MPEG2RawSlice *slice = unit->content; -GetBitContext gbc; -size_t bits_left; int err; err = cbs_mpeg2_write_slice_header(ctx, pbc, >header); @@ -273,21 +271,38 @@ static int cbs_mpeg2_write_slice(CodedBitstreamContext *ctx, return err; if (slice->data) { +size_t rest = slice->data_size - (slice->data_bit_start + 7) / 8; +uint8_t *pos = slice->data + slice->data_bit_start / 8; + +av_assert0(slice->data_bit_start >= 0 && + 8 * slice->data_size > slice->data_bit_start); + if (slice->data_size * 8 + 8 > put_bits_left(pbc)) return AVERROR(ENOSPC); -init_get_bits(, slice->data, slice->data_size * 8); -skip_bits_long(, slice->data_bit_start); - -while (get_bits_left() > 15) -put_bits(pbc, 16, get_bits(, 16)); +// First copy the remaining bits of the first byte +if (slice->data_bit_start % 8) +put_bits(pbc, 8 - slice->data_bit_start % 8, + *pos++ & MAX_UINT_BITS(8 - slice->data_bit_start % 8)); + +if (put_bits_count(pbc) % 8 == 0) { +// If the writer is aligned at this point, +// memcpy can be used to improve performance. +// This is the normal case. +flush_put_bits(pbc); +memcpy(put_bits_ptr(pbc), pos, rest); +skip_put_bytes(pbc, rest); +} else { +// If not, we have to copy manually: +for (; rest > 3; rest -= 4, pos += 4) +put_bits32(pbc, AV_RB32(pos)); -bits_left = get_bits_left(); -put_bits(pbc, bits_left, get_bits(, bits_left)); +for (; rest; rest--, pos++) +put_bits(pbc, 8, *pos); -// Align with zeroes. -while (put_bits_count(pbc) % 8 != 0) -put_bits(pbc, 1, 0); +// Align with zeros +put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0); +} } return 0; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h264_levels, h264_metadata_bsf: Fix levels typo
ffmpeg | branch: master | Andreas Rheinhardt | Mon Nov 12 15:18:12 2018 +0100| [959521b58de945ce8aacd4b0ba84958fc192a2c9] | committer: Mark Thompson h264_levels, h264_metadata_bsf: Fix levels typo profile_idc for level 1b should be 11, not 10. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=959521b58de945ce8aacd4b0ba84958fc192a2c9 --- libavcodec/h264_levels.c | 2 +- libavcodec/h264_metadata_bsf.c | 2 +- libavcodec/tests/h264_levels.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c index 737b7dcf06..7a55116773 100644 --- a/libavcodec/h264_levels.c +++ b/libavcodec/h264_levels.c @@ -25,7 +25,7 @@ static const H264LevelDescriptor h264_levels[] = { // | level_idc | MaxFS|MaxCPB| MaxMvsPer2Mb // | | cs3f| | MaxDpbMbs | | MaxVmvR | | { "1", 10, 0, 1485, 99,396, 64,175, 64, 2, 0 }, -{ "1b", 10, 1, 1485, 99,396,128,350, 64, 2, 0 }, +{ "1b", 11, 1, 1485, 99,396,128,350, 64, 2, 0 }, { "1b", 9, 0, 1485, 99,396,128,350, 64, 2, 0 }, { "1.1", 11, 0, 3000,396,900,192,500, 128, 2, 0 }, { "1.2", 12, 0, 6000,396, 2376,384, 1000, 128, 2, 0 }, diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index bf37528234..521bc36b7e 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -258,7 +258,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, if (sps->profile_idc == 66 || sps->profile_idc == 77 || sps->profile_idc == 88) { -sps->level_idc = 10; +sps->level_idc = 11; sps->constraint_set3_flag = 1; } else { sps->level_idc = 9; diff --git a/libavcodec/tests/h264_levels.c b/libavcodec/tests/h264_levels.c index 794517eb6c..0e00f05af6 100644 --- a/libavcodec/tests/h264_levels.c +++ b/libavcodec/tests/h264_levels.c @@ -102,7 +102,7 @@ static const struct { // Check level 1b. { 32 * 1200, 66, 10 }, { 32 * 1500, 100, 10 }, -{ 96 * 1200, 66, 10 }, +{ 96 * 1200, 66, 11 }, { 96 * 1500, 100, 9 }, { 144 * 1200, 66, 11 }, { 144 * 1500, 100, 11 }, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h264_metadata: Don't use inferred value of buffering frames
ffmpeg | branch: master | Andreas Rheinhardt | Mon Nov 12 15:18:15 2018 +0100| [3c9c9b1568ef6a9babb4237cf8850017ef547668] | committer: Mark Thompson h264_metadata: Don't use inferred value of buffering frames Using the value of buffering frames inferred from the old level is not a sensible approach when one wants to guess the level. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c9c9b1568ef6a9babb4237cf8850017ef547668 --- libavcodec/h264_metadata_bsf.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 521bc36b7e..e674f2a88d 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -222,7 +222,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, if (ctx->level == LEVEL_AUTO) { const H264LevelDescriptor *desc; int64_t bit_rate; -int width, height; +int width, height, dpb_frames; if (sps->vui.nal_hrd_parameters_present_flag) { bit_rate = (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) * @@ -236,13 +236,16 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, bit_rate = 0; } +// Don't use max_dec_frame_buffering if it is only inferred. +dpb_frames = sps->vui.bitstream_restriction_flag ? +sps->vui.max_dec_frame_buffering : H264_MAX_DPB_FRAMES; + width = 16 * (sps->pic_width_in_mbs_minus1 + 1); height = 16 * (sps->pic_height_in_map_units_minus1 + 1) * (2 - sps->frame_mbs_only_flag); desc = ff_h264_guess_level(sps->profile_idc, bit_rate, - width, height, - sps->vui.max_dec_frame_buffering); + width, height, dpb_frames); if (desc) { level_idc = desc->level_idc; } else { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avutil/mem: Correct documentation of av_fast_*alloc(z)
ffmpeg | branch: master | Andreas Rheinhardt | Sun Nov 18 15:08:45 2018 +0100| [8f875a90c440925268e55c2734ec258fe1994cab] | committer: Michael Niedermayer avutil/mem: Correct documentation of av_fast_*alloc(z) The current wording regarding size and min_size is completely wrong and ignores that min_size is indeed only a desired minimal size, not the actually allocated size. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8f875a90c440925268e55c2734ec258fe1994cab --- libavutil/mem.h | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavutil/mem.h b/libavutil/mem.h index 7e0b12a8a7..55ae573ac9 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -363,10 +363,10 @@ av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); * @endcode * * @param[in,out] ptr Already allocated buffer, or `NULL` - * @param[in,out] size Pointer to current size of buffer `ptr`. `*size` is - * changed to `min_size` in case of success or 0 in - * case of failure - * @param[in] min_size New size of buffer `ptr` + * @param[in,out] size Pointer to the size of buffer `ptr`. `*size` is + * updated to the new allocated size, in particular 0 + * in case of failure. + * @param[in] min_size Desired minimal size of buffer `ptr` * @return `ptr` if the buffer is large enough, a pointer to newly reallocated * buffer if the buffer was not large enough, or `NULL` in case of * error @@ -397,10 +397,10 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size); * @param[in,out] ptr Pointer to pointer to an already allocated buffer. * `*ptr` will be overwritten with pointer to new * buffer on success or `NULL` on failure - * @param[in,out] size Pointer to current size of buffer `*ptr`. `*size` is - * changed to `min_size` in case of success or 0 in - * case of failure - * @param[in] min_size New size of buffer `*ptr` + * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is + * updated to the new allocated size, in particular 0 + * in case of failure. + * @param[in] min_size Desired minimal size of buffer `*ptr` * @see av_realloc() * @see av_fast_mallocz() */ @@ -418,10 +418,10 @@ void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size); * @param[in,out] ptr Pointer to pointer to an already allocated buffer. * `*ptr` will be overwritten with pointer to new * buffer on success or `NULL` on failure - * @param[in,out] size Pointer to current size of buffer `*ptr`. `*size` is - * changed to `min_size` in case of success or 0 in - * case of failure - * @param[in] min_size New size of buffer `*ptr` + * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is + * updated to the new allocated size, in particular 0 + * in case of failure. + * @param[in] min_size Desired minimal size of buffer `*ptr` * @see av_fast_malloc() */ void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h264_redundant_pps: Fix memleak in case of errors
ffmpeg | branch: master | Andreas Rheinhardt | Fri Nov 9 06:31:36 2018 +0100| [40b74abfca39bf514333c3ebb6d6e946975057c3] | committer: Mark Thompson h264_redundant_pps: Fix memleak in case of errors Now the fragment is uninitialized and the input packet freed in case of errors. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=40b74abfca39bf514333c3ebb6d6e946975057c3 --- libavcodec/h264_redundant_pps_bsf.c | 40 - 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index af247eef21..0b7888c97e 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -80,7 +80,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) err = ff_cbs_read_packet(ctx->input, au, in); if (err < 0) -return err; +goto fail; au_has_sps = 0; for (i = 0; i < au->nb_units; i++) { @@ -89,11 +89,15 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) if (nal->type == H264_NAL_SPS) au_has_sps = 1; if (nal->type == H264_NAL_PPS) { -h264_redundant_pps_fixup_pps(ctx, nal->content); +err = h264_redundant_pps_fixup_pps(ctx, nal->content); +if (err < 0) +goto fail; if (!au_has_sps) { av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS " "at %"PRId64".\n", in->pts); -ff_cbs_delete_unit(ctx->input, au, i); +err = ff_cbs_delete_unit(ctx->input, au, i); +if (err < 0) +goto fail; } } if (nal->type == H264_NAL_SLICE || @@ -105,17 +109,21 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) err = ff_cbs_write_packet(ctx->output, out, au); if (err < 0) -return err; +goto fail; -ff_cbs_fragment_uninit(ctx->output, au); err = av_packet_copy_props(out, in); if (err < 0) -return err; +goto fail; +err = 0; +fail: +ff_cbs_fragment_uninit(ctx->output, au); av_packet_free(); +if (err < 0) +av_packet_unref(out); -return 0; +return err; } static int h264_redundant_pps_init(AVBSFContext *bsf) @@ -138,25 +146,29 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) err = ff_cbs_read_extradata(ctx->input, au, bsf->par_in); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); -return err; +goto fail; } for (i = 0; i < au->nb_units; i++) { -if (au->units[i].type == H264_NAL_PPS) -h264_redundant_pps_fixup_pps(ctx, au->units[i].content); +if (au->units[i].type == H264_NAL_PPS) { +err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content); +if (err < 0) +goto fail; +} } ctx->extradata_pic_init_qp = ctx->current_pic_init_qp; err = ff_cbs_write_extradata(ctx->output, bsf->par_out, au); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); -return err; +goto fail; } - -ff_cbs_fragment_uninit(ctx->output, au); } -return 0; +err = 0; +fail: +ff_cbs_fragment_uninit(ctx->output, au); +return err; } static void h264_redundant_pps_flush(AVBSFContext *bsf) ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h2645_parse: Make ff_h2645_packet_split reference-compatible
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 28 01:24:09 2018 +0100| [992532ee3122d7938a7581988eea401b57de8189] | committer: Mark Thompson h2645_parse: Make ff_h2645_packet_split reference-compatible This is in preparation for a patch for cbs_h2645. Now the packet's rbsp_buffer can be owned by an AVBuffer. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=992532ee3122d7938a7581988eea401b57de8189 --- libavcodec/cbs_h2645.c | 8 +++--- libavcodec/extract_extradata_bsf.c | 2 +- libavcodec/h2645_parse.c | 53 +++--- libavcodec/h2645_parse.h | 9 ++- libavcodec/h264_parse.c| 2 +- libavcodec/h264dec.c | 4 +-- libavcodec/hevc_parse.c| 3 ++- libavcodec/hevc_parser.c | 2 +- libavcodec/hevcdec.c | 2 +- 9 files changed, 70 insertions(+), 15 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 666970ed03..574a53a60a 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -612,7 +612,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -636,7 +636,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -690,7 +690,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -709,7 +709,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, frag->data, frag->data_size, ctx->log_ctx, priv->mp4, priv->nal_length_size, -codec_id, 1); +codec_id, 1, 0); if (err < 0) return err; diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index f37427c7e1..17e5deb96b 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -157,7 +157,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, } ret = ff_h2645_packet_split(>h2645_pkt, pkt->data, pkt->size, -ctx, 0, 0, ctx->par_in->codec_id, 1); +ctx, 0, 0, ctx->par_in->codec_id, 1, 0); if (ret < 0) return ret; diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index aaa4b8f443..942f2c5d71 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -343,9 +343,51 @@ static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc) return i + 3; } +static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref) +{ +if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) +goto fail; +size += AV_INPUT_BUFFER_PADDING_SIZE; + +if (rbsp->rbsp_buffer_alloc_size >= size && +(!rbsp->rbsp_buffer_ref || av_buffer_is_writable(rbsp->rbsp_buffer_ref))) +return; + +size = FFMIN(size + size / 16 + 32, INT_MAX); + +if (rbsp->rbsp_buffer_ref) +av_buffer_unref(>rbsp_buffer_ref); +else +av_free(rbsp->rbsp_buffer); + +rbsp->rbsp_buffer = av_malloc(size); +if (!rbsp->rbsp_buffer) +goto fail; +rbsp->rbsp_buffer_alloc_size = size; + +if (use_ref) { +rbsp->rbsp_buffer_ref = av_buffer_create(rbsp->rbsp_buffer, size, + NULL, NULL, 0); +if (!rbsp-&
[FFmpeg-cvslog] cbs_h2645: Avoid memcpy when splitting fragment #2
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 28 01:24:10 2018 +0100| [8ca55a2b9e95e79956ae0a9069f08e72c63fde16] | committer: Mark Thompson cbs_h2645: Avoid memcpy when splitting fragment #2 Now memcpy can be avoided for NAL units containing escapes, too. Particularly improves performance for files with hardcoded black bars. For such a file, time spent in cbs_h2645_split_fragment went down from 369410 decicycles to 327677 decicycles. (It were 379114 decicycles when every NAL unit was copied.) Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8ca55a2b9e95e79956ae0a9069f08e72c63fde16 --- libavcodec/cbs_h2645.c | 33 +++-- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 574a53a60a..e74f8dce81 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -531,6 +531,7 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, for (i = 0; i < packet->nb_nals; i++) { const H2645NAL *nal = >nals[i]; +AVBufferRef *ref; size_t size = nal->size; // Remove trailing zeroes. @@ -538,25 +539,13 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, --size; av_assert0(size > 0); -if (nal->data == nal->raw_data) { -err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, -(uint8_t*)nal->data, size, frag->data_ref); -if (err < 0) -return err; -} else { -uint8_t *data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); -if (!data) -return AVERROR(ENOMEM); -memcpy(data, nal->data, size); -memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); +ref = (nal->data == nal->raw_data) ? frag->data_ref + : packet->rbsp.rbsp_buffer_ref; -err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, - data, size, NULL); -if (err < 0) { -av_freep(); -return err; -} -} +err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, +(uint8_t*)nal->data, size, ref); +if (err < 0) +return err; } return 0; @@ -612,7 +601,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -636,7 +625,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -690,7 +679,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(>read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -709,7 +698,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, frag->data, frag->data_size, ctx->log_ctx, priv->mp4, priv->nal_length_size, -codec_id, 1, 0); +codec_id, 1, 1); if (err < 0) return err; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] trace_headers: Update documentation
ffmpeg | branch: master | Andreas Rheinhardt | Sat Dec 1 08:52:55 2018 +0100| [5d8df52c45b2b17e3b2e2b04640d580ea39707f1] | committer: Mark Thompson trace_headers: Update documentation It also supports AV1 and (M)JPEG. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5d8df52c45b2b17e3b2e2b04640d580ea39707f1 --- doc/bitstream_filters.texi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 15c578aa8a..b779265f58 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -632,7 +632,8 @@ Log trace output containing all syntax elements in the coded stream headers (everything above the level of individual coded blocks). This can be useful for debugging low-level stream issues. -Supports H.264, H.265, MPEG-2 and VP9. +Supports AV1, H.264, H.265, (M)JPEG, MPEG-2 and VP9, but depending +on the build only a subset of these may be available. @section truehd_core ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] cbs_h265: Fix Time Code SEI syntax
ffmpeg | branch: master | Andreas Rheinhardt | Sat Dec 1 08:52:54 2018 +0100| [9f588ba5ca283c6b0b0b744085275e6253ba5cc6] | committer: Mark Thompson cbs_h265: Fix Time Code SEI syntax Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f588ba5ca283c6b0b0b744085275e6253ba5cc6 --- libavcodec/cbs_h265_syntax_template.c | 56 +++ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index 0a430df23a..f1e1bb0e7e 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -1955,36 +1955,40 @@ static int FUNC(sei_time_code)(CodedBitstreamContext *ctx, RWContext *rw, u(2, num_clock_ts, 1, 3); for (i = 0; i < current->num_clock_ts; i++) { -flags(units_field_based_flag[i], 1, i); -us(5, counting_type[i], 0, 6,1, i); -flags(full_timestamp_flag[i],1, i); -flags(discontinuity_flag[i], 1, i); -flags(cnt_dropped_flag[i], 1, i); - -us(9, n_frames[i], 0, MAX_UINT_BITS(9), 1, i); - -if (current->full_timestamp_flag[i]) { -us(6, seconds_value[i], 0, 59, 1, i); -us(6, minutes_value[i], 0, 59, 1, i); -us(5, hours_value[i], 0, 23, 1, i); -} else { -flags(seconds_flag[i], 1, i); -if (current->seconds_flag[i]) { +flags(clock_timestamp_flag[i], 1, i); + +if (current->clock_timestamp_flag[i]) { +flags(units_field_based_flag[i], 1, i); +us(5, counting_type[i], 0, 6,1, i); +flags(full_timestamp_flag[i],1, i); +flags(discontinuity_flag[i], 1, i); +flags(cnt_dropped_flag[i], 1, i); + +us(9, n_frames[i], 0, MAX_UINT_BITS(9), 1, i); + +if (current->full_timestamp_flag[i]) { us(6, seconds_value[i], 0, 59, 1, i); -flags(minutes_flag[i], 1, i); -if (current->minutes_flag[i]) { -us(6, minutes_value[i], 0, 59, 1, i); -flags(hours_flag[i], 1, i); -if (current->hours_flag[i]) -us(5, hours_value[i], 0, 23, 1, i); +us(6, minutes_value[i], 0, 59, 1, i); +us(5, hours_value[i], 0, 23, 1, i); +} else { +flags(seconds_flag[i], 1, i); +if (current->seconds_flag[i]) { +us(6, seconds_value[i], 0, 59, 1, i); +flags(minutes_flag[i], 1, i); +if (current->minutes_flag[i]) { +us(6, minutes_value[i], 0, 59, 1, i); +flags(hours_flag[i], 1, i); +if (current->hours_flag[i]) +us(5, hours_value[i], 0, 23, 1, i); +} } } -} -us(5, time_offset_length[i], 0, 31, 1, i); -if (current->time_offset_length[i] > 0) -us(current->time_offset_length[i], time_offset_value[i], - 0, MAX_UINT_BITS(current->time_offset_length[i]), 1, i); +us(5, time_offset_length[i], 0, 31, 1, i); +if (current->time_offset_length[i] > 0) +us(current->time_offset_length[i], time_offset_value[i], + 0, MAX_UINT_BITS(current->time_offset_length[i]), 1, i); +} } return 0; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] cbs_h2645: Avoid memcpy when splitting fragment
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 21 19:34:29 2018 +0100| [e895b800fe273d3445be52a4880ae0172c193bc0] | committer: Mark Thompson cbs_h2645: Avoid memcpy when splitting fragment Now memcpy is avoided for NAL units that don't contain 0x03 escape characters. Improves performance of cbs_h2645_fragment_add_nals from 36940 decicycles to 6364 decicycles based on 8 runs with a 5.1 Mb/s H.264 sample (262144 runs each). Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e895b800fe273d3445be52a4880ae0172c193bc0 --- libavcodec/cbs_h2645.c | 28 +--- libavcodec/h2645_parse.h | 6 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index a2d0170e97..666970ed03 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -532,24 +532,30 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, for (i = 0; i < packet->nb_nals; i++) { const H2645NAL *nal = >nals[i]; size_t size = nal->size; -uint8_t *data; // Remove trailing zeroes. while (size > 0 && nal->data[size - 1] == 0) --size; av_assert0(size > 0); -data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); -if (!data) -return AVERROR(ENOMEM); -memcpy(data, nal->data, size); -memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); +if (nal->data == nal->raw_data) { +err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, +(uint8_t*)nal->data, size, frag->data_ref); +if (err < 0) +return err; +} else { +uint8_t *data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); +if (!data) +return AVERROR(ENOMEM); +memcpy(data, nal->data, size); +memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); -err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, - data, size, NULL); -if (err < 0) { -av_freep(); -return err; +err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, + data, size, NULL); +if (err < 0) { +av_freep(); +return err; +} } } diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h index 2e29ad26cb..6dbba8fe4a 100644 --- a/libavcodec/h2645_parse.h +++ b/libavcodec/h2645_parse.h @@ -86,6 +86,12 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp, /** * Split an input packet into NAL units. + * + * If data == raw_data holds true for a NAL unit of the returned pkt, then + * said NAL unit does not contain any emulation_prevention_three_byte and + * the data is contained in the input buffer pointed to by buf. + * Otherwise, the unescaped data is part of the rbsp_buffer described by the + * packet's H2645RBSP. */ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] libavcodec/cbs: Stop needlessly reallocating the units array
ffmpeg | branch: master | Andreas Rheinhardt | Mon Feb 11 23:47:43 2019 +0100| [b8c45bbcbc207293f955e838ea66106f4b65b1ac] | committer: Mark Thompson libavcodec/cbs: Stop needlessly reallocating the units array Currently, a fragment's unit array is constantly reallocated during splitting of a packet. This commit changes this: One can keep the units array by distinguishing between the number of allocated and the number of valid units in the units array. The more units a packet is split into, the bigger the benefit. So MPEG-2 benefits the most; for a video coming from an NTSC-DVD (usually 32 units per frame) the average cost of cbs_insert_unit (for a single unit) went down from 6717 decicycles to 450 decicycles (based upon 10 runs with 4194304 runs each); if each packet consists of only one unit, it went down from 2425 to 448; for a H.264 video where most packets contain nine units, it went from 4431 to 450. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b8c45bbcbc207293f955e838ea66106f4b65b1ac --- libavcodec/av1_metadata_bsf.c | 6 ++-- libavcodec/av1_parser.c | 5 +-- libavcodec/cbs.c| 62 + libavcodec/cbs.h| 33 +--- libavcodec/filter_units_bsf.c | 7 +++-- libavcodec/h264_metadata_bsf.c | 6 ++-- libavcodec/h264_redundant_pps_bsf.c | 6 ++-- libavcodec/h265_metadata_bsf.c | 6 ++-- libavcodec/mpeg2_metadata_bsf.c | 6 ++-- libavcodec/trace_headers_bsf.c | 5 +-- libavcodec/vaapi_encode_h264.c | 9 +++--- libavcodec/vaapi_encode_h265.c | 9 +++--- libavcodec/vaapi_encode_mjpeg.c | 3 +- libavcodec/vaapi_encode_mpeg2.c | 5 +-- libavcodec/vp9_metadata_bsf.c | 4 ++- 15 files changed, 113 insertions(+), 59 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index 52d383661f..2b74b697e4 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -170,7 +170,7 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) err = 0; fail: -ff_cbs_fragment_uninit(ctx->cbc, frag); +ff_cbs_fragment_reset(ctx->cbc, frag); if (err < 0) av_packet_unref(out); @@ -215,13 +215,15 @@ static int av1_metadata_init(AVBSFContext *bsf) err = 0; fail: -ff_cbs_fragment_uninit(ctx->cbc, frag); +ff_cbs_fragment_reset(ctx->cbc, frag); return err; } static void av1_metadata_close(AVBSFContext *bsf) { AV1MetadataContext *ctx = bsf->priv_data; + +ff_cbs_fragment_free(ctx->cbc, >access_unit); ff_cbs_close(>cbc); } diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c index 8df66498f4..bb8737a393 100644 --- a/libavcodec/av1_parser.c +++ b/libavcodec/av1_parser.c @@ -72,7 +72,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx, goto end; } -ff_cbs_fragment_uninit(s->cbc, td); +ff_cbs_fragment_reset(s->cbc, td); } ret = ff_cbs_read(s->cbc, td, data, size); @@ -159,7 +159,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx, } end: -ff_cbs_fragment_uninit(s->cbc, td); +ff_cbs_fragment_reset(s->cbc, td); s->cbc->log_ctx = NULL; @@ -193,6 +193,7 @@ static void av1_parser_close(AVCodecParserContext *ctx) { AV1ParseContext *s = ctx->priv_data; +ff_cbs_fragment_free(s->cbc, >temporal_unit); ff_cbs_close(>cbc); } diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index ecbf57c293..c388be896b 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -136,14 +136,13 @@ static void cbs_unit_uninit(CodedBitstreamContext *ctx, unit->data_bit_padding = 0; } -void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, -CodedBitstreamFragment *frag) +void ff_cbs_fragment_reset(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag) { int i; for (i = 0; i < frag->nb_units; i++) cbs_unit_uninit(ctx, >units[i]); -av_freep(>units); frag->nb_units = 0; av_buffer_unref(>data_ref); @@ -152,6 +151,15 @@ void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, frag->data_bit_padding = 0; } +void ff_cbs_fragment_free(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag) +{ +ff_cbs_fragment_reset(ctx, frag); + +av_freep(>units); +frag->nb_units_allocated = 0; +} + static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag) { @@ -216,8 +224,6 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx, { int err; -memset(frag, 0, sizeof(*frag)); - err = cbs_fill_fragment_data(ctx, frag, par->extradata, par->extra
[FFmpeg-cvslog] filter_units, trace_headers: Always use fragment from context
ffmpeg | branch: master | Andreas Rheinhardt | Mon Feb 11 23:47:42 2019 +0100| [c5b452ed2f16a0d7bf01d7d84097337f8756987b] | committer: Mark Thompson filter_units, trace_headers: Always use fragment from context This is in preparation for another patch that will stop needless reallocations of the unit array. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5b452ed2f16a0d7bf01d7d84097337f8756987b --- libavcodec/filter_units_bsf.c | 8 libavcodec/trace_headers_bsf.c | 13 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 1ee0afdf2b..0500dea6b2 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -199,18 +199,18 @@ static int filter_units_init(AVBSFContext *bsf) ctx->cbc->nb_decompose_unit_types = 0; if (bsf->par_in->extradata) { -CodedBitstreamFragment ps; +CodedBitstreamFragment *frag = >fragment; -err = ff_cbs_read_extradata(ctx->cbc, , bsf->par_in); +err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); } else { -err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, ); +err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag); if (err < 0) av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); } -ff_cbs_fragment_uninit(ctx->cbc, ); +ff_cbs_fragment_uninit(ctx->cbc, frag); } return err; diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c index 839d4c..61284e615e 100644 --- a/libavcodec/trace_headers_bsf.c +++ b/libavcodec/trace_headers_bsf.c @@ -28,6 +28,7 @@ typedef struct TraceHeadersContext { CodedBitstreamContext *cbc; +CodedBitstreamFragment fragment; } TraceHeadersContext; @@ -44,13 +45,13 @@ static int trace_headers_init(AVBSFContext *bsf) ctx->cbc->trace_level = AV_LOG_INFO; if (bsf->par_in->extradata) { -CodedBitstreamFragment ps; +CodedBitstreamFragment *frag = >fragment; av_log(bsf, AV_LOG_INFO, "Extradata\n"); -err = ff_cbs_read_extradata(ctx->cbc, , bsf->par_in); +err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in); -ff_cbs_fragment_uninit(ctx->cbc, ); +ff_cbs_fragment_uninit(ctx->cbc, frag); } return err; @@ -66,7 +67,7 @@ static void trace_headers_close(AVBSFContext *bsf) static int trace_headers(AVBSFContext *bsf, AVPacket *pkt) { TraceHeadersContext *ctx = bsf->priv_data; -CodedBitstreamFragment au; +CodedBitstreamFragment *frag = >fragment; char tmp[256] = { 0 }; int err; @@ -92,9 +93,9 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *pkt) av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp); -err = ff_cbs_read_packet(ctx->cbc, , pkt); +err = ff_cbs_read_packet(ctx->cbc, frag, pkt); -ff_cbs_fragment_uninit(ctx->cbc, ); +ff_cbs_fragment_uninit(ctx->cbc, frag); if (err < 0) av_packet_unref(pkt); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avcodec/mpeg4videodec: Fix nonsense warning
ffmpeg | branch: master | Andreas Rheinhardt | Mon Mar 11 11:32:05 2019 +0100| [3f086a2f665f9906e0f6197cddbfacc2f4b093a1] | committer: Michael Niedermayer avcodec/mpeg4videodec: Fix nonsense warning Since db772308941a2a338c7809f90d347219a6a93074 parsing of mpeg4-extradata lead to a "Failed to parse extradata" warning, because ff_mpeg4_decode_picture_header returns AVERROR_INVALIDDATA in case that no VOP was found. This patch adds a parameter to signify whether a header (where the absence of a VOP does not raise an error) or not is parsed. The first mode is of course used for parsing headers. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3f086a2f665f9906e0f6197cddbfacc2f4b093a1 --- libavcodec/h263dec.c | 4 ++-- libavcodec/mpeg4video.h| 2 +- libavcodec/mpeg4video_parser.c | 6 +++--- libavcodec/mpeg4videodec.c | 10 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 2cf01e3d98..8385ddfe2e 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -500,9 +500,9 @@ retry: GetBitContext gb; if (init_get_bits8(, s->avctx->extradata, s->avctx->extradata_size) >= 0 ) -ff_mpeg4_decode_picture_header(avctx->priv_data, ); +ff_mpeg4_decode_picture_header(avctx->priv_data, , 1); } -ret = ff_mpeg4_decode_picture_header(avctx->priv_data, >gb); +ret = ff_mpeg4_decode_picture_header(avctx->priv_data, >gb, 0); } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) { ret = ff_intel_h263_decode_picture_header(s); } else if (CONFIG_FLV_DECODER && s->h263_flv) { diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h index dd0a59038d..1a5da31928 100644 --- a/libavcodec/mpeg4video.h +++ b/libavcodec/mpeg4video.h @@ -163,7 +163,7 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, void ff_set_mpeg4_time(MpegEncContext *s); int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); -int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb); +int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header); void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); void ff_mpeg4_clean_buffers(MpegEncContext *s); void ff_mpeg4_stuffing(PutBitContext *pbc); diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c index 9ebb09a63e..9ca0f14976 100644 --- a/libavcodec/mpeg4video_parser.c +++ b/libavcodec/mpeg4video_parser.c @@ -89,13 +89,13 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, if (avctx->extradata_size && pc->first_picture) { init_get_bits(gb, avctx->extradata, avctx->extradata_size * 8); -ret = ff_mpeg4_decode_picture_header(dec_ctx, gb); -if (ret < -1) +ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 1); +if (ret < 0) av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata\n"); } init_get_bits(gb, buf, 8 * buf_size); -ret = ff_mpeg4_decode_picture_header(dec_ctx, gb); +ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 0); if (s->width && (!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height)) { ret = ff_set_dimensions(avctx, s->width, s->height); diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index ecd028a87c..99b1e10620 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -3203,11 +3203,13 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) /** * Decode MPEG-4 headers. - * @return <0 if no VOP found (or a damaged one) + * + * @param header If set the absence of a VOP is not treated as error; otherwise, it is treated as such. + * @return <0 if an error occured * FRAME_SKIPPED if a not coded VOP is found - * 0 if a VOP is found + * 0 else */ -int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb) +int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header) { MpegEncContext *s = >m; unsigned startcode, v; @@ -3236,6 +3238,8 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb) (ctx->divx_version >= 0 || ctx->xvid_build >= 0) || s->codec_tag == AV_RL32("QMP4")) { av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits); return FRAME_SKIPPED; // divx bug +} else if (header && get_bits_count(gb) == gb->size_in_bits) { +return 0; // ordinary return v
[FFmpeg-cvslog] h264_redundant_pps: Fix logging context
ffmpeg | branch: release/4.0 | Andreas Rheinhardt | Fri Nov 9 06:31:38 2018 +0100| [5bdc1e51fd3a57e5259279c950c47301a0aeaf7b] | committer: Michael Niedermayer h264_redundant_pps: Fix logging context The first element of H264RedundantPPSContext is not a pointer to an AVClass as required. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer (cherry picked from commit 6dafcb6fdb6271d35220b889833561705c2b366f) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5bdc1e51fd3a57e5259279c950c47301a0aeaf7b --- libavcodec/h264_redundant_pps_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index 26baca84e3..46cd77a7c1 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -90,7 +90,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) if (nal->type == H264_NAL_PPS) { h264_redundant_pps_fixup_pps(ctx, nal->content); if (!au_has_sps) { -av_log(ctx, AV_LOG_VERBOSE, "Deleting redundant PPS " +av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS " "at %"PRId64".\n", in->pts); ff_cbs_delete_unit(ctx->input, au, i); } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] avcodec/mpeg4_unpack_bframes_bsf: Use avpriv_find_start_code
ffmpeg | branch: master | Andreas Rheinhardt | Sat Feb 2 20:34:11 2019 +0100| [1eb6bfbc1ff5d9f670ae51b4ca41d0053a6fd486] | committer: Michael Niedermayer avcodec/mpeg4_unpack_bframes_bsf: Use avpriv_find_start_code instead of an ad-hoc function to search for start codes in order to remove code duplication and to improve performance. Improved performance of finding startcodes from 52606 decicycles to 9543 decicycles based upon 262144 runs for a 1 Mb/s MPEG4 video. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1eb6bfbc1ff5d9f670ae51b4ca41d0053a6fd486 --- libavcodec/mpeg4_unpack_bframes_bsf.c | 34 ++ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index e9c535f390..1daf133ce5 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -21,50 +21,36 @@ #include "avcodec.h" #include "bsf.h" +#include "internal.h" #include "mpeg4video.h" typedef struct UnpackBFramesBSFContext { AVPacket *b_frame; } UnpackBFramesBSFContext; -/* search next start code */ -static unsigned int find_startcode(const uint8_t *buf, int buf_size, int *pos) -{ -unsigned int startcode = 0xFF; - -for (; *pos < buf_size;) { -startcode = ((startcode << 8) | buf[*pos]) & 0x; -*pos +=1; -if ((startcode & 0xFF00) != 0x100) -continue; /* no startcode */ -return startcode; -} - -return 0; -} - /* determine the position of the packed marker in the userdata, * the number of VOPs and the position of the second VOP */ static void scan_buffer(const uint8_t *buf, int buf_size, int *pos_p, int *nb_vop, int *pos_vop2) { -unsigned int startcode; -int pos, i; +uint32_t startcode; +const uint8_t *end = buf + buf_size, *pos = buf; -for (pos = 0; pos < buf_size;) { -startcode = find_startcode(buf, buf_size, ); +while (pos < end) { +startcode = -1; +pos = avpriv_find_start_code(pos, end, ); if (startcode == USER_DATA_STARTCODE && pos_p) { /* check if the (DivX) userdata string ends with 'p' (packed) */ -for (i = 0; i < 255 && pos + i + 1 < buf_size; i++) { -if (buf[pos + i] == 'p' && buf[pos + i + 1] == '\0') { -*pos_p = pos + i; +for (int i = 0; i < 255 && pos + i + 1 < end; i++) { +if (pos[i] == 'p' && pos[i + 1] == '\0') { +*pos_p = pos + i - buf; break; } } } else if (startcode == VOP_STARTCODE && nb_vop) { *nb_vop += 1; if (*nb_vop == 2 && pos_vop2) { -*pos_vop2 = pos - 4; /* subtract 4 bytes startcode */ +*pos_vop2 = pos - buf - 4; /* subtract 4 bytes startcode */ } } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] bitstream_filters: Correct dump_extradata description
ffmpeg | branch: master | Andreas Rheinhardt | Tue Jun 4 15:41:05 2019 +0200| [d81913e680177bc46c482406fd257ac659c03899] | committer: Gyan Doshi bitstream_filters: Correct dump_extradata description The default is to dump extradata to keyframes, not all frames. Also improve the description of the relevant AVOption. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d81913e680177bc46c482406fd257ac659c03899 --- doc/bitstream_filters.texi | 2 +- libavcodec/dump_extradata_bsf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 25bbf8372b..40e8adad0f 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -120,7 +120,7 @@ add extradata to all packets @end table @end table -If not specified it is assumed @samp{e}. +If not specified it is assumed @samp{k}. For example the following @command{ffmpeg} command forces a global header (thus disabling individual packet headers) in the H.264 packets diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c index 188a1c619b..7112cd6bd4 100644 --- a/libavcodec/dump_extradata_bsf.c +++ b/libavcodec/dump_extradata_bsf.c @@ -81,7 +81,7 @@ fail: #define OFFSET(x) offsetof(DumpExtradataContext, x) #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM) static const AVOption options[] = { -{ "freq", "When do dump extradata", OFFSET(freq), AV_OPT_TYPE_INT, +{ "freq", "When to dump extradata", OFFSET(freq), AV_OPT_TYPE_INT, { .i64 = DUMP_FREQ_KEYFRAME }, DUMP_FREQ_KEYFRAME, DUMP_FREQ_ALL, FLAGS, "freq" }, { "k",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_KEYFRAME }, .flags = FLAGS, .unit = "freq" }, { "keyframe", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_KEYFRAME }, .flags = FLAGS, .unit = "freq" }, ___ 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_mpeg2: Correct error codes
ffmpeg | branch: master | Andreas Rheinhardt | Wed May 22 03:04:35 2019 +0200| [1759a9e5b52de524fa9f3f4d115087132744176b] | committer: Mark Thompson cbs_mpeg2: Correct error codes Up until now, things that are merely unsupported by cbs_mpeg2 have been declared to be invalid input. This has been changed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1759a9e5b52de524fa9f3f4d115087132744176b --- libavcodec/cbs_mpeg2.c | 4 +--- libavcodec/cbs_mpeg2_syntax_template.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 1f1197fb30..ce22e32c15 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -251,9 +251,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, group_of_pictures_header, NULL); #undef START default: -av_log(ctx->log_ctx, AV_LOG_ERROR, "Unknown start code %02"PRIx32".\n", - unit->type); -return AVERROR_INVALIDDATA; +return AVERROR(ENOSYS); } } diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index 09487fe56d..d753cdc901 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -335,9 +335,9 @@ static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw, return FUNC(picture_coding_extension) (ctx, rw, >data.picture_coding); default: -av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid extension ID %d.\n", +av_log(ctx->log_ctx, AV_LOG_ERROR, "Extension ID %d not supported.\n", current->extension_start_code_identifier); -return AVERROR_INVALIDDATA; +return AVERROR_PATCHWELCOME; } } ___ 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_mpeg2: Improve checks for invalid values
ffmpeg | branch: master | Andreas Rheinhardt | Wed May 22 03:04:32 2019 +0200| [9c3f2a8894a66d6b5b9285caa25f91fbfca7b3bc] | committer: Mark Thompson cbs_mpeg2: Improve checks for invalid values MPEG-2 contains several elements that mustn't be zero according to the specifications: horizontal/vertical_size_value, aspect_ratio_information, frame_rate_code, the quantiser matrices, the colour_description elements, picture_coding_type, the f_code[r][s] values and quantiser_scale_code. It is now checked that the invalid values don't occur. The colour_description elements are treated specially in this regard: Given that there are files in the wild which use illegal values for the colour_description elements (some of them created by mpeg2_metadata), they will be corrected to the value meaning "unknown" (namely 2) during reading. This has been done in such a way that trace_headers will nevertheless report the original value, together with a message about the fixup. Furthermore, the trace_headers output of user_data has been beautified. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9c3f2a8894a66d6b5b9285caa25f91fbfca7b3bc --- libavcodec/cbs_mpeg2.c | 16 + libavcodec/cbs_mpeg2_syntax_template.c | 64 +- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index f9f1d86b49..4605b2056e 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -41,20 +41,24 @@ #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) #define ui(width, name) \ -xui(width, name, current->name, 0) +xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0) +#define uir(width, name) \ +xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0) #define uis(width, name, subs, ...) \ -xui(width, name, current->name, subs, __VA_ARGS__) +xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) +#define uirs(width, name, subs, ...) \ +xui(width, name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__) #define READ #define READWRITE read #define RWContext GetBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xui(width, name, var, range_min, range_max, subs, ...) do { \ uint32_t value = 0; \ CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \ SUBSCRIPTS(subs, __VA_ARGS__), \ - , 0, (1 << width) - 1)); \ + , range_min, range_max)); \ var = value; \ } while (0) @@ -81,10 +85,10 @@ #define READWRITE write #define RWContext PutBitContext -#define xui(width, name, var, subs, ...) do { \ +#define xui(width, name, var, range_min, range_max, subs, ...) do { \ CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ SUBSCRIPTS(subs, __VA_ARGS__), \ -var, 0, (1 << width) - 1)); \ +var, range_min, range_max)); \ } while (0) #define marker_bit() do { \ diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index 10aaea7734..b9d53682fe 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -26,14 +26,14 @@ static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw, ui(8, sequence_header_code); -ui(12, horizontal_size_value); -ui(12, vertical_size_value); +uir(12, horizontal_size_value); +uir(12, vertical_size_value); mpeg2->horizontal_size = current->horizontal_size_value; mpeg2->vertical_size = current->vertical_size_value; -ui(4, aspect_ratio_information); -ui(4, frame_rate_code); +uir(4, aspect_ratio_information); +uir(4, frame_rate_code); ui(18, bit_rate_value); marker_bit(); @@ -44,13 +44,13 @@ static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw, ui(1, load_intra_quantiser_matrix); if (current->load_intra_quantiser_matrix) { for (i = 0; i < 64; i++) -uis(8, intra_quantiser_matrix[i], 1, i); +uirs(8, intra_quantiser_matrix[i], 1, i); } ui(1, load_non_intra_quantiser_matrix); if (current->load_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) -uis(8, non_intra_quantiser_matrix[i], 1, i); +uirs(8, non_intra_quantiser_matrix[i], 1, i); } return 0; @@ -79,7 +79,7 @@ static int FUNC(user_data)(CodedBitstreamContext *ctx, RWContext *rw, #endif for (k = 0; k < current->user_data_length; k++) -xui(8, user_data, current->user_data[k], 0); +uis(8, user_data[k], 1, k);
[FFmpeg-cvslog] cbs_mpeg2: Correct and use enum values
ffmpeg | branch: master | Andreas Rheinhardt | Wed May 22 03:04:31 2019 +0200| [cfe4389d477064b0424590a7b3e1ec94059db2fd] | committer: Mark Thompson cbs_mpeg2: Correct and use enum values Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cfe4389d477064b0424590a7b3e1ec94059db2fd --- libavcodec/cbs_mpeg2.c | 30 +- libavcodec/cbs_mpeg2.h | 2 +- libavcodec/cbs_mpeg2_syntax_template.c | 10 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 8b8b266563..f9f1d86b49 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -215,13 +215,16 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, return err; \ } \ break; -START(0x00, MPEG2RawPictureHeader, picture_header, NULL); -START(0xb2, MPEG2RawUserData, user_data, -_mpeg2_free_user_data); -START(0xb3, MPEG2RawSequenceHeader, sequence_header, NULL); -START(0xb5, MPEG2RawExtensionData, extension_data, NULL); -START(0xb8, MPEG2RawGroupOfPicturesHeader, - group_of_pictures_header, NULL); +START(MPEG2_START_PICTURE, MPEG2RawPictureHeader, + picture_header, NULL); +START(MPEG2_START_USER_DATA, MPEG2RawUserData, + user_data,_mpeg2_free_user_data); +START(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader, + sequence_header, NULL); +START(MPEG2_START_EXTENSION, MPEG2RawExtensionData, + extension_data, NULL); +START(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader, + group_of_pictures_header, NULL); #undef START default: av_log(ctx->log_ctx, AV_LOG_ERROR, "Unknown start code %02"PRIx32".\n", @@ -244,11 +247,12 @@ static int cbs_mpeg2_write_header(CodedBitstreamContext *ctx, case start_code: \ err = cbs_mpeg2_write_ ## func(ctx, pbc, unit->content); \ break; -START(0x00, MPEG2RawPictureHeader, picture_header); -START(0xb2, MPEG2RawUserData, user_data); -START(0xb3, MPEG2RawSequenceHeader, sequence_header); -START(0xb5, MPEG2RawExtensionData, extension_data); -START(0xb8, MPEG2RawGroupOfPicturesHeader, group_of_pictures_header); +START(MPEG2_START_PICTURE, MPEG2RawPictureHeader, picture_header); +START(MPEG2_START_USER_DATA, MPEG2RawUserData, user_data); +START(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader, sequence_header); +START(MPEG2_START_EXTENSION, MPEG2RawExtensionData, extension_data); +START(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader, + group_of_pictures_header); #undef START default: av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for start " @@ -331,7 +335,7 @@ static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx, init_put_bits(, priv->write_buffer, priv->write_buffer_size); -if (unit->type >= 0x01 && unit->type <= 0xaf) +if (MPEG2_START_IS_SLICE(unit->type)) err = cbs_mpeg2_write_slice(ctx, unit, ); else err = cbs_mpeg2_write_header(ctx, unit, ); diff --git a/libavcodec/cbs_mpeg2.h b/libavcodec/cbs_mpeg2.h index 92caa99dc1..7565695acb 100644 --- a/libavcodec/cbs_mpeg2.h +++ b/libavcodec/cbs_mpeg2.h @@ -51,7 +51,7 @@ enum { MPEG2_EXTENSION_PICTURE_CODING= 0x8, MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE = 0x9, MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0xa, -MPEG2_EXTENSION_CAMAERA_PARAMETERS= 0xb, +MPEG2_EXTENSION_CAMERA_PARAMETERS = 0xb, MPEG2_EXTENSION_ITU_T = 0xc, }; diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index 88cf453b17..10aaea7734 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -303,19 +303,19 @@ static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw, ui(4, extension_start_code_identifier); switch (current->extension_start_code_identifier) { -case 1: +case MPEG2_EXTENSION_SEQUENCE: return FUNC(sequence_extension) (ctx, rw, >data.sequence); -case 2: +case MPEG2_EXTENSION_SEQUENCE_DISPLAY: return FUNC(sequence_display_extension) (ctx, rw, >data.sequence_display); -case 3: +case MPEG2_EXTENSION_QUANT_MATRIX: return FUNC(quant_matrix_extension) (ctx, rw, >data.quant_ma
[FFmpeg-cvslog] cbs_mpeg2: Fix storage type for frame_centre_*_offset
ffmpeg | branch: master | Andreas Rheinhardt | Wed May 22 03:04:34 2019 +0200| [de5880383967f44927c599ab16fa0f4f96b38365] | committer: Mark Thompson cbs_mpeg2: Fix storage type for frame_centre_*_offset The frame_centre_horizontal/vertical_offset values contained in picture display extensions are actually signed values (i.e. it is possible to indicate that the display device should add black bars/pillars). The files sony-ct3.bs and tcela-6.bits (which are both used in fate tests for mpeg2_metadata) contain picture display extensions; the former even contains a negative frame_centre_vertical_offset. Fortunately, the old code did not damage the picture display extensions when one did a cycle of reading and writing. For the same reason the fate tests needn't be updated either. Furthermore these fields now use the trace output for matrices. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=de5880383967f44927c599ab16fa0f4f96b38365 --- libavcodec/cbs_mpeg2.c | 20 libavcodec/cbs_mpeg2.h | 4 ++-- libavcodec/cbs_mpeg2_syntax_template.c | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 4605b2056e..1f1197fb30 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -48,6 +48,8 @@ xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) #define uirs(width, name, subs, ...) \ xui(width, name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__) +#define sis(width, name, subs, ...) \ +xsi(width, name, current->name, subs, __VA_ARGS__) #define READ @@ -62,6 +64,15 @@ var = value; \ } while (0) +#define xsi(width, name, var, subs, ...) do { \ +int32_t value; \ +CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \ + SUBSCRIPTS(subs, __VA_ARGS__), , \ + MIN_INT_BITS(width), \ + MAX_INT_BITS(width))); \ +var = value; \ +} while (0) + #define marker_bit() do { \ av_unused uint32_t one; \ CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", NULL, , 1, 1)); \ @@ -77,6 +88,7 @@ #undef READWRITE #undef RWContext #undef xui +#undef xsi #undef marker_bit #undef nextbits @@ -91,6 +103,13 @@ var, range_min, range_max)); \ } while (0) +#define xsi(width, name, var, subs, ...) do { \ +CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \ + SUBSCRIPTS(subs, __VA_ARGS__), var, \ + MIN_INT_BITS(width), \ + MAX_INT_BITS(width))); \ +} while (0) + #define marker_bit() do { \ CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", NULL, 1, 1, 1)); \ } while (0) @@ -103,6 +122,7 @@ #undef READWRITE #undef RWContext #undef xui +#undef xsi #undef marker_bit #undef nextbits diff --git a/libavcodec/cbs_mpeg2.h b/libavcodec/cbs_mpeg2.h index 7565695acb..11f93b9df8 100644 --- a/libavcodec/cbs_mpeg2.h +++ b/libavcodec/cbs_mpeg2.h @@ -164,8 +164,8 @@ typedef struct MPEG2RawQuantMatrixExtension { } MPEG2RawQuantMatrixExtension; typedef struct MPEG2RawPictureDisplayExtension { -uint16_t frame_centre_horizontal_offset[3]; -uint16_t frame_centre_vertical_offset[3]; +int16_t frame_centre_horizontal_offset[3]; +int16_t frame_centre_vertical_offset[3]; } MPEG2RawPictureDisplayExtension; typedef struct MPEG2RawExtensionData { diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index b9d53682fe..09487fe56d 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -299,9 +299,9 @@ static int FUNC(picture_display_extension)(CodedBitstreamContext *ctx, RWContext HEADER("Picture Display Extension"); for (i = 0; i < mpeg2->number_of_frame_centre_offsets; i++) { -ui(16, frame_centre_horizontal_offset[i]); +sis(16, frame_centre_horizontal_offset[i], 1, i); marker_bit(); -ui(16, frame_centre_vertical_offset[i]); +sis(16, frame_centre_vertical_offset[i], 1, i); marker_bit(); } ___ 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/matroskadec: Compactify structure
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:47 2019 +0200| [410a0824f07ac4a526f633409cf893a897d2269c] | committer: Michael Niedermayer avformat/matroskadec: Compactify structure Matroska EBML IDs can be only four bytes long maximally, so it is natural to use uint32_t for them. By doing this and rearranging the elements of the MatroskaLevel1Element structure, one can reduce the size of said structure. Notice that this field is not read via the generic reading process for EBML_UINT, so one is not forced to use an uint64_t for it. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=410a0824f07ac4a526f633409cf893a897d2269c --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 6da9b15d79..3b8ddc5ecb 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -310,8 +310,8 @@ typedef struct MatroskaCluster { } MatroskaCluster; typedef struct MatroskaLevel1Element { -uint64_t id; uint64_t pos; +uint32_t id; int parsed; } MatroskaLevel1Element; ___ 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/matroskadec: Correct outdated error message
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:46 2019 +0200| [f767c68b3483cdcfd80f1510e1dbf539ee3ca69d] | committer: Michael Niedermayer avformat/matroskadec: Correct outdated error message This error message is outdated since d31fb1a9. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f767c68b3483cdcfd80f1510e1dbf539ee3ca69d --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index ed901f19ab..6da9b15d79 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3359,7 +3359,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf track = matroska_find_track_by_num(matroska, num); if (!track || !track->stream) { av_log(matroska->ctx, AV_LOG_INFO, - "Invalid stream %"PRIu64" or size %u\n", num, size); + "Invalid stream %"PRIu64"\n", num); return AVERROR_INVALIDDATA; } else if (size <= 3) return 0; ___ 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/matroskadec: Remove unused variables
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:45 2019 +0200| [c6bb825e7211f97cacf56c2c52472eecf4d969c6] | committer: Michael Niedermayer avformat/matroskadec: Remove unused variables Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c6bb825e7211f97cacf56c2c52472eecf4d969c6 --- libavformat/matroskadec.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index cba2b3d1f8..ed901f19ab 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -322,7 +322,6 @@ typedef struct MatroskaDemuxContext { /* EBML stuff */ int num_levels; MatroskaLevel levels[EBML_MAX_DEPTH]; -int level_up; uint32_t current_id; uint64_t time_scale; @@ -1611,7 +1610,6 @@ static void matroska_convert_tags(AVFormatContext *s) static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, uint64_t pos) { -uint32_t level_up = matroska->level_up; uint32_t saved_id = matroska->current_id; int64_t before_pos = avio_tell(matroska->ctx->pb); MatroskaLevel level; @@ -1647,7 +1645,6 @@ static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, } /* seek back */ avio_seek(matroska->ctx->pb, before_pos, SEEK_SET); -matroska->level_up = level_up; matroska->current_id = saved_id; return ret; @@ -3582,7 +3579,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, MatroskaDemuxContext *matroska = s->priv_data; MatroskaTrack *tracks = NULL; AVStream *st = s->streams[stream_index]; -int i, index, index_min; +int i, index; /* Parse the CUES now since we need the index data to seek. */ if (matroska->cues_parsing_deferred > 0) { @@ -3609,7 +3606,6 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1)) goto err; -index_min = index; tracks = matroska->tracks.elem; for (i = 0; i < matroska->tracks.nb_elem; i++) { tracks[i].audio.pkt_cnt= 0; @@ -3618,7 +3614,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, tracks[i].end_timecode = 0; } -avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET); +avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET); matroska->current_id = 0; if (flags & AVSEEK_FLAG_ANY) { st->skip_to_keyframe = 0; ___ 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, cbs_jpeg, cbs_mpeg2, cbs_vp9: Fix undef
ffmpeg | branch: master | Andreas Rheinhardt | Fri Jun 7 02:27:11 2019 +0200| [ad2745e86763c72b8580429e8e345196a4be27bc] | committer: Mark Thompson cbs_av1, cbs_jpeg, cbs_mpeg2, cbs_vp9: Fix undef READ has already been undefined at this point; it is obviously intended to undef WRITE. Furthermore, leb128 (in cbs_av1) was undefined too often and inconsistently. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ad2745e86763c72b8580429e8e345196a4be27bc --- libavcodec/cbs_av1.c | 5 ++--- libavcodec/cbs_jpeg.c | 2 +- libavcodec/cbs_mpeg2.c | 2 +- libavcodec/cbs_vp9.c | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index eb2d03ef43..eb6b801790 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -648,7 +648,6 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) #undef xf #undef xsu #undef uvlc -#undef leb128 #undef ns #undef increment #undef subexp @@ -720,17 +719,17 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) #include "cbs_av1_syntax_template.c" -#undef READ +#undef WRITE #undef READWRITE #undef RWContext #undef xf #undef xsu #undef uvlc -#undef leb128 #undef ns #undef increment #undef subexp #undef delta_q +#undef leb128 #undef infer #undef byte_alignment diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c index 5a72f0e2e7..83857bbba2 100644 --- a/libavcodec/cbs_jpeg.c +++ b/libavcodec/cbs_jpeg.c @@ -75,7 +75,7 @@ #include "cbs_jpeg_syntax_template.c" -#undef READ +#undef WRITE #undef READWRITE #undef RWContext #undef FUNC diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index ce22e32c15..cb202f835b 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -118,7 +118,7 @@ #include "cbs_mpeg2_syntax_template.c" -#undef READ +#undef WRITE #undef READWRITE #undef RWContext #undef xui diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c index 0b5f137ed8..5579d9b0af 100644 --- a/libavcodec/cbs_vp9.c +++ b/libavcodec/cbs_vp9.c @@ -395,7 +395,7 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, #include "cbs_vp9_syntax_template.c" -#undef READ +#undef WRITE #undef READWRITE #undef RWContext #undef xf ___ 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/matroskadec: Don't zero unnecessarily
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:48 2019 +0200| [1215b3a5f3f801f1f3179b9c29a0d52f906eef98] | committer: James Almer avformat/matroskadec: Don't zero unnecessarily It is only necessary to zero the initial allocated memory used to store the size of laced frames if the block used Xiph lacing. Otherwise no unintialized data was ever used, so use av_malloc instead of av_mallocz. Also use the correct type for the allocations. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1215b3a5f3f801f1f3179b9c29a0d52f906eef98 --- libavformat/matroskadec.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 09665fb680..996bddf1c1 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2788,7 +2788,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, if (!type) { *laces= 1; -*lace_buf = av_mallocz(sizeof(int)); +*lace_buf = av_malloc(sizeof(**lace_buf)); if (!*lace_buf) return AVERROR(ENOMEM); @@ -2800,7 +2800,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, *laces= *data + 1; data += 1; size -= 1; -lace_size = av_mallocz(*laces * sizeof(int)); +lace_size = av_malloc_array(*laces, sizeof(*lace_size)); if (!lace_size) return AVERROR(ENOMEM); @@ -2810,6 +2810,8 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, uint8_t temp; uint32_t total = 0; for (n = 0; res == 0 && n < *laces - 1; n++) { +lace_size[n] = 0; + while (1) { if (size <= total) { res = 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] avformat/matroskadec: Properly check return values
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:54 2019 +0200| [a27e5398e2d0e8af7eaa35001ea920d717fe9e38] | committer: James Almer avformat/matroskadec: Properly check return values Up until now, webm_dash_manifest_cues used the return values of ebml_read_num and ebml_read_length without checking for errors, i.e. return values < 0. This has been changed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a27e5398e2d0e8af7eaa35001ea920d717fe9e38 --- libavformat/matroskadec.c | 17 +++-- 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 996bddf1c1..0e9938b65e 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3864,12 +3864,17 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) cues_start = seekhead[i].pos + matroska->segment_start; if (avio_seek(matroska->ctx->pb, cues_start, SEEK_SET) == cues_start) { // cues_end is computed as cues_start + cues_length + length of the -// Cues element ID + EBML length of the Cues element. cues_end is -// inclusive and the above sum is reduced by 1. -uint64_t cues_length = 0, cues_id = 0, bytes_read = 0; -bytes_read += ebml_read_num(matroska, matroska->ctx->pb, 4, _id); -bytes_read += ebml_read_length(matroska, matroska->ctx->pb, _length); -cues_end = cues_start + cues_length + bytes_read - 1; +// Cues element ID (i.e. 4) + EBML length of the Cues element. +// cues_end is inclusive and the above sum is reduced by 1. +uint64_t cues_length, cues_id; +int bytes_read; +bytes_read = ebml_read_num (matroska, matroska->ctx->pb, 4, _id); +if (bytes_read < 0 || cues_id != (MATROSKA_ID_CUES & 0xfff)) +return bytes_read < 0 ? bytes_read : AVERROR_INVALIDDATA; +bytes_read = ebml_read_length(matroska, matroska->ctx->pb, _length); +if (bytes_read < 0) +return bytes_read; +cues_end = cues_start + 4 + bytes_read + cues_length - 1; } avio_seek(matroska->ctx->pb, before_pos, SEEK_SET); if (cues_start == -1 || cues_end == -1) return -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] avformat/matroskadec: Improve error/EOF checks III
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 24 01:42:31 2019 +0200| [ff5ea59f7b05cb4d37ba9e2c3ee383ff24a10ae0] | committer: James Almer avformat/matroskadec: Improve error/EOF checks III Up until now, when an element was skipped, it was relied upon ffio_limit to make sure that there is enough data available to skip. ffio_limit itself relies upon the availability of the file's size. As this needn't be available, the check has been refined: First one byte less than intended is skipped, then another byte is read, followed by a check of the error flags. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ff5ea59f7b05cb4d37ba9e2c3ee383ff24a10ae0 --- libavformat/matroskadec.c | 24 +--- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 5a9acd5ba7..bc73bfed11 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1258,13 +1258,23 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, case EBML_STOP: return 1; default: -if (ffio_limit(pb, length) != length) { -// ffio_limit emits its own error message, -// so we don't have to. -return AVERROR(EIO); -} -res = avio_skip(pb, length); -res = res < 0 ? res : 0; +if (length) { +if (ffio_limit(pb, length) != length) { +// ffio_limit emits its own error message, +// so we don't have to. +return AVERROR(EIO); +} +if ((res = avio_skip(pb, length - 1)) >= 0) { +// avio_skip might take us past EOF. We check for this +// by skipping only length - 1 bytes, reading a byte and +// checking the error flags. This is done in order to check +// that the element has been properly skipped even when +// no filesize (that ffio_limit relies on) is available. +avio_r8(pb); +res = NEEDS_CHECKING; +} +} else +res = 0; } if (res) { if (res == NEEDS_CHECKING) { ___ 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/matroskadec: Improve read error/EOF checks II
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 24 01:42:30 2019 +0200| [a569a7b3bb017315b954ca686e1e8add05f07f09] | committer: James Almer avformat/matroskadec: Improve read error/EOF checks II This commit fixes a number of bugs: 1. There was no check that no read error/EOF occured during ebml_read_uint, ebml_read_sint and ebml_read_float. 2. ebml_read_ascii and ebml_read_binary did sometimes not forward error codes; instead they simply returned AVERROR(EIO). 3. In particular, AVERROR_EOF hasn't been used and no dedicated error message for it existed. This has been changed. In order to reduce code duplication, the new error code NEEDS_CHECKING has been introduced which makes ebml_parse check the AVIOContext's status for errors. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a569a7b3bb017315b954ca686e1e8add05f07f09 --- libavformat/matroskadec.c | 59 --- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 59388efb64..5a9acd5ba7 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -69,6 +69,8 @@ #include "qtpalette.h" #define EBML_UNKNOWN_LENGTH UINT64_MAX /* EBML unknown length, in uint64_t */ +#define NEEDS_CHECKING2 /* Indicates that some error checks + * still need to be performed */ typedef enum { EBML_NONE, @@ -871,7 +873,7 @@ static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb, /* * Read the next element as an unsigned int. - * 0 is success, < 0 is failure. + * Returns NEEDS_CHECKING. */ static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num) { @@ -882,12 +884,12 @@ static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num) while (n++ < size) *num = (*num << 8) | avio_r8(pb); -return 0; +return NEEDS_CHECKING; } /* * Read the next element as a signed int. - * 0 is success, < 0 is failure. + * Returns NEEDS_CHECKING. */ static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num) { @@ -903,12 +905,12 @@ static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num) *num = ((uint64_t)*num << 8) | avio_r8(pb); } -return 0; +return NEEDS_CHECKING; } /* * Read the next element as a float. - * 0 is success, < 0 is failure. + * Returns NEEDS_CHECKING or < 0 on obvious failure. */ static int ebml_read_float(AVIOContext *pb, int size, double *num) { @@ -921,24 +923,25 @@ static int ebml_read_float(AVIOContext *pb, int size, double *num) else return AVERROR_INVALIDDATA; -return 0; +return NEEDS_CHECKING; } /* * Read the next element as an ASCII string. - * 0 is success, < 0 is failure. + * 0 is success, < 0 or NEEDS_CHECKING is failure. */ static int ebml_read_ascii(AVIOContext *pb, int size, char **str) { char *res; +int ret; /* EBML strings are usually not 0-terminated, so we allocate one * byte more, read the string and NULL-terminate it ourselves. */ if (!(res = av_malloc(size + 1))) return AVERROR(ENOMEM); -if (avio_read(pb, (uint8_t *) res, size) != size) { +if ((ret = avio_read(pb, (uint8_t *) res, size)) != size) { av_free(res); -return AVERROR(EIO); +return ret < 0 ? ret : NEEDS_CHECKING; } (res)[size] = '\0'; av_free(*str); @@ -949,7 +952,7 @@ static int ebml_read_ascii(AVIOContext *pb, int size, char **str) /* * Read the next element as binary data. - * 0 is success, < 0 is failure. + * 0 is success, < 0 or NEEDS_CHECKING is failure. */ static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) { @@ -963,11 +966,11 @@ static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) bin->data = bin->buf->data; bin->size = length; bin->pos = avio_tell(pb); -if (avio_read(pb, bin->data, length) != length) { +if ((ret = avio_read(pb, bin->data, length)) != length) { av_buffer_unref(>buf); bin->data = NULL; bin->size = 0; -return AVERROR(EIO); +return ret < 0 ? ret : NEEDS_CHECKING; } return 0; @@ -1255,14 +1258,34 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, case EBML_STOP: return 1; default: -if (ffio_limit(pb, length) != length) +if (ffio_limit(pb, length) != length) { +// ffio_limit emits its own error message, +// so we don't have to. return AVERROR(EIO); -return avio_skip(pb, length) < 0 ? AVERROR(EIO) : 0; +} +res = avio_skip(pb, length); +res = res < 0 ? res : 0; +} +if (res) { +if (res == NEEDS_CHECKING) { +if (pb->eof_reach
[FFmpeg-cvslog] avformat/matroskadec: Improve read error/EOF checks I
ffmpeg | branch: master | Andreas Rheinhardt | Tue Jun 25 03:08:56 2019 +0200| [239c7369e0490c6a130a1e4fd11c4fbf56379ce7] | committer: James Almer avformat/matroskadec: Improve read error/EOF checks I ebml_read_num had a number of flaws: 1. The check for read errors/EOF was totally wrong. E.g. an EBML number beginning with the invalid 0x00 would be considered a read error, although it is just invalid data. 2. The check for read errors/EOF was done just once, after reading the first byte of the EBML number. But errors/EOF can happen inbetween, of course, and this wasn't checked. 3. There was no way to distinguish when EOF should be an error (because the data has to be there) for which an error message should be emitted and when it is not necessarily an error (namely during parsing of EBML IDs). Such a possibility has been added and used. All this was fixed; furthermore, the error messages for invalid EBML numbers were improved and useless initializations were removed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=239c7369e0490c6a130a1e4fd11c4fbf56379ce7 --- libavformat/matroskadec.c | 74 +-- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 0e9938b65e..59388efb64 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -796,33 +796,32 @@ static int ebml_level_end(MatroskaDemuxContext *matroska) * Returns: number of bytes read, < 0 on error */ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, - int max_size, uint64_t *number) + int max_size, uint64_t *number, int eof_forbidden) { -int read = 1, n = 1; -uint64_t total = 0; +int read, n = 1; +uint64_t total; +int64_t pos; -/* The first byte tells us the length in bytes - avio_r8() can normally - * return 0, but since that's not a valid first ebmlID byte, we can - * use it safely here to catch EOS. */ -if (!(total = avio_r8(pb))) { -/* we might encounter EOS here */ -if (!avio_feof(pb)) { -int64_t pos = avio_tell(pb); -av_log(matroska->ctx, AV_LOG_ERROR, - "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", - pos, pos); -return pb->error ? pb->error : AVERROR(EIO); -} -return AVERROR_EOF; -} +/* The first byte tells us the length in bytes - except when it is zero. */ +total = avio_r8(pb); +if (pb->eof_reached) +goto err; /* get the length of the EBML number */ read = 8 - ff_log2_tab[total]; -if (read > max_size) { -int64_t pos = avio_tell(pb) - 1; -av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n", - (uint8_t) total, pos, pos); + +if (!total || read > max_size) { +pos = avio_tell(pb) - 1; +if (!total) { +av_log(matroska->ctx, AV_LOG_ERROR, + "0x00 at pos %"PRId64" (0x%"PRIx64") invalid as first byte " + "of an EBML number\n", pos, pos); +} else { +av_log(matroska->ctx, AV_LOG_ERROR, + "Length %d indicated by an EBML number's first byte 0x%02x " + "at pos %"PRId64" (0x%"PRIx64") exceeds max length %d.\n", + read, (uint8_t) total, pos, pos, max_size); +} return AVERROR_INVALIDDATA; } @@ -831,9 +830,29 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, while (n++ < read) total = (total << 8) | avio_r8(pb); +if (pb->eof_reached) { +eof_forbidden = 1; +goto err; +} + *number = total; return read; + +err: +pos = avio_tell(pb); +if (pb->error) { +av_log(matroska->ctx, AV_LOG_ERROR, + "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", + pos, pos); +return pb->error; +} +if (eof_forbidden) { +av_log(matroska->ctx, AV_LOG_ERROR, "File ended prematurely " + "at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); +return AVERROR(EIO); +} +return AVERROR_EOF; } /** @@ -844,7 +863,7 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb, uint64_t *number) { -int res = ebml_read_num(matroska, pb, 8, number); +int res = ebml_read_num(matroska, pb, 8, number, 1); if (res > 0 &&
[FFmpeg-cvslog] movsub_bsf: Fix mov2textsub regression
ffmpeg | branch: release/4.0 | Andreas Rheinhardt | Sun Jun 23 06:46:12 2019 +0200| [5ace41951948c6507926f13a924ff557bf7c2093] | committer: James Almer movsub_bsf: Fix mov2textsub regression The mov flavour of timed text uses the first two bytes of the packet as a length field. And up until 11bef2fe said length field has been read correctly in the mov2textsub bsf. But since then the next two bytes are read as if they were the length field. This is fixed in this commit. Reviewed-by: Philip Langdale Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer (cherry picked from commit 800f618a340d122754e7bdb82c22463cb9bd17b0) > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5ace41951948c6507926f13a924ff557bf7c2093 --- libavcodec/movsub_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c index 5878607061..cd48aa7bb8 100644 --- a/libavcodec/movsub_bsf.c +++ b/libavcodec/movsub_bsf.c @@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt) return AVERROR_INVALIDDATA; } -pkt->data += 2; pkt->size = FFMIN(pkt->size - 2, AV_RB16(pkt->data)); +pkt->data += 2; return 0; } ___ 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] movsub_bsf: Fix mov2textsub regression
ffmpeg | branch: release/4.1 | Andreas Rheinhardt | Sun Jun 23 06:46:12 2019 +0200| [b5229a0b3e422e0de5f0f3d06b354aa8abe901e3] | committer: James Almer movsub_bsf: Fix mov2textsub regression The mov flavour of timed text uses the first two bytes of the packet as a length field. And up until 11bef2fe said length field has been read correctly in the mov2textsub bsf. But since then the next two bytes are read as if they were the length field. This is fixed in this commit. Reviewed-by: Philip Langdale Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer (cherry picked from commit 800f618a340d122754e7bdb82c22463cb9bd17b0) > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b5229a0b3e422e0de5f0f3d06b354aa8abe901e3 --- libavcodec/movsub_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c index 5878607061..cd48aa7bb8 100644 --- a/libavcodec/movsub_bsf.c +++ b/libavcodec/movsub_bsf.c @@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt) return AVERROR_INVALIDDATA; } -pkt->data += 2; pkt->size = FFMIN(pkt->size - 2, AV_RB16(pkt->data)); +pkt->data += 2; return 0; } ___ 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] movsub_bsf: Fix mov2textsub regression
ffmpeg | branch: master | Andreas Rheinhardt | Sun Jun 23 06:46:12 2019 +0200| [800f618a340d122754e7bdb82c22463cb9bd17b0] | committer: James Almer movsub_bsf: Fix mov2textsub regression The mov flavour of timed text uses the first two bytes of the packet as a length field. And up until 11bef2fe said length field has been read correctly in the mov2textsub bsf. But since then the next two bytes are read as if they were the length field. This is fixed in this commit. Reviewed-by: Philip Langdale Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=800f618a340d122754e7bdb82c22463cb9bd17b0 --- libavcodec/movsub_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c index 5878607061..cd48aa7bb8 100644 --- a/libavcodec/movsub_bsf.c +++ b/libavcodec/movsub_bsf.c @@ -75,8 +75,8 @@ static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt) return AVERROR_INVALIDDATA; } -pkt->data += 2; pkt->size = FFMIN(pkt->size - 2, AV_RB16(pkt->data)); +pkt->data += 2; return 0; } ___ 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] libavcodec: Reduce the size of some arrays
ffmpeg | branch: master | Andreas Rheinhardt | Wed Jun 19 04:39:47 2019 +0200| [a1a8815220fcb844b645ce32cb1593e744798419] | committer: James Almer libavcodec: Reduce the size of some arrays This commit uses smaller types for some static const arrays to reduce their size in case the entries can be represented in the smaller type. The biggest savings came from inv_map_table in vp9.c. Reviewed-by: Michael Niedermayer Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a1a8815220fcb844b645ce32cb1593e744798419 --- libavcodec/a64multienc.c | 6 +++--- libavcodec/ac3enc.c | 2 +- libavcodec/adpcm.c| 8 libavcodec/aic.c | 4 ++-- libavcodec/atrac3plus.c | 12 ++-- libavcodec/atrac3plusdsp.c| 4 ++-- libavcodec/atrac9dec.c| 2 +- libavcodec/cbs_h264_syntax_template.c | 2 +- libavcodec/cbs_vp9_syntax_template.c | 4 ++-- libavcodec/vp9.c | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c index 91aac0933f..38f25020f5 100644 --- a/libavcodec/a64multienc.c +++ b/libavcodec/a64multienc.c @@ -60,11 +60,11 @@ typedef struct A64Context { } A64Context; /* gray gradient */ -static const int mc_colors[5]={0x0,0xb,0xc,0xf,0x1}; +static const uint8_t mc_colors[5]={0x0,0xb,0xc,0xf,0x1}; /* other possible gradients - to be tested */ -//static const int mc_colors[5]={0x0,0x8,0xa,0xf,0x7}; -//static const int mc_colors[5]={0x0,0x9,0x8,0xa,0x3}; +//static const uint8_t mc_colors[5]={0x0,0x8,0xa,0xf,0x7}; +//static const uint8_t mc_colors[5]={0x0,0x9,0x8,0xa,0x3}; static void to_meta_with_crop(AVCodecContext *avctx, const AVFrame *p, int *dest) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index e7e18af92d..f1c95ce877 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -652,7 +652,7 @@ void ff_ac3_process_exponents(AC3EncodeContext *s) */ static void count_frame_bits_fixed(AC3EncodeContext *s) { -static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; +static const uint8_t frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; int blk; int frame_bits; diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index ede0130bf1..e194764374 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -57,7 +57,7 @@ */ /* These are for CD-ROM XA ADPCM */ -static const int xa_adpcm_table[5][2] = { +static const int8_t xa_adpcm_table[5][2] = { { 0, 0 }, { 60, 0 }, { 115, -52 }, @@ -65,7 +65,7 @@ static const int xa_adpcm_table[5][2] = { { 122, -60 } }; -static const int ea_adpcm_table[] = { +static const int16_t ea_adpcm_table[] = { 0, 240, 460, 392, 0,0, -208, -220, 0,1,3,4, @@ -74,7 +74,7 @@ static const int ea_adpcm_table[] = { }; // padded to zero where table size is less then 16 -static const int swf_index_tables[4][16] = { +static const int8_t swf_index_tables[4][16] = { /*2*/ { -1, 2 }, /*3*/ { -1, -1, 2, 4 }, /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 }, @@ -484,7 +484,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ { ADPCMDecodeContext *c = avctx->priv_data; GetBitContext gb; -const int *table; +const int8_t *table; int k0, signmask, nb_bits, count; int size = buf_size*8; int i; diff --git a/libavcodec/aic.c b/libavcodec/aic.c index dc28c83661..956d71fcff 100644 --- a/libavcodec/aic.c +++ b/libavcodec/aic.c @@ -42,9 +42,9 @@ enum AICBands { NUM_BANDS }; -static const int aic_num_band_coeffs[NUM_BANDS] = { 64, 32, 192, 96 }; +static const uint8_t aic_num_band_coeffs[NUM_BANDS] = { 64, 32, 192, 96 }; -static const int aic_band_off[NUM_BANDS] = { 0, 64, 96, 288 }; +static const uint16_t aic_band_off[NUM_BANDS] = { 0, 64, 96, 288 }; static const uint8_t aic_quant_matrix[64] = { 8, 16, 19, 22, 22, 26, 26, 27, diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c index 3e3bba801b..9f964efb4d 100644 --- a/libavcodec/atrac3plus.c +++ b/libavcodec/atrac3plus.c @@ -81,8 +81,8 @@ av_cold void ff_atrac3p_init_vlcs(void) { int i, wl_vlc_offs, ct_vlc_offs, sf_vlc_offs, tab_offset; -static const int wl_nb_bits[4] = { 2, 3, 5, 5 }; -static const int wl_nb_codes[4] = { 3, 5, 8, 8 }; +static const uint8_t wl_nb_bits[4] = { 2, 3, 5, 5 }; +static const uint8_t wl_nb_codes[4] = { 3, 5, 8, 8 }; static const uint8_t * const wl_bits[4] = { atrac3p_wl_huff_bits1, atrac3p_wl_huff_bits2, atrac3p_wl_huff_bits3, atrac3p_wl_huff_bits4 @@ -95,8 +95,8 @@ av_cold void ff_atrac3p_init_vlcs(void) atrac3p_wl_huff_xlat1, atrac3p_wl_huff_xlat2, NULL, NULL }; -static const int ct_nb_bits[4] = { 3, 4, 4, 4 }; -static con
[FFmpeg-cvslog] avformat/matroskadec: Use generic size check for signed integers
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:50 2019 +0200| [e5ec1318562cba507171e4af74da65d2d45764dd] | committer: James Almer avformat/matroskadec: Use generic size check for signed integers and drop the redundant checks contained in ebml_read_uint and ebml_read_sint. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e5ec1318562cba507171e4af74da65d2d45764dd --- libavformat/matroskadec.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7ae73fda35..cb6908bf35 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -882,9 +882,6 @@ static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num) { int n = 0; -if (size > 8) -return AVERROR_INVALIDDATA; - /* big-endian ordering; build up number */ *num = 0; while (n++ < size) @@ -901,9 +898,6 @@ static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num) { int n = 1; -if (size > 8) -return AVERROR_INVALIDDATA; - if (size == 0) { *num = 0; } else { @@ -1161,6 +1155,7 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, { static const uint64_t max_lengths[EBML_TYPE_COUNT] = { [EBML_UINT] = 8, +[EBML_SINT] = 8, [EBML_FLOAT] = 8, // max. 16 MB for strings [EBML_STR] = 0x100, ___ 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/matroskadec: Don't copy attached pictures
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:52 2019 +0200| [07d4056052081b0157cf529dc2708834f8df9885] | committer: James Almer avformat/matroskadec: Don't copy attached pictures This commit replaces copying attached pictures by using references to the already existing buffers. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07d4056052081b0157cf529dc2708834f8df9885 --- libavformat/matroskadec.c | 16 ++-- 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3b8ddc5ecb..7ae73fda35 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2715,15 +2715,19 @@ static int matroska_read_header(AVFormatContext *s) attachments[j].stream = st; if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { +AVPacket *pkt = >attached_pic; + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; -av_init_packet(>attached_pic); -if ((res = av_new_packet(>attached_pic, attachments[j].bin.size)) < 0) -return res; -memcpy(st->attached_pic.data, attachments[j].bin.data, attachments[j].bin.size); -st->attached_pic.stream_index = st->index; -st->attached_pic.flags |= AV_PKT_FLAG_KEY; +av_init_packet(pkt); +pkt->buf = av_buffer_ref(attachments[j].bin.buf); +if (!pkt->buf) +return AVERROR(ENOMEM); +pkt->data = attachments[j].bin.data; +pkt->size = attachments[j].bin.size; +pkt->stream_index = st->index; +pkt->flags |= AV_PKT_FLAG_KEY; } else { st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; if (ff_alloc_extradata(st->codecpar, attachments[j].bin.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/matroskadec: Don't keep old blocks
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:59 2019 +0200| [ffa64a4db8ba37face9508caee0cf25efff70c4a] | committer: James Almer avformat/matroskadec: Don't keep old blocks Before this commit, the Matroska muxer would read a block when required to do so, parse the block, create and return the necessary AVPackets and yet keep the blocks (in a dynamically allocated list), although they aren't used at all any more. This has been changed. There is no list any more and the block is immediately discarded after parsing. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ffa64a4db8ba37face9508caee0cf25efff70c4a --- libavformat/matroskadec.c | 87 +-- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index b594bc4a95..c449edf7dd 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -304,9 +304,20 @@ typedef struct MatroskaLevel { uint64_t length; } MatroskaLevel; +typedef struct MatroskaBlock { +uint64_t duration; +int64_t reference; +uint64_t non_simple; +EbmlBin bin; +uint64_t additional_id; +EbmlBin additional; +int64_t discard_padding; +} MatroskaBlock; + typedef struct MatroskaCluster { +MatroskaBlock block; uint64_t timecode; -EbmlList blocks; +int64_t pos; } MatroskaCluster; typedef struct MatroskaLevel1Element { @@ -356,8 +367,6 @@ typedef struct MatroskaDemuxContext { MatroskaLevel1Element level1_elems[64]; int num_level1_elems; -int current_cluster_num_blocks; -int64_t current_cluster_pos; MatroskaCluster current_cluster; /* WebM DASH Manifest live flag */ @@ -367,16 +376,6 @@ typedef struct MatroskaDemuxContext { int bandwidth; } MatroskaDemuxContext; -typedef struct MatroskaBlock { -uint64_t duration; -int64_t reference; -uint64_t non_simple; -EbmlBin bin; -uint64_t additional_id; -EbmlBin additional; -int64_t discard_padding; -} MatroskaBlock; - static const EbmlSyntax ebml_header[] = { { EBML_ID_EBMLREADVERSION,EBML_UINT, 0, offsetof(Ebml, version), { .u = EBML_VERSION } }, { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml, max_size), { .u = 8 } }, @@ -705,9 +704,9 @@ static const EbmlSyntax matroska_blockgroup[] = { }; static const EbmlSyntax matroska_cluster_parsing[] = { -{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, -{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, -{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, +{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, +{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, +{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, { MATROSKA_ID_INFO,EBML_NONE }, @@ -3452,57 +3451,48 @@ end: static int matroska_parse_cluster(MatroskaDemuxContext *matroska) { -EbmlList *blocks_list; -MatroskaBlock *blocks; -int i, res; +MatroskaCluster *cluster = >current_cluster; +MatroskaBlock *block = >block; +int res; res = ebml_parse(matroska, matroska_cluster_parsing, - >current_cluster); + cluster); if (res == 1) { /* New Cluster */ -if (matroska->current_cluster_pos) +if (cluster->pos) ebml_level_end(matroska); -ebml_free(matroska_cluster_parsing, >current_cluster); -memset(>current_cluster, 0, sizeof(MatroskaCluster)); -matroska->current_cluster_num_blocks = 0; -matroska->current_cluster_pos= avio_tell(matroska->ctx->pb); +cluster->pos = avio_tell(matroska->ctx->pb); /* sizeof the ID which was already read */ if (matroska->current_id) -matroska->current_cluster_pos -= 4; +cluster->pos -= 4; res = ebml_parse(matroska, matroska_clusters, - >current_cluster); + cluster); /* Try parsing the block again. */ if (res == 1) res = ebml_parse(matroska, matroska_cluster_parsing, - >current_cluster); + cluster); } -if (!res && -matroska->current_cluster_num_blocks < -matroska->current_cluster.blocks.nb_elem) { -bl
[FFmpeg-cvslog] avformat/matroskadec: Remove redundant initialization
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:53 2019 +0200| [f3ca3e7f19c86563c2d3bca82962567396b1cc13] | committer: James Almer avformat/matroskadec: Remove redundant initialization Every new element of an EbmlList is zeroed initially in ebml_parse_elem, so that in particular a SimpleBlock's duration is initialized to zero. Therefore it is unnecessary to initialize this field again (for SimpleBlocks) in matroska_parse_cluster_incremental. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f3ca3e7f19c86563c2d3bca82962567396b1cc13 --- libavformat/matroskadec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d516ef37c7..b594bc4a95 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3491,8 +3491,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1; uint8_t* additional = blocks[i].additional.size > 0 ? blocks[i].additional.data : NULL; -if (!blocks[i].non_simple) -blocks[i].duration = 0; + res = matroska_parse_block(matroska, blocks[i].bin.buf, blocks[i].bin.data, blocks[i].bin.size, blocks[i].bin.pos, matroska->current_cluster.timecode, ___ 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/matroskadec: Get rid of cluster size field assumption
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:49 2019 +0200| [36aceb6174a6a1c40014001ff73c4c30012b569d] | committer: James Almer avformat/matroskadec: Get rid of cluster size field assumption The earlier code relied on the length of clusters always being coded on eight bytes as was the behaviour of libavformat's Matroska muxer until recently. But given that our own Matroska muxer now (and mkvmerge from time immemorial) creates files that don't conform to this assumption, it is high time to get rid of this assumption. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=36aceb6174a6a1c40014001ff73c4c30012b569d --- libavformat/matroskadec.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 1b0db92595..09b5cf3a28 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3656,15 +3656,17 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) cluster_pos = s->streams[0]->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { -int64_t cluster_id = 0, cluster_length = 0; +uint64_t cluster_id, cluster_length; +int read; AVPacket *pkt; avio_seek(s->pb, cluster_pos, SEEK_SET); // read cluster id and length -ebml_read_num(matroska, matroska->ctx->pb, 4, _id); -ebml_read_length(matroska, matroska->ctx->pb, _length); -if (cluster_id != 0xF43B675) { // done with all clusters +read = ebml_read_num(matroska, matroska->ctx->pb, 4, _id); +if (read < 0 || cluster_id != 0xF43B675) // done with all clusters +break; +read = ebml_read_length(matroska, matroska->ctx->pb, _length); +if (read < 0) break; -} avio_seek(s->pb, cluster_pos, SEEK_SET); matroska->current_id = 0; matroska_clear_queue(matroska); @@ -3673,7 +3675,8 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) break; } pkt = >queue->pkt; -cluster_pos += cluster_length + 12; // 12 is the offset of the cluster id and length. +// 4 + read is the length of the cluster id and the cluster length field. +cluster_pos += 4 + read + cluster_length; if (!(pkt->flags & AV_PKT_FLAG_KEY)) { rv = 0; break; ___ 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/matroskadec: Set offset of first cluster
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:51 2019 +0200| [43c3cebbd4c09dd4d2f9122b38f23eddfe7cadbe] | committer: James Almer avformat/matroskadec: Set offset of first cluster By default, the data_offset member of the AVFormatInternal of the AVFormatContext associated with the MatroskaDemuxContext has not been initialized explicitly by any Matroska-specific function, so that it was initialized by default to the offset at the end of matroska_read_header, i.e. usually to the offset of the length field of the first encountered cluster. This meant that in case that the Matroska-specific seek-code fails because there are no index entries for the target track a seek to data_offset would be performed and ordinary parsing would start from there which is nonsense: The length field would be treated as EBML ID and (if the length field is not longer than four bytes (EBML numbers that long are rejected as invalid EBML IDs)) whatever comes next would be treated as its EBML size although it simply isn't. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43c3cebbd4c09dd4d2f9122b38f23eddfe7cadbe --- libavformat/matroskadec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 09b5cf3a28..d516ef37c7 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2646,6 +2646,9 @@ static int matroska_read_header(AVFormatContext *s) pos = avio_tell(matroska->ctx->pb); res = ebml_parse(matroska, matroska_segment, matroska); } +/* Set data_offset as it might be needed later by seek_frame_generic. */ +if (matroska->current_id == MATROSKA_ID_CLUSTER) +s->internal->data_offset = avio_tell(matroska->ctx->pb) - 4; matroska_execute_seekhead(matroska); if (!matroska->time_scale) ___ 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/matroskadec: Remove non-incremental parsing of clusters
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:29:58 2019 +0200| [70baf729b536be532ef1de9a28b584f19e62eeeb] | committer: James Almer avformat/matroskadec: Remove non-incremental parsing of clusters When the new incremental parser was introduced, the old parser was kept, because the new parser was unable to handle the way SSA packets are put into Matroska. But since 2014 (since c7d8dbad) this is no longer needed, so that the old parser can be completely removed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=70baf729b536be532ef1de9a28b584f19e62eeeb --- libavformat/matroskadec.c | 72 +++ 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index cb6908bf35..1b0db92595 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -360,9 +360,6 @@ typedef struct MatroskaDemuxContext { int64_t current_cluster_pos; MatroskaCluster current_cluster; -/* File has SSA subtitles which prevent incremental cluster parsing. */ -int contains_ssa; - /* WebM DASH Manifest live flag */ int is_live; @@ -707,25 +704,7 @@ static const EbmlSyntax matroska_blockgroup[] = { { 0 } }; -static const EbmlSyntax matroska_cluster[] = { -{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, -{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, -{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, -{ MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, -{ MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, -{ 0 } -}; - -static const EbmlSyntax matroska_clusters[] = { -{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster } }, -{ MATROSKA_ID_INFO, EBML_NONE }, -{ MATROSKA_ID_CUES, EBML_NONE }, -{ MATROSKA_ID_TAGS, EBML_NONE }, -{ MATROSKA_ID_SEEKHEAD, EBML_NONE }, -{ 0 } -}; - -static const EbmlSyntax matroska_cluster_incremental_parsing[] = { +static const EbmlSyntax matroska_cluster_parsing[] = { { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, @@ -739,7 +718,7 @@ static const EbmlSyntax matroska_cluster_incremental_parsing[] = { { 0 } }; -static const EbmlSyntax matroska_cluster_incremental[] = { +static const EbmlSyntax matroska_cluster[] = { { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, @@ -748,8 +727,8 @@ static const EbmlSyntax matroska_cluster_incremental[] = { { 0 } }; -static const EbmlSyntax matroska_clusters_incremental[] = { -{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster_incremental } }, +static const EbmlSyntax matroska_clusters[] = { +{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster } }, { MATROSKA_ID_INFO, EBML_NONE }, { MATROSKA_ID_CUES, EBML_NONE }, { MATROSKA_ID_TAGS, EBML_NONE }, @@ -2602,8 +2581,6 @@ static int matroska_parse_tracks(AVFormatContext *s) } } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; -if (st->codecpar->codec_id == AV_CODEC_ID_ASS) -matroska->contains_ssa = 1; } } @@ -3470,19 +3447,19 @@ end: return res; } -static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska) +static int matroska_parse_cluster(MatroskaDemuxContext *matroska) { EbmlList *blocks_list; MatroskaBlock *blocks; int i, res; res = ebml_parse(matroska, - matroska_cluster_incremental_parsing, + matroska_cluster_parsing, >current_cluster); if (res == 1) { /* New Cluster */ if (matroska->current_cluster_pos) ebml_level_end(matroska); -ebml_free(matroska_cluster, >current_cluster); +ebml_free(matroska_cluster_parsing, >current_cluster); memset(>current_cluster, 0, sizeof(MatroskaCluster)); matroska->current_cluster_num_blocks = 0; matroska->current_cluster_pos= avio_tell(matroska->ctx->pb); @@ -3490,12 +3467,12 @@ static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska) if (matroska->cur
[FFmpeg-cvslog] avformat/matroskadec: Treat SimpleBlock as EBML_BIN
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:00 2019 +0200| [bc3306fd5b272730bb4bc2c571d575fed75a1ce4] | committer: James Almer avformat/matroskadec: Treat SimpleBlock as EBML_BIN Up until now, the SimpleBlock was treated specially: It basically had its own EBML category and it was also included in the BlockGroup EBML syntax (although a SimpleBlock must not exist in a BlockGroup according to the Matroska specifications). The latter fact also meant that a MatroskaBlock's buffer was always unreferenced twice. This has been changed: The type of a SimpleBlock is now an EBML_BIN. The only way in which SimpleBlocks are still different is that they share their associated structure with another unit (namely BlockGroup). This is also used to unref the block: It is always unreferenced via the BlockGroup syntax. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bc3306fd5b272730bb4bc2c571d575fed75a1ce4 --- libavformat/matroskadec.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index c449edf7dd..09665fb680 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -79,7 +79,6 @@ typedef enum { EBML_BIN, EBML_NEST, EBML_LEVEL1, -EBML_PASS, EBML_STOP, EBML_SINT, EBML_TYPE_COUNT @@ -694,7 +693,6 @@ static const EbmlSyntax matroska_blockadditions[] = { static const EbmlSyntax matroska_blockgroup[] = { { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, { MATROSKA_ID_BLOCKADDITIONS, EBML_NEST, 0, 0, { .n = matroska_blockadditions} }, -{ MATROSKA_ID_SIMPLEBLOCK,EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock, duration) }, { MATROSKA_ID_DISCARDPADDING, EBML_SINT, 0, offsetof(MatroskaBlock, discard_padding) }, { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, reference), { .i = INT64_MIN } }, @@ -706,7 +704,7 @@ static const EbmlSyntax matroska_blockgroup[] = { static const EbmlSyntax matroska_cluster_parsing[] = { { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, -{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, 0, 0, { .n = matroska_blockgroup } }, +{ MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, { MATROSKA_ID_INFO,EBML_NONE }, @@ -1161,7 +1159,7 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, list->nb_elem++; } -if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) { +if (syntax->type != EBML_STOP) { matroska->current_id = 0; if ((res = ebml_read_length(matroska, pb, )) < 0) return res; @@ -1235,8 +1233,6 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, level1_elem->parsed = 1; } return ebml_parse_nest(matroska, syntax->def.n, data); -case EBML_PASS: -return ebml_parse_id(matroska, syntax->def.n, id, data); case EBML_STOP: return 1; default: ___ 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] lavf/webm_chunk: Respect buffer size
ffmpeg | branch: release/3.2 | Andreas Rheinhardt | Sat Apr 20 00:03:14 2019 +0200| [9fad760f56483f0b5503457c780d9f80a84784c6] | committer: Michael Niedermayer lavf/webm_chunk: Respect buffer size The last argument of av_strlcpy is supposed to contain the size of the destination buffer, but it was filled with the size of the source string, effectively negating its very purpose. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer (cherry picked from commit 73ef1f47f5928264a968c8fbbcfb0bf0643f) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9fad760f56483f0b5503457c780d9f80a84784c6 --- libavformat/webm_chunk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index f8dbaa3339..3f91162da7 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -96,7 +96,7 @@ static int get_chunk_filename(AVFormatContext *s, int is_header, char *filename) av_log(oc, AV_LOG_ERROR, "No header filename provided\n"); return AVERROR(EINVAL); } -av_strlcpy(filename, wc->header_filename, strlen(wc->header_filename) + 1); +av_strlcpy(filename, wc->header_filename, MAX_FILENAME_SIZE); } else { if (av_get_frame_filename(filename, MAX_FILENAME_SIZE, s->filename, wc->chunk_index - 1) < 0) { ___ 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] avutil: Add missing reference files for pixdesc fate test
ffmpeg | branch: master | Andreas Rheinhardt | Tue May 14 07:53:13 2019 +0200| [8b2140de6314f9ea9ebbaf6a127cca35306d8a67] | committer: Michael Niedermayer avutil: Add missing reference files for pixdesc fate test Commit cd48318035 added support for NV24 and NV42, including several fate tests for these formats, but did not include the reference files for the tests filter-pixdesc-nv24 and filter-pixdesc-nv42. As a result, these two tests were broken. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b2140de6314f9ea9ebbaf6a127cca35306d8a67 --- tests/ref/fate/filter-pixdesc-nv24 | 1 + tests/ref/fate/filter-pixdesc-nv42 | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/ref/fate/filter-pixdesc-nv24 b/tests/ref/fate/filter-pixdesc-nv24 new file mode 100644 index 00..ce07331997 --- /dev/null +++ b/tests/ref/fate/filter-pixdesc-nv24 @@ -0,0 +1 @@ +pixdesc-nv247437f36b6ee58050564b20a1f839ff07 diff --git a/tests/ref/fate/filter-pixdesc-nv42 b/tests/ref/fate/filter-pixdesc-nv42 new file mode 100644 index 00..88ef431a1b --- /dev/null +++ b/tests/ref/fate/filter-pixdesc-nv42 @@ -0,0 +1 @@ +pixdesc-nv42110bad2f58424ab800ad832f6966cafe ___ 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/matroskaenc: Simplify check for writing CRCs
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:01 2019 +0200| [30d07c74dbd9384e50535cfedde5237114a81bee] | committer: James Almer avformat/matroskaenc: Simplify check for writing CRCs Up until now, the check for whether to write CRC32 elements was always mkv->write_crc && mkv->mode != MODE_WEBM. This is equivalent to simply set write_crc to zero in WebM-mode. And this is what this commit does. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=30d07c74dbd9384e50535cfedde5237114a81bee --- libavformat/matroskaenc.c | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 75863659bc..e62346963e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -341,7 +341,7 @@ static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matros if (pb->seekable & AVIO_SEEKABLE_NORMAL) { *master = start_ebml_master(pb, elementid, expectedsize); -if (mkv->write_crc && mkv->mode != MODE_WEBM) +if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ } else *master = start_ebml_master(*dyn_cp, elementid, expectedsize); @@ -357,7 +357,7 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk if (pb->seekable & AVIO_SEEKABLE_NORMAL) { size = avio_close_dyn_buf(*dyn_cp, ); -if (mkv->write_crc && mkv->mode != MODE_WEBM) { +if (mkv->write_crc) { skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); @@ -1867,9 +1867,10 @@ static int mkv_write_header(AVFormatContext *s) int ret, i, version = 2; int64_t creation_time; -if (!strcmp(s->oformat->name, "webm")) -mkv->mode = MODE_WEBM; -else +if (!strcmp(s->oformat->name, "webm")) { +mkv->mode = MODE_WEBM; +mkv->write_crc = 0; +} else mkv->mode = MODE_MATROSKAv2; if (mkv->mode != MODE_WEBM || ___ 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/matroskaenc: Improve log messages for blocks
ffmpeg | branch: master | Andreas Rheinhardt | Tue Apr 23 21:45:52 2019 +0200| [9b932a855e4416a1a7fe207cc8af0782b96823ee] | committer: James Almer avformat/matroskaenc: Improve log messages for blocks Up until now, a block's relative offset has been reported as the offset in the log messages output when writing blocks; given that it is impossible to know the real offset from the beginning of the file at this point due to the fact that it is not yet known how many bytes will be used for the containing cluster's length field both the relative offset in the cluster as well as the offset of the containing cluster will be reported from now on. Furthermore, the TrackNumber of the written block has been added to the log output. Also, the log message for writing vtt blocks has been brought in line with the message for normal blocks. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b932a855e4416a1a7fe207cc8af0782b96823ee --- libavformat/matroskaenc.c | 23 --- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 441315e2d5..01ccc9524c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2124,10 +2124,14 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, ts += mkv->tracks[pkt->stream_index].ts_offset; -av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " - "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", keyframe %d\n", - avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, - keyframe != 0); +/* The following string is identical to the one in mkv_write_vtt_blocks + * so that only one copy needs to exist in binaries. */ +av_log(s, AV_LOG_DEBUG, + "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", " + "duration %" PRId64 " at relative offset %" PRId64 " in cluster " + "at offset %" PRId64 ". TrackNumber %d, keyframe %d\n", + pkt->size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb), + mkv->cluster_pos, track_number, keyframe != 0); if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 && (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) ff_avc_parse_nal_units_buf(pkt->data, , ); @@ -2231,9 +2235,14 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *p size = id_size + 1 + settings_size + 1 + pkt->size; -av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " - "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", flags %d\n", - avio_tell(pb), size, pkt->pts, pkt->dts, pkt->duration, flags); +/* The following string is identical to the one in mkv_write_block so that + * only one copy needs to exist in binaries. */ +av_log(s, AV_LOG_DEBUG, + "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", " + "duration %" PRId64 " at relative offset %" PRId64 " in cluster " + "at offset %" PRId64 ". TrackNumber %d, keyframe %d\n", + size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb), + mkv->cluster_pos, pkt->stream_index + 1, 1); blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(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/matroskaenc: Change variable types
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:04 2019 +0200| [8f53fd2dfdea9f5fac4c49e6475e75fc2f59ef1e] | committer: James Almer avformat/matroskaenc: Change variable types A Matroska EBML ID can only be maximally four bytes long, so make the variables denoting EBML IDs uint32_t instead of unsigned int to better reflect this. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8f53fd2dfdea9f5fac4c49e6475e75fc2f59ef1e --- libavformat/matroskaenc.c | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 316a632805..0be33419eb 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -63,7 +63,7 @@ typedef struct ebml_master { } ebml_master; typedef struct mkv_seekhead_entry { -unsigned intelementid; +uint32_telementid; uint64_tsegmentpos; } mkv_seekhead_entry; @@ -182,12 +182,12 @@ typedef struct MatroskaMuxContext { /** Seek preroll value for opus */ #define OPUS_SEEK_PREROLL 8000 -static int ebml_id_size(unsigned int id) +static int ebml_id_size(uint32_t id) { return (av_log2(id + 1) - 1) / 7 + 1; } -static void put_ebml_id(AVIOContext *pb, unsigned int id) +static void put_ebml_id(AVIOContext *pb, uint32_t id) { int i = ebml_id_size(id); while (i--) @@ -242,7 +242,7 @@ static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes) avio_w8(pb, (uint8_t)(num >> i * 8)); } -static void put_ebml_uint(AVIOContext *pb, unsigned int elementid, uint64_t val) +static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val) { int i, bytes = 1; uint64_t tmp = val; @@ -255,7 +255,7 @@ static void put_ebml_uint(AVIOContext *pb, unsigned int elementid, uint64_t val) avio_w8(pb, (uint8_t)(val >> i * 8)); } -static void put_ebml_sint(AVIOContext *pb, unsigned int elementid, int64_t val) +static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val) { int i, bytes = 1; uint64_t tmp = 2*(val < 0 ? val^-1 : val); @@ -268,14 +268,14 @@ static void put_ebml_sint(AVIOContext *pb, unsigned int elementid, int64_t val) avio_w8(pb, (uint8_t)(val >> i * 8)); } -static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val) +static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val) { put_ebml_id(pb, elementid); put_ebml_num(pb, 8, 0); avio_wb64(pb, av_double2int(val)); } -static void put_ebml_binary(AVIOContext *pb, unsigned int elementid, +static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size) { put_ebml_id(pb, elementid); @@ -283,7 +283,7 @@ static void put_ebml_binary(AVIOContext *pb, unsigned int elementid, avio_write(pb, buf, size); } -static void put_ebml_string(AVIOContext *pb, unsigned int elementid, +static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str) { put_ebml_binary(pb, elementid, str, strlen(str)); @@ -312,7 +312,7 @@ static void put_ebml_void(AVIOContext *pb, uint64_t size) ffio_fill(pb, 0, currentpos + size - avio_tell(pb)); } -static ebml_master start_ebml_master(AVIOContext *pb, unsigned int elementid, +static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize) { int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; @@ -332,7 +332,7 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) } static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master *master, unsigned int elementid, uint64_t expectedsize) + ebml_master *master, uint32_t elementid, uint64_t expectedsize) { int ret; @@ -463,7 +463,7 @@ static mkv_seekhead *mkv_start_seekhead(AVIOContext *pb, int64_t segment_offset, return new_seekhead; } -static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos) +static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, uint32_t elementid, uint64_t filepos) { mkv_seekhead_entry *entries = seekhead->entries; @@ -1575,7 +1575,7 @@ static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) } static int mkv_write_tag_targets(AVFormatContext *s, - unsigned int elementid, unsigned int uid, + uint32_t elementid, unsigned int uid, ebml_master *tags, ebml_master* tag) { AVIOContext *pb; @@ -1599,7 +1599,7 @@ static int mkv_write_tag_targets(AVFormatContext *s, return 0; } -static int mkv_check_tag_name
[FFmpeg-cvslog] avformat/matroskaenc: Don't waste bytes writing level 1 elements
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:08 2019 +0200| [0b61ddb5766c8d5219150371db0649ff0cec730a] | committer: James Almer avformat/matroskaenc: Don't waste bytes writing level 1 elements Up until now, the length field of most level 1 elements has been written using eight bytes, although it is known in advance how much space the content of said elements will take up so that it would be possible to determine the minimal amount of bytes for the length field. This commit changes this. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b61ddb5766c8d5219150371db0649ff0cec730a --- libavformat/matroskaenc.c| 29 tests/fate/matroska.mak | 2 +- tests/fate/wavpack.mak | 4 ++-- tests/ref/fate/aac-autobsf-adtstoasc | 4 ++-- tests/ref/fate/binsub-mksenc | 2 +- tests/ref/fate/rgb24-mkv | 4 ++-- tests/ref/lavf/mka | 4 ++-- tests/ref/lavf/mkv | 4 ++-- tests/ref/lavf/mkv_attachment| 4 ++-- tests/ref/seek/lavf-mkv | 44 ++-- 10 files changed, 50 insertions(+), 51 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 15164bd87c..441315e2d5 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -60,7 +60,7 @@ typedef struct ebml_master { int64_t pos;///< absolute offset in the containing AVIOContext where the size field starts ///< for level 1 elements or else where the master's elements start -int sizebytes; ///< how many bytes were reserved/shall be used for the size +int sizebytes; ///< how many bytes were reserved for the size } ebml_master; typedef struct mkv_seekhead_entry { @@ -334,15 +334,15 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) } static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master *master, uint32_t elementid, uint64_t expectedsize) + ebml_master *master, uint32_t elementid) { -int ret, bytes = expectedsize ? ebml_num_size(expectedsize) : 8; +int ret; if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; put_ebml_id(pb, elementid); -*master = (ebml_master) { avio_tell(pb), bytes }; +*master = (ebml_master) { avio_tell(pb), 0 }; if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ @@ -356,7 +356,7 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk int size, skip = 0; size = avio_close_dyn_buf(*dyn_cp, ); -put_ebml_num(pb, size, master.sizebytes); +put_ebml_num(pb, size, 0); if (mkv->write_crc) { skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); @@ -377,7 +377,7 @@ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, ); -put_ebml_num(pb, size, master.sizebytes); +put_ebml_num(pb, size, 0); avio_write(pb, buf, size); } @@ -502,8 +502,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) } } -if (start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_SEEKHEAD, -seekhead->reserved_size) < 0) { +if (start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_SEEKHEAD) < 0) { currentpos = -1; goto fail; } @@ -578,7 +577,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra int i, j, ret; currentpos = avio_tell(pb); -ret = start_ebml_master_crc32(pb, _cp, mkv, _element, MATROSKA_ID_CUES, 0); +ret = start_ebml_master_crc32(pb, _cp, mkv, _element, MATROSKA_ID_CUES); if (ret < 0) return ret; @@ -1454,7 +1453,7 @@ static int mkv_write_tracks(AVFormatContext *s) if (ret < 0) return ret; -ret = start_ebml_master_crc32(pb, >tracks_bc, mkv, >tracks_master, MATROSKA_ID_TRACKS, 0); +ret = start_ebml_master_crc32(pb, >tracks_bc, mkv, >tracks_master, MATROSKA_ID_TRACKS); if (ret < 0) return ret; @@ -1490,7 +1489,7 @@ static int mkv_write_chapters(AVFormatContext *s) ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb)); if (ret < 0) return ret; -ret = start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_CHAPTERS, 0); +ret = s
[FFmpeg-cvslog] avformat/matroskaenc: Improve log message
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:02 2019 +0200| [924424d86781a5cfa4b59910f5f305e5ac348b4e] | committer: James Almer avformat/matroskaenc: Improve log message Since 4e3bdf729a80f868b014ceb02901d87198b545a5 there is no reason any more to treat the seekable and non-seekable cases separate with regards to the log message for a new cluster. This effectively reverts d41aeea8a64bab5d7aacd602f7214f95baad109f. Also improved the log message: "pts 80dts 0" -> "pts 80, dts 0". Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=924424d86781a5cfa4b59910f5f305e5ac348b4e --- libavformat/matroskaenc.c | 10 +- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index e62346963e..b300b23938 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2265,15 +2265,10 @@ static void mkv_start_new_cluster(AVFormatContext *s, AVPacket *pkt) end_ebml_master_crc32(s->pb, >dyn_bc, mkv, mkv->cluster); mkv->cluster_pos = -1; -if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 " bytes, " - "pts %" PRIu64 "dts %" PRIu64 "\n", + "pts %" PRIu64 ", dts %" PRIu64 "\n", avio_tell(s->pb), pkt->pts, pkt->dts); -else -av_log(s, AV_LOG_DEBUG, "Starting new cluster, " - "pts %" PRIu64 "dts %" PRIu64 "\n", - pkt->pts, pkt->dts); avio_flush(s->pb); } @@ -2551,12 +2546,9 @@ static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt) if (mkv->cluster_pos != -1) { end_ebml_master_crc32(s->pb, >dyn_bc, mkv, mkv->cluster); mkv->cluster_pos = -1; -if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) av_log(s, AV_LOG_DEBUG, "Flushing cluster at offset %" PRIu64 " bytes\n", avio_tell(s->pb)); -else -av_log(s, AV_LOG_DEBUG, "Flushing cluster\n"); avio_flush(s->pb); } return 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] avformat/matroskaenc: Cosmetics and typo
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:07 2019 +0200| [08f5d972994ef7160767d1bd99ef59b177db3199] | committer: James Almer avformat/matroskaenc: Cosmetics and typo Fixes intendation, whitespace, a typo and renames a variable (dyn_bc->cluster_bc) to make its meaning clearer and to bring it more in line with the naming of similar variables. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=08f5d972994ef7160767d1bd99ef59b177db3199 --- libavformat/matroskaenc.c | 103 +++--- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index d9a7ca9ad1..15164bd87c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -119,9 +119,8 @@ typedef struct mkv_attachments { #define MAX_TRACKS 126 typedef struct MatroskaMuxContext { -const AVClass *class; +const AVClass *class; int mode; -AVIOContext *dyn_bc; AVIOContext *tags_bc; ebml_master tags; AVIOContext *info_bc; @@ -130,6 +129,7 @@ typedef struct MatroskaMuxContext { ebml_master tracks_master; ebml_master segment; int64_t segment_offset; +AVIOContext *cluster_bc; ebml_master cluster; int64_t cluster_pos;///< file offset of the current cluster int64_t cluster_pts; @@ -159,8 +159,8 @@ typedef struct MatroskaMuxContext { int64_t last_track_timestamp[MAX_TRACKS]; -int64_t* stream_durations; -int64_t* stream_duration_offsets; +int64_t *stream_durations; +int64_t *stream_duration_offsets; int allow_raw_vfw; } MatroskaMuxContext; @@ -320,7 +320,7 @@ static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, put_ebml_id(pb, elementid); put_ebml_size_unknown(pb, bytes); -return (ebml_master) {avio_tell(pb), bytes }; +return (ebml_master) { avio_tell(pb), bytes }; } static void end_ebml_master(AVIOContext *pb, ebml_master master) @@ -341,10 +341,10 @@ static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matros if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; -put_ebml_id(pb, elementid); -*master = (ebml_master) { avio_tell(pb), bytes }; -if (mkv->write_crc) -put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ +put_ebml_id(pb, elementid); +*master = (ebml_master) { avio_tell(pb), bytes }; +if (mkv->write_crc) +put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ return 0; } @@ -355,31 +355,30 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk uint8_t *buf, crc[4]; int size, skip = 0; -size = avio_close_dyn_buf(*dyn_cp, ); -put_ebml_num(pb, size, master.sizebytes); -if (mkv->write_crc) { -skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ -AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); -put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); -} -avio_write(pb, buf + skip, size - skip); +size = avio_close_dyn_buf(*dyn_cp, ); +put_ebml_num(pb, size, master.sizebytes); +if (mkv->write_crc) { +skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ +AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); +put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); +} +avio_write(pb, buf + skip, size - skip); av_free(buf); *dyn_cp = NULL; } /** -* Complete ebml master whithout destroying the buffer, allowing for later updates +* Complete ebml master without destroying the buffer, allowing for later updates */ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, -ebml_master master) + ebml_master master) { - -uint8_t *buf; -int size = avio_get_dyn_buf(*dyn_cp, ); +uint8_t *buf; +int size = avio_get_dyn_buf(*dyn_cp, ); put_ebml_num(pb, size, master.sizebytes); -avio_write(pb, buf, size); +avio_write(pb, buf, size); } static void put_xiph_size(AVIOContext *pb, int size) @@ -393,8 +392,8 @@ static void put_xiph_size(AVIOContext *pb, int size) */ static void mkv_free(MatroskaMuxContext *mkv) { uint8_t* buf; -if (mkv->dyn_bc) { -avio_close_dyn_buf(mkv->dyn_bc, ); +if (mkv->cluster_bc) { +avio_close_dyn_buf(mkv->cluster_bc, );
[FFmpeg-cvslog] avformat/matroskaenc: Fix relative timestamp check
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:40:56 2019 +0200| [4ebeab15b037a21f195696cef1f7522daf42f3ee] | committer: James Almer avformat/matroskaenc: Fix relative timestamp check At this point, ts already includes the ts_offset so that the relative time written with the cluster is already given by ts - mkv->cluster_pts. It is this number that needs to fit into an int16_t. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4ebeab15b037a21f195696cef1f7522daf42f3ee --- libavformat/matroskaenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 1c98c0dceb..c006cbf35c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2404,7 +2404,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ ts += mkv->tracks[pkt->stream_index].ts_offset; if (mkv->cluster_pos != -1) { -int64_t cluster_time = ts - mkv->cluster_pts + mkv->tracks[pkt->stream_index].ts_offset; +int64_t cluster_time = ts - mkv->cluster_pts; if ((int16_t)cluster_time != cluster_time) { av_log(s, AV_LOG_WARNING, "Starting new cluster due to timestamp\n"); mkv_start_new_cluster(s, pkt); ___ 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/matroskaenc: Avoid seeking when writing level 1 elements
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:05 2019 +0200| [e04a24e70148e330bcdcfd7c049acbe1a821398f] | committer: James Almer avformat/matroskaenc: Avoid seeking when writing level 1 elements Up until now, the writing process for level 1 elements (those elements for which CRC-32 elements are written by default) was this in case the output was seekable: Write the EBML ID, write an "unkown length" EBML number of the desired length, then write the element into a dynamic buffer, then write the dynamic buffer (after possible calculation and writing of the CRC-element), then seek back to the size element and overwrite the unknown-size element with the real size. The seeking and overwriting part has been eliminated by not writing the size initially. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e04a24e70148e330bcdcfd7c049acbe1a821398f --- libavformat/matroskaenc.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 0be33419eb..2875552469 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -58,8 +58,9 @@ #include "libavcodec/internal.h" typedef struct ebml_master { -int64_t pos;///< absolute offset in the file where the master's elements start -int sizebytes; ///< how many bytes were reserved for the size +int64_t pos;///< absolute offset in the containing AVIOContext where the size field starts +///< for level 1 elements or else where the master's elements start +int sizebytes; ///< how many bytes were reserved/shall be used for the size } ebml_master; typedef struct mkv_seekhead_entry { @@ -316,6 +317,7 @@ static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize) { int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; + put_ebml_id(pb, elementid); put_ebml_size_unknown(pb, bytes); return (ebml_master) {avio_tell(pb), bytes }; @@ -340,7 +342,10 @@ static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matros return ret; if (pb->seekable & AVIO_SEEKABLE_NORMAL) { -*master = start_ebml_master(pb, elementid, expectedsize); +int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; + +put_ebml_id(pb, elementid); +*master = (ebml_master) { avio_tell(pb), bytes }; if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ } else @@ -357,13 +362,13 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk if (pb->seekable & AVIO_SEEKABLE_NORMAL) { size = avio_close_dyn_buf(*dyn_cp, ); +put_ebml_num(pb, size, master.sizebytes); if (mkv->write_crc) { skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); } avio_write(pb, buf + skip, size - skip); -end_ebml_master(pb, master); } else { end_ebml_master(*dyn_cp, master); size = avio_close_dyn_buf(*dyn_cp, ); @@ -383,8 +388,8 @@ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, ); +put_ebml_num(pb, size, master.sizebytes); avio_write(pb, buf, size); -end_ebml_master(pb, master); } static void put_xiph_size(AVIOContext *pb, int 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/matroskaenc: Write CRC-32 in non-seekable mode
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:06 2019 +0200| [add68dcca958f0f6b42cabea6f546ceae5c7f16d] | committer: James Almer avformat/matroskaenc: Write CRC-32 in non-seekable mode Given that in both the seekable as well as the non-seekable mode dynamic buffers are used to write level 1 elements and that now no seeks are used in the seekable case any more, the two modes can be combined; as a consequence, the non-seekable mode automatically inherits the ability to write CRC-32 elements. There are no differences in case the output is seekable; when it is not and writing CRC-32 elements is disabled, there can still be minor differences because before this commit, the EBML ID and length field were counted towards the cluster size limit; now they no longer are. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=add68dcca958f0f6b42cabea6f546ceae5c7f16d --- libavformat/matroskaenc.c| 14 ++ tests/fate/matroska.mak | 2 +- tests/fate/wavpack.mak | 4 ++-- tests/ref/fate/binsub-mksenc | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 2875552469..d9a7ca9ad1 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -336,20 +336,15 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, ebml_master *master, uint32_t elementid, uint64_t expectedsize) { -int ret; +int ret, bytes = expectedsize ? ebml_num_size(expectedsize) : 8; if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; -if (pb->seekable & AVIO_SEEKABLE_NORMAL) { -int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; - put_ebml_id(pb, elementid); *master = (ebml_master) { avio_tell(pb), bytes }; if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ -} else -*master = start_ebml_master(*dyn_cp, elementid, expectedsize); return 0; } @@ -360,7 +355,6 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk uint8_t *buf, crc[4]; int size, skip = 0; -if (pb->seekable & AVIO_SEEKABLE_NORMAL) { size = avio_close_dyn_buf(*dyn_cp, ); put_ebml_num(pb, size, master.sizebytes); if (mkv->write_crc) { @@ -369,11 +363,7 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); } avio_write(pb, buf + skip, size - skip); -} else { -end_ebml_master(*dyn_cp, master); -size = avio_close_dyn_buf(*dyn_cp, ); -avio_write(pb, buf, size); -} + av_free(buf); *dyn_cp = NULL; } diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak index 6bcd2b08d6..d1500a1aae 100644 --- a/tests/fate/matroska.mak +++ b/tests/fate/matroska.mak @@ -4,7 +4,7 @@ FATE_MATROSKA-$(call DEMMUX, MATROSKA, MATROSKA) += fate-matroska-remux fate-matroska-remux: CMD = md5pipe -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-2pass-akiyo.webm -color_trc 4 -c:v copy -fflags +bitexact -strict -2 -f matroska fate-matroska-remux: CMP = oneline -fate-matroska-remux: REF = 768af2b49132a0de5e0502926ab9ca4f +fate-matroska-remux: REF = 82a5beaf7a0fb5bb2970d9bba9028086 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += fate-matroska-spherical-mono fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mkv/spherical.mkv diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak index a4095a9771..7358d50d82 100644 --- a/tests/fate/wavpack.mak +++ b/tests/fate/wavpack.mak @@ -91,12 +91,12 @@ fate-wavpack-matroskamode: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/special/matros FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono fate-wavpack-matroska_mux-mono: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -fflags +bitexact -f matroska fate-wavpack-matroska_mux-mono: CMP = oneline -fate-wavpack-matroska_mux-mono: REF = 646c726a80857b74a55ba16a6d83aeed +fate-wavpack-matroska_mux-mono: REF = 942af4e88c4045e822508400545c47fd FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-61 fate-wavpack-matroska_mux-61: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/eva_2.22_6.1_16bit-partial.wv -c copy -fflags +bitexact -f matroska fate-wavpack-matroska_mux-61: CMP = oneline -fate-wavpack-matroska_mux-61: REF = 35b033bc75a0e18bbaabbaef38914837 +fate-wavpack-matroska_mux-61: REF = c874587c6172feb74df5223019739
[FFmpeg-cvslog] avformat/matroskaenc: Remove redundant check
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:03 2019 +0200| [4b2c24da462f90f49b7f072e8bc1bf47d55d1c8b] | committer: James Almer avformat/matroskaenc: Remove redundant check All places where end_ebml_master_crc32_preliminary are used already check for whether the output is seekable, so the check in the function is redundant. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b2c24da462f90f49b7f072e8bc1bf47d55d1c8b --- libavformat/matroskaenc.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index b300b23938..316a632805 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -379,14 +379,12 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, ebml_master master) { -if (pb->seekable & AVIO_SEEKABLE_NORMAL) { uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, ); avio_write(pb, buf, size); end_ebml_master(pb, master); -} } static void put_xiph_size(AVIOContext *pb, int 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/matroskaenc: Reduce usage of ebml_master
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:10 2019 +0200| [48539b62fcbd994723a71cbc1750476cbee8eaac] | committer: James Almer avformat/matroskaenc: Reduce usage of ebml_master After the last few commits, the functions for writing master elements with CRC-32 elements didn't really make use of the ebml_master structure any more, so remove these parameters from the functions. The only things that still need to be kept are the positions of the level 1 elements that are written preliminarily and updated later. These positions are stored in the MatroskaMuxContext and replace the corresponding ebml_master structures. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=48539b62fcbd994723a71cbc1750476cbee8eaac --- libavformat/matroskaenc.c | 103 ++ 1 file changed, 49 insertions(+), 54 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 01ccc9524c..cef504fa05 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -58,8 +58,7 @@ #include "libavcodec/internal.h" typedef struct ebml_master { -int64_t pos;///< absolute offset in the containing AVIOContext where the size field starts -///< for level 1 elements or else where the master's elements start +int64_t pos;///< absolute offset in the containing AVIOContext where the master's elements start int sizebytes; ///< how many bytes were reserved for the size } ebml_master; @@ -122,15 +121,14 @@ typedef struct MatroskaMuxContext { const AVClass *class; int mode; AVIOContext *tags_bc; -ebml_master tags; +int64_t tags_pos; AVIOContext *info_bc; -ebml_master info; +int64_t info_pos; AVIOContext *tracks_bc; -ebml_master tracks_master; +int64_t tracks_pos; ebml_master segment; int64_t segment_offset; AVIOContext *cluster_bc; -ebml_master cluster; int64_t cluster_pos;///< file offset of the current cluster int64_t cluster_pts; int64_t duration_offset; @@ -334,7 +332,7 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) } static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master *master, uint32_t elementid) + uint32_t elementid) { int ret; @@ -342,15 +340,13 @@ static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matros return ret; put_ebml_id(pb, elementid); -*master = (ebml_master) { avio_tell(pb), 0 }; if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ return 0; } -static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master master) +static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv) { uint8_t *buf, crc[4]; int size, skip = 0; @@ -372,11 +368,13 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk * Complete ebml master without destroying the buffer, allowing for later updates */ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master master) + int64_t *pos) { uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, ); +*pos = avio_tell(pb); + put_ebml_num(pb, size, 0); avio_write(pb, buf, size); } @@ -489,7 +487,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) { AVIOContext *dyn_cp; mkv_seekhead *seekhead = mkv->seekhead; -ebml_master metaseek, seekentry; +ebml_master seekentry; int64_t currentpos; int i; @@ -502,7 +500,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) } } -if (start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_SEEKHEAD) < 0) { +if (start_ebml_master_crc32(pb, _cp, mkv, MATROSKA_ID_SEEKHEAD) < 0) { currentpos = -1; goto fail; } @@ -519,7 +517,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); end_ebml_master(dyn_cp, seekentry); } -end_ebml_master_crc32(pb, _cp, mkv, metaseek); +end_ebml_master_crc32(pb, _cp, mkv); if (seekhead->reserved_size > 0)
[FFmpeg-cvslog] avformat/matroskaenc: Fix BlockGroup size calculation
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:40:57 2019 +0200| [8b7964f8f83edeb8296086470123050b3546d213] | committer: James Almer avformat/matroskaenc: Fix BlockGroup size calculation The earlier code included the size of the BlockGroup's length field and the EBML ID in the calculation of the size for the payload and ignored the size of the duration's length field. This meant that Blockgroups corresponding to packets with size 2^(7n) - 17 - n - i, i = 0,..., n - 1, n = 1,..., 8 (i.e. 110, 16364, 16365, 2097130..2097132, ...) were written with length fields that are unnecessarily long. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b7964f8f83edeb8296086470123050b3546d213 --- libavformat/matroskaenc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index c006cbf35c..1849ae 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2059,9 +2059,7 @@ static int mkv_blockgroup_size(int pkt_size) int size = pkt_size + 4; size += ebml_num_size(size); size += 2; // EBML ID for block and block duration -size += 8; // max size of block duration -size += ebml_num_size(size); -size += 1; // blockgroup EBML ID +size += 9; // max size of block duration incl. length field 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] avformat/matroskaenc: Don't waste bytes in EBML Header
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:40:59 2019 +0200| [4e6df068b5477eeb63a483e93bd63661712131ba] | committer: James Almer avformat/matroskaenc: Don't waste bytes in EBML Header Up until now the EBML Header length field has been written with eight bytes, although the EBML Header is always so small that only one byte is needed for it. This patch saves seven bytes for every Matroska/Webm file. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4e6df068b5477eeb63a483e93bd63661712131ba --- libavformat/matroskaenc.c| 5 +++- tests/fate/matroska.mak | 2 +- tests/fate/wavpack.mak | 4 ++-- tests/ref/fate/aac-autobsf-adtstoasc | 4 ++-- tests/ref/fate/binsub-mksenc | 2 +- tests/ref/fate/rgb24-mkv | 4 ++-- tests/ref/lavf/mka | 4 ++-- tests/ref/lavf/mkv | 4 ++-- tests/ref/lavf/mkv_attachment| 4 ++-- tests/ref/seek/lavf-mkv | 44 ++-- 10 files changed, 40 insertions(+), 37 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 0448253a77..5e2127de7e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -164,6 +164,9 @@ typedef struct MatroskaMuxContext { int allow_raw_vfw; } MatroskaMuxContext; +/** 2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint, + * 8 byte for "matroska" doctype string */ +#define MAX_EBML_HEADER_SIZE 35 /** 2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit * offset, 4 bytes for target EBML ID */ @@ -1886,7 +1889,7 @@ static int mkv_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } -ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0); +ebml_header = start_ebml_master(pb, EBML_ID_HEADER, MAX_EBML_HEADER_SIZE); put_ebml_uint (pb, EBML_ID_EBMLVERSION, 1); put_ebml_uint (pb, EBML_ID_EBMLREADVERSION, 1); put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH, 4); diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak index 2747496e1e..6bcd2b08d6 100644 --- a/tests/fate/matroska.mak +++ b/tests/fate/matroska.mak @@ -4,7 +4,7 @@ FATE_MATROSKA-$(call DEMMUX, MATROSKA, MATROSKA) += fate-matroska-remux fate-matroska-remux: CMD = md5pipe -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-2pass-akiyo.webm -color_trc 4 -c:v copy -fflags +bitexact -strict -2 -f matroska fate-matroska-remux: CMP = oneline -fate-matroska-remux: REF = 1ed49a4f2b6790357fac268938357353 +fate-matroska-remux: REF = 768af2b49132a0de5e0502926ab9ca4f FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += fate-matroska-spherical-mono fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mkv/spherical.mkv diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak index e4e8d47128..a4095a9771 100644 --- a/tests/fate/wavpack.mak +++ b/tests/fate/wavpack.mak @@ -91,12 +91,12 @@ fate-wavpack-matroskamode: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/special/matros FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono fate-wavpack-matroska_mux-mono: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -fflags +bitexact -f matroska fate-wavpack-matroska_mux-mono: CMP = oneline -fate-wavpack-matroska_mux-mono: REF = 11773e2a518edc788475f3880d849230 +fate-wavpack-matroska_mux-mono: REF = 646c726a80857b74a55ba16a6d83aeed FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-61 fate-wavpack-matroska_mux-61: CMD = md5pipe -i $(TARGET_SAMPLES)/wavpack/num_channels/eva_2.22_6.1_16bit-partial.wv -c copy -fflags +bitexact -f matroska fate-wavpack-matroska_mux-61: CMP = oneline -fate-wavpack-matroska_mux-61: REF = 9641abdf596c10c2e21bd9b026d4bade +fate-wavpack-matroska_mux-61: REF = 35b033bc75a0e18bbaabbaef38914837 FATE_SAMPLES_AVCONV += $(FATE_WAVPACK-yes) fate-wavpack: $(FATE_WAVPACK-yes) diff --git a/tests/ref/fate/aac-autobsf-adtstoasc b/tests/ref/fate/aac-autobsf-adtstoasc index 9ca8e7ed9e..3537e82a30 100644 --- a/tests/ref/fate/aac-autobsf-adtstoasc +++ b/tests/ref/fate/aac-autobsf-adtstoasc @@ -1,5 +1,5 @@ -b0375ba00bcbd55023a176255b8d4ba2 *tests/data/fate/aac-autobsf-adtstoasc.matroska -6728 tests/data/fate/aac-autobsf-adtstoasc.matroska +63292d538da403964777e17eb65deae7 *tests/data/fate/aac-autobsf-adtstoasc.matroska +6721 tests/data/fate/aac-autobsf-adtstoasc.matroska #extradata 0:2, 0x0030001c #tb 0: 1/1000 #media_type 0: audio diff --git a/tests/ref/fate/binsub-mksenc b/tests/ref/fate/binsub-mksenc index f247d9d22d..2f7022442f 100644 --- a/tests/ref/fate/binsub-mksenc +++ b/tests/ref/fate/binsub-mksenc @@ -1 +1 @@ -f80f42e646fce972e73
[FFmpeg-cvslog] avformat/matroskaenc: Slightly improve size bounds for cues
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:40:58 2019 +0200| [5d7d0fcd70b9d50f093df6f42f9124be55895575] | committer: James Almer avformat/matroskaenc: Slightly improve size bounds for cues The upper bounds currently used for determining the size of a CuePoint's length field can be improved somewhat; as a result, a CuePoint containing three CueTrackPositions will now only need a size field with one byte length. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5d7d0fcd70b9d50f093df6f42f9124be55895575 --- libavformat/matroskaenc.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 1849ae..0448253a77 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -169,12 +169,12 @@ typedef struct MatroskaMuxContext { * offset, 4 bytes for target EBML ID */ #define MAX_SEEKENTRY_SIZE 21 -/** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 4 - * 8-byte uint max */ -#define MAX_CUETRACKPOS_SIZE 42 +/** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint max + * and one 1-byte uint for the track number (this assumes MAX_TRACKS to be <= 255) */ +#define MAX_CUETRACKPOS_SIZE 35 -/** per-cuepoint - 2 1-byte EBML IDs, 2 1-byte EBML sizes, 8-byte uint max */ -#define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE * num_tracks +/** per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max */ +#define MAX_CUEPOINT_CONTENT_SIZE(num_tracks) 10 + MAX_CUETRACKPOS_SIZE * num_tracks /** Seek preroll value for opus */ #define OPUS_SEEK_PREROLL 8000 @@ -605,7 +605,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra ctp_nb ++; } -cuepoint = start_ebml_master(dyn_cp, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(ctp_nb)); +cuepoint = start_ebml_master(dyn_cp, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_CONTENT_SIZE(ctp_nb)); put_ebml_uint(dyn_cp, MATROSKA_ID_CUETIME, pts); // put all the entries from different tracks that have the exact same ___ 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/matroskaenc: Remove traces of secondary seek head
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 01:41:00 2019 +0200| [01506e6b663948c9e3666c6d35f7830f397ab78a] | committer: James Almer avformat/matroskaenc: Remove traces of secondary seek head Up until e7ddafd515dc9826915b739d0b977a63c21e96af the Matroska muxer wrote a secondary seek head referencing all the clusters. When this was changed, a (now completely wrong) comment remained and the unique remaining seek head was still called main_seekhead. This has been changed. Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=01506e6b663948c9e3666c6d35f7830f397ab78a --- libavformat/matroskaenc.c | 38 ++ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 5e2127de7e..75863659bc 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -134,7 +134,7 @@ typedef struct MatroskaMuxContext { int64_t cluster_pts; int64_t duration_offset; int64_t duration; -mkv_seekhead*main_seekhead; +mkv_seekhead*seekhead; mkv_cues*cues; mkv_track *tracks; mkv_attachments *attachments; @@ -416,9 +416,9 @@ static void mkv_free(MatroskaMuxContext *mkv) { avio_close_dyn_buf(mkv->tags_bc, ); av_free(buf); } -if (mkv->main_seekhead) { -av_freep(>main_seekhead->entries); -av_freep(>main_seekhead); +if (mkv->seekhead) { +av_freep(>seekhead->entries); +av_freep(>seekhead); } if (mkv->cues) { av_freep(>cues->entries); @@ -496,7 +496,7 @@ static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) { AVIOContext *dyn_cp; -mkv_seekhead *seekhead = mkv->main_seekhead; +mkv_seekhead *seekhead = mkv->seekhead; ebml_master metaseek, seekentry; int64_t currentpos; int i; @@ -538,8 +538,8 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) currentpos = seekhead->filepos; } fail: -av_freep(>main_seekhead->entries); -av_freep(>main_seekhead); +av_freep(>seekhead->entries); +av_freep(>seekhead); return currentpos; } @@ -1458,7 +1458,7 @@ static int mkv_write_tracks(AVFormatContext *s) AVIOContext *pb = s->pb; int i, ret, default_stream_exists = 0; -ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb)); +ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_TRACKS, avio_tell(pb)); if (ret < 0) return ret; @@ -1495,7 +1495,7 @@ static int mkv_write_chapters(AVFormatContext *s) if (!s->nb_chapters || mkv->wrote_chapters) return 0; -ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb)); +ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb)); if (ret < 0) return ret; ret = start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_CHAPTERS, 0); @@ -1586,7 +1586,7 @@ static int mkv_write_tag_targets(AVFormatContext *s, int ret; if (!tags->pos) { -ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TAGS, avio_tell(s->pb)); +ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_TAGS, avio_tell(s->pb)); if (ret < 0) return ret; start_ebml_master_crc32(s->pb, >tags_bc, mkv, tags, MATROSKA_ID_TAGS, 0); @@ -1753,7 +1753,7 @@ static int mkv_write_attachments(AVFormatContext *s) av_lfg_init(, av_get_random_seed()); -ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_ATTACHMENTS, avio_tell(pb)); +ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_ATTACHMENTS, avio_tell(pb)); if (ret < 0) return ret; ret = start_ebml_master_crc32(pb, _cp, mkv, , MATROSKA_ID_ATTACHMENTS, 0); @@ -1902,18 +1902,16 @@ static int mkv_write_header(AVFormatContext *s) mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0); mkv->segment_offset = avio_tell(pb); -// we write 2 seek heads - one at the end of the file to point to each -// cluster, and one at the beginning to point to all other level one -// elements (including the seek head at the end of the file), which -// isn't more than 10 elements if we only write one of each other -// currently defined level 1 element -mkv->main_seekhead= mkv_start_seekhead(pb, mkv->segment_offset, 10); -if (!mkv->main_seekhead) { +// we write a seek head at the beginning to point to all other level +// one elements, which aren't more than 10 elements as we write only one +// of every other currently defined level 1 element +
[FFmpeg-cvslog] avfilter/vf_stack: Don't modify const strings
ffmpeg | branch: master | Andreas Rheinhardt | Tue May 14 06:15:17 2019 +0200| [670251de56cdcda0c32d588959c8ed2da09075a2] | committer: Paul B Mahol avfilter/vf_stack: Don't modify const strings b3b7ba62 introduced undefined behaviour: A (non-modifiable) string literal has been assigned to a modifiable string; said string was indeed modified later via av_strtok. This of course caused compiler warnings because of the discarded qualifier; these are in particular fixed by this commit. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=670251de56cdcda0c32d588959c8ed2da09075a2 --- libavfilter/vf_stack.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index 1455f196a7..4d254e0013 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -84,9 +84,11 @@ static av_cold int init(AVFilterContext *ctx) if (!strcmp(ctx->filter->name, "xstack")) { if (!s->layout) { -if (s->nb_inputs == 2) -s->layout = "0_0|w0_0"; -else { +if (s->nb_inputs == 2) { +s->layout = av_strdup("0_0|w0_0"); +if (!s->layout) +return AVERROR(ENOMEM); +} else { av_log(ctx, AV_LOG_ERROR, "No layout specified.\n"); return AVERROR(EINVAL); } ___ 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] lavf/webm_chunk: Respect buffer size
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 00:03:14 2019 +0200| [73ef1f47f5928264a968c8fbbcfb0bf0643f] | committer: Michael Niedermayer lavf/webm_chunk: Respect buffer size The last argument of av_strlcpy is supposed to contain the size of the destination buffer, but it was filled with the size of the source string, effectively negating its very purpose. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=73ef1f47f5928264a968c8fbbcfb0bf0643f --- libavformat/webm_chunk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index ec1ec4bf91..2c99753b5b 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -96,7 +96,7 @@ static int get_chunk_filename(AVFormatContext *s, int is_header, char *filename) av_log(oc, AV_LOG_ERROR, "No header filename provided\n"); return AVERROR(EINVAL); } -av_strlcpy(filename, wc->header_filename, strlen(wc->header_filename) + 1); +av_strlcpy(filename, wc->header_filename, MAX_FILENAME_SIZE); } else { if (av_get_frame_filename(filename, MAX_FILENAME_SIZE, s->url, wc->chunk_index - 1) < 0) { ___ 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] lavf/webm_chunk: Respect buffer size
ffmpeg | branch: release/4.1 | Andreas Rheinhardt | Sat Apr 20 00:03:14 2019 +0200| [85578838cbc0d86baac9713b2cc47054e55d1a8e] | committer: Michael Niedermayer lavf/webm_chunk: Respect buffer size The last argument of av_strlcpy is supposed to contain the size of the destination buffer, but it was filled with the size of the source string, effectively negating its very purpose. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer (cherry picked from commit 73ef1f47f5928264a968c8fbbcfb0bf0643f) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=85578838cbc0d86baac9713b2cc47054e55d1a8e --- libavformat/webm_chunk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 7ceb276fc4..f60696e3ad 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -96,7 +96,7 @@ static int get_chunk_filename(AVFormatContext *s, int is_header, char *filename) av_log(oc, AV_LOG_ERROR, "No header filename provided\n"); return AVERROR(EINVAL); } -av_strlcpy(filename, wc->header_filename, strlen(wc->header_filename) + 1); +av_strlcpy(filename, wc->header_filename, MAX_FILENAME_SIZE); } else { if (av_get_frame_filename(filename, MAX_FILENAME_SIZE, s->url, wc->chunk_index - 1) < 0) { ___ 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] libavformat/mux: Fix mixed delarations and code
ffmpeg | branch: master | Andreas Rheinhardt | Thu Jun 27 19:47:23 2019 +0200| [45cfecdec645e0db0d2b8c76d6ece3860ab97c5b] | committer: James Almer libavformat/mux: Fix mixed delarations and code This commit fixes mixed declarations and code introduced in 1889e316. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=45cfecdec645e0db0d2b8c76d6ece3860ab97c5b --- libavformat/mux.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 5e1ecd8485..21f10caf53 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1005,10 +1005,11 @@ static int interleave_compare_dts(AVFormatContext *s, AVPacket *next, int preload = st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO; int preload2 = st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO; if (preload != preload2) { +int64_t ts, ts2; preload *= s->audio_preload; preload2 *= s->audio_preload; -int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - preload; -int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - preload2; +ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - preload; +ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - preload2; if (ts == ts2) { ts = ((uint64_t)pkt ->dts*st ->time_base.num*AV_TIME_BASE - (uint64_t)preload *st ->time_base.den)*st2->time_base.den - ((uint64_t)next->dts*st2->time_base.num*AV_TIME_BASE - (uint64_t)preload2*st2->time_base.den)*st ->time_base.den; ___ 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] libavformat/mux: Fix audio_preload
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 24 23:16:18 2019 +0200| [1889e3166cc5780780d7f40ac2271e5308f32b8e] | committer: Michael Niedermayer libavformat/mux: Fix audio_preload Commit 31f9032b added the audio_preload feature; its goal is to interleave audio earlier than the rest. Unfortunately, it has never ever worked, because the check for whether a packet should be interleaved before or after another packet was completely wrong: When audio_preload vanishes, interleave_compare_dts returns 1 if the new packet should be interleaved earlier than the packet it is compared with and that is what the rest of the code expects. But the codepath used when audio_preload is set does the opposite. Also fixes potential undefined behaviour (namely signed integer overflow). Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1889e3166cc5780780d7f40ac2271e5308f32b8e --- libavformat/mux.c | 22 ++ libavformat/version.h | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 83fe1de78f..5e1ecd8485 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1001,15 +1001,21 @@ static int interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVStream *st2 = s->streams[next->stream_index]; int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts, st->time_base); -if (s->audio_preload && ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) { -int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); -int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); -if (ts == ts2) { -ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den - -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den; -ts2=0; +if (s->audio_preload) { +int preload = st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO; +int preload2 = st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO; +if (preload != preload2) { +preload *= s->audio_preload; +preload2 *= s->audio_preload; +int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - preload; +int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - preload2; +if (ts == ts2) { +ts = ((uint64_t)pkt ->dts*st ->time_base.num*AV_TIME_BASE - (uint64_t)preload *st ->time_base.den)*st2->time_base.den +- ((uint64_t)next->dts*st2->time_base.num*AV_TIME_BASE - (uint64_t)preload2*st2->time_base.den)*st ->time_base.den; +ts2 = 0; +} +comp = (ts2 > ts) - (ts2 < ts); } -comp= (ts>ts2) - (tshttps://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] lavf/webm_chunk: Fix NULL dereference
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 00:03:15 2019 +0200| [8c6ee7626bcce7c270360f33b60dc7ef99939fc3] | committer: Paul B Mahol lavf/webm_chunk: Fix NULL dereference The earlier version of the webm_chunk muxer had several bugs: 1. If the first packet of an audio stream didn't have a PTS of zero, then no chunk will be started before a packet is delivered to the underlying Matroska/WebM muxer, i.e. the AVFormatContext used to write these packets had a NULL as AVIOContext for output. This is behind the crash in ticket #5752. 2. If an error happens during writing a packet, the underlyimg Matroska/WebM muxer context is freed. This leads to a use-after-free coupled with a double-free in webm_chunk_write_trailer (which supposes that the underlying AVFormatContext is still valid). 3. Even when no error occurs at all, webm_chunk_write_trailer is still buggy: After the underlying Matroska/WebM muxer has written its trailer, ending the chunk implicitly flushes it again which is illegal at this point. These bugs have been fixed. Fixes #5752. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8c6ee7626bcce7c270360f33b60dc7ef99939fc3 --- libavformat/webm_chunk.c | 44 +++- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 904bde7eb4..8196f3d096 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -173,7 +173,7 @@ static int chunk_start(AVFormatContext *s) return 0; } -static int chunk_end(AVFormatContext *s) +static int chunk_end(AVFormatContext *s, int flush) { WebMChunkContext *wc = s->priv_data; AVFormatContext *oc = wc->avf; @@ -184,11 +184,14 @@ static int chunk_end(AVFormatContext *s) char filename[MAX_FILENAME_SIZE]; AVDictionary *options = NULL; -if (wc->chunk_start_index == wc->chunk_index) +if (!oc->pb) return 0; -// Flush the cluster in WebM muxer. -oc->oformat->write_packet(oc, NULL); + +if (flush) +// Flush the cluster in WebM muxer. +oc->oformat->write_packet(oc, NULL); buffer_size = avio_close_dyn_buf(oc->pb, ); +oc->pb = NULL; ret = get_chunk_filename(s, 0, filename); if (ret < 0) goto fail; @@ -199,7 +202,6 @@ static int chunk_end(AVFormatContext *s) goto fail; avio_write(pb, buffer, buffer_size); ff_format_io_close(s, ); -oc->pb = NULL; fail: av_dict_free(); av_free(buffer); @@ -221,27 +223,19 @@ static int webm_chunk_write_packet(AVFormatContext *s, AVPacket *pkt) } // For video, a new chunk is started only on key frames. For audio, a new -// chunk is started based on chunk_duration. -if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && +// chunk is started based on chunk_duration. Also, a new chunk is started +// unconditionally if there is no currently open chunk. +if (!oc->pb || (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY)) || (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - (pkt->pts == 0 || wc->duration_written >= wc->chunk_duration))) { + wc->duration_written >= wc->chunk_duration)) { wc->duration_written = 0; -if ((ret = chunk_end(s)) < 0 || (ret = chunk_start(s)) < 0) { -goto fail; +if ((ret = chunk_end(s, 1)) < 0 || (ret = chunk_start(s)) < 0) { +return ret; } } ret = oc->oformat->write_packet(oc, pkt); -if (ret < 0) -goto fail; - -fail: -if (ret < 0) { -oc->streams = NULL; -oc->nb_streams = 0; -avformat_free_context(oc); -} return ret; } @@ -250,12 +244,20 @@ static int webm_chunk_write_trailer(AVFormatContext *s) { WebMChunkContext *wc = s->priv_data; AVFormatContext *oc = wc->avf; +int ret; + +if (!oc->pb) { +ret = chunk_start(s); +if (ret < 0) +goto fail; +} oc->oformat->write_trailer(oc); -chunk_end(s); +ret = chunk_end(s, 0); +fail: oc->streams = NULL; oc->nb_streams = 0; avformat_free_context(oc); -return 0; +return ret; } #define OFFSET(x) offsetof(WebMChunkContext, x) ___ 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] lavf/webm_chunk: Correct duration if start time > 0
ffmpeg | branch: master | Andreas Rheinhardt | Sat Apr 20 00:03:16 2019 +0200| [24a64e0462d5dad6f6cf629243abdbe975e33015] | committer: Paul B Mahol lavf/webm_chunk: Correct duration if start time > 0 Up until now, it was simply presumed that the first packet had a pts of zero; otherwise the duration of the first chunk was wrong. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24a64e0462d5dad6f6cf629243abdbe975e33015 --- libavformat/webm_chunk.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 8196f3d096..4e2ce21a79 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -52,7 +52,7 @@ typedef struct WebMChunkContext { int chunk_index; char *http_method; uint64_t duration_written; -int prev_pts; +int64_t prev_pts; ff_const59 AVOutputFormat *oformat; AVFormatContext *avf; } WebMChunkContext; @@ -129,6 +129,7 @@ static int webm_chunk_write_header(AVFormatContext *s) wc->oformat = av_guess_format("webm", s->url, "video/webm"); if (!wc->oformat) return AVERROR_MUXER_NOT_FOUND; +wc->prev_pts = AV_NOPTS_VALUE; ret = chunk_mux_init(s); if (ret < 0) @@ -216,9 +217,10 @@ static int webm_chunk_write_packet(AVFormatContext *s, AVPacket *pkt) int ret; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { -wc->duration_written += av_rescale_q(pkt->pts - wc->prev_pts, - st->time_base, - (AVRational) {1, 1000}); +if (wc->prev_pts != AV_NOPTS_VALUE) +wc->duration_written += av_rescale_q(pkt->pts - wc->prev_pts, + st->time_base, + (AVRational) {1, 1000}); wc->prev_pts = pkt->pts; } ___ 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: Don't suggest deprecated function
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 13 18:48:48 2019 +0200| [a2572e3c670db018a414e9c168eef23ec2e3abc4] | committer: James Almer avformat: Don't suggest deprecated function Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a2572e3c670db018a414e9c168eef23ec2e3abc4 --- libavformat/avformat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 734ae54cac..6eb329f13f 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -175,8 +175,8 @@ * Otherwise, if AVPacket.buf is NULL, the packet data is backed by a * static storage somewhere inside the demuxer and the packet is only valid * until the next av_read_frame() call or closing the file. If the caller - * requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy - * of it. + * requires a longer lifetime, av_packet_make_refcounted() will ensure that + * the data is reference counted, copying the data if necessary. * In both cases, the packet must be freed with av_packet_unref() when it is no * longer needed. * ___ 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, h264_metadata: Deleting SEI messages never fails
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jul 8 01:14:02 2019 +0200| [d9418aba66e7f9d32c11d0ee1b8cddaf1e68e1b6] | committer: Mark Thompson cbs_h264, h264_metadata: Deleting SEI messages never fails Given the recent changes to ff_cbs_delete_unit, it is no longer sensible to use a return value for ff_cbs_h264_delete_sei_message; instead, use asserts to ensure that the required conditions are met and remove the callers' checks for the return value. Also, document said conditions. An assert that is essentially equivalent to the one used in ff_cbs_delete_unit has been removed, too. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d9418aba66e7f9d32c11d0ee1b8cddaf1e68e1b6 --- libavcodec/cbs_h264.h | 11 +++ libavcodec/cbs_h2645.c | 11 --- libavcodec/h264_metadata_bsf.c | 21 + 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index a31be298ba..b39e7480c9 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -478,10 +478,13 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, * * Deletes from nal_unit, which must be an SEI NAL unit. If this is the * last message in nal_unit, also deletes it from access_unit. + * + * Requires nal_unit to be a unit in access_unit and position to be >= 0 + * and < the payload count of the SEI nal_unit. */ -int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, - CodedBitstreamFragment *access_unit, - CodedBitstreamUnit *nal_unit, - int position); +void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, +CodedBitstreamFragment *access_unit, +CodedBitstreamUnit *nal_unit, +int position); #endif /* AVCODEC_CBS_H264_H */ diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 484b145852..b286269913 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1644,10 +1644,10 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, return 0; } -int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, - CodedBitstreamFragment *au, - CodedBitstreamUnit *nal, - int position) +void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, +CodedBitstreamFragment *au, +CodedBitstreamUnit *nal, +int position) { H264RawSEI *sei = nal->content; @@ -1662,7 +1662,6 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, if (>units[i] == nal) break; } -av_assert0(i < au->nb_units && "NAL unit not in access unit."); ff_cbs_delete_unit(ctx, au, i); } else { @@ -1673,6 +1672,4 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, sei->payload + position + 1, (sei->payload_count - position) * sizeof(*sei->payload)); } - -return 0; } diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index e40baa3371..1c1c340d8f 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -437,15 +437,9 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) for (j = sei->payload_count - 1; j >= 0; j--) { if (sei->payload[j].payload_type == -H264_SEI_TYPE_FILLER_PAYLOAD) { -err = ff_cbs_h264_delete_sei_message(ctx->cbc, au, - >units[i], j); -if (err < 0) { -av_log(bsf, AV_LOG_ERROR, "Failed to delete " - "filler SEI message.\n"); -goto fail; -} -} +H264_SEI_TYPE_FILLER_PAYLOAD) +ff_cbs_h264_delete_sei_message(ctx->cbc, au, + >units[i], j); } } } @@ -469,13 +463,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) if (ctx->display_orientation == REMOVE || ctx->display_orientation == INSERT) { -err = ff_cbs_h264_delete_sei_message(ctx->cbc, au, - >units[i], j); -if (err < 0) { -av_log(bsf, AV_LOG_ERROR, "Failed to de
[FFmpeg-cvslog] cbs: ff_cbs_delete_unit: Replace return value with assert
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jul 8 01:14:01 2019 +0200| [730e5be3aa1118a63132122dd06aa4f3311af07d] | committer: Mark Thompson cbs: ff_cbs_delete_unit: Replace return value with assert ff_cbs_delete_unit never fails if the index of the unit to delete is valid, as it is with all current callers of the function. So just assert in ff_cbs_delete_unit that the index is valid and change the return value to void in order to remove the callers' checks for whether ff_cbs_delete_unit failed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=730e5be3aa1118a63132122dd06aa4f3311af07d --- libavcodec/av1_metadata_bsf.c | 9 ++--- libavcodec/cbs.c| 12 +--- libavcodec/cbs.h| 8 +--- libavcodec/cbs_h2645.c | 6 +++--- libavcodec/h264_metadata_bsf.c | 8 +--- libavcodec/h264_redundant_pps_bsf.c | 4 +--- 6 files changed, 17 insertions(+), 30 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index bb2ca2075b..226f7dffa4 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -167,13 +167,8 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) if (ctx->delete_padding) { for (i = frag->nb_units - 1; i >= 0; i--) { -if (frag->units[i].type == AV1_OBU_PADDING) { -err = ff_cbs_delete_unit(ctx->cbc, frag, i); -if (err < 0) { -av_log(bsf, AV_LOG_ERROR, "Failed to delete Padding OBU.\n"); -goto fail; -} -} +if (frag->units[i].type == AV1_OBU_PADDING) +ff_cbs_delete_unit(ctx->cbc, frag, i); } } diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 47679eca1b..2350416501 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -737,12 +737,12 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx, return 0; } -int ff_cbs_delete_unit(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - int position) +void ff_cbs_delete_unit(CodedBitstreamContext *ctx, +CodedBitstreamFragment *frag, +int position) { -if (position < 0 || position >= frag->nb_units) -return AVERROR(EINVAL); +av_assert0(0 <= position && position < frag->nb_units + && "Unit to be deleted not in fragment."); cbs_unit_uninit(ctx, >units[position]); @@ -752,6 +752,4 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx, memmove(frag->units + position, frag->units + position + 1, (frag->nb_units - position) * sizeof(*frag->units)); - -return 0; } diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 5260a39c63..fe57e7b2a5 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -380,10 +380,12 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx, /** * Delete a unit from a fragment and free all memory it uses. + * + * Requires position to be >= 0 and < frag->nb_units. */ -int ff_cbs_delete_unit(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - int position); +void ff_cbs_delete_unit(CodedBitstreamContext *ctx, +CodedBitstreamFragment *frag, +int position); #endif /* AVCODEC_CBS_H */ diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 0456937710..484b145852 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1664,7 +1664,7 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, } av_assert0(i < au->nb_units && "NAL unit not in access unit."); -return ff_cbs_delete_unit(ctx, au, i); +ff_cbs_delete_unit(ctx, au, i); } else { cbs_h264_free_sei_payload(>payload[position]); @@ -1672,7 +1672,7 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, memmove(sei->payload + position, sei->payload + position + 1, (sei->payload_count - position) * sizeof(*sei->payload)); - -return 0; } + +return 0; } diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index f7ca1f0f09..e40baa3371 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -427,13 +427,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) if (ctx->delete_filler) { for (i = au->nb_units - 1; i >= 0; i--) { if (au->units[i].type == H264_NAL_FILLER_DATA) { -// Filler NAL units. -err = ff_cbs_delete_unit(ctx->cbc, au, i); -
[FFmpeg-cvslog] configure, cbs_h2645: Remove unneeded golomb dependency
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jul 8 18:38:21 2019 +0200| [f83b46e2181c9eb0360cb61419f29a1e44f04954] | committer: Mark Thompson configure, cbs_h2645: Remove unneeded golomb dependency This has been forgotten in 44cde38c. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f83b46e2181c9eb0360cb61419f29a1e44f04954 --- configure | 4 ++-- libavcodec/cbs_h2645.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 7cea9d4d73..4005987409 100755 --- a/configure +++ b/configure @@ -2586,8 +2586,8 @@ threads_if_any="$THREADS_LIST" # subsystems cbs_av1_select="cbs" -cbs_h264_select="cbs golomb" -cbs_h265_select="cbs golomb" +cbs_h264_select="cbs" +cbs_h265_select="cbs" cbs_jpeg_select="cbs" cbs_mpeg2_select="cbs" cbs_vp9_select="cbs" diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index b286269913..da4927ca8e 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -24,7 +24,6 @@ #include "cbs_internal.h" #include "cbs_h264.h" #include "cbs_h265.h" -#include "golomb.h" #include "h264.h" #include "h264_sei.h" #include "h2645_parse.h" ___ 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] truehd_core: Correct output size
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 16:18:00 2019 +0200| [cbe23e40ae9120f6d5bc444b9b9970e67cbfdcc0] | committer: Paul B Mahol truehd_core: Correct output size If truehd_core strips Atmos data away, three parts of the output differ in size compared to the input access unit: a) The major_sync_info block if the extra_channel_meaning_data is present, as the newly written output never contains said block; b) the substream_directory (because entries relating to discarded substreams are discarded, too); and c) the actual substream data. b) and c) have already been taken into account when choosing the size of the output packet, but a) has been forgotten. This is also the reason behind the end of the output buffer having been uninitialized until 801d78f0. The workaround added in said commit has been removed, too. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cbe23e40ae9120f6d5bc444b9b9970e67cbfdcc0 --- libavcodec/truehd_core_bsf.c | 7 ++- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 757d26a10d..83f2b16e3d 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -46,7 +46,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) int in_size, out_size; int have_header = 0; int substream_bits = 0; -int start, end; +int end; uint16_t dts; ret = ff_bsf_get_packet(ctx, ); @@ -81,7 +81,6 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) if (s->hdr.num_substreams > MAX_SUBSTREAMS) goto fail; -start = get_bits_count(); for (i = 0; i < s->hdr.num_substreams; i++) { for (int j = 0; j < 4; j++) units[i].bits[j] = get_bits1(); @@ -104,7 +103,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) if (size >= 0 && size <= in->size) out_size = size; if (out_size < in_size) { -int bpos = 0, reduce = (end - start - substream_bits) >> 4; +int bpos = 0, reduce = (end - have_header * 28 * 8 - substream_bits) >> 4; uint16_t parity_nibble = 0; uint16_t auheader; @@ -117,8 +116,6 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) out->size -= reduce * 2; parity_nibble ^= out->size / 2; -if (out_size > 8) -AV_WN64(out->data + out_size - 8, 0); if (have_header) { memcpy(out->data + 4, in->data + 4, 28); out->data[16 + 4] = (out->data[16 + 4] & 0x0c) | (FFMIN(s->hdr.num_substreams, 3) << 4); ___ 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] truehd_core: Return error in case of error
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 16:18:01 2019 +0200| [610460a397b15993a6f469b2c50fe7a3bd4ff0a1] | committer: Paul B Mahol truehd_core: Return error in case of error Several checks (e.g. when the size of the input packet is too small) simply used "goto fail", but didn't set the return value appropriately for an error. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=610460a397b15993a6f469b2c50fe7a3bd4ff0a1 --- libavcodec/truehd_core_bsf.c | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 83f2b16e3d..f858c2d4d5 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -53,8 +53,10 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) if (ret < 0) return ret; -if (in->size < 4) +if (in->size < 4) { +ret = AVERROR_INVALIDDATA; goto fail; +} ret = init_get_bits(, in->data, 32); if (ret < 0) @@ -62,8 +64,10 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) skip_bits(, 4); in_size = get_bits(, 12) * 2; -if (in_size < 4 || in_size > in->size) +if (in_size < 4 || in_size > in->size) { +ret = AVERROR_INVALIDDATA; goto fail; +} out_size = in_size; dts = get_bits(, 16); @@ -73,13 +77,15 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) goto fail; if (show_bits_long(, 32) == 0xf8726fba) { -if ((ret = ff_mlp_read_major_sync(ctx, >hdr, )) != 0) +if ((ret = ff_mlp_read_major_sync(ctx, >hdr, )) < 0) goto fail; have_header = 1; } -if (s->hdr.num_substreams > MAX_SUBSTREAMS) +if (s->hdr.num_substreams > MAX_SUBSTREAMS) { +ret = AVERROR_INVALIDDATA; goto fail; +} for (i = 0; i < s->hdr.num_substreams; i++) { for (int j = 0; j < 4; j++) ___ 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] truehd_core: Miscellaneous improvements
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 16:18:02 2019 +0200| [2275e70569cea1bc976c349520fa029734b323de] | committer: Paul B Mahol truehd_core: Miscellaneous improvements 1. The loop counter of the substream_directory loop is always less than the number of substreams, yet within the loop it is checked whether it is less than FFMIN(3, s->hdr.num_substreams), although the check for < 3 would suffice. 2. In case the packet is a major sync packet, the last two bytes of the major sync structure were initialized to 0xff and then immediately overwritten afterwards without ever making use of the values just set. 3. When updating the parity_nibble during writing the new substream_directory, the parity_nibble is updated one byte at a time with bytes that might be read from the output packet's data. But one can do both bytes at the same time without resorting to the data just written by XOR'ing with the variable that contains the value that has just been written as a big endian number. This changes the intermediate value of parity_nibble, but in the end it just amounts to a reordering of the sum modulo two that will eventually be written as parity_nibble. Due to associativity and commutativity, this value is unchanged. 4. init_get_bits8 already checks that no overflow happens during the conversion of its argument from bytes to bits. ff_mlp_read_major_sync makes sure not to overread (the maximum size of a major_sync_info is 60 bytes anyway) and last_offset is < 2^13, so that no overflow in the calculation of size can happen, i.e. the check for whether size is >= 0 is unnecessary. But then size is completely unnecessary and can be removed. 5. In case the packet is just passed through, it is unnecessary to read the packet's dts. This is therefore postponed to when we know that the packet is not passed through. 6. Given that it seems overkill to use a bitreader just for one variable, the size of the input access unit is now read directly. 7. A substream's offset (of the end of the substream) is now stored as is (i.e. in units of words). These changes amount to a slight performance improvement: It improved from 5897 decicycles of ten runs with about 262144 runs each (including an insignificant amount -- about 20-25 usually of skips) to 5747 decicycles under the same conditions. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2275e70569cea1bc976c349520fa029734b323de --- libavcodec/truehd_core_bsf.c | 39 +-- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index f858c2d4d5..47684235db 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -42,12 +42,11 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) GetBitContext gbc; AccessUnit units[MAX_SUBSTREAMS]; AVPacket *in; -int ret, i, size, last_offset = 0; +int ret, i, last_offset = 0; int in_size, out_size; int have_header = 0; int substream_bits = 0; int end; -uint16_t dts; ret = ff_bsf_get_packet(ctx, ); if (ret < 0) @@ -58,20 +57,12 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) goto fail; } -ret = init_get_bits(, in->data, 32); -if (ret < 0) -goto fail; - -skip_bits(, 4); -in_size = get_bits(, 12) * 2; +in_size = (AV_RB16(in->data) & 0xFFF) * 2; if (in_size < 4 || in_size > in->size) { ret = AVERROR_INVALIDDATA; goto fail; } -out_size = in_size; -dts = get_bits(, 16); - ret = init_get_bits8(, in->data + 4, in->size - 4); if (ret < 0) goto fail; @@ -91,26 +82,24 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) for (int j = 0; j < 4; j++) units[i].bits[j] = get_bits1(); -units[i].offset = get_bits(, 12) * 2; -if (i < FFMIN(s->hdr.num_substreams, 3)) { -last_offset = units[i].offset; +units[i].offset = get_bits(, 12); +if (i < 3) { +last_offset = units[i].offset * 2; substream_bits += 16; } if (units[i].bits[0]) { units[i].optional = get_bits(, 16); -if (i < FFMIN(s->hdr.num_substreams, 3)) +if (i < 3) substream_bits += 16; } } end = get_bits_count(); -size = ((end + 7) >> 3) + 4 + last_offset; -if (size >= 0 && size <= in->size) -out_size = size; +out_size = ((end + 7) >> 3) + 4 + last_offset; if (out_size < in_size) { int bpos = 0, reduce = (end - have_header * 28 * 8 - substream_bits) >> 4; -uint16_t parity_nibble = 0; +uint16_t parity_nibble, dts = AV_RB16(in->data + 2); uint16_t auheader;
[FFmpeg-cvslog] truehd_core: Switch to in-place modifications
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 16:18:04 2019 +0200| [5a481b15bd866752e2729f95bfb61f55da1a3d11] | committer: Paul B Mahol truehd_core: Switch to in-place modifications The truehd_core bitstream filter decreases the sizes of the major_sync_info structure (if present), of the substream_directory and of the substreams themselves. As a consequence, there is enough space available in front of the actual substream data for the new header, so that one only needs to modify the header in front of the actual data (which apart from shrinking is left untouched) and the packet's size and buffer pointer (after having made sure that the packet is writable). This and switching to bsf_get_packet_ref also removed the need for having separate packets for in- and output. Even if the input is not writable, there are noticable performance improvements: The average of 10 iterations of processing a file with 262144 runs each (inlcuding about 20 skips per iteration) went down from 5669 to 4362 decicycles. If the input is writable, it goes down to 1363 decicycles. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5a481b15bd866752e2729f95bfb61f55da1a3d11 --- libavcodec/truehd_core_bsf.c | 64 +--- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 8ea80d3015..dbd05b34ca 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -36,34 +36,33 @@ typedef struct TrueHDCoreContext { MLPHeaderInfo hdr; } TrueHDCoreContext; -static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) +static int truehd_core_filter(AVBSFContext *ctx, AVPacket *pkt) { TrueHDCoreContext *s = ctx->priv_data; GetBitContext gbc; AccessUnit units[MAX_SUBSTREAMS]; -AVPacket *in; int ret, i, last_offset = 0; int in_size, out_size; int have_header = 0; int substream_bytes = 0; int end; -ret = ff_bsf_get_packet(ctx, ); +ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; -if (in->size < 4) { +if (pkt->size < 4) { ret = AVERROR_INVALIDDATA; goto fail; } -in_size = (AV_RB16(in->data) & 0xFFF) * 2; -if (in_size < 4 || in_size > in->size) { +in_size = (AV_RB16(pkt->data) & 0xFFF) * 2; +if (in_size < 4 || in_size > pkt->size) { ret = AVERROR_INVALIDDATA; goto fail; } -ret = init_get_bits8(, in->data + 4, in->size - 4); +ret = init_get_bits8(, pkt->data + 4, pkt->size - 4); if (ret < 0) goto fail; @@ -99,27 +98,31 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) out_size = end + 4 + last_offset; if (out_size < in_size) { int bpos = 0, reduce = end - have_header * 28 - substream_bytes; -uint16_t parity_nibble, dts = AV_RB16(in->data + 2); +uint16_t parity_nibble, dts = AV_RB16(pkt->data + 2); uint16_t auheader; +uint8_t header[28]; -av_assert1(reduce % 2 == 0); +av_assert1(reduce >= 0 && reduce % 2 == 0); -ret = av_new_packet(out, out_size); +if (have_header) { +memcpy(header, pkt->data + 4, 28); +header[16] = (header[16] & 0x0c) | (FFMIN(s->hdr.num_substreams, 3) << 4); +header[17] &= 0x7f; +header[25] &= 0xfe; +AV_WL16(header + 26, ff_mlp_checksum16(header, 26)); +} + +pkt->data += reduce; +out_size -= reduce; +pkt->size = out_size; + +ret = av_packet_make_writable(pkt); if (ret < 0) goto fail; -AV_WB16(out->data + 2, dts); +AV_WB16(pkt->data + 2, dts); parity_nibble = dts; -out->size -= reduce; -parity_nibble ^= out->size / 2; - -if (have_header) { -memcpy(out->data + 4, in->data + 4, 28); -out->data[16 + 4] = (out->data[16 + 4] & 0x0c) | (FFMIN(s->hdr.num_substreams, 3) << 4); -out->data[17 + 4]&= 0x7f; -out->data[25 + 4] = out->data[25 + 4] & 0xfe; -AV_WL16(out->data + 4 + 26, ff_mlp_checksum16(out->data + 4, 26)); -} +parity_nibble ^= out_size / 2; for (i = 0; i < FFMIN(s->hdr.num_substreams, 3); i++) { uint16_t substr_hdr = 0; @@ -130,13 +133,13 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) substr_hdr |= (units[i].bits[3] << 12); substr_hdr |= units[i].offset; -AV_WB16(out->data + have_header * 28 + 4 + bpos, substr_hdr); +AV_WB16(pkt->data + have_header * 28 + 4 + bpos, substr_hdr);
[FFmpeg-cvslog] truehd_core: Disable 16-channel presentation
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 15:59:06 2019 +0200| [99c191151a716d8315e938297bd9b50a6a0902d3] | committer: Paul B Mahol truehd_core: Disable 16-channel presentation The most serious bit of the substream_info header field (in a mayor sync packet) indicates whether a 16-channel presentation is present in the bitstream. If set, the extended_substream_info header field contains information about the 16-channel presentation. This presentation always uses substream 3, a substream that is discarded by truehd_core. So substream_info needs to be changed to no longer indicate the presence of a 16-channel presentation in order for truehd_core's output to be consistent. This is implemented in this commit. This change also makes MediaInfo no longer display the presence of Atmos in the output of truehd_core. Also, set the (now irrelevant) extended_substream_info field to zero as this seems to be the common value for ordinary TrueHD. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99c191151a716d8315e938297bd9b50a6a0902d3 --- libavcodec/truehd_core_bsf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 9e3ee07eed..757d26a10d 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -121,7 +121,8 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) AV_WN64(out->data + out_size - 8, 0); if (have_header) { memcpy(out->data + 4, in->data + 4, 28); -out->data[16 + 4] = (out->data[16 + 4] & 0x0f) | (FFMIN(s->hdr.num_substreams, 3) << 4); +out->data[16 + 4] = (out->data[16 + 4] & 0x0c) | (FFMIN(s->hdr.num_substreams, 3) << 4); +out->data[17 + 4]&= 0x7f; out->data[25 + 4] = out->data[25 + 4] & 0xfe; out->data[26 + 4] = 0xff; out->data[27 + 4] = 0xff; ___ 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] truehd_core: Use byte offsets instead of bit offsets
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 6 16:18:03 2019 +0200| [836065b27a0f5b8268c2fb6c6e825ac3b63168f0] | committer: Paul B Mahol truehd_core: Use byte offsets instead of bit offsets Words of 16 bit are the unit for TrueHD's size and offset fields; in particular the sizes of the high-level structures of TrueHD are always a multiple of a byte; yet truehd_core unnecessarily used bit offsets at several places. This has been changed. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=836065b27a0f5b8268c2fb6c6e825ac3b63168f0 --- libavcodec/truehd_core_bsf.c | 20 +++- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 47684235db..8ea80d3015 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -45,7 +45,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) int ret, i, last_offset = 0; int in_size, out_size; int have_header = 0; -int substream_bits = 0; +int substream_bytes = 0; int end; ret = ff_bsf_get_packet(ctx, ); @@ -85,30 +85,32 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) units[i].offset = get_bits(, 12); if (i < 3) { last_offset = units[i].offset * 2; -substream_bits += 16; +substream_bytes += 2; } if (units[i].bits[0]) { units[i].optional = get_bits(, 16); if (i < 3) -substream_bits += 16; +substream_bytes += 2; } } -end = get_bits_count(); +end = get_bits_count() >> 3; -out_size = ((end + 7) >> 3) + 4 + last_offset; +out_size = end + 4 + last_offset; if (out_size < in_size) { -int bpos = 0, reduce = (end - have_header * 28 * 8 - substream_bits) >> 4; +int bpos = 0, reduce = end - have_header * 28 - substream_bytes; uint16_t parity_nibble, dts = AV_RB16(in->data + 2); uint16_t auheader; +av_assert1(reduce % 2 == 0); + ret = av_new_packet(out, out_size); if (ret < 0) goto fail; AV_WB16(out->data + 2, dts); parity_nibble = dts; -out->size -= reduce * 2; +out->size -= reduce; parity_nibble ^= out->size / 2; if (have_header) { @@ -146,8 +148,8 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) parity_nibble &= 0xF; memcpy(out->data + have_header * 28 + 4 + bpos, - in->data + 4 + (end >> 3), - out_size - (4 + (end >> 3))); + in->data + 4 + end, + out_size - (4 + end)); auheader = (parity_nibble ^ 0xF) << 12; auheader |= (out->size / 2) & 0x0fff; AV_WB16(out->data, auheader); ___ 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] libavformat/subfile: Improve AVSEEK_SIZE/SEEK_END seeking
ffmpeg | branch: master | Andreas Rheinhardt | Thu Jun 20 06:33:41 2019 +0200| [4877b5869ee1b3d17a3ed9b5b6d0988bd8b02b21] | committer: Nicolas George libavformat/subfile: Improve AVSEEK_SIZE/SEEK_END seeking The subfile protocol treats an end of 0 as meaning "until EOF"; this got implemented by simply setting the end to INT64_MAX. But seeking relative to EOF or AVSEEK_SIZE seeking hasn't been adapted; the result is that e.g. the duration of transport streams isn't correctly determined when this option is used. This is fixed in this patch. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4877b5869ee1b3d17a3ed9b5b6d0988bd8b02b21 --- libavformat/subfile.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libavformat/subfile.c b/libavformat/subfile.c index b527f2bee1..2f162e0a34 100644 --- a/libavformat/subfile.c +++ b/libavformat/subfile.c @@ -116,11 +116,17 @@ static int subfile_read(URLContext *h, unsigned char *buf, int size) static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) { SubfileContext *c = h->priv_data; -int64_t new_pos = -1; +int64_t new_pos = -1, end; int ret; +if (whence == AVSEEK_SIZE || whence == SEEK_END) { +end = c->end; +if (end == INT64_MAX && (end = ffurl_seek(c->h, 0, AVSEEK_SIZE)) < 0) +return end; +} + if (whence == AVSEEK_SIZE) -return c->end - c->start; +return end - c->start; switch (whence) { case SEEK_SET: new_pos = c->start + pos; @@ -129,7 +135,7 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) new_pos += pos; break; case SEEK_END: -new_pos = c->end + c->pos; +new_pos = end + c->pos; break; } if (new_pos < c->start) ___ 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] av1_metadata: Error out if fragment is empty
ffmpeg | branch: master | Andreas Rheinhardt | Thu Jun 20 01:45:00 2019 +0200| [3f81cc8c94586ccd500827b606c1eabfb6e2dadb] | committer: Mark Thompson av1_metadata: Error out if fragment is empty If the fragment is empty after parsing (i.e. it contains no OBUs), then the check for the type of the fragment's first OBU is nonsensical; so error out in this case just as h264_metadata and hevc_metadata do. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3f81cc8c94586ccd500827b606c1eabfb6e2dadb --- libavcodec/av1_metadata_bsf.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index 842b80c201..bb2ca2075b 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -133,6 +133,12 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } +if (frag->nb_units == 0) { +av_log(bsf, AV_LOG_ERROR, "No OBU in packet.\n"); +err = AVERROR_INVALIDDATA; +goto fail; +} + for (i = 0; i < frag->nb_units; i++) { if (frag->units[i].type == AV1_OBU_SEQUENCE_HEADER) { obu = frag->units[i].content; ___ 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: Allow non-blank packets in ff_cbs_write_packet
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:06 2019 +0200| [1e93f5060f6f6f7a8729022d0120004902b4f64b] | committer: Mark Thompson cbs: Allow non-blank packets in ff_cbs_write_packet Up until now, ff_cbs_write_packet always initialized the packet structure it received without documenting this behaviour; furthermore, the packet's buffer would (on success) be overwritten with the new buffer without unreferencing the old. This meant that the input packet had to be either clean (otherwise there would be memleaks) in which case the initialization is redundant or uninitialized. ff_cbs_write_packet was never used with uninitialized packets, so the initialization was redundant. Worse yet, it forced callers to use more than one packet and made it difficult to add side-data to a packet designated for output, because said side-data could only be attached after the call to ff_cbs_write_packet. This has been changed. It is now allowed to use a non-blank packet. The currently existing buffer will be unreferenced and replaced by the new one, as will be the accompanying fields (i.e. data and size). The rest isn't touched at all. This change will enable us to use only one packet in the bitstream filters that rely on CBS. This commit also updates the documentation of ff_cbs_write_extradata and ff_cbs_write_packet (to better describe existing behaviour and in the latter case to also describe the new behaviour). Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e93f5060f6f6f7a8729022d0120004902b4f64b --- libavcodec/cbs.c | 3 ++- libavcodec/cbs.h | 10 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 0260ba6f67..47679eca1b 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -357,7 +357,8 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, if (!buf) return AVERROR(ENOMEM); -av_init_packet(pkt); +av_buffer_unref(>buf); + pkt->buf = buf; pkt->data = frag->data; pkt->size = frag->data_size; diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 967dcd1468..5260a39c63 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -297,7 +297,8 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, /** * Write the bitstream of a fragment to the extradata in codec parameters. * - * This replaces any existing extradata in the structure. + * Modifies context and fragment as ff_cbs_write_fragment_data does and + * replaces any existing extradata in the structure. */ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, @@ -305,6 +306,13 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, /** * Write the bitstream of a fragment to a packet. + * + * Modifies context and fragment as ff_cbs_write_fragment_data does. + * + * On success, the packet's buf is unreferenced and its buf, data and + * size fields are set to the corresponding values from the newly updated + * fragment; other fields are not touched. On failure, the packet is not + * touched at all. */ int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, ___ 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] filter_units: Reindent after previous commit
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:10 2019 +0200| [57f9bc90ae0993768c3ee70c5d9041aecc8593ed] | committer: Mark Thompson filter_units: Reindent after previous commit Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=57f9bc90ae0993768c3ee70c5d9041aecc8593ed --- libavcodec/filter_units_bsf.c | 46 +-- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index a787933f0a..8c501e1726 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -105,33 +105,33 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) AVPacket *in = NULL; int err, i, j; -err = ff_bsf_get_packet(bsf, ); -if (err < 0) -return err; +err = ff_bsf_get_packet(bsf, ); +if (err < 0) +return err; -if (ctx->mode == NOOP) { -av_packet_move_ref(out, in); -av_packet_free(); -return 0; -} +if (ctx->mode == NOOP) { +av_packet_move_ref(out, in); +av_packet_free(); +return 0; +} -err = ff_cbs_read_packet(ctx->cbc, frag, in); -if (err < 0) { -av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); -goto fail; -} +err = ff_cbs_read_packet(ctx->cbc, frag, in); +if (err < 0) { +av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); +goto fail; +} -for (i = 0; i < frag->nb_units; i++) { -for (j = 0; j < ctx->nb_types; j++) { -if (frag->units[i].type == ctx->type_list[j]) -break; -} -if (ctx->mode == REMOVE ? j < ctx->nb_types -: j >= ctx->nb_types) { -ff_cbs_delete_unit(ctx->cbc, frag, i); ---i; -} +for (i = 0; i < frag->nb_units; i++) { +for (j = 0; j < ctx->nb_types; j++) { +if (frag->units[i].type == ctx->type_list[j]) +break; +} +if (ctx->mode == REMOVE ? j < ctx->nb_types +: j >= ctx->nb_types) { +ff_cbs_delete_unit(ctx->cbc, frag, i); +--i; } +} if (frag->nb_units == 0) { // Don't return packets with nothing in them. ___ 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] filter_units: Avoid allocations and copies of packet structures
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:11 2019 +0200| [b0810454e473dd321a27c43de2d0e9d02fdba556] | committer: Mark Thompson filter_units: Avoid allocations and copies of packet structures This commit changes filter_units to (a) use ff_bsf_get_packet_ref instead of ff_bsf_get_packet (thereby avoiding one malloc and free per filtered packet) and (b) to use only one packet structure at all, thereby avoiding a call to av_packet_copy_props (or, in case of passthrough, to av_packet_move_ref). (b) has been made possible by the recent changes to ff_cbs_write_packet. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b0810454e473dd321a27c43de2d0e9d02fdba556 --- libavcodec/filter_units_bsf.c | 21 ++--- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 8c501e1726..f3691a5755 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -98,24 +98,20 @@ invalid: return AVERROR(EINVAL); } -static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) +static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) { FilterUnitsContext *ctx = bsf->priv_data; CodedBitstreamFragment *frag = >fragment; -AVPacket *in = NULL; int err, i, j; -err = ff_bsf_get_packet(bsf, ); +err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; -if (ctx->mode == NOOP) { -av_packet_move_ref(out, in); -av_packet_free(); +if (ctx->mode == NOOP) return 0; -} -err = ff_cbs_read_packet(ctx->cbc, frag, in); +err = ff_cbs_read_packet(ctx->cbc, frag, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -139,21 +135,16 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) goto fail; } -err = ff_cbs_write_packet(ctx->cbc, out, frag); +err = ff_cbs_write_packet(ctx->cbc, pkt, frag); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; } -err = av_packet_copy_props(out, in); -if (err < 0) -goto fail; - fail: if (err < 0) -av_packet_unref(out); +av_packet_unref(pkt); ff_cbs_fragment_reset(ctx->cbc, frag); -av_packet_free(); return err; } ___ 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] h264_metadata: Localize code for display orientation
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:14 2019 +0200| [3c8a2a1180f03ca6b299ebc27eef21ae86635ca0] | committer: Mark Thompson h264_metadata: Localize code for display orientation The recent changes to h264_metadata (enabled by the recent changes to ff_cbs_write_packet) made it possible to add side_data to the output packet at any place, not only after the output packet has been written and the properties of the input packet copied. This means that one can now localize the code to add display orientation side-data to the packet to the place dealing with said display-orientation. Furthermore, the documentation of av_display_rotation_set states that the matrix will be fully overwritten by it, so there is no need to allocate it with av_mallocz. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c8a2a1180f03ca6b299ebc27eef21ae86635ca0 --- libavcodec/h264_metadata_bsf.c | 33 - 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 18c5ae807d..f7ca1f0f09 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -289,8 +289,6 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) CodedBitstreamFragment *au = >access_unit; int err, i, j, has_sps; H264RawAUD aud; -uint8_t *displaymatrix_side_data = NULL; -size_t displaymatrix_side_data_size = 0; err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) @@ -487,7 +485,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) continue; } -matrix = av_mallocz(9 * sizeof(int32_t)); +matrix = av_malloc(9 * sizeof(int32_t)); if (!matrix) { err = AVERROR(ENOMEM); goto fail; @@ -499,11 +497,17 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); // If there are multiple display orientation messages in an -// access unit then ignore all but the first one. -av_freep(_side_data); - -displaymatrix_side_data = (uint8_t*)matrix; -displaymatrix_side_data_size = 9 * sizeof(int32_t); +// access unit, then the last one added to the packet (i.e. +// the first one in the access unit) will prevail. +err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, + (uint8_t*)matrix, + 9 * sizeof(int32_t)); +if (err < 0) { +av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " + "displaymatrix side data to packet.\n"); +av_freep(matrix); +goto fail; +} } } } @@ -583,24 +587,11 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } -if (displaymatrix_side_data) { -err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, - displaymatrix_side_data, - displaymatrix_side_data_size); -if (err) { -av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " - "displaymatrix side data to packet.\n"); -goto fail; -} -displaymatrix_side_data = NULL; -} - ctx->done_first_au = 1; err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, au); -av_freep(_side_data); if (err < 0) av_packet_unref(pkt); ___ 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] av1_metadata: Avoid allocations and copies of packet structures
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:07 2019 +0200| [7549f0ac1baffabfa964962c0c0067e8da692982] | committer: Mark Thompson av1_metadata: Avoid allocations and copies of packet structures This commit changes av1_metadata to (a) use ff_bsf_get_packet_ref instead of ff_bsf_get_packet (thereby avoiding one malloc and free per filtered packet) and (b) to use only one packet structure at all, thereby avoiding a call to av_packet_copy_props. (b) has been made possible by the recent changes to ff_cbs_write_packet. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7549f0ac1baffabfa964962c0c0067e8da692982 --- libavcodec/av1_metadata_bsf.c | 16 +--- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index fe208feaf5..e294d7a24e 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -116,19 +116,18 @@ static int av1_metadata_update_sequence_header(AVBSFContext *bsf, return 0; } -static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { AV1MetadataContext *ctx = bsf->priv_data; -AVPacket *in = NULL; CodedBitstreamFragment *frag = >access_unit; AV1RawOBU td, *obu; int err, i; -err = ff_bsf_get_packet(bsf, ); +err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; -err = ff_cbs_read_packet(ctx->cbc, frag, in); +err = ff_cbs_read_packet(ctx->cbc, frag, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -173,23 +172,18 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out) } } -err = ff_cbs_write_packet(ctx->cbc, out, frag); +err = ff_cbs_write_packet(ctx->cbc, pkt, frag); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; } -err = av_packet_copy_props(out, in); -if (err < 0) -goto fail; - err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, frag); if (err < 0) -av_packet_unref(out); -av_packet_free(); +av_packet_unref(pkt); return err; } ___ 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] filter_units: Don't use fake loop
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:09 2019 +0200| [83be17cfcdd98a09d93960d6df2ac4bdee884059] | committer: Mark Thompson filter_units: Don't use fake loop According to the BSF API, when a BSF is finished with an input packet, it should return AVERROR(EAGAIN) to signal that another packet should be sent to the BSF via av_bsf_send_packet that the actual BSF can receive via ff_bsf_get_packet[_ref]. filter_units on the other hand simply called ff_bsf_get_packet again if the first packet received didn't result in any output. This call of course returned AVERROR(EAGAIN) which was returned, but it is nevertheless better to not include a fake loop. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=83be17cfcdd98a09d93960d6df2ac4bdee884059 --- libavcodec/filter_units_bsf.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 0876693c81..a787933f0a 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -105,7 +105,6 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) AVPacket *in = NULL; int err, i, j; -while (1) { err = ff_bsf_get_packet(bsf, ); if (err < 0) return err; @@ -134,12 +133,10 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) } } -if (frag->nb_units > 0) -break; - +if (frag->nb_units == 0) { // Don't return packets with nothing in them. -av_packet_free(); -ff_cbs_fragment_reset(ctx->cbc, frag); +err = AVERROR(EAGAIN); +goto fail; } err = ff_cbs_write_packet(ctx->cbc, out, frag); ___ 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] h264_metadata: Avoid allocations and copies of packet structures
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:13 2019 +0200| [a72cc47a275a62c9a36f9df8c912e6f1cd820fc7] | committer: Mark Thompson h264_metadata: Avoid allocations and copies of packet structures This commit changes h264_metadata to (a) use ff_bsf_get_packet_ref instead of ff_bsf_get_packet (thereby avoiding one malloc and free per filtered packet) and (b) to use only one packet structure at all, thereby avoiding a call to av_packet_copy_props. (b) has been made possible by the recent changes to ff_cbs_write_packet. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a72cc47a275a62c9a36f9df8c912e6f1cd820fc7 --- libavcodec/h264_metadata_bsf.c | 20 +++- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index b95d2341dc..18c5ae807d 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -283,21 +283,20 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, return 0; } -static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) { H264MetadataContext *ctx = bsf->priv_data; -AVPacket *in = NULL; CodedBitstreamFragment *au = >access_unit; int err, i, j, has_sps; H264RawAUD aud; uint8_t *displaymatrix_side_data = NULL; size_t displaymatrix_side_data_size = 0; -err = ff_bsf_get_packet(bsf, ); +err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) return err; -err = ff_cbs_read_packet(ctx->cbc, au, in); +err = ff_cbs_read_packet(ctx->cbc, au, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -518,7 +517,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) int size; int write = 0; -data = av_packet_get_side_data(in, AV_PKT_DATA_DISPLAYMATRIX, ); +data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, ); if (data && size >= 9 * sizeof(int32_t)) { int32_t matrix[9]; int hflip, vflip; @@ -578,18 +577,14 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) } } -err = ff_cbs_write_packet(ctx->cbc, out, au); +err = ff_cbs_write_packet(ctx->cbc, pkt, au); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; } -err = av_packet_copy_props(out, in); -if (err < 0) -goto fail; - if (displaymatrix_side_data) { -err = av_packet_add_side_data(out, AV_PKT_DATA_DISPLAYMATRIX, +err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, displaymatrix_side_data, displaymatrix_side_data_size); if (err) { @@ -608,8 +603,7 @@ fail: av_freep(_side_data); if (err < 0) -av_packet_unref(out); -av_packet_free(); +av_packet_unref(pkt); return err; } ___ 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] filter_units: Unref packet on failure
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:08 2019 +0200| [45fd7e44a4ddee636d8c30b92b6a0ff39f976936] | committer: Mark Thompson filter_units: Unref packet on failure According to the API, the packet structure a bsf receives must not be touched on failure, yet filter_units nevertheless did it. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=45fd7e44a4ddee636d8c30b92b6a0ff39f976936 --- libavcodec/filter_units_bsf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index bc2ca288dd..0876693c81 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -153,6 +153,8 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out) goto fail; fail: +if (err < 0) +av_packet_unref(out); ff_cbs_fragment_reset(ctx->cbc, frag); av_packet_free(); ___ 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] av1/h264_metadata, filter_units: Count down when deleting units
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 17 05:42:12 2019 +0200| [36fcdc3fbe089bc01066e2afa5645f383025f0ec] | committer: Mark Thompson av1/h264_metadata, filter_units: Count down when deleting units When testing whether a particular unit should be kept or discarded, it is best to start at the very last unit of a fragment and count down, because that way a unit that will eventually be deleted won't be memmoved during earlier deletions; and frag/au->nb_units need only be evaluated once in this case and the counter is automatically correct when a unit got deleted. It also works for double loops, i.e. when looping over all SEI messages in all SEI units of an access unit. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=36fcdc3fbe089bc01066e2afa5645f383025f0ec --- libavcodec/av1_metadata_bsf.c | 3 +-- libavcodec/filter_units_bsf.c | 6 ++ libavcodec/h264_metadata_bsf.c | 18 ++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c index e294d7a24e..842b80c201 100644 --- a/libavcodec/av1_metadata_bsf.c +++ b/libavcodec/av1_metadata_bsf.c @@ -160,14 +160,13 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) } if (ctx->delete_padding) { -for (i = 0; i < frag->nb_units; i++) { +for (i = frag->nb_units - 1; i >= 0; i--) { if (frag->units[i].type == AV1_OBU_PADDING) { err = ff_cbs_delete_unit(ctx->cbc, frag, i); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to delete Padding OBU.\n"); goto fail; } ---i; } } } diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index f3691a5755..380f23e5a7 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -117,16 +117,14 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } -for (i = 0; i < frag->nb_units; i++) { +for (i = frag->nb_units - 1; i >= 0; i--) { for (j = 0; j < ctx->nb_types; j++) { if (frag->units[i].type == ctx->type_list[j]) break; } if (ctx->mode == REMOVE ? j < ctx->nb_types -: j >= ctx->nb_types) { +: j >= ctx->nb_types) ff_cbs_delete_unit(ctx->cbc, frag, i); ---i; -} } if (frag->nb_units == 0) { diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index ae54929b85..b95d2341dc 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -428,7 +428,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) } if (ctx->delete_filler) { -for (i = 0; i < au->nb_units; i++) { +for (i = au->nb_units - 1; i >= 0; i--) { if (au->units[i].type == H264_NAL_FILLER_DATA) { // Filler NAL units. err = ff_cbs_delete_unit(ctx->cbc, au, i); @@ -437,7 +437,6 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) "filler NAL.\n"); goto fail; } ---i; continue; } @@ -445,7 +444,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) // Filler SEI messages. H264RawSEI *sei = au->units[i].content; -for (j = 0; j < sei->payload_count; j++) { +for (j = sei->payload_count - 1; j >= 0; j--) { if (sei->payload[j].payload_type == H264_SEI_TYPE_FILLER_PAYLOAD) { err = ff_cbs_h264_delete_sei_message(ctx->cbc, au, @@ -455,10 +454,6 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) "filler SEI message.\n"); goto fail; } -// Renumbering might have happened, start again at -// the same NAL unit position. ---i; -break; } } } @@ -466,13 +461,13 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) } if (ctx->display_orientation != PASS) { -for (i = 0; i < au->nb_units; i++) { +for (i = au->nb_units - 1; i >= 0; i--) { H264RawSEI *sei; if (au->units[i].type != H264_NAL_SEI) continue; sei = au->units[i].content; -for (j = 0; j &
[FFmpeg-cvslog] dump_extra: Don't add extradata if it already exists
ffmpeg | branch: master | Andreas Rheinhardt | Sat Jul 13 04:55:50 2019 +0200| [3469cfab4adb242fa2116f4858f0768cec400afa] | committer: Michael Niedermayer dump_extra: Don't add extradata if it already exists The dump_extra bitstream filter currently simply adds the extradata to the packets indicated by the user without checking whether said extradata already exists in the packets. Besides wasting space duplicated extradata in the same packet/access unit is also forbidden for some codecs, e.g. MPEG-2. This check has been added to be able to use the mpeg2_qsv encoder (which only adds the sequence headers to the first packet) in broadcast scenarios where repeating sequence headers are required. The check used here is not perfect: E.g. dump_extra would add the extradata to a H.264 access unit consisting of an access unit delimiter, SPS, PPS and slices. Fixes #8007. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3469cfab4adb242fa2116f4858f0768cec400afa --- doc/bitstream_filters.texi | 4 +++- libavcodec/dump_extradata_bsf.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index a6a5a331f5..14f35893d3 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -103,7 +103,9 @@ DTS-HD. @section dump_extra -Add extradata to the beginning of the filtered packets. +Add extradata to the beginning of the filtered packets except when +said packets already exactly begin with the extradata that is intended +to be added. @table @option @item freq diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c index 7112cd6bd4..b641508234 100644 --- a/libavcodec/dump_extradata_bsf.c +++ b/libavcodec/dump_extradata_bsf.c @@ -50,7 +50,9 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out) if (ctx->par_in->extradata && (s->freq == DUMP_FREQ_ALL || - (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY))) { + (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) && + in->size >= ctx->par_in->extradata_size && + memcmp(in->data, ctx->par_in->extradata, ctx->par_in->extradata_size)) { if (in->size >= INT_MAX - ctx->par_in->extradata_size) { ret = AVERROR(ERANGE); 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] avformat/matroskadec: Reuse positions
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:12 2019 +0200| [7087fc95b258793cf55953e10fb9005f01141bc2] | committer: James Almer avformat/matroskadec: Reuse positions Up until now, avio_tell was used multiple times in ebml_parse and its subroutines, although the result of these calls can usually be simply derived from the result of earlier calls to avio_tell. This has been changed. Unnecessary calls to avio_tell in ebml_parse are avoided now. Furthermore, there has been a slight change in the output of some error messages relating to elements exceeding their containing master element: The reported position of the element now points to the first byte of the element ID and no longer to the first byte of the element's payload. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7087fc95b258793cf55953e10fb9005f01141bc2 --- libavformat/matroskadec.c | 33 +++-- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 8ab233b8df..686b988859 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -976,7 +976,8 @@ static int ebml_read_ascii(AVIOContext *pb, int size, char **str) * Read the next element as binary data. * 0 is success, < 0 or NEEDS_CHECKING is failure. */ -static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) +static int ebml_read_binary(AVIOContext *pb, int length, +int64_t pos, EbmlBin *bin) { int ret; @@ -987,7 +988,7 @@ static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) bin->data = bin->buf->data; bin->size = length; -bin->pos = avio_tell(pb); +bin->pos = pos; if ((ret = avio_read(pb, bin->data, length)) != length) { av_buffer_unref(>buf); bin->data = NULL; @@ -1003,9 +1004,9 @@ static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) * are supposed to be sub-elements which can be read separately. * 0 is success, < 0 is failure. */ -static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length) +static int ebml_read_master(MatroskaDemuxContext *matroska, +uint64_t length, int64_t pos) { -AVIOContext *pb = matroska->ctx->pb; MatroskaLevel *level; if (matroska->num_levels >= EBML_MAX_DEPTH) { @@ -1015,7 +1016,7 @@ static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length) } level = >levels[matroska->num_levels++]; -level->start = avio_tell(pb); +level->start = pos; level->length = length; return 0; @@ -1173,7 +1174,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, AVIOContext *pb = matroska->ctx->pb; uint32_t id; uint64_t length; -int64_t pos = avio_tell(pb); +int64_t pos = avio_tell(pb), pos_alt; int res, update_pos = 1, level_check; void *newelem; MatroskaLevel1Element *level1_elem; @@ -1201,8 +1202,11 @@ static int ebml_parse(MatroskaDemuxContext *matroska, return res; } matroska->current_id = id | 1 << 7 * res; -} else -pos -= (av_log2(matroska->current_id) + 7) / 8; +pos_alt = pos + res; +} else { +pos_alt = pos; +pos-= (av_log2(matroska->current_id) + 7) / 8; +} id = matroska->current_id; @@ -1247,14 +1251,15 @@ static int ebml_parse(MatroskaDemuxContext *matroska, length, max_lengths[syntax->type], syntax->type); return AVERROR_INVALIDDATA; } + +pos_alt += res; + if (matroska->num_levels > 0) { MatroskaLevel *level = >levels[matroska->num_levels - 1]; -AVIOContext *pb = matroska->ctx->pb; -int64_t pos = avio_tell(pb); if (length != EBML_UNKNOWN_LENGTH && level->length != EBML_UNKNOWN_LENGTH) { -uint64_t elem_end = pos + length, +uint64_t elem_end = pos_alt + length, level_end = level->start + level->length; if (elem_end < level_end) { @@ -1309,14 +1314,14 @@ static int ebml_parse(MatroskaDemuxContext *matroska, res = ebml_read_ascii(pb, length, data); break; case EBML_BIN: -res = ebml_read_binary(pb, length, data); +res = ebml_read_binary(pb, length, pos_alt, data); break; case EBML_LEVEL1: case EBML_NEST: -if ((res = ebml_read_master(matroska, length)) < 0) +if ((res = ebml_read_master(matroska, length, pos_alt)) < 0) return res; if (id == MATROSKA_ID_SEGMENT) -matroska->segment_start = avio_tell(matroska->ctx->pb); +matroska->seg
[FFmpeg-cvslog] avformat/matroskadec: Introduce a "last known good" position
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:05 2019 +0200| [a3db9f62a42a8e5365de67722ecfac7065a70699] | committer: James Almer avformat/matroskadec: Introduce a "last known good" position Currently, resyncing during reading packets works as follows: The current position is recorded, then a call to matroska_parse_cluster is made and if said call fails, the demuxer tries to resync from the earlier position. If the call doesn't fail, but also doesn't deliver a packet, then this is looped. There are two problems with this approach: 1. The Matroska file format aims to be forward-compatible; to achieve this, a demuxer should simply ignore and skip elements it doesn't know about. But it is not possible to reliably distinguish unknown elements from junk. If matroska_parse_cluster encounters an unknown element, it can therefore not simply error out; instead it returns zero and the loop is iterated which includes an update of the position that is intended to be used in case of errors, i.e. the element that is skipped is not searched for level 1 element ids to resync to at all if later calls to matroska_parse_cluster return an error. Notice that in case that sync has been lost there can be a chain of several unknown/possibly junk elements before an error is detected. 2. Even if a call to matroska_parse_cluster delivers a packet, this does not mean that everything is fine. E.g. it might be that some of the block's data is missing and that the data that was presumed to be from the block just read actually contains the beginning of the next element. This will only be apparent at the next call of matroska_read_packet, which uses the (false) end of the earlier block as resync position so that in the (not unlikely) case that the call to matroska_parse_cluster fails, the data believed to be part of the earlier block is not searched for a level 1 element to resync to. To counter this, a "last known good" position is introduced. When an element id that is known to be allowed at this position in the hierarchy (according to the syntax currently in use for parsing) is read and some further checks (regarding the length of the element and its containing master element) are passed, then the beginning of the current element is treated as a "good" position and recorded as such in the MatroskaDemuxContext. Because of 2., only the start of the element is treated as a "good" position, not the whole element. If an error occurs later during parsing of clusters, the resync process starts at the last known good position. Given that when the header is damaged the subsequent resync never skips over data and is therefore unaffected by both issues, the "last known good" concept is not used there. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a3db9f62a42a8e5365de67722ecfac7065a70699 --- libavformat/matroskadec.c | 27 +++ 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index eec7181d20..6825002523 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -335,6 +335,7 @@ typedef struct MatroskaDemuxContext { int num_levels; MatroskaLevel levels[EBML_MAX_DEPTH]; uint32_t current_id; +int64_t resync_pos; uint64_t time_scale; double duration; @@ -754,6 +755,9 @@ static int matroska_reset_status(MatroskaDemuxContext *matroska, matroska->current_id = id; matroska->num_levels = 1; matroska->current_cluster.pos = 0; +matroska->resync_pos = avio_tell(matroska->ctx->pb); +if (id) +matroska->resync_pos -= (av_log2(id) + 7) / 8; return 0; } @@ -1168,7 +1172,8 @@ static int ebml_parse(MatroskaDemuxContext *matroska, AVIOContext *pb = matroska->ctx->pb; uint32_t id; uint64_t length; -int res; +int64_t pos = avio_tell(pb); +int res, update_pos = 1; void *newelem; MatroskaLevel1Element *level1_elem; @@ -1181,7 +1186,8 @@ static int ebml_parse(MatroskaDemuxContext *matroska, res == AVERROR_EOF) ? 1 : res; } matroska->current_id = id | 1 << 7 * res; -} +} else +pos -= (av_log2(matroska->current_id) + 7) / 8; id = matroska->current_id; @@ -1192,6 +1198,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, return 0; // we reached the end of an unknown size cluster if (!syntax->id && id != EBML_ID_VOID && id != EBML_ID_CRC32) { av_log(matroska->ctx, AV_LOG_DEBUG, "Unknown entry 0x%"PRIX32"\n", id); +update_pos = 0; } data = (char *) data + syntax->data_offset; @@ -1246,6 +1253,13 @@ static int ebml_parse(MatroskaDemuxContext *matroska, return AVERROR_INVALIDDATA; } } + +
[FFmpeg-cvslog] avformat/matroskadec: Link to parents in syntax tables
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:06 2019 +0200| [c1abd95ad0964ff7295fa38af564f2dea1a3b314] | committer: James Almer avformat/matroskadec: Link to parents in syntax tables By linking to the syntax of the parent (i.e. the containing master element) one can check whether an element is actually part of a higher level in the EBML hierarchy. Knowing this is important for unknown-length levels, because they end when an element that doesn't belong to this, but to a higher hierarchy level is encountered. Sometimes there are different syntaxes dealing with the same elements. In this case it is important to use a parent that contains all the elements at the parent level; whether this is the syntax actually used to enter the child's level is irrelevant. This affects the list of level 1 elements (which has been used as parent for matroska_cluster, too) and it affects recursive elements (currently only the SimpleTag), where the non-recursive parent has to be choosen. This is in preparation for a patch that redoes level handling. Finally, the segment id has been added to ebml_syntax. This will enable handling of unknown-length EBML headers. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c1abd95ad0964ff7295fa38af564f2dea1a3b314 --- libavformat/matroskadec.c | 89 ++- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 6825002523..e8ebdea661 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -378,6 +378,15 @@ typedef struct MatroskaDemuxContext { int bandwidth; } MatroskaDemuxContext; +#define CHILD_OF(parent) { .def = { .n = parent } } + +static const EbmlSyntax ebml_syntax[], matroska_segment[], matroska_track_video_color[], matroska_track_video[], +matroska_track[], matroska_track_encoding[], matroska_track_encodings[], +matroska_track_combine_planes[], matroska_track_operation[], matroska_tracks[], +matroska_attachments[], matroska_chapter_entry[], matroska_chapter[], matroska_chapters[], +matroska_index_entry[], matroska_index[], matroska_tag[], matroska_tags[], matroska_seekhead[], +matroska_blockadditions[], matroska_blockgroup[], matroska_cluster_parsing[]; + static const EbmlSyntax ebml_header[] = { { EBML_ID_EBMLREADVERSION,EBML_UINT, 0, offsetof(Ebml, version), { .u = EBML_VERSION } }, { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml, max_size), { .u = 8 } }, @@ -386,11 +395,12 @@ static const EbmlSyntax ebml_header[] = { { EBML_ID_DOCTYPEREADVERSION, EBML_UINT, 0, offsetof(Ebml, doctype_version), { .u = 1 } }, { EBML_ID_EBMLVERSION,EBML_NONE }, { EBML_ID_DOCTYPEVERSION, EBML_NONE }, -{ 0 } +CHILD_OF(ebml_syntax) }; static const EbmlSyntax ebml_syntax[] = { -{ EBML_ID_HEADER, EBML_NEST, 0, 0, { .n = ebml_header } }, +{ EBML_ID_HEADER, EBML_NEST, 0, 0, { .n = ebml_header } }, +{ MATROSKA_ID_SEGMENT, EBML_STOP }, { 0 } }; @@ -402,7 +412,7 @@ static const EbmlSyntax matroska_info[] = { { MATROSKA_ID_MUXINGAPP, EBML_UTF8, 0, offsetof(MatroskaDemuxContext, muxingapp) }, { MATROSKA_ID_DATEUTC, EBML_BIN, 0, offsetof(MatroskaDemuxContext, date_utc) }, { MATROSKA_ID_SEGMENTUID,EBML_NONE }, -{ 0 } +CHILD_OF(matroska_segment) }; static const EbmlSyntax matroska_mastering_meta[] = { @@ -416,7 +426,7 @@ static const EbmlSyntax matroska_mastering_meta[] = { { MATROSKA_ID_VIDEOCOLOR_WHITEY, EBML_FLOAT, 0, offsetof(MatroskaMasteringMeta, white_y), { .f=-1 } }, { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, EBML_FLOAT, 0, offsetof(MatroskaMasteringMeta, min_luminance), { .f=-1 } }, { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, EBML_FLOAT, 0, offsetof(MatroskaMasteringMeta, max_luminance), { .f=-1 } }, -{ 0 } +CHILD_OF(matroska_track_video_color) }; static const EbmlSyntax matroska_track_video_color[] = { @@ -434,7 +444,7 @@ static const EbmlSyntax matroska_track_video_color[] = { { MATROSKA_ID_VIDEOCOLORMAXCLL, EBML_UINT, 0, offsetof(MatroskaTrackVideoColor, max_cll), { .u=0 } }, { MATROSKA_ID_VIDEOCOLORMAXFALL, EBML_UINT, 0, offsetof(MatroskaTrackVideoColor, max_fall), { .u=0 } }, { MATROSKA_ID_VIDEOCOLORMASTERINGMETA,EBML_NEST, 0, offsetof(MatroskaTrackVideoColor, mastering_meta), { .n = matroska_mastering_meta } }, -{ 0 } +CHILD_OF(matroska_track_video) }; static const EbmlSyntax matroska_track_video_projection[] = { @@ -443,7 +453,7 @@ static const EbmlSyntax matroska_track_video_projection[] = { { MATROSKA_ID_VIDEOPROJECTIONPOSEYAW, EBML_FLOAT, 0, offsetof(MatroskaTrackVideoProjection, yaw), { .f=
[FFmpeg-cvslog] avformat/matroskadec: Combine arrays
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:10 2019 +0200| [38255cdcf815ff44bb0ab10cb16b96e409f2eeed] | committer: James Almer avformat/matroskadec: Combine arrays By including SimpleBlocks and BlockGroups twice in the same EbmlSyntax array (with different semantics), one can reduce the duplication of the other values. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=38255cdcf815ff44bb0ab10cb16b96e409f2eeed --- libavformat/matroskadec.c | 18 -- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d2db3e5f0b..19eb5b0041 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -716,26 +716,21 @@ static const EbmlSyntax matroska_blockgroup[] = { CHILD_OF(matroska_cluster_parsing) }; +// The following array contains SimpleBlock and BlockGroup twice +// in order to reuse the other values for matroska_cluster_enter. static const EbmlSyntax matroska_cluster_parsing[] = { -{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, -{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, -{ MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, -{ MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, -CHILD_OF(matroska_segment) -}; - -static const EbmlSyntax matroska_cluster_initial[] = { +{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, -{ MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, +{ MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, CHILD_OF(matroska_segment) }; static const EbmlSyntax matroska_cluster_enter[] = { -{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster_initial } }, +{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = _cluster_parsing[2] } }, { 0 } }; @@ -1063,6 +1058,9 @@ static int ebml_parse(MatroskaDemuxContext *matroska, static EbmlSyntax *ebml_parse_id(EbmlSyntax *syntax, uint32_t id) { int i; + +// Whoever touches this should be aware of the duplication +// existing in matroska_cluster_parsing. for (i = 0; syntax[i].id; i++) if (id == syntax[i].id) break; ___ 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/matroskadec: Redo level handling
ffmpeg | branch: master | Andreas Rheinhardt | Mon Jun 24 01:46:54 2019 +0200| [b31c9b72e5e677149b73b5f26b0c1deabc6a0803] | committer: James Almer avformat/matroskadec: Redo level handling This commit changes how levels are handled: If the level used for ebml_parse ends directly after an element that has been consumed, then ebml_parse ends the level itself (and any known-length levels that end there as well) and informs the caller via the return value; if the current level is of unknown-length, then the level is ended as soon as an element that is not valid on the current level, but on a higher level is encountered (or if EOF has been encountered). This is designed for situations where one wants to parse master elements incrementally, i.e. not in one go via ebml_parse_nest. The (incremental) parsing of clusters still mixes levels by using a syntax list that contains elements from different levels and the level is still ended manually via a call to ebml_level_end if the last cluster was an unknown-length cluster (known-length clusters are already ended when their last element is read), but only if the next element is a cluster, too. A different level 1 element following an unknown-length cluster will currently simply be presumed to be part of the earlier cluster. Fixing this will be done in a future patch. The modifications to matroska_parse_cluster contained in this patch are only intended not to cause regressions. Nevertheless, the fact that known-length levels are automatically ended in ebml_parse when their last element has been read already fixes a bogus error message introduced in 9326117b that was emitted when a known-length cluster is followed by another level 1 element other than a cluster in which case the cluster's level was not ended (which only happened when a new cluster has been encountered) so that the length check (introduced in 9326117b) failed for the level 1 element as it is of course not contained in the previous cluster. Most Matroska files were affected by this. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b31c9b72e5e677149b73b5f26b0c1deabc6a0803 --- libavformat/matroskadec.c | 103 -- 1 file changed, 82 insertions(+), 21 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e8ebdea661..05c12edd16 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -71,6 +71,8 @@ #define EBML_UNKNOWN_LENGTH UINT64_MAX /* EBML unknown length, in uint64_t */ #define NEEDS_CHECKING2 /* Indicates that some error checks * still need to be performed */ +#define LEVEL_ENDED 3 /* return value of ebml_parse when the + * syntax level used for parsing ended. */ typedef enum { EBML_NONE, @@ -1087,7 +1089,7 @@ static EbmlSyntax *ebml_parse_id(EbmlSyntax *syntax, uint32_t id) static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data) { -int i, res = 0; +int i, res; for (i = 0; syntax[i].id; i++) switch (syntax[i].type) { @@ -1112,10 +1114,16 @@ static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, break; } -while (!res && !ebml_level_end(matroska)) +if (!matroska->levels[matroska->num_levels - 1].length) { +matroska->num_levels--; +return 0; +} + +do { res = ebml_parse(matroska, syntax, data); +} while (!res); -return res; +return res == LEVEL_ENDED ? 0 : res; } static int is_ebml_id_valid(uint32_t id) @@ -1184,17 +1192,26 @@ static int ebml_parse(MatroskaDemuxContext *matroska, uint32_t id; uint64_t length; int64_t pos = avio_tell(pb); -int res, update_pos = 1; +int res, update_pos = 1, level_check; void *newelem; MatroskaLevel1Element *level1_elem; +MatroskaLevel *level = matroska->num_levels ? >levels[matroska->num_levels - 1] : NULL; if (!matroska->current_id) { uint64_t id; res = ebml_read_num(matroska, pb, 4, , 0); if (res < 0) { -// in live mode, finish parsing if EOF is reached. -return (matroska->is_live && pb->eof_reached && -res == AVERROR_EOF) ? 1 : res; +if (pb->eof_reached && res == AVERROR_EOF) { +if (matroska->is_live) +// in live mode, finish parsing if EOF is reached. +return 1; +if (level && level->length == EBML_UNKNOWN_LENGTH && pos == avio_tell(pb)) { +// Unknown-length levels automatically end at EOF. +matroska->num_levels--; +return LEVEL_ENDED; +} +
[FFmpeg-cvslog] avformat/matroskadec: Don't reset cluster position
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:09 2019 +0200| [a9f051519e2ad3e4ea3062d2fd437209dc865eb8] | committer: James Almer avformat/matroskadec: Don't reset cluster position The new code does not rely on whether the cluster's position is set or not to infer whether a cluster needs to be closed or not (instead, this is done in ebml_parse), so there is no need to reset the cluster's position at all any more. It will be automatically set to the correct value when a cluster is entered. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a9f051519e2ad3e4ea3062d2fd437209dc865eb8 --- libavformat/matroskadec.c | 14 +++--- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index db1b4b864f..d2db3e5f0b 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -770,7 +770,6 @@ static int matroska_reset_status(MatroskaDemuxContext *matroska, matroska->current_id = id; matroska->num_levels = 1; -matroska->current_cluster.pos = 0; matroska->resync_pos = avio_tell(matroska->ctx->pb); if (id) matroska->resync_pos -= (av_log2(id) + 7) / 8; @@ -1750,8 +1749,8 @@ static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, } } } -/* Seek back - notice that in all instances where this is used it is safe - * to set the level to 1 and unset the position of the current cluster. */ +/* Seek back - notice that in all instances where this is used + * it is safe to set the level to 1. */ matroska_reset_status(matroska, saved_id, before_pos); return ret; @@ -3606,7 +3605,6 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) } if (matroska->num_levels == 2) { -int err = 0; /* We are inside a cluster. */ res = ebml_parse(matroska, matroska_cluster_parsing, cluster); @@ -3615,7 +3613,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) uint8_t* additional = block->additional.size > 0 ? block->additional.data : NULL; -err = matroska_parse_block(matroska, block->bin.buf, block->bin.data, +res = matroska_parse_block(matroska, block->bin.buf, block->bin.data, block->bin.size, block->bin.pos, cluster->timecode, block->duration, is_keyframe, additional, block->additional_id, @@ -3623,14 +3621,8 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) block->discard_padding); } -if (res == LEVEL_ENDED) -cluster->pos = 0; - ebml_free(matroska_blockgroup, block); memset(block, 0, sizeof(*block)); - -if (err < 0) -return err; } else if (!matroska->num_levels) { matroska->done = 1; return AVERROR_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] avformat/matroskadec: Make cluster parsing level compatible
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:08 2019 +0200| [865c5370078fe743a8259a3f83d69e5a0cb693b2] | committer: James Almer avformat/matroskadec: Make cluster parsing level compatible Before this commit, the parsing of clusters mixed EBML levels by allowing elements from different levels in a EbmlSyntax (namely matroska_cluster_parsing). This has been changed. And the level is now explicitly used to determine how to parse. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=865c5370078fe743a8259a3f83d69e5a0cb693b2 --- libavformat/matroskadec.c | 106 -- 1 file changed, 47 insertions(+), 59 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 05c12edd16..db1b4b864f 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -722,15 +722,10 @@ static const EbmlSyntax matroska_cluster_parsing[] = { { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, -{ MATROSKA_ID_INFO,EBML_NONE }, -{ MATROSKA_ID_CUES,EBML_NONE }, -{ MATROSKA_ID_TAGS,EBML_NONE }, -{ MATROSKA_ID_SEEKHEAD,EBML_NONE }, -{ MATROSKA_ID_CLUSTER, EBML_STOP }, -{ 0 } /* We don't want to go back to level 0, so don't add the parent. */ +CHILD_OF(matroska_segment) }; -static const EbmlSyntax matroska_cluster[] = { +static const EbmlSyntax matroska_cluster_initial[] = { { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, @@ -739,12 +734,20 @@ static const EbmlSyntax matroska_cluster[] = { CHILD_OF(matroska_segment) }; +static const EbmlSyntax matroska_cluster_enter[] = { +{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster_initial } }, +{ 0 } +}; + static const EbmlSyntax matroska_clusters[] = { -{ MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, { .n = matroska_cluster } }, -{ MATROSKA_ID_INFO, EBML_NONE }, -{ MATROSKA_ID_CUES, EBML_NONE }, -{ MATROSKA_ID_TAGS, EBML_NONE }, -{ MATROSKA_ID_SEEKHEAD, EBML_NONE }, +{ MATROSKA_ID_CLUSTER, EBML_STOP }, +{ MATROSKA_ID_CUES,EBML_NONE }, +{ MATROSKA_ID_TAGS,EBML_NONE }, +{ MATROSKA_ID_INFO,EBML_NONE }, +{ MATROSKA_ID_TRACKS, EBML_NONE }, +{ MATROSKA_ID_ATTACHMENTS, EBML_NONE }, +{ MATROSKA_ID_CHAPTERS,EBML_NONE }, +{ MATROSKA_ID_SEEKHEAD,EBML_NONE }, { 0 } /* We don't want to go back to level 0, so don't add the parent. */ }; #undef CHILD_OF @@ -815,24 +818,6 @@ static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos) } /* - * Return: Whether we reached the end of a level in the hierarchy or not. - */ -static int ebml_level_end(MatroskaDemuxContext *matroska) -{ -AVIOContext *pb = matroska->ctx->pb; -int64_t pos = avio_tell(pb); - -if (matroska->num_levels > 0) { -MatroskaLevel *level = >levels[matroska->num_levels - 1]; -if (pos - level->start >= level->length || matroska->current_id) { -matroska->num_levels--; -return 1; -} -} -return (matroska->is_live && matroska->ctx->pb->eof_reached) ? 1 : 0; -} - -/* * Read: an "EBML number", which is defined as a variable-length * array of bytes. The first byte indicates the length by giving a * number of 0-bits followed by a one. The position of the first @@ -3604,43 +3589,39 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) MatroskaCluster *cluster = >current_cluster; MatroskaBlock *block = >block; int res; -res = ebml_parse(matroska, - matroska_cluster_parsing, - cluster); -if (res == 1) { -/* New Cluster */ -if (cluster->pos) -ebml_level_end(matroska); -cluster->pos = avio_tell(matroska->ctx->pb); -/* sizeof the ID which was already read */ -if (matroska->current_id) -cluster->pos -= 4; -res = ebml_parse(matroska, - matroska_clusters, - cluster); -/* Try parsing the block again. */ -if (res == 1) -res = ebml_parse(matroska, - matroska_cluster_parsing, - cluster); -else -cluster->pos = 0; + +av_assert0(matroska->num_levels <= 2); + +if (matroska->num_levels == 1) { +res = ebml_parse(matroska, matroska_clusters, NULL); + +if (res == 1) { +/* Found a cluster: subtract the size of th
[FFmpeg-cvslog] avformat/matroskadec: Don't skip too much when unseekable
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:14 2019 +0200| [5120305137436b556a23208f25b549c5d64fb38e] | committer: James Almer avformat/matroskadec: Don't skip too much when unseekable The Matroska (and WebM) file format achieves forward-compability by insisting that demuxers ignore and skip elements they don't know about. Unfortunately, this complicates the detection of errors as errors resulting from loosing sync can't be reliably distinguished from unknown elements that are part of a future version of the standard. Up until now, the strategy to deal with this situation was to skip all unknown elements that are not obviously erroneous; if an error happened, it was tried to seek to the last known good position to resync from (and resync to level 1 elements). This is working fine if the input is seekable, but if it is not, then the skipped data can usually not be rechecked lateron. This is particularly acute if unknown-length clusters are in use, as the check for whether a child element exceeds the containing master element is ineffective in this situation. To remedy this, a new heuristic has been introduced: If an unknown element is encountered in non-seekable mode, an error is presumed to have happened based upon a combination of the length of the row of the already encountered unknown elements and of how far away skipping this element would take us. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5120305137436b556a23208f25b549c5d64fb38e --- libavformat/matroskadec.c | 54 +-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 2a1ad485d2..2485d8edf4 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -73,6 +73,12 @@ * still need to be performed */ #define LEVEL_ENDED 3 /* return value of ebml_parse when the * syntax level used for parsing ended. */ +#define SKIP_THRESHOLD 1024 * 1024 /* In non-seekable mode, if more than SKIP_THRESHOLD + * of unkown, potentially damaged data is encountered, + * it is considered an error. */ +#define UNKNOWN_EQUIV 50 * 1024 /* An unknown element is considered equivalent + * to this many bytes of unknown data for the + * SKIP_THRESHOLD check. */ typedef enum { EBML_NONE, @@ -338,6 +344,7 @@ typedef struct MatroskaDemuxContext { int num_levels; uint32_t current_id; int64_t resync_pos; +int unknown_count; uint64_t time_scale; double duration; @@ -763,8 +770,9 @@ static int matroska_reset_status(MatroskaDemuxContext *matroska, return err; } -matroska->current_id = id; -matroska->num_levels = 1; +matroska->current_id= id; +matroska->num_levels= 1; +matroska->unknown_count = 0; matroska->resync_pos = avio_tell(matroska->ctx->pb); if (id) matroska->resync_pos -= (av_log2(id) + 7) / 8; @@ -1289,6 +1297,48 @@ static int ebml_parse(MatroskaDemuxContext *matroska, } else level_check = 0; +if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) { +// Loosing sync will likely manifest itself as encountering unknown +// elements which are not reliably distinguishable from elements +// belonging to future extensions of the format. +// We use a heuristic to detect such situations: If the current +// element is not expected at the current syntax level and there +// were only a few unknown elements in a row, then the element is +// skipped or considered defective based upon the length of the +// current element (i.e. how much would be skipped); if there were +// more than a few skipped elements in a row and skipping the current +// element would lead us more than SKIP_THRESHOLD away from the last +// known good position, then it is inferred that an error occured. +// The dependency on the number of unknown elements in a row exists +// because the distance to the last known good position is +// automatically big if the last parsed element was big. +// In both cases, each unknown element is considered equivalent to +// UNKNOWN_EQUIV of skipped bytes for the check. +// The whole check is only done for non-seekable output, because +// in this situation skipped data can't simply be rechecked later. +// This is especially important when using unkown length elements +// as the check for whether
[FFmpeg-cvslog] avformat/matroskadec: Accept more unknown-length elements
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:16 2019 +0200| [3c70b941d5d1f756cf4e141c3c7ee921478ec300] | committer: James Almer avformat/matroskadec: Accept more unknown-length elements The current Matroska specifications mandate that only two elements may use an unknown-length length: Segments and clusters. But this was not always so: For the greater part of Matroska's existence, all master elements were allowed to make use of the unknown-length feature. And there were muxers creating such files: For several years libavformat's Matroska muxer used unknown-length for all master elements when the output wasn't seekable. This only stopped in March 2010 with 2529bb30. And even afterwards it was possible (albeit unlikely) for libavformat to create unknown-length master elements that are in violation of today's specifications, namely if the master element was so big that the seek backwards to update the size could no longer be performed inside the AVIOContext's write buffer. This has only been fixed in October 2016 (with the patches that introduced support for writing CRC-32 elements). Libavformat's Matroska demuxer meanwhile has never really supported unknown-length elements besides segments and clusters. Support for the latter was hardcoded. This commit changes this: Now all master elements for which a syntax to parse them is available are supported. This includes the files produced by old versions of libavformat's muxer. More precisely, master elements that have unknown length and are about to be parsed (not skipped) are supported; only a warning is emitted for them. For normal files, this means that level 1 elements after the clusters that are encountered after the clusters have been parsed (i.e. not because they are referenced by the seekhead at the beginning of the file) are still unsupported (they would be skipped at this point if their length were known). Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c70b941d5d1f756cf4e141c3c7ee921478ec300 --- libavformat/matroskadec.c | 23 ++- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 26a1d702a4..6eab076538 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1281,15 +1281,20 @@ static int ebml_parse(MatroskaDemuxContext *matroska, av_log(matroska->ctx, AV_LOG_ERROR, "Unknown-sized element " "at 0x%"PRIx64" inside parent with finite size\n", pos); return AVERROR_INVALIDDATA; -} else if (id != MATROSKA_ID_CLUSTER) { -// According to the specifications only clusters and segments -// are allowed to be unknown-sized. -av_log(matroska->ctx, AV_LOG_ERROR, - "Found unknown-sized element other than a cluster at " - "0x%"PRIx64". Dropping the invalid element.\n", pos); -return AVERROR_INVALIDDATA; -} else +} else { level_check = 0; +if (id != MATROSKA_ID_CLUSTER && (syntax->type == EBML_LEVEL1 + || syntax->type == EBML_NEST)) { +// According to the current specifications only clusters and +// segments are allowed to be unknown-length. We also accept +// other unknown-length master elements. +av_log(matroska->ctx, AV_LOG_WARNING, + "Found unknown-length element 0x%"PRIX32" other than " + "a cluster at 0x%"PRIx64". Spec-incompliant, but " + "parsing will nevertheless be attempted.\n", id, pos); +update_pos = -1; +} +} } else level_check = 0; @@ -1355,7 +1360,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, } } -if (update_pos) { +if (update_pos > 0) { // We have found an element that is allowed at this place // in the hierarchy and it passed all checks, so treat the beginning // of the element as the "last known good" position. ___ 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/matroskadec: Improve invalid length error handling
ffmpeg | branch: master | Andreas Rheinhardt | Fri May 17 00:30:15 2019 +0200| [04b62bd7ceb45d338799768a9c8b139f5b0ad77e] | committer: James Almer avformat/matroskadec: Improve invalid length error handling 1. Up until now, the error message for EBML numbers whose length exceeds the limits imposed upon them because of the element's type did not distinguish between known-length and unknown-length elements. As a consequence, the numerical value of the define constant EBML_UNKNOWN_LENGTH was emitted as part of the error message which is of course not appropriate. This commit changes this by adding error messages designed for unknown-length elements. 2. We impose some (arbitrary) sanity checks on the lengths of certain element types; these checks were conducted before the checks depending on whether the element exceeds its containing master element. Now the order has been reversed, because a failure at the (formerly) latter check implies that the file is truly erroneous and not only fails our arbitrary length limit. Moreover, this increases the informativeness of the error messages. 3. Furthermore, the error message in general has been changed by replacing the type of the element (something internal to this demuxer and therefore suitable as debug output at best, not as an error message intended for ordinary users) with the element ID. The element's position has been added, too. 4. Finally, the length limit for EBML_NONE elements has been changed so that all unknown-length elements of EBML_NONE-type trigger an error. This is done because unknown-length elements can't be skipped and need to be parsed, but there is no syntax to parse available for EBML_NONE elements. This is done in preparation for a further patch which allows more unknown-length elements than just clusters and segments. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=04b62bd7ceb45d338799768a9c8b139f5b0ad77e --- libavformat/matroskadec.c | 28 ++-- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 2485d8edf4..26a1d702a4 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1169,6 +1169,8 @@ static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data) { static const uint64_t max_lengths[EBML_TYPE_COUNT] = { +// Forbid unknown-length EBML_NONE elements. +[EBML_NONE] = EBML_UNKNOWN_LENGTH - 1, [EBML_UINT] = 8, [EBML_SINT] = 8, [EBML_FLOAT] = 8, @@ -1253,12 +1255,6 @@ static int ebml_parse(MatroskaDemuxContext *matroska, matroska->current_id = 0; if ((res = ebml_read_length(matroska, pb, )) < 0) return res; -if (max_lengths[syntax->type] && length > max_lengths[syntax->type]) { -av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid length 0x%"PRIx64" > 0x%"PRIx64" for syntax element %i\n", - length, max_lengths[syntax->type], syntax->type); -return AVERROR_INVALIDDATA; -} pos_alt += res; @@ -1297,6 +1293,26 @@ static int ebml_parse(MatroskaDemuxContext *matroska, } else level_check = 0; +if (max_lengths[syntax->type] && length > max_lengths[syntax->type]) { +if (length != EBML_UNKNOWN_LENGTH) { +av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid length 0x%"PRIx64" > 0x%"PRIx64" for element " + "with ID 0x%"PRIX32" at 0x%"PRIx64"\n", + length, max_lengths[syntax->type], id, pos); +} else if (syntax->type != EBML_NONE) { +av_log(matroska->ctx, AV_LOG_ERROR, + "Element with ID 0x%"PRIX32" at pos. 0x%"PRIx64" has " + "unknown length, yet the length of an element of its " + "type must be known.\n", id, pos); +} else { +av_log(matroska->ctx, AV_LOG_ERROR, + "Found unknown-length element with ID 0x%"PRIX32" at " + "pos. 0x%"PRIx64" for which no syntax for parsing is " + "available.\n", id, pos); +} +return AVERROR_INVALIDDATA; +} + if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) { // Loosing sync will likely manifest itself as encountering unknown // elements which are not reliably distinguishable from elements ___ 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".