Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Unified Diff: media/base/android/media_codec_player.h

Issue 1128383003: Implementation of MediaCodecPlayer stage 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unneeded changed to MediaPlayerAndroid, style guide compliance Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/android/media_codec_player.h
diff --git a/media/base/android/media_codec_player.h b/media/base/android/media_codec_player.h
index 518adbbbd8b17874e398fde3d9481762db02b4d9..da2d24a33e11917b1f2f8f3487403f8ad53eff74 100644
--- a/media/base/android/media_codec_player.h
+++ b/media/base/android/media_codec_player.h
@@ -9,14 +9,22 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
+#include "base/time/default_tick_clock.h"
+
qinmin 2015/05/14 17:54:07 no new lines among includes
Tima Vaisburd 2015/05/15 00:12:40 Done.
#include "media/base/android/demuxer_android.h"
#include "media/base/android/media_player_android.h"
+#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
+#include "media/base/time_delta_interpolator.h"
+
#include "ui/gl/android/scoped_java_surface.h"
namespace media {
class BrowserCdm;
+class MediaCodecPlayerState;
+class MediaCodecAudioDecoder;
+class MediaCodecVideoDecoder;
// Returns the task runner for the media thread
MEDIA_EXPORT scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner();
@@ -29,10 +37,20 @@ MEDIA_EXPORT scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner();
class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid,
public DemuxerAndroidClient {
public:
+
+ // Typedefs for the notification callbacks
+ typedef base::Callback<
+ void (base::TimeDelta duration, int width, int height, bool success)>
qinmin 2015/05/14 17:54:07 indent by 4
Tima Vaisburd 2015/05/15 00:12:39 Done.
+ MetadataChangedCallback;
+
+ typedef base::Callback<
+ void (base::TimeDelta current_timestamp, base::TimeTicks current_ticks)>
qinmin 2015/05/14 17:54:07 ditto
Tima Vaisburd 2015/05/15 00:12:40 Done.
+ TimeUpdateCallback;
+
// Constructs a player with the given ID and demuxer. |manager| must outlive
// the lifetime of this object.
MediaCodecPlayer(int player_id,
- MediaPlayerManager* manager,
+ base::WeakPtr<MediaPlayerManager> manager,
const RequestMediaResourcesCB& request_media_resources_cb,
scoped_ptr<DemuxerAndroid> demuxer,
const GURL& frame_url);
@@ -65,13 +83,85 @@ class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid,
// Helper methods
void Initialize();
- void DestroySelf();
+
+ base::WeakPtr<MediaCodecPlayer> weak_ptr() const { return weak_this_; }
private:
+ // The state machine states can access the player.
+ friend class MediaCodecPlayerState;
+ friend class StateWaitingForConfig;
+ friend class StateWaitingForSurface;
+ friend class StatePaused;
+ friend class StatePrefetching;
+ friend class StatePlaying;
+ friend class StateStopping;
+ friend class StateWaitingForSeek;
+ friend class StateError;
+
+ // Callbacks from decoders
+ void RequestDemuxerData(DemuxerStream::Type stream_type);
+ void OnPrefetchDone();
+ void OnStarvation();
+ void OnStopDone();
+ void OnError();
+ void OnTimeIntervalUpdate(base::TimeDelta now_playing,
+ base::TimeDelta last_buffered);
+
+ // Operations called from the state machine.
+ void SetState(MediaCodecPlayerState* new_state);
+ void SetPendingSurface(gfx::ScopedJavaSurface surface);
+ bool HasPendingSurface();
+ void SetPendingStart(bool need_to_start);
+ bool HasPendingStart();
+ bool HasVideo();
+ bool HasAudio();
+ void SetDemuxerConfigs(const DemuxerConfigs& configs);
+ void StartPrefetchDecoders();
+ void StartPlaybackDecoders();
+ void StopDecoders();
+ void RequestToStopDecoders();
+ void ReleaseDecoderResources();
+
+ // Helper methods.
+ void CreateDecoders();
+ bool AudioFinished();
+ bool VideoFinished();
+
+ // Data.
+
// Object for posting tasks on UI thread.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
+ // Major components: demuxer, audio and video decoders.
scoped_ptr<DemuxerAndroid> demuxer_;
+ scoped_ptr<MediaCodecAudioDecoder> audio_decoder_;
+ scoped_ptr<MediaCodecVideoDecoder> video_decoder_;
+
+ // The state of the state machine.
+ MediaCodecPlayerState* state_;
+
+ // Notification callbacks, we call manager() with them.
+ base::Closure request_resources_cb_;
+ MetadataChangedCallback metadata_changed_cb_;
+ TimeUpdateCallback time_update_cb_;
+ base::Closure completion_cb_;
+
+ // Total duration reported by demuxer.
+ base::TimeDelta duration_;
+
+ // base::TickClock used by |interpolator_|.
+ base::DefaultTickClock default_tick_clock_;
+
+ // Tracks the most recent media time update and provides interpolated values
+ // as playback progresses.
+ TimeDeltaInterpolator interpolator_;
+
+ // |interpolator_| will be accessed from the UI and decoder threads
+ base::Lock interpolator_lock_;
+
+ // Pendng data to be picked up by the upcoming state.
+ gfx::ScopedJavaSurface pending_surface_;
+ bool pending_start_;
base::WeakPtr<MediaCodecPlayer> weak_this_;
// NOTE: Weak pointers must be invalidated before all other member variables.

Powered by Google App Engine
This is Rietveld 408576698