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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Typedefs for the notification callbacks | 148 // Typedefs for the notification callbacks |
149 typedef base::Callback<void(base::TimeDelta, const gfx::Size&)> | 149 typedef base::Callback<void(base::TimeDelta, const gfx::Size&)> |
150 MetadataChangedCallback; | 150 MetadataChangedCallback; |
151 | 151 |
152 typedef base::Callback<void(base::TimeDelta, base::TimeTicks)> | 152 typedef base::Callback<void(base::TimeDelta, base::TimeTicks)> |
153 TimeUpdateCallback; | 153 TimeUpdateCallback; |
154 | 154 |
155 typedef base::Callback<void(const base::TimeDelta& current_timestamp)> | 155 typedef base::Callback<void(const base::TimeDelta& current_timestamp)> |
156 SeekDoneCallback; | 156 SeekDoneCallback; |
157 | 157 |
| 158 typedef base::Callback<void(int)> ErrorCallback; |
| 159 |
158 // Constructs a player with the given ID and demuxer. |manager| must outlive | 160 // Constructs a player with the given ID and demuxer. |manager| must outlive |
159 // the lifetime of this object. | 161 // the lifetime of this object. |
160 MediaCodecPlayer(int player_id, | 162 MediaCodecPlayer(int player_id, |
161 base::WeakPtr<MediaPlayerManager> manager, | 163 base::WeakPtr<MediaPlayerManager> manager, |
162 const RequestMediaResourcesCB& request_media_resources_cb, | 164 const RequestMediaResourcesCB& request_media_resources_cb, |
163 scoped_ptr<DemuxerAndroid> demuxer, | 165 scoped_ptr<DemuxerAndroid> demuxer, |
164 const GURL& frame_url); | 166 const GURL& frame_url); |
165 ~MediaCodecPlayer() override; | 167 ~MediaCodecPlayer() override; |
166 | 168 |
167 // A helper method that performs the media thread part of initialization. | 169 // A helper method that performs the media thread part of initialization. |
(...skipping 20 matching lines...) Expand all Loading... |
188 | 190 |
189 // DemuxerAndroidClient implementation. | 191 // DemuxerAndroidClient implementation. |
190 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; | 192 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; |
191 void OnDemuxerDataAvailable(const DemuxerData& params) override; | 193 void OnDemuxerDataAvailable(const DemuxerData& params) override; |
192 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; | 194 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; |
193 void OnDemuxerDurationChanged(base::TimeDelta duration) override; | 195 void OnDemuxerDurationChanged(base::TimeDelta duration) override; |
194 | 196 |
195 private: | 197 private: |
196 // The state machine states. | 198 // The state machine states. |
197 enum PlayerState { | 199 enum PlayerState { |
198 STATE_PAUSED, | 200 kStatePaused, |
199 STATE_WAITING_FOR_CONFIG, | 201 kStateWaitingForConfig, |
200 STATE_PREFETCHING, | 202 kStatePrefetching, |
201 STATE_PLAYING, | 203 kStatePlaying, |
202 STATE_STOPPING, | 204 kStateStopping, |
203 STATE_WAITING_FOR_SURFACE, | 205 kStateWaitingForSurface, |
204 STATE_WAITING_FOR_SEEK, | 206 kStateWaitingForSeek, |
205 STATE_ERROR, | 207 kStateError, |
| 208 }; |
| 209 |
| 210 enum StartStatus { |
| 211 kStartOk = 0, |
| 212 kStartBrowserSeekRequired, |
| 213 kStartFailed, |
206 }; | 214 }; |
207 | 215 |
208 // Cached values for the manager. | 216 // Cached values for the manager. |
209 struct MediaMetadata { | 217 struct MediaMetadata { |
210 base::TimeDelta duration; | 218 base::TimeDelta duration; |
211 gfx::Size video_size; | 219 gfx::Size video_size; |
212 }; | 220 }; |
213 | 221 |
214 // Information about current seek in progress. | 222 // Information about current seek in progress. |
215 struct SeekInfo { | 223 struct SeekInfo { |
(...skipping 21 matching lines...) Expand all Loading... |
237 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, | 245 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, |
238 base::TimeDelta now_playing, | 246 base::TimeDelta now_playing, |
239 base::TimeDelta last_buffered); | 247 base::TimeDelta last_buffered); |
240 | 248 |
241 // Callbacks from video decoder | 249 // Callbacks from video decoder |
242 void OnVideoCodecCreated(); | 250 void OnVideoCodecCreated(); |
243 void OnVideoResolutionChanged(const gfx::Size& size); | 251 void OnVideoResolutionChanged(const gfx::Size& size); |
244 | 252 |
245 // Operations called from the state machine. | 253 // Operations called from the state machine. |
246 void SetState(PlayerState new_state); | 254 void SetState(PlayerState new_state); |
247 void SetPendingSurface(gfx::ScopedJavaSurface surface); | |
248 bool HasPendingSurface() const; | |
249 void SetPendingStart(bool need_to_start); | 255 void SetPendingStart(bool need_to_start); |
250 bool HasPendingStart() const; | 256 bool HasPendingStart() const; |
251 void SetPendingSeek(base::TimeDelta timestamp); | 257 void SetPendingSeek(base::TimeDelta timestamp); |
252 base::TimeDelta GetPendingSeek() const; | 258 base::TimeDelta GetPendingSeek() const; |
253 bool HasVideo() const; | 259 bool HasVideo() const; |
254 bool HasAudio() const; | 260 bool HasAudio() const; |
255 void SetDemuxerConfigs(const DemuxerConfigs& configs); | 261 void SetDemuxerConfigs(const DemuxerConfigs& configs); |
256 void StartPrefetchDecoders(); | 262 void StartPrefetchDecoders(); |
257 void StartPlaybackDecoders(); | 263 void StartPlaybackOrBrowserSeek(); |
| 264 StartStatus StartPlaybackDecoders(); |
258 void StopDecoders(); | 265 void StopDecoders(); |
259 void RequestToStopDecoders(); | 266 void RequestToStopDecoders(); |
260 void RequestDemuxerSeek(base::TimeDelta seek_time, | 267 void RequestDemuxerSeek(base::TimeDelta seek_time, |
261 bool is_browser_seek = false); | 268 bool is_browser_seek = false); |
262 void ReleaseDecoderResources(); | 269 void ReleaseDecoderResources(); |
263 | 270 |
264 // Helper methods. | 271 // Helper methods. |
265 void CreateDecoders(); | 272 void CreateDecoders(); |
266 bool AudioFinished() const; | 273 bool AudioFinished() const; |
267 bool VideoFinished() const; | 274 bool VideoFinished() const; |
(...skipping 12 matching lines...) Expand all Loading... |
280 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; | 287 scoped_ptr<MediaCodecVideoDecoder> video_decoder_; |
281 | 288 |
282 // The state of the state machine. | 289 // The state of the state machine. |
283 PlayerState state_; | 290 PlayerState state_; |
284 | 291 |
285 // Notification callbacks, they call MediaPlayerManager. | 292 // Notification callbacks, they call MediaPlayerManager. |
286 base::Closure request_resources_cb_; | 293 base::Closure request_resources_cb_; |
287 TimeUpdateCallback time_update_cb_; | 294 TimeUpdateCallback time_update_cb_; |
288 base::Closure completion_cb_; | 295 base::Closure completion_cb_; |
289 SeekDoneCallback seek_done_cb_; | 296 SeekDoneCallback seek_done_cb_; |
| 297 ErrorCallback error_cb_; |
290 | 298 |
291 // A callback that updates metadata cache and calls the manager. | 299 // A callback that updates metadata cache and calls the manager. |
292 MetadataChangedCallback metadata_changed_cb_; | 300 MetadataChangedCallback metadata_changed_cb_; |
293 | 301 |
294 // We call the base class' AttachListener() and DetachListener() methods on UI | 302 // We call the base class' AttachListener() and DetachListener() methods on UI |
295 // thread with these callbacks. | 303 // thread with these callbacks. |
296 base::Closure attach_listener_cb_; | 304 base::Closure attach_listener_cb_; |
297 base::Closure detach_listener_cb_; | 305 base::Closure detach_listener_cb_; |
298 | 306 |
299 // Error callback is posted by decoders or by this class itself if we cannot | 307 // Error callback is posted by decoders or by this class itself if we cannot |
300 // configure or start decoder. | 308 // configure or start decoder. |
301 base::Closure error_cb_; | 309 base::Closure internal_error_cb_; |
302 | 310 |
303 // Total duration reported by demuxer. | 311 // Total duration reported by demuxer. |
304 base::TimeDelta duration_; | 312 base::TimeDelta duration_; |
305 | 313 |
306 // base::TickClock used by |interpolator_|. | 314 // base::TickClock used by |interpolator_|. |
307 base::DefaultTickClock default_tick_clock_; | 315 base::DefaultTickClock default_tick_clock_; |
308 | 316 |
309 // Tracks the most recent media time update and provides interpolated values | 317 // Tracks the most recent media time update and provides interpolated values |
310 // as playback progresses. | 318 // as playback progresses. |
311 TimeDeltaInterpolator interpolator_; | 319 TimeDeltaInterpolator interpolator_; |
(...skipping 15 matching lines...) Expand all Loading... |
327 base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 335 base::WeakPtr<MediaCodecPlayer> media_weak_this_; |
328 // NOTE: Weak pointers must be invalidated before all other member variables. | 336 // NOTE: Weak pointers must be invalidated before all other member variables. |
329 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 337 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; |
330 | 338 |
331 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 339 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); |
332 }; | 340 }; |
333 | 341 |
334 } // namespace media | 342 } // namespace media |
335 | 343 |
336 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 344 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
OLD | NEW |