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

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

Issue 1254293003: MediaCodecPlayer implementation (stage 4 - preroll) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-browserseek
Patch Set: Rebased Created 5 years, 4 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_decoder.h
diff --git a/media/base/android/media_codec_decoder.h b/media/base/android/media_codec_decoder.h
index aeaf4ec77957110bb4a0491e5b7f8f1ac7c78677..fce23c2988f101c6a1164ead9bd11f54def32602 100644
--- a/media/base/android/media_codec_decoder.h
+++ b/media/base/android/media_codec_decoder.h
@@ -177,13 +177,14 @@ class MediaCodecDecoder {
// the input. Decoder thread should not be running.
virtual void Flush();
- // Releases MediaCodecBridge.
- void ReleaseMediaCodec();
+ // Releases MediaCodecBridge and any related buffers or references.
+ virtual void ReleaseMediaCodec();
// Returns corresponding conditions.
bool IsPrefetchingOrPlaying() const;
bool IsStopped() const;
bool IsCompleted() const;
+ bool NeedsPreroll() const;
base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
@@ -194,8 +195,13 @@ class MediaCodecDecoder {
// Configures MediaCodec.
ConfigStatus Configure();
- // Starts the decoder thread and resumes the playback.
- bool Start(base::TimeDelta current_time);
+ // Starts the decoder for prerolling. This method starts the decoder thread.
+ bool Preroll(base::TimeDelta preroll_timestamp,
+ const base::Closure& preroll_done_cb);
+
+ // Starts the decoder after preroll is not needed, starting decoder thread
+ // if it has not started yet.
+ bool Start(base::TimeDelta start_timestamp);
// Stops the playback process synchronously. This method stops the decoder
// thread synchronously, and then releases all MediaCodec buffers.
@@ -209,10 +215,22 @@ class MediaCodecDecoder {
// Notification posted when asynchronous stop is done or playback completed.
void OnLastFrameRendered(bool completed);
+ // Notification posted when last prerolled frame has been returned to codec.
+ void OnPrerollDone();
+
// Puts the incoming data into AccessUnitQueue.
void OnDemuxerDataAvailable(const DemuxerData& data);
+ // For testing only. Returns true if the decoder is in kPrerolling state.
+ bool IsPrerollingForTests() const;
+
protected:
+ enum RenderMode {
+ kRenderSkip = 0,
+ kRenderAfterPreroll,
+ kRenderNow,
+ };
+
// Returns true if the new DemuxerConfigs requires MediaCodec
// reconfiguration.
virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& curr,
@@ -224,7 +242,10 @@ class MediaCodecDecoder {
// Associates PTS with device time so we can calculate delays.
// We use delays for video decoder only.
- virtual void SynchronizePTSWithTime(base::TimeDelta current_time) {}
+ virtual void AssociateCurrentTimeWithPTS(base::TimeDelta current_time) {}
+
+ // Invalidate delay calculation. We use delays for video decoder only.
+ virtual void DissociatePTSFromTime() {}
// Processes the change of the output format, varies by stream.
virtual void OnOutputFormatChanged() = 0;
@@ -233,16 +254,15 @@ class MediaCodecDecoder {
// a delayed task to do it at a later time,
virtual void Render(int buffer_index,
size_t size,
- bool render_output,
+ RenderMode render_mode,
base::TimeDelta pts,
bool eos_encountered) = 0;
// Returns the number of delayed task (we might have them for video).
virtual int NumDelayedRenderTasks() const;
- // Releases output buffers that are dequeued and not released yet (video)
- // if the |release| parameter is set and then remove the references to them.
- virtual void ClearDelayedBuffers(bool release) {}
+ // Releases output buffers that are dequeued and not released yet (video).
+ virtual void ReleaseDelayedBuffers() {}
#ifndef NDEBUG
// For video, checks that access unit is the key frame or stand-alone EOS.
@@ -254,6 +274,8 @@ class MediaCodecDecoder {
// Notifies the decoder if the frame is the last one.
void CheckLastFrame(bool eos_encountered, bool has_delayed_tasks);
+ const char* AsString(RenderMode render_mode);
+
// Protected data.
// Object for posting tasks on Media thread.
@@ -278,6 +300,8 @@ class MediaCodecDecoder {
kStopped = 0,
kPrefetching,
kPrefetched,
+ kPrerolling,
+ kPrerolled,
kRunning,
kStopping,
kInEmergencyStop,
@@ -321,6 +345,7 @@ class MediaCodecDecoder {
// These notifications are called on corresponding conditions.
base::Closure prefetch_done_cb_;
base::Closure starvation_cb_;
+ base::Closure preroll_done_cb_;
base::Closure stop_done_cb_;
base::Closure error_cb_;
@@ -330,10 +355,19 @@ class MediaCodecDecoder {
// Callback used to post OnCodecError method.
base::Closure internal_error_cb_;
+ // Callback for posting OnPrerollDone method.
+ base::Closure internal_preroll_done_cb_;
+
// Internal state.
DecoderState state_;
mutable base::Lock state_lock_;
+ // Preroll timestamp is set if we need preroll and cleared after we done it.
+ base::TimeDelta preroll_timestamp_;
+
+ // Indicates that playback should start with preroll.
+ bool needs_preroll_;
+
// Flag is set when the EOS is enqueued into MediaCodec. Reset by Flush.
bool eos_enqueued_;

Powered by Google App Engine
This is Rietveld 408576698