Skip to content

Commit 413272f

Browse files
committed
[module-ffmpeg] Improved events handling.
Do not manage SDL and GUI if it disabled at startup. Also improved stability for start/stop playback.
1 parent 08f18db commit 413272f

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

modules/ffmpeg/player.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static struct {
8686
volatile int skip_to_keyframe;
8787
volatile int is_fullscreen;
8888
int back_to_window;
89+
int sdl_gui_managed;
8990

9091
float frame_x, frame_y;
9192
float frame_x_old, frame_y_old;
@@ -788,6 +789,10 @@ static void PlayerDrawHandler(void *ds_event, void *param, int action) {
788789
render_stats();
789790
pvr_list_finish();
790791
}
792+
else if(!vid->sdl_gui_managed) {
793+
render_video_frame(&vid->txr[vid->txr_idx]);
794+
render_stats();
795+
}
791796
break;
792797
case EVENT_ACTION_RENDER_POST:
793798
if(!vid->is_fullscreen && !vid->pause &&
@@ -810,8 +815,10 @@ static void handle_player_click(int button) {
810815
vid->frame_y = vid->frame_y_old;
811816
ds_sfx_play(DS_SFX_CLICK);
812817
update_display_geometry();
813-
EnableScreen();
814-
GUI_Enable();
818+
if(vid->sdl_gui_managed) {
819+
EnableScreen();
820+
GUI_Enable();
821+
}
815822
}
816823
}
817824
else {
@@ -838,8 +845,11 @@ static void handle_player_click(int button) {
838845
vid->frame_y_old = vid->frame_y;
839846
ds_sfx_play(DS_SFX_CLICK);
840847
update_display_geometry();
841-
DisableScreen();
842-
GUI_Disable();
848+
849+
if(vid->sdl_gui_managed) {
850+
DisableScreen();
851+
GUI_Disable();
852+
}
843853
}
844854
}
845855
}
@@ -1537,16 +1547,21 @@ void ffplay_toggle_pause() {
15371547
}
15381548

15391549
int ffplay(const char *filename, ffplay_params_t *params) {
1550+
while(vid->done) {
1551+
thd_sleep(10);
1552+
}
15401553
if(vid->playing) {
15411554
ffplay_shutdown();
15421555
}
15431556

15441557
memset(vid, 0, sizeof(vids));
15451558
memset(aud, 0, sizeof(auds));
15461559
av_log_set_level(params->verbose ? AV_LOG_INFO : AV_LOG_QUIET);
1560+
vid->done = 3;
15471561

15481562
if(ffplay_open_file(filename, params) < 0) {
15491563
ffplay_close_file();
1564+
vid->done = 0;
15501565
return -1;
15511566
}
15521567
vid->frame[0] = avcodec_alloc_frame();
@@ -1555,6 +1570,7 @@ int ffplay(const char *filename, ffplay_params_t *params) {
15551570
if(!vid->frame[0] || !vid->frame[1]) {
15561571
ds_printf("DS_ERROR: avcodec_alloc_frame() failed\n");
15571572
ffplay_close_file();
1573+
vid->done = 0;
15581574
return -1;
15591575
}
15601576
vid->decode_frame_idx = 0;
@@ -1567,8 +1583,9 @@ int ffplay(const char *filename, ffplay_params_t *params) {
15671583

15681584
vid->is_fullscreen = vid->params.fullscreen;
15691585
vid->back_to_window = !vid->params.fullscreen;
1586+
vid->sdl_gui_managed = ScreenIsEnabled();
15701587

1571-
if(vid->is_fullscreen) {
1588+
if(vid->is_fullscreen && vid->sdl_gui_managed) {
15721589
GUI_Disable();
15731590
DisableScreen();
15741591
}
@@ -1622,18 +1639,20 @@ int ffplay(const char *filename, ffplay_params_t *params) {
16221639
}
16231640
}
16241641
}
1625-
vid->playing = 1;
16261642

16271643
if(vid->params.show_stat) {
16281644
load_stat_font();
16291645
}
16301646

1631-
vid->video_event = AddEvent("ffmpeg_player_video", EVENT_TYPE_VIDEO, EVENT_PRIO_DEFAULT, PlayerDrawHandler, NULL);
1647+
vid->video_event = AddEvent("ffmpeg_player_video", EVENT_TYPE_VIDEO, EVENT_PRIO_OVERLAY, PlayerDrawHandler, NULL);
16321648
vid->input_event = AddEvent("ffmpeg_player_input", EVENT_TYPE_INPUT, EVENT_PRIO_DEFAULT, PlayerInputHandler, NULL);
16331649

16341650
if(params->verbose) {
16351651
ds_printf("DS_FFMPEG: Starting playback thread...\n");
16361652
}
1653+
vid->playing = 1;
1654+
vid->done = 0;
1655+
16371656
vid->thread = thd_create(0, player_thread, NULL);
16381657

16391658
if(!vid->thread) {
@@ -1703,7 +1722,7 @@ static void ffplay_free() {
17031722
vid->playing = 0;
17041723
vid->done = 0;
17051724

1706-
if(vid->is_fullscreen) {
1725+
if(vid->is_fullscreen && vid->sdl_gui_managed) {
17071726
EnableScreen();
17081727
GUI_Enable();
17091728
}

0 commit comments

Comments
 (0)