Chromium Code Reviews| 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..fec7f93b13197f43984cad75e7e901b513cc5473 |
| --- /dev/null |
| +++ b/webkit/media/android/webmediaplayer_tv.cc |
| @@ -0,0 +1,214 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
qinmin
2013/04/29 17:31:49
2013
wonsik
2013/05/01 14:15:38
Done.
|
| +// 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, |
|
palmer
2013/04/29 18:58:44
Can any of these unsigned variables be changed to
wonsik
2013/05/01 14:15:38
Well these method signatures come all the way from
|
| + 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"; |
| + |
| + int flags = 0; |
| + 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. |
| + media_source_delegate_->InitializeMediaSource( |
| + frame(), client(), media_source, media_log_); |
| + flags = MediaPlayerBridge::FLAG_MEDIA_SOURCE; |
| + } 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_) { |
|
qinmin
2013/04/29 17:31:49
no { }
wonsik
2013/05/01 14:15:38
Done.
|
| + audio_renderer_->Start(); |
| + } |
| + flags = (MediaPlayerBridge::FLAG_MEDIA_SOURCE | |
| + MediaPlayerBridge::FLAG_LOW_LATENCY); |
| + } |
| + |
| + InitializeMediaPlayer(url, flags); |
| +} |
| + |
| +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 |