@@ -1182,35 +1182,42 @@ int process_non_multiprogram_general_loop(struct lib_ccx_ctx *ctx,
11821182
11831183 // Get or create pipeline for this DVB stream
11841184 struct ccx_subtitle_pipeline * pipe = get_or_create_pipeline (ctx , stream_pid , CCX_STREAM_TYPE_DVB_SUB , lang );
1185- if (pipe && pipe -> encoder && pipe -> decoder )
1185+ if (pipe && pipe -> encoder && pipe -> decoder && pipe -> dec_ctx )
11861186 {
1187- // Save current decoder context and encoder context
1188- void * saved_private = (* dec_ctx )-> private_data ;
1189- struct encoder_ctx * saved_enc = * enc_ctx ;
1190-
1191- // Swap to pipeline's DVB decoder and encoder
1192- (* dec_ctx )-> private_data = pipe -> decoder ;
1193- * enc_ctx = pipe -> encoder ;
1194-
1195- // Sync timing from main context to pipeline encoder
1196- // This ensures DVB decode has valid PTS/timing state
1187+ // Sync timing from main context to pipeline's decoder context
1188+ // The pipeline uses the main timing context for timestamp calculations
1189+ pipe -> dec_ctx -> timing = (* dec_ctx )-> timing ;
11971190 pipe -> encoder -> timing = (* dec_ctx )-> timing ;
11981191
1199- // Decode DVB directly using pipeline's decoder and encoder
1192+ // Set the PTS for this DVB packet before decoding
1193+ // Without this, the DVB decoder will use stale timing
1194+ if (dvb_ptr -> pts != CCX_NOPTS )
1195+ {
1196+ struct ccx_rational tb = {1 , MPEG_CLOCK_FREQ };
1197+ LLONG pts ;
1198+ if (dvb_ptr -> tb .num != 1 || dvb_ptr -> tb .den != MPEG_CLOCK_FREQ )
1199+ {
1200+ pts = change_timebase (dvb_ptr -> pts , dvb_ptr -> tb , tb );
1201+ }
1202+ else
1203+ {
1204+ pts = dvb_ptr -> pts ;
1205+ }
1206+ set_current_pts (pipe -> dec_ctx -> timing , pts );
1207+ set_fts (pipe -> dec_ctx -> timing );
1208+ }
1209+
1210+ // Decode DVB using the per-pipeline decoder context
1211+ // This ensures each stream has its own prev pointers
12001212 // Skip first 2 bytes (PES header) as done in process_data for DVB
1201- struct cc_subtitle dvb_sub = {0 };
1202- dvbsub_decode (pipe -> encoder , * dec_ctx , dvb_ptr -> buffer + 2 , dvb_ptr -> len - 2 , & dvb_sub );
1213+ dvbsub_decode (pipe -> encoder , pipe -> dec_ctx , dvb_ptr -> buffer + 2 , dvb_ptr -> len - 2 , & pipe -> sub );
12031214
12041215 // Encode output if produced
1205- if (dvb_sub .got_output )
1216+ if (pipe -> sub .got_output )
12061217 {
1207- encode_sub (pipe -> encoder , & dvb_sub );
1208- dvb_sub .got_output = 0 ;
1218+ encode_sub (pipe -> encoder , & pipe -> sub );
1219+ pipe -> sub .got_output = 0 ;
12091220 }
1210-
1211- // Restore original decoder/encoder context
1212- (* dec_ctx )-> private_data = saved_private ;
1213- * enc_ctx = saved_enc ;
12141221 }
12151222 }
12161223 dvb_ptr = dvb_ptr -> next_stream ;
0 commit comments