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

Side by Side Diff: content/common/gpu/media/android_video_decode_accelerator.h

Issue 1313913003: Begin refactor of AVDA to support zero-copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor updates. Created 5 years, 3 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ 5 #ifndef CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ 6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
watk 2015/08/28 21:52:05 Doesn't look like we need timer.h. Looks like ther
liberato (no reviews please) 2015/09/04 17:59:46 Done.
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "content/common/gpu/media/android_video_decode_accelerator_base.h"
18 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 19 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
20 #include "media/base/android/media_codec_bridge.h" 21 #include "media/base/android/media_codec_bridge.h"
21 #include "media/video/video_decode_accelerator.h" 22 #include "media/video/video_decode_accelerator.h"
22 23
23 namespace gfx {
24 class SurfaceTexture;
25 }
26
27 namespace content { 24 namespace content {
28 // A VideoDecodeAccelerator implementation for Android. 25 // A VideoDecodeAccelerator implementation for Android.
29 // This class decodes the input encoded stream by using Android's MediaCodec 26 // This class decodes the input encoded stream by using Android's MediaCodec
30 // class. http://developer.android.com/reference/android/media/MediaCodec.html 27 // class. http://developer.android.com/reference/android/media/MediaCodec.html
31 class CONTENT_EXPORT AndroidVideoDecodeAccelerator 28 class CONTENT_EXPORT AndroidVideoDecodeAccelerator
32 : public media::VideoDecodeAccelerator { 29 : public AndroidVideoDecodeAcceleratorBase {
33 public: 30 public:
34 // Does not take ownership of |client| which must outlive |*this|. 31 // Does not take ownership of |client| which must outlive |*this|.
watk 2015/08/28 21:52:04 Comment is out of date
liberato (no reviews please) 2015/09/04 17:59:47 Done.
35 AndroidVideoDecodeAccelerator( 32 AndroidVideoDecodeAccelerator(
36 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, 33 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder,
37 const base::Callback<bool(void)>& make_context_current); 34 const base::Callback<bool(void)>& make_context_current);
38 35
39 // media::VideoDecodeAccelerator implementation. 36 // media::VideoDecodeAccelerator implementation.
40 bool Initialize(media::VideoCodecProfile profile, Client* client) override;
41 void Decode(const media::BitstreamBuffer& bitstream_buffer) override;
42 void AssignPictureBuffers(
43 const std::vector<media::PictureBuffer>& buffers) override;
44 void ReusePictureBuffer(int32 picture_buffer_id) override;
45 void Flush() override;
46 void Reset() override;
47 void Destroy() override; 37 void Destroy() override;
48 bool CanDecodeOnIOThread() override;
49
50 static media::VideoDecodeAccelerator::SupportedProfiles
51 GetSupportedProfiles();
52 38
53 private: 39 private:
54 enum State {
55 NO_ERROR,
56 ERROR,
57 };
58
59 static const base::TimeDelta kDecodePollDelay;
60
61 ~AndroidVideoDecodeAccelerator() override; 40 ~AndroidVideoDecodeAccelerator() override;
62 41
63 // Configures |media_codec_| with the given codec parameters from the client. 42 protected: // AndroidVideoDecodeAcceleratorBase
64 bool ConfigureMediaCodec(); 43 uint32 GetNumPictureBuffers() const override;
44 uint32 GetTextureTarget() const override;
45 void AssignCurrentSurfaceToPictureBuffer(int32 codec_buffer_index,
46 const media::PictureBuffer&) override;
65 47
66 // Sends the current picture on the surface to the client. 48 private:
67 void SendCurrentSurfaceToClient(int32 bitstream_id);
68
69 // Does pending IO tasks if any. Once this is called, it polls |media_codec_|
70 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is
71 // used.
72 void DoIOTask();
73
74 // Feeds input data to |media_codec_|. This checks
75 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|.
76 void QueueInput();
77
78 // Dequeues output from |media_codec_| and feeds the decoded frame to the
79 // client.
80 void DequeueOutput();
81
82 // Requests picture buffers from the client.
83 void RequestPictureBuffers();
84
85 // Notifies the client about the availability of a picture.
86 void NotifyPictureReady(const media::Picture& picture);
87
88 // Notifies the client that the input buffer identifed by input_buffer_id has
89 // been processed.
90 void NotifyEndOfBitstreamBuffer(int input_buffer_id);
91
92 // Notifies the client that the decoder was flushed.
93 void NotifyFlushDone();
94
95 // Notifies the client that the decoder was reset.
96 void NotifyResetDone();
97
98 // Notifies about decoding errors.
99 void NotifyError(media::VideoDecodeAccelerator::Error error);
100
101 // Used to DCHECK that we are called on the correct thread.
102 base::ThreadChecker thread_checker_;
103
104 // To expose client callbacks from VideoDecodeAccelerator.
105 Client* client_;
106
107 // Callback to set the correct gl context.
108 base::Callback<bool(void)> make_context_current_;
109
110 // Codec type. Used when we configure media codec.
111 media::VideoCodec codec_;
112
113 // The current state of this class. For now, this is used only for setting
114 // error state.
115 State state_;
116
117 // This map maintains the picture buffers passed to the client for decoding.
118 // The key is the picture buffer id.
119 typedef std::map<int32, media::PictureBuffer> OutputBufferMap;
120 OutputBufferMap output_picture_buffers_;
121
122 // This keeps the free picture buffer ids which can be used for sending
123 // decoded frames to the client.
124 std::queue<int32> free_picture_ids_;
125
126 // Picture buffer ids which have been dismissed and not yet re-assigned. Used
127 // to ignore ReusePictureBuffer calls that were in flight when the
128 // DismissPictureBuffer call was made.
129 std::set<int32> dismissed_picture_ids_;
130
131 // The low-level decoder which Android SDK provides.
132 scoped_ptr<media::VideoCodecBridge> media_codec_;
133
134 // A container of texture. Used to set a texture to |media_codec_|.
135 scoped_refptr<gfx::SurfaceTexture> surface_texture_;
136
137 // The texture id which is set to |surface_texture_|.
138 uint32 surface_texture_id_;
139
140 // Set to true after requesting picture buffers to the client.
141 bool picturebuffers_requested_;
142
143 // The resolution of the stream.
144 gfx::Size size_;
145
146 // Encoded bitstream buffers to be passed to media codec, queued until an
147 // input buffer is available, along with the time when they were first
148 // enqueued.
149 typedef std::queue<std::pair<media::BitstreamBuffer, base::Time> >
150 PendingBitstreamBuffers;
151 PendingBitstreamBuffers pending_bitstream_buffers_;
152
153 // Keeps track of bitstream ids notified to the client with
154 // NotifyEndOfBitstreamBuffer() before getting output from the bitstream.
155 std::list<int32> bitstreams_notified_in_advance_;
156
157 // Owner of the GL context. Used to restore the context state.
158 base::WeakPtr<gpu::gles2::GLES2Decoder> gl_decoder_;
159
160 // Used for copy the texture from |surface_texture_| to picture buffers. 49 // Used for copy the texture from |surface_texture_| to picture buffers.
161 scoped_ptr<gpu::CopyTextureCHROMIUMResourceManager> copier_; 50 scoped_ptr<gpu::CopyTextureCHROMIUMResourceManager> copier_;
162
163 // Repeating timer responsible for draining pending IO to the codec.
164 base::RepeatingTimer<AndroidVideoDecodeAccelerator> io_timer_;
165
166 // WeakPtrFactory for posting tasks back to |this|.
167 base::WeakPtrFactory<AndroidVideoDecodeAccelerator> weak_this_factory_;
168
169 friend class AndroidVideoDecodeAcceleratorTest;
170 }; 51 };
171 52
172 } // namespace content 53 } // namespace content
173 54
174 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_ 55 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698