@@ -130,6 +130,7 @@ static ASS_Track *ass_track[MAX_STREAMS];
130130static uint8_t * ass_extra_data [MAX_STREAMS ];
131131static size_t ass_extra_data_size [MAX_STREAMS ];
132132static slock_t * ass_lock ;
133+ static void render_ass_img (AVFrame * conv_frame , ASS_Image * img );
133134#endif
134135
135136struct attachment
@@ -839,6 +840,19 @@ void CORE_PREFIX(retro_run)(void)
839840 video_buffer_get_finished_slot (video_buffer , & ctx );
840841 pts = ctx -> pts ;
841842
843+ #ifdef HAVE_SSA
844+ double video_time = ctx -> pts * av_q2d (fctx -> streams [video_stream_index ]-> time_base );
845+ slock_lock (ass_lock );
846+ if (ass_render && ctx -> ass_track_active )
847+ {
848+ int change = 0 ;
849+ ASS_Image * img = ass_render_frame (ass_render , ctx -> ass_track_active ,
850+ 1000 * video_time , & change );
851+ render_ass_img (ctx -> target , img );
852+ }
853+ slock_unlock (ass_lock );
854+ #endif
855+
842856#ifdef HAVE_OPENGLES
843857 data = video_frame_temp_buffer ;
844858#else
@@ -859,6 +873,7 @@ void CORE_PREFIX(retro_run)(void)
859873#ifndef HAVE_OPENGLES
860874 glUnmapBuffer (GL_PIXEL_UNPACK_BUFFER );
861875#endif
876+
862877 glBindTexture (GL_TEXTURE_2D , frames [1 ].tex );
863878#if defined(HAVE_OPENGLES )
864879 glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA ,
@@ -1495,19 +1510,6 @@ static void sws_worker_thread(void *arg)
14951510
14961511 ctx -> pts = ctx -> source -> best_effort_timestamp ;
14971512
1498- #ifdef HAVE_SSA
1499- double video_time = ctx -> pts * av_q2d (fctx -> streams [video_stream_index ]-> time_base );
1500- slock_lock (ass_lock );
1501- if (ass_render && ctx -> ass_track_active )
1502- {
1503- int change = 0 ;
1504- ASS_Image * img = ass_render_frame (ass_render , ctx -> ass_track_active ,
1505- 1000 * video_time , & change );
1506- render_ass_img (ctx -> target , img );
1507- }
1508- slock_unlock (ass_lock );
1509- #endif
1510-
15111513 av_frame_unref (ctx -> source );
15121514#if ENABLE_HW_ACCEL
15131515 av_frame_unref (ctx -> hw_source );
@@ -1910,13 +1912,26 @@ static void decode_thread(void *data)
19101912 break ;
19111913 }
19121914 }
1915+ log_cb (RETRO_LOG_DEBUG , "[FFMPEG] [ASS] Decoded subtitle packet, num_rects=%d, pkt->pts=%lld, pkt->duration=%lld, sub.start=%u, sub.end=%u\n" ,
1916+ sub .num_rects , (long long )pkt -> pts , (long long )pkt -> duration , sub .start_display_time , sub .end_display_time );
19131917#ifdef HAVE_SSA
19141918 for (i = 0 ; i < sub .num_rects ; i ++ )
19151919 {
19161920 slock_lock (ass_lock );
1921+ ass_flush_events (ass_track_active );
19171922 if (sub .rects [i ]-> ass && ass_track_active )
1918- ass_process_data (ass_track_active ,
1919- sub .rects [i ]-> ass , strlen (sub .rects [i ]-> ass ));
1923+ {
1924+ char dialogue_line [4096 ];
1925+
1926+ /* Convert packet timing from stream timebase to milliseconds */
1927+ double timebase_ms = av_q2d (fctx -> streams [subtitle_stream ]-> time_base ) * 1000.0 ;
1928+ long long start_time = (long long )((pkt -> pts >= 0 ? pkt -> pts : 0 ) * timebase_ms ) + sub .start_display_time ;
1929+ long long duration = (long long )(pkt -> duration > 0 ? (pkt -> duration * timebase_ms ) : (sub .end_display_time - sub .start_display_time ));
1930+
1931+ snprintf (dialogue_line , sizeof (dialogue_line ), "Dialogue: %s" , sub .rects [i ]-> ass );
1932+
1933+ ass_process_chunk (ass_track_active , dialogue_line , strlen (dialogue_line ), start_time , duration );
1934+ }
19201935 slock_unlock (ass_lock );
19211936 }
19221937#endif
0 commit comments