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/cdefs.h> 32 #include <sys/types.h> 33 34 #include "NdkMediaCodec.h" 35 #include "NdkMediaError.h" 36 #include "NdkMediaFormat.h" 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #if __ANDROID_API__ >= 21 43 44 struct AMediaMuxer; 45 typedef struct AMediaMuxer AMediaMuxer; 46 47 typedef enum { 48 AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4 = 0, 49 AMEDIAMUXER_OUTPUT_FORMAT_WEBM = 1, 50 } OutputFormat; 51 52 /** 53 * Create new media muxer 54 */ 55 AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format); 56 57 /** 58 * Delete a previously created media muxer 59 */ 60 media_status_t AMediaMuxer_delete(AMediaMuxer*); 61 62 /** 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 */ 73 media_status_t AMediaMuxer_setLocation(AMediaMuxer*, float latitude, float longitude); 74 75 /** 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 */ 87 media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees); 88 89 /** 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 */ 94 ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format); 95 96 /** 97 * Start the muxer. Should be called after AMediaMuxer_addTrack and 98 * before AMediaMuxer_writeSampleData. 99 */ 100 media_status_t AMediaMuxer_start(AMediaMuxer*); 101 102 /** 103 * Stops the muxer. 104 * Once the muxer stops, it can not be restarted. 105 */ 106 media_status_t AMediaMuxer_stop(AMediaMuxer*); 107 108 /** 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 */ 115 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer, 116 size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info); 117 118 #endif /* __ANDROID_API__ >= 21 */ 119 120 #ifdef __cplusplus 121 } // extern "C" 122 #endif 123 124 #endif // _NDK_MEDIA_MUXER_H 125