OLD | NEW |
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 MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <set> | |
12 #include <string> | 11 #include <string> |
13 #include <vector> | 12 #include <vector> |
14 | 13 |
15 #include "base/compiler_specific.h" | |
16 #include "base/macros.h" | 14 #include "base/macros.h" |
17 #include "base/time/time.h" | 15 #include "base/time/time.h" |
18 #include "media/base/android/media_codec_direction.h" | |
19 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
20 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
21 | 18 |
22 namespace media { | 19 namespace media { |
23 | 20 |
24 class EncryptionScheme; | 21 class EncryptionScheme; |
25 struct SubsampleEntry; | 22 struct SubsampleEntry; |
26 | 23 |
27 // These must be in sync with MediaCodecBridge.MEDIA_CODEC_XXX constants in | 24 // These must be in sync with MediaCodecBridge.MEDIA_CODEC_XXX constants in |
28 // MediaCodecBridge.java. | 25 // MediaCodecBridge.java. |
29 enum MediaCodecStatus { | 26 enum MediaCodecStatus { |
30 MEDIA_CODEC_OK, | 27 MEDIA_CODEC_OK, |
31 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, | 28 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, |
32 MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER, | 29 MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER, |
33 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, | 30 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, |
34 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, | 31 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, |
35 MEDIA_CODEC_INPUT_END_OF_STREAM, | |
36 MEDIA_CODEC_OUTPUT_END_OF_STREAM, | |
37 MEDIA_CODEC_NO_KEY, | 32 MEDIA_CODEC_NO_KEY, |
38 MEDIA_CODEC_ABORT, | |
39 MEDIA_CODEC_ERROR | 33 MEDIA_CODEC_ERROR |
40 }; | 34 }; |
41 | 35 |
42 // Interface for wrapping different Android MediaCodec implementations. For | 36 // An interface for a bridge to an Android MediaCodec. |
43 // more information on Android MediaCodec, check | |
44 // http://developer.android.com/reference/android/media/MediaCodec.html | |
45 // Note: MediaCodec is only available on JB and greater. | |
46 class MEDIA_EXPORT MediaCodecBridge { | 37 class MEDIA_EXPORT MediaCodecBridge { |
47 public: | 38 public: |
48 virtual ~MediaCodecBridge(); | 39 MediaCodecBridge() = default; |
| 40 virtual ~MediaCodecBridge() = default; |
49 | 41 |
50 // Calls start() against the media codec instance. Returns whether media | 42 // Calls start() against the media codec instance. Returns whether media |
51 // codec was successfully started. | 43 // codec was successfully started. |
52 virtual bool Start() = 0; | 44 virtual bool Start() = 0; |
53 | 45 |
54 // Finishes the decode/encode session. The instance remains active | 46 // Finishes the decode/encode session. The instance remains active |
55 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy | 47 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy |
56 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not | 48 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not |
57 // work on some devices. For reliability, Stop() -> delete and recreate new | 49 // work on some devices. For reliability, Stop() -> delete and recreate new |
58 // instance -> StartAudio/Video() is recommended. | 50 // instance -> StartAudio/Video() is recommended. |
(...skipping 25 matching lines...) Expand all Loading... |
84 // Submits a byte array to the given input buffer. Call this after getting an | 76 // Submits a byte array to the given input buffer. Call this after getting an |
85 // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the | 77 // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the |
86 // input buffer has already been populated (but still obey |size|). | 78 // input buffer has already been populated (but still obey |size|). |
87 // |data_size| must be less than kint32max (because Java). | 79 // |data_size| must be less than kint32max (because Java). |
88 virtual MediaCodecStatus QueueInputBuffer( | 80 virtual MediaCodecStatus QueueInputBuffer( |
89 int index, | 81 int index, |
90 const uint8_t* data, | 82 const uint8_t* data, |
91 size_t data_size, | 83 size_t data_size, |
92 base::TimeDelta presentation_time) = 0; | 84 base::TimeDelta presentation_time) = 0; |
93 | 85 |
94 // Similar to the above call, but submits a buffer that is encrypted. Note: | 86 // As above but for encrypted buffers. NULL |subsamples| indicates the |
95 // NULL |subsamples| indicates the whole buffer is encrypted. If |data| is | 87 // whole buffer is encrypted. |
96 // NULL, assume the input buffer has already been populated (but still obey | 88 virtual MediaCodecStatus QueueSecureInputBuffer( |
97 // |data_size|). |data_size| must be less than kint32max (because Java). | |
98 MediaCodecStatus QueueSecureInputBuffer( | |
99 int index, | 89 int index, |
100 const uint8_t* data, | 90 const uint8_t* data, |
101 size_t data_size, | 91 size_t data_size, |
102 const std::string& key_id, | 92 const std::string& key_id, |
103 const std::string& iv, | 93 const std::string& iv, |
104 const std::vector<SubsampleEntry>& subsamples, | 94 const std::vector<SubsampleEntry>& subsamples, |
105 const EncryptionScheme& encryption_scheme, | 95 const EncryptionScheme& encryption_scheme, |
106 base::TimeDelta presentation_time); | |
107 | |
108 // Same QueueSecureInputBuffer overriden for the use with | |
109 // AndroidVideoDecodeAccelerator and MediaCodecAudioDecoder. TODO(timav): | |
110 // remove this method and keep only the one above after we switch to the | |
111 // Spitzer pipeline. | |
112 virtual MediaCodecStatus QueueSecureInputBuffer( | |
113 int index, | |
114 const uint8_t* data, | |
115 size_t data_size, | |
116 const std::vector<char>& key_id, | |
117 const std::vector<char>& iv, | |
118 const SubsampleEntry* subsamples, | |
119 int subsamples_size, | |
120 const EncryptionScheme& encryption_scheme, | |
121 base::TimeDelta presentation_time) = 0; | 96 base::TimeDelta presentation_time) = 0; |
122 | 97 |
123 // Submits an empty buffer with a EOS (END OF STREAM) flag. | 98 // Submits an empty buffer with the END_OF_STREAM flag set. |
124 virtual void QueueEOS(int input_buffer_index) = 0; | 99 virtual void QueueEOS(int input_buffer_index) = 0; |
125 | 100 |
126 // Returns: | 101 // Returns: |
127 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, | 102 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, |
128 // MEDIA_CODEC_ENQUEUE_INPUT_AGAIN_LATER if no such buffer is available, or | 103 // MEDIA_CODEC_ENQUEUE_INPUT_AGAIN_LATER if no such buffer is available, or |
129 // MEDIA_CODEC_ERROR if unexpected error happens. | 104 // MEDIA_CODEC_ERROR if unexpected error happens. |
130 // Note: Never use infinite timeout as this would block the decoder thread and | |
131 // prevent the decoder job from being released. | |
132 virtual MediaCodecStatus DequeueInputBuffer(base::TimeDelta timeout, | 105 virtual MediaCodecStatus DequeueInputBuffer(base::TimeDelta timeout, |
133 int* index) = 0; | 106 int* index) = 0; |
134 | 107 |
135 // Dequeues an output buffer, block at most timeout_us microseconds. | 108 // Dequeues an output buffer, block for up to |timeout|. |
136 // Returns the status of this operation. If OK is returned, the output | 109 // Returns the status of this operation. If OK is returned, the output |
137 // parameters should be populated. Otherwise, the values of output parameters | 110 // parameters should be populated. Otherwise, the values of output parameters |
138 // should not be used. Output parameters other than index/offset/size are | 111 // should not be used. Output parameters other than index/offset/size are |
139 // optional and only set if not NULL. | 112 // optional and only set if not NULL. |
140 // Note: Never use infinite timeout as this would block the decoder thread and | |
141 // prevent the decoder job from being released. | |
142 // TODO(xhwang): Can we drop |end_of_stream| and return | |
143 // MEDIA_CODEC_OUTPUT_END_OF_STREAM? | |
144 virtual MediaCodecStatus DequeueOutputBuffer( | 113 virtual MediaCodecStatus DequeueOutputBuffer( |
145 base::TimeDelta timeout, | 114 base::TimeDelta timeout, |
146 int* index, | 115 int* index, |
147 size_t* offset, | 116 size_t* offset, |
148 size_t* size, | 117 size_t* size, |
149 base::TimeDelta* presentation_time, | 118 base::TimeDelta* presentation_time, |
150 bool* end_of_stream, | 119 bool* end_of_stream, |
151 bool* key_frame) = 0; | 120 bool* key_frame) = 0; |
152 | 121 |
153 // Returns the buffer to the codec. If you previously specified a surface when | 122 // Returns the buffer to the codec. If you previously specified a surface when |
154 // configuring this video decoder you can optionally render the buffer. | 123 // configuring this video decoder you can optionally render the buffer. |
155 virtual void ReleaseOutputBuffer(int index, bool render) = 0; | 124 virtual void ReleaseOutputBuffer(int index, bool render) = 0; |
156 | 125 |
157 // Returns an input buffer's base pointer and capacity. | 126 // Returns an input buffer's base pointer and capacity. |
158 virtual MediaCodecStatus GetInputBuffer(int input_buffer_index, | 127 virtual MediaCodecStatus GetInputBuffer(int input_buffer_index, |
159 uint8_t** data, | 128 uint8_t** data, |
160 size_t* capacity) = 0; | 129 size_t* capacity) = 0; |
161 | 130 |
162 // Gives the access to buffer's data which is referenced by |index| and | |
163 // |offset|. The size of available data for reading is written to |*capacity| | |
164 // and the address is written to |*addr|. | |
165 // Returns MEDIA_CODEC_ERROR if a error occurs, or MEDIA_CODEC_OK otherwise. | |
166 virtual MediaCodecStatus GetOutputBufferAddress(int index, | |
167 size_t offset, | |
168 const uint8_t** addr, | |
169 size_t* capacity) = 0; | |
170 | |
171 // Copies |num| bytes from output buffer |index|'s |offset| into the memory | 131 // Copies |num| bytes from output buffer |index|'s |offset| into the memory |
172 // region pointed to by |dst|. To avoid overflows, the size of both source | 132 // region pointed to by |dst|. To avoid overflows, the size of both source |
173 // and destination must be at least |num| bytes, and should not overlap. | 133 // and destination must be at least |num| bytes, and should not overlap. |
174 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 134 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
175 MediaCodecStatus CopyFromOutputBuffer(int index, | 135 virtual MediaCodecStatus CopyFromOutputBuffer(int index, |
176 size_t offset, | 136 size_t offset, |
177 void* dst, | 137 void* dst, |
178 size_t num); | 138 size_t num) = 0; |
179 | 139 |
180 // Gets the component name. Before API level 18 this returns an empty string. | 140 // Gets the component name. Before API level 18 this returns an empty string. |
181 virtual std::string GetName() = 0; | 141 virtual std::string GetName() = 0; |
182 | 142 |
183 protected: | |
184 MediaCodecBridge(); | |
185 | |
186 // Fills a particular input buffer; returns false if |data_size| exceeds the | |
187 // input buffer's capacity (and doesn't touch the input buffer in that case). | |
188 bool FillInputBuffer(int index, | |
189 const uint8_t* data, | |
190 size_t data_size) WARN_UNUSED_RESULT; | |
191 | |
192 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); | 143 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); |
193 }; | 144 }; |
194 | 145 |
195 } // namespace media | 146 } // namespace media |
196 | 147 |
197 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 148 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
OLD | NEW |