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

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

Issue 1128383003: Implementation of MediaCodecPlayer stage 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed stop procedure, fixed compilation 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_decoder.h
diff --git a/media/base/android/media_codec_decoder.h b/media/base/android/media_codec_decoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..9fb22c2d2a431c1c29e07ed9c5bba46809656db5
--- /dev/null
+++ b/media/base/android/media_codec_decoder.h
@@ -0,0 +1,161 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_
+#define MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_
+
+#include "base/android/scoped_java_ref.h"
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread.h"
+#include "base/time/time.h"
+#include "media/base/android/au_queue.h"
+#include "media/base/android/demuxer_stream_player_params.h"
+
+namespace media {
+
+class MediaCodecBridge;
+
qinmin 2015/05/12 23:58:23 extra line
Tima Vaisburd 2015/05/13 22:51:47 Removed.
+
+enum DecoderState {
+ STOPPED = 0,
+ PREFETCHING,
+ RUNNING,
+ STOPPING
+};
+
+class MediaCodecDecoder {
+ public:
+
+ enum ConfigStatus {
+ CONFIG_FAILURE = 0,
+ CONFIG_OK,
+ CONFIG_KEY_FRAME_REQUIRED,
+ };
+
+ typedef
+ base::Callback<void(base::TimeDelta, base::TimeDelta)> SetTimeCallback;
qinmin 2015/05/12 23:58:23 nit: spacing
Tima Vaisburd 2015/05/13 22:51:47 Done.
+
+ MediaCodecDecoder(
+ const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
+ const base::Closure& request_data_cb,
+ const base::Closure& starvation_cb,
+ const base::Closure& stop_done_cb,
+ const base::Closure& error_cb,
+ const SetTimeCallback& set_current_pts_cb,
+ const char* decoder_thread_name);
+ virtual ~MediaCodecDecoder();
+
+ virtual const char * class_name() const { return "Decoder"; }
qinmin 2015/05/12 23:58:23 nit: extra space after char
Tima Vaisburd 2015/05/13 22:51:47 Done.
+
+ virtual bool HasStream() const = 0;
+ virtual void ReleaseDecoderResources();
+ virtual void Flush();
+
+ void ReleaseMediaCodec();
+
+ bool IsPrefetchingOrPlaying() const;
+ bool IsStopped() const;
+ bool IsCompleted() const;
+
+ void SetDemuxerConfigs(const DemuxerConfigs& configs);
+
+ base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
+
+ void Prefetch(const base::Closure& prefetch_done_cb);
+ ConfigStatus Configure();
+ bool Start(base::TimeDelta current_time);
+ void SyncStop();
+ void RequestToStop();
+
+ void OnDemuxerDataAvailable(const DemuxerData& data);
+
+ void OnLastFrameRendered(bool completed);
+
+ protected:
+ virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& curr,
+ const DemuxerConfigs& next) const = 0;
+ virtual ConfigStatus ConfigureInternal() = 0;
+ virtual void Render(int buffer_index, size_t size, bool render_output,
+ base::TimeDelta pts, bool eos_encountered) = 0;
+ virtual int NumDelayedRenderTasks() const { return 0; }
+ virtual void ReleaseDelayedBuffers() {}
+
qinmin 2015/05/12 23:58:23 extra lines
Tima Vaisburd 2015/05/13 22:51:47 Removed
+
+
+ void PrefetchNextChunk();
+ void ProcessNextFrame();
+
+ // Returns false if there was MediaCodec error.
+ bool EnqueueInputBuffer(DecoderState state);
+
+ // Returns false if there was MediaCodec error.
+ bool DepleteOutputBufferQueue(DecoderState state, bool* eos_encountered);
+
+ DecoderState GetState() const;
+ void SetState(DecoderState state);
+
+ // Data.
+
+ // Object for posting tasks on Media thread.
+ scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
+
+ // Object for posting tasks on UI thread.
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
+
+ // Callback used to request more data.
+ base::Closure request_data_cb_;
+
+ // These notifications are called on corresponding conditions .
+ base::Closure prefetch_done_cb_;
+ base::Closure starvation_cb_;
+ base::Closure stop_done_cb_;
+ base::Closure error_cb_;
+ SetTimeCallback update_current_time_cb_;
+
+ // Controls Android MediaCodec
+ scoped_ptr<MediaCodecBridge> media_codec_bridge_;
+
+ // The queue of access units.
+ AUQueue au_queue_;
+
+ // We call MediaCodecBridge on this thread for both
+ // input and output buffers.
+ base::Thread decoder_thread_;
+
+ // Configuration received from demuxer
+ DemuxerConfigs configs_;
+ mutable base::Lock configs_lock_;
+
+ DecoderState state_;
+ mutable base::Lock state_lock_;
+
+ // Flag is set when the EOS is enqueued into MediaCodec.
+ bool eos_enqueued_;
+
+ // Flag is set when the EOS is received in MediaCodec output.
qinmin 2015/05/12 23:58:23 why all the members are protected here? if we don'
Tima Vaisburd 2015/05/13 22:51:47 Sorry I missed that. Separated protected and priva
+ bool completed_;
+
+ bool last_frame_posted_;
+
+ // Accociate presentation timestamps with time
+ base::TimeTicks start_time_ticks_;
+ base::TimeDelta start_pts_;
+
+ base::WeakPtr<MediaCodecDecoder> weak_this_;
+ // NOTE: Weak pointers must be invalidated before all other member variables.
+ base::WeakPtrFactory<MediaCodecDecoder> weak_factory_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MediaCodecDecoder);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_

Powered by Google App Engine
This is Rietveld 408576698