108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen/*
208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Copyright (C) 2014 The Android Open Source Project
308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen *
408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Licensed under the Apache License, Version 2.0 (the "License");
508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * you may not use this file except in compliance with the License.
608aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * You may obtain a copy of the License at
708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen *
808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen *      http://www.apache.org/licenses/LICENSE-2.0
908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen *
1008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Unless required by applicable law or agreed to in writing, software
1108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * distributed under the License is distributed on an "AS IS" BASIS,
1208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * See the License for the specific language governing permissions and
1408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * limitations under the License.
1508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen */
1608aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
1708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
1808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen/*
1908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * This file defines an NDK API.
2008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not remove methods.
2108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not change method signatures.
2208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not change the value of constants.
2308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not change the size of any of the classes defined in here.
2408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not reference types that are not part of the NDK.
2508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Do not #include files that aren't part of the NDK.
2608aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen */
2708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
2808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#ifndef _NDK_MEDIA_MUXER_H
2908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#define _NDK_MEDIA_MUXER_H
3008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
312975a24dc42c8953125b39a5194da3aec244cbefDan Albert#include <sys/cdefs.h>
3208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#include <sys/types.h>
3308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
3408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#include "NdkMediaCodec.h"
35e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissen#include "NdkMediaError.h"
36e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissen#include "NdkMediaFormat.h"
3708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
3808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#ifdef __cplusplus
3908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissenextern "C" {
4008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#endif
4108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
422975a24dc42c8953125b39a5194da3aec244cbefDan Albert#if __ANDROID_API__ >= 21
432975a24dc42c8953125b39a5194da3aec244cbefDan Albert
4408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissenstruct AMediaMuxer;
4508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissentypedef struct AMediaMuxer AMediaMuxer;
4608aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
4708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissentypedef enum {
4808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen    AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
4908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen    AMEDIAMUXER_OUTPUT_FORMAT_WEBM   = 1,
5008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen} OutputFormat;
5108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
5208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen/**
5308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Create new media muxer
5408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen */
5508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco NelissenAMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);
5608aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
5708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen/**
5808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen * Delete a previously created media muxer
5908aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen */
60e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissenmedia_status_t AMediaMuxer_delete(AMediaMuxer*);
6108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
6279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
6379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Set and store the geodata (latitude and longitude) in the output file.
6479e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * This method should be called before AMediaMuxer_start. The geodata is stored
6579e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * in udta box if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, and is
6679e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * ignored for other output formats.
6779e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * The geodata is stored according to ISO-6709 standard.
6879e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen *
6979e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Both values are specified in degrees.
7079e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Latitude must be in the range [-90, 90].
7179e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Longitude must be in the range [-180, 180].
7279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
7379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissenmedia_status_t AMediaMuxer_setLocation(AMediaMuxer*, float latitude, float longitude);
7408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
7579e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
7679e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Sets the orientation hint for output video playback.
7779e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * This method should be called before AMediaMuxer_start. Calling this
7879e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * method will not rotate the video frame when muxer is generating the file,
7979e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * but add a composition matrix containing the rotation angle in the output
8079e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * video if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, so that a
8179e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * video player can choose the proper orientation for playback.
8279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Note that some video players may choose to ignore the composition matrix
8379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * during playback.
8479e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * The angle is specified in degrees, clockwise.
8579e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * The supported angles are 0, 90, 180, and 270 degrees.
8679e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
87e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissenmedia_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees);
8808aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
8979e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
9079e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Adds a track with the specified format.
9179e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Returns the index of the new track or a negative value in case of failure,
9279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * which can be interpreted as a media_status_t.
9379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
9408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissenssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format);
9508aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
9679e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
9779e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Start the muxer. Should be called after AMediaMuxer_addTrack and
9879e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * before AMediaMuxer_writeSampleData.
9979e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
100e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissenmedia_status_t AMediaMuxer_start(AMediaMuxer*);
10108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
10279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
10379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Stops the muxer.
10479e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Once the muxer stops, it can not be restarted.
10579e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
106e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissenmedia_status_t AMediaMuxer_stop(AMediaMuxer*);
10708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
10879e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen/**
10979e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * Writes an encoded sample into the muxer.
11079e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * The application needs to make sure that the samples are written into
11179e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * the right tracks. Also, it needs to make sure the samples for each track
11279e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * are written in chronological order (e.g. in the order they are provided
11379e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen * by the encoder.)
11479e2b622702fb148ccff12d6f38643466555c4ebMarco Nelissen */
115e419d7cd5c62b4b5866a45d59c5770bb470193c1Marco Nelissenmedia_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
1160e03cf07deeda10c573657479591dcfbf1efca56Marco Nelissen        size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info);
11708aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
1182975a24dc42c8953125b39a5194da3aec244cbefDan Albert#endif /* __ANDROID_API__ >= 21 */
1192975a24dc42c8953125b39a5194da3aec244cbefDan Albert
12008aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#ifdef __cplusplus
12108aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen} // extern "C"
12208aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#endif
12308aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen
12408aaabe87960c04ecac180db1fe88b5a7bc2ed3bMarco Nelissen#endif // _NDK_MEDIA_MUXER_H
125