зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1014393 - Use MediaQueue to store frames pending write to muxer in MediaEncoder. r=pehrsons
MediaQueue provides a better interface for interleaving frames when writing to the muxer (this change will follow in another changeset). The queue interface provides a nicer abstraction than manually managing a nsTArray. MozReview-Commit-ID: 5V5XmYODFdA Differential Revision: https://phabricator.services.mozilla.com/D35387 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f767feb399
Коммит
b0e3afd09f
|
@ -902,25 +902,31 @@ nsresult MediaEncoder::EncodeData() {
|
|||
}
|
||||
|
||||
if (mVideoEncoder && !mVideoEncoder->IsEncodingComplete()) {
|
||||
nsresult rv = mVideoEncoder->GetEncodedTrack(mEncodedVideoFrames);
|
||||
nsTArray<RefPtr<EncodedFrame>> videoFrames;
|
||||
nsresult rv = mVideoEncoder->GetEncodedTrack(videoFrames);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Encoding might be canceled.
|
||||
LOG(LogLevel::Error, ("Failed to get encoded data from video encoder."));
|
||||
return rv;
|
||||
}
|
||||
for (const RefPtr<EncodedFrame>& frame : videoFrames) {
|
||||
mEncodedVideoFrames.Push(frame);
|
||||
}
|
||||
}
|
||||
|
||||
if (mAudioEncoder && !mAudioEncoder->IsEncodingComplete()) {
|
||||
nsresult rv = mAudioEncoder->GetEncodedTrack(mEncodedAudioFrames);
|
||||
nsTArray<RefPtr<EncodedFrame>> audioFrames;
|
||||
nsresult rv = mAudioEncoder->GetEncodedTrack(audioFrames);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Encoding might be canceled.
|
||||
LOG(LogLevel::Error, ("Failed to get encoded data from audio encoder."));
|
||||
return rv;
|
||||
}
|
||||
for (const RefPtr<EncodedFrame>& frame : mEncodedAudioFrames) {
|
||||
for (const RefPtr<EncodedFrame>& frame : audioFrames) {
|
||||
if (frame->mFrameType == EncodedFrame::FrameType::OPUS_AUDIO_FRAME) {
|
||||
frame->mTime += mAudioCodecDelay;
|
||||
}
|
||||
mEncodedAudioFrames.Push(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -938,11 +944,14 @@ nsresult MediaEncoder::WriteEncodedDataToMuxer() {
|
|||
}
|
||||
|
||||
if (mVideoEncoder) {
|
||||
nsTArray<RefPtr<EncodedFrame>> videoFrames;
|
||||
while (mEncodedVideoFrames.GetSize() > 0) {
|
||||
videoFrames.AppendElement(mEncodedVideoFrames.PopFront());
|
||||
}
|
||||
nsresult rv = mWriter->WriteEncodedTrack(
|
||||
mEncodedVideoFrames, mVideoEncoder->IsEncodingComplete()
|
||||
? ContainerWriter::END_OF_STREAM
|
||||
: 0);
|
||||
mEncodedVideoFrames.Clear();
|
||||
videoFrames, mVideoEncoder->IsEncodingComplete()
|
||||
? ContainerWriter::END_OF_STREAM
|
||||
: 0);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(LogLevel::Error,
|
||||
("Failed to write encoded video track to the muxer."));
|
||||
|
@ -951,11 +960,14 @@ nsresult MediaEncoder::WriteEncodedDataToMuxer() {
|
|||
}
|
||||
|
||||
if (mAudioEncoder) {
|
||||
nsTArray<RefPtr<EncodedFrame>> audioFrames;
|
||||
while (mEncodedAudioFrames.GetSize() > 0) {
|
||||
audioFrames.AppendElement(mEncodedAudioFrames.PopFront());
|
||||
}
|
||||
nsresult rv = mWriter->WriteEncodedTrack(
|
||||
mEncodedAudioFrames, mAudioEncoder->IsEncodingComplete()
|
||||
? ContainerWriter::END_OF_STREAM
|
||||
: 0);
|
||||
mEncodedAudioFrames.Clear();
|
||||
audioFrames, mAudioEncoder->IsEncodingComplete()
|
||||
? ContainerWriter::END_OF_STREAM
|
||||
: 0);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(LogLevel::Error,
|
||||
("Failed to write encoded audio track to the muxer."));
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ContainerWriter.h"
|
||||
#include "CubebUtils.h"
|
||||
#include "MediaQueue.h"
|
||||
#include "MediaStreamGraph.h"
|
||||
#include "MediaStreamListener.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
|
@ -288,9 +289,9 @@ class MediaEncoder {
|
|||
RefPtr<dom::VideoStreamTrack> mVideoTrack;
|
||||
|
||||
// Audio frames that have been encoded and are pending write to the muxer
|
||||
nsTArray<RefPtr<EncodedFrame>> mEncodedAudioFrames;
|
||||
MediaQueue<EncodedFrame> mEncodedAudioFrames;
|
||||
// Video frames that have been encoded and are pending write to the muxer
|
||||
nsTArray<RefPtr<EncodedFrame>> mEncodedVideoFrames;
|
||||
MediaQueue<EncodedFrame> mEncodedVideoFrames;
|
||||
|
||||
// How much each audio time stamp should be delayed in microseconds. Used to
|
||||
// adjust for opus codec delay.
|
||||
|
|
Загрузка…
Ссылка в новой задаче