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

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

Powered by Google App Engine
This is Rietveld 408576698