Set the initial clock time closer to starting playback

This commit is contained in:
Chris Robinson
2019-07-20 01:10:14 -07:00
parent 9959d661a0
commit f0ed35d3d0
+13 -15
View File
@@ -748,19 +748,10 @@ void AL_APIENTRY AudioState::EventCallback(ALenum eventType, ALuint object, ALui
int AudioState::handler()
{
std::unique_lock<std::mutex> srclock{mSrcMutex};
std::unique_lock<std::mutex> srclock{mSrcMutex, std::defer_lock};
milliseconds sleep_time{AudioBufferTime / 3};
ALenum fmt;
if(alcGetInteger64vSOFT)
{
int64_t devtime{};
alcGetInteger64vSOFT(alcGetContextsDevice(alcGetCurrentContext()), ALC_DEVICE_CLOCK_SOFT,
1, &devtime);
mDeviceStartTime = nanoseconds{devtime} - mCurrentPts;
}
srclock.unlock();
#ifdef AL_SOFT_events
const std::array<ALenum,6> evt_types{{
AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT,
@@ -1012,6 +1003,13 @@ int AudioState::handler()
mPackets.sendTo(mCodecCtx.get());
srclock.lock();
if(alcGetInteger64vSOFT)
{
int64_t devtime{};
alcGetInteger64vSOFT(alcGetContextsDevice(alcGetCurrentContext()), ALC_DEVICE_CLOCK_SOFT,
1, &devtime);
mDeviceStartTime = nanoseconds{devtime} - mCurrentPts;
}
while(alGetError() == AL_NO_ERROR && !mMovie.mQuit.load(std::memory_order_relaxed) &&
mConnected.test_and_set(std::memory_order_relaxed))
{
@@ -1301,11 +1299,6 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
int VideoState::handler()
{
{
std::lock_guard<std::mutex> _{mDispPtsMutex};
mDisplayPtsTime = get_avtime();
}
std::for_each(mPictQ.begin(), mPictQ.end(),
[](Picture &pict) -> void
{ pict.mFrame = AVFramePtr{av_frame_alloc()}; });
@@ -1313,6 +1306,11 @@ int VideoState::handler()
/* Prefill the codec buffer. */
mPackets.sendTo(mCodecCtx.get());
{
std::lock_guard<std::mutex> _{mDispPtsMutex};
mDisplayPtsTime = get_avtime();
}
while(!mMovie.mQuit.load(std::memory_order_relaxed))
{
size_t write_idx{mPictQWrite.load(std::memory_order_relaxed)};