diff --git a/command.c b/command.c index 95300916da..5c07767f71 100644 --- a/command.c +++ b/command.c @@ -737,8 +737,8 @@ bool command_play_replay_slot(command_t *cmd, const char *arg) { input_driver_state_t *input_st = input_state_get_ptr(); task_queue_wait(NULL,NULL); - if(input_st->bsv_movie_state_handle) - snprintf(reply, sizeof(reply) - 1, "PLAY_REPLAY_SLOT %lld", (long long)(input_st->bsv_movie_state_handle->identifier)); + if(input_st->bsv_movie_state_next_handle) + snprintf(reply, sizeof(reply) - 1, "PLAY_REPLAY_SLOT %lld", (long long)(input_st->bsv_movie_state_next_handle->identifier)); else snprintf(reply, sizeof(reply) - 1, "PLAY_REPLAY_SLOT 0"); command_post_state_loaded(); diff --git a/input/input_driver.c b/input/input_driver.c index 586f5ffac8..f3b01581cd 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -5039,6 +5039,14 @@ static void input_keys_pressed( /* Forward declaration */ void bsv_movie_free(bsv_movie_t*); +void bsv_movie_enqueue(input_driver_state_t *input_st, bsv_movie_t * state, enum bsv_flags flags) +{ + if (input_st->bsv_movie_state_next_handle) + bsv_movie_free(input_st->bsv_movie_state_next_handle); + input_st->bsv_movie_state_next_handle = state; + input_st->bsv_movie_state.flags = flags; +} + void bsv_movie_deinit(input_driver_state_t *input_st) { if (input_st->bsv_movie_state_handle) @@ -5046,6 +5054,14 @@ void bsv_movie_deinit(input_driver_state_t *input_st) input_st->bsv_movie_state_handle = NULL; } +void bsv_movie_deinit_full(input_driver_state_t *input_st) +{ + bsv_movie_deinit(input_st); + if (input_st->bsv_movie_state_next_handle) + bsv_movie_free(input_st->bsv_movie_state_next_handle); + input_st->bsv_movie_state_next_handle = NULL; +} + void bsv_movie_frame_rewind(void) { input_driver_state_t *input_st = &input_driver_st; @@ -5134,7 +5150,18 @@ void bsv_movie_next_frame(input_driver_state_t *input_st) { settings_t *settings = config_get_ptr(); unsigned checkpoint_interval = settings->uints.replay_checkpoint_interval; + /* if bsv_movie_state_next_handle is not null, deinit and set + bsv_movie_state_handle to bsv_movie_state_next_handle and clear + next_handle */ bsv_movie_t *handle = input_st->bsv_movie_state_handle; + if (input_st->bsv_movie_state_next_handle) + { + if(handle) + bsv_movie_deinit(input_st); + handle = input_st->bsv_movie_state_next_handle; + input_st->bsv_movie_state_handle = handle; + input_st->bsv_movie_state_next_handle = NULL; + } if (!handle) return; diff --git a/input/input_driver.h b/input/input_driver.h index 3fc6849f82..6fa75a3b35 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -512,6 +512,7 @@ typedef struct #endif #ifdef HAVE_BSV_MOVIE bsv_movie_t *bsv_movie_state_handle; /* ptr alignment */ + bsv_movie_t *bsv_movie_state_next_handle; /* ptr alignment */ #endif #ifdef HAVE_OVERLAY input_overlay_t *overlay_ptr; @@ -1003,6 +1004,8 @@ void bsv_movie_frame_rewind(void); void bsv_movie_next_frame(input_driver_state_t *input_st); void bsv_movie_finish_rewind(input_driver_state_t *input_st); void bsv_movie_deinit(input_driver_state_t *input_st); +void bsv_movie_deinit_full(input_driver_state_t *input_st); +void bsv_movie_enqueue(input_driver_state_t *input_st, bsv_movie_t *state, enum bsv_flags flags); bool movie_start_playback(input_driver_state_t *input_st, char *path); bool movie_start_record(input_driver_state_t *input_st, char *path); diff --git a/tasks/task_movie.c b/tasks/task_movie.c index dedc901bd3..1877a21a11 100644 --- a/tasks/task_movie.c +++ b/tasks/task_movie.c @@ -267,8 +267,7 @@ static bool bsv_movie_start_record(input_driver_state_t * input_st, char *path) return false; } - input_st->bsv_movie_state_handle = state; - input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_RECORDING; + bsv_movie_enqueue(input_st, state, BSV_FLAG_MOVIE_RECORDING); movie_rec_str = msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO); _len = strlcpy(msg, movie_rec_str, sizeof(msg)); snprintf(msg + _len, sizeof(msg) - _len, " \"%s\".", path); @@ -293,8 +292,7 @@ static bool bsv_movie_start_playback(input_driver_state_t *input_st, char *path) return false; } - input_st->bsv_movie_state_handle = state; - input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_PLAYBACK; + bsv_movie_enqueue(input_st, state, BSV_FLAG_MOVIE_PLAYBACK); starting_movie_str = msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK); @@ -380,7 +378,7 @@ bool movie_stop_playback(input_driver_state_t *input_st) NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); RARCH_LOG("%s\n", movie_playback_end_str); - bsv_movie_deinit(input_st); + bsv_movie_deinit_full(input_st); input_st->bsv_movie_state.flags &= ~( BSV_FLAG_MOVIE_END @@ -397,7 +395,7 @@ bool movie_stop_record(input_driver_state_t *input_st) 2, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); RARCH_LOG("%s\n", movie_rec_stopped_str); - bsv_movie_deinit(input_st); + bsv_movie_deinit_full(input_st); input_st->bsv_movie_state.flags &= ~( BSV_FLAG_MOVIE_END | BSV_FLAG_MOVIE_RECORDING);