OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SOURCE_PLAYER_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 MediaPlayerManager* manager, | 43 MediaPlayerManager* manager, |
44 const RequestMediaResourcesCB& request_media_resources_cb, | 44 const RequestMediaResourcesCB& request_media_resources_cb, |
45 const ReleaseMediaResourcesCB& release_media_resources_cb, | 45 const ReleaseMediaResourcesCB& release_media_resources_cb, |
46 scoped_ptr<DemuxerAndroid> demuxer); | 46 scoped_ptr<DemuxerAndroid> demuxer); |
47 virtual ~MediaSourcePlayer(); | 47 virtual ~MediaSourcePlayer(); |
48 | 48 |
49 // MediaPlayerAndroid implementation. | 49 // MediaPlayerAndroid implementation. |
50 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) OVERRIDE; | 50 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) OVERRIDE; |
51 virtual void Start() OVERRIDE; | 51 virtual void Start() OVERRIDE; |
52 virtual void Pause(bool is_media_related_action ALLOW_UNUSED) OVERRIDE; | 52 virtual void Pause(bool is_media_related_action ALLOW_UNUSED) OVERRIDE; |
53 virtual void SeekTo(const base::TimeDelta& timestamp) OVERRIDE; | 53 virtual void SeekTo(base::TimeDelta timestamp) OVERRIDE; |
54 virtual void Release() OVERRIDE; | 54 virtual void Release() OVERRIDE; |
55 virtual void SetVolume(double volume) OVERRIDE; | 55 virtual void SetVolume(double volume) OVERRIDE; |
56 virtual int GetVideoWidth() OVERRIDE; | 56 virtual int GetVideoWidth() OVERRIDE; |
57 virtual int GetVideoHeight() OVERRIDE; | 57 virtual int GetVideoHeight() OVERRIDE; |
58 virtual base::TimeDelta GetCurrentTime() OVERRIDE; | 58 virtual base::TimeDelta GetCurrentTime() OVERRIDE; |
59 virtual base::TimeDelta GetDuration() OVERRIDE; | 59 virtual base::TimeDelta GetDuration() OVERRIDE; |
60 virtual bool IsPlaying() OVERRIDE; | 60 virtual bool IsPlaying() OVERRIDE; |
61 virtual bool CanPause() OVERRIDE; | 61 virtual bool CanPause() OVERRIDE; |
62 virtual bool CanSeekForward() OVERRIDE; | 62 virtual bool CanSeekForward() OVERRIDE; |
63 virtual bool CanSeekBackward() OVERRIDE; | 63 virtual bool CanSeekBackward() OVERRIDE; |
64 virtual bool IsPlayerReady() OVERRIDE; | 64 virtual bool IsPlayerReady() OVERRIDE; |
65 virtual void SetDrmBridge(MediaDrmBridge* drm_bridge) OVERRIDE; | 65 virtual void SetDrmBridge(MediaDrmBridge* drm_bridge) OVERRIDE; |
66 virtual void OnKeyAdded() OVERRIDE; | 66 virtual void OnKeyAdded() OVERRIDE; |
67 virtual bool IsSurfaceInUse() const OVERRIDE; | 67 virtual bool IsSurfaceInUse() const OVERRIDE; |
68 | 68 |
69 // DemuxerAndroidClient implementation. | 69 // DemuxerAndroidClient implementation. |
70 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; | 70 virtual void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) OVERRIDE; |
71 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; | 71 virtual void OnDemuxerDataAvailable(const DemuxerData& params) OVERRIDE; |
72 virtual void OnDemuxerSeekDone( | 72 virtual void OnDemuxerSeekDone( |
73 const base::TimeDelta& actual_browser_seek_time) OVERRIDE; | 73 base::TimeDelta actual_browser_seek_time) OVERRIDE; |
74 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; | 74 virtual void OnDemuxerDurationChanged(base::TimeDelta duration) OVERRIDE; |
75 | 75 |
76 private: | 76 private: |
77 // Update the current timestamp. | 77 // Update the current timestamp. |
78 void UpdateTimestamps(const base::TimeDelta& presentation_timestamp, | 78 void UpdateTimestamps(base::TimeDelta presentation_timestamp, |
79 size_t audio_output_bytes); | 79 size_t audio_output_bytes); |
80 | 80 |
81 // Helper function for starting media playback. | 81 // Helper function for starting media playback. |
82 void StartInternal(); | 82 void StartInternal(); |
83 | 83 |
84 // Playback is completed for one channel. | 84 // Playback is completed for one channel. |
85 void PlaybackCompleted(bool is_audio); | 85 void PlaybackCompleted(bool is_audio); |
86 | 86 |
87 // Called when the decoder finishes its task. | 87 // Called when the decoder finishes its task. |
88 void MediaDecoderCallback( | 88 void MediaDecoderCallback( |
89 bool is_audio, MediaCodecStatus status, | 89 bool is_audio, MediaCodecStatus status, |
90 const base::TimeDelta& presentation_timestamp, | 90 base::TimeDelta presentation_timestamp, |
91 size_t audio_output_bytes); | 91 size_t audio_output_bytes); |
92 | 92 |
93 // Gets MediaCrypto object from |drm_bridge_|. | 93 // Gets MediaCrypto object from |drm_bridge_|. |
94 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 94 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
95 | 95 |
96 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. | 96 // Callback to notify that MediaCrypto is ready in |drm_bridge_|. |
97 void OnMediaCryptoReady(); | 97 void OnMediaCryptoReady(); |
98 | 98 |
99 // Handle pending events if all the decoder jobs are not currently decoding. | 99 // Handle pending events if all the decoder jobs are not currently decoding. |
100 void ProcessPendingEvents(); | 100 void ProcessPendingEvents(); |
101 | 101 |
102 // Helper method to clear any pending |SURFACE_CHANGE_EVENT_PENDING| | 102 // Helper method to clear any pending |SURFACE_CHANGE_EVENT_PENDING| |
103 // and reset |video_decoder_job_| to null. | 103 // and reset |video_decoder_job_| to null. |
104 void ResetVideoDecoderJob(); | 104 void ResetVideoDecoderJob(); |
| 105 void ResetAudioDecoderJob(); |
105 | 106 |
106 // Helper methods to configure the decoder jobs. | 107 // Helper methods to configure the decoder jobs. |
107 void ConfigureVideoDecoderJob(); | 108 void ConfigureVideoDecoderJob(); |
108 void ConfigureAudioDecoderJob(); | 109 void ConfigureAudioDecoderJob(); |
109 | 110 |
110 // Flush the decoders and clean up all the data needs to be decoded. | 111 // Flush the decoders and clean up all the data needs to be decoded. |
111 void ClearDecodingData(); | 112 void ClearDecodingData(); |
112 | 113 |
113 // Called to decode more data. | 114 // Called to decode more data. |
114 void DecodeMoreAudio(); | 115 void DecodeMoreAudio(); |
(...skipping 11 matching lines...) Expand all Loading... |
126 // Determine seekability based on duration. | 127 // Determine seekability based on duration. |
127 bool Seekable(); | 128 bool Seekable(); |
128 | 129 |
129 // Called when the |decoder_starvation_callback_| times out. | 130 // Called when the |decoder_starvation_callback_| times out. |
130 void OnDecoderStarved(); | 131 void OnDecoderStarved(); |
131 | 132 |
132 // Starts the |decoder_starvation_callback_| task with the timeout value. | 133 // Starts the |decoder_starvation_callback_| task with the timeout value. |
133 // |presentation_timestamp| - The presentation timestamp used for starvation | 134 // |presentation_timestamp| - The presentation timestamp used for starvation |
134 // timeout computations. It represents the timestamp of the last piece of | 135 // timeout computations. It represents the timestamp of the last piece of |
135 // decoded data. | 136 // decoded data. |
136 void StartStarvationCallback(const base::TimeDelta& presentation_timestamp); | 137 void StartStarvationCallback(base::TimeDelta presentation_timestamp); |
137 | 138 |
138 // Schedules a seek event in |pending_events_| and calls StopDecode() on all | 139 // Schedules a seek event in |pending_events_| and calls StopDecode() on all |
139 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets | 140 // the MediaDecoderJobs. Sets clock to |seek_time|, and resets |
140 // |pending_seek_|. There must not already be a seek event in | 141 // |pending_seek_|. There must not already be a seek event in |
141 // |pending_events_|. | 142 // |pending_events_|. |
142 void ScheduleSeekEventAndStopDecoding(const base::TimeDelta& seek_time); | 143 void ScheduleSeekEventAndStopDecoding(base::TimeDelta seek_time); |
143 | 144 |
144 // Schedules a browser seek event. We must not currently be processing any | 145 // Schedules a browser seek event. We must not currently be processing any |
145 // seek. Note that there is possibility that browser seek of renderer demuxer | 146 // seek. Note that there is possibility that browser seek of renderer demuxer |
146 // may unexpectedly stall due to lack of buffered data at or after the browser | 147 // may unexpectedly stall due to lack of buffered data at or after the browser |
147 // seek time. | 148 // seek time. |
148 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data | 149 // TODO(wolenetz): Instead of doing hack browser seek, replay cached data |
149 // since last keyframe. See http://crbug.com/304234. | 150 // since last keyframe. See http://crbug.com/304234. |
150 void BrowserSeekToCurrentTime(); | 151 void BrowserSeekToCurrentTime(); |
151 | 152 |
152 // Helper function to set the volume. | 153 // Helper function to set the volume. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // the player should pause. When a new key is added (OnKeyAdded()), we should | 276 // the player should pause. When a new key is added (OnKeyAdded()), we should |
276 // try to start playback again. | 277 // try to start playback again. |
277 bool is_waiting_for_key_; | 278 bool is_waiting_for_key_; |
278 | 279 |
279 // Test-only callback for hooking the completion of the next decode cycle. | 280 // Test-only callback for hooking the completion of the next decode cycle. |
280 base::Closure decode_callback_for_testing_; | 281 base::Closure decode_callback_for_testing_; |
281 | 282 |
282 // Whether |surface_| is currently used by the player. | 283 // Whether |surface_| is currently used by the player. |
283 bool is_surface_in_use_; | 284 bool is_surface_in_use_; |
284 | 285 |
| 286 // Whether there are pending data requests by the decoder. |
| 287 bool has_pending_audio_data_request_; |
| 288 bool has_pending_video_data_request_; |
| 289 |
285 friend class MediaSourcePlayerTest; | 290 friend class MediaSourcePlayerTest; |
286 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); | 291 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); |
287 }; | 292 }; |
288 | 293 |
289 } // namespace media | 294 } // namespace media |
290 | 295 |
291 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 296 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
OLD | NEW |