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

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

Issue 14247018: Implement WebRTC in Chrome for TV (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bugs 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/media/android/webmediaplayer_android.h" 5 #include "webkit/media/android/webmediaplayer_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
24 #include "webkit/media/android/webmediaplayer_manager_android.h" 24 #include "webkit/media/android/webmediaplayer_manager_android.h"
25 #include "webkit/media/android/webmediaplayer_proxy_android.h" 25 #include "webkit/media/android/webmediaplayer_proxy_android.h"
26 #include "webkit/media/webmediaplayer_util.h" 26 #include "webkit/media/webmediaplayer_util.h"
27 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" 27 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
28 28
29 #if defined(GOOGLE_TV) 29 #if defined(GOOGLE_TV)
30 #include "webkit/media/android/media_source_delegate.h" 30 #include "webkit/media/android/media_source_delegate.h"
31 #include "webkit/media/media_stream_audio_renderer.h"
32 #include "webkit/media/media_stream_client.h"
31 #endif 33 #endif
32 34
33 static const uint32 kGLTextureExternalOES = 0x8D65; 35 static const uint32 kGLTextureExternalOES = 0x8D65;
34 36
35 using WebKit::WebMediaPlayer; 37 using WebKit::WebMediaPlayer;
36 using WebKit::WebMediaSource; 38 using WebKit::WebMediaSource;
37 using WebKit::WebSize; 39 using WebKit::WebSize;
38 using WebKit::WebString; 40 using WebKit::WebString;
39 using WebKit::WebTimeRanges; 41 using WebKit::WebTimeRanges;
40 using WebKit::WebURL; 42 using WebKit::WebURL;
(...skipping 20 matching lines...) Expand all
61 network_state_(WebMediaPlayer::NetworkStateEmpty), 63 network_state_(WebMediaPlayer::NetworkStateEmpty),
62 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 64 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
63 is_playing_(false), 65 is_playing_(false),
64 needs_establish_peer_(true), 66 needs_establish_peer_(true),
65 has_size_info_(false), 67 has_size_info_(false),
66 stream_texture_factory_(factory), 68 stream_texture_factory_(factory),
67 needs_external_surface_(false), 69 needs_external_surface_(false),
68 video_frame_provider_client_(NULL), 70 video_frame_provider_client_(NULL),
69 proxy_(proxy), 71 proxy_(proxy),
70 current_time_(0), 72 current_time_(0),
71 media_log_(media_log) { 73 media_log_(media_log),
74 media_stream_client_(NULL) {
72 main_loop_->AddDestructionObserver(this); 75 main_loop_->AddDestructionObserver(this);
73 if (manager_) 76 if (manager_)
74 player_id_ = manager_->RegisterMediaPlayer(this); 77 player_id_ = manager_->RegisterMediaPlayer(this);
75 78
76 if (stream_texture_factory_) { 79 if (stream_texture_factory_) {
77 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 80 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
78 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); 81 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_);
79 ReallocateVideoFrame(); 82 ReallocateVideoFrame();
80 } 83 }
84 #if defined(GOOGLE_TV)
85 demuxer_ = NULL;
86 #endif
81 } 87 }
82 88
83 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { 89 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
84 SetVideoFrameProviderClient(NULL); 90 SetVideoFrameProviderClient(NULL);
85 client_->setWebLayer(NULL); 91 client_->setWebLayer(NULL);
86 92
87 if (proxy_) 93 if (proxy_)
88 proxy_->DestroyPlayer(player_id_); 94 proxy_->DestroyPlayer(player_id_);
89 95
90 if (stream_id_) 96 if (stream_id_)
91 stream_texture_factory_->DestroyStreamTexture(texture_id_); 97 stream_texture_factory_->DestroyStreamTexture(texture_id_);
92 98
93 if (manager_) 99 if (manager_)
94 manager_->UnregisterMediaPlayer(player_id_); 100 manager_->UnregisterMediaPlayer(player_id_);
95 101
96 if (main_loop_) 102 if (main_loop_)
97 main_loop_->RemoveDestructionObserver(this); 103 main_loop_->RemoveDestructionObserver(this);
104 #if defined(GOOGLE_TV)
105 if (demuxer_ && !destroy_demuxer_cb_.is_null()) {
106 media_source_delegate_.reset();
107 destroy_demuxer_cb_.Run();
108 }
109 #endif
98 } 110 }
99 111
100 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { 112 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) {
101 load(url, NULL, cors_mode); 113 load(url, NULL, cors_mode);
102 } 114 }
103 115
104 void WebMediaPlayerAndroid::load(const WebURL& url, 116 void WebMediaPlayerAndroid::load(const WebURL& url,
105 WebMediaSource* media_source, 117 WebMediaSource* media_source,
106 CORSMode cors_mode) { 118 CORSMode cors_mode) {
107 if (cors_mode != CORSModeUnspecified) 119 if (cors_mode != CORSModeUnspecified)
108 NOTIMPLEMENTED() << "No CORS support"; 120 NOTIMPLEMENTED() << "No CORS support";
109 121
110 scoped_ptr<WebKit::WebMediaSource> scoped_media_source(media_source); 122 MediaPlayerAndroid::SourceType media_source_type =
123 MediaPlayerAndroid::SOURCE_TYPE_URL;
124
125 if (media_source)
126 media_source_type = MediaPlayerAndroid::SOURCE_TYPE_MSE;
111 #if defined(GOOGLE_TV) 127 #if defined(GOOGLE_TV)
112 if (media_source) { 128 if (media_stream_client_) {
113 media_source_delegate_.reset( 129 LOG_IF(WARNING, media_source) << "It is absurd to have both media source "
acolwell GONE FROM CHROMIUM 2013/05/20 21:23:22 nit: DCHECK(!media_source) is sufficient.
wonsik 2013/05/21 10:09:29 Done.
114 new MediaSourceDelegate( 130 "and media stream set at the same time.";
115 frame_, client_, proxy_, player_id_, media_log_)); 131 media_source_type = MediaPlayerAndroid::SOURCE_TYPE_STREAM;
132 }
133
134 if (media_source_type != MediaPlayerAndroid::SOURCE_TYPE_URL) {
116 // |media_source_delegate_| is owned, so Unretained() is safe here. 135 // |media_source_delegate_| is owned, so Unretained() is safe here.
117 media_source_delegate_->Initialize( 136 media_source_delegate_.reset(new MediaSourceDelegate(
118 scoped_media_source.Pass(), 137 proxy_,
138 player_id_,
119 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, 139 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState,
120 base::Unretained(this))); 140 base::Unretained(this))));
141 if (media_source_type == MediaPlayerAndroid::SOURCE_TYPE_MSE) {
142 media_source_delegate_->InitializeMediaSource(
143 frame_, client_, media_source, media_log_);
144 } else if (media_source_type == MediaPlayerAndroid::SOURCE_TYPE_STREAM) {
145 media_source_delegate_->InitializeMediaStream(demuxer_);
146 }
121 } 147 }
122 #endif 148 #endif
123 149
150 InitializeMediaPlayer(url, media_source_type);
151 }
152
153 void WebMediaPlayerAndroid::InitializeMediaPlayer(
154 const WebURL& url,
155 MediaPlayerAndroid::SourceType media_source_type) {
124 url_ = url; 156 url_ = url;
125 GURL first_party_url = frame_->document().firstPartyForCookies(); 157 GURL first_party_url = frame_->document().firstPartyForCookies();
126 if (proxy_) { 158 if (proxy_) {
127 proxy_->Initialize(player_id_, url_, media_source != NULL, first_party_url); 159 proxy_->Initialize(player_id_, url, media_source_type, first_party_url);
128 if (manager_->IsInFullscreen(frame_)) 160 if (manager_->IsInFullscreen(frame_))
129 proxy_->EnterFullscreen(player_id_); 161 proxy_->EnterFullscreen(player_id_);
130 } 162 }
131 163
132 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); 164 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
133 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); 165 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing);
134 } 166 }
135 167
136 void WebMediaPlayerAndroid::cancelLoad() { 168 void WebMediaPlayerAndroid::cancelLoad() {
137 NOTIMPLEMENTED(); 169 NOTIMPLEMENTED();
138 } 170 }
139 171
140 void WebMediaPlayerAndroid::play() { 172 void WebMediaPlayerAndroid::play() {
141 #if defined(GOOGLE_TV) 173 #if defined(GOOGLE_TV)
142 if (hasVideo() && needs_external_surface_) { 174 if (hasVideo() && needs_external_surface_) {
143 DCHECK(!needs_establish_peer_);
144 if (proxy_) 175 if (proxy_)
145 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); 176 proxy_->RequestExternalSurface(player_id_, last_computed_rect_);
146 } 177 }
147 #endif 178 #endif
148 if (hasVideo() && needs_establish_peer_) 179 if (hasVideo() && needs_establish_peer_)
149 EstablishSurfaceTexturePeer(); 180 EstablishSurfaceTexturePeer();
150 181
151 if (paused() && proxy_) 182 if (paused() && proxy_)
152 proxy_->Start(player_id_); 183 proxy_->Start(player_id_);
153 is_playing_ = true; 184 is_playing_ = true;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 #if defined(GOOGLE_TV) 491 #if defined(GOOGLE_TV)
461 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( 492 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch(
462 switches::kUseExternalVideoSurfaceThresholdInPixels); 493 switches::kUseExternalVideoSurfaceThresholdInPixels);
463 static int threshold = 0; 494 static int threshold = 0;
464 static bool parsed_arg = 495 static bool parsed_arg =
465 has_switch && 496 has_switch &&
466 base::StringToInt( 497 base::StringToInt(
467 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 498 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
468 switches::kUseExternalVideoSurfaceThresholdInPixels), 499 switches::kUseExternalVideoSurfaceThresholdInPixels),
469 &threshold); 500 &threshold);
470
471 if ((parsed_arg && threshold <= width * height) || 501 if ((parsed_arg && threshold <= width * height) ||
472 // Use H/W surface for MSE as the content is protected. 502 // Use H/W surface for MSE as the content is protected.
473 media_source_delegate_) { 503 media_source_delegate_) {
474 needs_external_surface_ = true; 504 needs_external_surface_ = true;
475 SetNeedsEstablishPeer(false); 505 SetNeedsEstablishPeer(false);
476 if (!paused() && proxy_) 506 if (!paused() && proxy_)
477 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); 507 proxy_->RequestExternalSurface(player_id_, last_computed_rect_);
478 } 508 }
479 #endif 509 #endif
480 510
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 680
651 // Return false when the geometry hasn't been changed from the last time. 681 // Return false when the geometry hasn't been changed from the last time.
652 if (last_computed_rect_ == *rect) 682 if (last_computed_rect_ == *rect)
653 return false; 683 return false;
654 684
655 // Store the changed geometry information when it is actually changed. 685 // Store the changed geometry information when it is actually changed.
656 last_computed_rect_ = *rect; 686 last_computed_rect_ = *rect;
657 return true; 687 return true;
658 } 688 }
659 689
660 WebMediaPlayer::MediaKeyException 690 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest(
661 WebMediaPlayerAndroid::generateKeyRequest(const WebString& key_system, 691 const WebString& key_system,
662 const unsigned char* init_data, 692 const unsigned char* init_data,
663 unsigned init_data_length) { 693 unsigned init_data_length) {
664 if (media_source_delegate_) { 694 if (media_source_delegate_) {
665 return media_source_delegate_->GenerateKeyRequest( 695 return media_source_delegate_->GenerateKeyRequest(
666 key_system, init_data, init_data_length); 696 key_system, init_data, init_data_length);
667 } 697 }
668 return MediaKeyExceptionKeySystemNotSupported; 698 return MediaKeyExceptionKeySystemNotSupported;
669 } 699 }
670 700
671 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( 701 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey(
672 const WebString& key_system, 702 const WebString& key_system,
673 const unsigned char* key, 703 const unsigned char* key,
(...skipping 16 matching lines...) Expand all
690 return MediaKeyExceptionKeySystemNotSupported; 720 return MediaKeyExceptionKeySystemNotSupported;
691 } 721 }
692 722
693 void WebMediaPlayerAndroid::OnReadFromDemuxer( 723 void WebMediaPlayerAndroid::OnReadFromDemuxer(
694 media::DemuxerStream::Type type, bool seek_done) { 724 media::DemuxerStream::Type type, bool seek_done) {
695 if (media_source_delegate_) 725 if (media_source_delegate_)
696 media_source_delegate_->OnReadFromDemuxer(type, seek_done); 726 media_source_delegate_->OnReadFromDemuxer(type, seek_done);
697 else 727 else
698 NOTIMPLEMENTED(); 728 NOTIMPLEMENTED();
699 } 729 }
730
731 bool WebMediaPlayerAndroid::InjectMediaStream(
732 MediaStreamClient* media_stream_client,
733 media::Demuxer* demuxer,
734 const base::Closure& destroy_demuxer_cb) {
735 DCHECK(!demuxer);
736 media_stream_client_ = media_stream_client;
737 demuxer_ = demuxer;
738 destroy_demuxer_cb_ = destroy_demuxer_cb;
739 return true;
740 }
700 #endif 741 #endif
701 742
702 void WebMediaPlayerAndroid::enterFullscreen() { 743 void WebMediaPlayerAndroid::enterFullscreen() {
703 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { 744 if (proxy_ && manager_->CanEnterFullscreen(frame_)) {
704 proxy_->EnterFullscreen(player_id_); 745 proxy_->EnterFullscreen(player_id_);
705 SetNeedsEstablishPeer(false); 746 SetNeedsEstablishPeer(false);
706 } 747 }
707 } 748 }
708 749
709 void WebMediaPlayerAndroid::exitFullscreen() { 750 void WebMediaPlayerAndroid::exitFullscreen() {
710 if (proxy_) 751 if (proxy_)
711 proxy_->ExitFullscreen(player_id_); 752 proxy_->ExitFullscreen(player_id_);
712 } 753 }
713 754
714 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 755 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
715 return manager_->CanEnterFullscreen(frame_); 756 return manager_->CanEnterFullscreen(frame_);
716 } 757 }
717 758
718 } // namespace webkit_media 759 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698