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

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: WebRTC impl on Chrome for TV 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) 2012 The Chromium Authors. All rights reserved.
ycheo (away) 2013/04/29 13:18:13 2013
wonsik 2013/05/01 14:15:38 Done.
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 int flags = 0;
142 if (media_source) {
143 media_source_delegate_.reset(new MediaSourceDelegate(
144 proxy(), player_id(),
145 base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
146 base::Unretained(this))));
147 // |media_source_delegate_| is owned, so Unretained() is safe here.
148 media_source_delegate_->InitializeMediaSource(
149 frame(), client(), media_source, media_log_);
150 flags = MediaPlayerBridge::FLAG_MEDIA_SOURCE;
151 } else if (media_stream_client_) {
152 media_source_delegate_.reset(new MediaSourceDelegate(
153 proxy(), player_id(),
154 base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
155 base::Unretained(this))));
156 media_source_delegate_->InitializeMediaStream(demuxer_);
157
158 audio_renderer_ = media_stream_client_->GetAudioRenderer(url);
159 if (audio_renderer_) {
ycheo (away) 2013/04/29 13:18:13 Don't need {}.
wonsik 2013/05/01 14:15:38 Done.
160 audio_renderer_->Start();
161 }
162 flags = (MediaPlayerBridge::FLAG_MEDIA_SOURCE |
163 MediaPlayerBridge::FLAG_LOW_LATENCY);
164 }
165
166 InitializeMediaPlayer(url, flags);
167 }
168
169 void WebMediaPlayerTv::play() {
170 if (hasVideo() && NeedsExternalSurface()) {
171 if (proxy())
172 proxy()->RequestExternalSurface(player_id());
173 }
174 if (audio_renderer_ && paused())
175 audio_renderer_->Play();
176 WebMediaPlayerAndroid::play();
177 }
178
179 void WebMediaPlayerTv::pause() {
180 if (audio_renderer_ && !paused())
181 audio_renderer_->Pause();
182 WebMediaPlayerAndroid::pause();
183 }
184
185 void WebMediaPlayerTv::seek(double seconds) {
186 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
187 if (media_source_delegate_)
188 media_source_delegate_->Seek(seek_time);
189 WebMediaPlayerAndroid::seek(seconds);
190 }
191
192 void WebMediaPlayerTv::OnVideoSizeChanged(int width, int height) {
193 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch(
194 switches::kUseExternalVideoSurfaceThresholdInPixels);
195 static int threshold = 0;
196 static bool parsed_arg =
197 has_switch &&
198 base::StringToInt(
199 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
200 switches::kUseExternalVideoSurfaceThresholdInPixels),
201 &threshold);
202 if ((parsed_arg && threshold <= width * height) ||
203 // Use H/W surface for MSE as the content is protected.
204 media_source_delegate_) {
205 SetNeedsExternalSurface(true);
206 SetNeedsEstablishPeer(false);
207 if (!paused() && proxy())
208 proxy()->RequestExternalSurface(player_id());
209 }
210
211 WebMediaPlayerAndroid::OnVideoSizeChanged(width, height);
212 }
213
214 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698