Bug 1663662 - Pass the samplerate to EncodedFrame. r=bryce

Without this, EncodedFrame is relying on hardcoded values based on frame type.
That doesn't scale well.

Differential Revision: https://phabricator.services.mozilla.com/D91138
This commit is contained in:
Andreas Pehrson 2020-09-24 13:43:52 +00:00
Родитель beb9fe2e9a
Коммит ce274e63a2
4 изменённых файлов: 8 добавлений и 14 удалений

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

@ -37,25 +37,16 @@ class EncodedFrame final {
const nsTArray<uint8_t>& GetFrameData() const { return mFrameData; }
// Timestamp in microseconds
uint64_t mTime;
// The playback duration of this packet. The unit is determined by the use
// case. For VP8 the unit should be microseconds. For opus this is the number
// of samples.
// The time base of mDuration.
uint64_t mDurationBase;
// The playback duration of this packet in mDurationBase.
uint64_t mDuration;
// Represent what is in the FrameData
FrameType mFrameType;
// The end time of the frame in microseconds.
uint64_t GetEndTime() const {
// Defend against untested types. This assert can be removed but we want
// to make sure other types are correctly accounted for.
MOZ_ASSERT(mFrameType == OPUS_AUDIO_FRAME || mFrameType == VP8_I_FRAME ||
mFrameType == VP8_P_FRAME);
if (mFrameType == OPUS_AUDIO_FRAME) {
// See bug 1356054 for discussion around standardization of time units
// (can remove videoutils import when this goes)
return mTime + FramesToUsecs(mDuration, 48000).value();
} else {
return mTime + mDuration;
}
return mTime + FramesToUsecs(mDuration, mDurationBase).value();
}
private:

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

@ -372,6 +372,7 @@ nsresult OpusTrackEncoder::GetEncodedTrack(
// The ogg time stamping and pre-skip is always timed at 48000.
audiodata->mDuration = frameCopied * (kOpusSamplingRate / mSamplingRate);
}
audiodata->mDurationBase = kOpusSamplingRate;
// Remove the raw data which has been pulled to pcm buffer.
// The value of frameCopied should equal to (or smaller than, if eos)

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

@ -283,6 +283,7 @@ nsresult VP8TrackEncoder::GetEncodedPartitions(
mExtractedDurationUs = totalDuration;
videoData->mDuration = (uint64_t)duration.value();
videoData->mDurationBase = PR_USEC_PER_SEC;
videoData->SwapInFrameData(frameData);
VP8LOG(LogLevel::Verbose,
"GetEncodedPartitions TimeStamp %" PRIu64 ", Duration %" PRIu64

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

@ -79,6 +79,7 @@ class TestWebMWriter : public WebMWriter {
videoData->mFrameType = aFrameType;
videoData->mTime = mTimestamp;
videoData->mDuration = aDuration;
videoData->mDurationBase = PR_USEC_PER_SEC;
videoData->SwapInFrameData(frameData);
encodedVideoData.AppendElement(videoData);
WriteEncodedTrack(encodedVideoData, 0);