blob: c35c6b3b1435f0adc8a452e988c82857ccf03c29 [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
17/*
18 * This file defines an NDK API.
19 * Do not remove methods.
20 * Do not change method signatures.
21 * Do not change the value of constants.
22 * Do not change the size of any of the classes defined in here.
23 * Do not reference types that are not part of the NDK.
24 * Do not #include files that aren't part of the NDK.
25 */
26
27#ifndef _NDK_MEDIA_CODEC_H
28#define _NDK_MEDIA_CODEC_H
29
30#include <android/native_window.h>
31
32#include "NdkMediaFormat.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38
39struct AMediaCodec;
40typedef struct AMediaCodec AMediaCodec;
41
42struct AMediaCodecBufferInfo {
43 int32_t offset;
44 int32_t size;
45 int64_t presentationTimeUs;
46 uint32_t flags;
47};
48typedef struct AMediaCodecBufferInfo AMediaCodecBufferInfo;
49
50enum {
51 AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM = 4,
Marco Nelissen86aa02c2014-05-07 16:03:54 -070052 AMEDIACODEC_CONFIGURE_FLAG_ENCODE = 1,
Marco Nelissen0c3be872014-05-01 10:14:44 -070053 AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED = -3,
54 AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED = -2,
55 AMEDIACODEC_INFO_TRY_AGAIN_LATER = -1
56};
57
Marco Nelissen0c3be872014-05-01 10:14:44 -070058/**
Marco Nelissen86aa02c2014-05-07 16:03:54 -070059 * Create codec by name. Use this if you know the exact codec you want to use.
60 * When configuring, you will need to specify whether to use the codec as an
61 * encoder or decoder.
Marco Nelissen0c3be872014-05-01 10:14:44 -070062 */
Marco Nelissen86aa02c2014-05-07 16:03:54 -070063AMediaCodec* AMediaCodec_createCodecByName(const char *name);
Marco Nelissen0c3be872014-05-01 10:14:44 -070064
65/**
66 * Create codec by mime type. Most applications will use this, specifying a
67 * mime type obtained from media extractor.
68 */
Marco Nelissen86aa02c2014-05-07 16:03:54 -070069AMediaCodec* AMediaCodec_createDecoderByType(const char *mime_type);
Marco Nelissen0c3be872014-05-01 10:14:44 -070070
71/**
72 * Create encoder by name.
73 */
Marco Nelissen86aa02c2014-05-07 16:03:54 -070074AMediaCodec* AMediaCodec_createEncoderByType(const char *mime_type);
Marco Nelissen0c3be872014-05-01 10:14:44 -070075
76/**
77 * delete the codec and free its resources
78 */
79int AMediaCodec_delete(AMediaCodec*);
80
81/**
82 * Configure the codec. For decoding you would typically get the format from an extractor.
83 */
Marco Nelissen86aa02c2014-05-07 16:03:54 -070084int AMediaCodec_configure(AMediaCodec*, const AMediaFormat* format,
85 ANativeWindow* surface, uint32_t flags); // TODO: other args
Marco Nelissen0c3be872014-05-01 10:14:44 -070086
87/**
88 * Start the codec. A codec must be configured before it can be started, and must be started
89 * before buffers can be sent to it.
90 */
91int AMediaCodec_start(AMediaCodec*);
92
93/**
94 * Stop the codec.
95 */
96int AMediaCodec_stop(AMediaCodec*);
97
98/*
99 * Flush the codec's input and output. All indices previously returned from calls to
100 * AMediaCodec_dequeueInputBuffer and AMediaCodec_dequeueOutputBuffer become invalid.
101 */
102int AMediaCodec_flush(AMediaCodec*);
103
104/**
105 * Get an input buffer. The specified buffer index must have been previously obtained from
106 * dequeueInputBuffer, and not yet queued.
107 */
108uint8_t* AMediaCodec_getInputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
109
110/**
111 * Get an output buffer. The specified buffer index must have been previously obtained from
112 * dequeueOutputBuffer, and not yet queued.
113 */
114uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
115
116/**
117 * Get the index of the next available input buffer. An app will typically use this with
118 * getInputBuffer() to get a pointer to the buffer, then copy the data to be encoded or decoded
119 * into the buffer before passing it to the codec.
120 */
121ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs);
122
123/**
124 * Send the specified buffer to the codec for processing.
125 */
126int AMediaCodec_queueInputBuffer(AMediaCodec*,
127 size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
128
129/**
130 * Get the index of the next available buffer of processed data.
131 */
132ssize_t AMediaCodec_dequeueOutputBuffer(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
133AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*);
134
135/**
136 * Release and optionally render the specified buffer.
137 */
138int AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);
139
140
141
Marco Nelissencdb42cd2014-05-08 14:46:05 -0700142typedef void (*OnCodecEvent)(AMediaCodec *codec, void *userdata);
143
144/**
145 * Set a callback to be called when a new buffer is available, or there was a format
146 * or buffer change.
147 * Note that you cannot perform any operations on the mediacodec from within the callback.
148 * If you need to perform mediacodec operations, you must do so on a different thread.
149 */
150int AMediaCodec_setNotificationCallback(AMediaCodec*, OnCodecEvent callback, void *userdata);
151
152
Marco Nelissen0c3be872014-05-01 10:14:44 -0700153#ifdef __cplusplus
154} // extern "C"
155#endif
156
157#endif //_NDK_MEDIA_CODEC_H