OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
7 | 7 |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // | | | | 150 // | | | |
151 // v | | | 151 // v | | |
152 // | | | 152 // | | |
153 // [ Stopping ] -----------------------> | | | 153 // [ Stopping ] -----------------------> | | |
154 // StopDone -- -- | 154 // StopDone -- -- |
155 // w/pending seek: | 155 // w/pending seek: |
156 // demuxer.RequestSeek | 156 // demuxer.RequestSeek |
157 | 157 |
158 namespace media { | 158 namespace media { |
159 | 159 |
160 class BrowserCdm; | |
161 class MediaCodecAudioDecoder; | 160 class MediaCodecAudioDecoder; |
162 class MediaCodecVideoDecoder; | 161 class MediaCodecVideoDecoder; |
163 | 162 |
164 class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid, | 163 class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid, |
165 public DemuxerAndroidClient { | 164 public DemuxerAndroidClient { |
166 public: | 165 public: |
167 // Typedefs for the notification callbacks | 166 // Typedefs for the notification callbacks |
168 typedef base::Callback<void(base::TimeDelta, const gfx::Size&)> | 167 typedef base::Callback<void(base::TimeDelta, const gfx::Size&)> |
169 MetadataChangedCallback; | 168 MetadataChangedCallback; |
170 | 169 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void SetVolume(double volume) override; | 206 void SetVolume(double volume) override; |
208 int GetVideoWidth() override; | 207 int GetVideoWidth() override; |
209 int GetVideoHeight() override; | 208 int GetVideoHeight() override; |
210 base::TimeDelta GetCurrentTime() override; | 209 base::TimeDelta GetCurrentTime() override; |
211 base::TimeDelta GetDuration() override; | 210 base::TimeDelta GetDuration() override; |
212 bool IsPlaying() override; | 211 bool IsPlaying() override; |
213 bool CanPause() override; | 212 bool CanPause() override; |
214 bool CanSeekForward() override; | 213 bool CanSeekForward() override; |
215 bool CanSeekBackward() override; | 214 bool CanSeekBackward() override; |
216 bool IsPlayerReady() override; | 215 bool IsPlayerReady() override; |
217 void SetCdm(BrowserCdm* cdm) override; | 216 void SetCdm(const scoped_refptr<MediaKeys>& cdm) override; |
218 | 217 |
219 // DemuxerAndroidClient implementation. | 218 // DemuxerAndroidClient implementation. |
220 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; | 219 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; |
221 void OnDemuxerDataAvailable(const DemuxerData& params) override; | 220 void OnDemuxerDataAvailable(const DemuxerData& params) override; |
222 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; | 221 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; |
223 void OnDemuxerDurationChanged(base::TimeDelta duration) override; | 222 void OnDemuxerDurationChanged(base::TimeDelta duration) override; |
224 | 223 |
225 // For testing only. | 224 // For testing only. |
226 void SetDecodersTimeCallbackForTests(DecodersTimeCallback cb); | 225 void SetDecodersTimeCallbackForTests(DecodersTimeCallback cb); |
227 void SetCodecCreatedCallbackForTests(CodecCreatedCallback cb); | 226 void SetCodecCreatedCallbackForTests(CodecCreatedCallback cb); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 void OnError(); | 292 void OnError(); |
294 void OnStarvation(DemuxerStream::Type stream_type); | 293 void OnStarvation(DemuxerStream::Type stream_type); |
295 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, | 294 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, |
296 base::TimeDelta now_playing, | 295 base::TimeDelta now_playing, |
297 base::TimeDelta last_buffered, | 296 base::TimeDelta last_buffered, |
298 bool postpone); | 297 bool postpone); |
299 | 298 |
300 // Callbacks from video decoder | 299 // Callbacks from video decoder |
301 void OnVideoResolutionChanged(const gfx::Size& size); | 300 void OnVideoResolutionChanged(const gfx::Size& size); |
302 | 301 |
303 // Callbacks from CDM | 302 // Callbacks from MediaDrmBridge. |
304 void OnMediaCryptoReady(MediaDrmBridge::JavaObjectPtr media_crypto, | 303 void OnMediaCryptoReady(MediaDrmBridge::JavaObjectPtr media_crypto, |
305 bool needs_protected_surface); | 304 bool needs_protected_surface); |
306 void OnKeyAdded(); | 305 void OnKeyAdded(); |
307 void OnCdmUnset(); | |
308 | 306 |
309 // Operations called from the state machine. | 307 // Operations called from the state machine. |
310 void SetState(PlayerState new_state); | 308 void SetState(PlayerState new_state); |
311 void SetPendingStart(bool need_to_start); | 309 void SetPendingStart(bool need_to_start); |
312 bool HasPendingStart() const; | 310 bool HasPendingStart() const; |
313 void SetPendingSeek(base::TimeDelta timestamp); | 311 void SetPendingSeek(base::TimeDelta timestamp); |
314 base::TimeDelta GetPendingSeek() const; | 312 base::TimeDelta GetPendingSeek() const; |
315 bool HasVideo() const; | 313 bool HasVideo() const; |
316 bool HasAudio() const; | 314 bool HasAudio() const; |
317 void SetDemuxerConfigs(const DemuxerConfigs& configs); | 315 void SetDemuxerConfigs(const DemuxerConfigs& configs); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 386 |
389 // Configuration data for the manager, accessed on the UI thread. | 387 // Configuration data for the manager, accessed on the UI thread. |
390 MediaMetadata metadata_cache_; | 388 MediaMetadata metadata_cache_; |
391 | 389 |
392 // Cached current time, accessed on UI thread. | 390 // Cached current time, accessed on UI thread. |
393 base::TimeDelta current_time_cache_; | 391 base::TimeDelta current_time_cache_; |
394 | 392 |
395 // For testing only. | 393 // For testing only. |
396 DecodersTimeCallback decoders_time_cb_; | 394 DecodersTimeCallback decoders_time_cb_; |
397 | 395 |
398 // DRM | 396 // Holds a ref-count to the CDM to keep |media_crypto_| valid. |
| 397 scoped_refptr<MediaKeys> cdm_; |
| 398 |
399 MediaDrmBridge::JavaObjectPtr media_crypto_; | 399 MediaDrmBridge::JavaObjectPtr media_crypto_; |
400 | 400 |
401 MediaDrmBridge* drm_bridge_; | |
402 int cdm_registration_id_; | 401 int cdm_registration_id_; |
403 | 402 |
404 // The flag is set when the player receives the error from decoder that the | 403 // The flag is set when the player receives the error from decoder that the |
405 // decoder needs a new decryption key. Cleared on starting the playback. | 404 // decoder needs a new decryption key. Cleared on starting the playback. |
406 bool key_is_required_; | 405 bool key_is_required_; |
407 | 406 |
408 // The flag is set after the new encryption key is added to MediaDrm. Cleared | 407 // The flag is set after the new encryption key is added to MediaDrm. Cleared |
409 // on starting the playback. | 408 // on starting the playback. |
410 bool key_is_added_; | 409 bool key_is_added_; |
411 | 410 |
412 // Gathers and reports playback quality statistics to UMA. | 411 // Gathers and reports playback quality statistics to UMA. |
413 // Use pointer to enable replacement of this object for tests. | 412 // Use pointer to enable replacement of this object for tests. |
414 scoped_ptr<MediaStatistics> media_stat_; | 413 scoped_ptr<MediaStatistics> media_stat_; |
415 | 414 |
416 base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 415 base::WeakPtr<MediaCodecPlayer> media_weak_this_; |
417 // NOTE: Weak pointers must be invalidated before all other member variables. | 416 // NOTE: Weak pointers must be invalidated before all other member variables. |
418 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 417 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; |
419 | 418 |
420 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 419 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); |
421 }; | 420 }; |
422 | 421 |
423 } // namespace media | 422 } // namespace media |
424 | 423 |
425 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 424 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
OLD | NEW |