• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     AMEDIAMUXER_OUTPUT_FORMAT_THREE_GPP   = 2,
55 } OutputFormat;
56 
57 typedef enum {
58     /* Last group of pictures(GOP) of video track can be incomplete, so it would be safe to
59      * scrap that and rewrite.  If both audio and video tracks are present in a file, then
60      * samples of audio track after last GOP of video would be scrapped too.
61      * If only audio track is present, then no sample would be discarded.
62      */
63     AMEDIAMUXER_APPEND_IGNORE_LAST_VIDEO_GOP = 0,
64     // Keep all existing samples as it is and append new samples after that only.
65     AMEDIAMUXER_APPEND_TO_EXISTING_DATA = 1,
66 } AppendMode;
67 
68 /**
69  * Create new media muxer.
70  *
71  * Available since API level 21.
72  */
73 AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format) __INTRODUCED_IN(21);
74 
75 /**
76  * Delete a previously created media muxer.
77  *
78  * Available since API level 21.
79  */
80 media_status_t AMediaMuxer_delete(AMediaMuxer*) __INTRODUCED_IN(21);
81 
82 /**
83  * Set and store the geodata (latitude and longitude) in the output file.
84  * This method should be called before AMediaMuxer_start. The geodata is stored
85  * in udta box if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, and is
86  * ignored for other output formats.
87  * The geodata is stored according to ISO-6709 standard.
88  *
89  * Both values are specified in degrees.
90  * Latitude must be in the range [-90, 90].
91  * Longitude must be in the range [-180, 180].
92  *
93  * Available since API level 21.
94  */
95 media_status_t AMediaMuxer_setLocation(AMediaMuxer*,
96         float latitude, float longitude) __INTRODUCED_IN(21);
97 
98 /**
99  * Sets the orientation hint for output video playback.
100  * This method should be called before AMediaMuxer_start. Calling this
101  * method will not rotate the video frame when muxer is generating the file,
102  * but add a composition matrix containing the rotation angle in the output
103  * video if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, so that a
104  * video player can choose the proper orientation for playback.
105  * Note that some video players may choose to ignore the composition matrix
106  * during playback.
107  * The angle is specified in degrees, clockwise.
108  * The supported angles are 0, 90, 180, and 270 degrees.
109  *
110  * Available since API level 21.
111  */
112 media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees) __INTRODUCED_IN(21);
113 
114 /**
115  * Adds a track with the specified format.
116  * Returns the index of the new track or a negative value in case of failure,
117  * which can be interpreted as a media_status_t.
118  *
119  * Available since API level 21.
120  */
121 ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format) __INTRODUCED_IN(21);
122 
123 /**
124  * Start the muxer. Should be called after AMediaMuxer_addTrack and
125  * before AMediaMuxer_writeSampleData.
126  *
127  * Available since API level 21.
128  */
129 media_status_t AMediaMuxer_start(AMediaMuxer*) __INTRODUCED_IN(21);
130 
131 /**
132  * Stops the muxer.
133  * Once the muxer stops, it can not be restarted.
134  *
135  * Available since API level 21.
136  */
137 media_status_t AMediaMuxer_stop(AMediaMuxer*) __INTRODUCED_IN(21);
138 
139 /**
140  * Writes an encoded sample into the muxer.
141  * The application needs to make sure that the samples are written into
142  * the right tracks. Also, it needs to make sure the samples for each track
143  * are written in chronological order (e.g. in the order they are provided
144  * by the encoder.)
145  *
146  * Available since API level 21.
147  */
148 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
149         size_t trackIdx, const uint8_t *data,
150         const AMediaCodecBufferInfo *info) __INTRODUCED_IN(21);
151 
152 /**
153  * Creates a new media muxer for appending data to an existing MPEG4 file.
154  * This is a synchronous API call and could take a while to return if the existing file is large.
155  * Only works for MPEG4 files matching one of the following characteristics:
156  * <ul>
157  *    <li>a single audio track.</li>
158  *    <li>a single video track.</li>
159  *    <li>a single audio and a single video track.</li>
160  * </ul>
161  * @param fd Must be opened with read and write permission. Does not take ownership of
162  * this fd i.e., caller is responsible for closing fd.
163  * @param mode Specifies how data will be appended; the AppendMode enum describes
164  *             the possible methods for appending..
165  * @return Pointer to AMediaMuxer if the file(fd) has tracks already, otherwise, nullptr.
166  * {@link AMediaMuxer_delete} should be used to free the returned pointer.
167  *
168  * Available since API level 31.
169  */
170 AMediaMuxer* AMediaMuxer_append(int fd, AppendMode mode) __INTRODUCED_IN(31);
171 
172 /**
173  * Returns the number of tracks added in the file passed to {@link AMediaMuxer_new} or
174  * the number of existing tracks in the file passed to {@link AMediaMuxer_append}.
175  * Should be called in INITIALIZED or STARTED state, otherwise returns -1.
176  *
177  * Available since API level 31.
178  */
179 ssize_t AMediaMuxer_getTrackCount(AMediaMuxer*) __INTRODUCED_IN(31);
180 
181 /**
182  * Returns AMediaFormat of the added track with index idx in the file passed to
183  * {@link AMediaMuxer_new} or the AMediaFormat of the existing track with index idx
184  * in the file passed to {@link AMediaMuxer_append}.
185  * Should be called in INITIALIZED or STARTED state, otherwise returns nullptr.
186  * {@link AMediaFormat_delete} should be used to free the returned pointer.
187  *
188  * Available since API level 31.
189  */
190 AMediaFormat* AMediaMuxer_getTrackFormat(AMediaMuxer* muxer, size_t idx) __INTRODUCED_IN(31);
191 
192 __END_DECLS
193 
194 #endif // _NDK_MEDIA_MUXER_H
195 
196 /** @} */
197