[EMSS] Fix validating video config with capabilities returned by platform 20/320920/5
authorPiotr Bałut <p.balut@samsung.com>
Tue, 12 Nov 2024 14:19:06 +0000 (15:19 +0100)
committerBot Blink <blinkbot@samsung.com>
Mon, 25 Nov 2024 16:31:38 +0000 (16:31 +0000)
[PROBLEM]
Platform capabilities are stored in two places: one of them checks
hardware capabilities in the context of resolution + fps and
requirement of video texture support. The other one verfies what
TTvd assumes to be supported in the context of video codec profile
and resolution range; the latter was not checked.

[SOLUTION]
Video capabilities are now checked using both sourecs of truth
regarding what platform supports (please note both methods should
probably be merged eventually, however currently this issue is
fixed for WASM Player in EMSS code, as it's the affected component).

Bug: https://jira-eu.sec.samsung.net/browse/VDWASM-1922
Signed-off-by: Piotr Bałut <p.balut@samsung.com>
Change-Id: I3d62dbb6b8bb09eabdd35acdcb9ae9d99bc149dd

tizen_src/chromium_impl/content/renderer/media/tizen/elementary_media_stream_source/common/codec_capabilities.cc
tizen_src/chromium_impl/third_party/blink/renderer/modules/elementary_media_stream_source/elementary_media_track.cc

index f017d7a661f3b97f0b7535fbf41984c4609f5ca7..045352c80a8ee181335beae715d2a9d5e3fedc98 100644 (file)
@@ -4,11 +4,14 @@
 
 #include "tizen_src/chromium_impl/content/renderer/media/tizen/elementary_media_stream_source/common/codec_capabilities.h"
 
+#include <algorithm>
+#include <optional>
 #include <tuple>
 #include <vector>
 
 #include "content/renderer/media/tizen/elementary_media_stream_source/common/logger.h"
 #include "media/base/tizen/video_capabilities.h"
+#include "media/filters/tizen/video_decoding_capabilities.h"
 
 namespace content::elementary_media_stream_source {
 
@@ -28,6 +31,30 @@ constexpr std::array<VideoCapabilityTuple, 5>
         {media::VideoCodec::kVP9, {{3840, 2160}, 60}},
     }};
 
+std::optional<gfx::Size> GetResolutionClipForCapabilities(
+    media::VideoCodecProfile profile,
+    const gfx::Size& resolution,
+    const media::SupportedVideoDecoderConfigs& decoder_capabilities) {
+  for (const auto& decoder_capability : decoder_capabilities) {
+    if (profile < decoder_capability.profile_min ||
+        profile > decoder_capability.profile_max) {
+      continue;
+    }
+    if (resolution.width() > decoder_capability.coded_size_max.width() ||
+        resolution.height() > decoder_capability.coded_size_max.height()) {
+      // Profile was found, but decoder reports resolution is lower than what
+      // was estimated based on resource manager info. Resolution should be
+      // clipped.
+      return {{decoder_capability.coded_size_max.width(),
+               decoder_capability.coded_size_max.height()}};
+    }
+    // Profile was found and decoder agrees with rm info, no need to clip.
+    return std::nullopt;
+  }
+  // Profile was not found, clip resolution to 0 to reject any potential config.
+  return {{0, 0}};
+}
+
 }  // anonymous namespace
 
 std::vector<media::VideoCapability> GetVideoCapabilities(
@@ -57,7 +84,37 @@ std::vector<media::VideoCapability> GetVideoCapabilities(
   const auto media_player_mode = player_mode == PlayerMode::kDecodeToTexture
                                      ? media::PlaybackMode::kVideoDecoder
                                      : media::PlaybackMode::kPlayer;
-  return media::GetVideoCapabilities(codec, profile, media_player_mode);
+  auto capabilities =
+      media::GetVideoCapabilities(codec, profile, media_player_mode);
+
+  // FIXME(vdwasm): There are two sources of truth regarding supported configs:
+  // * media::GetVideoCapabilities(...) in video_capabilities.h which answers
+  //   whether or not hardware supports given config, which additionally takes
+  //   into account video texture support preference.
+  // * media::GetVideoCapabilities() in video_decoding_capabilities.h which
+  //   answers whether or not TTvd decoder declares support for a given
+  //   configuration. This does not account for video texture support preference
+  // Unfortunately getting a correct answer regarding config support requires
+  // querying both sources. Those should be unified in the future...
+  const auto& decoder_capabilities = media::GetVideoCapabilities();
+  for (auto& capability : capabilities) {
+    if (auto clipped_resolution = GetResolutionClipForCapabilities(
+            profile, capability.max_resolution, decoder_capabilities)) {
+      EMSS_DEBUG_NO_INSTANCE()
+          << "Clipping capability for " << media::GetProfileName(profile)
+          << "; fps: " << capability.max_framerate
+          << ", resolution: " << capability.max_resolution.ToString() << " -> "
+          << clipped_resolution->ToString();
+      capability.max_resolution = *clipped_resolution;
+    } else {
+      EMSS_VERBOSE_NO_INSTANCE()
+          << "Discovered capability for " << media::GetProfileName(profile)
+          << "; fps: " << capability.max_framerate
+          << ", resolution: " << capability.max_resolution.ToString();
+    }
+  };
+
+  return capabilities;
 }
 
 }  // namespace content::elementary_media_stream_source
index acc05bcd7ee53974d426d3ae38e399283e798a6a..b97acaf411df4c9ff14f413c659e5bf92bbda966 100644 (file)
@@ -432,28 +432,6 @@ ConfigVerificationResult VerifyVideoCodecParameters(
     bool is_software_decoder) {
   EMSS_VERBOSE_NO_INSTANCE();
 
-  {
-    // clang-format off
-    static const base::NoDestructor<std::unordered_set<VideoCodec>> kSpportedPlatformCodecs {std::unordered_set<VideoCodec>{
-#if BUILDFLAG(ENABLE_AV1_DECODER)
-      VideoCodec::kAV1,
-#endif
-      VideoCodec::kH264,
-#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
-      VideoCodec::kHEVC,
-#endif
-      VideoCodec::kMPEG2,
-      VideoCodec::kVP8,
-      VideoCodec::kVP9,}
-    };
-    // clang-format on
-
-    if (!kSpportedPlatformCodecs->count(codec)) {
-      EMSS_LOG_NO_INSTANCE(WARNING) << "Unsupported video codec: " << codec;
-      return ConfigVerificationResult::kInvalidCodec;
-    }
-  }
-
   const auto deocder_selection_policy =
       is_software_decoder ? media::DecoderSelectionPolicy::kSoftware
                           : media::DecoderSelectionPolicy::kHardware;