0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

Use MAX_TS_VAR for timestamp jump detection

This combines the 'direct' timestamp variance threshold with the maximum
timestamp jump threshold (or rather just removes the max timestamp jump
threshold and uses the timestamp variance threshold for both timestamp
jumps and detecting timestamps).

The reason why this was done was because a timestamp jump could occur at
a higher threshold than the threshold used for detecting OS timestamps
within a certain threshold.  If timestamps got between those two
thresholds it kind of became a weird situation where timestamps could be
sort of 'stuck' back or forward in time more than intended.  Better to
be consistent and use the same threshold for both values.
This commit is contained in:
jp9000 2014-10-19 09:17:53 -07:00
parent cd306d975a
commit 1c40ce6332

View File

@ -604,10 +604,8 @@ static inline uint64_t conv_frames_to_time(size_t frames)
(uint64_t)info->samples_per_sec; (uint64_t)info->samples_per_sec;
} }
/* maximum "direct" timestamp variance in nanoseconds */ /* maximum timestamp variance in nanoseconds */
#define MAX_TS_VAR 5000000000ULL #define MAX_TS_VAR 2000000000ULL
/* maximum time that timestamp can jump in nanoseconds */
#define MAX_TIMESTAMP_JUMP 2000000000ULL
static inline void reset_audio_timing(obs_source_t *source, uint64_t timestamp) static inline void reset_audio_timing(obs_source_t *source, uint64_t timestamp)
{ {
@ -731,7 +729,7 @@ static void source_output_audio_line(obs_source_t *source,
(in.timestamp - source->next_audio_ts_min); (in.timestamp - source->next_audio_ts_min);
/* smooth audio if within threshold */ /* smooth audio if within threshold */
if (diff > MAX_TIMESTAMP_JUMP) if (diff > MAX_TS_VAR)
handle_ts_jump(source, source->next_audio_ts_min, handle_ts_jump(source, source->next_audio_ts_min,
in.timestamp, diff); in.timestamp, diff);
else if (diff < TS_SMOOTHING_THRESHOLD) else if (diff < TS_SMOOTHING_THRESHOLD)
@ -1589,9 +1587,9 @@ void obs_source_output_audio(obs_source_t *source,
static inline bool frame_out_of_bounds(const obs_source_t *source, uint64_t ts) static inline bool frame_out_of_bounds(const obs_source_t *source, uint64_t ts)
{ {
if (ts < source->last_frame_ts) if (ts < source->last_frame_ts)
return ((source->last_frame_ts - ts) > MAX_TIMESTAMP_JUMP); return ((source->last_frame_ts - ts) > MAX_TS_VAR);
else else
return ((ts - source->last_frame_ts) > MAX_TIMESTAMP_JUMP); return ((ts - source->last_frame_ts) > MAX_TS_VAR);
} }
/* #define DEBUG_ASYNC_FRAMES 1 */ /* #define DEBUG_ASYNC_FRAMES 1 */
@ -1665,7 +1663,7 @@ static bool ready_async_frame(obs_source_t *source, uint64_t sys_time)
next_frame = source->video_frames.array[1]; next_frame = source->video_frames.array[1];
/* more timestamp checking and compensating */ /* more timestamp checking and compensating */
if ((next_frame->timestamp - frame_time) > MAX_TIMESTAMP_JUMP) { if ((next_frame->timestamp - frame_time) > MAX_TS_VAR) {
#if DEBUG_ASYNC_FRAMES #if DEBUG_ASYNC_FRAMES
blog(LOG_DEBUG, "timing jump"); blog(LOG_DEBUG, "timing jump");
#endif #endif