NdkMediaCodec.h revision 86aa02ce274826dc80ffa00766b16172c47503fd
1/*
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,
52    AMEDIACODEC_CONFIGURE_FLAG_ENCODE = 1,
53    AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED = -3,
54    AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED = -2,
55    AMEDIACODEC_INFO_TRY_AGAIN_LATER = -1
56};
57
58
59/**
60 * Create codec by name. Use this if you know the exact codec you want to use.
61 * When configuring, you will need to specify whether to use the codec as an
62 * encoder or decoder.
63 */
64AMediaCodec* AMediaCodec_createCodecByName(const char *name);
65
66/**
67 * Create codec by mime type. Most applications will use this, specifying a
68 * mime type obtained from media extractor.
69 */
70AMediaCodec* AMediaCodec_createDecoderByType(const char *mime_type);
71
72/**
73 * Create encoder by name.
74 */
75AMediaCodec* AMediaCodec_createEncoderByType(const char *mime_type);
76
77/**
78 * delete the codec and free its resources
79 */
80int AMediaCodec_delete(AMediaCodec*);
81
82/**
83 * Configure the codec. For decoding you would typically get the format from an extractor.
84 */
85int AMediaCodec_configure(AMediaCodec*, const AMediaFormat* format,
86        ANativeWindow* surface, uint32_t flags);  // TODO: other args
87
88/**
89 * Start the codec. A codec must be configured before it can be started, and must be started
90 * before buffers can be sent to it.
91 */
92int AMediaCodec_start(AMediaCodec*);
93
94/**
95 * Stop the codec.
96 */
97int AMediaCodec_stop(AMediaCodec*);
98
99/*
100 * Flush the codec's input and output. All indices previously returned from calls to
101 * AMediaCodec_dequeueInputBuffer and AMediaCodec_dequeueOutputBuffer become invalid.
102 */
103int AMediaCodec_flush(AMediaCodec*);
104
105/**
106 * Get an input buffer. The specified buffer index must have been previously obtained from
107 * dequeueInputBuffer, and not yet queued.
108 */
109uint8_t* AMediaCodec_getInputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
110
111/**
112 * Get an output buffer. The specified buffer index must have been previously obtained from
113 * dequeueOutputBuffer, and not yet queued.
114 */
115uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
116
117/**
118 * Get the index of the next available input buffer. An app will typically use this with
119 * getInputBuffer() to get a pointer to the buffer, then copy the data to be encoded or decoded
120 * into the buffer before passing it to the codec.
121 */
122ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs);
123
124/**
125 * Send the specified buffer to the codec for processing.
126 */
127int AMediaCodec_queueInputBuffer(AMediaCodec*,
128        size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
129
130/**
131 * Get the index of the next available buffer of processed data.
132 */
133ssize_t AMediaCodec_dequeueOutputBuffer(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
134AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*);
135
136/**
137 * Release and optionally render the specified buffer.
138 */
139int AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);
140
141
142
143#ifdef __cplusplus
144} // extern "C"
145#endif
146
147#endif //_NDK_MEDIA_CODEC_H
148