[M120 Migration] Support Dash high bitrate 48/306948/8
authoryangzhiwen <zw714.yang@samsung.com>
Thu, 29 Feb 2024 06:40:01 +0000 (14:40 +0800)
committerBot Blink <blinkbot@samsung.com>
Mon, 4 Mar 2024 07:32:36 +0000 (07:32 +0000)
void ewk_media_start_with_high_bit_rate(Evas_Object* ewkView, Eina_Bool high_bitrate)
This API was added so that Dash streams can support Dash high bitrate.
Process the URL of the video.

migrate from:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/292658/

Change-Id: Ic452e289854b7efbca6ccb958f8a8f68eca3e7b2
Signed-off-by: yangzhiwen <zw714.yang@samsung.com>
13 files changed:
content/public/browser/web_contents_delegate.h
tizen_src/chromium_impl/content/browser/media/tizen_renderer_impl.cc
tizen_src/chromium_impl/content/browser/media/tizen_renderer_impl.h
tizen_src/chromium_impl/media/base/efl/media_player_util_efl.h
tizen_src/chromium_impl/media/filters/media_player_bridge_capi_tv.cc
tizen_src/chromium_impl/media/filters/media_player_bridge_capi_tv.h
tizen_src/chromium_impl/media/filters/media_player_tizen.h
tizen_src/chromium_impl/media/filters/media_player_tizen_client.h
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/public/ewk_view.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h

