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

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

Powered by Google App Engine
This is Rietveld 408576698