Bug 930444 - [MediaEncoder] Add Profile Label in Encoding path. r=roc

--HG--
extra : rebase_source : 65fad92cc22eddf42e447ef574fda6ec40d92b96
This commit is contained in:
Alastor Wu 2014-10-20 16:17:26 +08:00
parent 1d09fc8964
commit 253a3938cf
9 changed files with 83 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include "nsMimeTypes.h"
#include "nsProxyRelease.h"
#include "nsTArray.h"
#include "GeckoProfiler.h"
#ifdef PR_LOGGING
PRLogModuleInfo* gMediaRecorderLog;
@ -242,6 +243,8 @@ class MediaRecorder::Session: public nsIObserver
} else {
// Flush out remaining encoded data.
mSession->Extract(true);
if (mSession->mIsRegisterProfiler)
profiler_unregister_thread();
if (NS_FAILED(NS_DispatchToMainThread(
new DestroyRunnable(mSession)))) {
MOZ_ASSERT(false, "NS_DispatchToMainThread DestroyRunnable failed");
@ -339,7 +342,8 @@ public:
: mRecorder(aRecorder),
mTimeSlice(aTimeSlice),
mStopIssued(false),
mCanRetrieveData(false)
mCanRetrieveData(false),
mIsRegisterProfiler(false)
{
MOZ_ASSERT(NS_IsMainThread());
@ -438,6 +442,15 @@ private:
MOZ_ASSERT(NS_GetCurrentThread() == mReadThread);
LOG(PR_LOG_DEBUG, ("Session.Extract %p", this));
if (!mIsRegisterProfiler) {
char aLocal;
profiler_register_thread("Media_Encoder", &aLocal);
mIsRegisterProfiler = true;
}
PROFILER_LABEL("MediaRecorder", "Session Extract",
js::ProfileEntry::Category::OTHER);
// Pull encoded media data from MediaEncoder
nsTArray<nsTArray<uint8_t> > encodedBuf;
mEncoder->GetEncodedData(&encodedBuf, mMimeType);
@ -534,7 +547,7 @@ private:
mTrackUnionStream->AddListener(mEncoder);
// Create a thread to read encode media data from MediaEncoder.
if (!mReadThread) {
nsresult rv = NS_NewNamedThread("Media Encoder", getter_AddRefs(mReadThread));
nsresult rv = NS_NewNamedThread("Media_Encoder", getter_AddRefs(mReadThread));
if (NS_FAILED(rv)) {
DoSessionEndTask(rv);
return;
@ -636,6 +649,8 @@ private:
bool mStopIssued;
// Indicate session has encoded data. This can be changed in recording thread.
bool mCanRetrieveData;
// The register flag for "Media_Encoder" thread to profiler
bool mIsRegisterProfiler;
};
NS_IMPL_ISUPPORTS(MediaRecorder::Session, nsIObserver)

View File

@ -10,6 +10,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/StaticPtr.h"
#include"GeckoProfiler.h"
#include "OggWriter.h"
#ifdef MOZ_OPUS
#include "OpusTrackEncoder.h"
@ -87,6 +88,9 @@ MediaEncoder::CreateEncoder(const nsAString& aMIMEType, uint8_t aTrackTypes)
gMediaEncoderLog = PR_NewLogModule("MediaEncoder");
}
#endif
PROFILER_LABEL("MediaEncoder", "CreateEncoder",
js::ProfileEntry::Category::OTHER);
nsAutoPtr<ContainerWriter> writer;
nsAutoPtr<AudioTrackEncoder> audioEncoder;
nsAutoPtr<VideoTrackEncoder> videoEncoder;
@ -186,6 +190,8 @@ MediaEncoder::GetEncodedData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
MOZ_ASSERT(!NS_IsMainThread());
aMIMEType = mMIMEType;
PROFILER_LABEL("MediaEncoder", "GetEncodedData",
js::ProfileEntry::Category::OTHER);
bool reloop = true;
while (reloop) {
@ -276,6 +282,10 @@ MediaEncoder::WriteEncodedDataToMuxer(TrackEncoder *aTrackEncoder)
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)) {
@ -300,6 +310,10 @@ MediaEncoder::CopyMetadataToMuxer(TrackEncoder *aTrackEncoder)
if (aTrackEncoder == nullptr) {
return NS_OK;
}
PROFILER_LABEL("MediaEncoder", "CopyMetadataToMuxer",
js::ProfileEntry::Category::OTHER);
nsRefPtr<TrackMetadataBase> meta = aTrackEncoder->GetMetadata();
if (meta == nullptr) {
LOG(PR_LOG_ERROR, ("Error! metadata = null"));

View File

@ -7,6 +7,7 @@
#include "OMXCodecWrapper.h"
#include "VideoUtils.h"
#include "ISOTrackMetadata.h"
#include "GeckoProfiler.h"
#ifdef MOZ_WIDGET_GONK
#include <android/log.h>
@ -52,6 +53,8 @@ OmxVideoTrackEncoder::Init(int aWidth, int aHeight, int aDisplayWidth,
already_AddRefed<TrackMetadataBase>
OmxVideoTrackEncoder::GetMetadata()
{
PROFILER_LABEL("OmxVideoTrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if mEncoder is not initialized nor is being canceled.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -76,6 +79,8 @@ OmxVideoTrackEncoder::GetMetadata()
nsresult
OmxVideoTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
{
PROFILER_LABEL("OmxVideoTrackEncoder", "GetEncodedTrack",
js::ProfileEntry::Category::OTHER);
VideoSegment segment;
{
// Move all the samples from mRawSegment to segment. We only hold the
@ -197,6 +202,8 @@ OmxAudioTrackEncoder::AppendEncodedFrames(EncodedFrameContainer& aContainer)
nsresult
OmxAudioTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
{
PROFILER_LABEL("OmxAACAudioTrackEncoder", "GetEncodedTrack",
js::ProfileEntry::Category::OTHER);
AudioSegment segment;
// Move all the samples from mRawSegment to segment. We only hold
// the monitor in this block.
@ -264,6 +271,8 @@ OmxAACAudioTrackEncoder::Init(int aChannels, int aSamplingRate)
already_AddRefed<TrackMetadataBase>
OmxAACAudioTrackEncoder::GetMetadata()
{
PROFILER_LABEL("OmxAACAudioTrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if mEncoder is not initialized nor is being canceled.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -304,6 +313,8 @@ OmxAMRAudioTrackEncoder::Init(int aChannels, int aSamplingRate)
already_AddRefed<TrackMetadataBase>
OmxAMRAudioTrackEncoder::GetMetadata()
{
PROFILER_LABEL("OmxAMRAudioTrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if mEncoder is not initialized nor is being canceled.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);

View File

@ -4,6 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OpusTrackEncoder.h"
#include "nsString.h"
#include "GeckoProfiler.h"
#include <opus/opus.h>
@ -204,6 +205,8 @@ OpusTrackEncoder::GetPacketDuration()
already_AddRefed<TrackMetadataBase>
OpusTrackEncoder::GetMetadata()
{
PROFILER_LABEL("OpusTrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if mEncoder is not initialized.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -244,6 +247,8 @@ OpusTrackEncoder::GetMetadata()
nsresult
OpusTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
{
PROFILER_LABEL("OpusTrackEncoder", "GetEncodedTrack",
js::ProfileEntry::Category::OTHER);
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
// Wait until initialized or cancelled.

View File

@ -11,6 +11,7 @@
#include "prsystem.h"
#include "WebMWriter.h"
#include "libyuv.h"
#include "GeckoProfiler.h"
namespace mozilla {
@ -146,6 +147,8 @@ VP8TrackEncoder::Init(int32_t aWidth, int32_t aHeight, int32_t aDisplayWidth,
already_AddRefed<TrackMetadataBase>
VP8TrackEncoder::GetMetadata()
{
PROFILER_LABEL("VP8TrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if mEncoder is not initialized.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -447,6 +450,8 @@ VP8TrackEncoder::CalculateEncodedDuration(TrackTicks aDurationCopied)
nsresult
VP8TrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
{
PROFILER_LABEL("VP8TrackEncoder", "GetEncodedTrack",
js::ProfileEntry::Category::OTHER);
{
// Move all the samples from mRawSegment to mSourceSegment. We only hold
// the monitor in this block.

View File

@ -6,6 +6,7 @@
#include <ogg/ogg.h>
#include <vorbis/vorbisenc.h>
#include "WebMWriter.h"
#include "GeckoProfiler.h"
// One actually used: Encoding using a VBR quality mode. The usable range is -.1
// (lowest quality, smallest file) to 1. (highest quality, largest file).
@ -90,6 +91,8 @@ void VorbisTrackEncoder::WriteLacing(nsTArray<uint8_t> *aOutput, int32_t aLacing
already_AddRefed<TrackMetadataBase>
VorbisTrackEncoder::GetMetadata()
{
PROFILER_LABEL("VorbisTrackEncoder", "GetMetadata",
js::ProfileEntry::Category::OTHER);
{
// Wait if encoder is not initialized.
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -160,6 +163,9 @@ VorbisTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
return NS_OK;
}
PROFILER_LABEL("VorbisTrackEncoder", "GetEncodedTrack",
js::ProfileEntry::Category::OTHER);
nsAutoPtr<AudioSegment> sourceSegment;
sourceSegment = new AudioSegment();
{

View File

@ -10,6 +10,7 @@
#include "nsThreadUtils.h"
#include "MediaEncoder.h"
#include "VideoUtils.h"
#include "GeckoProfiler.h"
#undef LOG
#ifdef MOZ_WIDGET_GONK
@ -82,6 +83,8 @@ nsresult
ISOMediaWriter::WriteEncodedTrack(const EncodedFrameContainer& aData,
uint32_t aFlags)
{
PROFILER_LABEL("ISOMediaWriter", "WriteEncodedTrack",
js::ProfileEntry::Category::OTHER);
// Muxing complete, it doesn't allowed to reentry again.
if (mState == MUXING_DONE) {
MOZ_ASSERT(false);
@ -191,6 +194,8 @@ nsresult
ISOMediaWriter::GetContainerData(nsTArray<nsTArray<uint8_t>>* aOutputBufs,
uint32_t aFlags)
{
PROFILER_LABEL("ISOMediaWriter", "GetContainerData",
js::ProfileEntry::Category::OTHER);
if (mBlobReady) {
if (mState == MUXING_DONE) {
mIsWritingComplete = true;
@ -204,6 +209,8 @@ ISOMediaWriter::GetContainerData(nsTArray<nsTArray<uint8_t>>* aOutputBufs,
nsresult
ISOMediaWriter::SetMetadata(TrackMetadataBase* aMetadata)
{
PROFILER_LABEL("ISOMediaWriter", "SetMetadata",
js::ProfileEntry::Category::OTHER);
if (aMetadata->GetKind() == TrackMetadataBase::METADATA_AAC ||
aMetadata->GetKind() == TrackMetadataBase::METADATA_AMR) {
mControl->SetMetadata(aMetadata);

View File

@ -4,6 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OggWriter.h"
#include "prtime.h"
#include "GeckoProfiler.h"
#undef LOG
#ifdef MOZ_WIDGET_GONK
@ -57,6 +58,9 @@ nsresult
OggWriter::WriteEncodedTrack(const EncodedFrameContainer& aData,
uint32_t aFlags)
{
PROFILER_LABEL("OggWriter", "WriteEncodedTrack",
js::ProfileEntry::Category::OTHER);
for (uint32_t i = 0; i < aData.GetEncodedFrames().Length(); i++) {
if (aData.GetEncodedFrames()[i]->GetFrameType() != EncodedFrame::OPUS_AUDIO_FRAME) {
LOG("[OggWriter] wrong encoded data type!");
@ -133,6 +137,8 @@ OggWriter::GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
uint32_t aFlags)
{
int rc = -1;
PROFILER_LABEL("OggWriter", "GetContainerData",
js::ProfileEntry::Category::OTHER);
// Generate the oggOpus Header
if (aFlags & ContainerWriter::GET_HEADER) {
OpusMetadata* meta = static_cast<OpusMetadata*>(mMetadata.get());
@ -180,6 +186,10 @@ nsresult
OggWriter::SetMetadata(TrackMetadataBase* aMetadata)
{
MOZ_ASSERT(aMetadata);
PROFILER_LABEL("OggWriter", "SetMetadata",
js::ProfileEntry::Category::OTHER);
if (aMetadata->GetKind() != TrackMetadataBase::METADATA_OPUS) {
LOG("wrong meta data type!");
return NS_ERROR_FAILURE;

View File

@ -5,6 +5,7 @@
#include "WebMWriter.h"
#include "EbmlComposer.h"
#include "GeckoProfiler.h"
namespace mozilla {
@ -23,6 +24,8 @@ nsresult
WebMWriter::WriteEncodedTrack(const EncodedFrameContainer& aData,
uint32_t aFlags)
{
PROFILER_LABEL("WebMWriter", "SetMetadata",
js::ProfileEntry::Category::OTHER);
for (uint32_t i = 0 ; i < aData.GetEncodedFrames().Length(); i++) {
mEbmlComposer->WriteSimpleBlock(aData.GetEncodedFrames().ElementAt(i).get());
}
@ -33,6 +36,8 @@ nsresult
WebMWriter::GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
uint32_t aFlags)
{
PROFILER_LABEL("WebMWriter", "GetContainerData",
js::ProfileEntry::Category::OTHER);
mEbmlComposer->ExtractBuffer(aOutputBufs, aFlags);
if (aFlags & ContainerWriter::FLUSH_NEEDED) {
mIsWritingComplete = true;
@ -44,6 +49,9 @@ nsresult
WebMWriter::SetMetadata(TrackMetadataBase* aMetadata)
{
MOZ_ASSERT(aMetadata);
PROFILER_LABEL("WebMWriter", "SetMetadata",
js::ProfileEntry::Category::OTHER);
if (aMetadata->GetKind() == TrackMetadataBase::METADATA_VP8) {
VP8Metadata* meta = static_cast<VP8Metadata*>(aMetadata);
MOZ_ASSERT(meta, "Cannot find vp8 encoder metadata");