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 |
9 #include <map> | 10 #include <map> |
| 11 #include <memory> |
10 #include <string> | 12 #include <string> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/android/scoped_java_ref.h" | 15 #include "base/android/scoped_java_ref.h" |
14 #include "base/callback.h" | 16 #include "base/callback.h" |
15 #include "base/cancelable_callback.h" | 17 #include "base/cancelable_callback.h" |
16 #include "base/macros.h" | 18 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
20 #include "base/time/default_tick_clock.h" | 21 #include "base/time/default_tick_clock.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "media/base/android/demuxer_android.h" | 23 #include "media/base/android/demuxer_android.h" |
23 #include "media/base/android/media_codec_bridge.h" | 24 #include "media/base/android/media_codec_bridge.h" |
24 #include "media/base/android/media_decoder_job.h" | 25 #include "media/base/android/media_decoder_job.h" |
25 #include "media/base/android/media_drm_bridge.h" | 26 #include "media/base/android/media_drm_bridge.h" |
26 #include "media/base/android/media_player_android.h" | 27 #include "media/base/android/media_player_android.h" |
27 #include "media/base/android/media_statistics.h" | 28 #include "media/base/android/media_statistics.h" |
28 #include "media/base/media_export.h" | 29 #include "media/base/media_export.h" |
29 #include "media/base/time_delta_interpolator.h" | 30 #include "media/base/time_delta_interpolator.h" |
30 | 31 |
31 namespace media { | 32 namespace media { |
32 | 33 |
33 class AudioDecoderJob; | 34 class AudioDecoderJob; |
34 class VideoDecoderJob; | 35 class VideoDecoderJob; |
35 | 36 |
36 // This class handles media source extensions on Android. It uses Android | 37 // This class handles media source extensions on Android. It uses Android |
37 // MediaCodec to decode audio and video streams in two separate threads. | 38 // MediaCodec to decode audio and video streams in two separate threads. |
38 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, | 39 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid, |
39 public DemuxerAndroidClient { | 40 public DemuxerAndroidClient { |
40 public: | 41 public: |
41 // Constructs a player with the given ID and demuxer. |manager| must outlive | 42 // Constructs a player with the given ID and demuxer. |manager| must outlive |
42 // the lifetime of this object. | 43 // the lifetime of this object. |
43 MediaSourcePlayer( | 44 MediaSourcePlayer( |
44 int player_id, | 45 int player_id, |
45 MediaPlayerManager* manager, | 46 MediaPlayerManager* manager, |
46 const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, | 47 const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, |
47 scoped_ptr<DemuxerAndroid> demuxer, | 48 std::unique_ptr<DemuxerAndroid> demuxer, |
48 const GURL& frame_url, | 49 const GURL& frame_url, |
49 int media_session_id); | 50 int media_session_id); |
50 ~MediaSourcePlayer() override; | 51 ~MediaSourcePlayer() override; |
51 | 52 |
52 // MediaPlayerAndroid implementation. | 53 // MediaPlayerAndroid implementation. |
53 void SetVideoSurface(gfx::ScopedJavaSurface surface) override; | 54 void SetVideoSurface(gfx::ScopedJavaSurface surface) override; |
54 void Start() override; | 55 void Start() override; |
55 void Pause(bool is_media_related_action) override; | 56 void Pause(bool is_media_related_action) override; |
56 void SeekTo(base::TimeDelta timestamp) override; | 57 void SeekTo(base::TimeDelta timestamp) override; |
57 void Release() override; | 58 void Release() override; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 187 |
187 static const char* GetEventName(PendingEventFlags event); | 188 static const char* GetEventName(PendingEventFlags event); |
188 bool IsEventPending(PendingEventFlags event) const; | 189 bool IsEventPending(PendingEventFlags event) const; |
189 void SetPendingEvent(PendingEventFlags event); | 190 void SetPendingEvent(PendingEventFlags event); |
190 void ClearPendingEvent(PendingEventFlags event); | 191 void ClearPendingEvent(PendingEventFlags event); |
191 | 192 |
192 // If the player is previously waiting for audio or video decoder job, retry | 193 // If the player is previously waiting for audio or video decoder job, retry |
193 // creating the decoders identified by |audio| and |video|. | 194 // creating the decoders identified by |audio| and |video|. |
194 void RetryDecoderCreation(bool audio, bool video); | 195 void RetryDecoderCreation(bool audio, bool video); |
195 | 196 |
196 scoped_ptr<DemuxerAndroid> demuxer_; | 197 std::unique_ptr<DemuxerAndroid> demuxer_; |
197 | 198 |
198 // Pending event that the player needs to do. | 199 // Pending event that the player needs to do. |
199 unsigned pending_event_; | 200 unsigned pending_event_; |
200 | 201 |
201 // Stats about the media. | 202 // Stats about the media. |
202 base::TimeDelta duration_; | 203 base::TimeDelta duration_; |
203 bool playing_; | 204 bool playing_; |
204 | 205 |
205 // base::TickClock used by |interpolator_|. | 206 // base::TickClock used by |interpolator_|. |
206 base::DefaultTickClock default_tick_clock_; | 207 base::DefaultTickClock default_tick_clock_; |
(...skipping 18 matching lines...) Expand all Loading... |
225 bool doing_browser_seek_; | 226 bool doing_browser_seek_; |
226 | 227 |
227 // If already doing a browser seek when a regular seek request arrives, | 228 // If already doing a browser seek when a regular seek request arrives, |
228 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger | 229 // these fields remember the regular seek so OnDemuxerSeekDone() can trigger |
229 // it when the browser seek is done. These are only valid when | 230 // it when the browser seek is done. These are only valid when |
230 // |SEEK_EVENT_PENDING| is pending. | 231 // |SEEK_EVENT_PENDING| is pending. |
231 bool pending_seek_; | 232 bool pending_seek_; |
232 base::TimeDelta pending_seek_time_; | 233 base::TimeDelta pending_seek_time_; |
233 | 234 |
234 // Decoder jobs. | 235 // Decoder jobs. |
235 scoped_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_; | 236 std::unique_ptr<AudioDecoderJob, MediaDecoderJob::Deleter> audio_decoder_job_; |
236 scoped_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_; | 237 std::unique_ptr<VideoDecoderJob, MediaDecoderJob::Deleter> video_decoder_job_; |
237 | 238 |
238 // Track the most recent preroll target. Decoder re-creation needs this to | 239 // Track the most recent preroll target. Decoder re-creation needs this to |
239 // resume any in-progress preroll. | 240 // resume any in-progress preroll. |
240 base::TimeDelta preroll_timestamp_; | 241 base::TimeDelta preroll_timestamp_; |
241 | 242 |
242 // A cancelable task that is posted when the audio decoder starts requesting | 243 // A cancelable task that is posted when the audio decoder starts requesting |
243 // new data. This callback runs if no data arrives before the timeout period | 244 // new data. This callback runs if no data arrives before the timeout period |
244 // elapses. | 245 // elapses. |
245 base::CancelableClosure decoder_starvation_callback_; | 246 base::CancelableClosure decoder_starvation_callback_; |
246 | 247 |
(...skipping 20 matching lines...) Expand all Loading... |
267 bool is_waiting_for_video_decoder_; | 268 bool is_waiting_for_video_decoder_; |
268 | 269 |
269 // Test-only callback for hooking the completion of the next decode cycle. | 270 // Test-only callback for hooking the completion of the next decode cycle. |
270 base::Closure decode_callback_for_testing_; | 271 base::Closure decode_callback_for_testing_; |
271 | 272 |
272 // Whether audio or video decoder is in the process of prerolling. | 273 // Whether audio or video decoder is in the process of prerolling. |
273 bool prerolling_; | 274 bool prerolling_; |
274 | 275 |
275 // Gathers and reports playback quality statistics to UMA. | 276 // Gathers and reports playback quality statistics to UMA. |
276 // Use pointer to enable replacement of this object for tests. | 277 // Use pointer to enable replacement of this object for tests. |
277 scoped_ptr<MediaStatistics> media_stat_; | 278 std::unique_ptr<MediaStatistics> media_stat_; |
278 | 279 |
279 // Weak pointer passed to media decoder jobs for callbacks. | 280 // Weak pointer passed to media decoder jobs for callbacks. |
280 base::WeakPtr<MediaSourcePlayer> weak_this_; | 281 base::WeakPtr<MediaSourcePlayer> weak_this_; |
281 // NOTE: Weak pointers must be invalidated before all other member variables. | 282 // NOTE: Weak pointers must be invalidated before all other member variables. |
282 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; | 283 base::WeakPtrFactory<MediaSourcePlayer> weak_factory_; |
283 | 284 |
284 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); | 285 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); |
285 }; | 286 }; |
286 | 287 |
287 } // namespace media | 288 } // namespace media |
288 | 289 |
289 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 290 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
OLD | NEW |