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 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; | 158 typedef base::Callback<void(int)> ErrorCallback; |
159 | 159 |
| 160 // For testing only. |
| 161 typedef base::Callback<void(DemuxerStream::Type, |
| 162 base::TimeDelta, |
| 163 base::TimeDelta)> DecodersTimeCallback; |
| 164 |
160 // Constructs a player with the given ID and demuxer. |manager| must outlive | 165 // Constructs a player with the given ID and demuxer. |manager| must outlive |
161 // the lifetime of this object. | 166 // the lifetime of this object. |
162 MediaCodecPlayer(int player_id, | 167 MediaCodecPlayer(int player_id, |
163 base::WeakPtr<MediaPlayerManager> manager, | 168 base::WeakPtr<MediaPlayerManager> manager, |
164 const RequestMediaResourcesCB& request_media_resources_cb, | 169 const RequestMediaResourcesCB& request_media_resources_cb, |
165 scoped_ptr<DemuxerAndroid> demuxer, | 170 scoped_ptr<DemuxerAndroid> demuxer, |
166 const GURL& frame_url); | 171 const GURL& frame_url); |
167 ~MediaCodecPlayer() override; | 172 ~MediaCodecPlayer() override; |
168 | 173 |
169 // A helper method that performs the media thread part of initialization. | 174 // A helper method that performs the media thread part of initialization. |
(...skipping 17 matching lines...) Expand all Loading... |
187 bool CanSeekBackward() override; | 192 bool CanSeekBackward() override; |
188 bool IsPlayerReady() override; | 193 bool IsPlayerReady() override; |
189 void SetCdm(BrowserCdm* cdm) override; | 194 void SetCdm(BrowserCdm* cdm) override; |
190 | 195 |
191 // DemuxerAndroidClient implementation. | 196 // DemuxerAndroidClient implementation. |
192 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; | 197 void OnDemuxerConfigsAvailable(const DemuxerConfigs& params) override; |
193 void OnDemuxerDataAvailable(const DemuxerData& params) override; | 198 void OnDemuxerDataAvailable(const DemuxerData& params) override; |
194 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; | 199 void OnDemuxerSeekDone(base::TimeDelta actual_browser_seek_time) override; |
195 void OnDemuxerDurationChanged(base::TimeDelta duration) override; | 200 void OnDemuxerDurationChanged(base::TimeDelta duration) override; |
196 | 201 |
| 202 // For testing only. |
| 203 void SetDecodersTimeCallbackForTests(DecodersTimeCallback cb); |
| 204 bool IsPrerollingForTests(DemuxerStream::Type type) const; |
| 205 |
197 private: | 206 private: |
198 // The state machine states. | 207 // The state machine states. |
199 enum PlayerState { | 208 enum PlayerState { |
200 kStatePaused, | 209 kStatePaused, |
201 kStateWaitingForConfig, | 210 kStateWaitingForConfig, |
202 kStatePrefetching, | 211 kStatePrefetching, |
203 kStatePlaying, | 212 kStatePlaying, |
204 kStateStopping, | 213 kStateStopping, |
205 kStateWaitingForSurface, | 214 kStateWaitingForSurface, |
206 kStateWaitingForSeek, | 215 kStateWaitingForSeek, |
(...skipping 25 matching lines...) Expand all Loading... |
232 void OnMediaMetadataChanged(base::TimeDelta duration, | 241 void OnMediaMetadataChanged(base::TimeDelta duration, |
233 const gfx::Size& video_size) override; | 242 const gfx::Size& video_size) override; |
234 | 243 |
235 // This method caches the current time and calls manager's OnTimeUpdate(). | 244 // This method caches the current time and calls manager's OnTimeUpdate(). |
236 void OnTimeUpdate(base::TimeDelta current_timestamp, | 245 void OnTimeUpdate(base::TimeDelta current_timestamp, |
237 base::TimeTicks current_time_ticks) override; | 246 base::TimeTicks current_time_ticks) override; |
238 | 247 |
239 // Callbacks from decoders | 248 // Callbacks from decoders |
240 void RequestDemuxerData(DemuxerStream::Type stream_type); | 249 void RequestDemuxerData(DemuxerStream::Type stream_type); |
241 void OnPrefetchDone(); | 250 void OnPrefetchDone(); |
| 251 void OnPrerollDone(); |
242 void OnStopDone(); | 252 void OnStopDone(); |
243 void OnError(); | 253 void OnError(); |
244 void OnStarvation(DemuxerStream::Type stream_type); | 254 void OnStarvation(DemuxerStream::Type stream_type); |
245 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, | 255 void OnTimeIntervalUpdate(DemuxerStream::Type stream_type, |
246 base::TimeDelta now_playing, | 256 base::TimeDelta now_playing, |
247 base::TimeDelta last_buffered); | 257 base::TimeDelta last_buffered); |
248 | 258 |
249 // Callbacks from video decoder | 259 // Callbacks from video decoder |
250 void OnVideoCodecCreated(); | 260 void OnVideoCodecCreated(); |
251 void OnVideoResolutionChanged(const gfx::Size& size); | 261 void OnVideoResolutionChanged(const gfx::Size& size); |
252 | 262 |
253 // Operations called from the state machine. | 263 // Operations called from the state machine. |
254 void SetState(PlayerState new_state); | 264 void SetState(PlayerState new_state); |
255 void SetPendingStart(bool need_to_start); | 265 void SetPendingStart(bool need_to_start); |
256 bool HasPendingStart() const; | 266 bool HasPendingStart() const; |
257 void SetPendingSeek(base::TimeDelta timestamp); | 267 void SetPendingSeek(base::TimeDelta timestamp); |
258 base::TimeDelta GetPendingSeek() const; | 268 base::TimeDelta GetPendingSeek() const; |
259 bool HasVideo() const; | 269 bool HasVideo() const; |
260 bool HasAudio() const; | 270 bool HasAudio() const; |
261 void SetDemuxerConfigs(const DemuxerConfigs& configs); | 271 void SetDemuxerConfigs(const DemuxerConfigs& configs); |
262 void StartPrefetchDecoders(); | 272 void StartPrefetchDecoders(); |
263 void StartPlaybackOrBrowserSeek(); | 273 void StartPlaybackOrBrowserSeek(); |
264 StartStatus StartPlaybackDecoders(); | 274 StartStatus StartPlaybackDecoders(); |
| 275 StartStatus ConfigureDecoders(); |
| 276 StartStatus MaybePrerollDecoders(base::TimeDelta current_time, |
| 277 bool* preroll_required); |
| 278 StartStatus StartDecoders(base::TimeDelta current_time); |
265 void StopDecoders(); | 279 void StopDecoders(); |
266 void RequestToStopDecoders(); | 280 void RequestToStopDecoders(); |
267 void RequestDemuxerSeek(base::TimeDelta seek_time, | 281 void RequestDemuxerSeek(base::TimeDelta seek_time, |
268 bool is_browser_seek = false); | 282 bool is_browser_seek = false); |
269 void ReleaseDecoderResources(); | 283 void ReleaseDecoderResources(); |
270 | 284 |
271 // Helper methods. | 285 // Helper methods. |
272 void CreateDecoders(); | 286 void CreateDecoders(); |
273 bool AudioFinished() const; | 287 bool AudioFinished() const; |
274 bool VideoFinished() const; | 288 bool VideoFinished() const; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 339 |
326 // Data associated with a seek in progress. | 340 // Data associated with a seek in progress. |
327 scoped_ptr<SeekInfo> seek_info_; | 341 scoped_ptr<SeekInfo> seek_info_; |
328 | 342 |
329 // Configuration data for the manager, accessed on the UI thread. | 343 // Configuration data for the manager, accessed on the UI thread. |
330 MediaMetadata metadata_cache_; | 344 MediaMetadata metadata_cache_; |
331 | 345 |
332 // Cached current time, accessed on UI thread. | 346 // Cached current time, accessed on UI thread. |
333 base::TimeDelta current_time_cache_; | 347 base::TimeDelta current_time_cache_; |
334 | 348 |
| 349 // For testing only. |
| 350 DecodersTimeCallback decoders_time_cb_; |
| 351 |
335 base::WeakPtr<MediaCodecPlayer> media_weak_this_; | 352 base::WeakPtr<MediaCodecPlayer> media_weak_this_; |
336 // NOTE: Weak pointers must be invalidated before all other member variables. | 353 // NOTE: Weak pointers must be invalidated before all other member variables. |
337 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; | 354 base::WeakPtrFactory<MediaCodecPlayer> media_weak_factory_; |
338 | 355 |
339 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); | 356 DISALLOW_COPY_AND_ASSIGN(MediaCodecPlayer); |
340 }; | 357 }; |
341 | 358 |
342 } // namespace media | 359 } // namespace media |
343 | 360 |
344 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ | 361 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_PLAYER_H_ |
OLD | NEW |