Bug 1667728 - Keep track of the output time by counting frames rather than accumulating packets durations in microseconds. r=bryce

There should be no accumulating rounding error here since packet durations are
exactly 200ms which does not lead to a rounding error when converting to
microseconds.

But this is for sanity, since the behavior prior to this patch is exactly how
you get an accumulating rounding error.

Differential Revision: https://phabricator.services.mozilla.com/D91955
This commit is contained in:
Andreas Pehrson 2020-10-08 15:40:58 +00:00
Родитель f0d67db160
Коммит 6473127af5
2 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -130,7 +130,8 @@ OpusTrackEncoder::OpusTrackEncoder(TrackRate aTrackRate)
: kOpusSamplingRate),
mEncoder(nullptr),
mLookahead(0),
mResampler(nullptr) {}
mResampler(nullptr),
mNumOutputFrames(0) {}
OpusTrackEncoder::~OpusTrackEncoder() {
if (mEncoder) {
@ -190,9 +191,6 @@ nsresult OpusTrackEncoder::Init(int aChannels) {
return NS_ERROR_FAILURE;
}
// Calculate offset in microseconds
mCodecDelay = FramesToTimeUnit(mLookahead, mOutputSampleRate);
SetInitialized();
return NS_OK;
@ -442,12 +440,13 @@ nsresult OpusTrackEncoder::GetEncodedTrack(
// timestamp should be the time of the first sample
aData.AppendElement(MakeRefPtr<EncodedFrame>(
mOutputTimeStamp + mCodecDelay, duration, kOpusSamplingRate,
EncodedFrame::OPUS_AUDIO_FRAME, std::move(frameData)));
FramesToTimeUnit(mNumOutputFrames + mLookahead, mOutputSampleRate),
duration, kOpusSamplingRate, EncodedFrame::OPUS_AUDIO_FRAME,
std::move(frameData)));
mOutputTimeStamp +=
FramesToTimeUnit(NumOutputFramesPerPacket(), kOpusSamplingRate);
LOG("[Opus] mOutputTimeStamp %.3f.", mOutputTimeStamp.ToSeconds());
mNumOutputFrames += NumOutputFramesPerPacket();
LOG("[Opus] mOutputTimeStamp %.3f.",
FramesToTimeUnit(mNumOutputFrames, mOutputSampleRate).ToSeconds());
}
return result >= 0 ? NS_OK : NS_ERROR_FAILURE;

Просмотреть файл

@ -107,7 +107,10 @@ class OpusTrackEncoder : public AudioTrackEncoder {
*/
nsTArray<AudioDataValue> mResampledLeftover;
media::TimeUnit mOutputTimeStamp;
/**
* Number of audio frames encoded, in kOpusSamplingRate.
*/
uint64_t mNumOutputFrames;
};
} // namespace mozilla