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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_
7
8 #include "base/android/scoped_java_ref.h"
9 #include "base/callback.h"
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h"
16 #include "base/time/time.h"
17 #include "media/base/android/au_queue.h"
18 #include "media/base/android/demuxer_stream_player_params.h"
19
20 namespace media {
21
22 class MediaCodecBridge;
23
qinmin 2015/05/12 23:58:23 extra line
Tima Vaisburd 2015/05/13 22:51:47 Removed.
24
25 enum DecoderState {
26 STOPPED = 0,
27 PREFETCHING,
28 RUNNING,
29 STOPPING
30 };
31
32 class MediaCodecDecoder {
33 public:
34
35 enum ConfigStatus {
36 CONFIG_FAILURE = 0,
37 CONFIG_OK,
38 CONFIG_KEY_FRAME_REQUIRED,
39 };
40
41 typedef
42 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.
43
44 MediaCodecDecoder(
45 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
46 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
47 const base::Closure& request_data_cb,
48 const base::Closure& starvation_cb,
49 const base::Closure& stop_done_cb,
50 const base::Closure& error_cb,
51 const SetTimeCallback& set_current_pts_cb,
52 const char* decoder_thread_name);
53 virtual ~MediaCodecDecoder();
54
55 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.
56
57 virtual bool HasStream() const = 0;
58 virtual void ReleaseDecoderResources();
59 virtual void Flush();
60
61 void ReleaseMediaCodec();
62
63 bool IsPrefetchingOrPlaying() const;
64 bool IsStopped() const;
65 bool IsCompleted() const;
66
67 void SetDemuxerConfigs(const DemuxerConfigs& configs);
68
69 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
70
71 void Prefetch(const base::Closure& prefetch_done_cb);
72 ConfigStatus Configure();
73 bool Start(base::TimeDelta current_time);
74 void SyncStop();
75 void RequestToStop();
76
77 void OnDemuxerDataAvailable(const DemuxerData& data);
78
79 void OnLastFrameRendered(bool completed);
80
81 protected:
82 virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& curr,
83 const DemuxerConfigs& next) const = 0;
84 virtual ConfigStatus ConfigureInternal() = 0;
85 virtual void Render(int buffer_index, size_t size, bool render_output,
86 base::TimeDelta pts, bool eos_encountered) = 0;
87 virtual int NumDelayedRenderTasks() const { return 0; }
88 virtual void ReleaseDelayedBuffers() {}
89
qinmin 2015/05/12 23:58:23 extra lines
Tima Vaisburd 2015/05/13 22:51:47 Removed
90
91
92 void PrefetchNextChunk();
93 void ProcessNextFrame();
94
95 // Returns false if there was MediaCodec error.
96 bool EnqueueInputBuffer(DecoderState state);
97
98 // Returns false if there was MediaCodec error.
99 bool DepleteOutputBufferQueue(DecoderState state, bool* eos_encountered);
100
101 DecoderState GetState() const;
102 void SetState(DecoderState state);
103
104 // Data.
105
106 // Object for posting tasks on Media thread.
107 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
108
109 // Object for posting tasks on UI thread.
110 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
111
112 // Callback used to request more data.
113 base::Closure request_data_cb_;
114
115 // These notifications are called on corresponding conditions .
116 base::Closure prefetch_done_cb_;
117 base::Closure starvation_cb_;
118 base::Closure stop_done_cb_;
119 base::Closure error_cb_;
120 SetTimeCallback update_current_time_cb_;
121
122 // Controls Android MediaCodec
123 scoped_ptr<MediaCodecBridge> media_codec_bridge_;
124
125 // The queue of access units.
126 AUQueue au_queue_;
127
128 // We call MediaCodecBridge on this thread for both
129 // input and output buffers.
130 base::Thread decoder_thread_;
131
132 // Configuration received from demuxer
133 DemuxerConfigs configs_;
134 mutable base::Lock configs_lock_;
135
136 DecoderState state_;
137 mutable base::Lock state_lock_;
138
139 // Flag is set when the EOS is enqueued into MediaCodec.
140 bool eos_enqueued_;
141
142 // 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
143 bool completed_;
144
145 bool last_frame_posted_;
146
147 // Accociate presentation timestamps with time
148 base::TimeTicks start_time_ticks_;
149 base::TimeDelta start_pts_;
150
151 base::WeakPtr<MediaCodecDecoder> weak_this_;
152 // NOTE: Weak pointers must be invalidated before all other member variables.
153 base::WeakPtrFactory<MediaCodecDecoder> weak_factory_;
154
155 private:
156 DISALLOW_COPY_AND_ASSIGN(MediaCodecDecoder);
157 };
158
159 } // namespace media
160
161 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698