diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5b9a627..423cc28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ name: build # workflow artifacts, and — when a tag is pushed — turns them into a GitHub release. # The SDK is fetched from foobar2000.org at build time (tools/setup_sdk.ps1) and the # renderer sources are part of this repository (kernel/, synced from JustOneCacophonyCXX -# commit 3f0d5e87fe41b90d9350528d2dca2ca82a637a3f), so nothing else is needed. +# commit abce8465f8edda3356738e1a1db7cb1b33191c72), so nothing else is needed. on: push: diff --git a/README.en.md b/README.en.md index 586cf6c..3ecb941 100644 --- a/README.en.md +++ b/README.en.md @@ -209,5 +209,5 @@ every container in the library, which is where the volume comes from. `LICENSE` is the upstream MIT licence, copied unchanged; `kernel/` is a copy of the upstream rendering core sources, synced to JustOneCacophonyCXX commit -`3f0d5e87fe41b90d9350528d2dca2ca82a637a3f` (the `v1.2.0` tag points at an older commit and is not +`abce8465f8edda3356738e1a1db7cb1b33191c72` (the `v1.2.0` tag points at an older commit and is not the sync baseline), and keeps their notices. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). diff --git a/README.md b/README.md index 89101fd..773fd1a 100644 --- a/README.md +++ b/README.md @@ -163,5 +163,5 @@ pwsh -File tools/package.ps1 # 两个架构,打包到 dist\*.fb2k-c ## 许可 `LICENSE` 是上游 MIT 许可,原样复制;`kernel/` 是上游渲染内核源码的副本,同步自 JustOneCacophonyCXX 的提交 -`3f0d5e87fe41b90d9350528d2dca2ca82a637a3f`(`v1.2.0` tag 指向更早的提交,不作为同步基准),保留其声明。见 +`abce8465f8edda3356738e1a1db7cb1b33191c72`(`v1.2.0` tag 指向更早的提交,不作为同步基准),保留其声明。见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。 diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 28a09a3..8ec7ba3 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -6,7 +6,7 @@ 专利的边界说明。 `kernel/` 整体是 JustOneCacophonyCXX 在提交 -`3f0d5e87fe41b90d9350528d2dca2ca82a637a3f`(版本号仍为 1.2.0)的逐字副本; +`abce8465f8edda3356738e1a1db7cb1b33191c72`(版本号 1.3.0)的逐字副本; `v1.2.0` tag 指向更早的提交 a276028,不作为同步基准。 ## 公开标准来源 diff --git a/kernel/include/joc_core.h b/kernel/include/joc_core.h index 6afcc92..9a24dba 100644 --- a/kernel/include/joc_core.h +++ b/kernel/include/joc_core.h @@ -190,9 +190,10 @@ typedef struct joc_object_params { /* 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 - * passes the core PCM through instead of decoding the matrix. Only status 3 - * still carries a complete object list (object count clamped to 15) for - * diagnostics; statuses 2 and 4 stop the parse after the failing header field. */ + * passes the core PCM through instead of decoding the matrix. Statuses 3 and 7 + * still carry the complete header and object list for diagnostics; statuses 2 + * 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 { JOC_FRAME_STATUS_OK = 0, 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_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */ /* 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 { @@ -225,12 +230,18 @@ typedef struct joc_frame_params { joc_object_params objects[JOC_MAX_OBJECTS]; } 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_frame_params* out_params); /* 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_frame_params* out_params, 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). * 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, uint32_t* out_trailing_bits); diff --git a/kernel/include/joc_stream.h b/kernel/include/joc_stream.h index 7511483..137b99e 100644 --- a/kernel/include/joc_stream.h +++ b/kernel/include/joc_stream.h @@ -97,8 +97,9 @@ typedef struct joc_stream_status_info { uint64_t oamd_payloads; uint64_t oamd_transitions; /* 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 - * EMDF container that is not this frame's JOC metadata. */ + * all, an ID14 payload that ends inside joc_data (that frame holds the previous + * 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 objects_clamped_frames; uint64_t extra_container_frames; @@ -108,6 +109,9 @@ typedef struct joc_stream_status_info { uint64_t bed_mask_mismatch_frames; uint32_t output_channels; 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_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out); diff --git a/kernel/include/joc_version.h b/kernel/include/joc_version.h index dc1143c..33bed7e 100644 --- a/kernel/include/joc_version.h +++ b/kernel/include/joc_version.h @@ -9,8 +9,8 @@ #define JOC_VERSION_H #define JOC_VERSION_MAJOR 1 -#define JOC_VERSION_MINOR 2 +#define JOC_VERSION_MINOR 3 #define JOC_VERSION_PATCH 0 -#define JOC_VERSION_STRING "1.2.0" +#define JOC_VERSION_STRING "1.3.0" #endif /* JOC_VERSION_H */ diff --git a/kernel/joc_kernel.vcxproj b/kernel/joc_kernel.vcxproj index 695c888..daeda62 100644 --- a/kernel/joc_kernel.vcxproj +++ b/kernel/joc_kernel.vcxproj @@ -5,7 +5,7 @@ shipping and loading joc_core.dll. The sources under kernel\src and kernel\include are a verbatim copy of the - upstream library at commit 3f0d5e87fe41b90d9350528d2dca2ca82a637a3f (see + upstream library at commit abce8465f8edda3356738e1a1db7cb1b33191c72 (see JustOneCacophonyCXX\CMakeLists.txt): nothing under either tree is edited here, and both are kept identical to it, so a single core serves the upstream tools and this component alike. The static build needs no branch diff --git a/kernel/src/api/joc_stream_api.cpp b/kernel/src/api/joc_stream_api.cpp index 6cb6bf0..350d178 100644 --- a/kernel/src/api/joc_stream_api.cpp +++ b/kernel/src/api/joc_stream_api.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -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( + 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; } diff --git a/kernel/src/joc_bitstream/joc_parser.cpp b/kernel/src/joc_bitstream/joc_parser.cpp index 08055b4..c37d708 100644 --- a/kernel/src/joc_bitstream/joc_parser.cpp +++ b/kernel/src/joc_bitstream/joc_parser.cpp @@ -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(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(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(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(reader.read(1)); info.n_dpoints = static_cast(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(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(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(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; } diff --git a/kernel/src/joc_core/eac3joc_core.cpp b/kernel/src/joc_core/eac3joc_core.cpp index 42b52a3..8a02c45 100644 --- a/kernel/src/joc_core/eac3joc_core.cpp +++ b/kernel/src/joc_core/eac3joc_core.cpp @@ -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) { diff --git a/kernel/src/stream/stream.cpp b/kernel/src/stream/stream.cpp index 80b617b..bc599d6 100644 --- a/kernel/src/stream/stream.cpp +++ b/kernel/src/stream/stream.cpp @@ -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. diff --git a/kernel/src/stream/stream.h b/kernel/src/stream/stream.h index 760ac94..5740926 100644 --- a/kernel/src/stream/stream.h +++ b/kernel/src/stream/stream.h @@ -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. diff --git a/kernel/src/task/task.cpp b/kernel/src/task/task.cpp index 8b3da7b..0e05dc4 100644 --- a/kernel/src/task/task.cpp +++ b/kernel/src/task/task.cpp @@ -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 "