blob: 25987a28a0680b0b6ea6e87d82e7514535d2b839 [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
17
18/*
19 * This file defines an NDK API.
20 * Do not remove methods.
21 * Do not change method signatures.
22 * Do not change the value of constants.
23 * Do not change the size of any of the classes defined in here.
24 * Do not reference types that are not part of the NDK.
25 * Do not #include files that aren't part of the NDK.
26 */
27
28#ifndef _NDK_MEDIA_MUXER_H
29#define _NDK_MEDIA_MUXER_H
30
Dan Albert2975a242016-09-23 16:17:45 -070031#include <sys/cdefs.h>
Marco Nelissen08aaabe2014-05-06 16:08:19 -070032#include <sys/types.h>
33
Marco Nelissen08aaabe2014-05-06 16:08:19 -070034#include "NdkMediaCodec.h"
Marco Nelissene419d7c2014-05-15 14:17:25 -070035#include "NdkMediaError.h"
36#include "NdkMediaFormat.h"
Marco Nelissen08aaabe2014-05-06 16:08:19 -070037
38#ifdef __cplusplus
39extern "C" {
40#endif
41
Dan Albert2975a242016-09-23 16:17:45 -070042#if __ANDROID_API__ >= 21
43
Marco Nelissen08aaabe2014-05-06 16:08:19 -070044struct AMediaMuxer;
45typedef struct AMediaMuxer AMediaMuxer;
46
47typedef enum {
48 AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
49 AMEDIAMUXER_OUTPUT_FORMAT_WEBM = 1,
50} OutputFormat;
51
52/**
53 * Create new media muxer
54 */
55AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);
56
57/**
58 * Delete a previously created media muxer
59 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070060media_status_t AMediaMuxer_delete(AMediaMuxer*);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070061
Marco Nelissen79e2b622014-05-16 08:07:28 -070062/**
63 * Set and store the geodata (latitude and longitude) in the output file.
64 * This method should be called before AMediaMuxer_start. The geodata is stored
65 * in udta box if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, and is
66 * ignored for other output formats.
67 * The geodata is stored according to ISO-6709 standard.
68 *
69 * Both values are specified in degrees.
70 * Latitude must be in the range [-90, 90].
71 * Longitude must be in the range [-180, 180].
72 */
73media_status_t AMediaMuxer_setLocation(AMediaMuxer*, float latitude, float longitude);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070074
Marco Nelissen79e2b622014-05-16 08:07:28 -070075/**
76 * Sets the orientation hint for output video playback.
77 * This method should be called before AMediaMuxer_start. Calling this
78 * method will not rotate the video frame when muxer is generating the file,
79 * but add a composition matrix containing the rotation angle in the output
80 * video if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, so that a
81 * video player can choose the proper orientation for playback.
82 * Note that some video players may choose to ignore the composition matrix
83 * during playback.
84 * The angle is specified in degrees, clockwise.
85 * The supported angles are 0, 90, 180, and 270 degrees.
86 */
Marco Nelissene419d7c2014-05-15 14:17:25 -070087media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees);
Marco Nelissen08aaabe2014-05-06 16:08:19 -070088
Marco Nelissen79e2b622014-05-16 08:07:28 -070089/**
90 * Adds a track with the specified format.
91 * Returns the index of the new track or a negative value in case of failure,
92 * which can be interpreted as a media_status_t.
93 */
Marco Nelissen08aaabe2014-05-06 16:08:19 -070094ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format);
95
Marco Nelissen79e2b622014-05-16 08:07:28 -070096/**
97 * Start the muxer. Should be called after AMediaMuxer_addTrack and
98 * before AMediaMuxer_writeSampleData.
99 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700100media_status_t AMediaMuxer_start(AMediaMuxer*);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700101
Marco Nelissen79e2b622014-05-16 08:07:28 -0700102/**
103 * Stops the muxer.
104 * Once the muxer stops, it can not be restarted.
105 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700106media_status_t AMediaMuxer_stop(AMediaMuxer*);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700107
Marco Nelissen79e2b622014-05-16 08:07:28 -0700108/**
109 * Writes an encoded sample into the muxer.
110 * The application needs to make sure that the samples are written into
111 * the right tracks. Also, it needs to make sure the samples for each track
112 * are written in chronological order (e.g. in the order they are provided
113 * by the encoder.)
114 */
Marco Nelissene419d7c2014-05-15 14:17:25 -0700115media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
Marco Nelissen0e03cf02014-05-21 07:53:04 -0700116 size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info);
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700117
Dan Albert2975a242016-09-23 16:17:45 -0700118#endif /* __ANDROID_API__ >= 21 */
119
Marco Nelissen08aaabe2014-05-06 16:08:19 -0700120#ifdef __cplusplus
121} // extern "C"
122#endif
123
124#endif // _NDK_MEDIA_MUXER_H