зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1350814 - Replace use of int64_t for microseconds by TimeUnit in AudioSink. r=kikuo
MozReview-Commit-ID: 3diOpJu7g8i --HG-- extra : rebase_source : 16d7050cd29ea774fce7e76a16ae9100c766b9f8 extra : source : cf6946ba307d04b00e02e353b4724655929eaa69
This commit is contained in:
Родитель
576387b0bc
Коммит
2860ecd0e5
|
@ -2700,7 +2700,8 @@ MediaDecoderStateMachine::CreateAudioSink()
|
|||
auto audioSinkCreator = [self] () {
|
||||
MOZ_ASSERT(self->OnTaskQueue());
|
||||
AudioSink* audioSink = new AudioSink(
|
||||
self->mTaskQueue, self->mAudioQueue, self->GetMediaTime(),
|
||||
self->mTaskQueue, self->mAudioQueue,
|
||||
TimeUnit::FromMicroseconds(self->GetMediaTime()),
|
||||
self->Info().mAudio, self->mAudioChannel);
|
||||
|
||||
self->mAudibleListener = audioSink->AudibleEvent().Connect(
|
||||
|
|
|
@ -33,11 +33,10 @@ static const int32_t LOW_AUDIO_USECS = 300000;
|
|||
|
||||
AudioSink::AudioSink(AbstractThread* aThread,
|
||||
MediaQueue<AudioData>& aAudioQueue,
|
||||
int64_t aStartTime,
|
||||
TimeUnit aStartTime,
|
||||
const AudioInfo& aInfo,
|
||||
dom::AudioChannel aChannel)
|
||||
: mStartTime(aStartTime)
|
||||
, mLastGoodPosition(0)
|
||||
, mInfo(aInfo)
|
||||
, mChannel(aChannel)
|
||||
, mPlaying(true)
|
||||
|
@ -48,7 +47,6 @@ AudioSink::AudioSink(AbstractThread* aThread,
|
|||
, mOwnerThread(aThread)
|
||||
, mProcessedQueueLength(0)
|
||||
, mFramesParsed(0)
|
||||
, mLastEndTime(0)
|
||||
, mIsAudioDataAudible(false)
|
||||
, mAudioQueue(aAudioQueue)
|
||||
{
|
||||
|
@ -103,12 +101,13 @@ AudioSink::Init(const PlaybackParams& aParams)
|
|||
return p;
|
||||
}
|
||||
|
||||
int64_t
|
||||
TimeUnit
|
||||
AudioSink::GetPosition()
|
||||
{
|
||||
int64_t pos;
|
||||
int64_t tmp;
|
||||
if (mAudioStream &&
|
||||
(pos = mAudioStream->GetPosition()) >= 0) {
|
||||
(tmp = mAudioStream->GetPosition()) >= 0) {
|
||||
TimeUnit pos = TimeUnit::FromMicroseconds(tmp);
|
||||
NS_ASSERTION(pos >= mLastGoodPosition,
|
||||
"AudioStream position shouldn't go backward");
|
||||
// Update the last good position when we got a good one.
|
||||
|
@ -221,7 +220,7 @@ AudioSink::InitializeAudioStream(const PlaybackParams& aParams)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
int64_t
|
||||
TimeUnit
|
||||
AudioSink::GetEndTime() const
|
||||
{
|
||||
int64_t written;
|
||||
|
@ -229,14 +228,14 @@ AudioSink::GetEndTime() const
|
|||
MonitorAutoLock mon(mMonitor);
|
||||
written = mWritten;
|
||||
}
|
||||
CheckedInt64 playedUsecs = FramesToUsecs(written, mOutputRate) + mStartTime;
|
||||
if (!playedUsecs.isValid()) {
|
||||
TimeUnit played = FramesToTimeUnit(written, mOutputRate) + mStartTime;
|
||||
if (!played.IsValid()) {
|
||||
NS_WARNING("Int overflow calculating audio end time");
|
||||
return 0;
|
||||
return TimeUnit::Zero();
|
||||
}
|
||||
// As we may be resampling, rounding errors may occur. Ensure we never get
|
||||
// past the original end time.
|
||||
return std::min<int64_t>(mLastEndTime, playedUsecs.value());
|
||||
return std::min(mLastEndTime, played);
|
||||
}
|
||||
|
||||
UniquePtr<AudioStream::Chunk>
|
||||
|
@ -407,8 +406,8 @@ AudioSink::NotifyAudioNeeded()
|
|||
// audio hardware, so we can play across the gap.
|
||||
// Calculate the timestamp of the next chunk of audio in numbers of
|
||||
// samples.
|
||||
CheckedInt64 sampleTime = UsecsToFrames(data->mTime - mStartTime,
|
||||
data->mRate);
|
||||
CheckedInt64 sampleTime = TimeUnitToFrames(
|
||||
TimeUnit::FromMicroseconds(data->mTime) - mStartTime, data->mRate);
|
||||
// Calculate the number of frames that have been pushed onto the audio hardware.
|
||||
CheckedInt64 missingFrames = sampleTime - mFramesParsed;
|
||||
|
||||
|
@ -450,7 +449,7 @@ AudioSink::NotifyAudioNeeded()
|
|||
}
|
||||
}
|
||||
|
||||
mLastEndTime = data->GetEndTime();
|
||||
mLastEndTime = TimeUnit::FromMicroseconds(data->GetEndTime());
|
||||
mFramesParsed += data->mFrames;
|
||||
|
||||
if (mConverter->InputConfig() != mConverter->OutputConfig()) {
|
||||
|
|
|
@ -32,7 +32,7 @@ class AudioSink : private AudioStream::DataSource {
|
|||
public:
|
||||
AudioSink(AbstractThread* aThread,
|
||||
MediaQueue<AudioData>& aAudioQueue,
|
||||
int64_t aStartTime,
|
||||
TimeUnit aStartTime,
|
||||
const AudioInfo& aInfo,
|
||||
dom::AudioChannel aChannel);
|
||||
|
||||
|
@ -46,8 +46,8 @@ public:
|
|||
* All public functions are not thread-safe.
|
||||
* Called on the task queue of MDSM only.
|
||||
*/
|
||||
int64_t GetPosition();
|
||||
int64_t GetEndTime() const;
|
||||
TimeUnit GetPosition();
|
||||
TimeUnit GetEndTime() const;
|
||||
|
||||
// Check whether we've pushed more frames to the audio hardware than it has
|
||||
// played.
|
||||
|
@ -80,15 +80,15 @@ private:
|
|||
// The audio stream resource. Used on the task queue of MDSM only.
|
||||
RefPtr<AudioStream> mAudioStream;
|
||||
|
||||
// The presentation time of the first audio frame that was played in
|
||||
// microseconds. We can add this to the audio stream position to determine
|
||||
// The presentation time of the first audio frame that was played.
|
||||
// We can add this to the audio stream position to determine
|
||||
// the current audio time.
|
||||
const int64_t mStartTime;
|
||||
const TimeUnit mStartTime;
|
||||
|
||||
// Keep the last good position returned from the audio stream. Used to ensure
|
||||
// position returned by GetPosition() is mono-increasing in spite of audio
|
||||
// stream error. Used on the task queue of MDSM only.
|
||||
int64_t mLastGoodPosition;
|
||||
TimeUnit mLastGoodPosition;
|
||||
|
||||
const AudioInfo mInfo;
|
||||
|
||||
|
@ -149,7 +149,7 @@ private:
|
|||
// at the current input framerate.
|
||||
int64_t mFramesParsed;
|
||||
Maybe<RefPtr<AudioData>> mLastProcessedPacket;
|
||||
int64_t mLastEndTime;
|
||||
TimeUnit mLastEndTime;
|
||||
// Never modifed after construction.
|
||||
uint32_t mOutputRate;
|
||||
uint32_t mOutputChannels;
|
||||
|
|
|
@ -58,7 +58,7 @@ AudioSinkWrapper::GetEndTime(TrackType aType) const
|
|||
AssertOwnerThread();
|
||||
MOZ_ASSERT(mIsStarted, "Must be called after playback starts.");
|
||||
if (aType == TrackInfo::kAudioTrack && mAudioSink) {
|
||||
return mAudioSink->GetEndTime();
|
||||
return mAudioSink->GetEndTime().ToMicroseconds();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ AudioSinkWrapper::GetPosition(TimeStamp* aTimeStamp) const
|
|||
|
||||
if (!mAudioEnded) {
|
||||
// Rely on the audio sink to report playback position when it is not ended.
|
||||
pos = mAudioSink->GetPosition();
|
||||
pos = mAudioSink->GetPosition().ToMicroseconds();
|
||||
} else if (!mPlayStartTime.IsNull()) {
|
||||
// Calculate playback position using system clock if we are still playing.
|
||||
pos = GetVideoPosition(t);
|
||||
|
|
Загрузка…
Ссылка в новой задаче