12#include <sp/spChunk.h>
19#define SP_MP4_BOX_MIN_ENTRY_ALLOC_COUNT 4
21#define spMp4BoxSize spChunkSize
23#define SP_MP4_META_DATA_TYPE_INDICATOR_UTF8 1
24#define SP_MP4_META_DATA_TYPE_INDICATOR_UTF16 2
25#define SP_MP4_META_DATA_TYPE_INDICATOR_SJIS 3
26#define SP_MP4_META_DATA_TYPE_INDICATOR_UTF8_SORT 4
27#define SP_MP4_META_DATA_TYPE_INDICATOR_UTF16_SORT 5
28#define SP_MP4_META_DATA_TYPE_INDICATOR_JPEG 13
29#define SP_MP4_META_DATA_TYPE_INDICATOR_PNG 14
30#define SP_MP4_META_DATA_TYPE_INDICATOR_BE_SIGNED_INT 21
31#define SP_MP4_META_DATA_TYPE_INDICATOR_BE_UNSIGNED_INT 22
32#define SP_MP4_META_DATA_TYPE_INDICATOR_BE_FLOAT 23
33#define SP_MP4_META_DATA_TYPE_INDICATOR_BE_DOUBLE 24
34#define SP_MP4_META_DATA_TYPE_INDICATOR_BMP 27
35#define SP_MP4_META_DATA_TYPE_INDICATOR_QT_METADATA 28
37#define SP_MP4_META_DATA_TYPE_TITLE "\251nam"
38#define SP_MP4_META_DATA_TYPE_ARTIST "\251ART"
39#define SP_MP4_META_DATA_TYPE_ALBUM_ARTIST "aART"
40#define SP_MP4_META_DATA_TYPE_ALBUM "\251alb"
41#define SP_MP4_META_DATA_TYPE_COMPOSER "\251wrt"
42#define SP_MP4_META_DATA_TYPE_GENRE "\251gen"
43#define SP_MP4_META_DATA_TYPE_RELEASE "\251day"
44#define SP_MP4_META_DATA_TYPE_SOFTWARE "\251too"
45#define SP_MP4_META_DATA_TYPE_COPYRIGHT "cprt"
46#define SP_MP4_META_DATA_TYPE_COMMENT "\251cmt"
47#define SP_MP4_META_DATA_TYPE_TITLE_YOMI "sonm"
48#define SP_MP4_META_DATA_TYPE_ARTIST_YOMI "soar"
49#define SP_MP4_META_DATA_TYPE_ALBUM_ARTIST_YOMI "soaa"
50#define SP_MP4_META_DATA_TYPE_ALBUM_YOMI "soal"
51#define SP_MP4_META_DATA_TYPE_COMPOSER_YOMI "soco"
52#define SP_MP4_META_DATA_TYPE_TRACK "trkn"
53#define SP_MP4_META_DATA_TYPE_DISC "disc"
54#define SP_MP4_META_DATA_TYPE_TEMPO "tmpo"
55#define SP_MP4_META_DATA_TYPE_COMPILATION "cpil"
56#define SP_MP4_META_DATA_TYPE_GAPLESS "pgap"
58typedef struct _spMp4BoxHeader {
61 spMp4BoxSize largesize;
62 unsigned char version;
63 unsigned char flags[3];
66 spMp4BoxSize marginsize;
69typedef struct _spMp4Box {
70 struct _spMp4Box *parent;
71 struct _spMp4Box *child;
73 struct _spMp4Box *prev;
74 struct _spMp4Box *next;
78 spMp4BoxHeader header;
81typedef struct _spMp4ULongOnlyBox {
82 struct _spMp4Box *parent;
83 struct _spMp4Box *child;
85 struct _spMp4Box *prev;
86 struct _spMp4Box *next;
90 spMp4BoxHeader header;
95typedef struct _spMp4DataOnlyBox {
96 struct _spMp4Box *parent;
97 struct _spMp4Box *child;
99 struct _spMp4Box *prev;
100 struct _spMp4Box *next;
104 spMp4BoxHeader header;
109typedef struct _spMp4MetaDataValueBox {
110 struct _spMp4Box *parent;
111 struct _spMp4Box *child;
113 struct _spMp4Box *prev;
114 struct _spMp4Box *next;
118 spMp4BoxHeader header;
120 unsigned long type_indicator;
121 unsigned short country;
122 unsigned short language;
124} spMp4MetaDataValueBox;
126typedef struct _spMp4UserDataStringBox {
127 struct _spMp4Box *parent;
128 struct _spMp4Box *child;
130 struct _spMp4Box *prev;
131 struct _spMp4Box *next;
135 spMp4BoxHeader header;
138 unsigned short language;
140} spMp4UserDataStringBox;
142typedef struct _spMp4FileTypeBox {
143 struct _spMp4Box *parent;
144 struct _spMp4Box *child;
146 struct _spMp4Box *prev;
147 struct _spMp4Box *next;
151 spMp4BoxHeader header;
157 char *compatible_brands;
160typedef struct _spMp4MovieHeaderBox {
161 struct _spMp4MovieBox *parent;
162 struct _spMp4Box *child;
164 struct _spMp4Box *prev;
165 struct _spMp4Box *next;
169 spMp4BoxHeader header;
173 char creation_time[8];
174 char modification_time[8];
175 unsigned long timescale;
180 unsigned long creation_time;
181 unsigned long modification_time;
182 unsigned long timescale;
183 unsigned long duration;
190 unsigned long reserved2[2];
192 unsigned long pre_defined[6];
193 unsigned long next_track_id;
195} spMp4MovieHeaderBox;
197typedef struct _spMp4TrackHeaderBox {
198 struct _spMp4TrackBox *parent;
199 struct _spMp4Box *child;
201 struct _spMp4Box *prev;
202 struct _spMp4Box *next;
206 spMp4BoxHeader header;
209 char creation_time[8];
210 char modification_time[8];
211 unsigned long track_id;
212 unsigned long reserved;
217 unsigned long creation_time;
218 unsigned long modification_time;
219 unsigned long track_id;
220 unsigned long reserved;
221 unsigned long duration;
225 unsigned long reserved2[2];
227 short alternate_group;
229 unsigned short reserved3;
233 unsigned long height;
234} spMp4TrackHeaderBox;
236typedef struct _spMp4MediaHeaderBox {
237 struct _spMp4MediaBox *parent;
238 struct _spMp4Box *child;
240 struct _spMp4Box *prev;
241 struct _spMp4Box *next;
245 spMp4BoxHeader header;
249 char creation_time[8];
250 char modification_time[8];
251 unsigned long timescale;
256 unsigned long creation_time;
257 unsigned long modification_time;
258 unsigned long timescale;
259 unsigned long duration;
263 unsigned short language;
264 unsigned short quality;
265} spMp4MediaHeaderBox;
267typedef struct _spMp4UserDataBox {
268 struct _spMp4Box *parent;
269 struct _spMp4Box *child;
271 struct _spMp4Box *prev;
272 struct _spMp4Box *next;
276 spMp4BoxHeader header;
278 struct _spMp4MetaBox *meta;
285typedef struct _spMp4LanguageList {
286 unsigned short language_count;
290typedef struct _spMp4LanguageListBox {
291 struct _spMp4Box *parent;
292 struct _spMp4Box *child;
294 struct _spMp4Box *prev;
295 struct _spMp4Box *next;
299 spMp4BoxHeader header;
301 unsigned long alloc_count;
302 unsigned long entry_count;
303 spMp4LanguageList *language_lists;
304} spMp4LanguageListBox;
306typedef struct _spMp4CountryList {
307 unsigned short country_count;
311typedef struct _spMp4CountryListBox {
312 struct _spMp4Box *parent;
313 struct _spMp4Box *child;
315 struct _spMp4Box *prev;
316 struct _spMp4Box *next;
320 spMp4BoxHeader header;
322 unsigned long alloc_count;
323 unsigned long entry_count;
324 spMp4CountryList *country_lists;
325} spMp4CountryListBox;
327typedef struct _spMp4KeyEntry {
333typedef struct _spMp4KeysBox {
334 struct _spMp4Box *parent;
335 struct _spMp4Box *child;
337 struct _spMp4Box *prev;
338 struct _spMp4Box *next;
342 spMp4BoxHeader header;
344 unsigned long alloc_count;
345 unsigned long entry_count;
349typedef struct _spMp4HandlerReferenceBox {
350 struct _spMp4Box *parent;
351 struct _spMp4Box *child;
353 struct _spMp4Box *prev;
354 struct _spMp4Box *next;
358 spMp4BoxHeader header;
360 unsigned long pre_defined;
361 char handler_type[4];
363 unsigned long reserved[3];
366} spMp4HandlerReferenceBox;
368typedef struct _spMp4VideoMediaHeaderBox {
369 struct _spMp4Box *parent;
370 struct _spMp4Box *child;
372 struct _spMp4Box *prev;
373 struct _spMp4Box *next;
377 spMp4BoxHeader header;
379 unsigned short graphicsmode;
380 unsigned short opcolor[3];
381} spMp4VideoMediaHeaderBox;
383typedef struct _spMp4SoundMediaHeaderBox {
384 struct _spMp4Box *parent;
385 struct _spMp4Box *child;
387 struct _spMp4Box *prev;
388 struct _spMp4Box *next;
392 spMp4BoxHeader header;
394 unsigned short balance;
395 unsigned short reserved;
396} spMp4SoundMediaHeaderBox;
398typedef struct _spMp4HintMediaHeaderBox {
399 struct _spMp4Box *parent;
400 struct _spMp4Box *child;
402 struct _spMp4Box *prev;
403 struct _spMp4Box *next;
407 spMp4BoxHeader header;
409 unsigned short maxPDUSize;
410 unsigned short avgPDUSize;
411 unsigned long maxBitRate;
412 unsigned long avgBitRate;
413 unsigned long reserved;
414} spMp4HintMediaHeaderBox;
416typedef struct _spMp4NullMediaHeaderBox {
417 struct _spMp4Box *parent;
418 struct _spMp4Box *child;
420 struct _spMp4Box *prev;
421 struct _spMp4Box *next;
425 spMp4BoxHeader header;
426} spMp4NullMediaHeaderBox;
428typedef struct _spMp4DataSampleEntry {
430} spMp4DataSampleEntry;
432typedef struct _spMp4RtpHintSampleEntry {
433 unsigned short hint_track_version;
434 unsigned short highest_compatible_version;
435 unsigned long max_packet_size;
437 spMp4ULongOnlyBox *tims;
438 spMp4ULongOnlyBox *tsro;
439 spMp4ULongOnlyBox *snro;
440} spMp4RtpHintSampleEntry;
442typedef struct _spMp4BitRateBox {
445 unsigned long bufferSizeDB;
446 unsigned long maxBitRate;
447 unsigned long avgBitRate;
450typedef struct _spMp4XMLMetaDataSampleEntry {
451 char content_encoding[256];
452 char name_space[256];
453 char schema_location[256];
455 spMp4BitRateBox bitRate;
456} spMp4XMLMetaDataSampleEntry;
458typedef struct _spMp4TextMetaDataSampleEntry {
459 char content_encoding[256];
460 char mime_format[256];
462 spMp4BitRateBox bitRate;
463} spMp4TextMetaDataSampleEntry;
465typedef struct _spMp4SampleScaleBox {
466 struct _spMp4Box *parent;
467 struct _spMp4Box *child;
469 struct _spMp4Box *prev;
470 struct _spMp4Box *next;
474 spMp4BoxHeader header;
477 unsigned char scale_method;
478 short display_center_x;
479 short display_center_y;
480} spMp4SampleScaleBox;
482typedef struct _spMp4PixelAspectRatioBox {
483 struct _spMp4Box *parent;
484 struct _spMp4Box *child;
486 struct _spMp4Box *prev;
487 struct _spMp4Box *next;
491 spMp4BoxHeader header;
493 unsigned long hSpacing;
494 unsigned long vSpacing;
495} spMp4PixelAspectRatioBox;
497typedef struct _spMp4CleanApertureBox {
498 struct _spMp4Box *parent;
499 struct _spMp4Box *child;
501 struct _spMp4Box *prev;
502 struct _spMp4Box *next;
506 spMp4BoxHeader header;
508 unsigned long cleanApertureWidthN;
509 unsigned long cleanApertureWidthD;
511 unsigned long cleanApertureHeightN;
512 unsigned long cleanApertureHeightD;
514 unsigned long horizOffN;
515 unsigned long horizOffD;
517 unsigned long vertOffN;
518 unsigned long vertOffD;
519} spMp4CleanApertureBox;
521typedef struct _spMp4ColorParameterBox {
522 struct _spMp4Box *parent;
523 struct _spMp4Box *child;
525 struct _spMp4Box *prev;
526 struct _spMp4Box *next;
530 spMp4BoxHeader header;
534 short primaries_index;
535 short transfer_function_index;
540} spMp4ColorParameterBox;
542typedef struct _spMp4VisualSampleEntry {
543 unsigned short version;
544 unsigned short revision;
545 unsigned long vendor;
546 unsigned long temporal_quality;
547 unsigned long spatial_quality;
548 unsigned short width;
549 unsigned short height;
550 unsigned long horizresolution;
551 unsigned long vertresolution;
552 unsigned long reserved2;
553 unsigned short frame_count;
554 char compressorname[32];
555 unsigned short depth;
556 short color_table_id;
558 spMp4ULongOnlyBox *gama;
559 spMp4DataOnlyBox *fiel;
560 spMp4DataOnlyBox *esds;
561 spMp4CleanApertureBox *clap;
562 spMp4ColorParameterBox *colr;
563 spMp4PixelAspectRatioBox *pasp;
564 spMp4SampleScaleBox *stsl;
565 spMp4DataOnlyBox *avcC;
566 spMp4DataOnlyBox *uuid;
567 spMp4DataOnlyBox *mjqt;
568 spMp4DataOnlyBox *mjht;
569} spMp4VisualSampleEntry;
571typedef struct _spMp4AudioSampleEntry {
572 unsigned short version;
573 unsigned short revision;
574 unsigned long vendor;
575 unsigned short channelcount;
576 unsigned short samplesize;
577 short compression_id;
578 unsigned short reserved;
579 unsigned long samplerate;
581 unsigned long samples_per_packet;
582 unsigned long bytes_per_packet;
583 unsigned long bytes_per_frame;
584 unsigned long bytes_per_sample;
586 spMp4DataOnlyBox *frma;
587 spMp4DataOnlyBox *esds;
588 spMp4DataOnlyBox *alac;
589} spMp4AudioSampleEntry;
591typedef struct _spMp4AudioV2SampleEntry {
592 unsigned short version;
593 unsigned short revision;
594 unsigned long vendor;
595 unsigned short always3;
596 unsigned short always16;
598 unsigned short always0;
599 unsigned long always65536;
601 unsigned long sizeOfStructOnly;
602 double audioSampleRate;
603 unsigned long numAudioChannels;
604 unsigned long always7F000000;
605 unsigned long constBitsPerChannels;
606 unsigned long formatSpecificFlags;
607 unsigned long constBytesPerAudioPacket;
608 unsigned long constLPCMFramesPerAudioPacket;
610 spMp4DataOnlyBox *frma;
611 spMp4DataOnlyBox *esds;
612 spMp4DataOnlyBox *alac;
613} spMp4AudioV2SampleEntry;
615typedef struct _spMp4TimecodeSampleEntry {
616 unsigned long reserved;
618 unsigned long timescale;
619 unsigned long frame_duration;
620 unsigned char number_of_frames;
621 unsigned char reserved2;
623 spMp4DataOnlyBox *name;
624} spMp4TimecodeSampleEntry;
626typedef struct _spMp4SampleEntryBox {
627 struct _spMp4Box *parent;
628 struct _spMp4Box *child;
630 struct _spMp4Box *prev;
631 struct _spMp4Box *next;
635 spMp4BoxHeader header;
637 unsigned char reserved[6];
638 unsigned short data_reference_index;
641 spMp4AudioSampleEntry soun;
642 spMp4VisualSampleEntry vide;
643 spMp4DataSampleEntry hint;
644 spMp4RtpHintSampleEntry rtp;
645 spMp4XMLMetaDataSampleEntry metx;
646 spMp4TextMetaDataSampleEntry mett;
647 spMp4TimecodeSampleEntry tmcd;
648 spMp4DataSampleEntry data;
650} spMp4SampleEntryBox;
652typedef struct _spMp4TimeToSampleEntry {
653 unsigned long sample_count;
654 unsigned long sample_delta;
655} spMp4TimeToSampleEntry;
657typedef struct _spMp4TimeToSampleBox {
658 struct _spMp4SampleTableBox *parent;
659 struct _spMp4Box *child;
661 struct _spMp4Box *prev;
662 struct _spMp4Box *next;
666 spMp4BoxHeader header;
668 unsigned long alloc_count;
669 unsigned long entry_count;
670 spMp4TimeToSampleEntry *entries;
672 unsigned long total_sample;
673#ifdef SP_SUPPORT_64BIT_INT
674 spLong64 total_duration;
676 char total_duration[8];
678} spMp4TimeToSampleBox;
680typedef struct _spMp4SampleToChunkEntry {
681 unsigned long first_chunk;
682 unsigned long samples_per_chunk;
683 unsigned long sample_description_index;
684} spMp4SampleToChunkEntry;
686typedef struct _spMp4SampleToChunkBox {
687 struct _spMp4SampleTableBox *parent;
688 struct _spMp4Box *child;
690 struct _spMp4Box *prev;
691 struct _spMp4Box *next;
695 spMp4BoxHeader header;
697 unsigned long alloc_count;
698 unsigned long entry_count;
699 spMp4SampleToChunkEntry *entries;
700} spMp4SampleToChunkBox;
702typedef struct _spMp4CompositionOffsetEntry {
703 unsigned long sample_count;
704 unsigned long sample_offset;
705} spMp4CompositionOffsetEntry;
707typedef struct _spMp4CompositionOffsetBox {
708 struct _spMp4SampleTableBox *parent;
709 struct _spMp4Box *child;
711 struct _spMp4Box *prev;
712 struct _spMp4Box *next;
716 spMp4BoxHeader header;
718 unsigned long alloc_count;
719 unsigned long entry_count;
720 spMp4CompositionOffsetEntry *entries;
721} spMp4CompositionOffsetBox;
723typedef struct _spMp4ChunkOffsetBox {
724 struct _spMp4SampleTableBox *parent;
725 struct _spMp4Box *child;
727 struct _spMp4Box *prev;
728 struct _spMp4Box *next;
732 spMp4BoxHeader header;
734 unsigned long alloc_count;
735 unsigned long entry_count;
736 spFileOffset *chunk_offset;
737} spMp4ChunkOffsetBox;
739typedef struct _spMp4SyncSampleBox {
740 struct _spMp4SampleTableBox *parent;
741 struct _spMp4Box *child;
743 struct _spMp4Box *prev;
744 struct _spMp4Box *next;
748 spMp4BoxHeader header;
750 unsigned long alloc_count;
751 unsigned long entry_count;
752 unsigned long *sample_number;
755typedef struct _spMp4ShadowSyncSampleEntry {
756 unsigned long shadowed_sample_number;
757 unsigned long sync_sample_number;
758} spMp4ShadowSyncSampleEntry;
760typedef struct _spMp4ShadowSyncSampleBox {
761 struct _spMp4SampleTableBox *parent;
762 struct _spMp4Box *child;
764 struct _spMp4Box *prev;
765 struct _spMp4Box *next;
769 spMp4BoxHeader header;
771 unsigned long alloc_count;
772 unsigned long entry_count;
773 spMp4ShadowSyncSampleEntry *entries;
774} spMp4ShadowSyncSampleBox;
776typedef struct _spMp4SampleDescriptionBox {
777 struct _spMp4SampleTableBox *parent;
778 struct _spMp4Box *child;
780 struct _spMp4Box *prev;
781 struct _spMp4Box *next;
785 spMp4BoxHeader header;
787 unsigned long alloc_count;
788 unsigned long entry_count;
789 spMp4SampleEntryBox *entries;
790 unsigned long end_marker_size;
791} spMp4SampleDescriptionBox;
793typedef struct _spMp4SampleDependencyTypeBox {
794 struct _spMp4SampleTableBox *parent;
795 struct _spMp4Box *child;
797 struct _spMp4Box *prev;
798 struct _spMp4Box *next;
802 spMp4BoxHeader header;
804 unsigned long entry_count;
805 unsigned char *entries;
806} spMp4SampleDependencyTypeBox;
808typedef struct _spMp4DegradationPriorityBox {
809 struct _spMp4SampleTableBox *parent;
810 struct _spMp4Box *child;
812 struct _spMp4Box *prev;
813 struct _spMp4Box *next;
817 spMp4BoxHeader header;
819 unsigned long entry_count;
820 unsigned short *priority;
821} spMp4DegradationPriorityBox;
823typedef struct _spMp4SampleSizeBox {
824 struct _spMp4SampleTableBox *parent;
825 struct _spMp4Box *child;
827 struct _spMp4Box *prev;
828 struct _spMp4Box *next;
832 spMp4BoxHeader header;
834 unsigned long sample_size;
835 unsigned char field_size;
837 unsigned long alloc_count;
838 unsigned long entry_count;
840 unsigned long *entries;
843typedef struct _spMp4SampleTableBox {
844 struct _spMp4MediaInformationBox *parent;
845 struct _spMp4Box *child;
847 struct _spMp4Box *prev;
848 struct _spMp4Box *next;
852 spMp4BoxHeader header;
854 spMp4SampleDescriptionBox *stsd;
855 spMp4TimeToSampleBox *stts;
856 spMp4CompositionOffsetBox *ctts;
857 spMp4SampleToChunkBox *stsc;
859 spMp4SampleSizeBox *stsz;
860 spMp4ChunkOffsetBox *stco;
861 spMp4SyncSampleBox *stss;
862 spMp4ShadowSyncSampleBox *stsh;
863 spMp4DegradationPriorityBox *stdp;
864 spMp4SampleDependencyTypeBox *sdtp;
865} spMp4SampleTableBox;
867typedef struct _spMp4DataReferenceBox {
868 struct _spMp4DataInformationBox *parent;
869 struct _spMp4Box *child;
871 struct _spMp4Box *prev;
872 struct _spMp4Box *next;
876 spMp4BoxHeader header;
878 unsigned long entry_count;
879} spMp4DataReferenceBox;
881typedef struct _spMp4DataInformationBox {
882 struct _spMp4MediaInformationBox *parent;
883 struct _spMp4Box *child;
885 struct _spMp4Box *prev;
886 struct _spMp4Box *next;
890 spMp4BoxHeader header;
892 spMp4DataReferenceBox *dref;
893} spMp4DataInformationBox;
895typedef struct _spMp4MediaInformationBox {
896 struct _spMp4MediaBox *parent;
897 struct _spMp4Box *child;
899 struct _spMp4Box *prev;
900 struct _spMp4Box *next;
904 spMp4BoxHeader header;
907 spMp4VideoMediaHeaderBox *vmhd;
908 spMp4SoundMediaHeaderBox *smhd;
909 spMp4HintMediaHeaderBox *hmhd;
910 spMp4NullMediaHeaderBox *nmhd;
913 spMp4DataInformationBox *dinf;
914 spMp4SampleTableBox *stbl;
915 spMp4HandlerReferenceBox *hdlr;
916} spMp4MediaInformationBox;
918typedef struct _spMp4MediaBox {
919 struct _spMp4TrackBox *parent;
920 struct _spMp4Box *child;
922 struct _spMp4Box *prev;
923 struct _spMp4Box *next;
927 spMp4BoxHeader header;
929 spMp4MediaHeaderBox *mdhd;
931 spMp4HandlerReferenceBox *hdlr;
932 spMp4MediaInformationBox *minf;
933 spMp4UserDataBox *udta;
936typedef struct _spMp4TrackReferenceBox {
937 struct _spMp4TrackBox *parent;
938 struct _spMp4Box *child;
940 struct _spMp4Box *prev;
941 struct _spMp4Box *next;
945 spMp4BoxHeader header;
947 spMp4BoxHeader reference_type;
948 unsigned long *track_ids;
949} spMp4TrackReferenceBox;
951typedef struct _spMp4EditListEntryV0 {
952 unsigned long segment_duration;
954 unsigned long media_rate;
955} spMp4EditListEntryV0;
957typedef struct _spMp4EditListEntryV1 {
958#ifdef SP_SUPPORT_64BIT_INT
959 spULong64 segment_duration;
962 char segment_duration[8];
965 unsigned long media_rate;
966} spMp4EditListEntryV1;
968typedef struct _spMp4EditListBox {
969 struct _spMp4Box *parent;
970 struct _spMp4Box *child;
972 struct _spMp4Box *prev;
973 struct _spMp4Box *next;
977 spMp4BoxHeader header;
979 unsigned long alloc_count;
980 unsigned long entry_count;
982 spMp4EditListEntryV0 *edit_list_table_v0;
983 spMp4EditListEntryV1 *edit_list_table_v1;
987typedef struct _spMp4MetaBox {
988 struct _spMp4Box *parent;
989 struct _spMp4Box *child;
991 struct _spMp4Box *prev;
992 struct _spMp4Box *next;
996 spMp4BoxHeader header;
998 spMp4HandlerReferenceBox *hdlr;
1000 spMp4ULongOnlyBox *mhdr;
1002 spMp4CountryListBox *ctry;
1003 spMp4LanguageListBox *lang;
1006typedef struct _spMp4TrackBox {
1007 struct _spMp4MovieBox *parent;
1008 struct _spMp4Box *child;
1010 struct _spMp4Box *prev;
1011 struct _spMp4Box *next;
1013 spFileOffset offset;
1015 spMp4BoxHeader header;
1017 spMp4TrackHeaderBox *tkhd;
1019 spMp4DataOnlyBox *clip;
1022 spMp4TrackReferenceBox *tref;
1023 spMp4DataOnlyBox *load;
1026 spMp4MediaBox *mdia;
1027 spMp4UserDataBox *udta;
1030typedef struct _spMp4MovieBox {
1031 struct _spMp4Box *parent;
1032 struct _spMp4Box *child;
1034 struct _spMp4Box *prev;
1035 struct _spMp4Box *next;
1037 spFileOffset offset;
1039 spMp4BoxHeader header;
1041 spMp4MovieHeaderBox *mvhd;
1042 spMp4TrackBox *trak;
1043 spMp4UserDataBox *udta;
1046typedef struct _spMp4Header {
1047 struct _spMp4Box *parent;
1048 struct _spMp4Box *child;
1050 struct _spMp4Box *prev;
1051 struct _spMp4Box *next;
1053 spFileOffset offset;
1055 spMp4BoxHeader header;
1057 spMp4FileTypeBox *ftyp;
1058 spMp4MovieBox *moov;
1059 struct _spMp4Box *mdat;
1062typedef spMp4BoxSize (*spMp4BoxUpdateFunc)(spMp4Box *box,
void *data);
1064extern unsigned short spGetMp4LangCode(
const char *lang);
1065extern void spGetMp4LangStr(
unsigned short code,
char *lang,
int lang_size);
1067extern spBool spEqMp4BoxType(spMp4Box *box,
const char *type);
1069extern spMp4BoxSize spGetMp4BoxContentMarginSize(spMp4Box *box);
1070extern spBool spSetMp4BoxContentMarginSize(spMp4Box *box, spMp4BoxSize marginsize);
1071extern spBool spSetMp4BoxHeaderContentSize(spMp4BoxHeader *box_header, spMp4BoxSize size);
1072extern spBool spSetMp4BoxContentSize(spMp4Box *box, spMp4BoxSize size,
spBool propagate_size);
1073extern spMp4BoxSize spGetMp4BoxHeaderContentSize(spMp4BoxHeader *box_header);
1074extern spMp4BoxSize spGetMp4BoxHeaderBoxSize(spMp4BoxHeader *box_header);
1075extern spMp4BoxSize spGetMp4BoxHeaderSize(spMp4Box *box);
1077extern spMp4BoxSize spGetMp4BoxSize(spMp4Box *box,
char *
string);
1078extern spMp4BoxSize spGetMp4BoxContentSize(spMp4Box *box,
char *
string);
1080extern spBool spGetMp4BoxHandleType(spMp4Box *box,
char *type);
1082extern spMp4BoxSize spUpdateMp4ULongOnlyBox(spMp4ULongOnlyBox *ulobox,
unsigned long value);
1083extern spMp4Box *spAppendMp4ULongOnlyBox(spMp4Box *parent,
const char *type,
unsigned long value);
1085extern spMp4BoxSize spUpdateMp4DataOnlyBox(spMp4DataOnlyBox *dobox,
const char *data, spMp4BoxSize size,
spBool propagate_size);
1086extern spMp4Box *spAppendMp4DataOnlyBox(spMp4Box *parent,
const char *type,
const char *data, spMp4BoxSize size);
1088extern spMp4MetaBox *spAppendMp4UserDataMetaBox(spMp4Box *parent, spMp4BoxSize meta_size,
const char *handler_type,
const char *handler_name);
1090extern spMp4BoxSize spUpdateMp4UserDataStringBox(spMp4UserDataStringBox *udsbox,
short language,
const char *
string,
spBool propagate_size);
1091extern spMp4Box *spAppendMp4UserDataStringBox(spMp4Box *parent,
const char *type,
short language,
const char *
string);
1094extern spMp4BoxSize spUpdateMp4MetaDataValueBox(spMp4MetaDataValueBox *databox,
1095 unsigned long type_indicator,
unsigned short country,
unsigned short language,
1096 const char *value, spMp4BoxSize value_size,
spBool propagate_size);
1097extern spMp4MetaDataValueBox *spAppendMp4MetaDataValueBox(spMp4Box *parent,
const char *type,
unsigned long type_indicator,
1098 unsigned short country,
unsigned short language,
1099 const char *value, spMp4BoxSize value_size);
1100extern spMp4MetaDataValueBox *spAppendMp4MetaDataUTF8String(spMp4MetaBox *meta,
const char *type,
1101 unsigned short country,
unsigned short language,
const char *utf8str);
1102extern spMp4MetaDataValueBox *spAppendMp4MetaDataUTF8StringFromLocaleCode(spMp4MetaBox *meta,
const char *type,
1103 unsigned short country,
unsigned short language,
const unsigned char *str_in_locale);
1105extern spBool spParseMp4MetaDataUTF8StringToLocaleCode(spMp4MetaDataValueBox *databox,
unsigned char *str_in_locale,
long size);
1106extern char *xspParseMp4MetaDataUTF8StringToLocaleCode(spMp4MetaDataValueBox *databox);
1107extern const char *spGetMp4MetaDataUTF8String(spMp4MetaBox *meta,
const char *type);
1108extern spBool spGetMp4MetaDataUTF8StringToLocaleCode(spMp4MetaBox *meta,
const char *type,
unsigned char *str_in_locale,
long size);
1109extern char *xspGetMp4MetaDataUTF8StringToLocaleCode(spMp4MetaBox *meta,
const char *type);
1111extern unsigned long spParseMp4MetaDataBESignedInt(spMp4MetaDataValueBox *databox,
long *number);
1112extern unsigned long spParseMp4MetaDataBEUnsignedInt(spMp4MetaDataValueBox *databox,
unsigned long *number);
1113extern spBool spGetMp4MetaDataTempo(spMp4MetaBox *meta,
long *tempo);
1114extern spBool spGetMp4MetaDataBoolean(spMp4MetaBox *meta,
const char *type,
spBool *flag);
1115extern spBool spGetMp4MetaDataGapless(spMp4MetaBox *meta,
spBool *flag);
1116extern spBool spGetMp4MetaDataCompilation(spMp4MetaBox *meta,
spBool *flag);
1117extern spMp4MetaDataValueBox *spAppendMp4MetaDataBESignedInt(spMp4MetaBox *meta,
const char *type,
long number,
unsigned long size);
1118extern spMp4MetaDataValueBox *spAppendMp4MetaDataBEUnsignedInt(spMp4MetaBox *meta,
const char *type,
unsigned long number,
unsigned long size);
1119extern spMp4MetaDataValueBox *spAppendMp4MetaDataTempo(spMp4MetaBox *meta,
long tempo);
1120extern spMp4MetaDataValueBox *spAppendMp4MetaDataBoolean(spMp4MetaBox *meta,
const char *type,
spBool flag);
1121extern spMp4MetaDataValueBox *spAppendMp4MetaDataGapless(spMp4MetaBox *meta,
spBool flag);
1122extern spMp4MetaDataValueBox *spAppendMp4MetaDataCompilation(spMp4MetaBox *meta,
spBool flag);
1124extern spBool spParseMp4MetaDataTrackNumber(spMp4MetaDataValueBox *databox,
unsigned short *number,
unsigned short *total);
1125extern spBool spParseMp4MetaDataDiscNumber(spMp4MetaDataValueBox *databox,
unsigned short *number,
unsigned short *total);
1126extern spBool spGetMp4MetaDataTrackNumber(spMp4MetaBox *meta,
unsigned short *number,
unsigned short *total);
1127extern spBool spGetMp4MetaDataDiscNumber(spMp4MetaBox *meta,
unsigned short *number,
unsigned short *total);
1128extern spMp4MetaDataValueBox *spAppendMp4MetaDataTrackNumber(spMp4MetaBox *meta,
unsigned short number,
unsigned short total);
1129extern spMp4MetaDataValueBox *spAppendMp4MetaDataDiscNumber(spMp4MetaBox *meta,
unsigned short number,
unsigned short total);
1132extern unsigned long spAppendMp4ShadowSyncSample(spMp4ShadowSyncSampleBox *stsh,
1133 unsigned long shadowed_sample_number,
unsigned long sync_sample_number);
1136extern unsigned long spAppendMp4SyncSample(spMp4SyncSampleBox *stss,
unsigned long sample);
1139unsigned long spAppendMp4ChunkOffset(spMp4ChunkOffsetBox *stco, spFileOffset offset);
1142extern unsigned long spGetMp4SampleSize(spMp4SampleSizeBox *stsz,
unsigned long sample);
1143extern spBool spSetMp4SampleSize(spMp4SampleSizeBox *stsz,
unsigned long sample,
unsigned long size);
1144extern unsigned long spAppendMp4SampleSize(spMp4SampleSizeBox *stsz,
unsigned long size);
1147extern unsigned long spAppendMp4SampleToChunk(spMp4SampleToChunkBox *stsc,
1148 unsigned long chunk ,
unsigned long samples_per_chunk,
unsigned long sample_description_index);
1151extern unsigned long spGetMp4SampleDuration(spMp4TimeToSampleBox *stts,
unsigned long sample);
1152extern unsigned long spGetMp4MaxSampleDuration(spMp4TimeToSampleBox *stts);
1153extern unsigned long spAppendMp4SampleDuration(spMp4TimeToSampleBox *stts,
unsigned long sample,
unsigned long sample_delta);
1156extern spMp4SampleEntryBox *spAppendMp4SampleDescriptionEntry(spMp4SampleDescriptionBox *stsd,
const char *codingname,
unsigned short data_reference_index);
1159extern spMp4BoxSize spUpdateMp4VideoMediaHeaderBox(spMp4VideoMediaHeaderBox *vmhd,
unsigned short graphicsmode,
unsigned short opcolor[3]);
1161extern spMp4BoxSize spUpdateMp4SoundMediaHeaderBox(spMp4SoundMediaHeaderBox *smhd,
unsigned short balance);
1163extern spMp4BoxSize spUpdateMp4HintMediaHeaderBox(spMp4HintMediaHeaderBox *hmhd,
unsigned short maxPDUSize,
unsigned short avgPDUSize,
1164 unsigned long maxBitRate,
unsigned long avgBitRate);
1167extern spMp4BoxSize spUpdateMp4KeysBox(spMp4KeysBox *keys, spMp4KeyEntry *entries,
long count,
spBool propagate_size);
1170extern spMp4BoxSize spUpdateMp4HandlerReferenceBox(spMp4HandlerReferenceBox *hdlr,
const char *handler_type,
const char *name,
spBool propagate_size);
1173extern spMp4BoxSize spUpdateMp4MediaHeaderBoxV0(spMp4MediaHeaderBox *mdhd,
1174 time_t creation_time, time_t modification_time,
1175 unsigned long timescale,
unsigned long duration,
1176 unsigned short language,
unsigned short quality);
1177#ifdef SP_SUPPORT_64BIT_INT
1178extern spMp4BoxSize spUpdateMp4MediaHeaderBoxV1(spMp4MediaHeaderBox *mdhd,
1179 time_t creation_time, time_t modification_time,
1180 unsigned long timescale, spLong64 duration,
1181 unsigned short language,
unsigned short quality);
1185extern spMp4Box *spAppendMp4DataReferenceEntry(spMp4DataReferenceBox *dref,
const char *type,
const char *data,
long size);
1188extern spMp4BoxSize spUpdateMp4TrackReferenceBox(spMp4TrackReferenceBox *tref,
const char *reference_type,
1189 unsigned long *track_ids,
long count,
spBool propagate_size);
1192extern spMp4BoxSize spUpdateMp4TrackHeaderBoxV0(spMp4TrackHeaderBox *tkhd,
unsigned long flags,
1193 time_t creation_time, time_t modification_time,
1194 unsigned long track_id,
unsigned long duration,
1195 short layer,
short alternate_group,
short volume,
long matrix[9],
1196 unsigned long width,
unsigned long height);
1197#ifdef SP_SUPPORT_64BIT_INT
1198extern spMp4BoxSize spUpdateMp4TrackHeaderBoxV1(spMp4TrackHeaderBox *tkhd,
unsigned long flags,
1199 time_t creation_time, time_t modification_time,
1200 unsigned long track_id, spLong64 duration,
1201 short layer,
short alternate_group,
short volume,
long matrix[9],
1202 unsigned long width,
unsigned long height);
1206extern spMp4BoxSize spUpdateMp4MovieHeaderBoxV0(spMp4MovieHeaderBox *mvhd,
1207 time_t creation_time, time_t modification_time,
1208 unsigned long timescale,
unsigned long duration,
1209 long rate,
short volume,
long matrix[9],
unsigned long next_track_id);
1210#ifdef SP_SUPPORT_64BIT_INT
1211extern spMp4BoxSize spUpdateMp4MovieHeaderBoxV1(spMp4MovieHeaderBox *mvhd,
1212 time_t creation_time, time_t modification_time,
1213 unsigned long timescale, spLong64 duration,
1214 long rate,
short volume,
long matrix[9],
unsigned long next_track_id);
1218extern spMp4BoxSize spUpdateMp4FileTypeBox(spMp4FileTypeBox *ftypbox,
const char *major_brand,
long minor_version,
1219 long nbrands,
const char *compatible_brands);
1221extern void spPropagateMp4BoxContentSize(spMp4Box *parent, spChunkSize size_diff);
1223extern spMp4BoxSize spReadMp4Header(spMp4Header *header, FILE *fp);
1224extern spBool spFreeMp4Header(spMp4Header *header);
1225extern spBool spInitMp4HeaderWithCB(spMp4Header *header, spMp4BoxUpdateFunc update_func,
void *data);
1226extern spBool spInitMp4Header(spMp4Header *header,
const char *major_brand,
long minor_version,
1227 long nbrands,
const char *compatible_brands);
1229extern spMp4BoxSize spWriteMp4Header(spMp4Header *header, spMp4BoxSize moov_size, spMp4Box **paused_box, FILE *fp);
1230extern spMp4BoxSize spRewriteMp4Header(spMp4Header *header, spMp4BoxSize mdat_size, spMp4Box **paused_box, FILE *fp);
1232extern spMp4BoxSize spCopyMp4Header(spMp4Header *dest_header, spMp4Header *src_header);
1234extern spMp4Box *spCreateMp4BoxWithCB(spMp4Box *parent,
const char *type, spMp4BoxUpdateFunc update_func,
void *data);
1235extern spMp4Box *spCreateMp4Box(spMp4Box *parent,
const char *type);
1237extern spMp4Box *spFindMp4BoxFromHeader(spMp4Header *header,
const char *type,
const char *parent_type);
1238extern spMp4Box *spFindMp4Box(spMp4Box *box,
const char *type,
const char *parent_type);
1239extern spMp4TrackBox *spFindMp4TrackBox(spMp4Header *header,
long index,
const char *handler_type);
1240extern unsigned long spGetMp4MaxTrackId(spMp4Header *header);
1241extern spMp4SampleTableBox *spGetMp4TrackSampleTableBox(spMp4TrackBox *trak);
1242extern spMp4SampleEntryBox *spGetMp4TrackSampleEntryBox(spMp4TrackBox *trak,
unsigned long index);
1244extern spMp4TrackBox *spAppendMp4SoundTrackBox(spMp4Header *header,
unsigned long track_id,
1245 const char *codingname,
unsigned short data_reference_index,
1246 unsigned short channelcount,
unsigned short samplesize,
1247 short compression_id,
double samplerate,
char stz2_field_size,
spBool co64_flag,
1248 spMp4BoxUpdateFunc update_func,
void *data);
1250extern spFileOffset spGetMp4MdatContentOffset(spMp4Header *header);
1251extern unsigned long spConvertMp4TimeToSample(spMp4TimeToSampleBox *stts, spULong t,
unsigned long *remainder);
1252extern unsigned long spConvertMp4ChunkToSample(spMp4SampleToChunkBox *stsc,
unsigned long chunk ,
1253 unsigned long *samples_per_chunk,
unsigned long *description_index);
1255extern unsigned long spConvertMp4SampleToChunk(spMp4SampleToChunkBox *stsc,
unsigned long description_index,
unsigned long sample,
1256 unsigned long *remainder);
1257extern spFileOffset spConvertMp4SampleToFileOffset(spMp4SampleToChunkBox *stsc,
unsigned long description_index,
unsigned long sample,
1258 unsigned long *chunk,
unsigned long *remainder,
unsigned long *sample_size);
1259extern spMp4TrackBox *spFindMp4NextChunkFromFileOffset(spMp4Header *header, spFileOffset offset,
1260 spFileOffset *o_offset,
unsigned long *chunk );
1265extern void spShowMp4HeaderInfo(spMp4Header *header);
1267extern void spConvMp4MatrixToDouble(
long *imatrix,
double *omatrix);
1268extern void spConvDoubleMatrixToMp4(
double *imatrix,
long *omatrix);
1269extern void spMultMp4MatrixToXY(
long *matrix,
long *x,
long *y);
1270extern void spMultMp4MatrixToXYZ(
long *matrix,
long *x,
long *y,
long *z);