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