Commit cbe23e40 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by 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: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
parent 99c19115
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment