Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: webkit/media/android/webmediaplayer_tv.cc

Issue 14247018: Implement WebRTC in Chrome for TV (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed some comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. 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.
4
5 #include "webkit/media/android/webmediaplayer_tv.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "media/base/android/media_player_bridge.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
18 #include "webkit/media/android/media_source_delegate.h"
19 #include "webkit/media/android/stream_texture_factory_android.h"
20 #include "webkit/media/android/webmediaplayer_manager_android.h"
21 #include "webkit/media/android/webmediaplayer_proxy_android.h"
22 #include "webkit/media/media_stream_audio_renderer.h"
23 #include "webkit/media/media_stream_client.h"
24 #include "webkit/media/media_switches.h"
25 #include "webkit/media/webmediaplayer_util.h"
26
27 using media::MediaPlayerBridge;
28 using WebKit::WebMediaPlayerClient;
29 using WebKit::WebMediaPlayer;
30 using WebKit::WebMediaSource;
31 using WebKit::WebString;
32 using WebKit::WebURL;
33
34 namespace webkit_media {
35
36 WebMediaPlayerTv::WebMediaPlayerTv(
37 WebKit::WebFrame* frame,
38 WebMediaPlayerClient* client,
39 WebMediaPlayerManagerAndroid* manager,
40 WebMediaPlayerProxyAndroid* proxy,
41 StreamTextureFactory* factory,
42 media::MediaLog* media_log,
43 MediaStreamClient* media_stream_client,
44 media::Demuxer* demuxer)
45 : WebMediaPlayerAndroid(frame, client, manager, proxy, factory),
46 media_log_(media_log),
47 media_stream_client_(media_stream_client),
48 demuxer_(demuxer) {}
49
50 WebMediaPlayerTv::~WebMediaPlayerTv() {
51 if (audio_renderer_) {
52 if (audio_renderer_->IsLocalRenderer()) {
53 audio_renderer_->Stop();
54 } else if (!paused()) {
55 // The |audio_renderer_| can be shared by multiple remote streams, and
56 // it will be stopped when WebRtcAudioDeviceImpl goes away. So we simply
57 // pause the |audio_renderer_| here to avoid re-creating the
58 // |audio_renderer_|.
59 audio_renderer_->Pause();
60 }
61 }
62 }
63
64 const WebKit::WebTimeRanges& WebMediaPlayerTv::buffered() {
65 if (media_source_delegate_)
66 return media_source_delegate_->Buffered();
67 return WebMediaPlayerAndroid::buffered();
68 }
69
70 unsigned WebMediaPlayerTv::decodedFrameCount() const {
71 if (media_source_delegate_)
72 return media_source_delegate_->DecodedFrameCount();
73 return WebMediaPlayerAndroid::decodedFrameCount();
74 }
75
76 unsigned WebMediaPlayerTv::droppedFrameCount() const {
77 if (media_source_delegate_)
78 return media_source_delegate_->DroppedFrameCount();
79 return WebMediaPlayerAndroid::droppedFrameCount();
80 }
81
82 unsigned WebMediaPlayerTv::audioDecodedByteCount() const {
83 if (media_source_delegate_)
84 return media_source_delegate_->AudioDecodedByteCount();
85 return WebMediaPlayerAndroid::audioDecodedByteCount();
86 }
87
88 unsigned WebMediaPlayerTv::videoDecodedByteCount() const {
89 if (media_source_delegate_)
90 return media_source_delegate_->VideoDecodedByteCount();
91 return WebMediaPlayerAndroid::videoDecodedByteCount();
92 }
93
94 WebMediaPlayer::MediaKeyException WebMediaPlayerTv::generateKeyRequest(
95 const WebString& key_system,
96 const unsigned char* init_data,
97 unsigned init_data_length) {
98 if (media_source_delegate_) {
99 return media_source_delegate_->GenerateKeyRequest(
100 key_system, init_data, init_data_length);
101 }
102 return MediaKeyExceptionKeySystemNotSupported;
103 }
104
105 WebMediaPlayer::MediaKeyException WebMediaPlayerTv::addKey(
106 const WebString& key_system,
107 const unsigned char* key,
108 unsigned key_length,
109 const unsigned char* init_data,
110 unsigned init_data_length,
111 const WebString& session_id) {
112 if (media_source_delegate_) {
113 return media_source_delegate_->AddKey(
114 key_system, key, key_length, init_data, init_data_length, session_id);
115 }
116 return MediaKeyExceptionKeySystemNotSupported;
117 }
118
119 WebMediaPlayer::MediaKeyException WebMediaPlayerTv::cancelKeyRequest(
120 const WebString& key_system,
121 const WebString& session_id) {
122 if (media_source_delegate_)
123 return media_source_delegate_->CancelKeyRequest(key_system, session_id);
124 return MediaKeyExceptionKeySystemNotSupported;
125 }
126
127 void WebMediaPlayerTv::OnReadFromDemuxer(
128 media::DemuxerStream::Type type, bool seek_done) {
129 if (media_source_delegate_)
130 media_source_delegate_->OnReadFromDemuxer(type, seek_done);
131 else
132 NOTIMPLEMENTED();
133 }
134
135 void WebMediaPlayerTv::load(const WebURL& url,
136 WebMediaSource* media_source,
137 CORSMode cors_mode) {
138 if (cors_mode != CORSModeUnspecified)
139 NOTIMPLEMENTED() << "No CORS support";
140
141 MediaPlayerBridge::MediaType media_type =
142 MediaPlayerBridge::MEDIA_TYPE_DEFAULT;
143 if (media_source) {
144 media_source_delegate_.reset(new MediaSourceDelegate(
145 proxy(), player_id(),
146 base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
147 base::Unretained(this))));
148 // |media_source_delegate_| is owned, so Unretained() is safe here.
ycheo (away) 2013/05/02 02:45:21 Move this comment in front of L146.
wonsik 2013/05/02 15:22:00 Done.
149 media_source_delegate_->InitializeMediaSource(
150 frame(), client(), media_source, media_log_);
151 media_type = MediaPlayerBridge::MEDIA_TYPE_MEDIA_SOURCE_EXTENSIONS;
ycheo (away) 2013/05/02 02:45:21 How about move this line at the beginning of the b
wonsik 2013/05/02 15:22:00 Done.
152 } else if (media_stream_client_) {
153 media_source_delegate_.reset(new MediaSourceDelegate(
154 proxy(), player_id(),
155 base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
156 base::Unretained(this))));
157 media_source_delegate_->InitializeMediaStream(demuxer_);
158
159 audio_renderer_ = media_stream_client_->GetAudioRenderer(url);
160 if (audio_renderer_)
161 audio_renderer_->Start();
162 media_type = MediaPlayerBridge::MEDIA_TYPE_MEDIA_STREAMS;
ycheo (away) 2013/05/02 02:45:21 Ditto.
wonsik 2013/05/02 15:22:00 Done.
163 }
164
165 InitializeMediaPlayer(url, media_type);
166 }
167
168 void WebMediaPlayerTv::play() {
169 if (hasVideo() && NeedsExternalSurface()) {
170 if (proxy())
171 proxy()->RequestExternalSurface(player_id());
172 }
173 if (audio_renderer_ && paused())
174 audio_renderer_->Play();
175 WebMediaPlayerAndroid::play();
176 }
177
178 void WebMediaPlayerTv::pause() {
179 if (audio_renderer_ && !paused())
180 audio_renderer_->Pause();
181 WebMediaPlayerAndroid::pause();
182 }
183
184 void WebMediaPlayerTv::seek(double seconds) {
185 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
186 if (media_source_delegate_)
187 media_source_delegate_->Seek(seek_time);
188 WebMediaPlayerAndroid::seek(seconds);
189 }
190
191 void WebMediaPlayerTv::OnVideoSizeChanged(int width, int height) {
192 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kUseExternalVideoSurfaceThresholdInPixels);
194 static int threshold = 0;
195 static bool parsed_arg =
196 has_switch &&
197 base::StringToInt(
198 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
199 switches::kUseExternalVideoSurfaceThresholdInPixels),
200 &threshold);
201 if ((parsed_arg && threshold <= width * height) ||
202 // Use H/W surface for MSE as the content is protected.
203 media_source_delegate_) {
204 SetNeedsExternalSurface(true);
205 SetNeedsEstablishPeer(false);
206 if (!paused() && proxy())
207 proxy()->RequestExternalSurface(player_id());
208 }
209
210 WebMediaPlayerAndroid::OnVideoSizeChanged(width, height);
211 }
212
213 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698