[FFmpeg-devel] [PATCH 2/6] truehd_core: Correct output size

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Jul 6 17:18:00 EEST 2019


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 <andreas.rheinhardt at gmail.com>
---
The extra_channel stuff can be 32 bytes at most, so the workaround might
have initialized too few bytes for some files.

 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, &in);
@@ -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(&gbc);
     for (i = 0; i < s->hdr.num_substreams; i++) {
         for (int j = 0; j < 4; j++)
             units[i].bits[j] = get_bits1(&gbc);
@@ -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);
-- 
2.21.0



More information about the ffmpeg-devel mailing list