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

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: marking XXX for issues should be resolved before committing. 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/non_thread_safe.h"
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 thread_checker.h, instead?
dwkang1 2013/02/04 14:08:26 Done.
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;
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 // Notifies the client that the decoder was reset.
81 void NotifyResetDone();
82
83 // Used to DCHECK that we are called on the correct thread.
84 base::ThreadChecker thread_checker_;
85
86 // To expose client callbacks from VideoDecodeAccelerator.
87 Client* client_;
88
89 // Callback to set the correct gl context.
90 base::Callback<bool(void)> make_context_current_;
91
92 // Codec type. Used when we configure media codec.
93 media::MediaCodecBridge::Codec codec_;
94
95 // The current state of this class. For now, this is used for setting error
96 // state.
97 State state_;
98
99 // This map maintains the picture buffers passed the client for decoding.
100 // The key is the picture buffer id.
101 typedef std::map<int32, media::PictureBuffer> OutputBufferMap;
102 OutputBufferMap output_picture_buffers_;
103
104 // This keeps the free picture buffer ids which can be used for sending
105 // decoded frames to the client.
106 std::queue<int32> free_picture_ids_;
107
108 // The low-level decoder which Android SDK provides.
109 scoped_ptr<media::MediaCodecBridge> media_codec_;
110
111 // A container of texture. Used to set a texture to |media_codec_|.
112 scoped_refptr<SurfaceTextureBridge> surface_texture_;
113
114 // The texture id which is set to |surface_texture_|.
115 uint32 surface_texture_id_;
116
117 // Set to true after requesting picture buffers to the client.
118 bool picturebuffers_requested_;
119
120 // Set to true when the polling against |media_codec_| is on.
121 bool io_task_is_running_;
122
123 // The resolution of the stream.
124 gfx::Size size_;
125
126 // Encoded bitstream buffers to be passed to media codec, queued until a input
127 // buffer is available.
128 typedef std::queue<media::BitstreamBuffer> BitstreamBufferList;
129 BitstreamBufferList pending_bitstream_buffers_;
130
131 // bitstream buffer ids that |media_codec_| is being processing.
132 std::queue<int32> bitstream_buffer_ids_in_decoder_;
133
134 // A helper which copies the given external texture
135 // (GL_TEXTURE_EXTERNAL_OES) to the target texture (GL_TEXTURE_2D).
136 scoped_ptr<Gles2ExternalTextureCopier> texture_copier_;
137 };
138
139 } // namespace content
140
141 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698