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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "cc/layers/video_layer.h" | 11 #include "cc/layers/video_layer.h" |
12 #include "gpu/GLES2/gl2extchromium.h" | 12 #include "gpu/GLES2/gl2extchromium.h" |
13 #include "media/base/android/media_player_android.h" | 13 #include "media/base/android/media_player_android.h" |
14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
15 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
22 #include "webkit/compositor_bindings/web_layer_impl.h" | 22 #include "webkit/compositor_bindings/web_layer_impl.h" |
23 #include "webkit/media/android/webmediaplayer_manager_android.h" | 23 #include "webkit/media/android/webmediaplayer_manager_android.h" |
24 #include "webkit/media/android/webmediaplayer_proxy_android.h" | 24 #include "webkit/media/android/webmediaplayer_proxy_android.h" |
25 #include "webkit/media/media_switches.h" | 25 #include "webkit/media/media_switches.h" |
26 #include "webkit/media/webmediaplayer_util.h" | 26 #include "webkit/media/webmediaplayer_util.h" |
27 | 27 |
28 #if defined(GOOGLE_TV) | 28 #if defined(GOOGLE_TV) |
29 #include "webkit/media/android/media_source_delegate.h" | 29 #include "webkit/media/android/media_source_delegate.h" |
| 30 #include "webkit/media/media_stream_audio_renderer.h" |
| 31 #include "webkit/media/media_stream_client.h" |
30 #endif | 32 #endif |
31 | 33 |
32 static const uint32 kGLTextureExternalOES = 0x8D65; | 34 static const uint32 kGLTextureExternalOES = 0x8D65; |
33 | 35 |
34 using WebKit::WebMediaPlayer; | 36 using WebKit::WebMediaPlayer; |
35 using WebKit::WebMediaSource; | 37 using WebKit::WebMediaSource; |
36 using WebKit::WebSize; | 38 using WebKit::WebSize; |
37 using WebKit::WebString; | 39 using WebKit::WebString; |
38 using WebKit::WebTimeRanges; | 40 using WebKit::WebTimeRanges; |
39 using WebKit::WebURL; | 41 using WebKit::WebURL; |
(...skipping 20 matching lines...) Expand all Loading... |
60 network_state_(WebMediaPlayer::NetworkStateEmpty), | 62 network_state_(WebMediaPlayer::NetworkStateEmpty), |
61 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 63 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
62 is_playing_(false), | 64 is_playing_(false), |
63 needs_establish_peer_(true), | 65 needs_establish_peer_(true), |
64 has_size_info_(false), | 66 has_size_info_(false), |
65 stream_texture_factory_(factory), | 67 stream_texture_factory_(factory), |
66 needs_external_surface_(false), | 68 needs_external_surface_(false), |
67 video_frame_provider_client_(NULL), | 69 video_frame_provider_client_(NULL), |
68 proxy_(proxy), | 70 proxy_(proxy), |
69 current_time_(0), | 71 current_time_(0), |
70 media_log_(media_log) { | 72 media_log_(media_log), |
| 73 media_stream_client_(NULL) { |
71 main_loop_->AddDestructionObserver(this); | 74 main_loop_->AddDestructionObserver(this); |
72 if (manager_) | 75 if (manager_) |
73 player_id_ = manager_->RegisterMediaPlayer(this); | 76 player_id_ = manager_->RegisterMediaPlayer(this); |
74 | 77 |
75 if (stream_texture_factory_) { | 78 if (stream_texture_factory_) { |
76 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 79 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
77 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 80 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
78 ReallocateVideoFrame(); | 81 ReallocateVideoFrame(); |
79 } | 82 } |
| 83 #if defined(GOOGLE_TV) |
| 84 demuxer_ = NULL; |
| 85 #endif |
80 } | 86 } |
81 | 87 |
82 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 88 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
83 SetVideoFrameProviderClient(NULL); | 89 SetVideoFrameProviderClient(NULL); |
84 client_->setWebLayer(NULL); | 90 client_->setWebLayer(NULL); |
85 | 91 |
86 if (proxy_) | 92 if (proxy_) |
87 proxy_->DestroyPlayer(player_id_); | 93 proxy_->DestroyPlayer(player_id_); |
88 | 94 |
89 if (stream_id_) | 95 if (stream_id_) |
90 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 96 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
91 | 97 |
92 if (manager_) | 98 if (manager_) |
93 manager_->UnregisterMediaPlayer(player_id_); | 99 manager_->UnregisterMediaPlayer(player_id_); |
94 | 100 |
95 if (main_loop_) | 101 if (main_loop_) |
96 main_loop_->RemoveDestructionObserver(this); | 102 main_loop_->RemoveDestructionObserver(this); |
| 103 #if defined(GOOGLE_TV) |
| 104 if (demuxer_ && !destroy_demuxer_cb_.is_null()) { |
| 105 destroy_demuxer_cb_.Run(); |
| 106 } |
| 107 #endif |
97 } | 108 } |
98 | 109 |
99 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { | 110 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { |
100 load(url, NULL, cors_mode); | 111 load(url, NULL, cors_mode); |
101 } | 112 } |
102 | 113 |
103 void WebMediaPlayerAndroid::load(const WebURL& url, | 114 void WebMediaPlayerAndroid::load(const WebURL& url, |
104 WebMediaSource* media_source, | 115 WebMediaSource* media_source, |
105 CORSMode cors_mode) { | 116 CORSMode cors_mode) { |
106 if (cors_mode != CORSModeUnspecified) | 117 if (cors_mode != CORSModeUnspecified) |
107 NOTIMPLEMENTED() << "No CORS support"; | 118 NOTIMPLEMENTED() << "No CORS support"; |
108 | 119 |
109 scoped_ptr<WebKit::WebMediaSource> scoped_media_source(media_source); | 120 MediaPlayerAndroid::MediaSourceType media_source_type = |
| 121 MediaPlayerAndroid::MEDIA_SOURCE_URL; |
110 #if defined(GOOGLE_TV) | 122 #if defined(GOOGLE_TV) |
111 if (media_source) { | 123 if (media_source) { |
112 media_source_delegate_.reset( | 124 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_MSE; |
113 new MediaSourceDelegate( | 125 } else if (media_stream_client_) { |
114 frame_, client_, proxy_, player_id_, media_log_)); | 126 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_STREAM; |
| 127 } |
| 128 |
| 129 if (media_source_type != MediaPlayerAndroid::MEDIA_SOURCE_URL) { |
115 // |media_source_delegate_| is owned, so Unretained() is safe here. | 130 // |media_source_delegate_| is owned, so Unretained() is safe here. |
116 media_source_delegate_->Initialize( | 131 media_source_delegate_.reset(new MediaSourceDelegate( |
117 scoped_media_source.Pass(), | 132 proxy_, |
| 133 player_id_, |
118 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, | 134 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, |
119 base::Unretained(this))); | 135 base::Unretained(this)))); |
| 136 if (media_source_type == MediaPlayerAndroid::MEDIA_SOURCE_MSE) { |
| 137 media_source_delegate_->InitializeMediaSource( |
| 138 frame_, client_, media_source, media_log_); |
| 139 } else if (media_source_type == MediaPlayerAndroid::MEDIA_SOURCE_STREAM) { |
| 140 media_source_delegate_->InitializeMediaStream(demuxer_); |
| 141 } |
120 } | 142 } |
| 143 #else |
| 144 if (media_source) |
| 145 media_source_type = MediaPlayerAndroid::MEDIA_SOURCE_MSE; |
121 #endif | 146 #endif |
122 | 147 |
| 148 InitializeMediaPlayer(url, media_source_type); |
| 149 } |
| 150 |
| 151 void WebMediaPlayerAndroid::InitializeMediaPlayer( |
| 152 const WebURL& url, |
| 153 MediaPlayerAndroid::MediaSourceType media_source_type) { |
123 url_ = url; | 154 url_ = url; |
124 GURL first_party_url = frame_->document().firstPartyForCookies(); | 155 GURL first_party_url = frame_->document().firstPartyForCookies(); |
125 if (proxy_) { | 156 if (proxy_) { |
126 proxy_->Initialize(player_id_, url_, media_source != NULL, first_party_url); | 157 proxy_->Initialize(player_id_, url, media_source_type, first_party_url); |
127 if (manager_->IsInFullscreen(frame_)) | 158 if (manager_->IsInFullscreen(frame_)) |
128 proxy_->EnterFullscreen(player_id_); | 159 proxy_->EnterFullscreen(player_id_); |
129 } | 160 } |
130 | 161 |
131 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 162 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
132 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 163 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
133 } | 164 } |
134 | 165 |
135 void WebMediaPlayerAndroid::cancelLoad() { | 166 void WebMediaPlayerAndroid::cancelLoad() { |
136 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
137 } | 168 } |
138 | 169 |
139 void WebMediaPlayerAndroid::play() { | 170 void WebMediaPlayerAndroid::play() { |
140 #if defined(GOOGLE_TV) | 171 #if defined(GOOGLE_TV) |
141 if (hasVideo() && needs_external_surface_) { | 172 if (hasVideo() && needs_external_surface_) { |
142 DCHECK(!needs_establish_peer_); | |
143 if (proxy_) | 173 if (proxy_) |
144 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 174 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
145 } | 175 } |
146 #endif | 176 #endif |
147 if (hasVideo() && needs_establish_peer_) | 177 if (hasVideo() && needs_establish_peer_) |
148 EstablishSurfaceTexturePeer(); | 178 EstablishSurfaceTexturePeer(); |
149 | 179 |
150 if (paused() && proxy_) | 180 if (paused() && proxy_) |
151 proxy_->Start(player_id_); | 181 proxy_->Start(player_id_); |
152 is_playing_ = true; | 182 is_playing_ = true; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 #if defined(GOOGLE_TV) | 487 #if defined(GOOGLE_TV) |
458 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( | 488 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( |
459 switches::kUseExternalVideoSurfaceThresholdInPixels); | 489 switches::kUseExternalVideoSurfaceThresholdInPixels); |
460 static int threshold = 0; | 490 static int threshold = 0; |
461 static bool parsed_arg = | 491 static bool parsed_arg = |
462 has_switch && | 492 has_switch && |
463 base::StringToInt( | 493 base::StringToInt( |
464 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 494 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
465 switches::kUseExternalVideoSurfaceThresholdInPixels), | 495 switches::kUseExternalVideoSurfaceThresholdInPixels), |
466 &threshold); | 496 &threshold); |
467 | |
468 if ((parsed_arg && threshold <= width * height) || | 497 if ((parsed_arg && threshold <= width * height) || |
469 // Use H/W surface for MSE as the content is protected. | 498 // Use H/W surface for MSE as the content is protected. |
470 media_source_delegate_) { | 499 media_source_delegate_) { |
471 needs_external_surface_ = true; | 500 needs_external_surface_ = true; |
472 SetNeedsEstablishPeer(false); | 501 SetNeedsEstablishPeer(false); |
473 if (!paused() && proxy_) | 502 if (!paused() && proxy_) |
474 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 503 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
475 } | 504 } |
476 #endif | 505 #endif |
477 | 506 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 676 |
648 // Return false when the geometry hasn't been changed from the last time. | 677 // Return false when the geometry hasn't been changed from the last time. |
649 if (last_computed_rect_ == *rect) | 678 if (last_computed_rect_ == *rect) |
650 return false; | 679 return false; |
651 | 680 |
652 // Store the changed geometry information when it is actually changed. | 681 // Store the changed geometry information when it is actually changed. |
653 last_computed_rect_ = *rect; | 682 last_computed_rect_ = *rect; |
654 return true; | 683 return true; |
655 } | 684 } |
656 | 685 |
657 WebMediaPlayer::MediaKeyException | 686 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( |
658 WebMediaPlayerAndroid::generateKeyRequest(const WebString& key_system, | 687 const WebString& key_system, |
659 const unsigned char* init_data, | 688 const unsigned char* init_data, |
660 unsigned init_data_length) { | 689 unsigned init_data_length) { |
661 if (media_source_delegate_) { | 690 if (media_source_delegate_) { |
662 return media_source_delegate_->GenerateKeyRequest( | 691 return media_source_delegate_->GenerateKeyRequest( |
663 key_system, init_data, init_data_length); | 692 key_system, init_data, init_data_length); |
664 } | 693 } |
665 return MediaKeyExceptionKeySystemNotSupported; | 694 return MediaKeyExceptionKeySystemNotSupported; |
666 } | 695 } |
667 | 696 |
668 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | 697 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( |
669 const WebString& key_system, | 698 const WebString& key_system, |
670 const unsigned char* key, | 699 const unsigned char* key, |
(...skipping 16 matching lines...) Expand all Loading... |
687 return MediaKeyExceptionKeySystemNotSupported; | 716 return MediaKeyExceptionKeySystemNotSupported; |
688 } | 717 } |
689 | 718 |
690 void WebMediaPlayerAndroid::OnReadFromDemuxer( | 719 void WebMediaPlayerAndroid::OnReadFromDemuxer( |
691 media::DemuxerStream::Type type, bool seek_done) { | 720 media::DemuxerStream::Type type, bool seek_done) { |
692 if (media_source_delegate_) | 721 if (media_source_delegate_) |
693 media_source_delegate_->OnReadFromDemuxer(type, seek_done); | 722 media_source_delegate_->OnReadFromDemuxer(type, seek_done); |
694 else | 723 else |
695 NOTIMPLEMENTED(); | 724 NOTIMPLEMENTED(); |
696 } | 725 } |
| 726 |
| 727 bool WebMediaPlayerAndroid::InjectMediaStream( |
| 728 MediaStreamClient* media_stream_client, |
| 729 media::Demuxer* demuxer, |
| 730 const base::Closure& destroy_demuxer_cb) { |
| 731 media_stream_client_ = media_stream_client; |
| 732 demuxer_ = demuxer; |
| 733 destroy_demuxer_cb_ = destroy_demuxer_cb; |
| 734 return true; |
| 735 } |
697 #endif | 736 #endif |
698 | 737 |
699 void WebMediaPlayerAndroid::enterFullscreen() { | 738 void WebMediaPlayerAndroid::enterFullscreen() { |
700 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { | 739 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { |
701 proxy_->EnterFullscreen(player_id_); | 740 proxy_->EnterFullscreen(player_id_); |
702 SetNeedsEstablishPeer(false); | 741 SetNeedsEstablishPeer(false); |
703 } | 742 } |
704 } | 743 } |
705 | 744 |
706 void WebMediaPlayerAndroid::exitFullscreen() { | 745 void WebMediaPlayerAndroid::exitFullscreen() { |
707 if (proxy_) | 746 if (proxy_) |
708 proxy_->ExitFullscreen(player_id_); | 747 proxy_->ExitFullscreen(player_id_); |
709 } | 748 } |
710 | 749 |
711 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 750 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
712 return manager_->CanEnterFullscreen(frame_); | 751 return manager_->CanEnterFullscreen(frame_); |
713 } | 752 } |
714 | 753 |
715 } // namespace webkit_media | 754 } // namespace webkit_media |
OLD | NEW |