From 8d4d84bd499ea3a457bc96d339bc8455c594fc86 Mon Sep 17 00:00:00 2001 From: Dhanush Varma Date: Wed, 17 Dec 2025 12:16:50 +0530 Subject: [PATCH 1/2] fix: prevent infinite loop when TS files have no subtitle streams - Check if all PMTs have been analyzed - After PMT analysis, verify if any caption streams (PIDs) were found - Exit after 1000 packets if num_of_PIDs == 0 (no caption streams) - Uses PMT-based detection instead of arbitrary packet limits This fix properly uses the Program Map Table data to determine if subtitle streams exist, rather than relying on arbitrary packet counts. Fixes #1754 --- src/lib_ccx/ts_functions.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib_ccx/ts_functions.c b/src/lib_ccx/ts_functions.c index 14a82c93f..132654bc5 100644 --- a/src/lib_ccx/ts_functions.c +++ b/src/lib_ccx/ts_functions.c @@ -748,6 +748,8 @@ long ts_readstream(struct ccx_demuxer *ctx, struct demuxer_data **data) struct cap_info *cinfo; struct ts_payload payload; int j; + int all_pmts_analyzed = 0; // Track if all programs have analyzed their PMT + int packets_after_pmt_analysis = 0; static int no_pat_warning_shown = 0; memset(&payload, 0, sizeof(payload)); @@ -756,6 +758,31 @@ long ts_readstream(struct ccx_demuxer *ctx, struct demuxer_data **data) { pcount++; + // Check if all PMTs have been analyzed + if (!all_pmts_analyzed) + { + all_pmts_analyzed = 1; + for (j = 0; j < ctx->nb_program; j++) + { + if (ctx->pinfo[j].analysed_PMT_once == CCX_FALSE) + { + all_pmts_analyzed = 0; + break; + } + } + } + + // After all PMTs analyzed, if no caption streams found after reasonable packets, exit + if (all_pmts_analyzed) + { + packets_after_pmt_analysis++; + if (packets_after_pmt_analysis > 1000 && ctx->num_of_PIDs == 0) + { + dbg_print(CCX_DMT_PARSE, "\nNo caption/subtitle streams found in any PMT after %ld packets. This file contains no extractable subtitles.\n", pcount); + return CCX_EOF; + } + } + // Exit the loop at EOF ret = ts_readpacket(ctx, &payload); if (ret != CCX_OK) From 926293cd4395e2911774be2527a5144b64288299 Mon Sep 17 00:00:00 2001 From: Dhanush Varma Date: Wed, 17 Dec 2025 12:25:49 +0530 Subject: [PATCH 2/2] style: apply clang-format to ts_functions.c --- src/lib_ccx/ts_functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_ccx/ts_functions.c b/src/lib_ccx/ts_functions.c index 132654bc5..6a55199fd 100644 --- a/src/lib_ccx/ts_functions.c +++ b/src/lib_ccx/ts_functions.c @@ -748,7 +748,7 @@ long ts_readstream(struct ccx_demuxer *ctx, struct demuxer_data **data) struct cap_info *cinfo; struct ts_payload payload; int j; - int all_pmts_analyzed = 0; // Track if all programs have analyzed their PMT + int all_pmts_analyzed = 0; // Track if all programs have analyzed their PMT int packets_after_pmt_analysis = 0; static int no_pat_warning_shown = 0;