• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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  * @file    M4MP4W_Types.h
20  * @brief   Definition of types for the core MP4 writer
21  ******************************************************************************
22  */
23 
24 #ifndef M4MP4W_TYPES_H
25 #define M4MP4W_TYPES_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30 
31 #include "NXPSW_CompilerSwitches.h"
32 
33 #ifndef _M4MP4W_USE_CST_MEMORY_WRITER
34 
35 /* includes */
36 #include "M4OSA_Types.h"
37 #include "M4OSA_FileWriter.h"
38 #include "M4OSA_FileReader.h"
39 #include "M4SYS_Stream.h"
40 
41 /**
42  ******************************************************************************
43  * structure    M4MP4C_FtypBox
44  * @brief       Information to build the 'ftyp' atom
45  ******************************************************************************
46  */
47 #define M4MPAC_FTYP_TAG 0x66747970 /* 'ftyp' */
48 #define M4MPAC_MAX_COMPATIBLE_BRANDS 10
49 typedef struct
50 {
51     /* All brand fields are actually char[4] stored in big-endian integer format */
52 
53     M4OSA_UInt32    major_brand;         /* generally '3gp4'            */
54     M4OSA_UInt32    minor_version;       /* generally '0000' or 'x.x '  */
55     M4OSA_UInt32    nbCompatibleBrands;  /* number of compatible brands */
56     M4OSA_UInt32    compatible_brands[M4MPAC_MAX_COMPATIBLE_BRANDS];   /* array of max compatible
57                                                                        brands */
58 } M4MP4C_FtypBox;
59 
60 
61 /**
62  ******************************************************************************
63  * structure    M4MP4W_memAddr
64  * @brief        Buffer structure for the MP4 writer
65  ******************************************************************************
66  */
67 typedef struct
68 {
69     M4OSA_UInt32        size;
70     M4OSA_MemAddr32    addr;
71 } M4MP4W_memAddr;
72 
73 /**
74  ******************************************************************************
75  * Time type for the core MP4 writer
76  ******************************************************************************
77  */
78 typedef M4OSA_UInt32 M4MP4W_Time32;
79 
80 /**
81  ******************************************************************************
82  * enumeration   M4MP4W_State
83  * @brief        This enum defines the core MP4 writer states
84  * @note         These states are used internaly, but can be retrieved from outside
85  *               the writer.
86  ******************************************************************************
87  */
88 typedef enum
89 {
90     M4MP4W_opened            = 0x100,
91     M4MP4W_ready             = 0x200,
92     M4MP4W_writing           = 0x300,
93     M4MP4W_writing_startAU   = 0x301,
94     M4MP4W_closed            = 0x400
95 } M4MP4W_State;
96 
97 /**
98  ******************************************************************************
99  * enumeration    M4MP4W_OptionID
100  * @brief        This enum defines the core MP4 writer options
101  * @note        These options give parameters for the core MP4 writer
102  ******************************************************************************
103  */
104 typedef enum
105 {
106     M4MP4W_maxAUperChunk        = 0xC101,
107     M4MP4W_maxChunkSize         = 0xC102,
108     M4MP4W_maxChunkInter        = 0xC103,
109     M4MP4W_preWriteCallBack     = 0xC104,
110     M4MP4W_postWriteCallBack    = 0xC105,
111     M4MP4W_maxAUsize            = 0xC106,
112     M4MP4W_IOD                  = 0xC111,
113     M4MP4W_ESD                  = 0xC112,
114     M4MP4W_SDP                  = 0xC113,
115     M4MP4W_trackSize            = 0xC114,
116     M4MP4W_MOOVfirst            = 0xC121,
117     M4MP4W_V2_MOOF              = 0xC131,
118     M4MP4W_V2_tblCompres        = 0xC132,
119     /*warning: unspecified options:*/
120     M4MP4W_maxFileSize          = 0xC152,
121     M4MP4W_CamcoderVersion      = 0xC153, /*000 to 999 !*/
122     M4MP4W_estimateAudioSize    = 0xC154, /*audio AUs are processed after the video, */
123     /*this option MUST NOT be set if non constant audio
124     frame size (e.g. if SID)*/
125     M4MP4W_embeddedString       = 0xC155,
126     M4MP4W_integrationTag       = 0xC156,
127     M4MP4W_maxFileDuration      = 0xC157,
128     M4MP4W_setFtypBox           = 0xC158,
129     M4MP4W_DSI                  = 0xC159,
130     /* H.264 trimming */
131     M4MP4W_MUL_PPS_SPS          = 0xC160,
132     /* H.264 trimming */
133 } M4MP4W_OptionID;
134 
135 /**
136  ******************************************************************************
137  * Audio & video stream IDs
138  ******************************************************************************
139  */
140 #define AudioStreamID 1
141 #define VideoStreamID 2
142 
143 /**
144  ******************************************************************************
145  * Default parameters values, that can be modified by M4MP4W_setOption
146  ******************************************************************************
147  */
148 #define M4MP4W_DefaultWidth 320
149 #define M4MP4W_DefaultHeight 240
150 #define M4MP4W_DefaultMaxAuSize  4096 /*bytes*/
151 #define M4MP4W_DefaultMaxChunkSize 100000 /*bytes*/
152 #define M4MP4W_DefaultInterleaveDur 0 /*bytes*/
153 
154 
155 /**
156  ******************************************************************************
157  * structure    M4MP4W_StreamIDsize
158  * @brief        Video plane size
159  ******************************************************************************
160  */
161 typedef struct
162 {
163     M4SYS_StreamID streamID;
164     M4OSA_UInt16    height;
165     M4OSA_UInt16    width;
166 } M4MP4W_StreamIDsize;
167 
168 /**
169  ******************************************************************************
170  * structure    M4MP4W_TrackData
171  * @brief       Internal core MP4 writer track structure
172  ******************************************************************************
173  */
174 typedef struct
175 {
176     M4SYS_StreamType    trackType;
177     M4OSA_UInt32        timescale;          /* T (video=1000), (AMR8=8000), (AMR16=16000)*/
178     M4OSA_UInt32        sampleSize;         /* S (video=0)*/
179     M4OSA_UInt32        sttsTableEntryNb;   /* J (audio=1)*/
180     M4MP4W_Time32        lastCTS;           /* CTS of the previous AU,
181                                                init to 0.Gives duration at the end.*/
182     M4OSA_UInt32        sampleNb;           /* K (audio=F)*/
183 } M4MP4W_TrackData;
184 
185 /**
186  ******************************************************************************
187  * structure    M4MP4W_AudioTrackData
188  * @brief       Internal core MP4 writer audio specific structure
189  ******************************************************************************
190  */
191 typedef struct
192 {
193     M4MP4W_State            microState;
194     M4MP4W_TrackData        CommonData;
195     M4OSA_UChar**           Chunk;
196     M4OSA_UInt32*           chunkSizeTable;
197 #ifndef _M4MP4W_MOOV_FIRST
198     M4OSA_UInt32*           chunkOffsetTable;
199 #endif /*_M4MP4W_MOOV_FIRST*/
200     M4OSA_UInt32*           chunkSampleNbTable;
201     M4OSA_UInt32*           chunkTimeMsTable;
202     M4OSA_UInt32            currentChunk;       /* Init to 0*/
203     M4OSA_UInt32            currentPos;         /* Init to 0 */
204 #ifdef _M4MP4W_OPTIMIZE_FOR_PHONE
205     M4OSA_UInt32            currentStsc;        /* Init to 0 */
206 #endif
207     M4MP4W_Time32           sampleDuration;     /* Check (AMR8=160), (AMR16=320)*/
208     M4OSA_UInt32            MaxChunkSize;       /* Init to M4MP4W_Mp4FileData.MaxChunkSize*/
209     M4OSA_UInt32            MaxAUSize;          /* Init to M4MP4W_Mp4FileData.MaxAUSize*/
210     M4OSA_UInt32            LastAllocatedChunk;
211     /* previously, audio au size was supposed constant,
212      * which is actually not the case if silences (sid).*/
213     /* at first audio au, sampleSize is set. It is later reset to 0 if non constant size.*/
214     /* So sampleSize should be tested to know weither or not there is a TABLE_STSZ. */
215     M4OSA_UInt32*           TABLE_STSZ; /* table size is 4K*/
216     M4OSA_UInt32            nbOfAllocatedStszBlocks;
217     M4OSA_UInt32*           TABLE_STTS;
218     M4OSA_UInt32            nbOfAllocatedSttsBlocks;
219     M4OSA_UInt32            maxBitrate;     /*not used in amr case*/
220     M4OSA_UInt32            avgBitrate;     /*not used in amr case*/
221     M4OSA_UChar*            DSI;            /* Decoder Specific Info: May be M4OSA_NULL
222                                             (defaulted) for AMR */
223     M4OSA_UInt8             dsiSize;        /* DSI size, always 9 bytes for AMR */
224 } M4MP4W_AudioTrackData;
225 
226 
227 /**
228  ******************************************************************************
229  * structure    M4MP4W_VideoTrackData
230  * @brief        Internal core MP4 writer video specific structure
231  ******************************************************************************
232  */
233 typedef struct
234 {
235     M4MP4W_State            microState;
236     M4MP4W_TrackData        CommonData;
237     M4OSA_UChar**           Chunk;
238     M4OSA_UInt32*           chunkSizeTable;
239 #ifndef _M4MP4W_MOOV_FIRST
240     M4OSA_UInt32*           chunkOffsetTable;
241 #endif /*_M4MP4W_MOOV_FIRST*/
242     M4OSA_UInt32*           chunkSampleNbTable;
243     M4MP4W_Time32*          chunkTimeMsTable;
244     M4OSA_UInt32            currentChunk;            /* Init to 0*/
245     M4OSA_UInt32            currentPos ;             /* Init to 0*/
246 #ifdef _M4MP4W_OPTIMIZE_FOR_PHONE
247     M4OSA_UInt32            currentStsc;             /* Init to 0*/
248 #endif
249     M4OSA_UInt32            stssTableEntryNb ;       /* N*/
250     M4OSA_UInt16            width;                   /* X*/
251     M4OSA_UInt16            height;                  /* Y*/
252     M4OSA_UInt32*           TABLE_STTS;              /* table size is J*/
253     M4OSA_UInt32            nbOfAllocatedSttsBlocks;
254 #ifdef _M4MP4W_OPTIMIZE_FOR_PHONE
255     M4OSA_UInt16*           TABLE_STSZ;              /* table size is 2K*/
256 #else
257     M4OSA_UInt32*           TABLE_STSZ;              /* table size is 4K*/
258 #endif
259     M4OSA_UInt32            nbOfAllocatedStszBlocks;
260     M4OSA_UInt32*           TABLE_STSS;              /* table size is N*/
261     M4OSA_UInt32            nbOfAllocatedStssBlocks;
262 #ifdef _M4MP4W_OPTIMIZE_FOR_PHONE
263     M4OSA_UInt32            MaxAUperChunk;           /*Init to 0, i.e. not used*/
264 #endif
265     M4OSA_UInt32            MaxChunkSize;            /*Init to M4MP4W_Mp4FileData.MaxChunkSize*/
266     M4OSA_UInt32            MaxAUSize;               /*Init to M4MP4W_Mp4FileData.MaxAUSize*/
267     M4OSA_UInt32            LastAllocatedChunk;
268     M4OSA_UInt32            maxBitrate;
269     M4OSA_UInt32            avgBitrate;
270     M4OSA_UChar*            DSI;            /* Decoder Specific Info: May be M4OSA_NULL
271                                             (defaulted) for H263*/
272     M4OSA_UInt8             dsiSize;        /* DSI size, always 7 bytes for H263 */
273 } M4MP4W_VideoTrackData;
274 
275 /**
276  ******************************************************************************
277  * structure    M4MP4W_Mp4FileData
278  * @brief       Internal core MP4 writer private context structure
279  ******************************************************************************
280  */
281 typedef struct
282 {
283     M4MP4W_State                  state;
284     M4OSA_Char*                   url;
285     M4OSA_UInt32                  duration;    /* D in ms, max duration of audio&video*/
286     M4OSA_UInt32                  filesize;    /* actual filesize in bytes*/
287     M4MP4W_AudioTrackData*        audioTrackPtr;
288     M4OSA_Bool                    hasAudio;
289     M4MP4W_VideoTrackData*        videoTrackPtr;
290     M4OSA_Bool                    hasVideo;
291     M4OSA_UInt32                  MaxChunkSize;       /* Init to 100000*/
292     M4OSA_UInt32                  MaxAUSize;          /* Init to 4096*/
293     M4OSA_UInt32                  MaxFileSize;        /* Init to 0, i.e. not used*/
294     M4MP4W_Time32                 InterleaveDur;      /* Init to 0, i.e. not used, ms*/
295     /* M4MP4W_WriteCallBack            PreWriteCallBack;*/    /*Init to M4OSA_NULL*/
296     /* M4MP4W_WriteCallBack            PostWriteCallBack;*/ /*Init to M4OSA_NULL*/
297     M4OSA_FileWriterPointer*      fileWriterFunctions;
298     M4OSA_FileReadPointer*        fileReaderFunctions;
299     M4OSA_UInt32                  camcoderVersion;
300     M4OSA_Bool                    estimateAudioSize;  /* default is false*/
301     M4OSA_UInt32                  audioMsChunkDur;    /* in ms, set only if estimateAudioSize
302                                                          is true*/
303     M4OSA_UInt32                  audioMsStopTime;    /* time to stop audio, set only if
304                                                          estimateAudioSize is true*/
305     M4OSA_Context                 fileWriterContext;
306 #ifndef _M4MP4W_MOOV_FIRST
307     M4OSA_UInt32                  absoluteCurrentPos; /* new field for offset update*/
308 #endif /*_M4MP4W_MOOV_FIRST*/
309     M4OSA_UChar*                  embeddedString;     /* 16 bytes string, default value
310                                                          writen if NULL*/
311     M4OSA_UChar*                  integrationTag;     /* 60 bytes string, memset to 0 if NULL */
312     M4OSA_UInt32                  MaxFileDuration;    /* Init to 0, i.e. not used*/
313     M4MP4C_FtypBox                ftyp;               /* ftyp atom, if not defined set major_brand
314                                                             = 0, will use default box */
315 #ifdef _M4MP4W_RESERVED_MOOV_DISK_SPACE
316     M4OSA_Char*                    safetyFileUrl;
317     M4OSA_Bool                        cleanSafetyFile;
318 #endif /* _M4MP4W_RESERVED_MOOV_DISK_SPACE */
319     M4OSA_Bool                               bMULPPSSPS;
320 } M4MP4W_Mp4FileData;
321 
322 #endif /* _M4MP4W_USE_CST_MEMORY_WRITER */
323 
324 #ifdef __cplusplus
325 }
326 #endif /* __cplusplus */
327 
328 #endif /*M4MP4W_TYPES_H*/
329 
330