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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: webkit/media/android/webmediaplayer_tv.cc
diff --git a/webkit/media/android/webmediaplayer_tv.cc b/webkit/media/android/webmediaplayer_tv.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21fb92808810ee5031c15a5948a9079b9e0b2b43
--- /dev/null
+++ b/webkit/media/android/webmediaplayer_tv.cc
@@ -0,0 +1,213 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/media/android/webmediaplayer_tv.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "media/base/android/media_player_bridge.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+#include "webkit/media/android/media_source_delegate.h"
+#include "webkit/media/android/stream_texture_factory_android.h"
+#include "webkit/media/android/webmediaplayer_manager_android.h"
+#include "webkit/media/android/webmediaplayer_proxy_android.h"
+#include "webkit/media/media_stream_audio_renderer.h"
+#include "webkit/media/media_stream_client.h"
+#include "webkit/media/media_switches.h"
+#include "webkit/media/webmediaplayer_util.h"
+
+using media::MediaPlayerBridge;
+using WebKit::WebMediaPlayerClient;
+using WebKit::WebMediaPlayer;
+using WebKit::WebMediaSource;
+using WebKit::WebString;
+using WebKit::WebURL;
+
+namespace webkit_media {
+
+WebMediaPlayerTv::WebMediaPlayerTv(
+ WebKit::WebFrame* frame,
+ WebMediaPlayerClient* client,
+ WebMediaPlayerManagerAndroid* manager,
+ WebMediaPlayerProxyAndroid* proxy,
+ StreamTextureFactory* factory,
+ media::MediaLog* media_log,
+ MediaStreamClient* media_stream_client,
+ media::Demuxer* demuxer)
+ : WebMediaPlayerAndroid(frame, client, manager, proxy, factory),
+ media_log_(media_log),
+ media_stream_client_(media_stream_client),
+ demuxer_(demuxer) {}
+
+WebMediaPlayerTv::~WebMediaPlayerTv() {
+ if (audio_renderer_) {
+ if (audio_renderer_->IsLocalRenderer()) {
+ audio_renderer_->Stop();
+ } else if (!paused()) {
+ // The |audio_renderer_| can be shared by multiple remote streams, and
+ // it will be stopped when WebRtcAudioDeviceImpl goes away. So we simply
+ // pause the |audio_renderer_| here to avoid re-creating the
+ // |audio_renderer_|.
+ audio_renderer_->Pause();
+ }
+ }
+}
+
+const WebKit::WebTimeRanges& WebMediaPlayerTv::buffered() {
+ if (media_source_delegate_)
+ return media_source_delegate_->Buffered();
+ return WebMediaPlayerAndroid::buffered();
+}
+
+unsigned WebMediaPlayerTv::decodedFrameCount() const {
+ if (media_source_delegate_)
+ return media_source_delegate_->DecodedFrameCount();
+ return WebMediaPlayerAndroid::decodedFrameCount();
+}
+
+unsigned WebMediaPlayerTv::droppedFrameCount() const {
+ if (media_source_delegate_)
+ return media_source_delegate_->DroppedFrameCount();
+ return WebMediaPlayerAndroid::droppedFrameCount();
+}
+
+unsigned WebMediaPlayerTv::audioDecodedByteCount() const {
+ if (media_source_delegate_)
+ return media_source_delegate_->AudioDecodedByteCount();
+ return WebMediaPlayerAndroid::audioDecodedByteCount();
+}
+
+unsigned WebMediaPlayerTv::videoDecodedByteCount() const {
+ if (media_source_delegate_)
+ return media_source_delegate_->VideoDecodedByteCount();
+ return WebMediaPlayerAndroid::videoDecodedByteCount();
+}
+
+WebMediaPlayer::MediaKeyException WebMediaPlayerTv::generateKeyRequest(
+ const WebString& key_system,
+ const unsigned char* init_data,
+ unsigned init_data_length) {
+ if (media_source_delegate_) {
+ return media_source_delegate_->GenerateKeyRequest(
+ key_system, init_data, init_data_length);
+ }
+ return MediaKeyExceptionKeySystemNotSupported;
+}
+
+WebMediaPlayer::MediaKeyException WebMediaPlayerTv::addKey(
+ const WebString& key_system,
+ const unsigned char* key,
+ unsigned key_length,
+ const unsigned char* init_data,
+ unsigned init_data_length,
+ const WebString& session_id) {
+ if (media_source_delegate_) {
+ return media_source_delegate_->AddKey(
+ key_system, key, key_length, init_data, init_data_length, session_id);
+ }
+ return MediaKeyExceptionKeySystemNotSupported;
+}
+
+WebMediaPlayer::MediaKeyException WebMediaPlayerTv::cancelKeyRequest(
+ const WebString& key_system,
+ const WebString& session_id) {
+ if (media_source_delegate_)
+ return media_source_delegate_->CancelKeyRequest(key_system, session_id);
+ return MediaKeyExceptionKeySystemNotSupported;
+}
+
+void WebMediaPlayerTv::OnReadFromDemuxer(
+ media::DemuxerStream::Type type, bool seek_done) {
+ if (media_source_delegate_)
+ media_source_delegate_->OnReadFromDemuxer(type, seek_done);
+ else
+ NOTIMPLEMENTED();
+}
+
+void WebMediaPlayerTv::load(const WebURL& url,
+ WebMediaSource* media_source,
+ CORSMode cors_mode) {
+ if (cors_mode != CORSModeUnspecified)
+ NOTIMPLEMENTED() << "No CORS support";
+
+ MediaPlayerBridge::MediaType media_type =
+ MediaPlayerBridge::MEDIA_TYPE_DEFAULT;
+ if (media_source) {
+ media_source_delegate_.reset(new MediaSourceDelegate(
+ proxy(), player_id(),
+ base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
+ base::Unretained(this))));
+ // |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.
+ media_source_delegate_->InitializeMediaSource(
+ frame(), client(), media_source, media_log_);
+ 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.
+ } else if (media_stream_client_) {
+ media_source_delegate_.reset(new MediaSourceDelegate(
+ proxy(), player_id(),
+ base::Bind(&WebMediaPlayerTv::UpdateNetworkState,
+ base::Unretained(this))));
+ media_source_delegate_->InitializeMediaStream(demuxer_);
+
+ audio_renderer_ = media_stream_client_->GetAudioRenderer(url);
+ if (audio_renderer_)
+ audio_renderer_->Start();
+ media_type = MediaPlayerBridge::MEDIA_TYPE_MEDIA_STREAMS;
ycheo (away) 2013/05/02 02:45:21 Ditto.
wonsik 2013/05/02 15:22:00 Done.
+ }
+
+ InitializeMediaPlayer(url, media_type);
+}
+
+void WebMediaPlayerTv::play() {
+ if (hasVideo() && NeedsExternalSurface()) {
+ if (proxy())
+ proxy()->RequestExternalSurface(player_id());
+ }
+ if (audio_renderer_ && paused())
+ audio_renderer_->Play();
+ WebMediaPlayerAndroid::play();
+}
+
+void WebMediaPlayerTv::pause() {
+ if (audio_renderer_ && !paused())
+ audio_renderer_->Pause();
+ WebMediaPlayerAndroid::pause();
+}
+
+void WebMediaPlayerTv::seek(double seconds) {
+ base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
+ if (media_source_delegate_)
+ media_source_delegate_->Seek(seek_time);
+ WebMediaPlayerAndroid::seek(seconds);
+}
+
+void WebMediaPlayerTv::OnVideoSizeChanged(int width, int height) {
+ static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kUseExternalVideoSurfaceThresholdInPixels);
+ static int threshold = 0;
+ static bool parsed_arg =
+ has_switch &&
+ base::StringToInt(
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kUseExternalVideoSurfaceThresholdInPixels),
+ &threshold);
+ if ((parsed_arg && threshold <= width * height) ||
+ // Use H/W surface for MSE as the content is protected.
+ media_source_delegate_) {
+ SetNeedsExternalSurface(true);
+ SetNeedsEstablishPeer(false);
+ if (!paused() && proxy())
+ proxy()->RequestExternalSurface(player_id());
+ }
+
+ WebMediaPlayerAndroid::OnVideoSizeChanged(width, height);
+}
+
+} // namespace webkit_media

Powered by Google App Engine
This is Rietveld 408576698