Skip to content

Commit 3365a71

Browse files
cfsmp3claude
andcommitted
fix: Properly handle ATSC CC in private MPEG-2 streams
This commit fixes two issues: 1. ATSC CC data in private MPEG-2 streams (stream type 0x06) was not being processed. The code returned CCX_PRIVATE_MPEG2_CC buffer type which was never properly implemented - it just dumped debug output and returned placeholder bytes. Fix: Treat ATSC CC in private MPEG-2 streams the same as in user-private streams (0x80-0x8F) by returning CCX_PES buffer type. Both contain the same CC data format and should use the same processing path. 2. Several dump() calls were using CCX_DMT_GENERIC_NOTICES which is enabled by default, causing binary output to flood the terminal when processing certain files. Fix: Changed to appropriate debug-only masks (CCX_DMT_VERBOSE, CCX_DMT_PARSE) so binary dumps only appear when debug mode is explicitly enabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 26e0f64 commit 3365a71

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

src/lib_ccx/avc_functions.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,10 @@ void sei_rbsp(struct avc_ctx *ctx, unsigned char *seibuf, unsigned char *seiend)
379379
}
380380
else
381381
{
382-
// TODO: This really really looks bad
383-
mprint("WARNING: Unexpected SEI unit length...trying to continue.");
384-
temp_debug = 1;
385-
mprint("\n Failed block (at sei_rbsp) was:\n");
386-
dump(CCX_DMT_GENERIC_NOTICES, (unsigned char *)seibuf, seiend - seibuf, 0, 0);
382+
// Unexpected SEI length - common with malformed streams, don't spam output
383+
dbg_print(CCX_DMT_VERBOSE, "WARNING: Unexpected SEI unit length (parsed to %p, expected %p)...trying to continue.\n",
384+
(void *)tbuf, (void *)(seiend - 1));
385+
dump(CCX_DMT_VERBOSE, (unsigned char *)seibuf, seiend - seibuf, 0, 0);
387386

388387
ctx->num_unexpected_sei_length++;
389388
}

src/lib_ccx/general_loop.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int ps_get_more_data(struct lib_ccx_ctx *ctx, struct demuxer_data **ppdata)
7575
if (!ctx->demux_ctx->strangeheader)
7676
{
7777
mprint("\nNot a recognized header. Searching for next header.\n");
78-
dump(CCX_DMT_GENERIC_NOTICES, nextheader, 6, 0, 0);
78+
dump(CCX_DMT_PARSE, nextheader, 6, 0, 0);
7979
// Only print the message once per loop / unrecognized header
8080
ctx->demux_ctx->strangeheader = 1;
8181
}
@@ -809,10 +809,6 @@ int process_data(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, str
809809
got = data_node->len;
810810
}
811811
}
812-
else if (data_node->bufferdatatype == CCX_PRIVATE_MPEG2_CC)
813-
{
814-
got = data_node->len; // Do nothing. Still don't know how to process it
815-
}
816812
else if (data_node->bufferdatatype == CCX_RAW) // Raw two byte 608 data from DVR-MS/ASF
817813
{
818814
// The asf_get_more_data() loop sets current_pts when possible

src/lib_ccx/ts_functions.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ enum ccx_bufferdata_type get_buffer_type(struct cap_info *cinfo)
153153
{
154154
return CCX_TELETEXT;
155155
}
156-
else if (cinfo->stream == CCX_STREAM_TYPE_PRIVATE_MPEG2 && cinfo->codec == CCX_CODEC_ATSC_CC)
157-
{
158-
return CCX_PRIVATE_MPEG2_CC;
159-
}
160-
else if (cinfo->stream == CCX_STREAM_TYPE_PRIVATE_USER_MPEG2 && cinfo->codec == CCX_CODEC_ATSC_CC)
156+
else if ((cinfo->stream == CCX_STREAM_TYPE_PRIVATE_MPEG2 ||
157+
cinfo->stream == CCX_STREAM_TYPE_PRIVATE_USER_MPEG2) &&
158+
cinfo->codec == CCX_CODEC_ATSC_CC)
161159
{
160+
// ATSC CC can be in either private stream type - process both as PES
162161
return CCX_PES;
163162
}
164163
else
@@ -567,15 +566,6 @@ int copy_capbuf_demux_data(struct ccx_demuxer *ctx, struct demuxer_data **data,
567566
if (!cinfo->capbuf || !cinfo->capbuflen)
568567
return -1;
569568

570-
if (ptr->bufferdatatype == CCX_PRIVATE_MPEG2_CC)
571-
{
572-
dump(CCX_DMT_GENERIC_NOTICES, cinfo->capbuf, cinfo->capbuflen, 0, 1);
573-
// Bogus data, so we return something
574-
ptr->buffer[ptr->len++] = 0xFA;
575-
ptr->buffer[ptr->len++] = 0x80;
576-
ptr->buffer[ptr->len++] = 0x80;
577-
return CCX_OK;
578-
}
579569
if (cinfo->codec == CCX_CODEC_TELETEXT)
580570
{
581571
memcpy(ptr->buffer + ptr->len, cinfo->capbuf, cinfo->capbuflen);

0 commit comments

Comments
 (0)