mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
22d3be643b
- fix mac build (11ff07d07d) - Merge branch 'dev' of https://github.com/rmottola/Arctic-Fox into dev (b1d5bda99a) - Bug 1171682 - Disable WebGL in safemode. r=jgilbert (4b388af71d) - Bug 1212724 - Fix compile error in non-unified mode. r=nical (a089c1d600) - bug 1210266 remove unused AudioNode::Callback() r=padenot (7cf3b8ac8d) - bug 1210266 unfriend AudioBufferSourceNode from AudioNode r=padenot (91055f431b) - bug 1210267 use DOMEventTargetHelper::LastRelease instead of custom Release r=baku (f81093ce16) - bug 1179662 call DisconnectFromGraph once only during unlink r=padenot (d95a512d7c) - Bug 1189506. Give AudioContext non-owning pointers to all its AudioNodes. r=karl (f9c2505e25) - bug 1197028 move AllocateAudioBlock to AudioBlock.h r=padenot (59e140347f) - bug 1197028 introduce AudioBlockBuffer r=padenot (bc33ccfc7f) - bug 1199559 write offline buffer in a format suitable for direct use by AudioBuffer r=padenot (69fd69c667) - bug 1199560 finish offline audio context processing even when allocation fails r=padenot (5863c0a56a) - Bug 1140448 - Improving the performances of how AudioEventTimeline calculates values, r=padenot (1a239c48e7) - bug 1191648 don't keep ScriptProcessorNode alive when it has no audioprocess listener r=padenot (8e1e5eb67d) - bug 1191649 determine ScriptProcessor connected status on main thread r=padenot (a919a422c4) - bug 1191648 don't create audioprocess event when there is no listener r=padenot (98ed82f86a) - bug 1199559 write audioprocess input buffer in a format suitable for direct use by AudioBuffer r=padenot (9ffcb9c64d) - bug 1197028 use AudioChunk::ChannelCount() r=padenot (1cf63e9959) - Bug 1148230 - Eliminate the duplicate subexpression (0f1ad073ff) - bug 1197028 use AudioChunk::GetDuration() r=padenot (b9c30d524c) - bug 1197028 introduce AudioBlock to keep track of downstream references to AudioBlockBuffer r=padenot (dfe5d1cb2f) - bug 1199559 add a helper to fallibly allocate ThreadSharedFloatArrayBufferList with buffers r=padenot (4e0c756087) - bug 1197028 use AudioBlock for web audio processing to reuse buffers shared downstream r=padenot (bf12911645) - bug 1201854 handle stop time precisely even when resampling r=padenot (8901626678) - back out part of bug 1197028 (d5d5bfc98a) - Bug 1189506. Put AudioContext::State inline. r=karl (ded4e9a6c0) - bug 916387 keep ScriptProcessorNode alive after input is GCed r=padenot (9430a56c6a) - Bug 1157137 - Fix WebAudio ScriptProcessorNode sometimes gaining high latency. r=padenot (32eadcafaf) - Bug 1189506. Pass AudioContext to AudioNodeStream::Create. r=karlt (8446b0d16d) - bug 1205558 remove unnecessary ScriptProcessorNodeEngine::mSource r=padenot (1e058b4390) - bug 1053011 align "extra" time on AudioContext with processing block size r=padenot (afeb49adbb) - Bug 1188099 - (Part 3) Introduce [ChromeOnly] SpeechSynthesis.forceEnd for tests. r=smaug r=kdavis (53d765144f) - Bug 1189506. Convert ChangeExplicitBlockerCount to MediaStream::Suspend/Resume. r=padenot (cb074a339e) - bug 1205540 don't send more null chunks than necessary to AnalyserNode r=padenot (d382e1f4ae) - bug 1205540 provide querying whether engines need to continue processing even without input r=padenot (36e44cb77b) - bug 1203380 destroy AudioBlocks on AudioNodeStream on graph thread r=padenot (777e68da76) - Bug 1201393. Create an iterator for MediaStreamGraph to iterate over all its streams. r=karlt (3fe295d8c4) - Bug 1195051 - Part 1: Do not unmute the destination node as soon as the AudioContext is constructed; r=padenot (4243840184) - Bug 1195051 - Part 2: Mute the destination node when the AudioContext is suspended, and unmute when resumed; r=padenot (e07d9e3268) - Bug 1201393. Make suspended MediaStreams implicitly always block. r=padenot (d4557acf43) - Bug 1189506. Make AudioContext responsible for tracking all nodes which need to be suspended and resumed. r=padenot (04410070e7) - Bug 1189506. Make suspending/resuming streams more reusable. r=padenot (503052804e) - bug 1201855 rearrange CopyFromBuffer to separate code using numFrames r=padenot (9e2147d19c) - revert blocked to finished (2bed009b25) - bug 1205540 account for active inputs and skip processing when streams are inactive r=padenot (a20049ae19) - bug 864171 move "extra" time accounting for AudioContext with no nodes to destination stream r=padenot (8ef43b8f25) - bug 1208327 make enum AudioContextOperation strongly typed and forward declare instead of including AudioContext.h r=roc (35cc6748c6) - Bug 1201393. Remove usage of FLAG_BLOCK_OUTPUT from MediaRecorder. r=jwwang (d7ddf40ba2) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaRecorder. r=jwwang (587979ca8a) - Bug 1189506. Remove usage of FLAG_BLOCK_OUTPUT from MediaManager. r=jesup (d2cb000648) - Bug 1201393. Remove usage of FLAG_BLOCK_* from OutputStreamData::Connect. r=jwwang (e31f1effc4) - Bug 1189506. Don't bother blocking captured media-element MediaStreams while we're not decoding. r=jwwang (c7240f6fc3) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from AudioParam/AudioNode. r=padenot (57a3e05283) - bug 1191649 add notification of input node changes r=padenot (752ae93e82) - bug 916387 add a notification of garbage collected input node r=padenot (6336b50f51) - Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaStreamAudioSourceNode. r=jwwang (df4d77f09a) - Bug 1189506. Remove aFlags parameter from AllocateInputPort. r=karlt (b62e152ec3) - bug 1205540 make source stream available during RemoveInput r=padenot (45341fac7f) - Bug 1189506. Remove MediaInputPort::mFlags. r=karlt (61cb5dce71) - Bug 1170958 - Allow MediaInputPort to lock to a specific input track. r=roc (a5ba676c3d) - Bug 1200579 - Stop copying AudioParam timelines. r=karlt (0720f80914) - bug 1209286 remove now unnecessary StreamTimeToDOMTime and DOMTimeToStreamTime r=padenot (ff93dd9d3a) - Bug 1140450 - Lower speex_resampler quality for Web Audio API. r=padenot (2f34f0b90c) - bug 1201855 keep track of buffer position even when there are no channels r=padenot (f3cdcd3bfc) - bug 1201855 send ended event even when the buffer has no channel data r=padenot (5175efcf0a) - backout from from bug 1197028 (ab2235c6b9) - Bug 1163958 - Reduce the allocation in MediaStreamGraph - patch 2, r=padenot (0b00b72341) - Bug 1189506. Fix multi-track MediaStream audio output. r=karlt (b136e91cc5) - Bug 1189506. Simplify PlayAudio based on the fact that track time units == stream time units. r=karlt (e3a164170c) - Bug 1189506. Remove misleading comment. r=karlt (f491ee4f02) - Bug 1189506. Simplify blocking code now that stream blocking decision are always independent of other streams. r=karlt (646ee9a8da) - Bug 1189506. Remove MediaStream::mBlockInThisPhase. r=karlt (4cfc75216f) - Bug 1189506. Remove mExplicitBlockerCount and related code since it's always zero now. r=karlt (1d45b877fc) - Bug 1189506. Remove unused MediaStreamGraph::GetBufferedTicks. r=karlt (5f90c53e87) - Bug 1189506. Simplify blocking calculations based on the observation that once a stream starts blocking in a given processing interval, it must stay blocked. r=karlt (bd1d2a90d0) - Bug 1189506. Replace MediaStream::mBlocked with simpler MediaStream::mStartBlocking. r=karlt (215bacd2fd) - Bug 1189506. Inline RecomputeBlocking. r=karlt (336a6ab1e9) - Bug 1189506. Inline ComputeStreamBlockTime. r=karlt (0b0256bb64) - Bug 1189506. Remove unused NotifyConsumptionChanged. r=karlt (c9f1250b34) - Bug 1189506. Remove unused mFlushSourcesNow/mFlushSourcesOnNextIteration. r=karlt (734d5fff71) - Bug 1189506. Factor out code from OneIteration into helper methods. r=karlt (52b5030073) - Bug 1189506. Move setting of mStateComputedTime to OneIteration so it's near setting mProcessedTime. r=karlt (c3507aaa84) - Bug 1189506. No need to pass aNextCurrentTime to UpdateCurrentTimeForStreams. r=karlt (1c6141e03e) - Bug 1189506. Inline StreamNotifyOutput/StreamNotifyFinished. r=karlt (cdac2c6405) - Bug 1189506. Rename StreamTimeToGraphTime/GraphTimeToStreamTime to ...WithBlocking. r=karlt (e61ffd53a4) - bug 1199559 permit writing to ThreadSharedFloatArrayBufferList when not shared r=padenot (4eaa511691) - bug 1199559 add a factory method to accept generated buffer contents in a format suitable for direct use r=padenot (801f9c6c35) - Bug 1170958 - Add input stream and track as args to NotifyQueuedTrackChanges. r=roc (b3677c801a) - bug 1196111 don't keep AudioContext alive from AudioBuffer r=baku (f1b113c655) - bug 1207003 fetch stream position once instead of three times r=padenot (2cef872dc0) - bug 1207003 remove unused aStream parameter r=padenot (8c3fa1ee88) - bug 1207003 add GraphTime parameter to ProcessBlock() and remove GetCurrentPosition() r=padenot (5f442537a2) - bug 1206362 be careful about double -> int conversion r=padenot (956051f9f1) - Bug 1189506. Remove invalid assertion. r=karlt (4fa8b5a7b1) - Bug 1189506. Create StreamTimeToGraphTime/GraphTimeToStreamTime that don't take account of blocking, and call them from AudioNodeStream. r=karlt (d10f5b1b62) - bug 1205558 use destination stream for audio node engine time r=padenot (a9361c32ac) - bug 1205558 remove unused AudioNodeStream* aSource parameter r=padenot (7667751920) - Bug 1189506. Use mProcessedTime in some places instead of passing aFrm. r=karlt (c5537555e5) - Bug 1189506. Use mStateComputedTime in some places instead of passing aTo. r=karlt (69ed378a74) - Bug 1189506. Use mProcessedTime/mStateComputedTime in ProduceDataForStreamsBlockByBlock. karlt (bc1c49c537) - bug 1214493 restore fractional start time accidentally rounded in 13e85dc6b41b r=padenot (87b7b5de82) - missing bit of 1205558 (a46dbdc0de) - Bug 1185176 - Account for the fact that it is possible for nodes to not have streams. r=karlt (1b5729312b) - Bug 1210266 use parameter index instead of node callback for sending timeline events r=padenot (6501350f34) - remove blocked for finished (89fcb0509c) - bug 1215096 correct off-by-one error in playback position of resampled buffers r=padenot (38c7351675) - bug 1020370 adjust assert to tolerate large skipFracNum r=padenot (f4f5c7f10f) - bug 1020370 use int64_t to avoid overflow in subsample calcs r=padenot (9ec82a2c36) - missing bit of bug 1201855 use unsigned integers for buffer positions (7e83ff4598) - bug 1179662 call UnregisterAudioBufferSourceNode only once r=padenot (40a5d8ab9a) - bug 1205558 introduce SecondsToNearestStreamTime r=padenot (719acd8bc2) - missing bits of Bug 1189506. Make AudioContext responsible (8bd5a1044d) - Bug 1189506. Call GraphTimeToStreamTime in ExtractPendingInput since we know no blocking time has been determined yet. r=karlt (bab799c1d0)
367 lines
12 KiB
C++
367 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
#include "MediaEncoder.h"
|
|
#include "MediaDecoder.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsMimeTypes.h"
|
|
#include "mozilla/Logging.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include"GeckoProfiler.h"
|
|
#include "OggWriter.h"
|
|
#include "OpusTrackEncoder.h"
|
|
|
|
#ifdef MOZ_VORBIS
|
|
#include "VorbisTrackEncoder.h"
|
|
#endif
|
|
#ifdef MOZ_WEBM_ENCODER
|
|
#include "VorbisTrackEncoder.h"
|
|
#include "VP8TrackEncoder.h"
|
|
#include "WebMWriter.h"
|
|
#endif
|
|
#ifdef MOZ_OMX_ENCODER
|
|
#include "OmxTrackEncoder.h"
|
|
#include "ISOMediaWriter.h"
|
|
#endif
|
|
|
|
#ifdef LOG
|
|
#undef LOG
|
|
#endif
|
|
|
|
PRLogModuleInfo* gMediaEncoderLog;
|
|
#define LOG(type, msg) MOZ_LOG(gMediaEncoderLog, type, msg)
|
|
|
|
namespace mozilla {
|
|
|
|
void
|
|
MediaEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph,
|
|
TrackID aID,
|
|
StreamTime aTrackOffset,
|
|
uint32_t aTrackEvents,
|
|
const MediaSegment& aQueuedMedia,
|
|
MediaStream* aInputStream,
|
|
TrackID aInputTrackID)
|
|
{
|
|
// Process the incoming raw track data from MediaStreamGraph, called on the
|
|
// thread of MediaStreamGraph.
|
|
if (mAudioEncoder && aQueuedMedia.GetType() == MediaSegment::AUDIO) {
|
|
mAudioEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
|
aTrackOffset, aTrackEvents,
|
|
aQueuedMedia);
|
|
|
|
} else if (mVideoEncoder && aQueuedMedia.GetType() == MediaSegment::VIDEO) {
|
|
mVideoEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
|
aTrackOffset, aTrackEvents,
|
|
aQueuedMedia);
|
|
}
|
|
}
|
|
|
|
void
|
|
MediaEncoder::NotifyEvent(MediaStreamGraph* aGraph,
|
|
MediaStreamListener::MediaStreamGraphEvent event)
|
|
{
|
|
// In case that MediaEncoder does not receive a TRACK_EVENT_ENDED event.
|
|
LOG(LogLevel::Debug, ("NotifyRemoved in [MediaEncoder]."));
|
|
if (mAudioEncoder) {
|
|
mAudioEncoder->NotifyEvent(aGraph, event);
|
|
}
|
|
if (mVideoEncoder) {
|
|
mVideoEncoder->NotifyEvent(aGraph, event);
|
|
}
|
|
}
|
|
|
|
/* static */
|
|
already_AddRefed<MediaEncoder>
|
|
MediaEncoder::CreateEncoder(const nsAString& aMIMEType, uint32_t aAudioBitrate,
|
|
uint32_t aVideoBitrate, uint32_t aBitrate,
|
|
uint8_t aTrackTypes)
|
|
{
|
|
if (!gMediaEncoderLog) {
|
|
gMediaEncoderLog = PR_NewLogModule("MediaEncoder");
|
|
}
|
|
PROFILER_LABEL("MediaEncoder", "CreateEncoder",
|
|
js::ProfileEntry::Category::OTHER);
|
|
|
|
nsAutoPtr<ContainerWriter> writer;
|
|
nsAutoPtr<AudioTrackEncoder> audioEncoder;
|
|
nsAutoPtr<VideoTrackEncoder> videoEncoder;
|
|
RefPtr<MediaEncoder> encoder;
|
|
nsString mimeType;
|
|
if (!aTrackTypes) {
|
|
LOG(LogLevel::Error, ("NO TrackTypes!!!"));
|
|
return nullptr;
|
|
}
|
|
#ifdef MOZ_WEBM_ENCODER
|
|
else if (MediaEncoder::IsWebMEncoderEnabled() &&
|
|
(aMIMEType.EqualsLiteral(VIDEO_WEBM) ||
|
|
(aTrackTypes & ContainerWriter::CREATE_VIDEO_TRACK))) {
|
|
if (aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK) {
|
|
audioEncoder = new VorbisTrackEncoder();
|
|
NS_ENSURE_TRUE(audioEncoder, nullptr);
|
|
}
|
|
videoEncoder = new VP8TrackEncoder();
|
|
writer = new WebMWriter(aTrackTypes);
|
|
NS_ENSURE_TRUE(writer, nullptr);
|
|
NS_ENSURE_TRUE(videoEncoder, nullptr);
|
|
mimeType = NS_LITERAL_STRING(VIDEO_WEBM);
|
|
}
|
|
#endif //MOZ_WEBM_ENCODER
|
|
#ifdef MOZ_OMX_ENCODER
|
|
else if (MediaEncoder::IsOMXEncoderEnabled() &&
|
|
(aMIMEType.EqualsLiteral(VIDEO_MP4) ||
|
|
(aTrackTypes & ContainerWriter::CREATE_VIDEO_TRACK))) {
|
|
if (aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK) {
|
|
audioEncoder = new OmxAACAudioTrackEncoder();
|
|
NS_ENSURE_TRUE(audioEncoder, nullptr);
|
|
}
|
|
videoEncoder = new OmxVideoTrackEncoder();
|
|
writer = new ISOMediaWriter(aTrackTypes);
|
|
NS_ENSURE_TRUE(writer, nullptr);
|
|
NS_ENSURE_TRUE(videoEncoder, nullptr);
|
|
mimeType = NS_LITERAL_STRING(VIDEO_MP4);
|
|
} else if (MediaEncoder::IsOMXEncoderEnabled() &&
|
|
(aMIMEType.EqualsLiteral(AUDIO_3GPP))) {
|
|
audioEncoder = new OmxAMRAudioTrackEncoder();
|
|
NS_ENSURE_TRUE(audioEncoder, nullptr);
|
|
|
|
writer = new ISOMediaWriter(aTrackTypes, ISOMediaWriter::TYPE_FRAG_3GP);
|
|
NS_ENSURE_TRUE(writer, nullptr);
|
|
mimeType = NS_LITERAL_STRING(AUDIO_3GPP);
|
|
}
|
|
#endif // MOZ_OMX_ENCODER
|
|
else if (MediaDecoder::IsOggEnabled() && MediaDecoder::IsOpusEnabled() &&
|
|
(aMIMEType.EqualsLiteral(AUDIO_OGG) ||
|
|
(aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK))) {
|
|
writer = new OggWriter();
|
|
audioEncoder = new OpusTrackEncoder();
|
|
NS_ENSURE_TRUE(writer, nullptr);
|
|
NS_ENSURE_TRUE(audioEncoder, nullptr);
|
|
mimeType = NS_LITERAL_STRING(AUDIO_OGG);
|
|
}
|
|
else {
|
|
LOG(LogLevel::Error, ("Can not find any encoder to record this media stream"));
|
|
return nullptr;
|
|
}
|
|
LOG(LogLevel::Debug, ("Create encoder result:a[%d] v[%d] w[%d] mimeType = %s.",
|
|
audioEncoder != nullptr, videoEncoder != nullptr,
|
|
writer != nullptr, mimeType.get()));
|
|
if (videoEncoder && aVideoBitrate != 0) {
|
|
videoEncoder->SetBitrate(aVideoBitrate);
|
|
}
|
|
if (audioEncoder && aAudioBitrate != 0) {
|
|
audioEncoder->SetBitrate(aAudioBitrate);
|
|
}
|
|
encoder = new MediaEncoder(writer.forget(), audioEncoder.forget(),
|
|
videoEncoder.forget(), mimeType, aAudioBitrate,
|
|
aVideoBitrate, aBitrate);
|
|
return encoder.forget();
|
|
}
|
|
|
|
/**
|
|
* GetEncodedData() runs as a state machine, starting with mState set to
|
|
* GET_METADDATA, the procedure should be as follow:
|
|
*
|
|
* While non-stop
|
|
* If mState is GET_METADDATA
|
|
* Get the meta data from audio/video encoder
|
|
* If a meta data is generated
|
|
* Get meta data from audio/video encoder
|
|
* Set mState to ENCODE_TRACK
|
|
* Return the final container data
|
|
*
|
|
* If mState is ENCODE_TRACK
|
|
* Get encoded track data from audio/video encoder
|
|
* If a packet of track data is generated
|
|
* Insert encoded track data into the container stream of writer
|
|
* If the final container data is copied to aOutput
|
|
* Return the copy of final container data
|
|
* If this is the last packet of input stream
|
|
* Set mState to ENCODE_DONE
|
|
*
|
|
* If mState is ENCODE_DONE or ENCODE_ERROR
|
|
* Stop the loop
|
|
*/
|
|
void
|
|
MediaEncoder::GetEncodedData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
|
|
nsAString& aMIMEType)
|
|
{
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
aMIMEType = mMIMEType;
|
|
PROFILER_LABEL("MediaEncoder", "GetEncodedData",
|
|
js::ProfileEntry::Category::OTHER);
|
|
|
|
bool reloop = true;
|
|
while (reloop) {
|
|
switch (mState) {
|
|
case ENCODE_METADDATA: {
|
|
LOG(LogLevel::Debug, ("ENCODE_METADDATA TimeStamp = %f", GetEncodeTimeStamp()));
|
|
nsresult rv = CopyMetadataToMuxer(mAudioEncoder.get());
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Error! Fail to Set Audio Metadata"));
|
|
break;
|
|
}
|
|
rv = CopyMetadataToMuxer(mVideoEncoder.get());
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Error! Fail to Set Video Metadata"));
|
|
break;
|
|
}
|
|
|
|
rv = mWriter->GetContainerData(aOutputBufs,
|
|
ContainerWriter::GET_HEADER);
|
|
if (aOutputBufs != nullptr) {
|
|
mSizeOfBuffer = aOutputBufs->ShallowSizeOfExcludingThis(MallocSizeOf);
|
|
}
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error,("Error! writer fail to generate header!"));
|
|
mState = ENCODE_ERROR;
|
|
break;
|
|
}
|
|
LOG(LogLevel::Debug, ("Finish ENCODE_METADDATA TimeStamp = %f", GetEncodeTimeStamp()));
|
|
mState = ENCODE_TRACK;
|
|
break;
|
|
}
|
|
|
|
case ENCODE_TRACK: {
|
|
LOG(LogLevel::Debug, ("ENCODE_TRACK TimeStamp = %f", GetEncodeTimeStamp()));
|
|
EncodedFrameContainer encodedData;
|
|
nsresult rv = NS_OK;
|
|
rv = WriteEncodedDataToMuxer(mAudioEncoder.get());
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Error! Fail to write audio encoder data to muxer"));
|
|
break;
|
|
}
|
|
LOG(LogLevel::Debug, ("Audio encoded TimeStamp = %f", GetEncodeTimeStamp()));
|
|
rv = WriteEncodedDataToMuxer(mVideoEncoder.get());
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Fail to write video encoder data to muxer"));
|
|
break;
|
|
}
|
|
LOG(LogLevel::Debug, ("Video encoded TimeStamp = %f", GetEncodeTimeStamp()));
|
|
// In audio only or video only case, let unavailable track's flag to be true.
|
|
bool isAudioCompleted = (mAudioEncoder && mAudioEncoder->IsEncodingComplete()) || !mAudioEncoder;
|
|
bool isVideoCompleted = (mVideoEncoder && mVideoEncoder->IsEncodingComplete()) || !mVideoEncoder;
|
|
rv = mWriter->GetContainerData(aOutputBufs,
|
|
isAudioCompleted && isVideoCompleted ?
|
|
ContainerWriter::FLUSH_NEEDED : 0);
|
|
if (aOutputBufs != nullptr) {
|
|
mSizeOfBuffer = aOutputBufs->ShallowSizeOfExcludingThis(MallocSizeOf);
|
|
}
|
|
if (NS_SUCCEEDED(rv)) {
|
|
// Successfully get the copy of final container data from writer.
|
|
reloop = false;
|
|
}
|
|
mState = (mWriter->IsWritingComplete()) ? ENCODE_DONE : ENCODE_TRACK;
|
|
LOG(LogLevel::Debug, ("END ENCODE_TRACK TimeStamp = %f "
|
|
"mState = %d aComplete %d vComplete %d",
|
|
GetEncodeTimeStamp(), mState, isAudioCompleted, isVideoCompleted));
|
|
break;
|
|
}
|
|
|
|
case ENCODE_DONE:
|
|
case ENCODE_ERROR:
|
|
LOG(LogLevel::Debug, ("MediaEncoder has been shutdown."));
|
|
mSizeOfBuffer = 0;
|
|
mShutdown = true;
|
|
reloop = false;
|
|
break;
|
|
default:
|
|
MOZ_CRASH("Invalid encode state");
|
|
}
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
MediaEncoder::WriteEncodedDataToMuxer(TrackEncoder *aTrackEncoder)
|
|
{
|
|
if (aTrackEncoder == nullptr) {
|
|
return NS_OK;
|
|
}
|
|
if (aTrackEncoder->IsEncodingComplete()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
PROFILER_LABEL("MediaEncoder", "WriteEncodedDataToMuxer",
|
|
js::ProfileEntry::Category::OTHER);
|
|
|
|
EncodedFrameContainer encodedVideoData;
|
|
nsresult rv = aTrackEncoder->GetEncodedTrack(encodedVideoData);
|
|
if (NS_FAILED(rv)) {
|
|
// Encoding might be canceled.
|
|
LOG(LogLevel::Error, ("Error! Fail to get encoded data from video encoder."));
|
|
mState = ENCODE_ERROR;
|
|
return rv;
|
|
}
|
|
rv = mWriter->WriteEncodedTrack(encodedVideoData,
|
|
aTrackEncoder->IsEncodingComplete() ?
|
|
ContainerWriter::END_OF_STREAM : 0);
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Error! Fail to write encoded video track to the media container."));
|
|
mState = ENCODE_ERROR;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
nsresult
|
|
MediaEncoder::CopyMetadataToMuxer(TrackEncoder *aTrackEncoder)
|
|
{
|
|
if (aTrackEncoder == nullptr) {
|
|
return NS_OK;
|
|
}
|
|
|
|
PROFILER_LABEL("MediaEncoder", "CopyMetadataToMuxer",
|
|
js::ProfileEntry::Category::OTHER);
|
|
|
|
RefPtr<TrackMetadataBase> meta = aTrackEncoder->GetMetadata();
|
|
if (meta == nullptr) {
|
|
LOG(LogLevel::Error, ("Error! metadata = null"));
|
|
mState = ENCODE_ERROR;
|
|
return NS_ERROR_ABORT;
|
|
}
|
|
|
|
nsresult rv = mWriter->SetMetadata(meta);
|
|
if (NS_FAILED(rv)) {
|
|
LOG(LogLevel::Error, ("Error! SetMetadata fail"));
|
|
mState = ENCODE_ERROR;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
#ifdef MOZ_WEBM_ENCODER
|
|
bool
|
|
MediaEncoder::IsWebMEncoderEnabled()
|
|
{
|
|
return Preferences::GetBool("media.encoder.webm.enabled");
|
|
}
|
|
#endif
|
|
|
|
#ifdef MOZ_OMX_ENCODER
|
|
bool
|
|
MediaEncoder::IsOMXEncoderEnabled()
|
|
{
|
|
return Preferences::GetBool("media.encoder.omx.enabled");
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* SizeOfExcludingThis measures memory being used by the Media Encoder.
|
|
* Currently it measures the size of the Encoder buffer and memory occupied
|
|
* by mAudioEncoder and mVideoEncoder.
|
|
*/
|
|
size_t
|
|
MediaEncoder::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
size_t amount = 0;
|
|
if (mState == ENCODE_TRACK) {
|
|
amount = mSizeOfBuffer +
|
|
(mAudioEncoder != nullptr ? mAudioEncoder->SizeOfExcludingThis(aMallocSizeOf) : 0) +
|
|
(mVideoEncoder != nullptr ? mVideoEncoder->SizeOfExcludingThis(aMallocSizeOf) : 0);
|
|
}
|
|
return amount;
|
|
}
|
|
|
|
} // namespace mozilla
|