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