blob: 3fdeea43858005d0ebf34e04991c453a7c797788 [file] [log] [blame]
Marco Nelissen08aaabe2014-05-06 16:08:19 -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
Dan Albertec6cd632018-04-13 15:57:25 -070017/**
18 * @addtogroup Media
19 * @{
20 */
21
22/**
23 * @file NdkMediaMuxer.h
24 */
Marco Nelissen08aaabe2014-05-06 16:08:19 -070025
26/*
27 * This file defines an NDK API.
28 * Do not remove methods.
29 * Do not change method signatures.
30 * Do not change the value of constants.
31 * Do not change the size of any of the classes defined in here.
32 * Do not reference types that are not part of the NDK.
33 * Do not #include files that aren't part of the NDK.
34 */
35
36#ifndef _NDK_MEDIA_MUXER_H
37#define _NDK_MEDIA_MUXER_H
38
Dan Albert2975a242016-09-23 16:17:45 -070039#include <sys/cdefs.h>
Marco Nelissen08aaabe2014-05-06 16:08:19 -070040#include <sys/types.h>
41
Marco Nelissen08aaabe2014-05-06 16:08:19 -070042#include "NdkMediaCodec.h"
Marco Nelissene419d7c2014-05-15 14:17:25 -070043#include "NdkMediaError.h"
44#include "NdkMediaFormat.h"
Marco Nelissen08aaabe2014-05-06 16:08:19 -070045
Dan Albert5e496db2017-10-05 15:03:07 -070046__BEGIN_DECLS
Dan Albert2975a242016-09-23 16:17:45 -070047
Marco Nelissen08aaabe2014-05-06 16:08:19 -070048struct AMediaMuxer;
49typedef struct AMediaMuxer AMediaMuxer;
50
51typedef enum {
52 AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
53 AMEDIAMUXER_OUTPUT_FORMAT_WEBM = 1,
54} OutputFormat;
55
Ryan Pricharda5249752018-07-19 18:03:48 -070056#if __ANDROID_API__ >= 21
57
Marco Nelissen08aaabe2014-05-06 16:08:19 -070058/**
Elliott Hughes64a3b062019-10-29 10:09:30 -070059 * Create new media muxer.
60 *
61 * Available since API level 21.
Marco Nelissen08aaabe2014-05-06 16:08:19 -070062 */
Elliott Hughes4280e862018-06-18 13:17:24 -070063AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070064
65/**
Elliott Hughes64a3b062019-10-29 10:09:30 -070066 * Delete a previously created media muxer.
67 *
68 * Available since API level 21.
Marco Nelissen08aaabe2014-05-06 16:08:19 -070069 */
Elliott Hughes4280e862018-06-18 13:17:24 -070070media_status_t AMediaMuxer_delete(AMediaMuxer*) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070071
Marco Nelissen79e2b622014-05-16 08:07:28 -070072/**
73 * Set and store the geodata (latitude and longitude) in the output file.
74 * This method should be called before AMediaMuxer_start. The geodata is stored
75 * in udta box if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, and is
76 * ignored for other output formats.
77 * The geodata is stored according to ISO-6709 standard.
78 *
79 * Both values are specified in degrees.
80 * Latitude must be in the range [-90, 90].
81 * Longitude must be in the range [-180, 180].
Elliott Hughes64a3b062019-10-29 10:09:30 -070082 *
83 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -070084 */
Elliott Hughes4280e862018-06-18 13:17:24 -070085media_status_t AMediaMuxer_setLocation(AMediaMuxer*,
86 float latitude, float longitude) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070087
Marco Nelissen79e2b622014-05-16 08:07:28 -070088/**
89 * Sets the orientation hint for output video playback.
90 * This method should be called before AMediaMuxer_start. Calling this
91 * method will not rotate the video frame when muxer is generating the file,
92 * but add a composition matrix containing the rotation angle in the output
93 * video if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, so that a
94 * video player can choose the proper orientation for playback.
95 * Note that some video players may choose to ignore the composition matrix
96 * during playback.
97 * The angle is specified in degrees, clockwise.
98 * The supported angles are 0, 90, 180, and 270 degrees.
Elliott Hughes64a3b062019-10-29 10:09:30 -070099 *
100 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700101 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700102media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700103
Marco Nelissen79e2b622014-05-16 08:07:28 -0700104/**
105 * Adds a track with the specified format.
106 * Returns the index of the new track or a negative value in case of failure,
107 * which can be interpreted as a media_status_t.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700108 *
109 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700110 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700111ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700112
Marco Nelissen79e2b622014-05-16 08:07:28 -0700113/**
114 * Start the muxer. Should be called after AMediaMuxer_addTrack and
115 * before AMediaMuxer_writeSampleData.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700116 *
117 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700118 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700119media_status_t AMediaMuxer_start(AMediaMuxer*) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700120
Marco Nelissen79e2b622014-05-16 08:07:28 -0700121/**
122 * Stops the muxer.
123 * Once the muxer stops, it can not be restarted.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700124 *
125 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700126 */
Elliott Hughes4280e862018-06-18 13:17:24 -0700127media_status_t AMediaMuxer_stop(AMediaMuxer*) __INTRODUCED_IN(21);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700128
Marco Nelissen79e2b622014-05-16 08:07:28 -0700129/**
130 * Writes an encoded sample into the muxer.
131 * The application needs to make sure that the samples are written into
132 * the right tracks. Also, it needs to make sure the samples for each track
133 * are written in chronological order (e.g. in the order they are provided
134 * by the encoder.)
Elliott Hughes64a3b062019-10-29 10:09:30 -0700135 *
136 * Available since API level 21.
Marco Nelissen79e2b622014-05-16 08:07:28 -0700137 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700138media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
Elliott Hughes4280e862018-06-18 13:17:24 -0700139 size_t trackIdx, const uint8_t *data,
140 const AMediaCodecBufferInfo *info) __INTRODUCED_IN(21);
Dan Albert2975a242016-09-23 16:17:45 -0700141
Ryan Pricharda5249752018-07-19 18:03:48 -0700142#endif /* __ANDROID_API__ >= 21 */
143
Dan Albert5e496db2017-10-05 15:03:07 -0700144__END_DECLS
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700145
146#endif // _NDK_MEDIA_MUXER_H
Dan Albertec6cd632018-04-13 15:57:25 -0700147
148/** @} */