From 80c02069eba79a0b95cd0caf440d49f6e066eb94 Mon Sep 17 00:00:00 2001 From: Butkovits Atila Date: Mon, 4 Oct 2021 21:33:41 +0300 Subject: [PATCH] Backed out 4 changesets (bug 1730020) for causing build bustages. CLOSED TREE Backed out changeset 580203e4b76a (bug 1730020) Backed out changeset b57ce3e0f39f (bug 1730020) Backed out changeset 085fb78aac06 (bug 1730020) Backed out changeset 8799f103c043 (bug 1730020) --- .../performance-new/popup/background.jsm.js | 1 - dom/media/MediaData.cpp | 15 -- dom/media/MediaDecoderStateMachine.cpp | 36 ++--- dom/media/MediaFormatReader.cpp | 65 ++------- dom/media/ipc/RemoteMediaData.cpp | 22 +-- dom/media/ipc/RemoteMediaData.h | 2 - dom/media/platforms/wmf/DXVA2Manager.cpp | 5 - dom/media/utils/PerformanceRecorder.cpp | 125 ---------------- dom/media/utils/PerformanceRecorder.h | 134 ------------------ .../utils/gtest/TestPerformanceRecorder.cpp | 61 -------- dom/media/utils/gtest/moz.build | 18 --- dom/media/utils/moz.build | 5 - 12 files changed, 26 insertions(+), 463 deletions(-) delete mode 100644 dom/media/utils/PerformanceRecorder.cpp delete mode 100644 dom/media/utils/PerformanceRecorder.h delete mode 100644 dom/media/utils/gtest/TestPerformanceRecorder.cpp delete mode 100644 dom/media/utils/gtest/moz.build diff --git a/devtools/client/performance-new/popup/background.jsm.js b/devtools/client/performance-new/popup/background.jsm.js index a0a5f0c75a1d..2fcd51e99923 100644 --- a/devtools/client/performance-new/popup/background.jsm.js +++ b/devtools/client/performance-new/popup/background.jsm.js @@ -160,7 +160,6 @@ const presets = { "ModuleProcessThread", "NativeAudioCallback", "PacerThread", - "RemVidChild", "RenderBackend", "Renderer", "SwComposite", diff --git a/dom/media/MediaData.cpp b/dom/media/MediaData.cpp index 4e6dcb70e978..a0113605e8d9 100644 --- a/dom/media/MediaData.cpp +++ b/dom/media/MediaData.cpp @@ -8,7 +8,6 @@ #include "ImageContainer.h" #include "MediaInfo.h" -#include "PerformanceRecorder.h" #include "VideoUtils.h" #include "YCbCrUtils.h" #include "mozilla/layers/ImageBridgeChild.h" @@ -318,9 +317,6 @@ already_AddRefed VideoData::CreateAndCopyData( return nullptr; } - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::CopyDecodedVideo, - aInfo.mImage.height); - perfRecorder.Start(); RefPtr v(new VideoData(aOffset, aTime, aDuration, aKeyframe, aTimecode, aInfo.mDisplay, 0)); @@ -341,7 +337,6 @@ already_AddRefed VideoData::CreateAndCopyData( : aAllocator, aContainer, data)) { v->mImage = d3d11Image; - perfRecorder.End(); return v.forget(); } } @@ -353,7 +348,6 @@ already_AddRefed VideoData::CreateAndCopyData( PlanarYCbCrData data = ConstructPlanarYCbCrData(aInfo, aBuffer, aPicture); if (ioImage->SetData(aContainer, data)) { v->mImage = ioImage; - perfRecorder.End(); return v.forget(); } } @@ -375,7 +369,6 @@ already_AddRefed VideoData::CreateAndCopyData( return nullptr; } - perfRecorder.End(); return v.forget(); } @@ -484,13 +477,6 @@ MediaRawData::MediaRawData(AlignedByteBuffer&& aData, mAlphaBuffer(std::move(aAlphaData)) {} already_AddRefed MediaRawData::Clone() const { - int32_t sampleHeight = 0; - if (mTrackInfo && mTrackInfo->GetAsVideoInfo()) { - sampleHeight = mTrackInfo->GetAsVideoInfo()->mImage.height; - } - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::CopyDemuxedData, - sampleHeight); - perfRecorder.Start(); RefPtr s = new MediaRawData; s->mTimecode = mTimecode; s->mTime = mTime; @@ -508,7 +494,6 @@ already_AddRefed MediaRawData::Clone() const { if (!s->mAlphaBuffer.Append(mAlphaBuffer.Data(), mAlphaBuffer.Length())) { return nullptr; } - perfRecorder.End(); return s.forget(); } diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 03af4ede5be3..b110a22012ab 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -35,7 +35,6 @@ #include "MediaShutdownManager.h" #include "MediaTrackGraph.h" #include "MediaTimer.h" -#include "PerformanceRecorder.h" #include "ReaderProxy.h" #include "TimeUnits.h" #include "VideoSegment.h" @@ -194,7 +193,7 @@ class MediaDecoderStateMachine::StateObject { virtual void HandleAudioDecoded(AudioData* aAudio) { Crash("Unexpected event!", __func__); } - virtual void HandleVideoDecoded(VideoData* aVideo) { + virtual void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) { Crash("Unexpected event!", __func__); } virtual void HandleAudioWaited(MediaData::Type aType) { @@ -435,7 +434,9 @@ class MediaDecoderStateMachine::DormantState void HandlePlayStateChanged(MediaDecoder::PlayState aPlayState) override; void HandleAudioDecoded(AudioData*) override { MaybeReleaseResources(); } - void HandleVideoDecoded(VideoData*) override { MaybeReleaseResources(); } + void HandleVideoDecoded(VideoData*, TimeStamp) override { + MaybeReleaseResources(); + } void HandleWaitingForAudio() override { MaybeReleaseResources(); } void HandleWaitingForVideo() override { MaybeReleaseResources(); } void HandleAudioCanceled() override { MaybeReleaseResources(); } @@ -485,7 +486,7 @@ class MediaDecoderStateMachine::DecodingFirstFrameState MaybeFinishDecodeFirstFrame(); } - void HandleVideoDecoded(VideoData* aVideo) override { + void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) override { mMaster->PushVideo(aVideo); MaybeFinishDecodeFirstFrame(); } @@ -590,7 +591,7 @@ class MediaDecoderStateMachine::DecodingState MaybeStopPrerolling(); } - void HandleVideoDecoded(VideoData* aVideo) override { + void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) override { const auto currentTime = mMaster->GetMediaTime(); if (aVideo->GetEndTime() < currentTime) { SLOG("video %" PRId64 " is too late (current=%" PRId64 ")", @@ -1056,7 +1057,8 @@ class MediaDecoderStateMachine::SeekingState State GetState() const override = 0; void HandleAudioDecoded(AudioData* aAudio) override = 0; - void HandleVideoDecoded(VideoData* aVideo) override = 0; + void HandleVideoDecoded(VideoData* aVideo, + TimeStamp aDecodeStart) override = 0; void HandleAudioWaited(MediaData::Type aType) override = 0; void HandleVideoWaited(MediaData::Type aType) override = 0; @@ -1144,7 +1146,7 @@ class MediaDecoderStateMachine::AccurateSeekingState MaybeFinishSeek(); } - void HandleVideoDecoded(VideoData* aVideo) override { + void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) override { MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished"); MOZ_ASSERT(aVideo); @@ -1541,7 +1543,7 @@ class MediaDecoderStateMachine::NextFrameSeekingState mMaster->PushAudio(aAudio); } - void HandleVideoDecoded(VideoData* aVideo) override { + void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) override { MOZ_ASSERT(aVideo); MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished"); MOZ_ASSERT(NeedMoreVideo()); @@ -1928,7 +1930,7 @@ class MediaDecoderStateMachine::BufferingState mMaster->ScheduleStateMachine(); } - void HandleVideoDecoded(VideoData* aVideo) override { + void HandleVideoDecoded(VideoData* aVideo, TimeStamp aDecodeStart) override { mMaster->PushVideo(aVideo); if (!mMaster->HaveEnoughDecodedVideo()) { mMaster->RequestVideoData(media::TimeUnit()); @@ -3272,15 +3274,11 @@ void MediaDecoderStateMachine::RequestAudioData() { LOGV("Queueing audio task - queued=%zu, decoder-queued=%zu", AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames()); - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestData); - perfRecorder.Start(); RefPtr self = this; mReader->RequestAudioData() ->Then( OwnerThread(), __func__, - [this, self, perfRecorder(std::move(perfRecorder))]( - RefPtr aAudio) mutable { - perfRecorder.End(); + [this, self](RefPtr aAudio) { AUTO_PROFILER_LABEL( "MediaDecoderStateMachine::RequestAudioData:Resolved", MEDIA_PLAYBACK); @@ -3333,16 +3331,12 @@ void MediaDecoderStateMachine::RequestVideoData( VideoQueue().GetSize(), mReader->SizeOfVideoQueueInFrames(), aCurrentTime.ToMicroseconds()); - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestData, - Info().mVideo.mImage.height); - perfRecorder.Start(); + TimeStamp videoDecodeStartTime = TimeStamp::Now(); RefPtr self = this; mReader->RequestVideoData(aCurrentTime, aRequestNextKeyFrame) ->Then( OwnerThread(), __func__, - [this, self, perfRecorder(std::move(perfRecorder))]( - RefPtr aVideo) mutable { - perfRecorder.End(); + [this, self, videoDecodeStartTime](RefPtr aVideo) { AUTO_PROFILER_LABEL( "MediaDecoderStateMachine::RequestVideoData:Resolved", MEDIA_PLAYBACK); @@ -3354,7 +3348,7 @@ void MediaDecoderStateMachine::RequestVideoData( LOGV("OnVideoDecoded [%" PRId64 ",%" PRId64 "]", aVideo->mTime.ToMicroseconds(), aVideo->GetEndTime().ToMicroseconds()); - mStateObj->HandleVideoDecoded(aVideo); + mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime); }, [this, self](const MediaResult& aError) { AUTO_PROFILER_LABEL( diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index ef7a6d40848d..b589b91c8faf 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -11,17 +11,13 @@ #include #include "AllocationPolicy.h" -#include "AOMDecoder.h" #include "DecoderBenchmark.h" #include "MediaData.h" #include "MediaDataDecoderProxy.h" #include "MediaInfo.h" -#include "MP4Decoder.h" #include "PDMFactory.h" -#include "PerformanceRecorder.h" #include "VideoFrameContainer.h" #include "VideoUtils.h" -#include "VPXDecoder.h" #include "mozilla/AbstractThread.h" #include "mozilla/CDMProxy.h" #include "mozilla/ClearOnShutdown.h" @@ -1459,14 +1455,10 @@ void MediaFormatReader::DoDemuxVideo() { using SamplesPromise = MediaTrackDemuxer::SamplesPromise; DDLOG(DDLogCategory::Log, "video_demuxing", DDNoValue{}); - PerformanceRecorder perfRecorder( - PerformanceRecorder::Stage::RequestDemux, - mVideo.GetCurrentInfo()->GetAsVideoInfo()->mImage.height); - perfRecorder.Start(); auto p = mVideo.mTrackDemuxer->GetSamples(1); - RefPtr self = this; if (mVideo.mFirstDemuxedSampleTime.isNothing()) { + RefPtr self = this; p = p->Then( OwnerThread(), __func__, [self](RefPtr aSamples) { @@ -1487,14 +1479,9 @@ void MediaFormatReader::DoDemuxVideo() { }); } - p->Then( - OwnerThread(), __func__, - [self, perfRecorder(std::move(perfRecorder))]( - RefPtr aSamples) mutable { - perfRecorder.End(); - self->OnVideoDemuxCompleted(std::move(aSamples)); - }, - [self](const MediaResult& aError) { self->OnVideoDemuxFailed(aError); }) + p->Then(OwnerThread(), __func__, this, + &MediaFormatReader::OnVideoDemuxCompleted, + &MediaFormatReader::OnVideoDemuxFailed) ->Track(mVideo.mDemuxRequest); } @@ -1553,12 +1540,10 @@ void MediaFormatReader::DoDemuxAudio() { using SamplesPromise = MediaTrackDemuxer::SamplesPromise; DDLOG(DDLogCategory::Log, "audio_demuxing", DDNoValue{}); - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestDemux); - perfRecorder.Start(); auto p = mAudio.mTrackDemuxer->GetSamples(1); - RefPtr self = this; if (mAudio.mFirstDemuxedSampleTime.isNothing()) { + RefPtr self = this; p = p->Then( OwnerThread(), __func__, [self](RefPtr aSamples) { @@ -1579,14 +1564,9 @@ void MediaFormatReader::DoDemuxAudio() { }); } - p->Then( - OwnerThread(), __func__, - [self, perfRecorder(std::move(perfRecorder))]( - RefPtr aSamples) mutable { - perfRecorder.End(); - self->OnAudioDemuxCompleted(std::move(aSamples)); - }, - [self](const MediaResult& aError) { self->OnAudioDemuxFailed(aError); }) + p->Then(OwnerThread(), __func__, this, + &MediaFormatReader::OnAudioDemuxCompleted, + &MediaFormatReader::OnAudioDemuxFailed) ->Track(mAudio.mDemuxRequest); } @@ -1885,37 +1865,10 @@ void MediaFormatReader::DecodeDemuxedSamples(TrackType aTrack, aSample->mTimecode.ToMicroseconds(), aSample->mDuration.ToMicroseconds(), aSample->mKeyframe ? " kf" : "", aSample->mEOS ? " eos" : ""); - - const int32_t height = - aTrack == TrackInfo::kVideoTrack - ? decoder.GetCurrentInfo()->GetAsVideoInfo()->mImage.height - : 0; - MediaInfoFlag flag = MediaInfoFlag::None; - flag |= - aSample->mKeyframe ? MediaInfoFlag::KeyFrame : MediaInfoFlag::NonKeyFrame; - if (aTrack == TrackInfo::kVideoTrack) { - flag |= VideoIsHardwareAccelerated() ? MediaInfoFlag::HardwareDecoding - : MediaInfoFlag::SoftwareDecoding; - const nsCString& mimeType = decoder.GetCurrentInfo()->mMimeType; - if (MP4Decoder::IsH264(mimeType)) { - flag |= MediaInfoFlag::VIDEO_H264; - } else if (VPXDecoder::IsVPX(mimeType, VPXDecoder::VP8)) { - flag |= MediaInfoFlag::VIDEO_VP8; - } else if (VPXDecoder::IsVPX(mimeType, VPXDecoder::VP9)) { - flag |= MediaInfoFlag::VIDEO_VP9; - } else if (AOMDecoder::IsAV1(mimeType)) { - flag |= MediaInfoFlag::VIDEO_AV1; - } - } - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestDecode, - height, flag); - perfRecorder.Start(); decoder.mDecoder->Decode(aSample) ->Then( mTaskQueue, __func__, - [self, aTrack, &decoder, perfRecorder(std::move(perfRecorder))]( - MediaDataDecoder::DecodedData&& aResults) mutable { - perfRecorder.End(); + [self, aTrack, &decoder](MediaDataDecoder::DecodedData&& aResults) { decoder.mDecodeRequest.Complete(); self->NotifyNewOutput(aTrack, std::move(aResults)); }, diff --git a/dom/media/ipc/RemoteMediaData.cpp b/dom/media/ipc/RemoteMediaData.cpp index f005160a35e9..1411cae2a250 100644 --- a/dom/media/ipc/RemoteMediaData.cpp +++ b/dom/media/ipc/RemoteMediaData.cpp @@ -6,7 +6,6 @@ #include "RemoteMediaData.h" -#include "PerformanceRecorder.h" #include "mozilla/CheckedInt.h" #include "mozilla/dom/MediaIPCUtils.h" #include "mozilla/ipc/Shmem.h" @@ -135,23 +134,16 @@ bool ArrayOfRemoteMediaRawData::Fill( nsTArray dataBuffers(aData.Length()); nsTArray alphaBuffers(aData.Length()); nsTArray> extraDataBuffers(aData.Length()); - int32_t height = 0; for (auto&& entry : aData) { dataBuffers.AppendElement(std::move(entry->mBuffer)); alphaBuffers.AppendElement(std::move(entry->mAlphaBuffer)); extraDataBuffers.AppendElement(std::move(entry->mExtraData)); - if (auto&& info = entry->mTrackInfo; info && info->GetAsVideoInfo()) { - height = info->GetAsVideoInfo()->mImage.height; - } mSamples.AppendElement(RemoteMediaRawData{ MediaDataIPDL(entry->mOffset, entry->mTime, entry->mTimecode, entry->mDuration, entry->mKeyframe), - entry->mEOS, height, entry->mDiscardPadding, + entry->mEOS, entry->mDiscardPadding, entry->mOriginalPresentationWindow}); } - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::CopyDemuxedData, - height); - perfRecorder.Start(); mBuffers = RemoteArrayOfByteBuffer(dataBuffers, aAllocator); if (!mBuffers.IsValid()) { return false; @@ -161,11 +153,7 @@ bool ArrayOfRemoteMediaRawData::Fill( return false; } mExtraDatas = RemoteArrayOfByteBuffer(extraDataBuffers, aAllocator); - if (!mExtraDatas.IsValid()) { - return false; - } - perfRecorder.End(); - return true; + return mExtraDatas.IsValid(); } already_AddRefed ArrayOfRemoteMediaRawData::ElementAt( @@ -179,9 +167,6 @@ already_AddRefed ArrayOfRemoteMediaRawData::ElementAt( mExtraDatas.Count() == Count(), "Something ain't right here"); const auto& sample = mSamples[aIndex]; - PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::CopyDemuxedData, - sample.mHeight); - perfRecorder.Start(); AlignedByteBuffer data = mBuffers.AlignedBufferAt(aIndex); if (mBuffers.SizeAt(aIndex) && !data) { // OOM @@ -206,7 +191,6 @@ already_AddRefed ArrayOfRemoteMediaRawData::ElementAt( rawData->mEOS = sample.mEOS; rawData->mDiscardPadding = sample.mDiscardPadding; rawData->mExtraData = mExtraDatas.MediaByteBufferAt(aIndex); - perfRecorder.End(); return rawData.forget(); } @@ -238,7 +222,6 @@ ipc::IPDLParamTraits::Write( IPC::Message* aMsg, ipc::IProtocol* aActor, const paramType& aVar) { WriteIPDLParam(aMsg, aActor, aVar.mBase); WriteIPDLParam(aMsg, aActor, aVar.mEOS); - WriteIPDLParam(aMsg, aActor, aVar.mHeight); WriteIPDLParam(aMsg, aActor, aVar.mDiscardPadding); WriteIPDLParam(aMsg, aActor, aVar.mOriginalPresentationWindow); } @@ -250,7 +233,6 @@ ipc::IPDLParamTraits::Read( MediaDataIPDL mBase; return ReadIPDLParam(aMsg, aIter, aActor, &aVar->mBase) && ReadIPDLParam(aMsg, aIter, aActor, &aVar->mEOS) && - ReadIPDLParam(aMsg, aIter, aActor, &aVar->mHeight) && ReadIPDLParam(aMsg, aIter, aActor, &aVar->mDiscardPadding) && ReadIPDLParam(aMsg, aIter, aActor, &aVar->mOriginalPresentationWindow); }; diff --git a/dom/media/ipc/RemoteMediaData.h b/dom/media/ipc/RemoteMediaData.h index f8f9aa4ad4c3..89a9a25d32f6 100644 --- a/dom/media/ipc/RemoteMediaData.h +++ b/dom/media/ipc/RemoteMediaData.h @@ -232,8 +232,6 @@ class ArrayOfRemoteMediaRawData { struct RemoteMediaRawData { MediaDataIPDL mBase; bool mEOS; - // This will be zero for audio. - int32_t mHeight; uint32_t mDiscardPadding; Maybe mOriginalPresentationWindow; }; diff --git a/dom/media/platforms/wmf/DXVA2Manager.cpp b/dom/media/platforms/wmf/DXVA2Manager.cpp index 2e77eafae1e9..93ef69499364 100644 --- a/dom/media/platforms/wmf/DXVA2Manager.cpp +++ b/dom/media/platforms/wmf/DXVA2Manager.cpp @@ -12,7 +12,6 @@ #include "ImageContainer.h" #include "MFTDecoder.h" #include "MediaTelemetryConstants.h" -#include "PerformanceRecorder.h" #include "VideoUtils.h" #include "WMFUtils.h" #include "gfxCrashReporterUtils.h" @@ -897,9 +896,6 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample, NS_ENSURE_TRUE(mSyncObject, E_FAIL); } - PerformanceRecorder perfRecorder( - PerformanceRecorder::Stage::CopyDecodedVideo, height); - perfRecorder.Start(); // The D3D11TextureClientAllocator may return a different texture format // than preferred. In which case the destination texture will be BGRA32. if (outDesc.Format == inDesc.Format) { @@ -929,7 +925,6 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample, [&]() -> void { hr = mTransform->Output(&sample); }); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); } - perfRecorder.End(); } if (!mutex && mDevice != DeviceManagerDx::Get()->GetCompositorDevice() && diff --git a/dom/media/utils/PerformanceRecorder.cpp b/dom/media/utils/PerformanceRecorder.cpp deleted file mode 100644 index 162d22cc3f36..000000000000 --- a/dom/media/utils/PerformanceRecorder.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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 "PerformanceRecorder.h" - -#include "mozilla/Logging.h" -#include "mozilla/ProfilerMarkers.h" -#include "nsString.h" - -namespace mozilla { - -const char* StageToStr(PerformanceRecorder::Stage aStage) { - switch (aStage) { - case PerformanceRecorder::Stage::RequestData: - return "RequestData"; - case PerformanceRecorder::Stage::RequestDemux: - return "RequestDemux"; - case PerformanceRecorder::Stage::CopyDemuxedData: - return "CopyDemuxedData"; - case PerformanceRecorder::Stage::RequestDecode: - return "RequestDecode"; - case PerformanceRecorder::Stage::CopyDecodedVideo: - return "CopyDecodedVideo"; - default: - return "InvalidStage"; - } -} - -/* static */ -const char* PerformanceRecorder::FindMediaResolution(int32_t aHeight) { - static const struct { - const int32_t mH; - const nsCString mRes; - } sResolutions[] = {{0, "A:0"_ns}, // other followings are for video - {240, "V:02160"_ns}}; - const char* resolution = sResolutions[0].mRes.get(); - for (auto&& res : sResolutions) { - if (aHeight <= res.mH) { - resolution = res.mRes.get(); - break; - } - } - return resolution; -} - -/* static */ -bool PerformanceRecorder::IsMeasurementEnabled() { - return profiler_can_accept_markers() || - PerformanceRecorder::sEnableMeasurementForTesting; -} - -/* static */ -TimeStamp PerformanceRecorder::GetCurrentTimeForMeasurement() { - // The system call to get the clock is rather expensive on Windows. As we - // only report the measurement report via markers, if the marker isn't enabled - // then we won't do any measurement in order to save CPU time. - return IsMeasurementEnabled() ? TimeStamp::Now() : TimeStamp(); -} - -void PerformanceRecorder::Start() { - MOZ_ASSERT(mStage != Stage::Invalid); - MOZ_ASSERT(!mStartTime); - mStartTime = Some(GetCurrentTimeForMeasurement()); -} - -void PerformanceRecorder::Reset() { - mStartTime.reset(); - mStage = Stage::Invalid; -} - -void AppendMediaInfoFlagToName(nsCString& aName, MediaInfoFlag aFlag) { - if (aFlag & MediaInfoFlag::KeyFrame) { - aName.Append("kf,"); - } - // Decoding - if (aFlag & MediaInfoFlag::SoftwareDecoding) { - aName.Append("sw,"); - } else if (aFlag & MediaInfoFlag::HardwareDecoding) { - aName.Append("hw,"); - } - // Codec type - if (aFlag & MediaInfoFlag::VIDEO_AV1) { - aName.Append("av1,"); - } else if (aFlag & MediaInfoFlag::VIDEO_H264) { - aName.Append("h264,"); - } else if (aFlag & MediaInfoFlag::VIDEO_VP8) { - aName.Append("vp8,"); - } else if (aFlag & MediaInfoFlag::VIDEO_VP9) { - aName.Append("vp9,"); - } -} - -float PerformanceRecorder::End() { - double elapsedTimeUs = 0.0; - if (mStartTime && !mStartTime->IsNull()) { - MOZ_ASSERT(mStage != Stage::Invalid); - if (IsMeasurementEnabled()) { - const auto now = TimeStamp::Now(); - elapsedTimeUs = (now - *mStartTime).ToMicroseconds(); - MOZ_ASSERT(elapsedTimeUs >= 0, "Elapsed time can't be less than 0!"); - nsAutoCString name(StageToStr(mStage)); - name.Append(":"); - name.Append(FindMediaResolution(mHeight)); - name.Append(":"); - AppendMediaInfoFlagToName(name, mFlag); - PROFILER_MARKER_UNTYPED( - name, MEDIA_PLAYBACK, - MarkerOptions(MarkerTiming::Interval(*mStartTime, now))); - } - Reset(); - } - return elapsedTimeUs; -} - -} // namespace mozilla diff --git a/dom/media/utils/PerformanceRecorder.h b/dom/media/utils/PerformanceRecorder.h deleted file mode 100644 index d6495dffbba3..000000000000 --- a/dom/media/utils/PerformanceRecorder.h +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=8 et ft=cpp : */ -/* 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/. */ - -#ifndef mozilla_PerformanceRecorder_h -#define mozilla_PerformanceRecorder_h - -#include "mozilla/Attributes.h" -#include "mozilla/Maybe.h" -#include "mozilla/TimeStamp.h" -#include "mozilla/TypedEnumBits.h" -#include "nsStringFwd.h" - -namespace mozilla { - -enum class MediaInfoFlag : uint16_t { - None = (0 << 0), - NonKeyFrame = (1 << 0), - KeyFrame = (1 << 1), - SoftwareDecoding = (1 << 2), - HardwareDecoding = (1 << 3), - VIDEO_AV1 = (1 << 4), - VIDEO_H264 = (1 << 5), - VIDEO_VP8 = (1 << 6), - VIDEO_VP9 = (1 << 7), -}; -MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaInfoFlag) - -/** - * This class is used to record the passed time on the different stages in the - * media playback pipeline. It needs to call `Start()` and `End()` explicitly - * in order to record the passed time between these two calls. - */ -class PerformanceRecorder { - public: - /** - * This represents the different stages that a media data will go through - * within the playback journey. - * - * |---| |---| |------| - * Copy Demuxed Copy Demuxed Copy Decoded - * Data Data Video - * |------------- | |-----------------------------------| - * Request Demux Request Decode - * |-----------------------------------------------------------| - * Request Data - * - * RequestData : Record the time where MediaDecoderStateMachine(MDSM) starts - * asking for a decoded data to MDSM receives a decoded data. - * - * RequestDemux : Record the time where MediaFormatReader(MFR) starts asking - * a demuxed sample to MFR received a demuxed sample. This stage is a sub- - * stage of RequestData. - * - * CopyDemuxedData : On some situations, we will need to copy the demuxed - * data, which is still not decoded yet so its size is still small. This - * records the time which we spend on copying data. This stage could happen - * multiple times, either being a sub-stage of RequestDemux (in MSE case), or - * being a sub-stage of RequestDecode (when sending data via IPC). - * - * RequestDecode : Record the time where MFR starts asking decoder to return - * a decoded data to MFR receives a decoded data. As the decoder might be - * remote, this stage might include the time spending on IPC trips. This stage - * is a sub-stage of RequestData. - * - * CopyDecodedVideo : If we can't reuse same decoder texture to the - * compositor, then we have to copy video data to to another sharable texture. - * This records the time which we spend on copying data. This stage is a sub- - * stage of RequestDecode. - */ - enum class Stage : uint8_t { - Invalid, - RequestData, - RequestDemux, - CopyDemuxedData, - RequestDecode, - CopyDecodedVideo, - }; - - explicit PerformanceRecorder(Stage aStage, int32_t aHeight = 0, - MediaInfoFlag aFlag = MediaInfoFlag::None) - : mStage(aStage), mHeight(aHeight), mFlag(aFlag) {} - ~PerformanceRecorder() = default; - - PerformanceRecorder(PerformanceRecorder&& aRhs) noexcept { - mStage = aRhs.mStage; - mHeight = aRhs.mHeight; - mStartTime = std::move(aRhs.mStartTime); - mFlag = aRhs.mFlag; - aRhs.mStage = Stage::Invalid; - } - - PerformanceRecorder& operator=(PerformanceRecorder&& aRhs) noexcept { - MOZ_ASSERT(&aRhs != this, "self-moves are prohibited"); - mStage = aRhs.mStage; - mHeight = aRhs.mHeight; - mStartTime = std::move(aRhs.mStartTime); - mFlag = aRhs.mFlag; - aRhs.mStage = Stage::Invalid; - return *this; - } - - PerformanceRecorder(const PerformanceRecorder&) = delete; - PerformanceRecorder& operator=(const PerformanceRecorder&) = delete; - - void Start(); - - // Return the passed time if it has started and still valid. Otherwise, - // return 0. - float End(); - - protected: - void Reset(); - - static bool IsMeasurementEnabled(); - static TimeStamp GetCurrentTimeForMeasurement(); - - // Return the resolution range for the given height. Eg. V:1080 mStartTime; - - // We would enable the measurement on testing. - static inline bool sEnableMeasurementForTesting = false; -}; - -} // namespace mozilla - -#endif // mozilla_PerformanceRecorder_h diff --git a/dom/media/utils/gtest/TestPerformanceRecorder.cpp b/dom/media/utils/gtest/TestPerformanceRecorder.cpp deleted file mode 100644 index 943d62e702e4..000000000000 --- a/dom/media/utils/gtest/TestPerformanceRecorder.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* 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 -#include - -#include "PerformanceRecorder.h" -#include "gtest/gtest.h" -#include "nsString.h" - -using Stage = mozilla::PerformanceRecorder::Stage; - -class PerformanceRecorderWrapper : public mozilla::PerformanceRecorder { - public: - PerformanceRecorderWrapper(Stage aStage, int32_t aHeight) - : PerformanceRecorder(aStage, aHeight) {} - - const char* Resolution() const { return FindMediaResolution(mHeight); } - - static void EnableMeasurementOnNonMarkerSituation() { - sEnableMeasurementForTesting = true; - } -}; - -TEST(PerformanceRecorder, TestResolution) -{ - static const struct { - const int32_t mH; - const char* mRes; - } resolutions[] = {{0, "A:0"}, - {240, "V:02160"}}; - - const Stage stage = Stage::RequestDecode; - for (auto&& res : resolutions) { - PerformanceRecorderWrapper w(stage, res.mH); - ASSERT_STREQ(w.Resolution(), res.mRes); - } -} - -TEST(PerformanceRecorder, TestMoveOperation) -{ - PerformanceRecorderWrapper::EnableMeasurementOnNonMarkerSituation(); - - const Stage stage = Stage::RequestDecode; - const uint32_t resolution = 1080; - PerformanceRecorderWrapper w1(stage, resolution); - w1.Start(); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - // w1 has been moved which won't continue measuring data. - PerformanceRecorderWrapper w2(std::move(w1)); - ASSERT_DOUBLE_EQ(w1.End(), 0.0); - ASSERT_TRUE(w2.End() > 0.0); -} diff --git a/dom/media/utils/gtest/moz.build b/dom/media/utils/gtest/moz.build deleted file mode 100644 index 8486f52f738a..000000000000 --- a/dom/media/utils/gtest/moz.build +++ /dev/null @@ -1,18 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -UNIFIED_SOURCES += [ - "TestPerformanceRecorder.cpp", -] - -LOCAL_INCLUDES += [ - "/dom/media/utils", -] - -FINAL_LIBRARY = "xul-gtest" - -if CONFIG["CC_TYPE"] in ("clang", "gcc"): - CXXFLAGS += ["-Wno-error=shadow"] diff --git a/dom/media/utils/moz.build b/dom/media/utils/moz.build index cc91c79c6477..4bb2ee70e71a 100644 --- a/dom/media/utils/moz.build +++ b/dom/media/utils/moz.build @@ -8,17 +8,12 @@ with Files("test/**"): EXPORTS += [ "MediaElementEventRunners.h", - "PerformanceRecorder.h", "TelemetryProbesReporter.h", ] UNIFIED_SOURCES += [ "MediaElementEventRunners.cpp", - "PerformanceRecorder.cpp", "TelemetryProbesReporter.cpp", ] -if CONFIG["ENABLE_TESTS"]: - DIRS += ["gtest"] - FINAL_LIBRARY = "xul"