Skip to content

Commit cc64cae

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 cc64cae

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

modules/ffmpeg/player.c

Lines changed: 24 additions & 9 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;
@@ -782,7 +783,7 @@ static void PlayerDrawHandler(void *ds_event, void *param, int action) {
782783
if(vid->video_started > 1) {
783784
switch(action) {
784785
case EVENT_ACTION_RENDER:
785-
if(vid->is_fullscreen) {
786+
if(vid->is_fullscreen || !vid->sdl_gui_managed) {
786787
pvr_list_begin(PVR_LIST_TR_POLY);
787788
render_video_frame(&vid->txr[vid->txr_idx]);
788789
render_stats();
@@ -810,8 +811,10 @@ static void handle_player_click(int button) {
810811
vid->frame_y = vid->frame_y_old;
811812
ds_sfx_play(DS_SFX_CLICK);
812813
update_display_geometry();
813-
EnableScreen();
814-
GUI_Enable();
814+
if(vid->sdl_gui_managed) {
815+
EnableScreen();
816+
GUI_Enable();
817+
}
815818
}
816819
}
817820
else {
@@ -838,8 +841,11 @@ static void handle_player_click(int button) {
838841
vid->frame_y_old = vid->frame_y;
839842
ds_sfx_play(DS_SFX_CLICK);
840843
update_display_geometry();
841-
DisableScreen();
842-
GUI_Disable();
844+
845+
if(vid->sdl_gui_managed) {
846+
DisableScreen();
847+
GUI_Disable();
848+
}
843849
}
844850
}
845851
}
@@ -1537,16 +1543,21 @@ void ffplay_toggle_pause() {
15371543
}
15381544

15391545
int ffplay(const char *filename, ffplay_params_t *params) {
1546+
while(vid->done) {
1547+
thd_sleep(10);
1548+
}
15401549
if(vid->playing) {
15411550
ffplay_shutdown();
15421551
}
15431552

15441553
memset(vid, 0, sizeof(vids));
15451554
memset(aud, 0, sizeof(auds));
15461555
av_log_set_level(params->verbose ? AV_LOG_INFO : AV_LOG_QUIET);
1556+
vid->done = 3;
15471557

15481558
if(ffplay_open_file(filename, params) < 0) {
15491559
ffplay_close_file();
1560+
vid->done = 0;
15501561
return -1;
15511562
}
15521563
vid->frame[0] = avcodec_alloc_frame();
@@ -1555,6 +1566,7 @@ int ffplay(const char *filename, ffplay_params_t *params) {
15551566
if(!vid->frame[0] || !vid->frame[1]) {
15561567
ds_printf("DS_ERROR: avcodec_alloc_frame() failed\n");
15571568
ffplay_close_file();
1569+
vid->done = 0;
15581570
return -1;
15591571
}
15601572
vid->decode_frame_idx = 0;
@@ -1567,8 +1579,9 @@ int ffplay(const char *filename, ffplay_params_t *params) {
15671579

15681580
vid->is_fullscreen = vid->params.fullscreen;
15691581
vid->back_to_window = !vid->params.fullscreen;
1582+
vid->sdl_gui_managed = ScreenIsEnabled();
15701583

1571-
if(vid->is_fullscreen) {
1584+
if(vid->is_fullscreen && vid->sdl_gui_managed) {
15721585
GUI_Disable();
15731586
DisableScreen();
15741587
}
@@ -1622,18 +1635,20 @@ int ffplay(const char *filename, ffplay_params_t *params) {
16221635
}
16231636
}
16241637
}
1625-
vid->playing = 1;
16261638

16271639
if(vid->params.show_stat) {
16281640
load_stat_font();
16291641
}
16301642

1631-
vid->video_event = AddEvent("ffmpeg_player_video", EVENT_TYPE_VIDEO, EVENT_PRIO_DEFAULT, PlayerDrawHandler, NULL);
1643+
vid->video_event = AddEvent("ffmpeg_player_video", EVENT_TYPE_VIDEO, EVENT_PRIO_OVERLAY, PlayerDrawHandler, NULL);
16321644
vid->input_event = AddEvent("ffmpeg_player_input", EVENT_TYPE_INPUT, EVENT_PRIO_DEFAULT, PlayerInputHandler, NULL);
16331645

16341646
if(params->verbose) {
16351647
ds_printf("DS_FFMPEG: Starting playback thread...\n");
16361648
}
1649+
vid->playing = 1;
1650+
vid->done = 0;
1651+
16371652
vid->thread = thd_create(0, player_thread, NULL);
16381653

16391654
if(!vid->thread) {
@@ -1703,7 +1718,7 @@ static void ffplay_free() {
17031718
vid->playing = 0;
17041719
vid->done = 0;
17051720

1706-
if(vid->is_fullscreen) {
1721+
if(vid->is_fullscreen && vid->sdl_gui_managed) {
17071722
EnableScreen();
17081723
GUI_Enable();
17091724
}

0 commit comments

Comments
 (0)