From 4518944045eef3ea0f76f1b08c0a10778b1a8c85 Mon Sep 17 00:00:00 2001 From: walkawayy <81546780+walkawayy@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:55:09 -0400 Subject: [PATCH] wip: save timestamp --- src/game/savegame/savegame_bson.c | 4 ++-- src/specific/s_audio_stream.c | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/game/savegame/savegame_bson.c b/src/game/savegame/savegame_bson.c index 2b1a7e5a4..4178d45fd 100644 --- a/src/game/savegame/savegame_bson.c +++ b/src/game/savegame/savegame_bson.c @@ -1222,7 +1222,7 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) int16_t load_track = json_object_get_int(root_obj, "music_track", -1); - int32_t timestamp_arr[2]; + int64_t timestamp_arr[2]; timestamp_arr[0] = json_object_get_int(root_obj, "music_timestamp1", -1); timestamp_arr[1] = json_object_get_int(root_obj, "music_timestamp2", -1); LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]); @@ -1308,7 +1308,7 @@ void Savegame_BSON_SaveToFile(MYFILE *fp, GAME_INFO *game_info) if (save_track) { save_timestamp = Music_GetTimestamp(Music_CurrentTrack()); } - int *timestamp_arr = (int *)&save_timestamp; + int64_t *timestamp_arr = (int64_t *)&save_timestamp; json_object_append_int(root_obj, "music_timestamp1", timestamp_arr[0]); json_object_append_int(root_obj, "music_timestamp2", timestamp_arr[1]); LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]); diff --git a/src/specific/s_audio_stream.c b/src/specific/s_audio_stream.c index adcae2f23..b9ce5b9d4 100644 --- a/src/specific/s_audio_stream.c +++ b/src/specific/s_audio_stream.c @@ -528,8 +528,14 @@ int64_t S_Audio_StreamGetTimestamp(int sound_id) LOG_DEBUG("Getting timestamp for sound_id %d.", sound_id); SDL_LockAudioDevice(g_AudioDeviceID); AUDIO_STREAM_SOUND *stream = &m_StreamSounds[sound_id]; - return stream->av.frame->best_effort_timestamp; + int64_t timestamp = 0; + int ret = avcodec_receive_frame(stream->av.codec_ctx, stream->av.frame); + if (ret >= 0) { + timestamp = stream->av.frame->best_effort_timestamp; + } SDL_UnlockAudioDevice(g_AudioDeviceID); + LOG_DEBUG("Timestamp: %d.", timestamp); + return timestamp; } return -1;