Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 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 | |
Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame^] | 31 | #include <sys/cdefs.h> |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 32 | #include <sys/types.h> |
| 33 | |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 34 | #include "NdkMediaCodec.h" |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 35 | #include "NdkMediaError.h" |
| 36 | #include "NdkMediaFormat.h" |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame^] | 42 | #if __ANDROID_API__ >= 21 |
| 43 | |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 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 | */ |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 60 | media_status_t AMediaMuxer_delete(AMediaMuxer*); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 61 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 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); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 74 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 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 | */ |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 87 | media_status_t AMediaMuxer_setOrientationHint(AMediaMuxer*, int degrees); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 88 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 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 | */ |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 94 | ssize_t AMediaMuxer_addTrack(AMediaMuxer*, const AMediaFormat* format); |
| 95 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Start the muxer. Should be called after AMediaMuxer_addTrack and |
| 98 | * before AMediaMuxer_writeSampleData. |
| 99 | */ |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 100 | media_status_t AMediaMuxer_start(AMediaMuxer*); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 101 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Stops the muxer. |
| 104 | * Once the muxer stops, it can not be restarted. |
| 105 | */ |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 106 | media_status_t AMediaMuxer_stop(AMediaMuxer*); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 107 | |
Marco Nelissen | 79e2b62 | 2014-05-16 08:07:28 -0700 | [diff] [blame] | 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 | */ |
Marco Nelissen | e419d7c | 2014-05-15 14:17:25 -0700 | [diff] [blame] | 115 | media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer, |
Marco Nelissen | 0e03cf0 | 2014-05-21 07:53:04 -0700 | [diff] [blame] | 116 | size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info); |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 117 | |
Dan Albert | 2975a24 | 2016-09-23 16:17:45 -0700 | [diff] [blame^] | 118 | #endif /* __ANDROID_API__ >= 21 */ |
| 119 | |
Marco Nelissen | 08aaabe | 2014-05-06 16:08:19 -0700 | [diff] [blame] | 120 | #ifdef __cplusplus |
| 121 | } // extern "C" |
| 122 | #endif |
| 123 | |
| 124 | #endif // _NDK_MEDIA_MUXER_H |