Chromium Code Reviews| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "media/base/android/media_player_bridge.h" | 9 #include "media/base/android/media_player_bridge.h" |
| 10 #include "net/base/mime_util.h" | 10 #include "net/base/mime_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 buffered_(1u), | 34 buffered_(1u), |
| 35 main_loop_(MessageLoop::current()), | 35 main_loop_(MessageLoop::current()), |
| 36 pending_seek_(0), | 36 pending_seek_(0), |
| 37 seeking_(false), | 37 seeking_(false), |
| 38 did_loading_progress_(false), | 38 did_loading_progress_(false), |
| 39 manager_(manager), | 39 manager_(manager), |
| 40 network_state_(WebMediaPlayer::NetworkStateEmpty), | 40 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 41 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 41 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 42 is_playing_(false), | 42 is_playing_(false), |
| 43 needs_establish_peer_(true), | 43 needs_establish_peer_(true), |
| 44 has_size_info_(false), | |
| 44 stream_texture_factory_(factory) { | 45 stream_texture_factory_(factory) { |
| 45 main_loop_->AddDestructionObserver(this); | 46 main_loop_->AddDestructionObserver(this); |
| 46 if (manager_) | 47 if (manager_) |
| 47 player_id_ = manager_->RegisterMediaPlayer(this); | 48 player_id_ = manager_->RegisterMediaPlayer(this); |
| 48 | 49 |
| 49 if (stream_texture_factory_.get()) { | 50 if (stream_texture_factory_.get()) { |
| 50 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 51 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 51 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 52 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
| 52 ReallocateVideoFrame(); | 53 ReallocateVideoFrame(); |
| 53 } | 54 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 // TODO(qinmin): Remove this from WebKit::WebMediaPlayer as it is never used. | 124 // TODO(qinmin): Remove this from WebKit::WebMediaPlayer as it is never used. |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool WebMediaPlayerAndroid::totalBytesKnown() { | 127 bool WebMediaPlayerAndroid::totalBytesKnown() { |
| 127 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
| 128 return false; | 129 return false; |
| 129 } | 130 } |
| 130 | 131 |
| 131 bool WebMediaPlayerAndroid::hasVideo() const { | 132 bool WebMediaPlayerAndroid::hasVideo() const { |
| 132 // If we have obtained video size information before, use it. | 133 // If we have obtained video size information before, use it. |
| 133 if (!natural_size_.isEmpty()) | 134 if (has_size_info_) |
| 134 return true; | 135 return !natural_size_.isEmpty(); |
| 135 | 136 |
| 136 // TODO(qinmin): need a better method to determine whether the current media | 137 // TODO(qinmin): need a better method to determine whether the current media |
| 137 // content contains video. Android does not provide any function to do | 138 // content contains video. Android does not provide any function to do |
| 138 // this. | 139 // this. |
| 139 // We don't know whether the current media content has video unless | 140 // We don't know whether the current media content has video unless |
| 140 // the player is prepared. If the player is not prepared, we fall back | 141 // the player is prepared. If the player is not prepared, we fall back |
| 141 // to the mime-type. There may be no mime-type on a redirect URL. | 142 // to the mime-type. There may be no mime-type on a redirect URL. |
| 142 // In that case, we conservatively assume it contains video so that | 143 // In that case, we conservatively assume it contains video so that |
| 143 // enterfullscreen call will not fail. | 144 // enterfullscreen call will not fail. |
| 144 if (!url_.has_path()) | 145 if (!url_.has_path()) |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 case MediaPlayerBridge::MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK: | 317 case MediaPlayerBridge::MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK: |
| 317 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); | 318 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); |
| 318 break; | 319 break; |
| 319 case MediaPlayerBridge::MEDIA_ERROR_INVALID_CODE: | 320 case MediaPlayerBridge::MEDIA_ERROR_INVALID_CODE: |
| 320 break; | 321 break; |
| 321 } | 322 } |
| 322 client_->repaint(); | 323 client_->repaint(); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { | 326 void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { |
| 327 has_size_info_ = true; | |
|
Miguel Garcia
2012/11/29 20:28:02
shouldn't you check that width or height is > 0?
qinmin
2012/11/29 20:39:33
No, we don't. This is called by the android media
Miguel Garcia
2012/11/29 20:43:36
OK, makes sense
On 2012/11/29 20:39:33, qinmin w
| |
| 326 if (natural_size_.width == width && natural_size_.height == height) | 328 if (natural_size_.width == width && natural_size_.height == height) |
| 327 return; | 329 return; |
| 328 | 330 |
| 329 natural_size_.width = width; | 331 natural_size_.width = width; |
| 330 natural_size_.height = height; | 332 natural_size_.height = height; |
| 331 ReallocateVideoFrame(); | 333 ReallocateVideoFrame(); |
| 332 } | 334 } |
| 333 | 335 |
| 334 void WebMediaPlayerAndroid::UpdateNetworkState( | 336 void WebMediaPlayerAndroid::UpdateNetworkState( |
| 335 WebMediaPlayer::NetworkState state) { | 337 WebMediaPlayer::NetworkState state) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 | 413 |
| 412 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 414 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
| 413 needs_establish_peer_ = needs_establish_peer; | 415 needs_establish_peer_ = needs_establish_peer; |
| 414 } | 416 } |
| 415 | 417 |
| 416 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 418 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
| 417 is_playing_ = is_playing; | 419 is_playing_ = is_playing; |
| 418 } | 420 } |
| 419 | 421 |
| 420 } // namespace webkit_media | 422 } // namespace webkit_media |
| OLD | NEW |