Carry a truncated JOC payload as an invalid frame status
ci / ubuntu-latest (push) Failing after 13s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s

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:
TheM14 committed 2026-11-09 23:53:16 +08:00
1 parent 3f0d5e87fe
commit abce8465f8
12 files changed
+309 -37

No files matched your search

+17 -5
View File
@@ -288,10 +288,20 @@ contract.
Every frame carries a status; a non-zero status is reported as a diagnostic. A non-zero status Every frame carries a status; a non-zero status is reported as a diagnostic. A non-zero status
makes the frame invalid for rendering, so the renderer holds the previous matrices or passes the makes the frame invalid for rendering, so the renderer holds the previous matrices or passes the
core PCM through instead of decoding that frame's matrix: 2 unsupported downmix configuration, core PCM through instead of decoding that frame's matrix: 2 unsupported downmix configuration,
3 object count clamped to 15, 4 unknown parameter-band index, 5 invalid `offset_ts`, and 6 3 object count clamped to 15, 4 unknown parameter-band index, 5 invalid `offset_ts`, 6 trailing
trailing data after byte padding. A file task refuses a `joc_dmx_config_idx` outside 0..4 data after byte padding, and 7 an ID14 payload that ends inside `joc_data`. A file task refuses a
earlier, in the metadata scan, as an unsupported variant. Status 3 still yields the clamped `joc_dmx_config_idx` outside 0..4 earlier, in the metadata scan, as an unsupported variant.
object list for diagnostics, while status 2 and 4 stop the parse at the failing header field. Status 3 still yields the clamped object list for diagnostics, status 2 and 4 stop the parse at
the failing header field, and status 7 keeps the complete header, clipgain, sequence counter and
object parameters, with only the object matrices missing.
Status 7 is classified only when the EMDF container itself is complete: a container length past
the syncframe, or a payload too short for the 12-bit `joc_header`, stays a transport error, and
the file task and stream API additionally require the container's ID11 payload to parse. A
complete container whose payload ends inside `joc_data` takes the invalid-frame path (the
previous matrices are held), so decoding continues instead of stopping; the stream statistics
count those frames in `truncated_joc_frames`, and `joc_check_id14_padding` still reports
`JOC_ERR_BITSTREAM_TRUNCATED` for them.
Rendering then runs a per-frame state machine: normal, hold, hard cut, and core passthrough. An Rendering then runs a per-frame state machine: normal, hold, hard cut, and core passthrough. An
unusable-JOC frame that arrives during normal rendering enters hold, where the previous frame-end unusable-JOC frame that arrives during normal rendering enters hold, where the previous frame-end
@@ -307,7 +317,9 @@ A frame with no JOC EMDF at all (for example when the encoder wrote none for the
always takes the passthrough path: the eight core planes L, R, C, LFE, Ls, Rs, (Lrs, Rrs) are always takes the passthrough path: the eight core planes L, R, C, LFE, Ls, Rs, (Lrs, Rrs) are
written to output slots 0..7 by identity, each delayed by 1217 samples, slots 8..15 stay zero, written to output slots 0..7 by identity, each delayed by 1217 samples, slots 8..15 stay zero,
and the 8-plane history keeps advancing. Those frames are counted separately in the statistics, and the 8-plane history keeps advancing. Those frames are counted separately in the statistics,
and E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. While hold or and E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. A frame whose
ID14 payload ended inside `joc_data` is not one of these: it takes the hold path above and is
counted separately in the stream statistics (`truncated_joc_frames`). While hold or
passthrough runs without fresh parameters, the analysis scalar and the LFE ramp keep the passthrough runs without fresh parameters, the analysis scalar and the LFE ramp keep the
currently held clipgain. currently held clipgain.
+12 -4
View File
@@ -239,9 +239,16 @@ OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只
每个帧都带一个状态,非零状态按诊断报告。非零状态使该帧不能用于渲染,渲染器因此保持上一帧矩阵或输出 每个帧都带一个状态,非零状态按诊断报告。非零状态使该帧不能用于渲染,渲染器因此保持上一帧矩阵或输出
核心 PCM 直通,而不还原该帧的矩阵:2 不支持的下混配置,3 对象数截断到 15,4 未知参数带索引, 核心 PCM 直通,而不还原该帧的矩阵:2 不支持的下混配置,3 对象数截断到 15,4 未知参数带索引,
5 非法 `offset_ts`,6 字节对齐后存在尾随数据。文件任务对 `joc_dmx_config_idx` 超出 0..4 的 5 非法 `offset_ts`,6 字节对齐后存在尾随数据,7 ID14 载荷在 `joc_data` 内提前结束。文件任务对
输入更早在元数据扫描阶段按不支持变体拒绝。状态 3 仍给出截断后的对象列表(供诊断),状态 2、4 `joc_dmx_config_idx` 超出 0..4 的输入更早在元数据扫描阶段按不支持变体拒绝。状态 3 仍给出截断后的
在出错的头字段处停止解析。 对象列表(供诊断),状态 2、4 在出错的头字段处停止解析,状态 7 则保留完整的头、clipgain、序号和
对象参数,只缺对象矩阵。
状态 7 只在 EMDF 容器本身完整时才分类:容器长度越界、或载荷短到连 12 bit 的 `joc_header` 都放
不下仍是传输错误,文件任务与流接口还要求同一容器里的 ID11 载荷能解析。容器完整而载荷在
`joc_data` 中提前结束的帧按无效帧处理(保持上一帧矩阵),文件任务和流接口因此继续解码而不中断,
流接口统计里的 `truncated_joc_frames` 记录这类帧,`joc_check_id14_padding` 对它们仍报
`JOC_ERR_BITSTREAM_TRUNCATED`。
渲染随后按帧级状态机运行:正常、保持、硬切、核心直通。正常渲染期间出现 JOC 参数不可用的帧时 渲染随后按帧级状态机运行:正常、保持、硬切、核心直通。正常渲染期间出现 JOC 参数不可用的帧时
进入保持,继续发布上一帧末的矩阵;连续六个不可用帧只把内部保持状态推进一档、仍保持;出现有效 进入保持,继续发布上一帧末的矩阵;连续六个不可用帧只把内部保持状态推进一档、仍保持;出现有效
@@ -252,7 +259,8 @@ OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只
音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧一律走直通路径:8 路核心平面 音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧一律走直通路径:8 路核心平面
L、R、C、LFE、Ls、Rs、(Lrs, Rrs) 按 identity 写入输出槽 0..7,每路延迟 1217 采样,槽 8..15 L、R、C、LFE、Ls、Rs、(Lrs, Rrs) 按 identity 写入输出槽 0..7,每路延迟 1217 采样,槽 8..15
保持零,8 平面历史照常推进。这类帧在统计里单独计数;不含 JOC 元数据(ID11 + ID14)的 E-AC-3 保持零,8 平面历史照常推进。这类帧在统计里单独计数;不含 JOC 元数据(ID11 + ID14)的 E-AC-3
输入不在支持范围。保持或直通期间没有新参数时,分析标量与 LFE 斜坡沿用当前保持的 clipgain。 输入不在支持范围。ID14 载荷在 `joc_data` 内提前结束的帧不属于这一类:它走上面的保持路径,
在流接口统计里单独计数(`truncated_joc_frames`)。保持或直通期间没有新参数时,分析标量与 LFE 斜坡沿用当前保持的 clipgain。
## 许可 ## 许可
+19 -7
View File
@@ -190,9 +190,10 @@ typedef struct joc_object_params {
/* Per-frame JOC parse status (joc_frame_params.status). A non-zero status makes /* Per-frame JOC parse status (joc_frame_params.status). A non-zero status makes
* the frame invalid for rendering: the renderer holds the previous matrices or * the frame invalid for rendering: the renderer holds the previous matrices or
* passes the core PCM through instead of decoding the matrix. Only status 3 * passes the core PCM through instead of decoding the matrix. Statuses 3 and 7
* still carries a complete object list (object count clamped to 15) for * still carry the complete header and object list for diagnostics; statuses 2
* diagnostics; statuses 2 and 4 stop the parse after the failing header field. */ * and 4 stop the parse after the failing header field, and 7 stops inside
* joc_data, so only the per-object matrices are missing there. */
enum { enum {
JOC_FRAME_STATUS_OK = 0, JOC_FRAME_STATUS_OK = 0,
JOC_FRAME_STATUS_UNSUPPORTED_DMX = 2, /* joc_dmx_config_idx outside 0..4 */ JOC_FRAME_STATUS_UNSUPPORTED_DMX = 2, /* joc_dmx_config_idx outside 0..4 */
@@ -200,7 +201,11 @@ enum {
JOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4, /* unknown num_bands index */ JOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4, /* unknown num_bands index */
JOC_FRAME_STATUS_BAD_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */ JOC_FRAME_STATUS_BAD_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */
/* strictly increasing */ /* strictly increasing */
JOC_FRAME_STATUS_TRAILING_DATA = 6 /* bytes after joc_data alignment */ JOC_FRAME_STATUS_TRAILING_DATA = 6, /* bytes after joc_data alignment */
/* The ID14 payload ends before its joc_data is complete. The header,
* clipgain, sequence counter and object parameters are intact, so the frame
* stays classified and is concealed by holding the previous matrices. */
JOC_FRAME_STATUS_TRUNCATED = 7
}; };
typedef struct joc_frame_params { typedef struct joc_frame_params {
@@ -225,12 +230,18 @@ typedef struct joc_frame_params {
joc_object_params objects[JOC_MAX_OBJECTS]; joc_object_params objects[JOC_MAX_OBJECTS];
} joc_frame_params; } joc_frame_params;
/* Parse an EMDF ID14 (JOC) payload. */ /* Parse an EMDF ID14 (JOC) payload. A payload that ends inside joc_data is a
* damaged frame rather than a transport error: the call succeeds, the header and
* object parameters are filled in, and out_params->status is
* JOC_FRAME_STATUS_TRUNCATED. A payload too short for the 12-bit joc_header is
* unclassifiable and stays JOC_ERR_BITSTREAM_TRUNCATED. */
JOC_API joc_error JOC_CALL joc_parse_id14(const uint8_t* payload, size_t payload_size, JOC_API joc_error JOC_CALL joc_parse_id14(const uint8_t* payload, size_t payload_size,
joc_frame_params* out_params); joc_frame_params* out_params);
/* Locate the contiguous JOC EMDF container inside one E-AC-3 syncframe and /* Locate the contiguous JOC EMDF container inside one E-AC-3 syncframe and
* parse its ID14 payload. out_emdf may be NULL. */ * parse its ID14 payload. out_emdf may be NULL. A damaged ID14 payload is
* reported through out_params->status like joc_parse_id14(); an incomplete
* container stays a transport error. */
JOC_API joc_error JOC_CALL joc_parse_eac3_frame(const uint8_t* frame, size_t frame_size, JOC_API joc_error JOC_CALL joc_parse_eac3_frame(const uint8_t* frame, size_t frame_size,
joc_frame_params* out_params, joc_frame_params* out_params,
joc_emdf_info* out_emdf); joc_emdf_info* out_emdf);
@@ -251,7 +262,8 @@ JOC_API joc_error JOC_CALL joc_eac3_frame_bytes(const uint8_t* data, size_t size
/* Strict trailing-bit check for the JOC payload (A/B robustness corpus). /* Strict trailing-bit check for the JOC payload (A/B robustness corpus).
* Returns JOC_ERR_BITSTREAM_PADDING when more than 7 bits are left over or the * Returns JOC_ERR_BITSTREAM_PADDING when more than 7 bits are left over or the
* leftover bits are not zero. */ * leftover bits are not zero, and JOC_ERR_BITSTREAM_TRUNCATED when the payload
* ends inside joc_data. */
JOC_API joc_error JOC_CALL joc_check_id14_padding(const uint8_t* payload, size_t payload_size, JOC_API joc_error JOC_CALL joc_check_id14_padding(const uint8_t* payload, size_t payload_size,
uint32_t* out_trailing_bits); uint32_t* out_trailing_bits);
+6 -2
View File
@@ -97,8 +97,9 @@ typedef struct joc_stream_status_info {
uint64_t oamd_payloads; uint64_t oamd_payloads;
uint64_t oamd_transitions; uint64_t oamd_transitions;
/* Metadata the renderer had to work around, per audio frame: no JOC payload at /* Metadata the renderer had to work around, per audio frame: no JOC payload at
* all, a declared object count clamped to 15, and a syncframe carrying a second * all, an ID14 payload that ends inside joc_data (that frame holds the previous
* EMDF container that is not this frame's JOC metadata. */ * matrices), a declared object count clamped to 15, and a syncframe carrying a
* second EMDF container that is not this frame's JOC metadata. */
uint64_t missing_joc_frames; uint64_t missing_joc_frames;
uint64_t objects_clamped_frames; uint64_t objects_clamped_frames;
uint64_t extra_container_frames; uint64_t extra_container_frames;
@@ -108,6 +109,9 @@ typedef struct joc_stream_status_info {
uint64_t bed_mask_mismatch_frames; uint64_t bed_mask_mismatch_frames;
uint32_t output_channels; uint32_t output_channels;
uint32_t ended; /* 1 after flush() */ uint32_t ended; /* 1 after flush() */
/* Appended field: joc_stream_status() accepts the size that ends at `ended`
* as well, so a caller built against the previous header keeps working. */
uint64_t truncated_joc_frames;
} joc_stream_status_info; } joc_stream_status_info;
JOC_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out); JOC_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out);
+2 -2
View File
@@ -9,8 +9,8 @@
#define JOC_VERSION_H #define JOC_VERSION_H
#define JOC_VERSION_MAJOR 1 #define JOC_VERSION_MAJOR 1
#define JOC_VERSION_MINOR 2 #define JOC_VERSION_MINOR 3
#define JOC_VERSION_PATCH 0 #define JOC_VERSION_PATCH 0
#define JOC_VERSION_STRING "1.2.0" #define JOC_VERSION_STRING "1.3.0"
#endif /* JOC_VERSION_H */ #endif /* JOC_VERSION_H */
+10 -1
View File
@@ -1,3 +1,4 @@
#include <cstddef>
#include <cstring> #include <cstring>
#include <string> #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) { 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 || 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; return JOC_ERR_INVALID_ARGUMENT;
} }
const joc::stream::Info& info = stream->instance.info(); 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->bed_mask_mismatch_frames = info.bed_mask_mismatch_frames;
out->output_channels = info.output_channels; out->output_channels = info.output_channels;
out->ended = info.ended; out->ended = info.ended;
if (out->struct_size > kSizeBeforeTruncatedFrames) {
out->truncated_joc_frames = info.truncated_joc_frames;
}
return JOC_OK; return JOC_OK;
} }
+44 -15
View File
@@ -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 } // namespace
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out, 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->clipgain_y_bits = static_cast<std::uint8_t>(reader.read(5));
out->seq_count = reader.read(10); out->seq_count = reader.read(10);
if (reader.failed()) { 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 // 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. // 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]; joc_object_params& info = out->objects[obj];
info.present = static_cast<std::uint8_t>(reader.read(1)); info.present = static_cast<std::uint8_t>(reader.read(1));
if (reader.failed()) { if (reader.failed()) {
return truncated_fail(reader); return truncated_frame(reader, out, payload, payload_size);
} }
if (info.present == 0u) { if (info.present == 0u) {
continue; continue;
} }
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3)); info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
if (reader.failed()) { 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); const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
if (bands < 0) { 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.num_dpoints_bits = static_cast<std::uint8_t>(reader.read(1));
info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u); info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u);
if (reader.failed()) { if (reader.failed()) {
return truncated_fail(reader); return truncated_frame(reader, out, payload, payload_size);
} }
if (info.slope_idx == 1u) { if (info.slope_idx == 1u) {
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) { for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5)); info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5));
} }
if (reader.failed()) { 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 // offset_ts is the raw 5-bit slot index (legal range 0..23) and one
// object's data points must be strictly increasing. // 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 Tree idx_tree = select_tree(info.quant_idx, SymbolKind::Idx, n_channels);
const std::uint32_t first = reader.read(3); const std::uint32_t first = reader.read(3);
if (reader.failed()) { 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); symbol->idx[dp][0] = static_cast<std::uint8_t>(first);
for (int pb = 1; pb < info.n_bands; ++pb) { for (int pb = 1; pb < info.n_bands; ++pb) {
std::int16_t value = 0; std::int16_t value = 0;
if (!huff_decode(idx_tree, reader, &value)) { 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); 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) { for (int pb = 0; pb < info.n_bands; ++pb) {
std::int16_t value = 0; std::int16_t value = 0;
if (!huff_decode(vec_tree, reader, &value)) { if (!huff_decode(vec_tree, reader, &value)) {
return truncated_fail(reader); return truncated_frame(reader, out, payload, payload_size);
} }
symbol->vec[dp][pb] = value; 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) { for (int pb = 0; pb < info.n_bands; ++pb) {
std::int16_t value = 0; std::int16_t value = 0;
if (!huff_decode(mtx_tree, reader, &value)) { 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; 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; FrameSymbols symbols;
if (parse_id14(bytes.data(), bytes.size(), &params, &symbols).ok()) { if (parse_id14(bytes.data(), bytes.size(), &params, &symbols).ok()) {
// The reference scores a payload by the frame status: an unsupported // The reference scores a payload by the frame status: an unsupported
// downmix configuration (2) or an unknown parameter-band count (4) // downmix configuration (2), an unknown parameter-band count (4) or a
// leaves the syntax unparsable and must not win the container choice. // 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 && 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 && 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()) { if (!status.ok()) {
return status; return status;
} }
// The two statuses that stop the parse early leave the payload without a // The statuses that stop the parse early leave the payload without a
// joc_data end position, so they keep reporting the syntax failure they // joc_data end position, so they keep reporting the failure they reported
// reported before the frame-status split. // before the frame-status split.
if (params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) { if (params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc, return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc,
"downmix_config_unsupported: joc_dmx_config_idx outside 0..4"); "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, return Status::fail(JOC_ERR_JOC_SYNTAX, stage::kJoc,
"unknown JOC num_bands index stops the payload"); "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) { if (out_trailing_bits != nullptr) {
*out_trailing_bits = params.trailing_bits; *out_trailing_bits = params.trailing_bits;
} }
+1 -1
View File
@@ -999,7 +999,7 @@ private:
if (status != EJOC_FRAME_STATUS_NO_METADATA) { if (status != EJOC_FRAME_STATUS_NO_METADATA) {
return fail("a frame without JOC metadata must use frame_status 8"); 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"); return fail("frame_status is not a JOC parse status");
} }
if ((input.object_mask & ~((1u << EJOC_MAX_OBJECTS) - 1u)) != 0u) { if ((input.object_mask & ~((1u << EJOC_MAX_OBJECTS) - 1u)) != 0u) {
+3
View File
@@ -246,6 +246,9 @@ Status Stream::flush_pending_frame() {
if (entry.params.objects_clamped != 0u) { if (entry.params.objects_clamped != 0u) {
++info_.objects_clamped_frames; ++info_.objects_clamped_frames;
} }
if (entry.params.status == JOC_FRAME_STATUS_TRUNCATED) {
++info_.truncated_joc_frames;
}
} else { } else {
// No JOC metadata for this audio frame: the object channels stay silent // No JOC metadata for this audio frame: the object channels stay silent
// while the kernel state still advances for the frame. // while the kernel state still advances for the frame.
+3
View File
@@ -47,6 +47,9 @@ struct Info {
std::uint64_t oamd_payloads = 0; std::uint64_t oamd_payloads = 0;
std::uint64_t oamd_transitions = 0; std::uint64_t oamd_transitions = 0;
std::uint64_t missing_joc_frames = 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; std::uint64_t objects_clamped_frames = 0;
// Audio frames whose syncframe held more than one top-level JOC container and // 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. // were decoded from the single one that carries a complete joc() payload.
+9
View File
@@ -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 // count was clamped to 15, and frames whose syncframe carried a second EMDF
// container that is not this frame's JOC metadata. // container that is not this frame's JOC metadata.
std::uint64_t missing_joc_frames = 0; std::uint64_t missing_joc_frames = 0;
std::uint64_t truncated_joc_frames = 0;
std::uint64_t objects_clamped_frames = 0; std::uint64_t objects_clamped_frames = 0;
std::uint64_t bad_parameter_band_frames = 0; std::uint64_t bad_parameter_band_frames = 0;
std::uint64_t bad_offset_ts_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: case JOC_FRAME_STATUS_TRAILING_DATA:
++trailing_data_frames; ++trailing_data_frames;
break; break;
case JOC_FRAME_STATUS_TRUNCATED:
++truncated_joc_frames;
break;
default: default:
break; 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; " " audio frame(s) carried JOC data after the byte-alignment padding; "
"the frame took the invalid-frame path"); "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) { if (extra_container_frames != 0u) {
bus.warning(std::to_string(extra_container_frames) + bus.warning(std::to_string(extra_container_frames) +
" audio frame(s) carried a second EMDF container; the container whose OAMD " " audio frame(s) carried a second EMDF container; the container whose OAMD "
+183
View File
@@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <filesystem> #include <filesystem>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@@ -1376,6 +1377,41 @@ bool clipgain_process(ejoc_renderer_handle handle, const ClipGainInputs& in, dou
out->data()) == 0; out->data()) == 0;
} }
// The status struct only grows by appending fields: both the current size and
// the size that ended at `ended` are accepted, and an unrelated size is rejected.
void test_stream_status_struct_sizes() {
joc_stream_config config{};
config.struct_size = sizeof(config);
config.struct_version = 1;
config.input = JOC_STREAM_IN_EAC3;
config.output = JOC_STREAM_OUT_SPEAKER;
config.speaker_layout_name = "7.1";
joc_stream* stream = nullptr;
CHECK(joc_stream_create(&config, &stream) == JOC_OK);
CHECK(stream != nullptr);
if (stream == nullptr) {
return;
}
joc_stream_status_info legacy{};
legacy.struct_size =
static_cast<std::uint32_t>(offsetof(joc_stream_status_info, truncated_joc_frames));
legacy.struct_version = 1;
CHECK(joc_stream_status(stream, &legacy) == JOC_OK);
CHECK(legacy.output_channels == 8u);
CHECK(legacy.truncated_joc_frames == 0u);
joc_stream_status_info current{};
current.struct_size = sizeof(current);
current.struct_version = 1;
CHECK(joc_stream_status(stream, &current) == JOC_OK);
CHECK(current.output_channels == 8u);
CHECK(current.truncated_joc_frames == 0u);
joc_stream_status_info rejected{};
rejected.struct_size = 64;
rejected.struct_version = 1;
CHECK(joc_stream_status(stream, &rejected) == JOC_ERR_INVALID_ARGUMENT);
CHECK(joc_stream_destroy(stream) == JOC_OK);
}
void test_clipgain_first_frame_uses_its_own_gain() { void test_clipgain_first_frame_uses_its_own_gain() {
const ClipGainInputs in; const ClipGainInputs in;
std::vector<float> unity; std::vector<float> unity;
@@ -1742,6 +1778,129 @@ void test_joc_parse_status_and_offset_ts() {
} }
} }
// Helpers for the truncated-payload tests. The container is byte aligned and
// carries one ID11 and one ID14 payload, the shape a JOC syncframe carries; the
// bytes are not a real E-AC-3 frame because the container scan only needs the
// EMDF syncword.
std::vector<std::uint8_t> make_joc_emdf_container(const std::vector<std::uint8_t>& oamd,
const std::vector<std::uint8_t>& joc) {
JocBitWriter body;
body.write(0, 2); // emdf_version
body.write(0, 3); // key_id
for (int index = 0; index < 2; ++index) {
const bool first = index == 0;
const std::vector<std::uint8_t>& payload = first ? oamd : joc;
body.write(first ? 11u : 14u, 5);
body.write(0, 1); // has_sample_offset
body.write(0, 1); // has_duration
body.write(1, 1); // has_group_id
body.write(0, 2); // group_id, one variable_bits(2) group
body.write(0, 1); // end of the variable_bits chain
body.write(0, 1); // has_codec_data
body.write(0, 1); // discard_unknown_payload
body.write(1, 1); // payload_frame_aligned
body.write(0, 2); // alignment padding
body.write(0, 7); // alignment padding
// The test payloads are shorter than 256 bytes: one variable_bits group.
body.write(static_cast<std::uint32_t>(payload.size()), 8);
body.write(0, 1);
for (const std::uint8_t byte : payload) {
body.write(byte, 8);
}
}
body.write(0, 5); // payload id 0 terminates the container
std::vector<std::uint8_t> out;
out.push_back(0x58);
out.push_back(0x38);
const std::size_t length = (body.bit_count + 7u) / 8u;
out.push_back(static_cast<std::uint8_t>((length >> 8) & 0xFFu));
out.push_back(static_cast<std::uint8_t>(length & 0xFFu));
out.insert(out.end(), body.bytes.begin(), body.bytes.end());
return out;
}
// A JOC payload that ends inside joc_data is a damaged frame, not a transport
// error: the header and object parameters stay available, so the frame keeps
// its classification and the renderer can hold the previous matrices. A
// payload too short to hold the joc_header is not classifiable.
void test_joc_truncated_payload_status() {
Id14Spec spec;
spec.present = true;
const std::vector<std::uint8_t> full = make_id14_payload(spec);
joc_frame_params parsed{};
CHECK(joc::joc::parse_id14(full.data(), full.size(), &parsed, nullptr).ok());
CHECK(parsed.status == JOC_FRAME_STATUS_OK);
// Drop the last byte: object 0's five dense MTX symbols no longer fit.
std::vector<std::uint8_t> cut(full.begin(), full.end() - 1);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(cut.data(), cut.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_TRUNCATED);
CHECK(params.dmx_config_idx == 3u);
CHECK(params.n_channels == 5u);
CHECK(params.n_objects == 1u);
CHECK(params.objects[0].present == 1u);
CHECK(params.objects[0].n_bands == 1u);
CHECK(params.objects[0].n_dpoints == 1u);
CHECK(params.present_mask == 1u);
CHECK(params.data_end_bits == cut.size() * 8u);
// One byte cannot even hold the 12-bit joc_header, so the payload stays an
// unclassifiable transport error.
std::vector<std::uint8_t> headerless(full.begin(), full.begin() + 1);
joc_frame_params headerless_params{};
CHECK(joc::joc::parse_id14(headerless.data(), headerless.size(), &headerless_params,
nullptr)
.code() == JOC_ERR_BITSTREAM_TRUNCATED);
// The strict padding verifier keeps reporting the truncation.
std::uint32_t trailing = 0;
CHECK(joc::joc::check_id14_padding(cut.data(), cut.size(), &trailing).code() ==
JOC_ERR_BITSTREAM_TRUNCATED);
}
// The container layer passes a truncated ID14 payload up as a frame status while
// a broken container transport stays fatal.
void test_eac3_frame_truncated_joc_payload() {
Id14Spec spec;
spec.present = true;
const std::vector<std::uint8_t> oamd(8, 0);
std::vector<std::uint8_t> joc = make_id14_payload(spec);
{
const std::vector<std::uint8_t> frame = make_joc_emdf_container(oamd, joc);
joc_frame_params params{};
CHECK(joc::joc::parse_eac3_frame(frame.data(), frame.size(), &params, nullptr, nullptr)
.ok());
CHECK(params.status == JOC_FRAME_STATUS_OK);
}
{
joc.pop_back();
const std::vector<std::uint8_t> frame = make_joc_emdf_container(oamd, joc);
joc_frame_params params{};
joc::emdf::Container container;
CHECK(joc::joc::parse_eac3_frame(frame.data(), frame.size(), &params, &container,
nullptr)
.ok());
CHECK(params.status == JOC_FRAME_STATUS_TRUNCATED);
CHECK(params.present_mask == 1u);
CHECK(container.find(joc::emdf::kIdJoc) != nullptr);
CHECK(container.find(joc::emdf::kIdOamd) != nullptr);
}
{
// The same container with a declared length past the buffer is still a
// transport error, not a frame status.
joc = make_id14_payload(spec);
std::vector<std::uint8_t> frame = make_joc_emdf_container(oamd, joc);
frame[2] = 0x7F;
frame[3] = 0xFF;
joc_frame_params params{};
const joc::Status status =
joc::joc::parse_eac3_frame(frame.data(), frame.size(), &params, nullptr, nullptr);
CHECK(!status.ok());
CHECK(status.code() == JOC_ERR_EMDF_TRANSPORT);
}
}
// Synthetic audio frames driven through the frame-level kernel. // Synthetic audio frames driven through the frame-level kernel.
struct FrameCase { struct FrameCase {
ejoc_renderer_handle handle = nullptr; ejoc_renderer_handle handle = nullptr;
@@ -2058,6 +2217,26 @@ void test_joc_frame_state_machine() {
} }
} }
// The truncated-frame status is a JOC parse status, so the kernel accepts it and
// renders through the invalid-frame path: the previous matrices are held, the
// frame produces its 1536 samples, and the next valid frame resynchronises.
void test_joc_truncated_frame_holds_previous_matrix() {
FrameCase frame;
frame.create();
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame.bed[static_cast<std::size_t>(sample)] =
static_cast<float>(0.2 * std::sin(static_cast<double>(sample) * 0.05));
}
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, JOC_FRAME_STATUS_TRUNCATED, 2u,
true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 3u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
}
void test_joc_no_previous_interpolation() { void test_joc_no_previous_interpolation() {
auto prepare = [](FrameCase* frame) { auto prepare = [](FrameCase* frame) {
frame->create(); frame->create();
@@ -2214,14 +2393,18 @@ int main() {
test_rosella_model_errors(); test_rosella_model_errors();
test_rosella_filterbank_config(); test_rosella_filterbank_config();
test_stream_render_ahead(); test_stream_render_ahead();
test_stream_status_struct_sizes();
test_clipgain_first_frame_uses_its_own_gain(); test_clipgain_first_frame_uses_its_own_gain();
test_clipgain_change_applies_to_the_current_frame(); test_clipgain_change_applies_to_the_current_frame();
test_clipgain_reset_clears_the_previous_gain(); test_clipgain_reset_clears_the_previous_gain();
test_joc_clipgain_formula(); test_joc_clipgain_formula();
test_joc_parse_status_and_offset_ts(); test_joc_parse_status_and_offset_ts();
test_joc_truncated_payload_status();
test_eac3_frame_truncated_joc_payload();
test_joc_lfe_clipgain_ramp(); test_joc_lfe_clipgain_ramp();
test_joc_passthrough_8_plane_layout(); test_joc_passthrough_8_plane_layout();
test_joc_frame_state_machine(); test_joc_frame_state_machine();
test_joc_truncated_frame_holds_previous_matrix();
test_joc_no_previous_interpolation(); test_joc_no_previous_interpolation();
test_binaural_timeline_full_frame_state(); test_binaural_timeline_full_frame_state();
std::printf("%d checks, %d failure(s)\n", g_checks, g_failures); std::printf("%d checks, %d failure(s)\n", g_checks, g_failures);