| 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..8c3aa94d3caa20f3df80371117a17faff3492014 100644
|
| --- a/media/base/android/media_codec_player.h
|
| +++ b/media/base/android/media_codec_player.h
|
| @@ -9,30 +9,85 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/threading/thread.h"
|
| +#include "base/time/default_tick_clock.h"
|
| #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/gfx/geometry/size.h"
|
| #include "ui/gl/android/scoped_java_surface.h"
|
|
|
| +// The MediaCodecPlayer class implements the media player by using Android's
|
| +// MediaCodec. It differs from MediaSourcePlayer in that it removes most
|
| +// processing away from the UI thread: it uses a dedicated Media thread to
|
| +// receive the data and to handle the commands.
|
| +
|
| +/*
|
| + State machine diagram.
|
| +
|
| +
|
| + --------------------------> Paused
|
| + | StopDone:
|
| + | ^ |
|
| + | | |
|
| + | Pause: | | Start: dec.Prefetch
|
| + | | |
|
| + | | |
|
| + | | |
|
| + | | v PrefetchDone,
|
| + | no surface:
|
| + | ------------------> Prefetching --------------> Waiting
|
| + | | for surface
|
| + | | | /
|
| + | | | /
|
| + | | StopDone w/ | /
|
| + | | pending start: | PrefetchDone: /
|
| + | | dec.Prefetch | dec.Start /
|
| + | | | / SetSurface:
|
| + | | | / dec.Start
|
| + | | | /
|
| + | | v /
|
| + | | /
|
| + | | Playing <----------/
|
| + | |
|
| + | | |
|
| + | | |
|
| + | | | Pause: dec.RequestToStop
|
| + | | |
|
| + | | |
|
| + | | v
|
| + | |
|
| + -------------------------- Stopping
|
| +
|
| + */
|
| +
|
| namespace media {
|
|
|
| class BrowserCdm;
|
| +class MediaCodecAudioDecoder;
|
| +class MediaCodecVideoDecoder;
|
|
|
| // Returns the task runner for the media thread
|
| MEDIA_EXPORT scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner();
|
|
|
| -
|
| -// This class implements the media player using Android's MediaCodec.
|
| -// It differs from MediaSourcePlayer in that it removes most
|
| -// processing away from UI thread: it uses a dedicated Media thread
|
| -// to receive the data and to handle commands.
|
| class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid,
|
| public DemuxerAndroidClient {
|
| public:
|
| +
|
| + // Typedefs for the notification callbacks
|
| + typedef base::Callback<
|
| + void (base::TimeDelta duration, const gfx::Size& video_size)>
|
| + MetadataChangedCallback;
|
| +
|
| + typedef base::Callback<
|
| + void (base::TimeDelta current_timestamp, base::TimeTicks current_ticks)>
|
| + 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 +120,115 @@ class MEDIA_EXPORT MediaCodecPlayer : public MediaPlayerAndroid,
|
|
|
| // Helper methods
|
| void Initialize();
|
| - void DestroySelf();
|
| +
|
| + base::WeakPtr<MediaCodecPlayer> weak_ptr() const { return weak_this_; }
|
| +
|
| + protected:
|
| + // MediaPlayerAndroid implementation.
|
| + // This method caches the data and calls manager's OnMediaMetadataChanged().
|
| + void OnMediaMetadataChanged(
|
| + base::TimeDelta duration, const gfx::Size& video_size) override;
|
|
|
| private:
|
| + // The state machine states.
|
| + enum PlayerState {
|
| + STATE_PAUSED,
|
| + STATE_WAITING_FOR_CONFIG,
|
| + STATE_PREFETCHING,
|
| + STATE_PLAYING,
|
| + STATE_STOPPING,
|
| + STATE_WAITING_FOR_SURFACE,
|
| + STATE_WAITING_FOR_SEEK,
|
| + STATE_ERROR,
|
| + };
|
| +
|
| + // Cached valued for the manager, accessed on the UI thread.
|
| + struct MediaMetadata {
|
| + base::TimeDelta duration;
|
| + gfx::Size video_size;
|
| + // Have some defined aspect ratio by default.
|
| + MediaMetadata() : duration(), video_size(320, 240) {}
|
| + };
|
| +
|
| + // 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(PlayerState 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();
|
| +
|
| + static const char* AsString(PlayerState state);
|
| +
|
| + // 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.
|
| + PlayerState state_;
|
| +
|
| + // Notification callbacks, they call MediaPlayerManager.
|
| + base::Closure request_resources_cb_;
|
| + TimeUpdateCallback time_update_cb_;
|
| + base::Closure completion_cb_;
|
| +
|
| + // A callback that updates metadata cache and calls the manager.
|
| + MetadataChangedCallback metadata_changed_cb_;
|
| +
|
| + // We call the base class' AttachListener() and DetachListener() methods on UI
|
| + // thread with these callbacks.
|
| + base::Closure attach_listener_cb_;
|
| + base::Closure detach_listener_cb_;
|
| +
|
| + // Error callback might be posted internally
|
| + base::Closure error_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_;
|
| +
|
| + // Configuration data for the manager, accessed on the UI thread.
|
| + MediaMetadata metadata_cache_;
|
|
|
| base::WeakPtr<MediaCodecPlayer> weak_this_;
|
| // NOTE: Weak pointers must be invalidated before all other member variables.
|
|
|