fix: Fix variable shadowing and teletext context refresh issues

This commit fixes two issues uncovered during Sample Platform testing:

1. Variable shadowing in general_loop() (general_loop.c):
   - The inner `int ret = process_non_multiprogram_general_loop(...)`
     was shadowing the outer `ret` variable
   - This caused the return value to always be 0, making ccextractor
     report "No captions found" even when captions were extracted
   - Also added `ret = 1` when captions are detected via counters,
     needed for CEA-708 which writes directly via Rust

2. Missing private_data refresh in update_decoder_list_cinfo (lib_ccx.c):
   - After PAT changes, dinit_cap() frees the teletext context and
     NULLs dec_ctx->private_data
   - But update_decoder_list_cinfo() returned existing decoder without
     refreshing private_data from the new cap_info
   - This caused all subsequent teletext processing to be skipped
   - Fixed by updating dec_ctx->private_data when returning existing decoder

These fixes resolve Sample Platform test failures in CEA-708 and Teletext
categories where tests returned exit code 10 (no captions) unexpectedly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Carlos Fernandez
2025-12-18 10:10:25 +01:00
parent a0809caa94
commit 442ce1015d
2 changed files with 25 additions and 8 deletions

View File

@@ -1017,7 +1017,13 @@ int process_non_multiprogram_general_loop(struct lib_ccx_ctx *ctx,
if (*enc_ctx != NULL)
{
if ((*enc_ctx)->srt_counter || (*enc_ctx)->cea_708_counter || (*dec_ctx)->saw_caption_block || ret == 1)
{
*caps = 1;
/* Also update ret to indicate captions were found.
This is needed for CEA-708 which writes directly via Rust
and doesn't set got_output like CEA-608/DVB do. */
ret = 1;
}
}
// Process the last subtitle for DVB
@@ -1108,14 +1114,18 @@ int general_loop(struct lib_ccx_ctx *ctx)
if (!ctx->multiprogram)
{
struct encoder_ctx *enc_ctx = NULL;
int ret = process_non_multiprogram_general_loop(ctx,
&datalist,
&data_node,
&dec_ctx,
&enc_ctx,
&min_pts,
ret,
&caps);
/* Note: Do NOT declare a new 'ret' variable here!
We must update the outer 'ret' to track whether captions were found.
Variable shadowing here would cause general_loop to always return 0
(no captions found) regardless of actual caption content. */
ret = process_non_multiprogram_general_loop(ctx,
&datalist,
&data_node,
&dec_ctx,
&enc_ctx,
&min_pts,
ret,
&caps);
if (ret == CCX_EINVAL)
{
break;

View File

@@ -346,7 +346,14 @@ struct lib_cc_decode *update_decoder_list_cinfo(struct lib_ccx_ctx *ctx, struct
list_for_each_entry(dec_ctx, &ctx->dec_ctx_head, list, struct lib_cc_decode)
{
if (!cinfo || ctx->multiprogram == CCX_FALSE)
{
/* Update private_data from cinfo if available.
This is needed after PAT changes when dinit_cap() freed the old context
and a new cap_info was created with a new codec_private_data. */
if (cinfo && cinfo->codec_private_data)
dec_ctx->private_data = cinfo->codec_private_data;
return dec_ctx;
}
if (dec_ctx->program_number == cinfo->program_number)
return dec_ctx;