Carry a truncated JOC payload as an invalid frame status
A real E-AC-3 JOC stream can carry an ID14 payload that ends inside joc_data: the header, clipgain, sequence counter and object parameters are complete, only the per-object matrices are missing. That frame used to abort the stream with JOC_ERR_BITSTREAM_TRUNCATED. The overrun is now classified as JOC_FRAME_STATUS_TRUNCATED (7) and the renderer takes its existing invalid-frame path, so it holds the previous matrices and playback continues; the damaged frame stays visible in the stream's truncated_joc_frames counter and the file task's warning. A payload too short for the 12-bit joc_header, a container length past the syncframe and a Huffman walk leaving the tree stay fatal, the strict padding checker still reports the truncation, and container scoring no longer prefers such a payload. The stream status struct grows by one appended field and joc_stream_status() accepts the previous size as well. Bump the version to 1.3.0.
This commit is contained in:
1 parent
3f0d5e87fe
commit
abce8465f8
12 files changed
+309
-37
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
@@ -140,8 +141,13 @@ joc_error JOC_CALL joc_stream_reset(joc_stream* stream) {
|
||||
}
|
||||
|
||||
joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status_info* out) {
|
||||
// The info struct only grows by appending fields, so a caller built against
|
||||
// the previous size still gets every field it knows about.
|
||||
constexpr uint32_t kSizeBeforeTruncatedFrames = static_cast<uint32_t>(
|
||||
offsetof(joc_stream_status_info, truncated_joc_frames));
|
||||
if (stream == nullptr || out == nullptr ||
|
||||
out->struct_size != sizeof(joc_stream_status_info)) {
|
||||
(out->struct_size != sizeof(joc_stream_status_info) &&
|
||||
out->struct_size != kSizeBeforeTruncatedFrames)) {
|
||||
return JOC_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
const joc::stream::Info& info = stream->instance.info();
|
||||
@@ -160,6 +166,9 @@ joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status
|
||||
out->bed_mask_mismatch_frames = info.bed_mask_mismatch_frames;
|
||||
out->output_channels = info.output_channels;
|
||||
out->ended = info.ended;
|
||||
if (out->struct_size > kSizeBeforeTruncatedFrames) {
|
||||
out->truncated_joc_frames = info.truncated_joc_frames;
|
||||
}
|
||||
return JOC_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,6 +229,28 @@ void tail_info(joc_frame_params* out, const bits::BitReader& reader, const std::
|
||||
}
|
||||
}
|
||||
|
||||
// A payload that runs out of bits after the joc_header is a damaged but
|
||||
// identifiable JOC frame: the header, clipgain, sequence counter and object
|
||||
// parameters are intact, so the frame keeps its identity and the renderer can
|
||||
// hold the previous matrices instead of stopping the stream. A payload that
|
||||
// ends before the header cannot be classified and stays a transport error; a
|
||||
// Huffman walk that leaves the tree is a syntax error, never a truncation.
|
||||
Status truncated_frame(const bits::BitReader& reader, joc_frame_params* out,
|
||||
const std::uint8_t* payload, std::size_t payload_size) {
|
||||
if (reader.error() != JOC_ERR_BITSTREAM_TRUNCATED) {
|
||||
return syntax_fail(reader.error_message());
|
||||
}
|
||||
out->status = JOC_FRAME_STATUS_TRUNCATED;
|
||||
out->present_mask = 0u;
|
||||
for (std::uint32_t obj = 0; obj < out->n_objects; ++obj) {
|
||||
if (out->objects[obj].present != 0u) {
|
||||
out->present_mask |= 1u << obj;
|
||||
}
|
||||
}
|
||||
tail_info(out, reader, payload, payload_size);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out,
|
||||
@@ -255,7 +277,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
out->clipgain_y_bits = static_cast<std::uint8_t>(reader.read(5));
|
||||
out->seq_count = reader.read(10);
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
// clipgain = 2^(x-4) * (1 + y/32); ldexp builds the power of two exactly
|
||||
// over the whole legal range, so the result is bit-exact to the reference.
|
||||
@@ -273,14 +295,14 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
joc_object_params& info = out->objects[obj];
|
||||
info.present = static_cast<std::uint8_t>(reader.read(1));
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
if (info.present == 0u) {
|
||||
continue;
|
||||
}
|
||||
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
|
||||
if (bands < 0) {
|
||||
@@ -299,14 +321,14 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
info.num_dpoints_bits = static_cast<std::uint8_t>(reader.read(1));
|
||||
info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u);
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
if (info.slope_idx == 1u) {
|
||||
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
|
||||
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5));
|
||||
}
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
// offset_ts is the raw 5-bit slot index (legal range 0..23) and one
|
||||
// object's data points must be strictly increasing.
|
||||
@@ -350,13 +372,13 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
const Tree idx_tree = select_tree(info.quant_idx, SymbolKind::Idx, n_channels);
|
||||
const std::uint32_t first = reader.read(3);
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->idx[dp][0] = static_cast<std::uint8_t>(first);
|
||||
for (int pb = 1; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(idx_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->idx[dp][pb] = static_cast<std::uint8_t>(value);
|
||||
}
|
||||
@@ -364,7 +386,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(vec_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->vec[dp][pb] = value;
|
||||
}
|
||||
@@ -374,7 +396,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(mtx_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->mtx[dp][ch][pb] = value;
|
||||
}
|
||||
@@ -460,10 +482,13 @@ int score_container_as_joc(const std::uint8_t* data, std::size_t size,
|
||||
FrameSymbols symbols;
|
||||
if (parse_id14(bytes.data(), bytes.size(), ¶ms, &symbols).ok()) {
|
||||
// The reference scores a payload by the frame status: an unsupported
|
||||
// downmix configuration (2) or an unknown parameter-band count (4)
|
||||
// leaves the syntax unparsable and must not win the container choice.
|
||||
// downmix configuration (2), an unknown parameter-band count (4) or a
|
||||
// payload that ends inside joc_data (7) must not win the container
|
||||
// choice, because another candidate may carry the frame's complete
|
||||
// metadata.
|
||||
parses = params.status != JOC_FRAME_STATUS_UNSUPPORTED_DMX &&
|
||||
params.status != JOC_FRAME_STATUS_BAD_PARAMETER_BAND;
|
||||
params.status != JOC_FRAME_STATUS_BAD_PARAMETER_BAND &&
|
||||
params.status != JOC_FRAME_STATUS_TRUNCATED;
|
||||
}
|
||||
}
|
||||
const bool associated = oamd->has_group_id != 0u && payload->has_group_id != 0u &&
|
||||
@@ -522,9 +547,9 @@ Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
// The two statuses that stop the parse early leave the payload without a
|
||||
// joc_data end position, so they keep reporting the syntax failure they
|
||||
// reported before the frame-status split.
|
||||
// The statuses that stop the parse early leave the payload without a
|
||||
// joc_data end position, so they keep reporting the failure they reported
|
||||
// before the frame-status split.
|
||||
if (params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
|
||||
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc,
|
||||
"downmix_config_unsupported: joc_dmx_config_idx outside 0..4");
|
||||
@@ -533,6 +558,10 @@ Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
||||
return Status::fail(JOC_ERR_JOC_SYNTAX, stage::kJoc,
|
||||
"unknown JOC num_bands index stops the payload");
|
||||
}
|
||||
if (params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
||||
return Status::fail(JOC_ERR_BITSTREAM_TRUNCATED, stage::kJoc,
|
||||
"the ID14 payload ends before its joc_data is complete");
|
||||
}
|
||||
if (out_trailing_bits != nullptr) {
|
||||
*out_trailing_bits = params.trailing_bits;
|
||||
}
|
||||
|
||||
@@ -999,7 +999,7 @@ private:
|
||||
if (status != EJOC_FRAME_STATUS_NO_METADATA) {
|
||||
return fail("a frame without JOC metadata must use frame_status 8");
|
||||
}
|
||||
} else if (status != 0u && (status < 2u || status > 6u)) {
|
||||
} else if (status != 0u && (status < 2u || status > 7u)) {
|
||||
return fail("frame_status is not a JOC parse status");
|
||||
}
|
||||
if ((input.object_mask & ~((1u << EJOC_MAX_OBJECTS) - 1u)) != 0u) {
|
||||
|
||||
@@ -246,6 +246,9 @@ Status Stream::flush_pending_frame() {
|
||||
if (entry.params.objects_clamped != 0u) {
|
||||
++info_.objects_clamped_frames;
|
||||
}
|
||||
if (entry.params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
||||
++info_.truncated_joc_frames;
|
||||
}
|
||||
} else {
|
||||
// No JOC metadata for this audio frame: the object channels stay silent
|
||||
// while the kernel state still advances for the frame.
|
||||
|
||||
@@ -47,6 +47,9 @@ struct Info {
|
||||
std::uint64_t oamd_payloads = 0;
|
||||
std::uint64_t oamd_transitions = 0;
|
||||
std::uint64_t missing_joc_frames = 0;
|
||||
// Audio frames whose ID14 payload ended inside joc_data; they render as
|
||||
// invalid frames and hold the previous matrices.
|
||||
std::uint64_t truncated_joc_frames = 0;
|
||||
std::uint64_t objects_clamped_frames = 0;
|
||||
// Audio frames whose syncframe held more than one top-level JOC container and
|
||||
// were decoded from the single one that carries a complete joc() payload.
|
||||
|
||||
@@ -1594,6 +1594,7 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
// count was clamped to 15, and frames whose syncframe carried a second EMDF
|
||||
// container that is not this frame's JOC metadata.
|
||||
std::uint64_t missing_joc_frames = 0;
|
||||
std::uint64_t truncated_joc_frames = 0;
|
||||
std::uint64_t objects_clamped_frames = 0;
|
||||
std::uint64_t bad_parameter_band_frames = 0;
|
||||
std::uint64_t bad_offset_ts_frames = 0;
|
||||
@@ -1678,6 +1679,9 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
case JOC_FRAME_STATUS_TRAILING_DATA:
|
||||
++trailing_data_frames;
|
||||
break;
|
||||
case JOC_FRAME_STATUS_TRUNCATED:
|
||||
++truncated_joc_frames;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -2219,6 +2223,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
" audio frame(s) carried JOC data after the byte-alignment padding; "
|
||||
"the frame took the invalid-frame path");
|
||||
}
|
||||
if (truncated_joc_frames != 0u) {
|
||||
bus.warning(std::to_string(truncated_joc_frames) +
|
||||
" audio frame(s) carried a JOC payload that ends inside joc_data; "
|
||||
"the frame took the invalid-frame path and held the previous matrices");
|
||||
}
|
||||
if (extra_container_frames != 0u) {
|
||||
bus.warning(std::to_string(extra_container_frames) +
|
||||
" audio frame(s) carried a second EMDF container; the container whose OAMD "
|
||||
|
||||
Reference in new issue
Block a user