1 // Copyright 2023 Samsung Electronics Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/filters/media_player_bridge_capi_tv.h"
7 #include "tizen_src/chromium_impl/media/filters/media_player_tizen_client.h"
10 const int kSeekableTimeUpdateInterval = 500;
15 MediaPlayerBridgeCapiTV::MediaPlayerBridgeCapiTV(const GURL& url,
16 const std::string& user_agent,
18 : MediaPlayerBridgeCapi(url, user_agent, volume), weak_factory_(this) {
19 LOG(INFO) << "(" << static_cast<void*>(this) << ") " << __func__;
22 MediaPlayerBridgeCapiTV::~MediaPlayerBridgeCapiTV() {
23 LOG(INFO) << "(" << static_cast<void*>(this) << ") " << __func__;
24 weak_factory_.InvalidateWeakPtrs();
27 void MediaPlayerBridgeCapiTV::SetContentMimeType(const std::string& mime_type) {
28 LOG(INFO) << "(" << static_cast<void*>(this) << ") " << __func__
29 << " mime_type : " << mime_type;
30 mime_type_ = mime_type;
33 void MediaPlayerBridgeCapiTV::Prepare() {
34 MediaPlayerBridgeCapi::Prepare();
37 void MediaPlayerBridgeCapiTV::Release() {
38 StopSeekableTimeUpdateTimer();
39 MediaPlayerBridgeCapi::Release();
42 bool MediaPlayerBridgeCapiTV::Play() {
43 if (!MediaPlayerBridgeCapi::Play())
48 void MediaPlayerBridgeCapiTV::PlaybackCompleteUpdate() {
49 MediaPlayerBridgeCapi::PlaybackCompleteUpdate();
52 void MediaPlayerBridgeCapiTV::PlayerPrepared() {
53 MediaPlayerBridgeCapi::PlayerPrepared();
55 GetAdaptiveStreamingInfo();
56 if (/*!blink::IsHbbTV() && */is_live_stream_) {
58 StartSeekableTimeUpdateTimer();
62 void MediaPlayerBridgeCapiTV::StartSeekableTimeUpdateTimer() {
63 if (!seekable_time_update_timer_.IsRunning()) {
64 seekable_time_update_timer_.Start(
65 FROM_HERE, base::Milliseconds(kSeekableTimeUpdateInterval), this,
66 &MediaPlayerBridgeCapiTV::OnSeekableTimeUpdateTimerFired);
70 void MediaPlayerBridgeCapiTV::StopSeekableTimeUpdateTimer() {
71 if (seekable_time_update_timer_.IsRunning())
72 seekable_time_update_timer_.Stop();
75 void MediaPlayerBridgeCapiTV::OnSeekableTimeUpdateTimerFired() {
79 void MediaPlayerBridgeCapiTV::GetAdaptiveStreamingInfo() {
80 int ret = player_get_adaptive_streaming_info(player_, &is_live_stream_,
81 PLAYER_ADAPTIVE_INFO_IS_LIVE);
82 if (ret != PLAYER_ERROR_NONE || is_live_stream_) {
83 LOG(INFO) << "(" << static_cast<void*>(this) << ") " << __func__
88 void MediaPlayerBridgeCapiTV::UpdateSeekableTime() {
89 if (GetPlayerState() == PLAYER_STATE_NONE || !is_live_stream_)
92 int64_t min = 0, max = 0;
93 if (GetLiveStreamingDuration(&min, &max)) {
94 if (min_seekable_time_.InMilliseconds() != min ||
95 max_seekable_time_.InMilliseconds() != max) {
96 min_seekable_time_ = base::Milliseconds(min);
97 max_seekable_time_ = base::Milliseconds(max);
98 if (GetMediaPlayerClient())
99 GetMediaPlayerClient()->OnSeekableTimeChange(
100 min_seekable_time_, max_seekable_time_, is_live_stream_);
106 GetAdaptiveStreamingInfo();
107 if (!is_live_stream_) {
108 LOG(INFO) << "(" << static_cast<void*>(this) << ") " << __func__
109 << " changed to static stream";
110 if (GetMediaPlayerClient())
111 GetMediaPlayerClient()->OnSeekableTimeChange({}, {}, is_live_stream_);
112 MediaPlayerBridgeCapi::UpdateDuration();
116 bool MediaPlayerBridgeCapiTV::GetLiveStreamingDuration(int64_t* min,
120 constexpr const size_t kDurationBufferSize = 64;
121 char live_duration[kDurationBufferSize] = {
124 char* live_ptr = live_duration;
125 const auto err = player_get_adaptive_streaming_info(
126 player_, live_duration, PLAYER_ADAPTIVE_INFO_LIVE_DURATION);
127 if (err != PLAYER_ERROR_NONE) {
128 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
129 << " |player_get_adaptive_streaming_info| failed " << err;
133 const std::string duration(live_duration);
134 const std::string::size_type delimiter = duration.find('|');
135 if (delimiter == std::string::npos) {
136 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
137 << " Failed to find delimiter | in duration: " << duration;
141 const std::string duration_min = duration.substr(0, delimiter);
142 if (duration_min.empty()) {
143 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
144 << " Failed empty min sub str: " << duration << ", "
150 if (!base::StringToInt64(duration_min, &out_min)) {
151 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
152 << " Failed to get min from duration: " << duration;
156 const std::string duration_max = duration.substr(delimiter + 1);
157 if (duration_max.empty()) {
158 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
159 << " empty max sub str: " << duration << ", " << delimiter;
164 if (!base::StringToInt64(duration_max, &out_max)) {
165 LOG(ERROR) << "(" << static_cast<void*>(this) << ") " << __func__
166 << " Failed to get max from duration: " << duration;