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  * @addtogroup Media
19  * @{
20  */
21 
22 /**
23  * @file NdkMediaMuxer.h
24  */
25 
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 
39 #include <sys/cdefs.h>
40 #include <sys/types.h>
41 
42 #include "NdkMediaCodec.h"
43 #include "NdkMediaError.h"
44 #include "NdkMediaFormat.h"
45 
46 __BEGIN_DECLS
47 
48 struct AMediaMuxer;
49 typedef struct AMediaMuxer AMediaMuxer;
50 
51 typedef enum {
52     AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
53     AMEDIAMUXER_OUTPUT_FORMAT_WEBM   = 1,
54 } OutputFormat;
55 
56 #if __ANDROID_API__ >= 21
57 
58 /**
59  * Create new media muxer.
60  *
61  * Available since API level 21.
62  */
63 AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format) __INTRODUCED_IN(21);
64 
65 /**
66  * Delete a previously created media muxer.
67  *
68  * Available since API level 21.
69  */
70 media_status_t AMediaMuxer_delete(AMediaMuxer*) __INTRODUCED_IN(21);
71 
72 /**
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].
82  *
83  * Available since API level 21.
84  */
85 media_status_t AMediaMuxer_setLocation(AMediaMuxer*,
86         float latitude, float longitude) __INTRODUCED_IN(21);
87 
88 /**
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.
99  *
100  * Available since API level 21.
101  */
102 media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees) __INTRODUCED_IN(21);
103 
104 /**
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.
108  *
109  * Available since API level 21.
110  */
111 ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format) __INTRODUCED_IN(21);
112 
113 /**
114  * Start the muxer. Should be called after AMediaMuxer_addTrack and
115  * before AMediaMuxer_writeSampleData.
116  *
117  * Available since API level 21.
118  */
119 media_status_t AMediaMuxer_start(AMediaMuxer*) __INTRODUCED_IN(21);
120 
121 /**
122  * Stops the muxer.
123  * Once the muxer stops, it can not be restarted.
124  *
125  * Available since API level 21.
126  */
127 media_status_t AMediaMuxer_stop(AMediaMuxer*) __INTRODUCED_IN(21);
128 
129 /**
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.)
135  *
136  * Available since API level 21.
137  */
138 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
139         size_t trackIdx, const uint8_t *data,
140         const AMediaCodecBufferInfo *info) __INTRODUCED_IN(21);
141 
142 #endif /* __ANDROID_API__ >= 21 */
143 
144 __END_DECLS
145 
146 #endif // _NDK_MEDIA_MUXER_H
147 
148 /** @} */
149