1 /*
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  *
12  * The Original Code is MPEG4IP.
13  *
14  * The Initial Developer of the Original Code is Cisco Systems Inc.
15  * Portions created by Cisco Systems Inc. are
16  * Copyright (C) Cisco Systems Inc. 2001 - 2005.  All Rights Reserved.
17  *
18  * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
19  * and was contributed by Ximpo Group Ltd.
20  *
21  * Portions created by Ximpo Group Ltd. are
22  * Copyright (C) Ximpo Group Ltd. 2003, 2004.  All Rights Reserved.
23  *
24  * Contributor(s):
25  *		Dave Mackie			dmackie@cisco.com
26  *		Alix Marchandise-Franquet	alix@cisco.com
27  *              Ximpo Group Ltd.                mp4v2@ximpo.com
28  *              Bill May                        wmay@cisco.com
29  */
30 
31 #ifndef __MP4_INCLUDED__
32 #define __MP4_INCLUDED__
33 
34 /* include system and project specific headers */
35 #include "mpeg4ip.h"
36 #include <math.h>	/* to define float HUGE_VAL and/or NAN */
37 #ifndef NAN
38 #define NAN HUGE_VAL
39 #endif
40 
41 #ifndef DEFAULT
42 #ifdef __cplusplus
43 /* exploit C++ ability of default values for function parameters */
44 #define DEFAULT(x)	=x
45 #else
46 #define DEFAULT(x)
47 #endif
48 #endif
49 
50 /* MP4 API types */
51 typedef void*		MP4FileHandle;
52 typedef u_int32_t	MP4TrackId;
53 typedef u_int32_t	MP4SampleId;
54 typedef u_int64_t	MP4Timestamp;
55 typedef u_int64_t	MP4Duration;
56 typedef u_int32_t	MP4EditId;
57 
58 typedef u_int64_t (*VIRTUALIO_GETFILELENGTH)(void *user); // return file length in bytes
59 typedef int (*VIRTUALIO_SETPOSITION)(void *user, u_int64_t position); // return 0 on success
60 typedef int (*VIRTUALIO_GETPOSITION)(void *user, u_int64_t *position); // fill position, return 0 on success
61 typedef size_t (*VIRTUALIO_READ)(void *user, void *buffer, size_t size); // return number of bytes actually read
62 typedef size_t (*VIRTUALIO_WRITE)(void *user, void *buffer, size_t size); // return number of bytes actually written
63 typedef int (*VIRTUALIO_ENDOFFILE)(void *user); // return 1 if file hit EOF
64 typedef int (*VIRTUALIO_CLOSE)(void *user); // return 0 on success
65 
66 typedef struct Virtual_IO
67 {
68 	VIRTUALIO_GETFILELENGTH	GetFileLength;
69 	VIRTUALIO_SETPOSITION SetPosition;
70 	VIRTUALIO_GETPOSITION GetPosition;
71 	VIRTUALIO_READ Read;
72 	VIRTUALIO_WRITE Write;
73 	VIRTUALIO_ENDOFFILE EndOfFile;
74 	VIRTUALIO_CLOSE Close;
75 } Virtual_IO_t;
76 
77 
78 /* Invalid values for API types */
79 #define MP4_INVALID_FILE_HANDLE	((MP4FileHandle)NULL)
80 #define MP4_INVALID_TRACK_ID	((MP4TrackId)0)
81 #define MP4_INVALID_SAMPLE_ID	((MP4SampleId)0)
82 #define MP4_INVALID_TIMESTAMP	((MP4Timestamp)-1)
83 #define MP4_INVALID_DURATION	((MP4Duration)-1)
84 #define MP4_INVALID_EDIT_ID		((MP4EditId)0)
85 
86 /* Macros to test for API type validity */
87 #define MP4_IS_VALID_FILE_HANDLE(x)	((x) != MP4_INVALID_FILE_HANDLE)
88 #define MP4_IS_VALID_TRACK_ID(x)	((x) != MP4_INVALID_TRACK_ID)
89 #define MP4_IS_VALID_SAMPLE_ID(x)	((x) != MP4_INVALID_SAMPLE_ID)
90 #define MP4_IS_VALID_TIMESTAMP(x)	((x) != MP4_INVALID_TIMESTAMP)
91 #define MP4_IS_VALID_DURATION(x)	((x) != MP4_INVALID_DURATION)
92 #define MP4_IS_VALID_EDIT_ID(x)		((x) != MP4_INVALID_EDIT_ID)
93 
94 /* MP4 verbosity levels - e.g. MP4SetVerbosity() */
95 #define MP4_DETAILS_ALL				0xFFFFFFFF
96 #define MP4_DETAILS_ERROR			0x00000001
97 #define MP4_DETAILS_WARNING			0x00000002
98 #define MP4_DETAILS_READ			0x00000004
99 #define MP4_DETAILS_WRITE			0x00000008
100 #define MP4_DETAILS_FIND			0x00000010
101 #define MP4_DETAILS_TABLE			0x00000020
102 #define MP4_DETAILS_SAMPLE			0x00000040
103 #define MP4_DETAILS_HINT			0x00000080
104 #define MP4_DETAILS_ISMA			0x00000100
105 #define MP4_DETAILS_EDIT			0x00000200
106 
107 #define MP4_DETAILS_READ_ALL		\
108 	(MP4_DETAILS_READ | MP4_DETAILS_TABLE | MP4_DETAILS_SAMPLE)
109 #define MP4_DETAILS_WRITE_ALL		\
110 	(MP4_DETAILS_WRITE | MP4_DETAILS_TABLE | MP4_DETAILS_SAMPLE)
111 
112 /*
113  * MP4 Known track type names - e.g. MP4GetNumberOfTracks(type)
114  *
115  * Note this first group of track types should be created
116  * via the MP4Add<Type>Track() functions, and not MP4AddTrack(type)
117  */
118 #define MP4_OD_TRACK_TYPE		"odsm"
119 #define MP4_SCENE_TRACK_TYPE	"sdsm"
120 #define MP4_AUDIO_TRACK_TYPE	"soun"
121 #define MP4_VIDEO_TRACK_TYPE	"vide"
122 #define MP4_HINT_TRACK_TYPE		"hint"
123 #define MP4_CNTL_TRACK_TYPE     "cntl"
124 #define MP4_TEXT_TRACK_TYPE		"text"
125 /*
126  * This second set of track types should be created
127  * via MP4AddSystemsTrack(type)
128  */
129 #define MP4_CLOCK_TRACK_TYPE	"crsm"
130 #define MP4_MPEG7_TRACK_TYPE	"m7sm"
131 #define MP4_OCI_TRACK_TYPE		"ocsm"
132 #define MP4_IPMP_TRACK_TYPE		"ipsm"
133 #define MP4_MPEGJ_TRACK_TYPE	"mjsm"
134 
135 #define MP4_IS_VIDEO_TRACK_TYPE(type) \
136 	(!strcasecmp(type, MP4_VIDEO_TRACK_TYPE))
137 
138 #define MP4_IS_AUDIO_TRACK_TYPE(type) \
139 	(!strcasecmp(type, MP4_AUDIO_TRACK_TYPE))
140 
141 #define MP4_IS_CNTL_TRACK_TYPE(type) \
142         (!strcasecmp(type, MP4_CNTL_TRACK_TYPE))
143 
144 #define MP4_IS_OD_TRACK_TYPE(type) \
145 	(!strcasecmp(type, MP4_OD_TRACK_TYPE))
146 
147 #define MP4_IS_SCENE_TRACK_TYPE(type) \
148 	(!strcasecmp(type, MP4_SCENE_TRACK_TYPE))
149 
150 #define MP4_IS_HINT_TRACK_TYPE(type) \
151 	(!strcasecmp(type, MP4_HINT_TRACK_TYPE))
152 
153 #define MP4_IS_SYSTEMS_TRACK_TYPE(type) \
154 	(!strcasecmp(type, MP4_CLOCK_TRACK_TYPE) \
155 	|| !strcasecmp(type, MP4_MPEG7_TRACK_TYPE) \
156 	|| !strcasecmp(type, MP4_OCI_TRACK_TYPE) \
157 	|| !strcasecmp(type, MP4_IPMP_TRACK_TYPE) \
158 	|| !strcasecmp(type, MP4_MPEGJ_TRACK_TYPE))
159 
160 /* MP4 Audio track types - see MP4AddAudioTrack()*/
161 #define MP4_INVALID_AUDIO_TYPE			0x00
162 #define MP4_MPEG1_AUDIO_TYPE			0x6B
163 #define MP4_MPEG2_AUDIO_TYPE			0x69
164 #define MP4_MP3_AUDIO_TYPE				MP4_MPEG2_AUDIO_TYPE
165 #define MP4_MPEG2_AAC_MAIN_AUDIO_TYPE	0x66
166 #define MP4_MPEG2_AAC_LC_AUDIO_TYPE		0x67
167 #define MP4_MPEG2_AAC_SSR_AUDIO_TYPE	0x68
168 #define MP4_MPEG2_AAC_AUDIO_TYPE		MP4_MPEG2_AAC_MAIN_AUDIO_TYPE
169 #define MP4_MPEG4_AUDIO_TYPE			0x40
170 #define MP4_PRIVATE_AUDIO_TYPE			0xC0
171 #define MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE	0xE0	/* a private definition */
172 #define MP4_VORBIS_AUDIO_TYPE			0xE1	/* a private definition */
173 #define MP4_AC3_AUDIO_TYPE				0xE2	/* a private definition */
174 #define MP4_ALAW_AUDIO_TYPE				0xE3	/* a private definition */
175 #define MP4_ULAW_AUDIO_TYPE				0xE4	/* a private definition */
176 #define MP4_G723_AUDIO_TYPE                             0xE5    /* a private definition */
177 #define MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE         0xE6 /* a private definition */
178 
179 /* MP4 MPEG-4 Audio types from 14496-3 Table 1.5.1 */
180 #define MP4_MPEG4_INVALID_AUDIO_TYPE		0
181 #define MP4_MPEG4_AAC_MAIN_AUDIO_TYPE		1
182 #define MP4_MPEG4_AAC_LC_AUDIO_TYPE			2
183 #define MP4_MPEG4_AAC_SSR_AUDIO_TYPE		3
184 #define MP4_MPEG4_AAC_LTP_AUDIO_TYPE		4
185 #define MP4_MPEG4_AAC_HE_AUDIO_TYPE             5
186 #define MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE	6
187 #define MP4_MPEG4_CELP_AUDIO_TYPE			8
188 #define MP4_MPEG4_HVXC_AUDIO_TYPE			9
189 #define MP4_MPEG4_TTSI_AUDIO_TYPE			12
190 #define MP4_MPEG4_MAIN_SYNTHETIC_AUDIO_TYPE	13
191 #define MP4_MPEG4_WAVETABLE_AUDIO_TYPE		14
192 #define MP4_MPEG4_MIDI_AUDIO_TYPE			15
193 #define MP4_MPEG4_ALGORITHMIC_FX_AUDIO_TYPE	16
194 #define MP4_MPEG4_ALS_AUDIO_TYPE    31
195 #define MP4_MPEG4_LAYER1_AUDIO_TYPE 32
196 #define MP4_MPEG4_LAYER2_AUDIO_TYPE 33
197 #define MP4_MPEG4_LAYER3_AUDIO_TYPE 34
198 #define MP4_MPEG4_SLS_AUDIO_TYPE    35
199 
200 /* MP4 Audio type utilities following common usage */
201 #define MP4_IS_MP3_AUDIO_TYPE(type) \
202 	((type) == MP4_MPEG1_AUDIO_TYPE || (type) == MP4_MPEG2_AUDIO_TYPE)
203 
204 #define MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
205 	(((type) >= MP4_MPEG2_AAC_MAIN_AUDIO_TYPE \
206 		&& (type) <= MP4_MPEG2_AAC_SSR_AUDIO_TYPE))
207 
208 #define MP4_IS_MPEG4_AAC_AUDIO_TYPE(mpeg4Type) \
209 	(((mpeg4Type) >= MP4_MPEG4_AAC_MAIN_AUDIO_TYPE \
210 		&& (mpeg4Type) <= MP4_MPEG4_AAC_HE_AUDIO_TYPE) \
211 	  || (mpeg4Type) == MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE \
212           || (mpeg4Type) == 17)
213 
214 #define MP4_IS_AAC_AUDIO_TYPE(type) \
215 	(MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
216 	|| (type) == MP4_MPEG4_AUDIO_TYPE)
217 
218 /* MP4 Video track types - see MP4AddVideoTrack() */
219 #define MP4_INVALID_VIDEO_TYPE			0x00
220 #define MP4_MPEG1_VIDEO_TYPE			0x6A
221 #define MP4_MPEG2_SIMPLE_VIDEO_TYPE		0x60
222 #define MP4_MPEG2_MAIN_VIDEO_TYPE		0x61
223 #define MP4_MPEG2_SNR_VIDEO_TYPE		0x62
224 #define MP4_MPEG2_SPATIAL_VIDEO_TYPE	0x63
225 #define MP4_MPEG2_HIGH_VIDEO_TYPE		0x64
226 #define MP4_MPEG2_442_VIDEO_TYPE		0x65
227 #define MP4_MPEG2_VIDEO_TYPE			MP4_MPEG2_MAIN_VIDEO_TYPE
228 #define MP4_MPEG4_VIDEO_TYPE			0x20
229 #define MP4_JPEG_VIDEO_TYPE				0x6C
230 #define MP4_PRIVATE_VIDEO_TYPE			0xD0
231 #define MP4_YUV12_VIDEO_TYPE			0xF0	/* a private definition */
232 #define MP4_H263_VIDEO_TYPE				0xF2	/* a private definition */
233 #define MP4_H261_VIDEO_TYPE				0xF3	/* a private definition */
234 
235 /* MP4 Video type utilities */
236 #define MP4_IS_MPEG1_VIDEO_TYPE(type) \
237 	((type) == MP4_MPEG1_VIDEO_TYPE)
238 
239 #define MP4_IS_MPEG2_VIDEO_TYPE(type) \
240 	(((type) >= MP4_MPEG2_SIMPLE_VIDEO_TYPE \
241 		&& (type) <= MP4_MPEG2_442_VIDEO_TYPE) \
242 	  || MP4_IS_MPEG1_VIDEO_TYPE(type))
243 
244 #define MP4_IS_MPEG4_VIDEO_TYPE(type) \
245 	((type) == MP4_MPEG4_VIDEO_TYPE)
246 
247 /* Mpeg4 Visual Profile Defines - ISO/IEC 14496-2:2001/Amd.2:2002(E) */
248 #define MPEG4_SP_L1 (0x1)
249 #define MPEG4_SP_L2 (0x2)
250 #define MPEG4_SP_L3 (0x3)
251 #define MPEG4_SP_L0 (0x8)
252 #define MPEG4_SSP_L1 (0x11)
253 #define MPEG4_SSP_L2 (0x12)
254 #define MPEG4_CP_L1 (0x21)
255 #define MPEG4_CP_L2 (0x22)
256 #define MPEG4_MP_L2 (0x32)
257 #define MPEG4_MP_L3 (0x33)
258 #define MPEG4_MP_L4 (0x34)
259 #define MPEG4_NBP_L2 (0x42)
260 #define MPEG4_STP_L1 (0x51)
261 #define MPEG4_SFAP_L1 (0x61)
262 #define MPEG4_SFAP_L2 (0x62)
263 #define MPEG4_SFBAP_L1 (0x63)
264 #define MPEG4_SFBAP_L2 (0x64)
265 #define MPEG4_BATP_L1 (0x71)
266 #define MPEG4_BATP_L2 (0x72)
267 #define MPEG4_HP_L1 (0x81)
268 #define MPEG4_HP_L2 (0x82)
269 #define MPEG4_ARTSP_L1 (0x91)
270 #define MPEG4_ARTSP_L2 (0x92)
271 #define MPEG4_ARTSP_L3 (0x93)
272 #define MPEG4_ARTSP_L4 (0x94)
273 #define MPEG4_CSP_L1 (0xa1)
274 #define MPEG4_CSP_L2 (0xa2)
275 #define MPEG4_CSP_L3 (0xa3)
276 #define MPEG4_ACEP_L1 (0xb1)
277 #define MPEG4_ACEP_L2 (0xb2)
278 #define MPEG4_ACEP_L3 (0xb3)
279 #define MPEG4_ACEP_L4 (0xb4)
280 #define MPEG4_ACP_L1 (0xc1)
281 #define MPEG4_ACP_L2 (0xc2)
282 #define MPEG4_AST_L1 (0xd1)
283 #define MPEG4_AST_L2 (0xd2)
284 #define MPEG4_AST_L3 (0xd3)
285 #define MPEG4_S_STUDIO_P_L1 (0xe1)
286 #define MPEG4_S_STUDIO_P_L2 (0xe2)
287 #define MPEG4_S_STUDIO_P_L3 (0xe3)
288 #define MPEG4_S_STUDIO_P_L4 (0xe4)
289 #define MPEG4_C_STUDIO_P_L1 (0xe5)
290 #define MPEG4_C_STUDIO_P_L2 (0xe6)
291 #define MPEG4_C_STUDIO_P_L3 (0xe7)
292 #define MPEG4_C_STUDIO_P_L4 (0xe8)
293 #define MPEG4_ASP_L0 (0xF0)
294 #define MPEG4_ASP_L1 (0xF1)
295 #define MPEG4_ASP_L2 (0xF2)
296 #define MPEG4_ASP_L3 (0xF3)
297 #define MPEG4_ASP_L4 (0xF4)
298 #define MPEG4_ASP_L5 (0xF5)
299 #define MPEG4_ASP_L3B (0xF7)
300 #define MPEG4_FGSP_L0 (0xf8)
301 #define MPEG4_FGSP_L1 (0xf9)
302 #define MPEG4_FGSP_L2 (0xfa)
303 #define MPEG4_FGSP_L3 (0xfb)
304 #define MPEG4_FGSP_L4 (0xfc)
305 #define MPEG4_FGSP_L5 (0xfd)
306 
307 /* MP4 API declarations */
308 
309 #ifdef __cplusplus
310 extern "C" {
311 #endif
312 
313 /* file operations */
314 #define MP4_CREATE_64BIT_DATA (0x01)
315 #define MP4_CREATE_64BIT_TIME (0x02) // Quicktime is not compatible with this
316 #define MP4_CREATE_64BIT (MP4_CREATE_64BIT_DATA | MP4_CREATE_64BIT_TIME)
317 #define MP4_CREATE_EXTENSIBLE_FORMAT (0x04)
318 
319 MP4FileHandle MP4Create(
320 	const char* fileName,
321 	u_int32_t verbosity DEFAULT(0),
322 	u_int32_t flags DEFAULT(0));
323 MP4FileHandle MP4CreateEx(
324         const char *fileName,
325 	u_int32_t verbosity DEFAULT(0),
326 	u_int32_t flags DEFAULT(0),
327 	int add_ftyp DEFAULT(1),
328 	int add_iods DEFAULT(1),
329 	char* majorBrand DEFAULT(0),
330 	u_int32_t minorVersion DEFAULT(0),
331 	char** supportedBrands DEFAULT(0),
332 	u_int32_t supportedBrandsCount DEFAULT(0));
333 
334 MP4FileHandle MP4Modify(
335 	const char* fileName,
336 	u_int32_t verbosity DEFAULT(0),
337 	u_int32_t flags DEFAULT(0));
338 
339 MP4FileHandle MP4Read(
340 	const char* fileName,
341 	u_int32_t verbosity DEFAULT(0));
342 
343 // benski>
344 MP4FileHandle MP4ReadEx(const char* fileName,
345 			void *user,
346 			Virtual_IO_t *virtual_IO,
347 			u_int32_t verbosity DEFAULT(0));
348 
349 void MP4Close(
350 	MP4FileHandle hFile);
351 
352 bool MP4Optimize(
353 	const char* existingFileName,
354 	const char* newFileName DEFAULT(NULL),
355 	u_int32_t verbosity DEFAULT(0));
356 
357 bool MP4Dump(
358 	MP4FileHandle hFile,
359 	FILE* pDumpFile DEFAULT(NULL),
360 	bool dumpImplicits DEFAULT(0));
361 
362 char* MP4Info(
363 	MP4FileHandle hFile,
364 	MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID));
365 
366 char* MP4FileInfo(
367 	const char* fileName,
368 	MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID));
369 
370 /* file properties */
371 
372 /* specific file properties */
373 
374 u_int32_t MP4GetVerbosity(MP4FileHandle hFile);
375 
376 void MP4SetVerbosity(MP4FileHandle hFile, u_int32_t verbosity);
377 
378 MP4Duration MP4GetDuration(MP4FileHandle hFile);
379 
380 u_int32_t MP4GetTimeScale(MP4FileHandle hFile);
381 
382 bool MP4SetTimeScale(MP4FileHandle hFile, u_int32_t value);
383 
384 u_int8_t MP4GetODProfileLevel(MP4FileHandle hFile);
385 
386 bool MP4SetODProfileLevel(MP4FileHandle hFile, u_int8_t value);
387 
388 u_int8_t MP4GetSceneProfileLevel(MP4FileHandle hFile);
389 
390 bool MP4SetSceneProfileLevel(MP4FileHandle hFile, u_int8_t value);
391 
392 u_int8_t MP4GetVideoProfileLevel(MP4FileHandle hFile,
393 				 MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID));
394 
395 void MP4SetVideoProfileLevel(MP4FileHandle hFile, u_int8_t value);
396 
397 u_int8_t MP4GetAudioProfileLevel(MP4FileHandle hFile);
398 
399 void MP4SetAudioProfileLevel(MP4FileHandle hFile, u_int8_t value);
400 
401 u_int8_t MP4GetGraphicsProfileLevel(MP4FileHandle hFile);
402 
403 bool MP4SetGraphicsProfileLevel(MP4FileHandle hFile, u_int8_t value);
404 
405 /* generic file properties */
406 bool MP4HaveAtom(MP4FileHandle hFile,
407 		 const char *atomName);
408 
409 bool MP4GetIntegerProperty(
410 	MP4FileHandle hFile,
411 	const char* propName,
412 	u_int64_t *retval );
413 
414 
415 bool MP4GetFloatProperty(
416 	MP4FileHandle hFile,
417 	const char* propName,
418 	float *retvalue);
419 
420 bool MP4GetStringProperty(
421 	MP4FileHandle hFile,
422 	const char* propName,
423 	const char **retvalue);
424 
425 bool MP4GetBytesProperty(
426 	MP4FileHandle hFile,
427 	const char* propName,
428 	u_int8_t** ppValue,
429 	u_int32_t* pValueSize);
430 
431 bool MP4SetIntegerProperty(
432 	MP4FileHandle hFile,
433 	const char* propName,
434 	int64_t value);
435 
436 bool MP4SetFloatProperty(
437 	MP4FileHandle hFile,
438 	const char* propName,
439 	float value);
440 
441 bool MP4SetStringProperty(
442 	MP4FileHandle hFile, const char* propName, const char* value);
443 
444 bool MP4SetBytesProperty(
445 	MP4FileHandle hFile, const char* propName,
446 	const u_int8_t* pValue, u_int32_t valueSize);
447 
448 /* track operations */
449 
450 MP4TrackId MP4AddTrack(
451 	MP4FileHandle hFile,
452 	const char* type);
453 
454 MP4TrackId MP4AddSystemsTrack(
455 	MP4FileHandle hFile,
456 	const char* type);
457 
458 MP4TrackId MP4AddODTrack(
459 	MP4FileHandle hFile);
460 
461 MP4TrackId MP4AddSceneTrack(
462 	MP4FileHandle hFile);
463 
464 MP4TrackId MP4AddAudioTrack(
465 	MP4FileHandle hFile,
466 	u_int32_t timeScale,
467 	MP4Duration sampleDuration,
468 	u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
469 
470 typedef struct mp4v2_ismacryp_session_params {
471   u_int32_t  scheme_type;
472   u_int16_t  scheme_version;
473   u_int8_t  key_ind_len;
474   u_int8_t  iv_len;
475   u_int8_t  selective_enc;
476   const char   *kms_uri;
477 } mp4v2_ismacrypParams;
478 
479 // API to initialize ismacryp properties to sensible defaults
480 // if input param is null then mallocs a params struct
481 mp4v2_ismacrypParams *MP4DefaultISMACrypParams(mp4v2_ismacrypParams *ptr);
482 
483 MP4TrackId MP4AddEncAudioTrack(
484 	MP4FileHandle hFile,
485 	u_int32_t timeScale,
486 	MP4Duration sampleDuration,
487         mp4v2_ismacrypParams *icPp,
488 	u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
489 
490 MP4TrackId MP4AddAmrAudioTrack(
491 		MP4FileHandle hFile,
492 		u_int32_t timeScale,
493 		u_int16_t modeSet,
494 		u_int8_t modeChangePeriod,
495 		u_int8_t framesPerSample,
496 		bool isAmrWB);
497 
498 void MP4SetAmrVendor(
499 		MP4FileHandle hFile,
500 		MP4TrackId trackId,
501 		u_int32_t vendor);
502 
503 void MP4SetAmrDecoderVersion(
504 		MP4FileHandle hFile,
505 		MP4TrackId trackId,
506 		u_int8_t decoderVersion);
507 
508 void MP4SetAmrModeSet(MP4FileHandle hFile, MP4TrackId trakId, uint16_t modeSet);
509 uint16_t MP4GetAmrModeSet(MP4FileHandle hFile, MP4TrackId trackId);
510 
511 MP4TrackId MP4AddHrefTrack(MP4FileHandle hFile,
512 			   uint32_t timeScale,
513 			   MP4Duration sampleDuration,
514 			   const char *base_url DEFAULT(NULL));
515 
516 const char *MP4GetHrefTrackBaseUrl(MP4FileHandle hFile,
517 				   MP4TrackId trackId);
518 MP4TrackId MP4AddVideoTrack(
519 	MP4FileHandle hFile,
520 	u_int32_t timeScale,
521 	MP4Duration sampleDuration,
522 	u_int16_t width,
523 	u_int16_t height,
524 	u_int8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE));
525 
526 MP4TrackId MP4AddEncVideoTrack(
527 	MP4FileHandle hFile,
528 	u_int32_t timeScale,
529 	MP4Duration sampleDuration,
530 	u_int16_t width,
531 	u_int16_t height,
532         mp4v2_ismacrypParams *icPp,
533 	u_int8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE),
534 	const char *oFormat DEFAULT(NULL));
535 
536 MP4TrackId MP4AddH264VideoTrack(
537 				MP4FileHandle hFile,
538 				u_int32_t timeScale,
539 				MP4Duration sampleDuration,
540 				u_int16_t width,
541 				u_int16_t height,
542 				uint8_t AVCProfileIndication,
543 				uint8_t profile_compat,
544 				uint8_t AVCLevelIndication,
545 				uint8_t sampleLenFieldSizeMinusOne);
546 
547 MP4TrackId MP4AddEncH264VideoTrack(
548 				MP4FileHandle dstFile,
549 				u_int32_t timeScale,
550 				MP4Duration sampleDuration,
551 				u_int16_t width,
552 				u_int16_t height,
553 				MP4FileHandle srcFile,
554 				MP4TrackId srcTrackId,
555 				mp4v2_ismacrypParams *icPp);
556 
557 void MP4AddH264SequenceParameterSet(MP4FileHandle hFile,
558 				    MP4TrackId trackId,
559 				    const uint8_t *pSequence,
560 				    uint16_t sequenceLen);
561 void MP4AddH264PictureParameterSet(MP4FileHandle hFile,
562 				   MP4TrackId trackId,
563 				   const uint8_t *pPict,
564 				   uint16_t pictLen);
565 void MP4SetH263Vendor(
566 		MP4FileHandle hFile,
567 		MP4TrackId trackId,
568 		u_int32_t vendor);
569 
570 void  MP4SetH263DecoderVersion(
571 		MP4FileHandle hFile,
572 		MP4TrackId trackId,
573 		u_int8_t decoderVersion);
574 
575 void MP4SetH263Bitrates(
576 		MP4FileHandle hFile,
577 		MP4TrackId trackId,
578 		u_int32_t avgBitrate,
579 		u_int32_t maxBitrate);
580 
581 MP4TrackId MP4AddH263VideoTrack(
582 		MP4FileHandle hFile,
583 		u_int32_t timeScale,
584 		MP4Duration sampleDuration,
585 		u_int16_t width,
586 		u_int16_t height,
587 		u_int8_t h263Level,
588 		u_int8_t h263Profile,
589 		u_int32_t avgBitrate,
590 		u_int32_t maxBitrate);
591 
592 MP4TrackId MP4AddHintTrack(
593 	MP4FileHandle hFile,
594 	MP4TrackId refTrackId);
595 
596 MP4TrackId MP4AddTextTrack(
597 	MP4FileHandle hFile,
598 	MP4TrackId refTrackId);
599 
600 MP4TrackId MP4AddChapterTextTrack(
601 	MP4FileHandle hFile,
602 	MP4TrackId refTrackId);
603 
604 MP4TrackId MP4CloneTrack(
605 	MP4FileHandle srcFile,
606 	MP4TrackId srcTrackId,
607 	MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
608 	MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
609 
610 MP4TrackId MP4EncAndCloneTrack(
611         MP4FileHandle srcFile,
612         MP4TrackId srcTrackId,
613         mp4v2_ismacrypParams *icPp,
614         MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
615         MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
616 
617 MP4TrackId MP4CopyTrack(
618 	MP4FileHandle srcFile,
619 	MP4TrackId srcTrackId,
620 	MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
621 	bool applyEdits DEFAULT(false),
622 	MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
623 
624 typedef u_int32_t (*encryptFunc_t)(u_int32_t, u_int32_t, u_int8_t*, u_int32_t*, u_int8_t **);
625 
626 MP4TrackId MP4EncAndCopyTrack(
627 	MP4FileHandle srcFile,
628 	MP4TrackId srcTrackId,
629         mp4v2_ismacrypParams *icPp,
630         encryptFunc_t encfcnp,
631         u_int32_t encfcnparam1,
632 	MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
633 	bool applyEdits DEFAULT(false),
634 	MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
635 
636 void MP4DeleteTrack(
637 	MP4FileHandle hFile,
638 	MP4TrackId trackId);
639 
640 u_int32_t MP4GetNumberOfTracks(
641 	MP4FileHandle hFile,
642 	const char* type DEFAULT(NULL),
643 	u_int8_t subType DEFAULT(0));
644 
645 MP4TrackId MP4FindTrackId(
646 	MP4FileHandle hFile,
647 	u_int16_t index,
648 	const char* type DEFAULT(NULL),
649 	u_int8_t subType DEFAULT(0));
650 
651 u_int16_t MP4FindTrackIndex(
652 	MP4FileHandle hFile,
653 	MP4TrackId trackId);
654 
655 /* track properties */
656 
657 /* specific track properties */
658 
659 bool MP4HaveTrackAtom(MP4FileHandle hFile,
660 		      MP4TrackId trackId,
661 		      const char *atomname);
662 
663 const char* MP4GetTrackType(
664 	MP4FileHandle hFile,
665 	MP4TrackId trackId);
666 
667 const char *MP4GetTrackMediaDataName(MP4FileHandle hFile,
668 				     MP4TrackId trackId);
669 
670 // MP4GetTrackMediaDataOriginalFormat is to be used to get the original
671 // MediaDataName if a track has been encrypted.
672 bool MP4GetTrackMediaDataOriginalFormat(MP4FileHandle hFile,
673 	    MP4TrackId trackId, char *originalFormat, u_int32_t buflen);
674 
675 MP4Duration MP4GetTrackDuration(
676 	MP4FileHandle hFile,
677 	MP4TrackId trackId);
678 
679 u_int32_t MP4GetTrackTimeScale(
680 	MP4FileHandle hFile,
681 	MP4TrackId trackId);
682 
683 void MP4SetTrackTimeScale(
684 	MP4FileHandle hFile,
685 	MP4TrackId trackId,
686 	u_int32_t value);
687 
688 u_int8_t MP4GetTrackAudioMpeg4Type(
689 	MP4FileHandle hFile,
690 	MP4TrackId trackId);
691 
692 u_int8_t MP4GetTrackEsdsObjectTypeId(
693 	MP4FileHandle hFile,
694 	MP4TrackId trackId);
695 
696 /* returns MP4_INVALID_DURATION if track samples do not have a fixed duration */
697 MP4Duration MP4GetTrackFixedSampleDuration(
698 	MP4FileHandle hFile,
699 	MP4TrackId trackId);
700 
701 u_int32_t MP4GetTrackBitRate(
702 	MP4FileHandle hFile,
703 	MP4TrackId trackId);
704 
705 bool MP4GetTrackVideoMetadata(MP4FileHandle hFile,
706 			      MP4TrackId trackId,
707 			      uint8_t **ppConfig,
708 			      uint32_t *pConfigSize);
709 
710 bool MP4GetTrackESConfiguration(
711 	MP4FileHandle hFile,
712 	MP4TrackId trackId,
713 	u_int8_t** ppConfig,
714 	u_int32_t* pConfigSize);
715 
716 bool MP4SetTrackESConfiguration(
717 	MP4FileHandle hFile,
718 	MP4TrackId trackId,
719 	const u_int8_t* pConfig,
720 	u_int32_t configSize);
721 
722 /* h264 information routines */
723 bool MP4GetTrackH264ProfileLevel(MP4FileHandle hFile,
724 				 MP4TrackId trackId,
725 				 uint8_t *pProfile,
726 				 uint8_t *pLevel);
727 void MP4GetTrackH264SeqPictHeaders(MP4FileHandle hFile,
728 				   MP4TrackId trackId,
729 				   uint8_t ***pSeqHeaders,
730 				   uint32_t **pSeqHeaderSize,
731 				   uint8_t ***pPictHeader,
732 				   uint32_t **pPictHeaderSize);
733 bool MP4GetTrackH264LengthSize(MP4FileHandle hFile,
734 			       MP4TrackId trackId,
735 			       uint32_t *pLength);
736 MP4SampleId MP4GetTrackNumberOfSamples(
737 	MP4FileHandle hFile,
738 	MP4TrackId trackId);
739 
740 u_int16_t MP4GetTrackVideoWidth(
741 	MP4FileHandle hFile,
742 	MP4TrackId trackId);
743 
744 u_int16_t MP4GetTrackVideoHeight(
745 	MP4FileHandle hFile,
746 	MP4TrackId trackId);
747 
748 double MP4GetTrackVideoFrameRate(
749 	MP4FileHandle hFile,
750 	MP4TrackId trackId);
751 
752 int MP4GetTrackAudioChannels(MP4FileHandle hFile,
753 				  MP4TrackId trackId);
754 
755 bool MP4IsIsmaCrypMediaTrack(
756         MP4FileHandle hFile,
757         MP4TrackId trackId);
758 
759 /* generic track properties */
760 
761 bool MP4HaveTrackAtom(MP4FileHandle hFile,
762 		      MP4TrackId trackId,
763 		      const char *atomName);
764 
765 bool MP4GetTrackIntegerProperty(
766 	MP4FileHandle hFile,
767 	MP4TrackId trackId,
768 	const char* propName,
769 	u_int64_t *retvalue);
770 
771 bool MP4GetTrackFloatProperty(
772 	MP4FileHandle hFile,
773 	MP4TrackId trackId,
774 	const char* propName,
775 	float *ret_value);
776 
777 bool MP4GetTrackStringProperty(
778 	MP4FileHandle hFile,
779 	MP4TrackId trackId,
780 	const char* propName,
781 	const char **retvalue);
782 
783 bool MP4GetTrackBytesProperty(
784 	MP4FileHandle hFile,
785 	MP4TrackId trackId,
786 	const char* propName,
787 	u_int8_t** ppValue,
788 	u_int32_t* pValueSize);
789 
790 bool MP4SetTrackIntegerProperty(
791 	MP4FileHandle hFile,
792 	MP4TrackId trackId,
793 	const char* propName,
794 	int64_t value);
795 
796 bool MP4SetTrackFloatProperty(
797 	MP4FileHandle hFile,
798 	MP4TrackId trackId,
799 	const char* propName,
800 	float value);
801 
802 bool MP4SetTrackStringProperty(
803 	MP4FileHandle hFile,
804 	MP4TrackId trackId,
805 	const char* propName,
806 	const char* value);
807 
808 bool MP4SetTrackBytesProperty(
809 	MP4FileHandle hFile,
810 	MP4TrackId trackId,
811 	const char* propName,
812 	const u_int8_t* pValue,
813 	u_int32_t valueSize);
814 
815 /* sample operations */
816 
817 bool MP4ReadSample(
818 	/* input parameters */
819 	MP4FileHandle hFile,
820 	MP4TrackId trackId,
821 	MP4SampleId sampleId,
822 	/* input/output parameters */
823 	u_int8_t** ppBytes,
824 	u_int32_t* pNumBytes,
825 	/* output parameters */
826 	MP4Timestamp* pStartTime DEFAULT(NULL),
827 	MP4Duration* pDuration DEFAULT(NULL),
828 	MP4Duration* pRenderingOffset DEFAULT(NULL),
829 	bool* pIsSyncSample DEFAULT(NULL));
830 
831 /* uses (unedited) time to specify sample instead of sample id */
832 bool MP4ReadSampleFromTime(
833 	/* input parameters */
834 	MP4FileHandle hFile,
835 	MP4TrackId trackId,
836 	MP4Timestamp when,
837 	/* input/output parameters */
838 	u_int8_t** ppBytes,
839 	u_int32_t* pNumBytes,
840 	/* output parameters */
841 	MP4Timestamp* pStartTime DEFAULT(NULL),
842 	MP4Duration* pDuration DEFAULT(NULL),
843 	MP4Duration* pRenderingOffset DEFAULT(NULL),
844 	bool* pIsSyncSample DEFAULT(NULL));
845 
846 bool MP4WriteSample(
847 	MP4FileHandle hFile,
848 	MP4TrackId trackId,
849 	const u_int8_t* pBytes,
850 	u_int32_t numBytes,
851 	MP4Duration duration DEFAULT(MP4_INVALID_DURATION),
852 	MP4Duration renderingOffset DEFAULT(0),
853 	bool isSyncSample DEFAULT(true));
854 
855 bool MP4CopySample(
856 	MP4FileHandle srcFile,
857 	MP4TrackId srcTrackId,
858 	MP4SampleId srcSampleId,
859 	MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
860 	MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
861 	MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
862 
863 bool MP4EncAndCopySample(
864 	MP4FileHandle srcFile,
865 	MP4TrackId srcTrackId,
866 	MP4SampleId srcSampleId,
867         encryptFunc_t encfcnp,
868         u_int32_t encfcnparam1,
869 	MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
870 	MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
871 	MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
872 
873 /* Note this function is not yet implemented */
874 bool MP4ReferenceSample(
875 	MP4FileHandle srcFile,
876 	MP4TrackId srcTrackId,
877 	MP4SampleId srcSampleId,
878 	MP4FileHandle dstFile,
879 	MP4TrackId dstTrackId,
880 	MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
881 
882 u_int32_t MP4GetSampleSize(
883 	MP4FileHandle hFile,
884 	MP4TrackId trackId,
885 	MP4SampleId sampleId);
886 
887 u_int32_t MP4GetTrackMaxSampleSize(
888 	MP4FileHandle hFile,
889 	MP4TrackId trackId);
890 
891 MP4SampleId MP4GetSampleIdFromTime(
892 	MP4FileHandle hFile,
893 	MP4TrackId trackId,
894 	MP4Timestamp when,
895 	bool wantSyncSample DEFAULT(false));
896 
897 MP4Timestamp MP4GetSampleTime(
898 	MP4FileHandle hFile,
899 	MP4TrackId trackId,
900 	MP4SampleId sampleId);
901 
902 MP4Duration MP4GetSampleDuration(
903 	MP4FileHandle hFile,
904 	MP4TrackId trackId,
905 	MP4SampleId sampleId);
906 
907 MP4Duration MP4GetSampleRenderingOffset(
908 	MP4FileHandle hFile,
909 	MP4TrackId trackId,
910 	MP4SampleId sampleId);
911 
912 bool MP4SetSampleRenderingOffset(
913 	MP4FileHandle hFile,
914 	MP4TrackId trackId,
915 	MP4SampleId sampleId,
916 	MP4Duration renderingOffset);
917 
918 int8_t MP4GetSampleSync(
919 	MP4FileHandle hFile,
920 	MP4TrackId trackId,
921 	MP4SampleId sampleId);
922 
923 /* rtp hint track operations */
924 
925 bool MP4GetHintTrackRtpPayload(
926 	MP4FileHandle hFile,
927 	MP4TrackId hintTrackId,
928 	char** ppPayloadName DEFAULT(NULL),
929 	u_int8_t* pPayloadNumber DEFAULT(NULL),
930 	u_int16_t* pMaxPayloadSize DEFAULT(NULL),
931 	char **ppEncodingParams DEFAULT(NULL));
932 
933 #define MP4_SET_DYNAMIC_PAYLOAD 0xff
934 
935 bool MP4SetHintTrackRtpPayload(
936 	MP4FileHandle hFile,
937 	MP4TrackId hintTrackId,
938 	const char* pPayloadName,
939 	u_int8_t* pPayloadNumber,
940 	u_int16_t maxPayloadSize DEFAULT(0),
941 	const char *encode_params DEFAULT(NULL),
942 	bool include_rtp_map DEFAULT(true),
943 	bool include_mpeg4_esid DEFAULT(true));
944 
945 const char* MP4GetSessionSdp(
946 	MP4FileHandle hFile);
947 
948 bool MP4SetSessionSdp(
949 	MP4FileHandle hFile,
950 	const char* sdpString);
951 
952 bool MP4AppendSessionSdp(
953 	MP4FileHandle hFile,
954 	const char* sdpString);
955 
956 const char* MP4GetHintTrackSdp(
957 	MP4FileHandle hFile,
958 	MP4TrackId hintTrackId);
959 
960 bool MP4SetHintTrackSdp(
961 	MP4FileHandle hFile,
962 	MP4TrackId hintTrackId,
963 	const char* sdpString);
964 
965 bool MP4AppendHintTrackSdp(
966 	MP4FileHandle hFile,
967 	MP4TrackId hintTrackId,
968 	const char* sdpString);
969 
970 MP4TrackId MP4GetHintTrackReferenceTrackId(
971 	MP4FileHandle hFile,
972 	MP4TrackId hintTrackId);
973 
974 bool MP4ReadRtpHint(
975 	MP4FileHandle hFile,
976 	MP4TrackId hintTrackId,
977 	MP4SampleId hintSampleId,
978 	u_int16_t* pNumPackets DEFAULT(NULL));
979 
980 u_int16_t MP4GetRtpHintNumberOfPackets(
981 	MP4FileHandle hFile,
982 	MP4TrackId hintTrackId);
983 
984 int8_t MP4GetRtpPacketBFrame(
985 	MP4FileHandle hFile,
986 	MP4TrackId hintTrackId,
987 	u_int16_t packetIndex);
988 
989 int32_t MP4GetRtpPacketTransmitOffset(
990 	MP4FileHandle hFile,
991 	MP4TrackId hintTrackId,
992 	u_int16_t packetIndex);
993 
994 bool MP4ReadRtpPacket(
995 	MP4FileHandle hFile,
996 	MP4TrackId hintTrackId,
997 	u_int16_t packetIndex,
998 	u_int8_t** ppBytes,
999 	u_int32_t* pNumBytes,
1000 	u_int32_t ssrc DEFAULT(0),
1001 	bool includeHeader DEFAULT(true),
1002 	bool includePayload DEFAULT(true));
1003 
1004 MP4Timestamp MP4GetRtpTimestampStart(
1005 	MP4FileHandle hFile,
1006 	MP4TrackId hintTrackId);
1007 
1008 bool MP4SetRtpTimestampStart(
1009 	MP4FileHandle hFile,
1010 	MP4TrackId hintTrackId,
1011 	MP4Timestamp rtpStart);
1012 
1013 bool MP4AddRtpHint(
1014 	MP4FileHandle hFile,
1015 	MP4TrackId hintTrackId);
1016 
1017 bool MP4AddRtpVideoHint(
1018 	MP4FileHandle hFile,
1019 	MP4TrackId hintTrackId,
1020 	bool isBframe DEFAULT(false),
1021 	u_int32_t timestampOffset DEFAULT(0));
1022 
1023 bool MP4AddRtpPacket(
1024 	MP4FileHandle hFile,
1025 	MP4TrackId hintTrackId,
1026 	bool setMbit DEFAULT(false),
1027 	int32_t transmitOffset DEFAULT(0));
1028 
1029 bool MP4AddRtpImmediateData(
1030 	MP4FileHandle hFile,
1031 	MP4TrackId hintTrackId,
1032 	const u_int8_t* pBytes,
1033 	u_int32_t numBytes);
1034 
1035 bool MP4AddRtpSampleData(
1036 	MP4FileHandle hFile,
1037 	MP4TrackId hintTrackId,
1038 	MP4SampleId sampleId,
1039 	u_int32_t dataOffset,
1040 	u_int32_t dataLength);
1041 
1042 bool MP4AddRtpESConfigurationPacket(
1043 	MP4FileHandle hFile,
1044 	MP4TrackId hintTrackId);
1045 
1046 bool MP4WriteRtpHint(
1047 	MP4FileHandle hFile,
1048 	MP4TrackId hintTrackId,
1049 	MP4Duration duration,
1050 	bool isSyncSample DEFAULT(true));
1051 
1052 /* 3GP specific utilities */
1053 
1054 bool MP4Make3GPCompliant(
1055 	const char* fileName,
1056 	u_int32_t verbosity DEFAULT(0),
1057 	char* majorBrand DEFAULT(0),
1058 	u_int32_t minorVersion DEFAULT(0),
1059 	char** supportedBrands DEFAULT(NULL),
1060 	u_int32_t supportedBrandsCount DEFAULT(0),
1061 	bool deleteIodsAtom DEFAULT(true));
1062 
1063 /* ISMA specific utilities */
1064 
1065 bool MP4MakeIsmaCompliant(const char* fileName,
1066 	u_int32_t verbosity DEFAULT(0),
1067 	bool addIsmaComplianceSdp DEFAULT(true));
1068 
1069 char* MP4MakeIsmaSdpIod(
1070 	u_int8_t videoProfile,
1071 	u_int32_t videoBitrate,
1072 	u_int8_t* videoConfig,
1073 	u_int32_t videoConfigLength,
1074 	u_int8_t audioProfile,
1075 	u_int32_t audioBitrate,
1076 	u_int8_t* audioConfig,
1077 	u_int32_t audioConfigLength,
1078 	u_int32_t verbosity DEFAULT(0));
1079 
1080 /* edit list */
1081 
1082 /* NOTE this section of functionality
1083  * has not yet been fully tested
1084  */
1085 
1086 MP4EditId MP4AddTrackEdit(
1087 	MP4FileHandle hFile,
1088 	MP4TrackId trackId,
1089 	MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID),
1090 	MP4Timestamp startTime DEFAULT(0),
1091 	MP4Duration duration DEFAULT(0),
1092 	bool dwell DEFAULT(false));
1093 
1094 bool MP4DeleteTrackEdit(
1095 	MP4FileHandle hFile,
1096 	MP4TrackId trackId,
1097 	MP4EditId editId);
1098 
1099 u_int32_t MP4GetTrackNumberOfEdits(
1100 	MP4FileHandle hFile,
1101 	MP4TrackId trackId);
1102 
1103 MP4Timestamp MP4GetTrackEditStart(
1104 	MP4FileHandle hFile,
1105 	MP4TrackId trackId,
1106 	MP4EditId editId);
1107 
1108 MP4Duration MP4GetTrackEditTotalDuration(
1109 	MP4FileHandle hFile,
1110 	MP4TrackId trackId,
1111 	MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID));
1112 
1113 MP4Timestamp MP4GetTrackEditMediaStart(
1114 	MP4FileHandle hFile,
1115 	MP4TrackId trackId,
1116 	MP4EditId editId);
1117 
1118 bool MP4SetTrackEditMediaStart(
1119 	MP4FileHandle hFile,
1120 	MP4TrackId trackId,
1121 	MP4EditId editId,
1122 	MP4Timestamp startTime);
1123 
1124 MP4Duration MP4GetTrackEditDuration(
1125 	MP4FileHandle hFile,
1126 	MP4TrackId trackId,
1127 	MP4EditId editId);
1128 
1129 bool MP4SetTrackEditDuration(
1130 	MP4FileHandle hFile,
1131 	MP4TrackId trackId,
1132 	MP4EditId editId,
1133 	MP4Duration duration);
1134 
1135 int8_t MP4GetTrackEditDwell(
1136 	MP4FileHandle hFile,
1137 	MP4TrackId trackId,
1138 	MP4EditId editId);
1139 
1140 bool MP4SetTrackEditDwell(
1141 	MP4FileHandle hFile,
1142 	MP4TrackId trackId,
1143 	MP4EditId editId,
1144 	bool dwell);
1145 
1146 bool MP4ReadSampleFromEditTime(
1147 	/* input parameters */
1148 	MP4FileHandle hFile,
1149 	MP4TrackId trackId,
1150 	MP4Timestamp when,
1151 	/* input/output parameters */
1152 	u_int8_t** ppBytes,
1153 	u_int32_t* pNumBytes,
1154 	/* output parameters */
1155 	MP4Timestamp* pStartTime DEFAULT(NULL),
1156 	MP4Duration* pDuration DEFAULT(NULL),
1157 	MP4Duration* pRenderingOffset DEFAULT(NULL),
1158 	bool* pIsSyncSample DEFAULT(NULL));
1159 
1160 MP4SampleId MP4GetSampleIdFromEditTime(
1161 	MP4FileHandle hFile,
1162 	MP4TrackId trackId,
1163 	MP4Timestamp when,
1164 	MP4Timestamp* pStartTime DEFAULT(NULL),
1165 	MP4Duration* pDuration DEFAULT(NULL));
1166 /* iTunes metadata handling */
1167 bool MP4MetadataDelete(MP4FileHandle hFile);
1168 bool MP4GetMetadataByIndex(MP4FileHandle hFile, u_int32_t index,
1169 			   char** ppName, // need to free memory
1170 			   u_int8_t** ppValue,  // need to free
1171 			   u_int32_t* pValueSize);
1172 bool MP4SetMetadataName(MP4FileHandle hFile, const char* value);
1173 bool MP4GetMetadataName(MP4FileHandle hFile, char** value);
1174 bool MP4DeleteMetadataName(MP4FileHandle hFile);
1175 bool MP4SetMetadataArtist(MP4FileHandle hFile, const char* value);
1176 bool MP4GetMetadataArtist(MP4FileHandle hFile, char** value);
1177 bool MP4DeleteMetadataArtist(MP4FileHandle hFile);
1178 bool MP4SetMetadataWriter(MP4FileHandle hFile, const char* value);
1179 bool MP4GetMetadataWriter(MP4FileHandle hFile, char** value);
1180 bool MP4DeleteMetadataWriter(MP4FileHandle hFile);
1181 bool MP4SetMetadataComment(MP4FileHandle hFile, const char* value);
1182 bool MP4GetMetadataComment(MP4FileHandle hFile, char** value);
1183 bool MP4DeleteMetadataComment(MP4FileHandle hFile);
1184 bool MP4SetMetadataTool(MP4FileHandle hFile, const char* value);
1185 bool MP4GetMetadataTool(MP4FileHandle hFile, char** value);
1186 bool MP4DeleteMetadataTool(MP4FileHandle hFile);
1187 bool MP4SetMetadataYear(MP4FileHandle hFile, const char* value);
1188 bool MP4GetMetadataYear(MP4FileHandle hFile, char** value);
1189 bool MP4DeleteMetadataYear(MP4FileHandle hFile);
1190 bool MP4SetMetadataAlbum(MP4FileHandle hFile, const char* value);
1191 bool MP4GetMetadataAlbum(MP4FileHandle hFile, char** value);
1192 bool MP4DeleteMetadataAlbum(MP4FileHandle hFile);
1193 bool MP4SetMetadataTrack(MP4FileHandle hFile,
1194 			 u_int16_t track, u_int16_t totalTracks);
1195 bool MP4GetMetadataTrack(MP4FileHandle hFile,
1196 			 u_int16_t* track, u_int16_t* totalTracks);
1197 bool MP4DeleteMetadataTrack(MP4FileHandle hFile);
1198 bool MP4SetMetadataDisk(MP4FileHandle hFile,
1199 			u_int16_t disk, u_int16_t totalDisks);
1200 bool MP4GetMetadataDisk(MP4FileHandle hFile,
1201 			u_int16_t* disk, u_int16_t* totalDisks);
1202 bool MP4DeleteMetadataDisk(MP4FileHandle hFile);
1203 bool MP4SetMetadataGenre(MP4FileHandle hFile, const char *genre);
1204 bool MP4GetMetadataGenre(MP4FileHandle hFile, char **genre);
1205 bool MP4DeleteMetadataGenre(MP4FileHandle hFile);
1206 bool MP4SetMetadataGrouping(MP4FileHandle hFile, const char *grouping);
1207 bool MP4GetMetadataGrouping(MP4FileHandle hFile, char **grouping);
1208 bool MP4DeleteMetadataGrouping(MP4FileHandle hFile);
1209 bool MP4SetMetadataTempo(MP4FileHandle hFile, u_int16_t tempo);
1210 bool MP4GetMetadataTempo(MP4FileHandle hFile, u_int16_t* tempo);
1211 bool MP4DeleteMetadataTempo(MP4FileHandle hFile);
1212 bool MP4SetMetadataCompilation(MP4FileHandle hFile, u_int8_t cpl);
1213 bool MP4GetMetadataCompilation(MP4FileHandle hFile, u_int8_t* cpl);
1214 bool MP4DeleteMetadataCompilation(MP4FileHandle hFile);
1215 bool MP4SetMetadataPartOfGaplessAlbum(MP4FileHandle hFile, uint8_t pgap);
1216 bool MP4GetMetadataPartOfGaplessAlbum(MP4FileHandle hFile, uint8_t *pgap);
1217 bool MP4DeleteMetadataPartOfGaplessAlbum(MP4FileHandle hFile);
1218 bool MP4SetMetadataCoverArt(MP4FileHandle hFile,
1219 			    u_int8_t *coverArt, u_int32_t size);
1220 bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
1221 			    u_int8_t **coverArt, u_int32_t* size,
1222 			    uint32_t index DEFAULT(0));
1223 u_int32_t MP4GetMetadataCoverArtCount(MP4FileHandle hFile);
1224 bool MP4DeleteMetadataCoverArt(MP4FileHandle hFile);
1225 bool MP4SetMetadataAlbumArtist(MP4FileHandle hFile, const char* value);
1226 bool MP4GetMetadataAlbumArtist(MP4FileHandle hFile,    char** value);
1227 bool MP4DeleteMetadataAlbumArtist(MP4FileHandle hFile);
1228 
1229 
1230 bool MP4SetMetadataFreeForm(MP4FileHandle hFile, const char *name,
1231 			    const u_int8_t* pValue, u_int32_t valueSize, const char *owner DEFAULT(NULL));
1232 bool MP4GetMetadataFreeForm(MP4FileHandle hFile, const char *name,
1233 			    u_int8_t** pValue, u_int32_t* valueSize, const char *owner DEFAULT(NULL));
1234 bool MP4DeleteMetadataFreeForm(MP4FileHandle hFile, const char *name, const char *owner DEFAULT(NULL));
1235 
1236 /* time conversion utilties */
1237 
1238 /* predefined values for timeScale parameter below */
1239 #define MP4_SECONDS_TIME_SCALE		1
1240 #define MP4_MILLISECONDS_TIME_SCALE 1000
1241 #define MP4_MICROSECONDS_TIME_SCALE 1000000
1242 #define MP4_NANOSECONDS_TIME_SCALE 	1000000000
1243 
1244 #define MP4_SECS_TIME_SCALE 	MP4_SECONDS_TIME_SCALE
1245 #define MP4_MSECS_TIME_SCALE	MP4_MILLISECONDS_TIME_SCALE
1246 #define MP4_USECS_TIME_SCALE	MP4_MICROSECONDS_TIME_SCALE
1247 #define MP4_NSECS_TIME_SCALE	MP4_NANOSECONDS_TIME_SCALE
1248 
1249 u_int64_t MP4ConvertFromMovieDuration(
1250 	MP4FileHandle hFile,
1251 	MP4Duration duration,
1252 	u_int32_t timeScale);
1253 
1254 u_int64_t MP4ConvertFromTrackTimestamp(
1255 	MP4FileHandle hFile,
1256 	MP4TrackId trackId,
1257 	MP4Timestamp timeStamp,
1258 	u_int32_t timeScale);
1259 
1260 MP4Timestamp MP4ConvertToTrackTimestamp(
1261 	MP4FileHandle hFile,
1262 	MP4TrackId trackId,
1263 	u_int64_t timeStamp,
1264 	u_int32_t timeScale);
1265 
1266 u_int64_t MP4ConvertFromTrackDuration(
1267 	MP4FileHandle hFile,
1268 	MP4TrackId trackId,
1269 	MP4Duration duration,
1270 	u_int32_t timeScale);
1271 
1272 MP4Duration MP4ConvertToTrackDuration(
1273 	MP4FileHandle hFile,
1274 	MP4TrackId trackId,
1275 	u_int64_t duration,
1276 	u_int32_t timeScale);
1277 
1278 char* MP4BinaryToBase16(
1279 	const u_int8_t* pData,
1280 	u_int32_t dataSize);
1281 
1282 char* MP4BinaryToBase64(
1283 	const u_int8_t* pData,
1284 	u_int32_t dataSize);
1285 
1286 uint8_t *Base64ToBinary(const char *pData,
1287 			uint32_t decodeSize,
1288 			uint32_t *pDataSize);
1289 void MP4Free(void *p);
1290 
1291   void MP4SetLibFunc(lib_message_func_t libfunc);
1292 
1293 #ifdef __cplusplus
1294 }
1295 #endif
1296 
1297 /* undefined our utlity macro to avoid conflicts */
1298 #undef DEFAULT
1299 
1300 #endif /* __MP4_INCLUDED__ */
1301