diff --git a/devtools/client/performance-new/popup/background.jsm.js b/devtools/client/performance-new/popup/background.jsm.js index 2fcd51e99923..a0a5f0c75a1d 100644 --- a/devtools/client/performance-new/popup/background.jsm.js +++ b/devtools/client/performance-new/popup/background.jsm.js @@ -160,6 +160,7 @@ const presets = { "ModuleProcessThread", "NativeAudioCallback", "PacerThread", + "RemVidChild", "RenderBackend", "Renderer", "SwComposite", diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 20b5140b9793..ef7a6d40848d 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -11,14 +11,17 @@ #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" @@ -1887,8 +1890,25 @@ void MediaFormatReader::DecodeDemuxedSamples(TrackType aTrack, 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); + height, flag); perfRecorder.Start(); decoder.mDecoder->Decode(aSample) ->Then( diff --git a/dom/media/utils/PerformanceRecorder.cpp b/dom/media/utils/PerformanceRecorder.cpp index d87f0f861fb5..1ce470921759 100644 --- a/dom/media/utils/PerformanceRecorder.cpp +++ b/dom/media/utils/PerformanceRecorder.cpp @@ -7,6 +7,7 @@ #include "PerformanceRecorder.h" #include "mozilla/Logging.h" +#include "mozilla/ProfilerMarkers.h" #include "nsString.h" namespace mozilla { @@ -51,10 +52,17 @@ const char* FindMediaResolution(int32_t aHeight) { return resolution; } +static TimeStamp 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 profiler_can_accept_markers() ? TimeStamp::Now() : TimeStamp(); +} + void PerformanceRecorder::Start() { MOZ_ASSERT(mStage != Stage::Invalid); MOZ_ASSERT(!mStartTime); - mStartTime = Some(TimeStamp::Now()); + mStartTime = Some(GetCurrentTimeForMeasurement()); } void PerformanceRecorder::Reset() { @@ -62,13 +70,44 @@ void PerformanceRecorder::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,"); + } +} + void PerformanceRecorder::End() { - if (mStartTime) { + if (mStartTime && !mStartTime->IsNull()) { MOZ_ASSERT(mStage != Stage::Invalid); - const double passedTimeUs = - (TimeStamp::Now() - *mStartTime).ToMicroseconds(); - MOZ_ASSERT(passedTimeUs > 0, "Passed time can't be less than 0!"); - // TODO : report the time in following patches. + if (profiler_can_accept_markers()) { + const auto now = TimeStamp::Now(); + const double passedTimeUs = (now - *mStartTime).ToMicroseconds(); + MOZ_ASSERT(passedTimeUs > 0, "Passed 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(); } } diff --git a/dom/media/utils/PerformanceRecorder.h b/dom/media/utils/PerformanceRecorder.h index 7138119234b2..8ee75b630dd9 100644 --- a/dom/media/utils/PerformanceRecorder.h +++ b/dom/media/utils/PerformanceRecorder.h @@ -10,10 +10,24 @@ #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 @@ -65,14 +79,16 @@ class PerformanceRecorder { CopyDecodedVideo, }; - explicit PerformanceRecorder(Stage aStage, int32_t aHeight = 0) - : mStage(aStage), mHeight(aHeight) {} + 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; } @@ -81,6 +97,7 @@ class PerformanceRecorder { mStage = aRhs.mStage; mHeight = aRhs.mHeight; mStartTime = std::move(aRhs.mStartTime); + mFlag = aRhs.mFlag; aRhs.mStage = Stage::Invalid; return *this; } @@ -96,6 +113,7 @@ class PerformanceRecorder { Stage mStage = Stage::Invalid; int32_t mHeight; + MediaInfoFlag mFlag = MediaInfoFlag::None; Maybe mStartTime; };