OLD | NEW |
---|---|
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 Loading... | |
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/compositor_bindings/web_layer_impl.h" | 24 #include "webkit/compositor_bindings/web_layer_impl.h" |
25 #include "webkit/media/android/webmediaplayer_manager_android.h" | 25 #include "webkit/media/android/webmediaplayer_manager_android.h" |
26 #include "webkit/media/android/webmediaplayer_proxy_android.h" | 26 #include "webkit/media/android/webmediaplayer_proxy_android.h" |
27 #include "webkit/media/webmediaplayer_util.h" | 27 #include "webkit/media/webmediaplayer_util.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 Loading... | |
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 destroy_demuxer_cb_.Run(); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
You should probably clear the media_source_delegat
wonsik
2013/05/20 14:02:24
Done.
| |
107 } | |
108 #endif | |
98 } | 109 } |
99 | 110 |
100 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { | 111 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { |
101 load(url, NULL, cors_mode); | 112 load(url, NULL, cors_mode); |
102 } | 113 } |
103 | 114 |
104 void WebMediaPlayerAndroid::load(const WebURL& url, | 115 void WebMediaPlayerAndroid::load(const WebURL& url, |
105 WebMediaSource* media_source, | 116 WebMediaSource* media_source, |
106 CORSMode cors_mode) { | 117 CORSMode cors_mode) { |
107 if (cors_mode != CORSModeUnspecified) | 118 if (cors_mode != CORSModeUnspecified) |
108 NOTIMPLEMENTED() << "No CORS support"; | 119 NOTIMPLEMENTED() << "No CORS support"; |
109 | 120 |
110 scoped_ptr<WebKit::WebMediaSource> scoped_media_source(media_source); | 121 MediaPlayerAndroid::MediaSourceType media_source_type = |
122 MediaPlayerAndroid::MEDIA_SOURCE_URL; | |
111 #if defined(GOOGLE_TV) | 123 #if defined(GOOGLE_TV) |
112 if (media_source) { | 124 if (media_source) { |
113 media_source_delegate_.reset( | 125 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_MSE; |
114 new MediaSourceDelegate( | 126 } else if (media_stream_client_) { |
115 frame_, client_, proxy_, player_id_, media_log_)); | 127 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_STREAM; |
128 } | |
129 | |
130 if (media_source_type != MediaPlayerAndroid::MEDIA_SOURCE_URL) { | |
116 // |media_source_delegate_| is owned, so Unretained() is safe here. | 131 // |media_source_delegate_| is owned, so Unretained() is safe here. |
117 media_source_delegate_->Initialize( | 132 media_source_delegate_.reset(new MediaSourceDelegate( |
118 scoped_media_source.Pass(), | 133 proxy_, |
134 player_id_, | |
119 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, | 135 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, |
120 base::Unretained(this))); | 136 base::Unretained(this)))); |
137 if (media_source_type == MediaPlayerAndroid::MEDIA_SOURCE_MSE) { | |
138 media_source_delegate_->InitializeMediaSource( | |
139 frame_, client_, media_source, media_log_); | |
140 } else if (media_source_type == MediaPlayerAndroid::MEDIA_SOURCE_STREAM) { | |
141 media_source_delegate_->InitializeMediaStream(demuxer_); | |
142 } | |
121 } | 143 } |
144 #else | |
145 if (media_source) | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: I think this isn't necessary if you move the
wonsik
2013/05/20 14:02:24
Done --- assuming I understood your intention here
| |
146 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_MSE; | |
122 #endif | 147 #endif |
123 | 148 |
149 InitializeMediaPlayer(url, media_source_type); | |
150 } | |
151 | |
152 void WebMediaPlayerAndroid::InitializeMediaPlayer( | |
153 const WebURL& url, | |
154 MediaPlayerAndroid::MediaSourceType media_source_type) { | |
124 url_ = url; | 155 url_ = url; |
125 GURL first_party_url = frame_->document().firstPartyForCookies(); | 156 GURL first_party_url = frame_->document().firstPartyForCookies(); |
126 if (proxy_) { | 157 if (proxy_) { |
127 proxy_->Initialize(player_id_, url_, media_source != NULL, first_party_url); | 158 proxy_->Initialize(player_id_, url, media_source_type, first_party_url); |
128 if (manager_->IsInFullscreen(frame_)) | 159 if (manager_->IsInFullscreen(frame_)) |
129 proxy_->EnterFullscreen(player_id_); | 160 proxy_->EnterFullscreen(player_id_); |
130 } | 161 } |
131 | 162 |
132 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 163 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
133 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 164 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
134 } | 165 } |
135 | 166 |
136 void WebMediaPlayerAndroid::cancelLoad() { | 167 void WebMediaPlayerAndroid::cancelLoad() { |
137 NOTIMPLEMENTED(); | 168 NOTIMPLEMENTED(); |
138 } | 169 } |
139 | 170 |
140 void WebMediaPlayerAndroid::play() { | 171 void WebMediaPlayerAndroid::play() { |
141 #if defined(GOOGLE_TV) | 172 #if defined(GOOGLE_TV) |
142 if (hasVideo() && needs_external_surface_) { | 173 if (hasVideo() && needs_external_surface_) { |
143 DCHECK(!needs_establish_peer_); | |
144 if (proxy_) | 174 if (proxy_) |
145 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 175 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
146 } | 176 } |
147 #endif | 177 #endif |
148 if (hasVideo() && needs_establish_peer_) | 178 if (hasVideo() && needs_establish_peer_) |
149 EstablishSurfaceTexturePeer(); | 179 EstablishSurfaceTexturePeer(); |
150 | 180 |
151 if (paused() && proxy_) | 181 if (paused() && proxy_) |
152 proxy_->Start(player_id_); | 182 proxy_->Start(player_id_); |
153 is_playing_ = true; | 183 is_playing_ = true; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 #if defined(GOOGLE_TV) | 488 #if defined(GOOGLE_TV) |
459 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( | 489 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( |
460 switches::kUseExternalVideoSurfaceThresholdInPixels); | 490 switches::kUseExternalVideoSurfaceThresholdInPixels); |
461 static int threshold = 0; | 491 static int threshold = 0; |
462 static bool parsed_arg = | 492 static bool parsed_arg = |
463 has_switch && | 493 has_switch && |
464 base::StringToInt( | 494 base::StringToInt( |
465 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 495 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
466 switches::kUseExternalVideoSurfaceThresholdInPixels), | 496 switches::kUseExternalVideoSurfaceThresholdInPixels), |
467 &threshold); | 497 &threshold); |
468 | |
469 if ((parsed_arg && threshold <= width * height) || | 498 if ((parsed_arg && threshold <= width * height) || |
470 // Use H/W surface for MSE as the content is protected. | 499 // Use H/W surface for MSE as the content is protected. |
471 media_source_delegate_) { | 500 media_source_delegate_) { |
472 needs_external_surface_ = true; | 501 needs_external_surface_ = true; |
473 SetNeedsEstablishPeer(false); | 502 SetNeedsEstablishPeer(false); |
474 if (!paused() && proxy_) | 503 if (!paused() && proxy_) |
475 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 504 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
476 } | 505 } |
477 #endif | 506 #endif |
478 | 507 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 | 677 |
649 // Return false when the geometry hasn't been changed from the last time. | 678 // Return false when the geometry hasn't been changed from the last time. |
650 if (last_computed_rect_ == *rect) | 679 if (last_computed_rect_ == *rect) |
651 return false; | 680 return false; |
652 | 681 |
653 // Store the changed geometry information when it is actually changed. | 682 // Store the changed geometry information when it is actually changed. |
654 last_computed_rect_ = *rect; | 683 last_computed_rect_ = *rect; |
655 return true; | 684 return true; |
656 } | 685 } |
657 | 686 |
658 WebMediaPlayer::MediaKeyException | 687 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( |
659 WebMediaPlayerAndroid::generateKeyRequest(const WebString& key_system, | 688 const WebString& key_system, |
660 const unsigned char* init_data, | 689 const unsigned char* init_data, |
661 unsigned init_data_length) { | 690 unsigned init_data_length) { |
662 if (media_source_delegate_) { | 691 if (media_source_delegate_) { |
663 return media_source_delegate_->GenerateKeyRequest( | 692 return media_source_delegate_->GenerateKeyRequest( |
664 key_system, init_data, init_data_length); | 693 key_system, init_data, init_data_length); |
665 } | 694 } |
666 return MediaKeyExceptionKeySystemNotSupported; | 695 return MediaKeyExceptionKeySystemNotSupported; |
667 } | 696 } |
668 | 697 |
669 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | 698 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( |
670 const WebString& key_system, | 699 const WebString& key_system, |
671 const unsigned char* key, | 700 const unsigned char* key, |
(...skipping 16 matching lines...) Expand all Loading... | |
688 return MediaKeyExceptionKeySystemNotSupported; | 717 return MediaKeyExceptionKeySystemNotSupported; |
689 } | 718 } |
690 | 719 |
691 void WebMediaPlayerAndroid::OnReadFromDemuxer( | 720 void WebMediaPlayerAndroid::OnReadFromDemuxer( |
692 media::DemuxerStream::Type type, bool seek_done) { | 721 media::DemuxerStream::Type type, bool seek_done) { |
693 if (media_source_delegate_) | 722 if (media_source_delegate_) |
694 media_source_delegate_->OnReadFromDemuxer(type, seek_done); | 723 media_source_delegate_->OnReadFromDemuxer(type, seek_done); |
695 else | 724 else |
696 NOTIMPLEMENTED(); | 725 NOTIMPLEMENTED(); |
697 } | 726 } |
727 | |
728 bool WebMediaPlayerAndroid::InjectMediaStream( | |
729 MediaStreamClient* media_stream_client, | |
730 media::Demuxer* demuxer, | |
731 const base::Closure& destroy_demuxer_cb) { | |
732 media_stream_client_ = media_stream_client; | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
DCHECK(!demuxer_)?
wonsik
2013/05/20 14:02:24
Done.
| |
733 demuxer_ = demuxer; | |
734 destroy_demuxer_cb_ = destroy_demuxer_cb; | |
735 return true; | |
736 } | |
698 #endif | 737 #endif |
699 | 738 |
700 void WebMediaPlayerAndroid::enterFullscreen() { | 739 void WebMediaPlayerAndroid::enterFullscreen() { |
701 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { | 740 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { |
702 proxy_->EnterFullscreen(player_id_); | 741 proxy_->EnterFullscreen(player_id_); |
703 SetNeedsEstablishPeer(false); | 742 SetNeedsEstablishPeer(false); |
704 } | 743 } |
705 } | 744 } |
706 | 745 |
707 void WebMediaPlayerAndroid::exitFullscreen() { | 746 void WebMediaPlayerAndroid::exitFullscreen() { |
708 if (proxy_) | 747 if (proxy_) |
709 proxy_->ExitFullscreen(player_id_); | 748 proxy_->ExitFullscreen(player_id_); |
710 } | 749 } |
711 | 750 |
712 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 751 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
713 return manager_->CanEnterFullscreen(frame_); | 752 return manager_->CanEnterFullscreen(frame_); |
714 } | 753 } |
715 | 754 |
716 } // namespace webkit_media | 755 } // namespace webkit_media |
OLD | NEW |