Skip to content

Commit

Permalink
Report replay frame number for active_replay stdout api (#17039)
Browse files Browse the repository at this point in the history
This changes the replay movie's frame_ptr (a 20-bit number used to
point to a log of file offsets) into a frame counter, which is masked
against the 20-bit pattern for use in the file offset log but also
functions as a time index into the replay.  Right now that is reported
in `GET_CONFIG_PARAM active_replay` but in the future it could be used
to show how far into the replay we are during playback or how long the
replay is during recording.
  • Loading branch information
JoeOsborn authored Sep 27, 2024
1 parent 8a6eb2d commit abe7d01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
13 changes: 8 additions & 5 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,15 @@ bool command_get_config_param(command_t *cmd, const char* arg)
input_driver_state_t *input_st = input_state_get_ptr();
value = value_dynamic;
value_dynamic[0] = '\0';
if(input_st->bsv_movie_state_handle)
snprintf(value_dynamic, sizeof(value_dynamic), "%lld %u",
(long long)(input_st->bsv_movie_state_handle->identifier),
input_st->bsv_movie_state.flags);
if(input_st->bsv_movie_state_handle) {
bsv_movie_t *movie = input_st->bsv_movie_state_handle;
snprintf(value_dynamic, sizeof(value_dynamic), "%lld %u %lld",
(long long)(movie->identifier),
input_st->bsv_movie_state.flags,
(long long)(movie->frame_counter));
}
else
strlcpy(value_dynamic, "0 0", sizeof(value_dynamic));
strlcpy(value_dynamic, "0 0 0", sizeof(value_dynamic));
}
#endif
/* TODO: query any string */
Expand Down
21 changes: 12 additions & 9 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5685,11 +5685,11 @@ void bsv_movie_frame_rewind(void)

handle->did_rewind = true;

if ( (handle->frame_ptr <= 1)
if ( ( (handle->frame_counter & handle->frame_mask) <= 1)
&& (handle->frame_pos[0] == handle->min_file_pos))
{
/* If we're at the beginning... */
handle->frame_ptr = 0;
handle->frame_counter = 0;
intfstream_seek(handle->file, (int)handle->min_file_pos, SEEK_SET);
if (recording)
intfstream_truncate(handle->file, (int)handle->min_file_pos);
Expand All @@ -5702,11 +5702,14 @@ void bsv_movie_frame_rewind(void)
*
* Sucessively rewinding frames, we need to rewind past the read data,
* plus another. */
handle->frame_ptr = (handle->frame_ptr -
(handle->first_rewind ? 1 : 2)) & handle->frame_mask;
intfstream_seek(handle->file, (int)handle->frame_pos[handle->frame_ptr], SEEK_SET);
uint8_t delta = handle->first_rewind ? 1 : 2;
if (handle->frame_counter >= delta)
handle->frame_counter -= delta;
else
handle->frame_counter = 0;
intfstream_seek(handle->file, (int)handle->frame_pos[handle->frame_counter & handle->frame_mask], SEEK_SET);
if (recording)
intfstream_truncate(handle->file, (int)handle->frame_pos[handle->frame_ptr]);
intfstream_truncate(handle->file, (int)handle->frame_pos[handle->frame_counter & handle->frame_mask]);
}

if (intfstream_tell(handle->file) <= (long)handle->min_file_pos)
Expand Down Expand Up @@ -5758,7 +5761,7 @@ void bsv_movie_finish_rewind(input_driver_state_t *input_st)
bsv_movie_t *handle = input_st->bsv_movie_state_handle;
if (!handle)
return;
handle->frame_ptr = (handle->frame_ptr + 1) & handle->frame_mask;
handle->frame_counter += 1;
handle->first_rewind = !handle->did_rewind;
handle->did_rewind = false;
}
Expand Down Expand Up @@ -5797,7 +5800,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
bsv_movie_handle_clear_key_events(handle);

/* Maybe record checkpoint */
if (checkpoint_interval != 0 && handle->frame_ptr > 0 && (handle->frame_ptr % (checkpoint_interval*60) == 0))
if (checkpoint_interval != 0 && handle->frame_counter > 0 && (handle->frame_counter % (checkpoint_interval*60) == 0))
{
retro_ctx_serialize_info_t serial_info;
uint8_t frame_tok = REPLAY_TOKEN_CHECKPOINT_FRAME;
Expand Down Expand Up @@ -5893,7 +5896,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
}
}
}
handle->frame_pos[handle->frame_ptr] = intfstream_tell(handle->file);
handle->frame_pos[handle->frame_counter & handle->frame_mask] = intfstream_tell(handle->file);
}

size_t replay_get_serialize_size(void)
Expand Down
2 changes: 1 addition & 1 deletion input/input_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct bsv_movie
size_t *frame_pos;
int64_t identifier;
size_t frame_mask;
size_t frame_ptr;
uint64_t frame_counter;
size_t min_file_pos;
size_t state_size;
bsv_key_data_t key_events[NAME_MAX_LENGTH]; /* uint32_t alignment */
Expand Down

0 comments on commit abe7d01

Please sign in to comment.