summaryrefslogtreecommitdiffstats
path: root/include/ndk
diff options
context:
space:
mode:
Diffstat (limited to 'include/ndk')
-rw-r--r--include/ndk/NdkMediaCodec.h147
-rw-r--r--include/ndk/NdkMediaExtractor.h125
-rw-r--r--include/ndk/NdkMediaFormat.h109
-rw-r--r--include/ndk/NdkMediaMuxer.h75
4 files changed, 456 insertions, 0 deletions
diff --git a/include/ndk/NdkMediaCodec.h b/include/ndk/NdkMediaCodec.h
new file mode 100644
index 0000000..2af88d0
--- /dev/null
+++ b/include/ndk/NdkMediaCodec.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_MEDIA_CODEC_H
+#define _NDK_MEDIA_CODEC_H
+
+#include <android/native_window.h>
+
+#include "NdkMediaFormat.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct AMediaCodec;
+typedef struct AMediaCodec AMediaCodec;
+
+struct AMediaCodecBufferInfo {
+ int32_t offset;
+ int32_t size;
+ int64_t presentationTimeUs;
+ uint32_t flags;
+};
+typedef struct AMediaCodecBufferInfo AMediaCodecBufferInfo;
+
+enum {
+ AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM = 4,
+ AMEDIACODEC_CONFIGURE_FLAG_ENCODE = 1,
+ AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED = -3,
+ AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED = -2,
+ AMEDIACODEC_INFO_TRY_AGAIN_LATER = -1
+};
+
+
+/**
+ * Create codec by name. Use this if you know the exact codec you want to use.
+ * When configuring, you will need to specify whether to use the codec as an
+ * encoder or decoder.
+ */
+AMediaCodec* AMediaCodec_createCodecByName(const char *name);
+
+/**
+ * Create codec by mime type. Most applications will use this, specifying a
+ * mime type obtained from media extractor.
+ */
+AMediaCodec* AMediaCodec_createDecoderByType(const char *mime_type);
+
+/**
+ * Create encoder by name.
+ */
+AMediaCodec* AMediaCodec_createEncoderByType(const char *mime_type);
+
+/**
+ * delete the codec and free its resources
+ */
+int AMediaCodec_delete(AMediaCodec*);
+
+/**
+ * Configure the codec. For decoding you would typically get the format from an extractor.
+ */
+int AMediaCodec_configure(AMediaCodec*, const AMediaFormat* format,
+ ANativeWindow* surface, uint32_t flags); // TODO: other args
+
+/**
+ * Start the codec. A codec must be configured before it can be started, and must be started
+ * before buffers can be sent to it.
+ */
+int AMediaCodec_start(AMediaCodec*);
+
+/**
+ * Stop the codec.
+ */
+int AMediaCodec_stop(AMediaCodec*);
+
+/*
+ * Flush the codec's input and output. All indices previously returned from calls to
+ * AMediaCodec_dequeueInputBuffer and AMediaCodec_dequeueOutputBuffer become invalid.
+ */
+int AMediaCodec_flush(AMediaCodec*);
+
+/**
+ * Get an input buffer. The specified buffer index must have been previously obtained from
+ * dequeueInputBuffer, and not yet queued.
+ */
+uint8_t* AMediaCodec_getInputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
+
+/**
+ * Get an output buffer. The specified buffer index must have been previously obtained from
+ * dequeueOutputBuffer, and not yet queued.
+ */
+uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec*, size_t idx, size_t *out_size);
+
+/**
+ * Get the index of the next available input buffer. An app will typically use this with
+ * getInputBuffer() to get a pointer to the buffer, then copy the data to be encoded or decoded
+ * into the buffer before passing it to the codec.
+ */
+ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs);
+
+/**
+ * Send the specified buffer to the codec for processing.
+ */
+int AMediaCodec_queueInputBuffer(AMediaCodec*,
+ size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
+
+/**
+ * Get the index of the next available buffer of processed data.
+ */
+ssize_t AMediaCodec_dequeueOutputBuffer(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
+AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*);
+
+/**
+ * Release and optionally render the specified buffer.
+ */
+int AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);
+
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif //_NDK_MEDIA_CODEC_H
diff --git a/include/ndk/NdkMediaExtractor.h b/include/ndk/NdkMediaExtractor.h
new file mode 100644
index 0000000..a7c32c4
--- /dev/null
+++ b/include/ndk/NdkMediaExtractor.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_MEDIA_EXTRACTOR_H
+#define _NDK_MEDIA_EXTRACTOR_H
+
+#include <sys/types.h>
+
+#include "NdkMediaFormat.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AMediaExtractor;
+typedef struct AMediaExtractor AMediaExtractor;
+
+
+/**
+ * Create new media extractor
+ */
+AMediaExtractor* AMediaExtractor_new();
+
+/**
+ * Delete a previously created media extractor
+ */
+int AMediaExtractor_delete(AMediaExtractor*);
+
+/**
+ * Set the file descriptor from which the extractor will read.
+ */
+int AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);
+
+/**
+ * Set the URI from which the extractor will read.
+ */
+int AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers
+
+/**
+ * Return the number of tracks in the previously specified media file
+ */
+int AMediaExtractor_getTrackCount(AMediaExtractor*);
+
+/**
+ * Return the format of the specified track. The caller must free the returned format
+ */
+AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor*, size_t idx);
+
+/**
+ * Select the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
+ * getSampleTime only retrieve information for the subset of tracks selected.
+ * Selecting the same track multiple times has no effect, the track is
+ * only selected once.
+ */
+int AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);
+
+/**
+ * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
+ * getSampleTime only retrieve information for the subset of tracks selected..
+ */
+int AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);
+
+/**
+ * Read the current sample.
+ */
+int AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);
+
+/**
+ * Read the current sample's flags.
+ */
+int AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below
+
+/**
+ * Returns the track index the current sample originates from (or -1
+ * if no more samples are available)
+ */
+int AMediaExtractor_getSampleTrackIndex(AMediaExtractor*);
+
+/**
+ * Returns the current sample's presentation time in microseconds.
+ * or -1 if no more samples are available.
+ */
+int64_t AMediaExtractor_getSampletime(AMediaExtractor*);
+
+/**
+ * Advance to the next sample. Returns false if no more sample data
+ * is available (end of stream).
+ */
+bool AMediaExtractor_advance(AMediaExtractor*);
+
+enum {
+ AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
+ AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
+};
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_MEDIA_EXTRACTOR_H
diff --git a/include/ndk/NdkMediaFormat.h b/include/ndk/NdkMediaFormat.h
new file mode 100644
index 0000000..e0caeab
--- /dev/null
+++ b/include/ndk/NdkMediaFormat.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_MEDIA_FORMAT_H
+#define _NDK_MEDIA_FORMAT_H
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AMediaFormat;
+typedef struct AMediaFormat AMediaFormat;
+
+AMediaFormat *AMediaFormat_new();
+int AMediaFormat_delete(AMediaFormat*);
+
+/**
+ * Human readable representation of the format. The returned string is owned by the format,
+ * and remains valid until the next call to toString, or until the format is deleted.
+ */
+const char* AMediaFormat_toString(AMediaFormat*);
+
+bool AMediaFormat_getInt32(AMediaFormat*, const char *name, int32_t *out);
+bool AMediaFormat_getInt64(AMediaFormat*, const char *name, int64_t *out);
+bool AMediaFormat_getFloat(AMediaFormat*, const char *name, float *out);
+/**
+ * The returned data is owned by the format and remains valid as long as the named entry
+ * is part of the format.
+ */
+bool AMediaFormat_getBuffer(AMediaFormat*, const char *name, void** data, size_t *size);
+/**
+ * The returned string is owned by the format, and remains valid until the next call to getString,
+ * or until the format is deleted.
+ */
+bool AMediaFormat_getString(AMediaFormat*, const char *name, const char **out);
+
+
+void AMediaFormat_setInt32(AMediaFormat*, const char* name, int32_t value);
+void AMediaFormat_setInt64(AMediaFormat*, const char* name, int64_t value);
+void AMediaFormat_setFloat(AMediaFormat*, const char* name, float value);
+/**
+ * The provided string is copied into the format.
+ */
+void AMediaFormat_setString(AMediaFormat*, const char* name, const char* value);
+/**
+ * The provided data is copied into the format.
+ */
+void AMediaFormat_setBuffer(AMediaFormat*, const char* name, void* data, size_t size);
+
+
+
+/**
+ * XXX should these be ints/enums that we look up in a table as needed?
+ */
+extern const char* AMEDIAFORMAT_KEY_AAC_PROFILE;
+extern const char* AMEDIAFORMAT_KEY_BIT_RATE;
+extern const char* AMEDIAFORMAT_KEY_CHANNEL_COUNT;
+extern const char* AMEDIAFORMAT_KEY_CHANNEL_MASK;
+extern const char* AMEDIAFORMAT_KEY_COLOR_FORMAT;
+extern const char* AMEDIAFORMAT_KEY_DURATION;
+extern const char* AMEDIAFORMAT_KEY_FLAC_COMPRESSION_LEVEL;
+extern const char* AMEDIAFORMAT_KEY_FRAME_RATE;
+extern const char* AMEDIAFORMAT_KEY_HEIGHT;
+extern const char* AMEDIAFORMAT_KEY_IS_ADTS;
+extern const char* AMEDIAFORMAT_KEY_IS_AUTOSELECT;
+extern const char* AMEDIAFORMAT_KEY_IS_DEFAULT;
+extern const char* AMEDIAFORMAT_KEY_IS_FORCED_SUBTITLE;
+extern const char* AMEDIAFORMAT_KEY_I_FRAME_INTERVAL;
+extern const char* AMEDIAFORMAT_KEY_LANGUAGE;
+extern const char* AMEDIAFORMAT_KEY_MAX_HEIGHT;
+extern const char* AMEDIAFORMAT_KEY_MAX_INPUT_SIZE;
+extern const char* AMEDIAFORMAT_KEY_MAX_WIDTH;
+extern const char* AMEDIAFORMAT_KEY_MIME;
+extern const char* AMEDIAFORMAT_KEY_PUSH_BLANK_BUFFERS_ON_STOP;
+extern const char* AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER;
+extern const char* AMEDIAFORMAT_KEY_SAMPLE_RATE;
+extern const char* AMEDIAFORMAT_KEY_WIDTH;
+extern const char* AMEDIAFORMAT_KEY_STRIDE;
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_MEDIA_FORMAT_H
diff --git a/include/ndk/NdkMediaMuxer.h b/include/ndk/NdkMediaMuxer.h
new file mode 100644
index 0000000..deb150d
--- /dev/null
+++ b/include/ndk/NdkMediaMuxer.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_MEDIA_MUXER_H
+#define _NDK_MEDIA_MUXER_H
+
+#include <sys/types.h>
+
+#include "NdkMediaFormat.h"
+#include "NdkMediaCodec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AMediaMuxer;
+typedef struct AMediaMuxer AMediaMuxer;
+
+typedef enum {
+ AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
+ AMEDIAMUXER_OUTPUT_FORMAT_WEBM = 1,
+} OutputFormat;
+
+/**
+ * Create new media muxer
+ */
+AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);
+
+/**
+ * Delete a previously created media muxer
+ */
+int AMediaMuxer_delete(AMediaMuxer*);
+
+int AMediaMuxer_setLocation(AMediaMuxer*, float latitude, float longtitude);
+
+int AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees);
+
+ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format);
+
+int AMediaMuxer_start(AMediaMuxer*);
+
+int AMediaMuxer_stop(AMediaMuxer*);
+
+int AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
+ size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo &info);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_MEDIA_MUXER_H