int64_t BufferedAudioStream::GetPositionInFramesUnlocked() { mMonitor.AssertCurrentThreadOwns(); if (!mCubebStream || mState == ERRORED) { return -1; } uint64_t position = 0; { MonitorAutoUnlock mon(mMonitor); if (cubeb_stream_get_position(mCubebStream, &position) != CUBEB_OK) { return -1; } } // Adjust the reported position by the number of silent frames written // during stream underruns. uint64_t adjustedPosition = 0; if (position >= mLostFrames) { adjustedPosition = position - mLostFrames; } return std::min<uint64_t>(adjustedPosition, INT64_MAX); }
void BufferedAudioStream::StartUnlocked() { mMonitor.AssertCurrentThreadOwns(); if (!mCubebStream || mState != INITIALIZED) { return; } if (mState != STARTED) { int r; { MonitorAutoUnlock mon(mMonitor); r = cubeb_stream_start(mCubebStream); } if (mState != ERRORED) { mState = r == CUBEB_OK ? STARTED : ERRORED; } } }