blob: 9dc120df298d8a12dc68fba6716ba16bf6304ec4 [file] [log] [blame]
Marco Nelissen0c3be872014-05-01 10:14:44 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Albertec6cd632018-04-13 15:57:25 -070017/**
18 * @addtogroup Media
19 * @{
20 */
21
22/**
23 * @file NdkMediaCodec.h
24 */
25
Marco Nelissen0c3be872014-05-01 10:14:44 -070026/*
27 * This file defines an NDK API.
28 * Do not remove methods.
29 * Do not change method signatures.
30 * Do not change the value of constants.
31 * Do not change the size of any of the classes defined in here.
32 * Do not reference types that are not part of the NDK.
33 * Do not #include files that aren't part of the NDK.
34 */
35
36#ifndef _NDK_MEDIA_CODEC_H
37#define _NDK_MEDIA_CODEC_H
38
Dan Albert19abcd82017-07-17 13:37:56 -070039#include <stdint.h>
Dan Albert2975a242016-09-23 16:17:45 -070040#include <sys/cdefs.h>
41
Marco Nelissen050eb322014-05-09 15:10:23 -070042#include "NdkMediaCrypto.h"
Marco Nelissene419d7c2014-05-15 14:17:25 -070043#include "NdkMediaError.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070044#include "NdkMediaFormat.h"
45
Dan Albert5e496db2017-10-05 15:03:07 -070046__BEGIN_DECLS
Marco Nelissen0c3be872014-05-01 10:14:44 -070047
Mathias Agopianbc1713d2017-02-13 18:37:50 -080048struct ANativeWindow;
Robert Shihf6d10492017-09-26 13:30:48 -070049typedef struct ANativeWindow ANativeWindow;
Mathias Agopianbc1713d2017-02-13 18:37:50 -080050
Marco Nelissen0c3be872014-05-01 10:14:44 -070051
52struct AMediaCodec;
53typedef struct AMediaCodec AMediaCodec;
54
55struct AMediaCodecBufferInfo {
56 int32_t offset;
57 int32_t size;
58 int64_t presentationTimeUs;
59 uint32_t flags;
60};
61typedef struct AMediaCodecBufferInfo AMediaCodecBufferInfo;
Marco Nelissen050eb322014-05-09 15:10:23 -070062typedef struct AMediaCodecCryptoInfo AMediaCodecCryptoInfo;
Marco Nelissen0c3be872014-05-01 10:14:44 -070063
64enum {
Wei Jia00cc9922017-11-23 08:00:34 -080065 AMEDIACODEC_BUFFER_FLAG_CODEC_CONFIG = 2,
Marco Nelissen0c3be872014-05-01 10:14:44 -070066 AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM = 4,
Wei Jia00cc9922017-11-23 08:00:34 -080067 AMEDIACODEC_BUFFER_FLAG_PARTIAL_FRAME = 8,
68
Marco Nelissen86aa02c2014-05-07 16:03:54 -070069 AMEDIACODEC_CONFIGURE_FLAG_ENCODE = 1,
Marco Nelissen0c3be872014-05-01 10:14:44 -070070 AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED = -3,
71 AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED = -2,
Wei Jia00cc9922017-11-23 08:00:34 -080072 AMEDIACODEC_INFO_TRY_AGAIN_LATER = -1,
73};
74
75/**
76 * Called when an input buffer becomes available.
77 * The specified index is the index of the available input buffer.
78 */
79typedef void (*AMediaCodecOnAsyncInputAvailable)(
80 AMediaCodec *codec,
81 void *userdata,
82 int32_t index);
83/**
84 * Called when an output buffer becomes available.
85 * The specified index is the index of the available output buffer.
86 * The specified bufferInfo contains information regarding the available output buffer.
87 */
88typedef void (*AMediaCodecOnAsyncOutputAvailable)(
89 AMediaCodec *codec,
90 void *userdata,
91 int32_t index,
92 AMediaCodecBufferInfo *bufferInfo);
93/**
94 * Called when the output format has changed.
95 * The specified format contains the new output format.
96 */
97typedef void (*AMediaCodecOnAsyncFormatChanged)(
98 AMediaCodec *codec,
99 void *userdata,
100 AMediaFormat *format);
101/**
102 * Called when the MediaCodec encountered an error.
103 * The specified actionCode indicates the possible actions that client can take,
104 * and it can be checked by calling AMediaCodecActionCode_isRecoverable or
105 * AMediaCodecActionCode_isTransient. If both AMediaCodecActionCode_isRecoverable()
106 * and AMediaCodecActionCode_isTransient() return false, then the codec error is fatal
107 * and the codec must be deleted.
108 * The specified detail may contain more detailed messages about this error.
109 */
110typedef void (*AMediaCodecOnAsyncError)(
111 AMediaCodec *codec,
112 void *userdata,
113 media_status_t error,
114 int32_t actionCode,
115 const char *detail);
116
117struct AMediaCodecOnAsyncNotifyCallback {
118 AMediaCodecOnAsyncInputAvailable onAsyncInputAvailable;
119 AMediaCodecOnAsyncOutputAvailable onAsyncOutputAvailable;
120 AMediaCodecOnAsyncFormatChanged onAsyncFormatChanged;
121 AMediaCodecOnAsyncError onAsyncError;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700122};
123
Ryan Pricharda5249752018-07-19 18:03:48 -0700124#if __ANDROID_API__ >= 21
125
Marco Nelissen0c3be872014-05-01 10:14:44 -0700126/**
Marco Nelissen86aa02c2014-05-07 16:03:54 -0700127 * Create codec by name. Use this if you know the exact codec you want to use.
128 * When configuring, you will need to specify whether to use the codec as an
129 * encoder or decoder.
Marco Nelissen0c3be872014-05-01 10:14:44 -0700130 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700131AMediaCodec* AMediaCodec_createCodecByName(const char *name) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700132
133/**
134 * Create codec by mime type. Most applications will use this, specifying a
135 * mime type obtained from media extractor.
136 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700137AMediaCodec* AMediaCodec_createDecoderByType(const char *mime_type) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700138
139/**
140 * Create encoder by name.
141 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700142AMediaCodec* AMediaCodec_createEncoderByType(const char *mime_type) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700143
144/**
145 * delete the codec and free its resources
146 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700147media_status_t AMediaCodec_delete(AMediaCodec*) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700148
149/**
150 * Configure the codec. For decoding you would typically get the format from an extractor.
151 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700152media_status_t AMediaCodec_configure(
Marco Nelissen050eb322014-05-09 15:10:23 -0700153 AMediaCodec*,
154 const AMediaFormat* format,
155 ANativeWindow* surface,
156 AMediaCrypto *crypto,
Elliott Hughes4280e862018-06-18 13:17:24 -0700157 uint32_t flags) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700158
159/**
160 * Start the codec. A codec must be configured before it can be started, and must be started
161 * before buffers can be sent to it.
162 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700163media_status_t AMediaCodec_start(AMediaCodec*) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700164
165/**
166 * Stop the codec.
167 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700168media_status_t AMediaCodec_stop(AMediaCodec*) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700169
170/*
171 * Flush the codec's input and output. All indices previously returned from calls to
172 * AMediaCodec_dequeueInputBuffer and AMediaCodec_dequeueOutputBuffer become invalid.
173 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700174media_status_t AMediaCodec_flush(AMediaCodec*) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700175
176/**
177 * Get an input buffer. The specified buffer index must have been previously obtained from
178 * dequeueInputBuffer, and not yet queued.
179 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700180uint8_t* AMediaCodec_getInputBuffer(AMediaCodec*, size_t idx, size_t *out_size) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700181
182/**
183 * Get an output buffer. The specified buffer index must have been previously obtained from
184 * dequeueOutputBuffer, and not yet queued.
185 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700186uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec*, size_t idx, size_t *out_size) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700187
188/**
189 * Get the index of the next available input buffer. An app will typically use this with
190 * getInputBuffer() to get a pointer to the buffer, then copy the data to be encoded or decoded
191 * into the buffer before passing it to the codec.
192 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700193ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700194
Dan Albert19abcd82017-07-17 13:37:56 -0700195/*
196 * __USE_FILE_OFFSET64 changes the type of off_t in LP32, which changes the ABI
197 * of these declarations to not match the platform. In that case, define these
198 * APIs in terms of int32_t instead. Passing an off_t in this situation will
199 * result in silent truncation unless the user builds with -Wconversion, but the
200 * only alternative it to not expose them at all for this configuration, which
201 * makes the whole API unusable.
202 *
203 * https://github.com/android-ndk/ndk/issues/459
Marco Nelissen0c3be872014-05-01 10:14:44 -0700204 */
Dan Albert19abcd82017-07-17 13:37:56 -0700205#if defined(__USE_FILE_OFFSET64) && !defined(__LP64__)
206#define _off_t_compat int32_t
207#else
208#define _off_t_compat off_t
209#endif /* defined(__USE_FILE_OFFSET64) && !defined(__LP64__) */
210
211#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
212 __STDC_VERSION__ >= 201112L
Elliott Hughes0d626522017-09-11 13:07:20 -0700213#include <assert.h>
Dan Albert19abcd82017-07-17 13:37:56 -0700214static_assert(sizeof(_off_t_compat) == sizeof(long),
215 "_off_t_compat does not match the NDK ABI. See "
216 "https://github.com/android-ndk/ndk/issues/459.");
217#endif
Marco Nelissen0c3be872014-05-01 10:14:44 -0700218
219/**
Marco Nelissen050eb322014-05-09 15:10:23 -0700220 * Send the specified buffer to the codec for processing.
221 */
Dan Albert19abcd82017-07-17 13:37:56 -0700222media_status_t AMediaCodec_queueInputBuffer(AMediaCodec*, size_t idx,
223 _off_t_compat offset, size_t size,
Elliott Hughes4280e862018-06-18 13:17:24 -0700224 uint64_t time, uint32_t flags) __INTRODUCED_IN(21);
Dan Albert19abcd82017-07-17 13:37:56 -0700225
226/**
227 * Send the specified buffer to the codec for processing.
228 */
229media_status_t AMediaCodec_queueSecureInputBuffer(AMediaCodec*, size_t idx,
230 _off_t_compat offset,
231 AMediaCodecCryptoInfo*,
Elliott Hughes4280e862018-06-18 13:17:24 -0700232 uint64_t time, uint32_t flags) __INTRODUCED_IN(21);
Dan Albert19abcd82017-07-17 13:37:56 -0700233
234#undef _off_t_compat
Marco Nelissen050eb322014-05-09 15:10:23 -0700235
236/**
Marco Nelissen0c3be872014-05-01 10:14:44 -0700237 * Get the index of the next available buffer of processed data.
238 */
Glenn Kastenb187de12014-12-30 08:18:15 -0800239ssize_t AMediaCodec_dequeueOutputBuffer(AMediaCodec*, AMediaCodecBufferInfo *info,
Elliott Hughes4280e862018-06-18 13:17:24 -0700240 int64_t timeoutUs) __INTRODUCED_IN(21);
241AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700242
243/**
Manikanta Kanamarlapudi2c32f4d2017-07-07 16:24:31 +0530244 * Get format of the buffer. The specified buffer index must have been previously obtained from
245 * dequeueOutputBuffer.
246 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700247AMediaFormat* AMediaCodec_getBufferFormat(AMediaCodec*, size_t index) __INTRODUCED_IN(21);
Manikanta Kanamarlapudi2c32f4d2017-07-07 16:24:31 +0530248
249/**
Marco Nelissen79e2b622014-05-16 08:07:28 -0700250 * If you are done with a buffer, use this call to return the buffer to
251 * the codec. If you previously specified a surface when configuring this
252 * video decoder you can optionally render the buffer.
Marco Nelissen0c3be872014-05-01 10:14:44 -0700253 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700254media_status_t AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render) __INTRODUCED_IN(21);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700255
Marco Nelissen79e2b622014-05-16 08:07:28 -0700256/**
Vineeta Srivastava8c35da52016-01-08 17:33:09 -0800257 * Dynamically sets the output surface of a codec.
258 *
259 * This can only be used if the codec was configured with an output surface. The
260 * new output surface should have a compatible usage type to the original output surface.
261 * E.g. codecs may not support switching from a SurfaceTexture (GPU readable) output
262 * to ImageReader (software readable) output.
263 *
264 * For more details, see the Java documentation for MediaCodec.setOutputSurface.
265 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700266media_status_t AMediaCodec_setOutputSurface(AMediaCodec*, ANativeWindow* surface) __INTRODUCED_IN(21);
Vineeta Srivastava8c35da52016-01-08 17:33:09 -0800267
268/**
Marco Nelissen79e2b622014-05-16 08:07:28 -0700269 * If you are done with a buffer, use this call to update its surface timestamp
270 * and return it to the codec to render it on the output surface. If you
271 * have not specified an output surface when configuring this video codec,
272 * this call will simply return the buffer to the codec.
273 *
274 * For more details, see the Java documentation for MediaCodec.releaseOutputBuffer.
275 */
276media_status_t AMediaCodec_releaseOutputBufferAtTime(
Elliott Hughes4280e862018-06-18 13:17:24 -0700277 AMediaCodec *mData, size_t idx, int64_t timestampNs) __INTRODUCED_IN(21);
Robert Shih8f61a2b2017-09-11 14:03:11 -0700278
Ryan Pricharda5249752018-07-19 18:03:48 -0700279#if __ANDROID_API__ >= 26
280
Praveen Chavan19431582017-01-16 11:56:18 -0800281/**
282 * Creates a Surface that can be used as the input to encoder, in place of input buffers
283 *
284 * This can only be called after the codec has been configured via
285 * AMediaCodec_configure(..); and before AMediaCodec_start() has been called.
286 *
287 * The application is responsible for releasing the surface by calling
288 * ANativeWindow_release() when done.
289 *
290 * For more details, see the Java documentation for MediaCodec.createInputSurface.
291 */
Praveen Chavan85a53632017-01-31 12:21:33 -0800292media_status_t AMediaCodec_createInputSurface(
Elliott Hughes4280e862018-06-18 13:17:24 -0700293 AMediaCodec *mData, ANativeWindow **surface) __INTRODUCED_IN(26);
Praveen Chavan85a53632017-01-31 12:21:33 -0800294
295/**
296 * Creates a persistent Surface that can be used as the input to encoder
297 *
298 * Persistent surface can be reused by MediaCodec instances and can be set
299 * on a new instance via AMediaCodec_setInputSurface().
300 * A persistent surface can be connected to at most one instance of MediaCodec
301 * at any point in time.
302 *
303 * The application is responsible for releasing the surface by calling
304 * ANativeWindow_release() when done.
305 *
306 * For more details, see the Java documentation for MediaCodec.createPersistentInputSurface.
307 */
308media_status_t AMediaCodec_createPersistentInputSurface(
Elliott Hughes4280e862018-06-18 13:17:24 -0700309 ANativeWindow **surface) __INTRODUCED_IN(26);
Praveen Chavan85a53632017-01-31 12:21:33 -0800310
311/**
312 * Set a persistent-surface that can be used as the input to encoder, in place of input buffers
313 *
314 * The surface provided *must* be a persistent surface created via
315 * AMediaCodec_createPersistentInputSurface()
316 * This can only be called after the codec has been configured by calling
317 * AMediaCodec_configure(..); and before AMediaCodec_start() has been called.
318 *
319 * For more details, see the Java documentation for MediaCodec.setInputSurface.
320 */
321media_status_t AMediaCodec_setInputSurface(
Elliott Hughes4280e862018-06-18 13:17:24 -0700322 AMediaCodec *mData, ANativeWindow *surface) __INTRODUCED_IN(26);
Praveen Chavan85a53632017-01-31 12:21:33 -0800323
Praveen Chavanf373e842017-02-01 11:50:15 -0800324/**
325 * Signal additional parameters to the codec instance.
326 *
327 * Parameters can be communicated only when the codec is running, i.e
328 * after AMediaCodec_start() has been called.
329 *
330 * NOTE: Some of these parameter changes may silently fail to apply.
331 */
332media_status_t AMediaCodec_setParameters(
Elliott Hughes4280e862018-06-18 13:17:24 -0700333 AMediaCodec *mData, const AMediaFormat* params) __INTRODUCED_IN(26);
Praveen Chavan85a53632017-01-31 12:21:33 -0800334
Robert Shihaf42d3f2017-03-20 16:45:37 -0700335/**
336 * Signals end-of-stream on input. Equivalent to submitting an empty buffer with
337 * AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM set.
338 *
339 * Returns AMEDIA_ERROR_INVALID_OPERATION when used with an encoder not in executing state
340 * or not receiving input from a Surface created by AMediaCodec_createInputSurface or
341 * AMediaCodec_createPersistentInputSurface.
342 *
343 * Returns the previous codec error if one exists.
344 *
345 * Returns AMEDIA_OK when completed succesfully.
346 *
347 * For more details, see the Java documentation for MediaCodec.signalEndOfInputStream.
348 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700349media_status_t AMediaCodec_signalEndOfInputStream(AMediaCodec *mData) __INTRODUCED_IN(26);
Wei Jia00cc9922017-11-23 08:00:34 -0800350
Ryan Pricharda5249752018-07-19 18:03:48 -0700351#endif /* __ANDROID_API__ >= 26 */
352
353#if __ANDROID_API__ >= 28
354
Wei Jia00cc9922017-11-23 08:00:34 -0800355/**
356 * Get the component name. If the codec was created by createDecoderByType
357 * or createEncoderByType, what component is chosen is not known beforehand.
358 * Caller shall call AMediaCodec_releaseName to free the returned pointer.
359 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700360media_status_t AMediaCodec_getName(AMediaCodec*, char** out_name) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800361
362/**
363 * Free the memory pointed by name which is returned by AMediaCodec_getName.
364 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700365void AMediaCodec_releaseName(AMediaCodec*, char* name) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800366
367/**
368 * Set an asynchronous callback for actionable AMediaCodec events.
369 * When asynchronous callback is enabled, the client should not call
370 * AMediaCodec_getInputBuffers(), AMediaCodec_getOutputBuffers(),
371 * AMediaCodec_dequeueInputBuffer() or AMediaCodec_dequeueOutputBuffer().
372 *
373 * Also, AMediaCodec_flush() behaves differently in asynchronous mode.
374 * After calling AMediaCodec_flush(), you must call AMediaCodec_start() to
375 * "resume" receiving input buffers, even if an input surface was created.
376 *
377 * Refer to the definition of AMediaCodecOnAsyncNotifyCallback on how each
378 * callback function is called and what are specified.
379 * The specified userdata is the pointer used when those callback functions are
380 * called.
381 *
382 * All callbacks are fired on one NDK internal thread.
383 * AMediaCodec_setAsyncNotifyCallback should not be called on the callback thread.
384 * No heavy duty task should be performed on callback thread.
385 */
386media_status_t AMediaCodec_setAsyncNotifyCallback(
387 AMediaCodec*,
388 AMediaCodecOnAsyncNotifyCallback callback,
Elliott Hughes4280e862018-06-18 13:17:24 -0700389 void *userdata) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800390
391/**
392 * Release the crypto if applicable.
393 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700394media_status_t AMediaCodec_releaseCrypto(AMediaCodec*) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800395
396/**
397 * Call this after AMediaCodec_configure() returns successfully to get the input
398 * format accepted by the codec. Do this to determine what optional configuration
399 * parameters were supported by the codec.
400 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700401AMediaFormat* AMediaCodec_getInputFormat(AMediaCodec*) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800402
403/**
404 * Returns true if the codec cannot proceed further, but can be recovered by stopping,
405 * configuring, and starting again.
406 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700407bool AMediaCodecActionCode_isRecoverable(int32_t actionCode) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800408
409/**
410 * Returns true if the codec error is a transient issue, perhaps due to
411 * resource constraints, and that the method (or encoding/decoding) may be
412 * retried at a later time.
413 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700414bool AMediaCodecActionCode_isTransient(int32_t actionCode) __INTRODUCED_IN(28);
Wei Jia00cc9922017-11-23 08:00:34 -0800415
Ryan Pricharda5249752018-07-19 18:03:48 -0700416#endif /* __ANDROID_API__ >= 28 */
417
Marco Nelissen79e2b622014-05-16 08:07:28 -0700418typedef enum {
Marco Nelissen050eb322014-05-09 15:10:23 -0700419 AMEDIACODECRYPTOINFO_MODE_CLEAR = 0,
Jeff Tinkerf45c7e72016-03-23 17:50:11 -0700420 AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1,
421 AMEDIACODECRYPTOINFO_MODE_AES_WV = 2,
422 AMEDIACODECRYPTOINFO_MODE_AES_CBC = 3
Marco Nelissen79e2b622014-05-16 08:07:28 -0700423} cryptoinfo_mode_t;
Marco Nelissen050eb322014-05-09 15:10:23 -0700424
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800425typedef struct {
426 int32_t encryptBlocks;
427 int32_t skipBlocks;
428} cryptoinfo_pattern_t;
429
Marco Nelissen050eb322014-05-09 15:10:23 -0700430/**
Marco Nelissen79e2b622014-05-16 08:07:28 -0700431 * Create an AMediaCodecCryptoInfo from scratch. Use this if you need to use custom
Marco Nelissen050eb322014-05-09 15:10:23 -0700432 * crypto info, rather than one obtained from AMediaExtractor.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700433 *
434 * AMediaCodecCryptoInfo describes the structure of an (at least
435 * partially) encrypted input sample.
436 * A buffer's data is considered to be partitioned into "subsamples",
437 * each subsample starts with a (potentially empty) run of plain,
438 * unencrypted bytes followed by a (also potentially empty) run of
439 * encrypted bytes.
440 * numBytesOfClearData can be null to indicate that all data is encrypted.
441 * This information encapsulates per-sample metadata as outlined in
442 * ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".
Marco Nelissen050eb322014-05-09 15:10:23 -0700443 */
444AMediaCodecCryptoInfo *AMediaCodecCryptoInfo_new(
445 int numsubsamples,
446 uint8_t key[16],
447 uint8_t iv[16],
Marco Nelissen79e2b622014-05-16 08:07:28 -0700448 cryptoinfo_mode_t mode,
Marco Nelissen050eb322014-05-09 15:10:23 -0700449 size_t *clearbytes,
Elliott Hughes4280e862018-06-18 13:17:24 -0700450 size_t *encryptedbytes) __INTRODUCED_IN(21);
Marco Nelissen050eb322014-05-09 15:10:23 -0700451
452/**
Marco Nelissen829e0972014-05-13 16:22:19 -0700453 * delete an AMediaCodecCryptoInfo created previously with AMediaCodecCryptoInfo_new, or
Marco Nelissen050eb322014-05-09 15:10:23 -0700454 * obtained from AMediaExtractor
455 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700456media_status_t AMediaCodecCryptoInfo_delete(AMediaCodecCryptoInfo*) __INTRODUCED_IN(21);
Marco Nelissen050eb322014-05-09 15:10:23 -0700457
Marco Nelissen79e2b622014-05-16 08:07:28 -0700458/**
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800459 * Set the crypto pattern on an AMediaCryptoInfo object
460 */
461void AMediaCodecCryptoInfo_setPattern(
462 AMediaCodecCryptoInfo *info,
Elliott Hughes4280e862018-06-18 13:17:24 -0700463 cryptoinfo_pattern_t *pattern) __INTRODUCED_IN(21);
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800464
465/**
Marco Nelissen79e2b622014-05-16 08:07:28 -0700466 * The number of subsamples that make up the buffer's contents.
467 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700468size_t AMediaCodecCryptoInfo_getNumSubSamples(AMediaCodecCryptoInfo*) __INTRODUCED_IN(21);
Marco Nelissen79e2b622014-05-16 08:07:28 -0700469
470/**
471 * A 16-byte opaque key
472 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700473media_status_t AMediaCodecCryptoInfo_getKey(AMediaCodecCryptoInfo*, uint8_t *dst) __INTRODUCED_IN(21);
Marco Nelissen79e2b622014-05-16 08:07:28 -0700474
475/**
476 * A 16-byte initialization vector
477 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700478media_status_t AMediaCodecCryptoInfo_getIV(AMediaCodecCryptoInfo*, uint8_t *dst) __INTRODUCED_IN(21);
Marco Nelissen79e2b622014-05-16 08:07:28 -0700479
480/**
481 * The type of encryption that has been applied,
482 * one of AMEDIACODECRYPTOINFO_MODE_CLEAR or AMEDIACODECRYPTOINFO_MODE_AES_CTR.
483 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700484cryptoinfo_mode_t AMediaCodecCryptoInfo_getMode(AMediaCodecCryptoInfo*) __INTRODUCED_IN(21);
Marco Nelissen79e2b622014-05-16 08:07:28 -0700485
486/**
487 * The number of leading unencrypted bytes in each subsample.
488 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700489media_status_t AMediaCodecCryptoInfo_getClearBytes(AMediaCodecCryptoInfo*, size_t *dst) __INTRODUCED_IN(21);
Marco Nelissen79e2b622014-05-16 08:07:28 -0700490
491/**
492 * The number of trailing encrypted bytes in each subsample.
493 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700494media_status_t AMediaCodecCryptoInfo_getEncryptedBytes(AMediaCodecCryptoInfo*, size_t *dst) __INTRODUCED_IN(21);
Dan Albert2975a242016-09-23 16:17:45 -0700495
Ryan Pricharda5249752018-07-19 18:03:48 -0700496#endif /* __ANDROID_API__ >= 21 */
497
Dan Albert5e496db2017-10-05 15:03:07 -0700498__END_DECLS
Marco Nelissen0c3be872014-05-01 10:14:44 -0700499
500#endif //_NDK_MEDIA_CODEC_H
Dan Albertec6cd632018-04-13 15:57:25 -0700501
502/** @} */