commit a1c66caba0bad8995e0ec6389d1b331ec971dd3d
Author: Mark Spieth <mspieth@digivation.com.au>
Date: Sun Mar 3 08:43:07 2019 +1100
Use monotonic time for avsync2 when possible
diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
index 84c903bf1c..aa1195e90b 100644
a
|
b
|
MythPlayer::MythPlayer(PlayerFlags flags) |
270 | 270 | avsync2adjustms = 1; |
271 | 271 | if (avsync2adjustms > 40) |
272 | 272 | avsync2adjustms = 40; |
| 273 | m_avTimer.start(); |
273 | 274 | } |
274 | 275 | |
275 | 276 | MythPlayer::~MythPlayer(void) |
… |
… |
void MythPlayer::AVSync(VideoFrame *buffer, bool limit_delay) |
2167 | 2168 | } |
2168 | 2169 | } |
2169 | 2170 | |
2170 | | static void wait_for_time(int64_t framedue); |
2171 | | |
2172 | | void wait_for_time(int64_t framedue) |
| 2171 | void MythPlayer::WaitForTime(int64_t framedue) |
2173 | 2172 | { |
2174 | | QDateTime now = QDateTime::currentDateTimeUtc(); |
2175 | | int64_t unow = now.toMSecsSinceEpoch() * 1000; |
| 2173 | int64_t unow = m_avTimer.nsecsElapsed() / 1000; |
2176 | 2174 | int64_t delay = framedue - unow; |
2177 | | if (delay > 0) |
2178 | | QThread::usleep(delay); |
| 2175 | while (delay > 0) |
| 2176 | { |
| 2177 | int64_t stepDelay = std::min(delay, (int64_t)2000); |
| 2178 | QThread::usleep(stepDelay); |
| 2179 | delay -= stepDelay; |
| 2180 | } |
2179 | 2181 | } |
2180 | 2182 | |
2181 | 2183 | #define AVSYNC_MAX_LATE 10000000 |
… |
… |
void MythPlayer::AVSync2(VideoFrame *buffer) |
2194 | 2196 | bool pause_audio = false; |
2195 | 2197 | int64_t framedue = 0; |
2196 | 2198 | int64_t audio_adjustment = 0; |
2197 | | QDateTime now; |
2198 | 2199 | int64_t unow = 0; |
2199 | 2200 | int64_t lateness = 0; |
2200 | 2201 | int64_t playspeed1000 = (float)1000 / play_speed; |
… |
… |
void MythPlayer::AVSync2(VideoFrame *buffer) |
2210 | 2211 | videotimecode = maxtcval; |
2211 | 2212 | } |
2212 | 2213 | |
2213 | | now = QDateTime::currentDateTimeUtc(); |
2214 | | unow = now.toMSecsSinceEpoch() * 1000; |
| 2214 | unow = m_avTimer.nsecsElapsed() / 1000; |
2215 | 2215 | |
2216 | 2216 | if (!normal_speed || FlagIsSet(kMusicChoice)) |
2217 | 2217 | { |
… |
… |
void MythPlayer::AVSync2(VideoFrame *buffer) |
2350 | 2350 | // Don't wait for sync if this is a secondary PBP otherwise |
2351 | 2351 | // the primary PBP will become out of sync |
2352 | 2352 | if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP()) |
2353 | | wait_for_time(framedue); |
| 2353 | WaitForTime(framedue); |
2354 | 2354 | // get time codes for calculating difference next time |
2355 | 2355 | prior_audiotimecode = audio.GetAudioTime(); |
2356 | 2356 | videoOutput->Show(ps); |
… |
… |
void MythPlayer::AVSync2(VideoFrame *buffer) |
2381 | 2381 | if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP()) |
2382 | 2382 | { |
2383 | 2383 | int64_t due = framedue + frame_interval / 2; |
2384 | | wait_for_time(due); |
| 2384 | WaitForTime(due); |
2385 | 2385 | } |
2386 | 2386 | videoOutput->Show(ps); |
2387 | 2387 | } |
2388 | 2388 | } |
2389 | 2389 | else |
2390 | | wait_for_time(framedue); |
| 2390 | WaitForTime(framedue); |
2391 | 2391 | |
2392 | 2392 | LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC + |
2393 | 2393 | QString("A/V timecodes audio=%1 video=%2 frameinterval=%3 " |
diff --git a/mythtv/libs/libmythtv/mythplayer.h b/mythtv/libs/libmythtv/mythplayer.h
index 4b295af28f..0a54a25ca3 100644
a
|
b
|
class MTV_PUBLIC MythPlayer |
625 | 625 | int64_t AVSyncGetAudiotime(void); |
626 | 626 | void SetFrameInterval(FrameScanType scan, double speed); |
627 | 627 | void FallbackDeint(void); |
| 628 | void WaitForTime(int64_t framedue); |
628 | 629 | |
629 | 630 | // Private LiveTV stuff |
630 | 631 | void SwitchToProgram(void); |
… |
… |
class MTV_PUBLIC MythPlayer |
711 | 712 | int64_t totalDuration; |
712 | 713 | long long rewindtime; |
713 | 714 | int64_t m_latestVideoTimecode; |
| 715 | QElapsedTimer m_avTimer; |
714 | 716 | |
715 | 717 | // -- end state stuff -- |
716 | 718 | |