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

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

Issue 11973010: AndroidVDA by using Android's MediaCodec API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: using flush() for reset(). Created 7 years, 10 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 (c) 2013 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 CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
7
8 #include <dlfcn.h>
9 #include <map>
10 #include <queue>
11 #include <string>
12 #include <vector>
13
14 #include "base/compiler_specific.h"
15 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h"
17 #include "media/base/android/media_codec_bridge.h"
18 #include "media/video/video_decode_accelerator.h"
19
20 class MessageLoop;
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 unused
dwkang1 2013/02/07 14:01:36 Done.
21
22 namespace content {
23
24 class SurfaceTextureBridge;
25 class Gles2ExternalTextureCopier;
26
27 // A VideoDecodeAccelerator implementation for Android.
28 // This class decodes the input encoded stream by using Android's MediaCodec
29 // class. http://developer.android.com/reference/android/media/MediaCodec.html
30 class CONTENT_EXPORT AndroidVideoDecodeAccelerator :
31 public media::VideoDecodeAccelerator {
32 public:
33 // Does not take ownership of |client| which must outlive |*this|.
34 AndroidVideoDecodeAccelerator(
35 media::VideoDecodeAccelerator::Client* client,
36 const base::Callback<bool(void)>& make_context_current);
37
38 // media::VideoDecodeAccelerator implementation.
39 bool Initialize(media::VideoCodecProfile profile) OVERRIDE;
40 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE;
41 virtual void AssignPictureBuffers(
42 const std::vector<media::PictureBuffer>& buffers) OVERRIDE;
43 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE;
44 void Flush() OVERRIDE;
45 void Reset() OVERRIDE;
46 void Destroy() OVERRIDE;
47
48 private:
49 enum State {
50 NO_ERROR,
51 ERROR,
52 };
53
54 static const base::TimeDelta kDecodePollDelay;
55
56 virtual ~AndroidVideoDecodeAccelerator();
57
58 // Configures |media_codec_| with the given codec parameters from the client.
59 void ConfigureMediaCodec();
60
61 // Sends the current picture on the surface to the client.
62 void SendCurrentSurfaceToClient(int32 bitstream_id);
63
64 // Does pending IO tasks if any. Once this is called, it polls |media_codec_|
65 // until it finishes pending tasks. For the polling, |kDecodePollDelay| is
66 // used.
67 void DoIOTask();
68
69 // Feeds input data to |media_codec_|. This checks
70 // |pending_bitstream_buffers_| and queues a buffer to |media_codec_|.
71 void QueueInput();
72
73 // Dequeues output from |media_codec_| and feeds the decoded frame to the
74 // client.
75 void DequeueOutput();
76
77 // Notifies the client that initialize was completed.
78 void NotifyInitializeDone();
79
80 // Requests picture buffers from the client.
81 void RequestPictureBuffers();
82
83 // Notifies the client about the availability of a picture.
84 void NotifyPictureReady(const media::Picture& picture);
85
86 // Notifies the client that the input buffer identifed by input_buffer_id has
87 // been processed.
88 void NotifyEndOfBitstreamBuffer(int input_buffer_id);
89
90 // Notifies the client that the decoder was flushed.
91 void NotifyFlushDone();
92
93 // Notifies the client that the decoder was reset.
94 void NotifyResetDone();
95
96 // Notifies about decoding errors.
97 void NotifyError(media::VideoDecodeAccelerator::Error error);
98
99 // Used to DCHECK that we are called on the correct thread.
100 base::ThreadChecker thread_checker_;
101
102 // To expose client callbacks from VideoDecodeAccelerator.
103 Client* client_;
104
105 // Callback to set the correct gl context.
106 base::Callback<bool(void)> make_context_current_;
107
108 // Codec type. Used when we configure media codec.
109 media::MediaCodecBridge::Codec codec_;
110
111 // The current state of this class. For now, this is used for setting error
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 s/for/only for/
dwkang1 2013/02/07 14:01:36 Done.
112 // state.
113 State state_;
114
115 // This map maintains the picture buffers passed the client for decoding.
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 s/passed/passed to/
dwkang1 2013/02/07 14:01:36 Done.
116 // The key is the picture buffer id.
117 typedef std::map<int32, media::PictureBuffer> OutputBufferMap;
118 OutputBufferMap output_picture_buffers_;
119
120 // This keeps the free picture buffer ids which can be used for sending
121 // decoded frames to the client.
122 std::queue<int32> free_picture_ids_;
123
124 // The low-level decoder which Android SDK provides.
125 scoped_ptr<media::MediaCodecBridge> media_codec_;
126
127 // A container of texture. Used to set a texture to |media_codec_|.
128 scoped_refptr<SurfaceTextureBridge> surface_texture_;
129
130 // The texture id which is set to |surface_texture_|.
131 uint32 surface_texture_id_;
132
133 // Set to true after requesting picture buffers to the client.
134 bool picturebuffers_requested_;
135
136 // Set to true when DoIOTask is in the message loop.
137 bool io_task_is_posted_;
138
139 // Set to true when decoder outputs EOS (end of stream).
140 bool decoder_met_eos_;
141
142 // The resolution of the stream.
143 gfx::Size size_;
144
145 // Encoded bitstream buffers to be passed to media codec, queued until a input
146 // buffer is available.
147 typedef std::queue<media::BitstreamBuffer> BitstreamBufferList;
148 BitstreamBufferList pending_bitstream_buffers_;
149
150 // Indicates the number of bytes already passed to the decoder in the first
151 // buffer in |pending_bitstream_buffers_|.
152 size_t num_bytes_used_in_the_pending_buffer_;
153
154 // A helper which copies the given external texture
155 // (GL_TEXTURE_EXTERNAL_OES) to the target texture (GL_TEXTURE_2D).
156 scoped_ptr<Gles2ExternalTextureCopier> texture_copier_;
157 };
158
159 } // namespace content
160
161 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698