index e7cdfd4..3798652 100644 (file)
@@ -739,7 +739,9 @@ class CONTENT_EXPORT WebContentsDelegate {
   virtual void NotifyMediaStateChanged(uint32_t type,
                                        uint32_t previous,
                                        uint32_t current) {};
+  virtual bool IsHighBitRate() const { return false; }
 #endif
+
 #if BUILDFLAG(IS_ANDROID)
   // Updates information to determine whether a user gesture should carryover to
   // future navigations. This is needed so navigations within a certain
index e3bfcf1..e380885 100644 (file)
@@ -361,6 +361,18 @@ void TizenRendererImpl::Suspend() {
   is_suspended_ = true;
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+content::WebContentsDelegate* TizenRendererImpl::GetWebContentsDelegate()
+    const {
+  content::WebContents* web_contents = GetWebContents();
+  if (!web_contents) {
+    LOG(ERROR) << "web_contents is nullptr";
+    return nullptr;
+  }
+  return web_contents->GetDelegate();
+}
+#endif
+
 void TizenRendererImpl::ToggleFullscreenMode(bool is_fullscreen,
                                              ToggledFullscreenCB cb) {
   if (media_player_)
index 13af303..bac0971 100644 (file)
@@ -128,6 +128,10 @@ class CONTENT_EXPORT TizenRendererImpl
                            uint32_t height) override;
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  content::WebContentsDelegate* GetWebContentsDelegate() const override;
+#endif
+
 #if defined(TIZEN_VIDEO_HOLE)
   void SetVideoHole(bool is_video_hole) final;
   void SetMediaGeometry(const gfx::RectF& rect) final;
index 2f74670..00cd6dd 100644 (file)
 #include "media/base/media_export.h"
 #include "url/gurl.h"
 
+#define BLINKFREE(p) \
+  do {               \
+    if (p) {         \
+      delete[] p;    \
+      p = 0;         \
+    }                \
+  } while (0)
+
 namespace media {
 
 struct MediaFormatDeleter {
index 7cfb666..1a05845 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "media/filters/media_player_bridge_capi_tv.h"
 
+#include "media/base/efl/media_player_util_efl.h"
 #include "tizen_src/chromium_impl/media/filters/media_player_tizen_client.h"
 
 namespace {
@@ -31,6 +32,8 @@ void MediaPlayerBridgeCapiTV::SetContentMimeType(const std::string& mime_type) {
 }
 
 void MediaPlayerBridgeCapiTV::Prepare() {
+  if (blink::IsHbbTV() && CheckHighBitRate() && stream_type_ == DASH_STREAM)
+    AppendUrlHighBitRate(url_.spec());
   MediaPlayerBridgeCapi::Prepare();
 }
 
@@ -172,4 +175,38 @@ bool MediaPlayerBridgeCapiTV::GetLiveStreamingDuration(int64_t* min,
   return true;
 }
 
+void MediaPlayerBridgeCapiTV::AppendUrlHighBitRate(const std::string& url) {
+  // don't use url.append("|STARTBITRATE=HIGHEST") to get hbbtv url
+  // "|" will be replaced with "%7C"
+  const char high_bitrate[] = "|STARTBITRATE=HIGHEST";
+  int len = url.length() + strlen(high_bitrate) + 1;
+  char* str_url = new char[len];
+  if (!str_url) {
+    return;
+  }
+
+  memset(str_url, 0, len);
+  strncat(str_url, url.c_str(), url.length());
+  strncat(str_url, high_bitrate, strlen(high_bitrate));
+  hbbtv_url_ = str_url;
+  BLINKFREE(str_url);
+  LOG(INFO) << "hbbtv url:" << hbbtv_url_.c_str();
+}
+
+bool MediaPlayerBridgeCapiTV::CheckHighBitRate() {
+  if (!GetMediaPlayerClient()) {
+    LOG(ERROR) << "MediaPlayerClient is null";
+    return false;
+  }
+  content::WebContentsDelegate* web_contents_delegate =
+      GetMediaPlayerClient()->GetWebContentsDelegate();
+  if (!web_contents_delegate) {
+    LOG(ERROR) << "get web_contents_delegate fail";
+    return false;
+  }
+  bool ret = web_contents_delegate->IsHighBitRate();
+  LOG(INFO) << "get high bit rate: " << std::boolalpha << ret;
+  return ret;
+}
+
 }  // namespace media
index b6c5a16..eeeba28 100644 (file)
 
 namespace media {
 
+enum StreamType {
+  HLS_STREAM = 0,
+  DASH_STREAM,
+  TS_STREAM,
+  OTHER_STREAM,
+};
+
 // This class is focus on HBBTV/HLS feature on Tizen TV.
 class MEDIA_EXPORT MediaPlayerBridgeCapiTV : public MediaPlayerBridgeCapi {
  public:
@@ -24,6 +31,8 @@ class MEDIA_EXPORT MediaPlayerBridgeCapiTV : public MediaPlayerBridgeCapi {
   void Release() override;
   void SetContentMimeType(const std::string& mime_type) override;
   void PlaybackCompleteUpdate() override;
+  void AppendUrlHighBitRate(const std::string& url);
+  bool CheckHighBitRate();
 
  protected:
   void PlayerPrepared() override;
@@ -36,6 +45,8 @@ class MEDIA_EXPORT MediaPlayerBridgeCapiTV : public MediaPlayerBridgeCapi {
   void UpdateSeekableTime();
   bool GetLiveStreamingDuration(int64_t* min, int64_t* max);
 
+  StreamType stream_type_{OTHER_STREAM};
+  std::string hbbtv_url_{""};  // url_ + HIGHBITRATE(if mpd)
   std::string mime_type_ = "";
   bool is_live_stream_ = false;
 
index defac69..c097ec1 100644 (file)
@@ -9,6 +9,7 @@
 #include "base/task/single_thread_task_runner.h"
 #include "media/base/demuxer_stream.h"
 #include "media/filters/flags.h"
+#include "third_party/blink/public/platform/web_application_type.h"
 #include "ui/gfx/geometry/rect_f.h"
 #include "ui/gfx/tbm_buffer_handle.h"
 
@@ -71,6 +72,7 @@ class MEDIA_EXPORT MediaPlayerTizen {
   virtual void SetVolume(double volume) = 0;
   virtual base::TimeDelta GetCurrentTime() = 0;
 
+  virtual MediaPlayerTizenClient* GetMediaPlayerClient() const {return nullptr;}
   virtual void ToggleFullscreenMode(bool is_fullscreen) {}
 
 #if defined(TIZEN_TBM_SUPPORT)
index d98b4d9..71cb20d 100644 (file)
@@ -5,6 +5,7 @@
 #ifndef MEDIA_FILTERS_MEDIA_PLAYER_TIZEN_CLIENT_H_
 #define MEDIA_FILTERS_MEDIA_PLAYER_TIZEN_CLIENT_H_
 
+#include "content/public/browser/web_contents_delegate.h"
 #include "media/base/audio_decoder_config.h"
 #include "media/base/pipeline_status.h"
 #include "media/base/video_decoder_config.h"
@@ -52,6 +53,10 @@ class MEDIA_EXPORT MediaPlayerTizenClient {
                                    uint32_t width,
                                    uint32_t height) = 0;
 #endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  virtual content::WebContentsDelegate* GetWebContentsDelegate() const = 0;
+#endif
 };
 
 }  // namespace media
index 0b8b2a0..bef9a78 100644 (file)
@@ -3492,4 +3492,9 @@ void EWebView::NotifyMediaStateChanged(uint32_t device_type,
 
   delete user_media_state_info;
 }
+
+void EWebView::SetHighBitRate(Eina_Bool high_bitrate) {
+  LOG(INFO) << "high_bitrate: " << std::boolalpha << high_bitrate;
+  is_high_bitrate_ = high_bitrate;
+}
 #endif
index 9900db5..1662c18 100644 (file)
@@ -744,6 +744,8 @@ class EWebView {
   void NotifyMediaStateChanged(uint32_t type,
                                uint32_t previous,
                                uint32_t current);
+  void SetHighBitRate(Eina_Bool is_high_bitrate);
+  bool IsHighBitRate() const { return is_high_bitrate_; }
 #endif  // IS_TIZEN_TV
 
   void SetDidChangeThemeColorCallback(
@@ -940,6 +942,7 @@ class EWebView {
   bool use_early_rwi_;
   bool rwi_info_showed_;
   GURL rwi_gurl_;
+  bool is_high_bitrate_ = false;
 
   base::OnceClosure pending_setfocus_closure_;
 #endif
index 10b1b1a..27c36b5 100644 (file)
@@ -1732,9 +1732,14 @@ void ewk_media_set_parental_rating_result(Evas_Object* ewkView, const char* url,
   LOG_EWK_API_MOCKUP();
 }
 
-void ewk_media_start_with_high_bit_rate(Evas_Object* ewkView, Eina_Bool is_high_bitrate)
+void ewk_media_start_with_high_bit_rate(Evas_Object* ewkView, Eina_Bool high_bitrate)
 {
-  LOG_EWK_API_MOCKUP();
+#if BUILDFLAG(IS_TIZEN_TV)
+  EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
+  impl->SetHighBitRate(high_bitrate);
+#else
+  LOG_EWK_API_MOCKUP("Only for Tizen TV.");
+#endif
 }
 
 double ewk_view_media_current_time_get(const Evas_Object *o)
index ad3d799..18fb985 100644 (file)
@@ -778,5 +778,9 @@ void WebContentsDelegateEfl::DidEdgeScrollBy(const gfx::Point& offset,
   if (web_view_)
     web_view_->InvokeEdgeScrollByCallback(offset, handled);
 }
+
+bool WebContentsDelegateEfl::IsHighBitRate() const {
+  return web_view_ ? web_view_->IsHighBitRate() : false;
+}
 #endif
 }  // namespace content
index 5d0a080..9eca28d 100644 (file)
@@ -141,6 +141,7 @@ class WebContentsDelegateEfl : public WebContentsDelegate {
   void NotifyMediaStateChanged(uint32_t type,
                                uint32_t previous,
                                uint32_t current) override;
+  bool IsHighBitRate() const override;
 #endif
 
 #if defined(TIZEN_AUTOFILL)