[go: nahoru, domu]

Add metrics for video chroma subsampling formats.

This adds UMA metrics for decoding requests to platform decoders with
different chroma subsampling formats, even some of the formats may be
rejected by the platform decoder.

Bug: 1348712
Change-Id: I4aac5b6f2af638c9930804f864540878e8276174
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3817231
Reviewed-by: Evan Liu <evliu@google.com>
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Commit-Queue: Jianlin Qiu <jianlin.qiu@intel.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1036438}
diff --git a/media/gpu/vp9_decoder.cc b/media/gpu/vp9_decoder.cc
index 60328ee..fbac517 100644
--- a/media/gpu/vp9_decoder.cc
+++ b/media/gpu/vp9_decoder.cc
@@ -9,6 +9,7 @@
 #include "base/bind.h"
 #include "base/feature_list.h"
 #include "base/logging.h"
+#include "base/metrics/histogram_functions.h"
 #include "build/build_config.h"
 #include "build/chromeos_buildflags.h"
 #include "media/base/limits.h"
@@ -85,9 +86,20 @@
   }
 }
 
-bool IsYUV420Sequence(const Vp9FrameHeader& frame_header) {
-  // Spec 7.2.2
-  return frame_header.subsampling_x == 1u && frame_header.subsampling_y == 1u;
+VideoChromaSampling GetVP9ChromaSampling(const Vp9FrameHeader& frame_header) {
+  // Spec section 7.2.2
+  uint8_t subsampling_x = frame_header.subsampling_x;
+  uint8_t subsampling_y = frame_header.subsampling_y;
+  if (subsampling_x == 0 && subsampling_y == 0) {
+    return VideoChromaSampling::k444;
+  } else if (subsampling_x == 1u && subsampling_y == 0u) {
+    return VideoChromaSampling::k422;
+  } else if (subsampling_x == 1u && subsampling_y == 1u) {
+    return VideoChromaSampling::k420;
+  } else {
+    DLOG(WARNING) << "Unknown chroma sampling format.";
+    return VideoChromaSampling::kUnknown;
+  }
 }
 }  // namespace
 
@@ -265,7 +277,15 @@
                << ", profile=" << GetProfileName(new_profile);
       return kDecodeError;
     }
-    if (!IsYUV420Sequence(*curr_frame_hdr_)) {
+    VideoChromaSampling new_chroma_sampling =
+        GetVP9ChromaSampling(*curr_frame_hdr_);
+    if (new_chroma_sampling != chroma_sampling_) {
+      chroma_sampling_ = new_chroma_sampling;
+      base::UmaHistogramEnumeration(
+          "Media.PlatformVideoDecoding.ChromaSampling", chroma_sampling_);
+    }
+
+    if (chroma_sampling_ != VideoChromaSampling::k420) {
       DVLOG(1) << "Only YUV 4:2:0 is supported";
       return kDecodeError;
     }
@@ -409,9 +429,7 @@
 }
 
 VideoChromaSampling VP9Decoder::GetChromaSampling() const {
-  // VP9 decoder currently does not rely on chroma sampling format for
-  // creating/reconfiguring decoder, so return an unknown format.
-  return VideoChromaSampling::kUnknown;
+  return chroma_sampling_;
 }
 
 size_t VP9Decoder::GetRequiredNumOfPictures() const {