task,
141 | final T... args) {
142 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
143 | throw new UnsupportedOperationException(
144 | "This class can only be used on API 4 and newer.");
145 | }
146 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || forceSerial) {
147 | task.execute(args);
148 | } else {
149 | task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
150 | }
151 | }
152 |
153 | /**
154 | * Used to determine if there is an active data connection and what type of
155 | * connection it is if there is one
156 | *
157 | * @param context The {@link android.content.Context} to use
158 | * @return True if there is an active data connection, false otherwise.
159 | * Also, if the user has checked to only download via Wi-Fi in the
160 | * settings, the mobile data and other network connections aren't
161 | * returned at all
162 | */
163 | public static final boolean isOnline(final Context context) {
164 | /*
165 | * This sort of handles a sudden configuration change, but I think it
166 | * should be dealt with in a more professional way.
167 | */
168 | if (context == null) {
169 | return false;
170 | }
171 |
172 | boolean state = false;
173 | final boolean onlyOnWifi = true;//PreferenceUtils.getInstance(context).onlyOnWifi();
174 |
175 | /* Monitor network connections */
176 | final ConnectivityManager connectivityManager = (ConnectivityManager)context
177 | .getSystemService(Context.CONNECTIVITY_SERVICE);
178 |
179 | /* Wi-Fi connection */
180 | final NetworkInfo wifiNetwork = connectivityManager
181 | .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
182 | if (wifiNetwork != null) {
183 | state = wifiNetwork.isConnectedOrConnecting();
184 | }
185 |
186 | /* Mobile data connection */
187 | final NetworkInfo mbobileNetwork = connectivityManager
188 | .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
189 | if (mbobileNetwork != null) {
190 | if (!onlyOnWifi) {
191 | state = mbobileNetwork.isConnectedOrConnecting();
192 | }
193 | }
194 |
195 | /* Other networks */
196 | final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
197 | if (activeNetwork != null) {
198 | if (!onlyOnWifi) {
199 | state = activeNetwork.isConnectedOrConnecting();
200 | }
201 | }
202 |
203 | return state;
204 | }
205 |
206 | /**
207 | * Display a {@link android.widget.Toast} letting the user know what an item does when long
208 | * pressed.
209 | *
210 | * @param view The {@link android.view.View} to copy the content description from.
211 | */
212 | public static void showCheatSheet(final View view) {
213 |
214 | final int[] screenPos = new int[2]; // origin is device display
215 | final Rect displayFrame = new Rect(); // includes decorations (e.g.
216 | // status bar)
217 | view.getLocationOnScreen(screenPos);
218 | view.getWindowVisibleDisplayFrame(displayFrame);
219 |
220 | final Context context = view.getContext();
221 | final int viewWidth = view.getWidth();
222 | final int viewHeight = view.getHeight();
223 | final int viewCenterX = screenPos[0] + viewWidth / 2;
224 | final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
225 | final int estimatedToastHeight = (int)(48 * context.getResources().getDisplayMetrics().density);
226 |
227 | final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(),
228 | Toast.LENGTH_SHORT);
229 | final boolean showBelow = screenPos[1] < estimatedToastHeight;
230 | if (showBelow) {
231 | // Show below
232 | // Offsets are after decorations (e.g. status bar) are factored in
233 | cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX
234 | - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight);
235 | } else {
236 | // Show above
237 | // Offsets are after decorations (e.g. status bar) are factored in
238 | cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX
239 | - screenWidth / 2, displayFrame.bottom - screenPos[1]);
240 | }
241 | cheatSheet.show();
242 | }
243 |
244 | /**
245 | * Calculate whether a color is light or dark, based on a commonly known
246 | * brightness formula.
247 | *
248 | * @see {@literal http://en.wikipedia.org/wiki/HSV_color_space%23Lightness}
249 | */
250 | public static final boolean isColorDark(final int color) {
251 | return (30 * Color.red(color) + 59 * Color.green(color) + 11 * Color.blue(color)) / 100 <= BRIGHTNESS_THRESHOLD;
252 | }
253 |
254 | /**
255 | * Runs a piece of code after the next layout run
256 | *
257 | * @param view The {@link android.view.View} used.
258 | * @param runnable The {@link Runnable} used after the next layout run
259 | */
260 | @SuppressLint("NewApi")
261 | public static void doAfterLayout(final View view, final Runnable runnable) {
262 | final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
263 | @SuppressWarnings("deprecation")
264 | @Override
265 | public void onGlobalLayout() {
266 | /* Layout pass done, unregister for further events */
267 | if (hasJellyBean()) {
268 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
269 | } else {
270 | view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
271 | }
272 | runnable.run();
273 | }
274 | };
275 | view.getViewTreeObserver().addOnGlobalLayoutListener(listener);
276 | }
277 |
278 | /**
279 | * Method that removes the support for HardwareAcceleration from a {@link android.view.View}.
280 | *
281 | * Check AOSP notice:
282 | *
283 | * 'ComposeShader can only contain shaders of different types (a BitmapShader and a
284 | * LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your
285 | * application is affected by any of these missing features or limitations, you can turn
286 | * off hardware acceleration for just the affected portion of your application by calling
287 | * setLayerType(View.LAYER_TYPE_SOFTWARE, null).'
288 | *
289 | * @param v The view
290 | */
291 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
292 | public static void removeHardwareAccelerationSupport(View v) {
293 | if (v.getLayerType() != View.LAYER_TYPE_SOFTWARE) {
294 | v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
295 | }
296 | }
297 |
298 | /**
299 | * Used to know if Apollo was sent into the background
300 | *
301 | * @param context The {@link android.content.Context} to use
302 | */
303 | public static final boolean isApplicationSentToBackground(final Context context) {
304 | final ActivityManager activityManager = (ActivityManager)context
305 | .getSystemService(Context.ACTIVITY_SERVICE);
306 | final List tasks = activityManager.getRunningTasks(1);
307 | System.out.println("tasks:"+tasks);
308 | if (!tasks.isEmpty()) {
309 | //listTask(tasks);
310 | final ComponentName topActivity = tasks.get(0).topActivity;
311 | if (!topActivity.getPackageName().equals(context.getPackageName())) {
312 | return true;
313 | }
314 | }
315 | return false;
316 | }
317 |
318 | private static void listTask(List tasks) {
319 | for (ActivityManager.RunningTaskInfo taskInfo:tasks){
320 | System.out.println("task:"+taskInfo.topActivity.getPackageName()+" task:"+taskInfo);
321 | }
322 | }
323 | }
324 |
--------------------------------------------------------------------------------
/app/libs/include/mp4v2/track.h:
--------------------------------------------------------------------------------
1 | #ifndef MP4V2_TRACK_H
2 | #define MP4V2_TRACK_H
3 |
4 | /**************************************************************************//**
5 | *
6 | * @defgroup mp4_track MP4v2 Track
7 | * @{
8 | *
9 | *****************************************************************************/
10 |
11 | /** Add a user defined track.
12 | *
13 | * MP4AddTrack adds a user defined track to the mp4 file. Care should be
14 | * taken to avoid any of the standardized track type names. A useful
15 | * convention is use only uppercase characters for user defined track types.
16 | * The string should be exactly four characters in length, e.g. "MINE".
17 | *
18 | * Note this should not be used to add any of the known track types defined
19 | * in the MP4 standard (ISO/IEC 14496-1:2001).
20 | *
21 | * @param hFile handle of file for operation.
22 | * @param type specifies the type of track to be added.
23 | * @param timeScale the time scale in ticks per second of the track. Default is 1000.
24 | *
25 | * @return On success, the track-id of new track.
26 | * On failure, #MP4_INVALID_TRACK_ID.
27 | */
28 | MP4V2_EXPORT
29 | MP4TrackId MP4AddTrack(
30 | MP4FileHandle hFile,
31 | const char* type,
32 | uint32_t timeScale DEFAULT(MP4_MSECS_TIME_SCALE) );
33 |
34 | /** Add an MPEG-4 systems track.
35 | *
36 | * MP4AddSystemsTrack adds an MPEG-4 Systems track to the mp4 file. Note
37 | * this should not be used to add OD or scene tracks, MP4AddODTrack() and
38 | * MP4AddSceneTrack() should be used for those purposes. Other known
39 | * MPEG-4 System track types are:
40 | * @li #MP4_CLOCK_TRACK_TYPE
41 | * @li #MP4_MPEG7_TRACK_TYPE
42 | * @li #MP4_OCI_TRACK_TYPE
43 | * @li #MP4_IPMP_TRACK_TYPE
44 | * @li #MP4_MPEGJ_TRACK_TYPE
45 | *
46 | * @param hFile handle of file for operation.
47 | * @param type specifies the type of track to be added.
48 | *
49 | * @return On success, the track-id of new track.
50 | * On failure, #MP4_INVALID_TRACK_ID.
51 | */
52 | MP4V2_EXPORT
53 | MP4TrackId MP4AddSystemsTrack(
54 | MP4FileHandle hFile,
55 | const char* type );
56 |
57 | /** Add a object descriptor (OD) track.
58 | *
59 | * MP4AddODTrack adds an object descriptor (aka OD) track to the mp4 file.
60 | * MP4WriteSample() can then be used to add the desired OD commands to the
61 | * track. The burden is currently on the calling application to understand
62 | * OD.
63 | *
64 | * Those wishing to have a simple audio/video scene without understanding
65 | * OD may wish to use MP4MakeIsmaCompliant() to create the minimal OD and
66 | * BIFS information.
67 | *
68 | * @param hFile handle of file for operation.
69 | *
70 | * @return On success, the track-id of new track.
71 | * On failure, #MP4_INVALID_TRACK_ID.
72 | */
73 | MP4V2_EXPORT
74 | MP4TrackId MP4AddODTrack(
75 | MP4FileHandle hFile );
76 |
77 | /** Add a scene (BIFS) track.
78 | *
79 | * MP4AddSceneTrack adds a scene (aka BIFS) track to the mp4 file.
80 | * MP4WriteSample() can then be used to add the desired BIFS commands to
81 | * the track. The burden is currently on the calling application to
82 | * understand BIFS.
83 | *
84 | * Those wishing to have a simple audio/video scene without understanding
85 | * BIFS may wish to use MP4MakeIsmaCompliant() to create the minimal OD
86 | * and BIFS information.
87 | *
88 | * @param hFile handle of file for operation.
89 | *
90 | * @return On success, the track-id of new track.
91 | * On failure, #MP4_INVALID_TRACK_ID.
92 | */
93 | MP4V2_EXPORT
94 | MP4TrackId MP4AddSceneTrack(
95 | MP4FileHandle hFile );
96 |
97 | /** Add audio track to mp4 file.
98 | *
99 | * MP4AddAudioTrack adds an audio track to the mp4 file. MP4WriteSample()
100 | * can then be used to add the desired audio samples.
101 | *
102 | * It is recommended that the time scale be set to the sampling frequency
103 | * (eg. 44100 Hz) of the audio so as to preserve the timing information
104 | * accurately.
105 | *
106 | * If the audio encoding uses a fixed duration for each sample that should
107 | * be specified here. If not then the value #MP4_INVALID_DURATION
108 | * should be given for the sampleDuration argument.
109 | *
110 | * @param hFile handle of file for operation.
111 | * @param timeScale the time scale in ticks per second of the track.
112 | * @param sampleDuration the fixed duration for all track samples.
113 | * Caveat: the value should be in track-timescale units.
114 | * @param audioType the audio encoding type.
115 | * See MP4GetTrackEsdsObjectTypeId() for known values.
116 | *
117 | * @return On success, the track-id of the new track.
118 | * On error, #MP4_INVALID_TRACK_ID.
119 | */
120 | MP4V2_EXPORT
121 | MP4TrackId MP4AddAudioTrack(
122 | MP4FileHandle hFile,
123 | uint32_t timeScale,
124 | MP4Duration sampleDuration,
125 | uint8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE) );
126 |
127 | /** Add ulaw track to mp4 file.
128 | *
129 | * MP4AddULawAudioTrack adds a ulaw track to the mp4 file. MP4WriteSample()
130 | * can then be used to add the desired audio samples.
131 | *
132 | * @param hFile handle of file for operation.
133 | * @param timeScale the time scale in ticks per second of the track.
134 | *
135 | * @return On success, the track-id of the new track.
136 | * On error, #MP4_INVALID_TRACK_ID.
137 | */
138 | MP4V2_EXPORT
139 | MP4TrackId MP4AddULawAudioTrack(
140 | MP4FileHandle hFile,
141 | uint32_t timeScale);
142 |
143 | /** Add alaw track to mp4 file.
144 | *
145 | * MP4AddALawAudioTrack adds a alaw track to the mp4 file. MP4WriteSample()
146 | * can then be used to add the desired audio samples.
147 | *
148 | * @param hFile handle of file for operation.
149 | * @param timeScale the time scale in ticks per second of the track.
150 | *
151 | * @return On success, the track-id of the new track.
152 | * On error, #MP4_INVALID_TRACK_ID.
153 | */
154 | MP4V2_EXPORT
155 | MP4TrackId MP4AddALawAudioTrack(
156 | MP4FileHandle hFile,
157 | uint32_t timeScale);
158 |
159 | MP4V2_EXPORT
160 | MP4TrackId MP4AddAC3AudioTrack(
161 | MP4FileHandle hFile,
162 | uint32_t samplingRate,
163 | uint8_t fscod,
164 | uint8_t bsid,
165 | uint8_t bsmod,
166 | uint8_t acmod,
167 | uint8_t lfeon,
168 | uint8_t bit_rate_code );
169 |
170 | MP4V2_EXPORT
171 | MP4TrackId MP4AddAmrAudioTrack(
172 | MP4FileHandle hFile,
173 | uint32_t timeScale,
174 | uint16_t modeSet,
175 | uint8_t modeChangePeriod,
176 | uint8_t framesPerSample,
177 | bool isAmrWB );
178 |
179 | MP4V2_EXPORT
180 | void MP4SetAmrVendor(
181 | MP4FileHandle hFile,
182 | MP4TrackId trackId,
183 | uint32_t vendor );
184 |
185 | MP4V2_EXPORT
186 | void MP4SetAmrDecoderVersion(
187 | MP4FileHandle hFile,
188 | MP4TrackId trackId,
189 | uint8_t decoderVersion );
190 |
191 | MP4V2_EXPORT
192 | void MP4SetAmrModeSet(
193 | MP4FileHandle hFile,
194 | MP4TrackId trakId,
195 | uint16_t modeSet );
196 |
197 | MP4V2_EXPORT
198 | uint16_t MP4GetAmrModeSet(
199 | MP4FileHandle hFile,
200 | MP4TrackId trackId );
201 |
202 | MP4V2_EXPORT
203 | MP4TrackId MP4AddHrefTrack(
204 | MP4FileHandle hFile,
205 | uint32_t timeScale,
206 | MP4Duration sampleDuration,
207 | const char* base_url DEFAULT(NULL) );
208 |
209 | MP4V2_EXPORT
210 | const char* MP4GetHrefTrackBaseUrl(
211 | MP4FileHandle hFile,
212 | MP4TrackId trackId );
213 |
214 | /** Add a video track.
215 | *
216 | * MP4AddVideoTrack adds a video track to the mp4 file. MP4WriteSample()
217 | * can then be used to add the desired video samples.
218 | *
219 | * It is recommended that the time scale be set to 90000 so as to preserve
220 | * the timing information accurately for the range of video frame rates
221 | * commonly in use.
222 | *
223 | * If the video frame rate is to be fixed then the sampleDuration argument
224 | * should be give the appropriate fixed value. If the video frame rate is
225 | * to be variable then the value #MP4_INVALID_DURATION should be
226 | * given for the sampleDuration argument.
227 | *
228 | * @param hFile handle of file for operation.
229 | * @param timeScale the timescale in ticks per second of the track.
230 | * @param sampleDuration specifies fixed sample duration for all track
231 | * samples. Caveat: the value should be in track timescale units.
232 | * @param width specifies the video frame width in pixels.
233 | * @param height specifies the video frame height in pixels.
234 | * @param videoType specifies the video encoding type.
235 | * See MP4GetTrackVideoType() for known values.
236 | *
237 | * @return On success, the track-id of the new track.
238 | * On error, #MP4_INVALID_TRACK_ID.
239 | */
240 | MP4V2_EXPORT
241 | MP4TrackId MP4AddVideoTrack(
242 | MP4FileHandle hFile,
243 | uint32_t timeScale,
244 | MP4Duration sampleDuration,
245 | uint16_t width,
246 | uint16_t height,
247 | uint8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE) );
248 |
249 | MP4V2_EXPORT
250 | MP4TrackId MP4AddH264VideoTrack(
251 | MP4FileHandle hFile,
252 | uint32_t timeScale,
253 | MP4Duration sampleDuration,
254 | uint16_t width,
255 | uint16_t height,
256 | uint8_t AVCProfileIndication,
257 | uint8_t profile_compat,
258 | uint8_t AVCLevelIndication,
259 | uint8_t sampleLenFieldSizeMinusOne );
260 |
261 | MP4V2_EXPORT
262 | void MP4AddH264SequenceParameterSet(
263 | MP4FileHandle hFile,
264 | MP4TrackId trackId,
265 | const uint8_t* pSequence,
266 | uint16_t sequenceLen );
267 |
268 | MP4V2_EXPORT
269 | void MP4AddH264PictureParameterSet(
270 | MP4FileHandle hFile,
271 | MP4TrackId trackId,
272 | const uint8_t* pPict,
273 | uint16_t pictLen );
274 |
275 | MP4V2_EXPORT
276 | void MP4SetH263Vendor(
277 | MP4FileHandle hFile,
278 | MP4TrackId trackId,
279 | uint32_t vendor );
280 |
281 | MP4V2_EXPORT
282 | void MP4SetH263DecoderVersion(
283 | MP4FileHandle hFile,
284 | MP4TrackId trackId,
285 | uint8_t decoderVersion );
286 |
287 | MP4V2_EXPORT
288 | void MP4SetH263Bitrates(
289 | MP4FileHandle hFile,
290 | MP4TrackId trackId,
291 | uint32_t avgBitrate,
292 | uint32_t maxBitrate );
293 |
294 | MP4V2_EXPORT
295 | MP4TrackId MP4AddH263VideoTrack(
296 | MP4FileHandle hFile,
297 | uint32_t timeScale,
298 | MP4Duration sampleDuration,
299 | uint16_t width,
300 | uint16_t height,
301 | uint8_t h263Level,
302 | uint8_t h263Profile,
303 | uint32_t avgBitrate,
304 | uint32_t maxBitrate );
305 |
306 | /** Add a hint track.
307 | *
308 | * MP4AddHintTrack adds a hint track to the mp4 file. A hint track is used
309 | * to describe how to send the reference media track over a particular
310 | * network transport. In the case of the IETF RTP protocol, the hint track
311 | * describes how the media data should be placed into packets and any
312 | * media specific protocol headers that should be added.
313 | *
314 | * Typically there is a one to one correspondence between reference media
315 | * track samples and hint track samples. The start time, duration, and
316 | * sync flags are typically the same, however provisions are made for
317 | * deviations from this rule.
318 | *
319 | * The MP4 library provides extensive support for RTP hint tracks. This
320 | * includes a easy to use API to create RTP hint tracks, and read out
321 | * fully constructed RTP packets based on the hint track.
322 | *
323 | * @param hFile handle of file for operation.
324 | * @param refTrackId specifies the reference media track for this hint track.
325 | *
326 | * @return On success, the track-id of the new track.
327 | * On error, #MP4_INVALID_TRACK_ID.
328 | */
329 | MP4V2_EXPORT
330 | MP4TrackId MP4AddHintTrack(
331 | MP4FileHandle hFile,
332 | MP4TrackId refTrackId );
333 |
334 | MP4V2_EXPORT
335 | MP4TrackId MP4AddTextTrack(
336 | MP4FileHandle hFile,
337 | MP4TrackId refTrackId );
338 |
339 | MP4V2_EXPORT
340 | MP4TrackId MP4AddSubtitleTrack(
341 | MP4FileHandle hFile,
342 | uint32_t timescale,
343 | uint16_t width,
344 | uint16_t height );
345 |
346 | MP4V2_EXPORT
347 | MP4TrackId MP4AddSubpicTrack(
348 | MP4FileHandle hFile,
349 | uint32_t timescale,
350 | uint16_t width,
351 | uint16_t height );
352 |
353 | MP4V2_EXPORT
354 | MP4TrackId MP4AddPixelAspectRatio(
355 | MP4FileHandle hFile,
356 | MP4TrackId refTrackId,
357 | uint32_t hSpacing,
358 | uint32_t vSpacing );
359 |
360 | MP4V2_EXPORT
361 | MP4TrackId MP4AddColr(
362 | MP4FileHandle hFile,
363 | MP4TrackId refTrackId,
364 | uint16_t primary,
365 | uint16_t transfer,
366 | uint16_t matrix );
367 |
368 | MP4V2_EXPORT
369 | MP4TrackId MP4CloneTrack(
370 | MP4FileHandle srcFile,
371 | MP4TrackId srcTrackId,
372 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
373 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) );
374 |
375 | MP4V2_EXPORT
376 | MP4TrackId MP4CopyTrack(
377 | MP4FileHandle srcFile,
378 | MP4TrackId srcTrackId,
379 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
380 | bool applyEdits DEFAULT(false),
381 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) );
382 |
383 | MP4V2_EXPORT
384 | bool MP4DeleteTrack(
385 | MP4FileHandle hFile,
386 | MP4TrackId trackId );
387 |
388 | MP4V2_EXPORT
389 | uint32_t MP4GetNumberOfTracks(
390 | MP4FileHandle hFile,
391 | const char* type DEFAULT(NULL),
392 | uint8_t subType DEFAULT(0) );
393 |
394 | MP4V2_EXPORT
395 | MP4TrackId MP4FindTrackId(
396 | MP4FileHandle hFile,
397 | uint16_t index,
398 | const char* type DEFAULT(NULL),
399 | uint8_t subType DEFAULT(0) );
400 |
401 | MP4V2_EXPORT
402 | uint16_t MP4FindTrackIndex(
403 | MP4FileHandle hFile,
404 | MP4TrackId trackId );
405 |
406 | /** Get maximum duration of chunk.
407 | *
408 | * MP4GetTrackDurationPerChunk gets the maximum duration for each chunk.
409 | *
410 | * @param hFile handle of file for operation.
411 | * @param trackId id of track for operation.
412 | * @param duration out value of duration in track timescale units.
413 | *
414 | * return true on success, false on failure.
415 | */
416 | MP4V2_EXPORT
417 | bool MP4GetTrackDurationPerChunk(
418 | MP4FileHandle hFile,
419 | MP4TrackId trackId,
420 | MP4Duration* duration );
421 |
422 | /** Set maximum duration of chunk.
423 | *
424 | * MP4SetTrackDurationPerChunk sets the maximum duration for each chunk.
425 | *
426 | * @param hFile handle of file for operation.
427 | * @param trackId id of track for operation.
428 | * @param duration in timescale units.
429 | *
430 | * @return true on success, false on failure.
431 | */
432 | MP4V2_EXPORT
433 | bool MP4SetTrackDurationPerChunk(
434 | MP4FileHandle hFile,
435 | MP4TrackId trackId,
436 | MP4Duration duration );
437 |
438 | /**
439 | * @param hFile handle of file for operation.
440 | * @param trackId id of track for operation.
441 | *
442 | * @return true on success, false on failure.
443 | */
444 | MP4V2_EXPORT
445 | bool MP4AddIPodUUID(
446 | MP4FileHandle hFile,
447 | MP4TrackId trackId );
448 |
449 | /** @} ***********************************************************************/
450 |
451 | #endif /* MP4V2_TRACK_H */
452 |
--------------------------------------------------------------------------------
/app/libs/include/mp4v2/file.h:
--------------------------------------------------------------------------------
1 | #ifndef MP4V2_FILE_H
2 | #define MP4V2_FILE_H
3 |
4 | /**************************************************************************//**
5 | *
6 | * @defgroup mp4_file MP4v2 File I/O
7 | * @{
8 | *
9 | *****************************************************************************/
10 |
11 | /** Bit: enable 64-bit data-atoms. */
12 | #define MP4_CREATE_64BIT_DATA 0x01
13 | /** Bit: enable 64-bit time-atoms. @note Incompatible with QuickTime. */
14 | #define MP4_CREATE_64BIT_TIME 0x02
15 | /** Bit: do not recompute avg/max bitrates on file close. @note See http://code.google.com/p/mp4v2/issues/detail?id=66 */
16 | #define MP4_CLOSE_DO_NOT_COMPUTE_BITRATE 0x01
17 |
18 | /** Enumeration of file modes for custom file provider. */
19 | typedef enum MP4FileMode_e
20 | {
21 | FILEMODE_UNDEFINED, /**< undefined */
22 | FILEMODE_READ, /**< file may be read */
23 | FILEMODE_MODIFY, /**< file may be read/written */
24 | FILEMODE_CREATE /**< file will be created/truncated for read/write */
25 | } MP4FileMode;
26 |
27 | /** Structure of functions implementing custom file provider.
28 | *
29 | * Except for open, all the functions must return a true value
30 | * to indicate failure or false on success. The open function must return
31 | * a pointer or handle which represents the open file, otherwise NULL.
32 | *
33 | * maxChunkSize is a hint suggesting what the max size of data should be read
34 | * as in underlying read/write operations. A value of 0 indicates there is no hint.
35 | */
36 | typedef struct MP4FileProvider_s
37 | {
38 | void* ( *open )( const char* name, MP4FileMode mode );
39 | int ( *seek )( void* handle, int64_t pos );
40 | int ( *read )( void* handle, void* buffer, int64_t size, int64_t* nin, int64_t maxChunkSize );
41 | int ( *write )( void* handle, const void* buffer, int64_t size, int64_t* nout, int64_t maxChunkSize );
42 | int ( *close )( void* handle );
43 | } MP4FileProvider;
44 |
45 | /** Close an mp4 file.
46 | * MP4Close closes a previously opened mp4 file. If the file was opened
47 | * writable with MP4Create() or MP4Modify(), then MP4Close() will write
48 | * out all pending information to disk.
49 | *
50 | * @param hFile handle of file to close.
51 | * @param flags bitmask that allows the user to set extra options for the
52 | * close commands. Valid options include:
53 | * @li #MP4_CLOSE_DO_NOT_COMPUTE_BITRATE
54 | */
55 | MP4V2_EXPORT
56 | void MP4Close(
57 | MP4FileHandle hFile,
58 | uint32_t flags DEFAULT(0) );
59 |
60 | /** Create a new mp4 file.
61 | *
62 | * MP4Create is the first call that should be used when you want to create
63 | * a new, empty mp4 file. It is equivalent to opening a file for writing,
64 | * but also involved with creation of necessary mp4 framework structures.
65 | * ie. invoking MP4Create() followed by MP4Close() will result in a file
66 | * with a non-zero size.
67 | *
68 | * @param fileName pathname of the file to be created.
69 | * On Windows, this should be a UTF-8 encoded string.
70 | * On other platforms, it should be an 8-bit encoding that is
71 | * appropriate for the platform, locale, file system, etc.
72 | * (prefer to use UTF-8 when possible).
73 | * @param flags bitmask that allows the user to set 64-bit values for
74 | * data or time atoms. Valid bits may be any combination of:
75 | * @li #MP4_CREATE_64BIT_DATA
76 | * @li #MP4_CREATE_64BIT_TIME
77 | *
78 | * @return On success a handle of the newly created file for use in
79 | * subsequent calls to the library.
80 | * On error, #MP4_INVALID_FILE_HANDLE.
81 | */
82 | MP4V2_EXPORT
83 | MP4FileHandle MP4Create(
84 | const char* fileName,
85 | uint32_t flags DEFAULT(0) );
86 |
87 | /** Create a new mp4 file with extended options.
88 | *
89 | * MP4CreateEx is an extended version of MP4Create().
90 | *
91 | * @param fileName pathname of the file to be created.
92 | * On Windows, this should be a UTF-8 encoded string.
93 | * On other platforms, it should be an 8-bit encoding that is
94 | * appropriate for the platform, locale, file system, etc.
95 | * (prefer to use UTF-8 when possible).
96 | * @param flags bitmask that allows the user to set 64-bit values for
97 | * data or time atoms. Valid bits may be any combination of:
98 | * @li #MP4_CREATE_64BIT_DATA
99 | * @li #MP4_CREATE_64BIT_TIME
100 | * @param add_ftyp if true an ftyp atom is automatically created.
101 | * @param add_iods if true an iods atom is automatically created.
102 | * @param majorBrand ftyp brand identifier.
103 | * @param minorVersion ftyp informative integer for the minor version
104 | * of the major brand.
105 | * @param compatibleBrands ftyp list of compatible brands.
106 | * @param compatibleBrandsCount is the count of items specified in
107 | * compatibleBrands.
108 | *
109 | * @return On success a handle of the newly created file for use in
110 | * subsequent calls to the library.
111 | * On error, #MP4_INVALID_FILE_HANDLE.
112 | */
113 | MP4V2_EXPORT
114 | MP4FileHandle MP4CreateEx(
115 | const char* fileName,
116 | uint32_t flags DEFAULT(0),
117 | int add_ftyp DEFAULT(1),
118 | int add_iods DEFAULT(1),
119 | char* majorBrand DEFAULT(0),
120 | uint32_t minorVersion DEFAULT(0),
121 | char** compatibleBrands DEFAULT(0),
122 | uint32_t compatibleBrandsCount DEFAULT(0) );
123 |
124 | /** Dump mp4 file contents as ASCII either to stdout or the
125 | * log callback (@p see MP4SetLogCallback)
126 | *
127 | * Dump is an invaluable debugging tool in that in can reveal all the details
128 | * of the mp4 control structures. However, the output will not make much sense
129 | * until you familiarize yourself with the mp4 specification (or the Quicktime
130 | * File Format specification).
131 | *
132 |
133 | * Note that MP4Dump() will not print the individual values of control tables,
134 | * such as the size of each sample, unless the current log level is at least
135 | * #MP4_LOG_VERBOSE2. @p see MP4LogSetLevel() for how to set this.
136 | *
137 | * @param hFile handle of file to dump.
138 | * @param dumpImplicits prints properties which would not actually be
139 | * written to the mp4 file, but still exist in mp4 control structures.
140 | * ie. they are implicit given the current values of other controlling
141 | * properties.
142 | *
143 | * @return true on success, false on failure.
144 | */
145 | MP4V2_EXPORT
146 | bool MP4Dump(
147 | MP4FileHandle hFile,
148 | bool dumpImplicits DEFAULT(0) );
149 |
150 | /** Return a textual summary of an mp4 file.
151 | *
152 | * MP4FileInfo provides a string that contains a textual summary of the
153 | * contents of an mp4 file. This includes the track id's, the track type,
154 | * and track specific information. For example, for a video track, media
155 | * encoding, image size, frame rate, and bitrate are summarized.
156 | *
157 | * Note that the returned string is malloc'ed, so it is the caller's
158 | * responsibility to free() the string. Also note that the returned string
159 | * contains newlines and tabs which may or may not be desirable.
160 | *
161 | * The following is an example of the output of MP4Info():
162 | @verbatim
163 | Track Type Info
164 | 1 video MPEG-4 Simple @ L3, 119.625 secs, 1008 kbps, 352x288 @ 24.00 fps
165 | 2 audio MPEG-4, 119.327 secs, 128 kbps, 44100 Hz
166 | 3 hint Payload MP4V-ES for track 1
167 | 4 hint Payload mpeg4-generic for track 2
168 | 5 od Object Descriptors
169 | 6 scene BIFS
170 | @endverbatim
171 | *
172 | * @param fileName pathname to mp4 file to summarize.
173 | * On Windows, this should be a UTF-8 encoded string.
174 | * On other platforms, it should be an 8-bit encoding that is
175 | * appropriate for the platform, locale, file system, etc.
176 | * (prefer to use UTF-8 when possible).
177 | * @param trackId specifies track to summarize. If the value is
178 | * #MP4_INVALID_TRACK_ID, the summary info is created for all
179 | * tracks in the file.
180 | *
181 | * @return On success a malloc'd string containing summary information.
182 | * On failure, NULL.
183 | *
184 | * @see MP4Info().
185 | */
186 | MP4V2_EXPORT
187 | char* MP4FileInfo(
188 | const char* fileName,
189 | MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID) );
190 |
191 | /** Accessor for the filename associated with a file handle
192 | *
193 | * @param hFile a file handle
194 | *
195 | * @return the NUL-terminated, UTF-8 encoded filename
196 | * associated with @p hFile
197 | */
198 | MP4V2_EXPORT
199 | const char* MP4GetFilename(
200 | MP4FileHandle hFile );
201 |
202 | /** Return a textual summary of an mp4 file.
203 | *
204 | * MP4FileInfo provides a string that contains a textual summary of the
205 | * contents of an mp4 file. This includes the track id's, the track type,
206 | * and track specific information. For example, for a video track, media
207 | * encoding, image size, frame rate, and bitrate are summarized.
208 | *
209 | * Note that the returned string is malloc'ed, so it is the caller's
210 | * responsibility to free() the string. Also note that the returned string
211 | * contains newlines and tabs which may or may not be desirable.
212 | *
213 | * The following is an example of the output of MP4Info():
214 | @verbatim
215 | Track Type Info
216 | 1 video MPEG-4 Simple @ L3, 119.625 secs, 1008 kbps, 352x288 @ 24.00 fps
217 | 2 audio MPEG-4, 119.327 secs, 128 kbps, 44100 Hz
218 | 3 hint Payload MP4V-ES for track 1
219 | 4 hint Payload mpeg4-generic for track 2
220 | 5 od Object Descriptors
221 | 6 scene BIFS
222 | @endverbatim
223 | *
224 | * @param hFile handle of file to summarize.
225 | * @param trackId specifies track to summarize. If the value is
226 | * #MP4_INVALID_TRACK_ID, the summary info is created for all
227 | * tracks in the file.
228 | *
229 | * @return On success a malloc'd string containing summary information.
230 | * On failure, NULL.
231 | *
232 | * @see MP4FileInfo().
233 | */
234 | MP4V2_EXPORT
235 | char* MP4Info(
236 | MP4FileHandle hFile,
237 | MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID) );
238 |
239 | /** Modify an existing mp4 file.
240 | *
241 | * MP4Modify is the first call that should be used when you want to modify
242 | * an existing mp4 file. It is roughly equivalent to opening a file in
243 | * read/write mode.
244 | *
245 | * Since modifications to an existing mp4 file can result in a sub-optimal
246 | * file layout, you may want to use MP4Optimize() after you have modified
247 | * and closed the mp4 file.
248 | *
249 | * @param fileName pathname of the file to be modified.
250 | * On Windows, this should be a UTF-8 encoded string.
251 | * On other platforms, it should be an 8-bit encoding that is
252 | * appropriate for the platform, locale, file system, etc.
253 | * (prefer to use UTF-8 when possible).
254 | * @param flags currently ignored.
255 | *
256 | * @return On success a handle of the target file for use in subsequent calls
257 | * to the library.
258 | * On error, #MP4_INVALID_FILE_HANDLE.
259 | */
260 | MP4V2_EXPORT
261 | MP4FileHandle MP4Modify(
262 | const char* fileName,
263 | uint32_t flags DEFAULT(0) );
264 |
265 | /** Optimize the layout of an mp4 file.
266 | *
267 | * MP4Optimize reads an existing mp4 file and writes a new version of the
268 | * file with the two important changes:
269 | *
270 | * First, the mp4 control information is moved to the beginning of the file.
271 | * (Frequenty it is at the end of the file due to it being constantly
272 | * modified as track samples are added to an mp4 file). This optimization
273 | * is useful in that in allows the mp4 file to be HTTP streamed.
274 | *
275 | * Second, the track samples are interleaved so that the samples for a
276 | * particular instant in time are colocated within the file. This
277 | * eliminates disk seeks during playback of the file which results in
278 | * better performance.
279 | *
280 | * There are also two important side effects of MP4Optimize():
281 | *
282 | * First, any free blocks within the mp4 file are eliminated.
283 | *
284 | * Second, as a side effect of the sample interleaving process any media
285 | * data chunks that are not actually referenced by the mp4 control
286 | * structures are deleted. This is useful if you have called MP4DeleteTrack()
287 | * which only deletes the control information for a track, and not the
288 | * actual media data.
289 | *
290 | * @param fileName pathname of (existing) file to be optimized.
291 | * On Windows, this should be a UTF-8 encoded string.
292 | * On other platforms, it should be an 8-bit encoding that is
293 | * appropriate for the platform, locale, file system, etc.
294 | * (prefer to use UTF-8 when possible).
295 | * @param newFileName pathname of the new optimized file.
296 | * On Windows, this should be a UTF-8 encoded string.
297 | * On other platforms, it should be an 8-bit encoding that is
298 | * appropriate for the platform, locale, file system, etc.
299 | * (prefer to use UTF-8 when possible).
300 | * If NULL a temporary file in the same directory as the
301 | * fileName will be used and fileName
302 | * will be over-written upon successful completion.
303 | *
304 | * @return true on success, false on failure.
305 | */
306 | MP4V2_EXPORT
307 | bool MP4Optimize(
308 | const char* fileName,
309 | const char* newFileName DEFAULT(NULL) );
310 |
311 |
312 | /** Read an existing mp4 file.
313 | *
314 | * MP4Read is the first call that should be used when you want to just
315 | * read an existing mp4 file. It is equivalent to opening a file for
316 | * reading, but in addition the mp4 file is parsed and the control
317 | * information is loaded into memory. Note that actual track samples are not
318 | * read into memory until MP4ReadSample() is called.
319 | *
320 | * @param fileName pathname of the file to be read.
321 | * On Windows, this should be a UTF-8 encoded string.
322 | * On other platforms, it should be an 8-bit encoding that is
323 | * appropriate for the platform, locale, file system, etc.
324 | * (prefer to use UTF-8 when possible).
325 | (
326 | * @return On success a handle of the file for use in subsequent calls to
327 | * the library.
328 | * On error, #MP4_INVALID_FILE_HANDLE.
329 | */
330 | MP4V2_EXPORT
331 | MP4FileHandle MP4Read(
332 | const char* fileName );
333 |
334 | /** Read an existing mp4 file.
335 | *
336 | * MP4ReadProvider is the first call that should be used when you want to just
337 | * read an existing mp4 file. It is equivalent to opening a file for
338 | * reading, but in addition the mp4 file is parsed and the control
339 | * information is loaded into memory. Note that actual track samples are not
340 | * read into memory until MP4ReadSample() is called.
341 | *
342 | * @param fileName pathname of the file to be read.
343 | * On Windows, this should be a UTF-8 encoded string.
344 | * On other platforms, it should be an 8-bit encoding that is
345 | * appropriate for the platform, locale, file system, etc.
346 | * (prefer to use UTF-8 when possible).
347 | * @param fileProvider custom implementation of file I/O operations.
348 | * All functions in structure must be implemented.
349 | * The structure is immediately copied internally.
350 | *
351 | * @return On success a handle of the file for use in subsequent calls to
352 | * the library.
353 | * On error, #MP4_INVALID_FILE_HANDLE.
354 | */
355 | MP4V2_EXPORT
356 | MP4FileHandle MP4ReadProvider(
357 | const char* fileName,
358 | const MP4FileProvider* fileProvider DEFAULT(NULL) );
359 |
360 | /** @} ***********************************************************************/
361 |
362 | #endif /* MP4V2_FILE_H */
363 |
--------------------------------------------------------------------------------
/app/libs/include/mp4v2/general.h:
--------------------------------------------------------------------------------
1 | #ifndef MP4V2_GENERAL_H
2 | #define MP4V2_GENERAL_H
3 |
4 | /**************************************************************************//**
5 | *
6 | * @defgroup mp4_general MP4v2 General
7 | * @{
8 | *
9 | *****************************************************************************/
10 |
11 | /* MP4 API types */
12 | typedef void* MP4FileHandle;
13 | typedef uint32_t MP4TrackId;
14 | typedef uint32_t MP4SampleId;
15 | typedef uint64_t MP4Timestamp;
16 | typedef uint64_t MP4Duration;
17 | typedef uint32_t MP4EditId;
18 |
19 | typedef enum {
20 | MP4_LOG_NONE = 0,
21 | MP4_LOG_ERROR = 1,
22 | MP4_LOG_WARNING = 2,
23 | MP4_LOG_INFO = 3,
24 | MP4_LOG_VERBOSE1 = 4,
25 | MP4_LOG_VERBOSE2 = 5,
26 | MP4_LOG_VERBOSE3 = 6,
27 | MP4_LOG_VERBOSE4 = 7
28 | } MP4LogLevel;
29 |
30 | /*****************************************************************************/
31 |
32 | typedef void (*MP4LogCallback)(
33 | MP4LogLevel loglevel,
34 | const char* fmt,
35 | va_list ap );
36 |
37 | /*****************************************************************************/
38 |
39 | /** Encryption function pointer.
40 | *
41 | * @see MP4EncAndCopySample().
42 | * @see MP4EncAndCopyTrack().
43 | */
44 | typedef uint32_t (*encryptFunc_t)( uint32_t, uint32_t, uint8_t*, uint32_t*, uint8_t** );
45 |
46 | /*****************************************************************************/
47 |
48 | #define MP4_INVALID_FILE_HANDLE ((MP4FileHandle)NULL) /**< Constant: invalid MP4FileHandle. */
49 | #define MP4_INVALID_TRACK_ID ((MP4TrackId)0) /**< Constant: invalid MP4TrackId. */
50 | #define MP4_INVALID_SAMPLE_ID ((MP4SampleId)0) /**< Constant: invalid MP4SampleId. */
51 | #define MP4_INVALID_TIMESTAMP ((MP4Timestamp)-1) /**< Constant: invalid MP4Timestamp. */
52 | #define MP4_INVALID_DURATION ((MP4Duration)-1) /**< Constant: invalid MP4Duration. */
53 | #define MP4_INVALID_EDIT_ID ((MP4EditId)0) /**< Constant: invalid MP4EditId. */
54 |
55 | /* Macros to test for API type validity */
56 | #define MP4_IS_VALID_FILE_HANDLE(x) ((x) != MP4_INVALID_FILE_HANDLE)
57 | #define MP4_IS_VALID_TRACK_ID(x) ((x) != MP4_INVALID_TRACK_ID)
58 | #define MP4_IS_VALID_SAMPLE_ID(x) ((x) != MP4_INVALID_SAMPLE_ID)
59 | #define MP4_IS_VALID_TIMESTAMP(x) ((x) != MP4_INVALID_TIMESTAMP)
60 | #define MP4_IS_VALID_DURATION(x) ((x) != MP4_INVALID_DURATION)
61 | #define MP4_IS_VALID_EDIT_ID(x) ((x) != MP4_INVALID_EDIT_ID)
62 |
63 | /*
64 | * MP4 Known track type names - e.g. MP4GetNumberOfTracks(type)
65 | *
66 | * Note this first group of track types should be created
67 | * via the MP4AddTrack() functions, and not MP4AddTrack(type)
68 | */
69 | #define MP4_OD_TRACK_TYPE "odsm" /**< Constant: OD track. */
70 | #define MP4_SCENE_TRACK_TYPE "sdsm" /**< Constant: scene track. */
71 | #define MP4_AUDIO_TRACK_TYPE "soun" /**< Constant: audio track. */
72 | #define MP4_VIDEO_TRACK_TYPE "vide" /**< Constant: video track. */
73 | #define MP4_HINT_TRACK_TYPE "hint" /**< Constant: hint track. */
74 | #define MP4_CNTL_TRACK_TYPE "cntl" /**< Constant: control track. */
75 | #define MP4_TEXT_TRACK_TYPE "text" /**< Constant: text track. */
76 | #define MP4_SUBTITLE_TRACK_TYPE "sbtl" /**< Constant: subtitle track. */
77 | #define MP4_SUBPIC_TRACK_TYPE "subp" /**< Constant: subpic track. */
78 | /*
79 | * This second set of track types should be created
80 | * via MP4AddSystemsTrack(type)
81 | */
82 | #define MP4_CLOCK_TRACK_TYPE "crsm" /**< Constant: clock track. */
83 | #define MP4_MPEG7_TRACK_TYPE "m7sm" /**< Constant: mpeg7 track. */
84 | #define MP4_OCI_TRACK_TYPE "ocsm" /**< Constant: OCI track. */
85 | #define MP4_IPMP_TRACK_TYPE "ipsm" /**< Constant: IPMP track. */
86 | #define MP4_MPEGJ_TRACK_TYPE "mjsm" /**< Constant: MPEGJ track. */
87 |
88 | #define MP4_IS_VIDEO_TRACK_TYPE(type) \
89 | (!strcasecmp(type, MP4_VIDEO_TRACK_TYPE))
90 |
91 | #define MP4_IS_AUDIO_TRACK_TYPE(type) \
92 | (!strcasecmp(type, MP4_AUDIO_TRACK_TYPE))
93 |
94 | #define MP4_IS_CNTL_TRACK_TYPE(type) \
95 | (!strcasecmp(type, MP4_CNTL_TRACK_TYPE))
96 |
97 | #define MP4_IS_OD_TRACK_TYPE(type) \
98 | (!strcasecmp(type, MP4_OD_TRACK_TYPE))
99 |
100 | #define MP4_IS_SCENE_TRACK_TYPE(type) \
101 | (!strcasecmp(type, MP4_SCENE_TRACK_TYPE))
102 |
103 | #define MP4_IS_HINT_TRACK_TYPE(type) \
104 | (!strcasecmp(type, MP4_HINT_TRACK_TYPE))
105 |
106 | #define MP4_IS_SYSTEMS_TRACK_TYPE(type) \
107 | (!strcasecmp(type, MP4_CLOCK_TRACK_TYPE) \
108 | || !strcasecmp(type, MP4_MPEG7_TRACK_TYPE) \
109 | || !strcasecmp(type, MP4_OCI_TRACK_TYPE) \
110 | || !strcasecmp(type, MP4_IPMP_TRACK_TYPE) \
111 | || !strcasecmp(type, MP4_MPEGJ_TRACK_TYPE))
112 |
113 | /* MP4 Audio track types - see MP4AddAudioTrack()*/
114 | #define MP4_INVALID_AUDIO_TYPE 0x00
115 | #define MP4_MPEG1_AUDIO_TYPE 0x6B
116 | #define MP4_MPEG2_AUDIO_TYPE 0x69
117 | #define MP4_MP3_AUDIO_TYPE MP4_MPEG2_AUDIO_TYPE
118 | #define MP4_MPEG2_AAC_MAIN_AUDIO_TYPE 0x66
119 | #define MP4_MPEG2_AAC_LC_AUDIO_TYPE 0x67
120 | #define MP4_MPEG2_AAC_SSR_AUDIO_TYPE 0x68
121 | #define MP4_MPEG2_AAC_AUDIO_TYPE MP4_MPEG2_AAC_MAIN_AUDIO_TYPE
122 | #define MP4_MPEG4_AUDIO_TYPE 0x40
123 | #define MP4_PRIVATE_AUDIO_TYPE 0xC0
124 | #define MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE 0xE0 /* a private definition */
125 | #define MP4_VORBIS_AUDIO_TYPE 0xE1 /* a private definition */
126 | #define MP4_AC3_AUDIO_TYPE 0xE2 /* a private definition */
127 | #define MP4_ALAW_AUDIO_TYPE 0xE3 /* a private definition */
128 | #define MP4_ULAW_AUDIO_TYPE 0xE4 /* a private definition */
129 | #define MP4_G723_AUDIO_TYPE 0xE5 /* a private definition */
130 | #define MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE 0xE6 /* a private definition */
131 |
132 | /* MP4 MPEG-4 Audio types from 14496-3 Table 1.5.1 */
133 | #define MP4_MPEG4_INVALID_AUDIO_TYPE 0
134 | #define MP4_MPEG4_AAC_MAIN_AUDIO_TYPE 1
135 | #define MP4_MPEG4_AAC_LC_AUDIO_TYPE 2
136 | #define MP4_MPEG4_AAC_SSR_AUDIO_TYPE 3
137 | #define MP4_MPEG4_AAC_LTP_AUDIO_TYPE 4
138 | #define MP4_MPEG4_AAC_HE_AUDIO_TYPE 5
139 | #define MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE 6
140 | #define MP4_MPEG4_CELP_AUDIO_TYPE 8
141 | #define MP4_MPEG4_HVXC_AUDIO_TYPE 9
142 | #define MP4_MPEG4_TTSI_AUDIO_TYPE 12
143 | #define MP4_MPEG4_MAIN_SYNTHETIC_AUDIO_TYPE 13
144 | #define MP4_MPEG4_WAVETABLE_AUDIO_TYPE 14
145 | #define MP4_MPEG4_MIDI_AUDIO_TYPE 15
146 | #define MP4_MPEG4_ALGORITHMIC_FX_AUDIO_TYPE 16
147 | #define MP4_MPEG4_ALS_AUDIO_TYPE 31
148 | #define MP4_MPEG4_LAYER1_AUDIO_TYPE 32
149 | #define MP4_MPEG4_LAYER2_AUDIO_TYPE 33
150 | #define MP4_MPEG4_LAYER3_AUDIO_TYPE 34
151 | #define MP4_MPEG4_SLS_AUDIO_TYPE 35
152 |
153 | /* MP4 Audio type utilities following common usage */
154 | #define MP4_IS_MP3_AUDIO_TYPE(type) \
155 | ((type) == MP4_MPEG1_AUDIO_TYPE || (type) == MP4_MPEG2_AUDIO_TYPE)
156 |
157 | #define MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
158 | (((type) >= MP4_MPEG2_AAC_MAIN_AUDIO_TYPE \
159 | && (type) <= MP4_MPEG2_AAC_SSR_AUDIO_TYPE))
160 |
161 | #define MP4_IS_MPEG4_AAC_AUDIO_TYPE(mpeg4Type) \
162 | (((mpeg4Type) >= MP4_MPEG4_AAC_MAIN_AUDIO_TYPE \
163 | && (mpeg4Type) <= MP4_MPEG4_AAC_HE_AUDIO_TYPE) \
164 | || (mpeg4Type) == MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE \
165 | || (mpeg4Type) == 17)
166 |
167 | #define MP4_IS_AAC_AUDIO_TYPE(type) \
168 | (MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
169 | || (type) == MP4_MPEG4_AUDIO_TYPE)
170 |
171 | /* MP4 Video track types - see MP4AddVideoTrack() */
172 | #define MP4_INVALID_VIDEO_TYPE 0x00
173 | #define MP4_MPEG1_VIDEO_TYPE 0x6A
174 | #define MP4_MPEG2_SIMPLE_VIDEO_TYPE 0x60
175 | #define MP4_MPEG2_MAIN_VIDEO_TYPE 0x61
176 | #define MP4_MPEG2_SNR_VIDEO_TYPE 0x62
177 | #define MP4_MPEG2_SPATIAL_VIDEO_TYPE 0x63
178 | #define MP4_MPEG2_HIGH_VIDEO_TYPE 0x64
179 | #define MP4_MPEG2_442_VIDEO_TYPE 0x65
180 | #define MP4_MPEG2_VIDEO_TYPE MP4_MPEG2_MAIN_VIDEO_TYPE
181 | #define MP4_MPEG4_VIDEO_TYPE 0x20
182 | #define MP4_JPEG_VIDEO_TYPE 0x6C
183 | #define MP4_PRIVATE_VIDEO_TYPE 0xD0
184 | #define MP4_YUV12_VIDEO_TYPE 0xF0 /* a private definition */
185 | #define MP4_H263_VIDEO_TYPE 0xF2 /* a private definition */
186 | #define MP4_H261_VIDEO_TYPE 0xF3 /* a private definition */
187 |
188 | /* MP4 Video type utilities */
189 | #define MP4_IS_MPEG1_VIDEO_TYPE(type) \
190 | ((type) == MP4_MPEG1_VIDEO_TYPE)
191 |
192 | #define MP4_IS_MPEG2_VIDEO_TYPE(type) \
193 | (((type) >= MP4_MPEG2_SIMPLE_VIDEO_TYPE \
194 | && (type) <= MP4_MPEG2_442_VIDEO_TYPE) \
195 | || MP4_IS_MPEG1_VIDEO_TYPE(type))
196 |
197 | #define MP4_IS_MPEG4_VIDEO_TYPE(type) \
198 | ((type) == MP4_MPEG4_VIDEO_TYPE)
199 |
200 | /* Mpeg4 Visual Profile Defines - ISO/IEC 14496-2:2001/Amd.2:2002(E) */
201 | #define MPEG4_SP_L1 (0x1)
202 | #define MPEG4_SP_L2 (0x2)
203 | #define MPEG4_SP_L3 (0x3)
204 | #define MPEG4_SP_L0 (0x8)
205 | #define MPEG4_SSP_L1 (0x11)
206 | #define MPEG4_SSP_L2 (0x12)
207 | #define MPEG4_CP_L1 (0x21)
208 | #define MPEG4_CP_L2 (0x22)
209 | #define MPEG4_MP_L2 (0x32)
210 | #define MPEG4_MP_L3 (0x33)
211 | #define MPEG4_MP_L4 (0x34)
212 | #define MPEG4_NBP_L2 (0x42)
213 | #define MPEG4_STP_L1 (0x51)
214 | #define MPEG4_SFAP_L1 (0x61)
215 | #define MPEG4_SFAP_L2 (0x62)
216 | #define MPEG4_SFBAP_L1 (0x63)
217 | #define MPEG4_SFBAP_L2 (0x64)
218 | #define MPEG4_BATP_L1 (0x71)
219 | #define MPEG4_BATP_L2 (0x72)
220 | #define MPEG4_HP_L1 (0x81)
221 | #define MPEG4_HP_L2 (0x82)
222 | #define MPEG4_ARTSP_L1 (0x91)
223 | #define MPEG4_ARTSP_L2 (0x92)
224 | #define MPEG4_ARTSP_L3 (0x93)
225 | #define MPEG4_ARTSP_L4 (0x94)
226 | #define MPEG4_CSP_L1 (0xa1)
227 | #define MPEG4_CSP_L2 (0xa2)
228 | #define MPEG4_CSP_L3 (0xa3)
229 | #define MPEG4_ACEP_L1 (0xb1)
230 | #define MPEG4_ACEP_L2 (0xb2)
231 | #define MPEG4_ACEP_L3 (0xb3)
232 | #define MPEG4_ACEP_L4 (0xb4)
233 | #define MPEG4_ACP_L1 (0xc1)
234 | #define MPEG4_ACP_L2 (0xc2)
235 | #define MPEG4_AST_L1 (0xd1)
236 | #define MPEG4_AST_L2 (0xd2)
237 | #define MPEG4_AST_L3 (0xd3)
238 | #define MPEG4_S_STUDIO_P_L1 (0xe1)
239 | #define MPEG4_S_STUDIO_P_L2 (0xe2)
240 | #define MPEG4_S_STUDIO_P_L3 (0xe3)
241 | #define MPEG4_S_STUDIO_P_L4 (0xe4)
242 | #define MPEG4_C_STUDIO_P_L1 (0xe5)
243 | #define MPEG4_C_STUDIO_P_L2 (0xe6)
244 | #define MPEG4_C_STUDIO_P_L3 (0xe7)
245 | #define MPEG4_C_STUDIO_P_L4 (0xe8)
246 | #define MPEG4_ASP_L0 (0xF0)
247 | #define MPEG4_ASP_L1 (0xF1)
248 | #define MPEG4_ASP_L2 (0xF2)
249 | #define MPEG4_ASP_L3 (0xF3)
250 | #define MPEG4_ASP_L4 (0xF4)
251 | #define MPEG4_ASP_L5 (0xF5)
252 | #define MPEG4_ASP_L3B (0xF7)
253 | #define MPEG4_FGSP_L0 (0xf8)
254 | #define MPEG4_FGSP_L1 (0xf9)
255 | #define MPEG4_FGSP_L2 (0xfa)
256 | #define MPEG4_FGSP_L3 (0xfb)
257 | #define MPEG4_FGSP_L4 (0xfc)
258 | #define MPEG4_FGSP_L5 (0xfd)
259 |
260 | /*****************************************************************************/
261 |
262 | /* 3GP specific utilities */
263 |
264 | MP4V2_EXPORT
265 | bool MP4Make3GPCompliant(
266 | const char* fileName,
267 | char* majorBrand DEFAULT(0),
268 | uint32_t minorVersion DEFAULT(0),
269 | char** supportedBrands DEFAULT(NULL),
270 | uint32_t supportedBrandsCount DEFAULT(0),
271 | bool deleteIodsAtom DEFAULT(true) );
272 |
273 | /* NOTE this section of functionality has not yet been fully tested */
274 |
275 | MP4V2_EXPORT
276 | MP4EditId MP4AddTrackEdit(
277 | MP4FileHandle hFile,
278 | MP4TrackId trackId,
279 | MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID),
280 | MP4Timestamp startTime DEFAULT(0),
281 | MP4Duration duration DEFAULT(0),
282 | bool dwell DEFAULT(false) );
283 |
284 | MP4V2_EXPORT
285 | bool MP4DeleteTrackEdit(
286 | MP4FileHandle hFile,
287 | MP4TrackId trackId,
288 | MP4EditId editId );
289 |
290 | MP4V2_EXPORT
291 | uint32_t MP4GetTrackNumberOfEdits(
292 | MP4FileHandle hFile,
293 | MP4TrackId trackId );
294 |
295 | MP4V2_EXPORT
296 | MP4Timestamp MP4GetTrackEditStart(
297 | MP4FileHandle hFile,
298 | MP4TrackId trackId,
299 | MP4EditId editId );
300 |
301 | MP4V2_EXPORT
302 | MP4Duration MP4GetTrackEditTotalDuration(
303 | MP4FileHandle hFile,
304 | MP4TrackId trackId,
305 | MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID) );
306 |
307 | MP4V2_EXPORT
308 | MP4Timestamp MP4GetTrackEditMediaStart(
309 | MP4FileHandle hFile,
310 | MP4TrackId trackId,
311 | MP4EditId editId );
312 |
313 | MP4V2_EXPORT
314 | bool MP4SetTrackEditMediaStart(
315 | MP4FileHandle hFile,
316 | MP4TrackId trackId,
317 | MP4EditId editId,
318 | MP4Timestamp startTime );
319 |
320 | MP4V2_EXPORT
321 | MP4Duration MP4GetTrackEditDuration(
322 | MP4FileHandle hFile,
323 | MP4TrackId trackId,
324 | MP4EditId editId );
325 |
326 | MP4V2_EXPORT
327 | bool MP4SetTrackEditDuration(
328 | MP4FileHandle hFile,
329 | MP4TrackId trackId,
330 | MP4EditId editId,
331 | MP4Duration duration );
332 |
333 | MP4V2_EXPORT
334 | int8_t MP4GetTrackEditDwell(
335 | MP4FileHandle hFile,
336 | MP4TrackId trackId,
337 | MP4EditId editId );
338 |
339 | MP4V2_EXPORT
340 | bool MP4SetTrackEditDwell(
341 | MP4FileHandle hFile,
342 | MP4TrackId trackId,
343 | MP4EditId editId,
344 | bool dwell );
345 |
346 | MP4V2_EXPORT
347 | bool MP4ReadSampleFromEditTime(
348 | /* input parameters */
349 | MP4FileHandle hFile,
350 | MP4TrackId trackId,
351 | MP4Timestamp when,
352 | /* input/output parameters */
353 | uint8_t** ppBytes,
354 | uint32_t* pNumBytes,
355 | /* output parameters */
356 | MP4Timestamp* pStartTime DEFAULT(NULL),
357 | MP4Duration* pDuration DEFAULT(NULL),
358 | MP4Duration* pRenderingOffset DEFAULT(NULL),
359 | bool* pIsSyncSample DEFAULT(NULL) );
360 |
361 | MP4V2_EXPORT
362 | MP4SampleId MP4GetSampleIdFromEditTime(
363 | MP4FileHandle hFile,
364 | MP4TrackId trackId,
365 | MP4Timestamp when,
366 | MP4Timestamp* pStartTime DEFAULT(NULL),
367 | MP4Duration* pDuration DEFAULT(NULL) );
368 |
369 | /* time conversion utilties */
370 |
371 | /* predefined values for timeScale parameter below */
372 | #define MP4_SECONDS_TIME_SCALE 1
373 | #define MP4_MILLISECONDS_TIME_SCALE 1000
374 | #define MP4_MICROSECONDS_TIME_SCALE 1000000
375 | #define MP4_NANOSECONDS_TIME_SCALE 1000000000
376 |
377 | #define MP4_SECS_TIME_SCALE MP4_SECONDS_TIME_SCALE
378 | #define MP4_MSECS_TIME_SCALE MP4_MILLISECONDS_TIME_SCALE
379 | #define MP4_USECS_TIME_SCALE MP4_MICROSECONDS_TIME_SCALE
380 | #define MP4_NSECS_TIME_SCALE MP4_NANOSECONDS_TIME_SCALE
381 |
382 | MP4V2_EXPORT
383 | uint64_t MP4ConvertFromMovieDuration(
384 | MP4FileHandle hFile,
385 | MP4Duration duration,
386 | uint32_t timeScale );
387 |
388 | MP4V2_EXPORT
389 | uint64_t MP4ConvertFromTrackTimestamp(
390 | MP4FileHandle hFile,
391 | MP4TrackId trackId,
392 | MP4Timestamp timeStamp,
393 | uint32_t timeScale );
394 |
395 | MP4V2_EXPORT
396 | MP4Timestamp MP4ConvertToTrackTimestamp(
397 | MP4FileHandle hFile,
398 | MP4TrackId trackId,
399 | uint64_t timeStamp,
400 | uint32_t timeScale );
401 |
402 | /** Convert duration from track time scale to an arbitrary time scale.
403 | *
404 | * MP4ConvertFromTrackDuration converts a duration such as a sample duration
405 | * from the track time scale to another time scale. This can be used by a
406 | * player application to map all track samples to a common time scale.
407 | *
408 | * @param hFile handle of file for operation.
409 | * @param trackId id of track for operation.
410 | * @param duration value to be converted.
411 | * @param timeScale time scale in ticks per second.
412 | *
413 | * @return On success, the duration in arbitrary time scale units.
414 | * On error, 0.
415 | *
416 | * @see MP4GetSampleDuration().
417 | * @see MP4ConvertToTrackDuration().
418 | */
419 | MP4V2_EXPORT
420 | uint64_t MP4ConvertFromTrackDuration(
421 | MP4FileHandle hFile,
422 | MP4TrackId trackId,
423 | MP4Duration duration,
424 | uint32_t timeScale );
425 |
426 | /** Convert duration from arbitrary time scale to track time scale.
427 | *
428 | * MP4ConvertToTrackDuration converts a duration such as a sample duration
429 | * from the specified time scale to the track time scale.
430 | *
431 | * @param hFile handle of file for operation.
432 | * @param trackId id of track for operation.
433 | * @param duration value to be converted.
434 | * @param timeScale time scale in ticks per second.
435 | *
436 | * @return On success, the duration in track time scale units.
437 | * On error, #MP4_INVALID_DURATION.
438 | *
439 | * @see MP4ConvertFromTrackDuration().
440 | */
441 | MP4V2_EXPORT
442 | MP4Duration MP4ConvertToTrackDuration(
443 | MP4FileHandle hFile,
444 | MP4TrackId trackId,
445 | uint64_t duration,
446 | uint32_t timeScale );
447 |
448 | MP4V2_EXPORT
449 | char* MP4BinaryToBase16(
450 | const uint8_t* pData,
451 | uint32_t dataSize );
452 |
453 | MP4V2_EXPORT
454 | char* MP4BinaryToBase64(
455 | const uint8_t* pData,
456 | uint32_t dataSize );
457 |
458 | MP4V2_EXPORT
459 | uint8_t* Base64ToBinary(
460 | const char* pData,
461 | uint32_t decodeSize,
462 | uint32_t* pDataSize );
463 |
464 | MP4V2_EXPORT
465 | void MP4Free(
466 | void* p );
467 |
468 | /** Set the function to call in place of default logging behavior
469 | *
470 | * @param cb_func the function to call
471 | */
472 | MP4V2_EXPORT
473 | void MP4SetLogCallback(
474 | MP4LogCallback cb_func );
475 | /** @} ***********************************************************************/
476 |
477 | /**
478 | * Accessor for the maximum level for diagnostic information
479 | *
480 | * @return the maximum level for diagnostic information
481 | *
482 | * @see MP4LogSetLevel() for further details.
483 | */
484 | MP4V2_EXPORT
485 | MP4LogLevel MP4LogGetLevel( void );
486 |
487 | /**
488 | * Set the maximum level for diagnostic information
489 | *
490 | * @param verbosity the level to set
491 | */
492 | MP4V2_EXPORT
493 | void MP4LogSetLevel( MP4LogLevel verbosity );
494 |
495 | #endif /* MP4V2_GENERAL_H */
496 |
--------------------------------------------------------------------------------
/app/libs/include/mp4v2/sample.h:
--------------------------------------------------------------------------------
1 | #ifndef MP4V2_SAMPLE_H
2 | #define MP4V2_SAMPLE_H
3 |
4 | /**************************************************************************//**
5 | *
6 | * @defgroup mp4_sample MP4v2 Sample
7 | * @{
8 | *
9 | *****************************************************************************/
10 |
11 | /** Sample dependency types.
12 | *
13 | * Bit combinations 0x03, 0x30, 0xc0 are reserved.
14 | */
15 | typedef enum MP4SampleDependencyType_e {
16 | MP4_SDT_UNKNOWN = 0x00, /**< unknown */
17 | MP4_SDT_HAS_REDUNDANT_CODING = 0x01, /**< contains redundant coding */
18 | MP4_SDT_HAS_NO_REDUNDANT_CODING = 0x02, /**< does not contain redundant coding */
19 | MP4_SDT_HAS_DEPENDENTS = 0x04, /**< referenced by other samples */
20 | MP4_SDT_HAS_NO_DEPENDENTS = 0x08, /**< not referenced by other samples */
21 | MP4_SDT_IS_DEPENDENT = 0x10, /**< references other samples */
22 | MP4_SDT_IS_INDEPENDENT = 0x20, /**< does not reference other samples */
23 | MP4_SDT_EARLIER_DISPLAY_TIMES_ALLOWED = 0x40, /**< subequent samples in GOP may display earlier */
24 | _MP4_SDT_RESERVED = 0x80 /**< reserved */
25 | } MP4SampleDependencyType;
26 |
27 | /** Read a track sample.
28 | *
29 | * MP4ReadSample reads the specified sample from the specified track.
30 | * Typically this sample is then decoded in a codec dependent fashion and
31 | * rendered in an appropriate fashion.
32 | *
33 | * The argument ppBytes allows for two possible approaches for
34 | * buffering:
35 | *
36 | * If the calling application wishes to handle its own buffering it can set
37 | * *ppBytes to the buffer it wishes to use. The calling application is
38 | * responsible for ensuring that the buffer is large enough to hold the
39 | * sample. This can be done by using either MP4GetSampleSize() or
40 | * MP4GetTrackMaxSampleSize() to determine before-hand how large the
41 | * receiving buffer must be.
42 | *
43 | * If the value of *ppBytes is NULL, then an appropriately sized buffer is
44 | * automatically malloc'ed for the sample data and *ppBytes set to this
45 | * pointer. The calling application is responsible for free'ing this
46 | * memory.
47 | *
48 | * The last four arguments are pointers to variables that can receive
49 | * optional sample information.
50 | *
51 | * Typically for audio none of these are needed. MPEG audio such as MP3 or
52 | * AAC has a fixed sample duration and every sample can be accessed at
53 | * random.
54 | *
55 | * For video, all of these optional values could be needed. MPEG video can
56 | * be encoded at a variable frame rate, with only occasional random access
57 | * points, and with "B frames" which cause the rendering (display) order
58 | * of the video frames to differ from the storage/decoding order.
59 | *
60 | * Other media types fall between these two extremes.
61 | *
62 | * @param hFile handle of file for operation.
63 | * @param trackId id of track for operation.
64 | * @param sampleId specifies which sample is to be read.
65 | * Caveat: the first sample has id 1 not 0.
66 | * @param ppBytes pointer to the pointer to the sample data.
67 | * @param pNumBytes pointer to variable that will be hold the size in bytes
68 | * of the sample.
69 | * @param pStartTime if non-NULL, pointer to variable that will receive the
70 | * starting timestamp for this sample. Caveat: The timestamp is in
71 | * trackId's timescale.
72 | * @param pDuration if non-NULL, pointer to variable that will receive the
73 | * duration for this sample. Caveat: The duration is in
74 | * trackId's timescale.
75 | * @param pRenderingOffset if non-NULL, pointer to variable that will
76 | * receive the rendering offset for this sample. Currently the only
77 | * media type that needs this feature is MPEG video. Caveat: The offset
78 | * is in trackId's timescale.
79 | * @param pIsSyncSample if non-NULL, pointer to variable that will receive
80 | * the state of the sync/random access flag for this sample.
81 | *
82 | * @return true on success, false on failure.
83 | *
84 | * @see MP4GetSampleSize().
85 | * @see MP4GetTrackMaxSampleSize().
86 | */
87 | MP4V2_EXPORT
88 | bool MP4ReadSample(
89 | /* input parameters */
90 | MP4FileHandle hFile,
91 | MP4TrackId trackId,
92 | MP4SampleId sampleId,
93 | /* input/output parameters */
94 | uint8_t** ppBytes,
95 | uint32_t* pNumBytes,
96 | /* output parameters */
97 | MP4Timestamp* pStartTime DEFAULT(NULL),
98 | MP4Duration* pDuration DEFAULT(NULL),
99 | MP4Duration* pRenderingOffset DEFAULT(NULL),
100 | bool* pIsSyncSample DEFAULT(NULL) );
101 |
102 | /** Read a track sample based on a specified time.
103 | *
104 | * MP4ReadSampleFromTime is similar to MP4ReadSample() except the sample
105 | * is specified by using a timestamp instead of sampleId.
106 | * Typically this sample is then decoded in a codec dependent fashion and
107 | * rendered in an appropriate fashion.
108 | *
109 | * The argument ppBytes allows for two possible approaches for
110 | * buffering:
111 | *
112 | * If the calling application wishes to handle its own buffering it can set
113 | * *ppBytes to the buffer it wishes to use. The calling application is
114 | * responsible for ensuring that the buffer is large enough to hold the
115 | * sample. This can be done by using either MP4GetSampleSize() or
116 | * MP4GetTrackMaxSampleSize() to determine before-hand how large the
117 | * receiving buffer must be.
118 | *
119 | * If the value of *ppBytes is NULL, then an appropriately sized buffer is
120 | * automatically malloc'ed for the sample data and *ppBytes set to this
121 | * pointer. The calling application is responsible for free'ing this
122 | * memory.
123 | *
124 | * The last four arguments are pointers to variables that can receive
125 | * optional sample information.
126 | *
127 | * Typically for audio none of these are needed. MPEG audio such as MP3 or
128 | * AAC has a fixed sample duration and every sample can be accessed at
129 | * random.
130 | *
131 | * For video, all of these optional values could be needed. MPEG video can
132 | * be encoded at a variable frame rate, with only occasional random access
133 | * points, and with "B frames" which cause the rendering (display) order
134 | * of the video frames to differ from the storage/decoding order.
135 | *
136 | * Other media types fall between these two extremes.
137 | *
138 | * @param hFile handle of file for operation.
139 | * @param trackId id of track for operation.
140 | * @param when specifies which sample is to be read based on a time in the
141 | * track timeline. See MP4GetSampleIdFromTime() for details.
142 | * @param ppBytes pointer to the pointer to the sample data.
143 | * @param pNumBytes pointer to variable that will be hold the size in bytes
144 | * of the sample.
145 | * @param pStartTime if non-NULL, pointer to variable that will receive the
146 | * starting timestamp for this sample. Caveat: The timestamp is in
147 | * trackId's timescale.
148 | * @param pDuration if non-NULL, pointer to variable that will receive the
149 | * duration for this sample. Caveat: The duration is in
150 | * trackId's timescale.
151 | * @param pRenderingOffset if non-NULL, pointer to variable that will
152 | * receive the rendering offset for this sample. Currently the only
153 | * media type that needs this feature is MPEG video. Caveat: The offset
154 | * is in trackId's timescale.
155 | * @param pIsSyncSample if non-NULL, pointer to variable that will receive
156 | * the state of the sync/random access flag for this sample.
157 | *
158 | * @return true on success, false on failure.
159 | *
160 | * @see MP4ReadSample().
161 | * @see MP4GetSampleIdFromTime().
162 | * @see MP4GetSampleSize().
163 | * @see MP4GetTrackMaxSampleSize().
164 | */
165 | MP4V2_EXPORT
166 | bool MP4ReadSampleFromTime(
167 | /* input parameters */
168 | MP4FileHandle hFile,
169 | MP4TrackId trackId,
170 | MP4Timestamp when,
171 | /* input/output parameters */
172 | uint8_t** ppBytes,
173 | uint32_t* pNumBytes,
174 | /* output parameters */
175 | MP4Timestamp* pStartTime DEFAULT(NULL),
176 | MP4Duration* pDuration DEFAULT(NULL),
177 | MP4Duration* pRenderingOffset DEFAULT(NULL),
178 | bool* pIsSyncSample DEFAULT(NULL) );
179 |
180 | /** Write a track sample.
181 | *
182 | * MP4WriteSample writes the given sample at the end of the specified track.
183 | * Currently the library does not support random insertion of samples into
184 | * the track timeline. Note that with mp4 there cannot be any holes or
185 | * overlapping samples in the track timeline. The last three arguments give
186 | * optional sample information.
187 | *
188 | * The value of duration can be given as #MP4_INVALID_DURATION if all samples
189 | * in the track have the same duration. This can be specified with
190 | * MP4AddTrack() and related functions.
191 | *
192 | * Typically for audio none of the optional arguments are needed. MPEG audio
193 | * such as MP3 or AAC has a fixed sample duration and every sample can be
194 | * accessed at random.
195 | *
196 | * For video, all of the optional arguments could be needed. MPEG video
197 | * can be encoded at a variable frame rate, with only occasional random
198 | * access points, and with "B frames" which cause the rendering (display)
199 | * order of the video frames to differ from the storage/decoding order.
200 | *
201 | * Other media types fall between these two extremes.
202 | *
203 | * @param hFile handle of file for operation.
204 | * @param trackId id of track for operation.
205 | * @param pBytes pointer to sample data.
206 | * @param numBytes length of sample data in bytes.
207 | * @param duration sample duration. Caveat: should be in track timescale.
208 | * @param renderingOffset the rendering offset for this sample.
209 | * Currently the only media type that needs this feature is MPEG
210 | * video. Caveat: The offset should be in the track timescale.
211 | * @param isSyncSample the sync/random access flag for this sample.
212 | *
213 | * @return true on success, false on failure.
214 | *
215 | * @see MP4AddTrack().
216 | */
217 | MP4V2_EXPORT
218 | bool MP4WriteSample(
219 | MP4FileHandle hFile,
220 | MP4TrackId trackId,
221 | const uint8_t* pBytes,
222 | uint32_t numBytes,
223 | MP4Duration duration DEFAULT(MP4_INVALID_DURATION),
224 | MP4Duration renderingOffset DEFAULT(0),
225 | bool isSyncSample DEFAULT(true) );
226 |
227 | /** Write a track sample and supply dependency information.
228 | *
229 | * MP4WriteSampleDependency writes the given sample at the end of the specified track.
230 | * Currently the library does not support random insertion of samples into
231 | * the track timeline. Note that with mp4 there cannot be any holes or
232 | * overlapping samples in the track timeline. The last three arguments give
233 | * optional sample information.
234 | *
235 | * The value of duration can be given as #MP4_INVALID_DURATION if all samples
236 | * in the track have the same duration. This can be specified with
237 | * MP4AddTrack() and related functions.
238 | *
239 | * When this method is used instead of MP4WriteSample() it enables sdtp
240 | * atom to be written out. This atom may be used by advanced players to
241 | * optimize trick-operations such as fast-fwd, reverse or scrubbing.
242 | *
243 | * An sdtp atom will always be written out if this method is used.
244 | * To avoid writing the atom, use MP4WriteSample() instead.
245 | *
246 | * Intermixing use of MP4WriteSampleDependency() and MP4WriteSample() on the
247 | * same track is not permitted.
248 | *
249 | * @param hFile handle of file for operation.
250 | * @param trackId id of track for operation.
251 | * @param pBytes pointer to sample data.
252 | * @param numBytes length of sample data in bytes.
253 | * @param duration sample duration. Caveat: should be in track timescale.
254 | * @param renderingOffset the rendering offset for this sample.
255 | * Currently the only media type that needs this feature is MPEG
256 | * video. Caveat: The offset should be in the track timescale.
257 | * @param isSyncSample the sync/random access flag for this sample.
258 | * @param dependencyFlags bitmask specifying sample dependency characteristics.
259 | * See #MP4SampleDependencyType for bit constants.
260 | *
261 | * @return true on success, false on failure.
262 | *
263 | * @see MP4AddTrack().
264 | */
265 | MP4V2_EXPORT
266 | bool MP4WriteSampleDependency(
267 | MP4FileHandle hFile,
268 | MP4TrackId trackId,
269 | const uint8_t* pBytes,
270 | uint32_t numBytes,
271 | MP4Duration duration,
272 | MP4Duration renderingOffset,
273 | bool isSyncSample,
274 | uint32_t dependencyFlags );
275 |
276 | /** Make a copy of a sample.
277 | *
278 | * MP4CopySample creates a new sample based on an existing sample. Note that
279 | * another copy of the media sample data is created in the file using this
280 | * function. ie. this call is equivalent to MP4ReadSample() followed by
281 | * MP4WriteSample().
282 | *
283 | * Note that is the responsibility of the caller to ensure that the copied
284 | * media sample makes sense in the destination track. eg. copying a video
285 | * sample to an audio track is unlikely to result in anything good happening,
286 | * even copying a sample from video track to another requires that the tracks
287 | * use the same encoding and that issues such as image size are addressed.
288 | *
289 | * @param srcFile source sample file handle.
290 | * @param srcTrackId source sample track id.
291 | * @param srcSampleId source sample id.
292 | * @param dstFile destination file handle for new (copied) sample.
293 | * If the value is #MP4_INVALID_FILE_HANDLE, the copy is created in
294 | * the same file as srcFile.
295 | * @param dstTrackId destination track id for new sample.
296 | * If the value is #MP4_INVALID_TRACK_ID, the the copy is created in
297 | * the same track as the srcTrackId.
298 | * @param dstSampleDuration duration in track timescale for new sample.
299 | * If the value is #MP4_INVALID_DURATION, then the duration of
300 | * the source sample is used.
301 | *
302 | * @return On success, thew id of the new sample.
303 | * On error, #MP4_INVALID_SAMPLE_ID.
304 | *
305 | * @see MP4ReadSample().
306 | * @see MP4WriteSample().
307 | */
308 | MP4V2_EXPORT
309 | bool MP4CopySample(
310 | MP4FileHandle srcFile,
311 | MP4TrackId srcTrackId,
312 | MP4SampleId srcSampleId,
313 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
314 | MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
315 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) );
316 |
317 | /** Make a copy of a sample.
318 | *
319 | * MP4EncAndCopySample is similar to MP4CopySample() except that it
320 | * offers an encryption hook to the caller.
321 | *
322 | * @param srcFile source sample file handle.
323 | * @param srcTrackId source sample track id.
324 | * @param srcSampleId source sample id.
325 | * @param encfcnp undocumented.
326 | * @param encfcnparam1 undocumented.
327 | * @param dstFile destination file handle for new (copied) sample.
328 | * If the value is #MP4_INVALID_FILE_HANDLE, the copy is created in
329 | * the same file as srcFile.
330 | * @param dstTrackId destination track id for new sample.
331 | * If the value is #MP4_INVALID_TRACK_ID, the the copy is created in
332 | * the same track as the srcTrackId.
333 | * @param dstSampleDuration duration in track timescale for new sample.
334 | * If the value is #MP4_INVALID_DURATION, then the duration of
335 | * the source sample is used.
336 | *
337 | * @return On success, thew id of the new sample.
338 | * On error, #MP4_INVALID_SAMPLE_ID.
339 | *
340 | * @see MP4CopySample().
341 | */
342 | MP4V2_EXPORT
343 | bool MP4EncAndCopySample(
344 | MP4FileHandle srcFile,
345 | MP4TrackId srcTrackId,
346 | MP4SampleId srcSampleId,
347 | encryptFunc_t encfcnp,
348 | uint32_t encfcnparam1,
349 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
350 | MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
351 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) );
352 |
353 | /** Not implemented.
354 | */
355 | MP4V2_EXPORT
356 | bool MP4ReferenceSample(
357 | MP4FileHandle srcFile,
358 | MP4TrackId srcTrackId,
359 | MP4SampleId srcSampleId,
360 | MP4FileHandle dstFile,
361 | MP4TrackId dstTrackId,
362 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) );
363 |
364 | /** Get size of a track sample.
365 | *
366 | * MP4GetSampleSize returns the size in bytes of the specified sample from the
367 | * the specified track.
368 | *
369 | * @param hFile handle of file for operation.
370 | * @param trackId id of track for operation.
371 | * @param sampleId id of sample for operation. Caveat: the first sample has
372 | * id 1, not 0.
373 | *
374 | * @return On success the sample size in bytes. On error, 0.
375 | */
376 | MP4V2_EXPORT
377 | uint32_t MP4GetSampleSize(
378 | MP4FileHandle hFile,
379 | MP4TrackId trackId,
380 | MP4SampleId sampleId);
381 |
382 | /** Get the maximum sample size of a track.
383 | *
384 | * MP4GetTrackMaxSampleSize returns the maximum size in bytes of all the
385 | * samples in the specified track.
386 | *
387 | * @param hFile handle of file for operation.
388 | * @param trackId id of track for operation.
389 | *
390 | * @return On success, the maximum sample size in bytes. On error, 0.
391 | *
392 | * @see MP4GetSampleSize().
393 | */
394 | MP4V2_EXPORT
395 | uint32_t MP4GetTrackMaxSampleSize(
396 | MP4FileHandle hFile,
397 | MP4TrackId trackId );
398 |
399 | /** Get sample id of a specified time.
400 | *
401 | * MP4GetSampleIdFromTime returns the sample id of the track sample in which
402 | * the specified time occurs.
403 | *
404 | * The specified time should be in the track timescale.
405 | *
406 | * It is wise to use MP4GetSampleTime() with the returned sample id so one
407 | * can adjust for any difference between the specified time and the actual
408 | * start time of the sample.
409 | *
410 | * If the calling application needs a sample that can be accessed randomly
411 | * then the wantSyncSample argument should be set to true. This could
412 | * be the case for a player that is implementing a positioning function and
413 | * needs to be able to start decoding a track from the returned sample id.
414 | *
415 | * @param hFile handle of file for operation.
416 | * @param trackId id of track for operation.
417 | * @param when time in track timescale.
418 | * @param wantSyncSample specifies if the result sample id must correspond
419 | * to a sample whose sync/random access flag is true.
420 | *
421 | * @return On success, the sample id that occurs at the specified time.
422 | * On error, #MP4_INVALID_SAMPLE_ID.
423 | *
424 | * @see MP4ConvertToTrackTimestamp() for how to map a time value to this
425 | * timescale.
426 | */
427 | MP4V2_EXPORT
428 | MP4SampleId MP4GetSampleIdFromTime(
429 | MP4FileHandle hFile,
430 | MP4TrackId trackId,
431 | MP4Timestamp when,
432 | bool wantSyncSample DEFAULT(false) );
433 |
434 | /** Get start time of track sample.
435 | *
436 | * MP4GetSampleTime returns the start time of the specified sample from
437 | * the specified track in the track timescale units.
438 | *
439 | * @param hFile handle of file for operation.
440 | * @param trackId id of track for operation.
441 | * @param sampleId id of sample for operation. Caveat: the first sample has
442 | * id 1, not 0.
443 | *
444 | * @return On success, sample start time in track timescale units.
445 | * On error, #MP4_INVALID_TIMESTAMP.
446 | *
447 | * @see MP4ConvertFromTrackTimestamp() for how to map this value to another
448 | * timescale.
449 | */
450 | MP4V2_EXPORT
451 | MP4Timestamp MP4GetSampleTime(
452 | MP4FileHandle hFile,
453 | MP4TrackId trackId,
454 | MP4SampleId sampleId );
455 |
456 | /** Get the duration of a track sample.
457 | *
458 | * MP4GetSampleDuration returns the duration of the specified sample from
459 | * the specified track in the track timescale units.
460 | *
461 | * @param hFile handle of file for operation.
462 | * @param trackId id of track for operation.
463 | * @param sampleId id of sample for operation. Caveat: the first sample has
464 | * id 1, not 0.
465 | *
466 | * @return On success, the sample duration in track timescale units.
467 | * On error, #MP4_INVALID_DURATION.
468 | *
469 | * @see MP4ConvertFromTrackDuration() for how to map this value to another
470 | * timescale.
471 | */
472 | MP4V2_EXPORT
473 | MP4Duration MP4GetSampleDuration(
474 | MP4FileHandle hFile,
475 | MP4TrackId trackId,
476 | MP4SampleId sampleId );
477 |
478 | /** Get the rendering offset of a track sample.
479 | *
480 | * MP4GetSampleRenderingOffset returns the rendering offset of the specified
481 | * sample from the specified track in the track timescale units.
482 | *
483 | * The sample rendering offset is typically zero for all media types other
484 | * than video. For video, encodings such as those defined by MPEG have
485 | * three types of frames: I, P, and B. To increase coding efficiency B
486 | * frames can depend on I or P frames that should be rendered after the B
487 | * frame. However to decode the B frame the I or P frame must already have
488 | * been decoded. This situation is addressed by placing the frames in
489 | * decoding order in the video track, and then setting the rendering offset
490 | * property to indicate when the video frame should actually be rendered to
491 | * the screen. Hence the start time of a sample indicates when it should be
492 | * decoded, the start time plus the rendering offset indicates when it
493 | * should be rendered.
494 | *
495 | * @param hFile handle of file for operation.
496 | * @param trackId id of track for operation.
497 | * @param sampleId id of sample for operation. Caveat: the first sample has
498 | * id 1, not 0.
499 | *
500 | * @return On success, the rendering offset in track timescale units.
501 | * On error, #MP4_INVALID_DURATION.
502 | *
503 | * @see MP4ConvertFromTrackDuration() for how to map this value to another
504 | * timescale.
505 | */
506 | MP4V2_EXPORT
507 | MP4Duration MP4GetSampleRenderingOffset(
508 | MP4FileHandle hFile,
509 | MP4TrackId trackId,
510 | MP4SampleId sampleId );
511 |
512 | /** Set the rendering offset of a track sample.
513 | *
514 | * MP4SetSampleRenderingOffset sets the rendering offset of the specified
515 | * sample from the specified track in the track timescale units.
516 | *
517 | * @param hFile handle of file for operation.
518 | * @param trackId id of track for operation.
519 | * @param sampleId id of sample for operation. Caveat: the first sample has
520 | * id 1, not 0.
521 | * @param renderingOffset new offset value in timescale units.
522 | *
523 | * @return true on success, false on failure.
524 | *
525 | * @see MP4ConvertToTrackDuration() for how to map this value from another
526 | * timescale.
527 | * @see MP4GetSampleRenderingOffset() for a description of this sample
528 | * property.
529 | */
530 | MP4V2_EXPORT
531 | bool MP4SetSampleRenderingOffset(
532 | MP4FileHandle hFile,
533 | MP4TrackId trackId,
534 | MP4SampleId sampleId,
535 | MP4Duration renderingOffset );
536 |
537 | /** Get sync/random access state of sample.
538 | *
539 | * MP4GetSampleSync returns the state of the sync/random access flag of
540 | * the specified sample from the specified track.
541 | *
542 | * @param hFile handle of file for operation.
543 | * @param trackId id of track for operation.
544 | * @param sampleId id of sample for operation. Caveat: the first sample has
545 | * id 1, not 0.
546 | *
547 | * @return 1 when true, 0 when false. On error, -1.
548 | */
549 | MP4V2_EXPORT
550 | int8_t MP4GetSampleSync(
551 | MP4FileHandle hFile,
552 | MP4TrackId trackId,
553 | MP4SampleId sampleId );
554 |
555 | /* @} ***********************************************************************/
556 |
557 | #endif /* MP4V2_SAMPLE_H */
558 |
--------------------------------------------------------------------------------