summaryrefslogtreecommitdiffstats
path: root/dom/media/utils/PerformanceRecorder.h
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/utils/PerformanceRecorder.h')
-rw-r--r--dom/media/utils/PerformanceRecorder.h56
1 files changed, 41 insertions, 15 deletions
diff --git a/dom/media/utils/PerformanceRecorder.h b/dom/media/utils/PerformanceRecorder.h
index e423c3fb5d..95fdab90ba 100644
--- a/dom/media/utils/PerformanceRecorder.h
+++ b/dom/media/utils/PerformanceRecorder.h
@@ -8,11 +8,13 @@
#define mozilla_PerformanceRecorder_h
#include <type_traits>
+#include <utility>
#include "mozilla/Attributes.h"
#include "mozilla/BaseProfilerMarkersPrerequisites.h"
#include "mozilla/Maybe.h"
#include "mozilla/Mutex.h"
+#include "mozilla/ProfilerMarkerTypes.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/TypedEnumBits.h"
#include "nsStringFwd.h"
@@ -118,7 +120,19 @@ enum class MediaStage : uint8_t {
CopyDecodedVideo,
};
-class PlaybackStage {
+class StageBase {
+ public:
+ virtual void AddMarker(MarkerOptions&& aOption) {
+ profiler_add_marker(Name(), Category(),
+ std::forward<MarkerOptions&&>(aOption));
+ }
+
+ protected:
+ virtual ProfilerString8View Name() const = 0;
+ virtual const MarkerCategory& Category() const = 0;
+};
+
+class PlaybackStage : public StageBase {
public:
explicit PlaybackStage(MediaStage aStage, int32_t aHeight = 0,
MediaInfoFlag aFlag = MediaInfoFlag::None)
@@ -126,20 +140,28 @@ class PlaybackStage {
MOZ_ASSERT(aStage != MediaStage::Invalid);
}
- ProfilerString8View Name() const;
- const MarkerCategory& Category() const {
+ ProfilerString8View Name() const override;
+ const MarkerCategory& Category() const override {
return baseprofiler::category::MEDIA_PLAYBACK;
}
+ void AddMarker(MarkerOptions&& aOption) override;
+
+ void SetStartTimeAndEndTime(uint64_t aStartTime, uint64_t aEndTime) {
+ mStartAndEndTimeUs =
+ Some(std::pair<uint64_t, uint64_t>{aStartTime, aEndTime});
+ }
MediaStage mStage;
int32_t mHeight;
MediaInfoFlag mFlag;
+ Maybe<std::pair<uint64_t, uint64_t>> mStartAndEndTimeUs;
+
private:
mutable Maybe<nsCString> mName;
};
-class CaptureStage {
+class CaptureStage : public StageBase {
public:
enum class ImageType : uint8_t {
Unknown,
@@ -160,8 +182,8 @@ class CaptureStage {
mHeight(aHeight),
mImageType(aImageType) {}
- ProfilerString8View Name() const;
- const MarkerCategory& Category() const {
+ ProfilerString8View Name() const override;
+ const MarkerCategory& Category() const override {
return baseprofiler::category::MEDIA_RT;
}
@@ -175,7 +197,7 @@ class CaptureStage {
mutable Maybe<nsCString> mName;
};
-class CopyVideoStage {
+class CopyVideoStage : public StageBase {
public:
CopyVideoStage(nsCString aSource, TrackingId aTrackingId, int32_t aWidth,
int32_t aHeight)
@@ -184,8 +206,8 @@ class CopyVideoStage {
mWidth(aWidth),
mHeight(aHeight) {}
- ProfilerString8View Name() const;
- const MarkerCategory& Category() const {
+ ProfilerString8View Name() const override;
+ const MarkerCategory& Category() const override {
return baseprofiler::category::MEDIA_RT;
}
@@ -201,7 +223,7 @@ class CopyVideoStage {
mutable Maybe<nsCString> mName;
};
-class DecodeStage {
+class DecodeStage : public StageBase {
public:
enum ImageFormat : uint8_t {
YUV420P,
@@ -223,8 +245,8 @@ class DecodeStage {
: mSource(std::move(aSource)),
mTrackingId(std::move(aTrackingId)),
mFlag(aFlag) {}
- ProfilerString8View Name() const;
- const MarkerCategory& Category() const {
+ ProfilerString8View Name() const override;
+ const MarkerCategory& Category() const override {
return baseprofiler::category::MEDIA_PLAYBACK;
}
@@ -242,6 +264,11 @@ class DecodeStage {
void SetColorDepth(gfx::ColorDepth aColorDepth) {
mColorDepth = Some(aColorDepth);
}
+ void SetStartTimeAndEndTime(uint64_t aStartTime, uint64_t aEndTime) {
+ mStartAndEndTimeUs =
+ Some(std::pair<uint64_t, uint64_t>{aStartTime, aEndTime});
+ }
+ void AddMarker(MarkerOptions&& aOption) override;
// The name of the source that performs this stage.
nsCString mSource;
@@ -256,6 +283,7 @@ class DecodeStage {
Maybe<gfx::ColorRange> mColorRange;
Maybe<gfx::ColorDepth> mColorDepth;
mutable Maybe<nsCString> mName;
+ Maybe<std::pair<uint64_t, uint64_t>> mStartAndEndTimeUs;
};
class PerformanceRecorderBase {
@@ -325,9 +353,7 @@ class PerformanceRecorderImpl : public PerformanceRecorderBase {
MOZ_ASSERT(elapsedTimeUs >= 0, "Elapsed time can't be less than 0!");
aStageMutator(stage);
AUTO_PROFILER_STATS(PROFILER_MARKER_UNTYPED);
- profiler_add_marker(
- stage.Name(), stage.Category(),
- MarkerOptions(MarkerTiming::Interval(startTime, now)));
+ stage.AddMarker(MarkerOptions(MarkerTiming::Interval(startTime, now)));
}
return static_cast<float>(elapsedTimeUs);
}