• 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 /*
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 
31 #include <sys/types.h>
32 
33 #include "NdkMediaCodec.h"
34 #include "NdkMediaError.h"
35 #include "NdkMediaFormat.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 struct AMediaMuxer;
42 typedef struct AMediaMuxer AMediaMuxer;
43 
44 typedef enum {
45     AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0,
46     AMEDIAMUXER_OUTPUT_FORMAT_WEBM   = 1,
47 } OutputFormat;
48 
49 /**
50  * Create new media muxer
51  */
52 AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);
53 
54 /**
55  * Delete a previously created media muxer
56  */
57 media_status_t AMediaMuxer_delete(AMediaMuxer*);
58 
59 /**
60  * Set and store the geodata (latitude and longitude) in the output file.
61  * This method should be called before AMediaMuxer_start. The geodata is stored
62  * in udta box if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, and is
63  * ignored for other output formats.
64  * The geodata is stored according to ISO-6709 standard.
65  *
66  * Both values are specified in degrees.
67  * Latitude must be in the range [-90, 90].
68  * Longitude must be in the range [-180, 180].
69  */
70 media_status_t AMediaMuxer_setLocation(AMediaMuxer*, float latitude, float longitude);
71 
72 /**
73  * Sets the orientation hint for output video playback.
74  * This method should be called before AMediaMuxer_start. Calling this
75  * method will not rotate the video frame when muxer is generating the file,
76  * but add a composition matrix containing the rotation angle in the output
77  * video if the output format is AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4, so that a
78  * video player can choose the proper orientation for playback.
79  * Note that some video players may choose to ignore the composition matrix
80  * during playback.
81  * The angle is specified in degrees, clockwise.
82  * The supported angles are 0, 90, 180, and 270 degrees.
83  */
84 media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees);
85 
86 /**
87  * Adds a track with the specified format.
88  * Returns the index of the new track or a negative value in case of failure,
89  * which can be interpreted as a media_status_t.
90  */
91 ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format);
92 
93 /**
94  * Start the muxer. Should be called after AMediaMuxer_addTrack and
95  * before AMediaMuxer_writeSampleData.
96  */
97 media_status_t AMediaMuxer_start(AMediaMuxer*);
98 
99 /**
100  * Stops the muxer.
101  * Once the muxer stops, it can not be restarted.
102  */
103 media_status_t AMediaMuxer_stop(AMediaMuxer*);
104 
105 /**
106  * Writes an encoded sample into the muxer.
107  * The application needs to make sure that the samples are written into
108  * the right tracks. Also, it needs to make sure the samples for each track
109  * are written in chronological order (e.g. in the order they are provided
110  * by the encoder.)
111  */
112 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
113         size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info);
114 
115 #ifdef __cplusplus
116 } // extern "C"
117 #endif
118 
119 #endif // _NDK_MEDIA_MUXER_H
120