Chris@634
|
1 //***********************************************************//
|
Chris@634
|
2 // Interactive Music Audio Format (IMAF) ENCODER //
|
Chris@634
|
3 // Version 2.0 //
|
Chris@634
|
4 // //
|
Chris@634
|
5 // Eugenio Oñate Hospital //
|
Chris@634
|
6 // Jesús Corral García & Costantino Taglialatela //
|
Chris@634
|
7 // //
|
Chris@634
|
8 // Copyright (c) 2013 Centre for Digital Music (C4DM) //
|
Chris@634
|
9 // Queen Mary University of London. All rights reserved. //
|
Chris@634
|
10 //***********************************************************//
|
Chris@634
|
11 // main.c //
|
Chris@634
|
12 //***********************************************************//
|
Chris@634
|
13
|
Chris@634
|
14 //File input/output
|
Chris@634
|
15 #include <stdio.h>
|
Chris@634
|
16 //Standard library: numeric conversion, memory allocation...
|
Chris@634
|
17 #include <stdlib.h>
|
Chris@634
|
18 //Operations with strings
|
Chris@634
|
19 #include <string.h>
|
Chris@634
|
20 //Get the creation time: clock
|
Chris@634
|
21 #include <time.h>
|
Chris@634
|
22 #include "IMAFencoder.h"
|
Chris@634
|
23 //Qt libraries
|
Chris@634
|
24 #include <QTextStream>
|
Chris@634
|
25 #include <QMessageBox>
|
Chris@634
|
26 #include <QByteArray>
|
Chris@634
|
27
|
Chris@634
|
28
|
Chris@634
|
29 /*Prototype*/
|
Chris@634
|
30 void filetypebx(FileTypeBox *ftyp);
|
Chris@634
|
31 int mdatbox(MediaDataBox *mdat, int, FILE *imf, FILE *song, FILE *text, int, int, u32);
|
Chris@634
|
32 void moovheaderbox(MovieBox *moov, int, int, int, int, int, int, int);
|
Chris@634
|
33 int trackstructure(MovieBox *moov, int, int, int, int,const char *name);
|
Chris@634
|
34 int samplecontainer(MovieBox *moov, int, int, const char *name);
|
Chris@634
|
35 int sampledescription(MovieBox *moov, int);
|
Chris@634
|
36 int presetcontainer(MovieBox *moov, int, int *vol_values, int type, int fade_in);
|
Chris@634
|
37 int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
|
Chris@634
|
38 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4);
|
Chris@636
|
39 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile);
|
Chris@634
|
40 int readTrack(MovieBox *moov, int,const char *name);
|
Chris@634
|
41
|
Chris@634
|
42 // Timed Text Functions
|
Chris@634
|
43 int trackstructure_text (MovieBox *moov, int numtrack, int clock, int durationTrack, int sizemdat,const char *textfile,FILE *text,int totaltracks);
|
Chris@634
|
44 int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat, const char *textfiles,int totaltracks);
|
Chris@634
|
45 int aux (FILE *text,int num,int num1,int num2,int num3,int *sal);
|
Chris@634
|
46 int getTextSize (FILE *text);
|
Chris@634
|
47 // Group and Preset functions
|
Chris@634
|
48 int groupcontainer(MovieBox *moov, int *group_tracks, int grp_vol, QString grp_name,
|
Chris@634
|
49 QString grp_description, int totaltracks);
|
Chris@634
|
50 void writepresets(MovieBox moov, int numtrack,int totaltracks, FILE *imf); // NOT YET USED
|
Chris@634
|
51
|
Chris@634
|
52 // MetaData and JPEG Image functions
|
Chris@634
|
53 int metacontainer (MetaBox *meta);
|
Chris@634
|
54 u32 getImageSize(const char *imag);
|
Chris@634
|
55 void insertImage (MetaBox *meta, FILE **imf, u32 imagesize, const char *imagedir);
|
Chris@634
|
56 void writemetabox(MetaBox meta, FILE *imf);
|
Chris@634
|
57
|
Chris@634
|
58 int bytereverse(int num);
|
Chris@634
|
59 int bytereverse16(int num);
|
Chris@634
|
60 int size_phrase[1000];//the total number of bytes in a phrase including modifiers
|
Chris@634
|
61 int phrases;//the number of phrases in the whole text
|
Chris@634
|
62
|
Chris@634
|
63
|
Chris@634
|
64 // Qt Widget for the "Exit Window"
|
Chris@634
|
65 class ExitWindow : public QWidget
|
Chris@634
|
66 {
|
Chris@634
|
67 public:
|
Chris@634
|
68 ExitWindow();
|
Chris@634
|
69 private:
|
Chris@634
|
70 QMessageBox *file_created;
|
Chris@634
|
71 };
|
Chris@634
|
72
|
Chris@634
|
73 ExitWindow::ExitWindow()
|
Chris@634
|
74 {
|
Chris@634
|
75 file_created = new QMessageBox();
|
Chris@634
|
76 file_created->setFixedSize(400,200); // doesn't seem to work
|
Chris@634
|
77 file_created->setWindowTitle("IM AF Encoder");
|
Chris@634
|
78 file_created->setText("IM AF file successfully created!");
|
Chris@634
|
79 file_created->show();
|
Chris@634
|
80 }
|
Chris@634
|
81
|
Chris@634
|
82 int mainIMAFencoder (int totaltracks, QString files_path[maxtracks],QString outimaf,
|
Chris@634
|
83 QString picturefile, QString textfile, int vol_values[maxtracks], bool HasImageFile,
|
Chris@636
|
84 bool HasTextFile, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
|
Chris@634
|
85 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4,
|
Chris@634
|
86 int group_tracks[maxtracks], int group_volume, QString group_name, QString group_description,
|
Chris@634
|
87 int pres_type, int fade_in)
|
Chris@634
|
88 {
|
Chris@634
|
89 //Variables
|
Chris@634
|
90 FileTypeBox ftyp;
|
Chris@634
|
91 MediaDataBox mdat;
|
Chris@634
|
92 MovieBox moov;
|
Chris@634
|
93 MetaBox meta;
|
Chris@634
|
94
|
Chris@634
|
95 //Media Data Box - Contains the audio
|
Chris@634
|
96 FILE *song; //MP3
|
Chris@634
|
97 u32 sizeTRAK = 0;
|
Chris@634
|
98 int numtr;
|
Chris@634
|
99 //Output File
|
Chris@634
|
100 FILE *imf; //IMA
|
Chris@634
|
101 int numtrack, sizemdat, durationTrack;
|
Chris@634
|
102 //Image
|
Chris@634
|
103 u32 imagesize;
|
Chris@634
|
104 QTextStream out (stdout);
|
Chris@634
|
105 //Timed-Text
|
Chris@634
|
106 FILE *text;
|
Chris@634
|
107 int sizetext;
|
Chris@634
|
108 const char *c_str1[8];//change this value to support more than 8 audio tracks
|
Chris@634
|
109 const char *c_str2;
|
Chris@634
|
110
|
Chris@634
|
111 //Groups, Presets, Rules and Metadata boxes sizes
|
Chris@634
|
112 u32 sizeGRCO, sizePRCO, sizeRUCO, sizeMETA;
|
Chris@634
|
113
|
Chris@634
|
114 /* Obtain current time as seconds elapsed since the Epoch. */
|
Chris@634
|
115 time_t clock = time(NULL);
|
Chris@634
|
116
|
Chris@634
|
117
|
Chris@634
|
118 //INPUT: Image
|
Chris@634
|
119 if (HasImageFile){
|
Chris@634
|
120 c_str2= picturefile.toStdString().c_str(); //convert QString to const char
|
Chris@634
|
121 imagesize = getImageSize(c_str2);//calculate the size of the jpeg
|
Chris@634
|
122 } else { //if there is no image, the size is 0
|
Chris@634
|
123 imagesize = 0;
|
Chris@634
|
124 }
|
Chris@634
|
125
|
Chris@634
|
126 //INPUT: Timed-Text
|
Chris@636
|
127 if (HasTextFile){
|
Chris@636
|
128 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
|
Chris@636
|
129 text = fopen(c_str2, "rb");
|
Chris@636
|
130 sizetext= getTextSize (text); //calculate the size of the text
|
Chris@636
|
131 }
|
Chris@636
|
132 else{
|
Chris@636
|
133 sizetext = 0;
|
Chris@636
|
134 }
|
Chris@634
|
135 //Create OUTPUT file (.ima)
|
Chris@634
|
136 imf = fopen (outimaf.toStdString().c_str(),"wb");
|
Chris@634
|
137
|
Chris@634
|
138 //Define the File Type Box
|
Chris@634
|
139 filetypebx(&ftyp);
|
Chris@634
|
140 fwrite(&ftyp, sizeof(FileTypeBox),1, imf);
|
Chris@634
|
141 //AUDIO
|
Chris@634
|
142 //Put the tracks in Media Data Box
|
Chris@634
|
143 for (numtr=0; numtr<totaltracks; numtr++) {
|
Chris@634
|
144 c_str1[numtr]= files_path[numtr].toStdString().c_str(); //convert Qstring to const char
|
Chris@634
|
145 song = fopen(c_str1[numtr], "rb");
|
Chris@634
|
146
|
Chris@634
|
147 //Extract the samples from the audio file and the text
|
Chris@634
|
148 sizemdat = mdatbox(&mdat, totaltracks, imf, song, text, numtr, sizetext, imagesize);//sizemdat is the size of one audio track
|
Chris@634
|
149
|
Chris@634
|
150 fclose(song); //Close the audio file
|
Chris@634
|
151 }//close for
|
Chris@634
|
152
|
Chris@634
|
153 //For each track write track information
|
Chris@634
|
154 durationTrack = (sizemdat*8)/128;
|
Chris@634
|
155
|
Chris@634
|
156 for (numtrack = 0; numtrack < totaltracks; numtrack++) {
|
Chris@634
|
157 c_str1[numtrack]= files_path[numtrack].toStdString().c_str(); //convert QString to const char
|
Chris@634
|
158 sizeTRAK = trackstructure(&moov, numtrack, clock, durationTrack,sizemdat,c_str1[numtrack])+ sizeTRAK;
|
Chris@634
|
159 }
|
Chris@634
|
160 //At this point, the variable sizeTRAK will be the sum of the size of the box ´trak´ in all the audio tracks.
|
Chris@634
|
161 //The size of the box trak of the text track will be added after.
|
Chris@634
|
162
|
Chris@634
|
163 if (HasImageFile){
|
Chris@634
|
164 //Meta
|
Chris@634
|
165 sizeMETA = metacontainer(&meta);
|
Chris@634
|
166
|
Chris@634
|
167 //Read the image from the JPEG file and write it in the IMAF file
|
Chris@634
|
168 c_str2= picturefile.toStdString().c_str(); //convert Qstring to const char
|
Chris@634
|
169 insertImage(&meta, &imf, imagesize,c_str2);
|
Chris@634
|
170 }
|
Chris@634
|
171
|
Chris@634
|
172 //Groups
|
Chris@634
|
173 sizeGRCO = groupcontainer(&moov, group_tracks, group_volume, group_name, group_description, totaltracks); //Creates the group, returns the size of the box
|
Chris@634
|
174
|
Chris@634
|
175 //Presets
|
Chris@634
|
176 sizePRCO = presetcontainer(&moov, totaltracks, vol_values, pres_type, fade_in); // Creates the preset, returns the size of the box.
|
Chris@634
|
177
|
Chris@634
|
178 //Rules
|
Chris@634
|
179 sizeRUCO = rulescontainer(&moov, SelRuleType, SelRule_PAR1, SelRule_PAR2,
|
Chris@634
|
180 MixRuleType, MixRule_PAR1, MixRule_PAR2, MixRule_PAR3, MixRule_PAR4); // Creates the rules, returns the size of the box.
|
Chris@634
|
181
|
Chris@634
|
182 //Text track
|
Chris@636
|
183 if (HasTextFile){
|
Chris@636
|
184 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
|
Chris@636
|
185 sizeTRAK = trackstructure_text (&moov, numtrack, clock, durationTrack, sizemdat, c_str2, text, totaltracks) + sizeTRAK;
|
Chris@636
|
186 }
|
Chris@634
|
187 //Movie Header - Overall declarations
|
Chris@634
|
188 moovheaderbox(&moov, clock, sizeTRAK, sizePRCO, totaltracks, durationTrack, sizeRUCO, sizeGRCO); // -> enter sizeGRCO instead of 0
|
Chris@634
|
189
|
Chris@634
|
190 //Writes the movie box into the file
|
Chris@636
|
191 writemoovbox(moov, numtrack, totaltracks, imf, text, HasTextFile);
|
Chris@634
|
192
|
Chris@634
|
193 //Writes the meta box into the IMAF file
|
Chris@634
|
194 if (HasImageFile){
|
Chris@634
|
195 writemetabox(meta,imf);
|
Chris@634
|
196 }
|
Chris@634
|
197
|
Chris@634
|
198 //Close Files and show exit dialog window
|
Chris@634
|
199 fclose(imf);
|
Chris@634
|
200 fclose (text);
|
Chris@634
|
201 ExitWindow *window = new ExitWindow();
|
Chris@634
|
202 }
|
Chris@634
|
203
|
Chris@634
|
204
|
Chris@634
|
205
|
Chris@634
|
206 void filetypebx(FileTypeBox *ftyp){
|
Chris@634
|
207 int swap;
|
Chris@634
|
208
|
Chris@634
|
209 swap = bytereverse(24);// 24 is the size of the box "ftyp"
|
Chris@634
|
210 ftyp->size = swap;
|
Chris@634
|
211 swap = bytereverse('ftyp');
|
Chris@634
|
212 ftyp->type = swap;
|
Chris@634
|
213 swap = bytereverse('im02'); // Conformance point 3 (see ISO/IEC 23000-12:2010/FDAM 1:2011(E))
|
Chris@634
|
214 ftyp->major_brand = swap;
|
Chris@634
|
215 ftyp->minor_version = 0;
|
Chris@634
|
216 swap = bytereverse('im02'); // Conformance point 3 (see ISO/IEC 23000-12:2010/FDAM 1:2011(E))
|
Chris@634
|
217 ftyp->compatible_brands[0] = swap;
|
Chris@634
|
218 swap = bytereverse('isom');
|
Chris@634
|
219 ftyp->compatible_brands[1] = swap;
|
Chris@634
|
220 }
|
Chris@634
|
221
|
Chris@634
|
222 int mdatbox(MediaDataBox *mdat, int totaltracks, FILE *imf, FILE *song, FILE *text, int numtr, int sizetext, u32 imagesize){
|
Chris@634
|
223
|
Chris@634
|
224 int d=0, cnt=0, j, find = 0, sizestring = 0, i = 0,cnt2=0,highlight_end_time=0;
|
Chris@634
|
225 int dat = 0, dat1 = 0, dat2 = 0, dat3 = 0,k=0;
|
Chris@634
|
226 u32 size = 0, swap, sizeMDAT = 0;
|
Chris@634
|
227 unsigned char c1=0,c2=0,numwords=0,initposition[3000],endposition[3000];
|
Chris@634
|
228
|
Chris@634
|
229 //Positionate the pointer at the end of the file to know the size of it
|
Chris@634
|
230 fseek(song, 0, SEEK_END);
|
Chris@634
|
231 size = ftell(song);
|
Chris@634
|
232 //Positionate the pointer at first
|
Chris@634
|
233 fseek(song, 0, SEEK_SET);
|
Chris@634
|
234
|
Chris@634
|
235 initposition[0]=0; // this array saves the position of the first letter of a word in a phrase
|
Chris@634
|
236 phrases=0;// this variable saves the number of phrases in the whole text
|
Chris@634
|
237
|
Chris@634
|
238 //Find the header of the first frame (the beginning), when find it d=1 and jump out the loop.
|
Chris@634
|
239 // The header is 32 bytes. We find in groups of 8 bytes
|
Chris@634
|
240 // Contemplate all possible options of headers
|
Chris@634
|
241 while (d == 0) {
|
Chris@634
|
242 find = 0;
|
Chris@634
|
243 fread(&dat, sizeof(unsigned char), 1, song);
|
Chris@634
|
244 cnt++;
|
Chris@634
|
245
|
Chris@634
|
246 if (dat == 0xFF) {
|
Chris@634
|
247 cnt++; // cnt : stores the position of the pointer.
|
Chris@634
|
248 fread(&dat1, sizeof(unsigned char), 1, song);
|
Chris@634
|
249 cnt++;
|
Chris@634
|
250 fread(&dat2, sizeof(unsigned char), 1, song);
|
Chris@634
|
251 cnt++;
|
Chris@634
|
252 fread(&dat3, sizeof(unsigned char), 1, song);
|
Chris@634
|
253 if (dat1 == 0xFB && dat2 == 146 && dat3 == 64 ) {
|
Chris@634
|
254 find = 1; // find: if the header is found
|
Chris@634
|
255 d=1; // d: jump out the loop
|
Chris@634
|
256 }
|
Chris@634
|
257 if (dat1 == 0xFB && dat2 == 146 && dat3 == 96 ) {
|
Chris@634
|
258 d=1;
|
Chris@634
|
259 find = 1;
|
Chris@634
|
260 }
|
Chris@634
|
261 if (dat1 == 0xFB && dat2 == 144 && dat3 == 64 ) {
|
Chris@634
|
262 find = 1;
|
Chris@634
|
263 d=1;
|
Chris@634
|
264 }
|
Chris@634
|
265 if (dat1 == 0xFB && dat2 == 144 && dat3 == 96 ) {
|
Chris@634
|
266 find = 1;
|
Chris@634
|
267 d=1;
|
Chris@634
|
268 }
|
Chris@634
|
269 if (dat1 == 0xFB && dat2 == 146 && dat3 == 100 ) {
|
Chris@634
|
270 d=1;
|
Chris@634
|
271 find = 1;
|
Chris@634
|
272 }
|
Chris@634
|
273 if (dat1 == 0xFB && dat2 == 144 && dat3 == 100 ) {
|
Chris@634
|
274 find = 1;
|
Chris@634
|
275 d=1;
|
Chris@634
|
276 }
|
Chris@634
|
277 if (dat1 == 0xFA && dat2 == 146 && dat3 == 64 ) {
|
Chris@634
|
278 find = 1;
|
Chris@634
|
279 d=1;
|
Chris@634
|
280 }
|
Chris@634
|
281 if (dat1 == 0xFA && dat2 == 146 && dat3 == 96 ) {
|
Chris@634
|
282 d=1;
|
Chris@634
|
283 find = 1;
|
Chris@634
|
284 }
|
Chris@634
|
285 if (dat1 == 0xFA && dat2 == 144 && dat3 == 64 ) {
|
Chris@634
|
286 find = 1;
|
Chris@634
|
287 d=1;
|
Chris@634
|
288 }
|
Chris@634
|
289 if (dat1 == 0xFA && dat2 == 144 && dat3 == 96 ) {
|
Chris@634
|
290 find = 1;
|
Chris@634
|
291 d=1;
|
Chris@634
|
292 }
|
Chris@634
|
293 if (dat1 == 0xFA && dat2 == 146 && dat3 == 100 ) {
|
Chris@634
|
294 d=1;
|
Chris@634
|
295 find = 1;
|
Chris@634
|
296 }
|
Chris@634
|
297 if (dat1 == 0xFA && dat2 == 144 && dat3 == 100 ) {
|
Chris@634
|
298 find = 1;
|
Chris@634
|
299 d=1;
|
Chris@634
|
300 }
|
Chris@634
|
301 if (find == 0) {
|
Chris@634
|
302 fseek(song, -3, SEEK_CUR); // if 3 last bytes in the header are not correct
|
Chris@634
|
303 cnt = cnt - 3;
|
Chris@634
|
304 }
|
Chris@634
|
305 } // close if
|
Chris@634
|
306 if (cnt == size) { //if we have readen all the bytes in the audio file
|
Chris@634
|
307 d = 1;
|
Chris@634
|
308 }
|
Chris@634
|
309 }//close while
|
Chris@634
|
310 size = size - (cnt - 4); // Calculate the size of the samples. size = pos. end of file - pos. first header.
|
Chris@634
|
311 if (numtr == 0) { //if it is the first audio track the code writes the mdat size
|
Chris@634
|
312 sizeMDAT = size*totaltracks + 8 + sizetext + imagesize; // size of the whole media box -> INCLUDING IMAGE and TEXT SIZE.The text size does not include modifiers
|
Chris@634
|
313 swap = bytereverse(sizeMDAT);
|
Chris@634
|
314 fwrite(&swap, sizeof(u32), 1, imf);
|
Chris@634
|
315 swap = bytereverse('mdat');
|
Chris@634
|
316 mdat->type = swap;
|
Chris@634
|
317 fwrite(&mdat->type, sizeof(u32), 1, imf);
|
Chris@634
|
318 }
|
Chris@634
|
319 fseek(song, cnt - 4, SEEK_SET);
|
Chris@634
|
320 for (j=0; j<size; j++) { //read all the samples of one track and writes them in the IM AF file
|
Chris@634
|
321 fread(&mdat->data, sizeof(char), 1, song);
|
Chris@634
|
322 fwrite(&mdat->data, sizeof(char), 1, imf);
|
Chris@634
|
323 }
|
Chris@634
|
324
|
Chris@634
|
325 // copy the text in the 3gp to the ima and add the text modifiers
|
Chris@636
|
326 if (sizetext !=0){
|
Chris@634
|
327 cnt=0;// the total number of bytes of the whole text including modifiers
|
Chris@634
|
328 fseek(text,0,SEEK_CUR);
|
Chris@634
|
329 sizestring=0;//number of bytes of a phrase (without modifiers)
|
Chris@634
|
330 initposition[0]=0;// this array saves the initial position of a word
|
Chris@634
|
331 if(numtr==totaltracks-1){ // writes the text after the samples of all the audio tracks
|
Chris@634
|
332 j=0;cnt=0;
|
Chris@634
|
333 while(j<sizetext){ //this loop reads the whole text
|
Chris@634
|
334 cnt2=0;//the total number of bytes of a phrase including the modifiers
|
Chris@634
|
335 fread(&c1,sizeof(char),1,text);
|
Chris@634
|
336 fread(&c2,sizeof(char),1,text);
|
Chris@634
|
337 fwrite(&c1,sizeof(char),1,imf);//two bytes of sizestring
|
Chris@634
|
338 fwrite(&c2,sizeof(char),1,imf);
|
Chris@634
|
339 sizestring = (c1<<8) | (c2);//sizestring is the size of one phrase contained in 3gp
|
Chris@634
|
340 j=j+2;
|
Chris@634
|
341 cnt=cnt+2;
|
Chris@634
|
342 cnt2=cnt2+2;
|
Chris@634
|
343 phrases++;//the number of phrases in the whole text
|
Chris@634
|
344 numwords=0;// the number of words in a phrase
|
Chris@634
|
345 initposition[0]=0;//this array saves the first position of a word in a phrase
|
Chris@634
|
346 endposition[0]=0;// this array saves the last position of a word in a phrase
|
Chris@634
|
347 k=0;//the index for endposition array and initposition array
|
Chris@634
|
348 for(i=0;i< sizestring;i++){
|
Chris@634
|
349 fread(&mdat->data,sizeof(char),1,text);
|
Chris@634
|
350 fwrite(&mdat->data,sizeof(char),1,imf);
|
Chris@634
|
351 j++;
|
Chris@634
|
352 cnt=cnt+1;
|
Chris@634
|
353 cnt2=cnt2+1;
|
Chris@634
|
354 if(mdat->data==0x20){ //a blank space separates two words. 0x20 = blank space
|
Chris@634
|
355
|
Chris@634
|
356 numwords++;
|
Chris@634
|
357 endposition[k]=i;
|
Chris@634
|
358 initposition[k+1]=i+1;
|
Chris@634
|
359 k++;
|
Chris@634
|
360 }
|
Chris@634
|
361
|
Chris@634
|
362
|
Chris@634
|
363 } //close for
|
Chris@634
|
364 endposition[k]=sizestring-1;//saves the last position of the last word in a phrase
|
Chris@634
|
365 numwords++;
|
Chris@634
|
366
|
Chris@634
|
367
|
Chris@634
|
368 mdat->data=0x00;
|
Chris@634
|
369 fwrite(&mdat->data,sizeof(char),1,imf);//hclr size
|
Chris@634
|
370 fwrite(&mdat->data,sizeof(char),1,imf);//hclr size
|
Chris@634
|
371 fwrite(&mdat->data,sizeof(char),1,imf);//hclr size
|
Chris@634
|
372 mdat->data=0x0C;
|
Chris@634
|
373 fwrite(&mdat->data,sizeof(char),1,imf); //hclr size
|
Chris@634
|
374 fwrite("h",sizeof(char),1,imf);
|
Chris@634
|
375 fwrite("c",sizeof(char),1,imf);
|
Chris@634
|
376 fwrite("l",sizeof(char),1,imf);
|
Chris@634
|
377 fwrite("r",sizeof(char),1,imf);
|
Chris@634
|
378 mdat->data=0xFF;
|
Chris@634
|
379 fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba
|
Chris@634
|
380 mdat->data=0x62;
|
Chris@634
|
381 fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba
|
Chris@634
|
382 mdat->data=0x04;
|
Chris@634
|
383 fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba
|
Chris@634
|
384 mdat->data=0xFF;
|
Chris@634
|
385 fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba
|
Chris@634
|
386 mdat->data=0x00;
|
Chris@634
|
387 fwrite(&mdat->data,sizeof(char),1,imf); //krok size
|
Chris@634
|
388 mdat->data=0x00;
|
Chris@634
|
389 fwrite(&mdat->data,sizeof(char),1,imf);//krok size
|
Chris@634
|
390 mdat->data=0x00;
|
Chris@634
|
391 fwrite(&mdat->data,sizeof(char),1,imf);//krok size
|
Chris@634
|
392 mdat->data=14+(8*numwords);
|
Chris@634
|
393 fwrite(&mdat->data,sizeof(char),1,imf); //krok size
|
Chris@634
|
394 fwrite("k",sizeof(char),1,imf);
|
Chris@634
|
395 fwrite("r",sizeof(char),1,imf);
|
Chris@634
|
396 fwrite("o",sizeof(char),1,imf);
|
Chris@634
|
397 fwrite("k",sizeof(char),1,imf);
|
Chris@634
|
398 mdat->data=0x00;
|
Chris@634
|
399 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time
|
Chris@634
|
400 mdat->data=0x00;
|
Chris@634
|
401 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time
|
Chris@634
|
402 mdat->data=0x00;
|
Chris@634
|
403 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time
|
Chris@634
|
404 mdat->data=0x00;
|
Chris@634
|
405 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time
|
Chris@634
|
406 mdat->data=0x00;
|
Chris@634
|
407 fwrite(&mdat->data,sizeof(char),1,imf);//entry-count
|
Chris@634
|
408 mdat->data=numwords;
|
Chris@634
|
409 fwrite(&mdat->data,sizeof(char),1,imf);//entry-count
|
Chris@634
|
410
|
Chris@634
|
411 for(i=0;i<numwords;i++){
|
Chris@634
|
412
|
Chris@634
|
413 mdat->data=0x00;
|
Chris@634
|
414 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
415 mdat->data=0x00;
|
Chris@634
|
416 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
417
|
Chris@634
|
418
|
Chris@634
|
419 if(i==numwords-1){ //if it is the last word in a phrase we put this value
|
Chris@634
|
420 mdat->data=0xFF;
|
Chris@634
|
421 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
422 mdat->data=0xFF;
|
Chris@634
|
423 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
424
|
Chris@634
|
425 }
|
Chris@634
|
426
|
Chris@634
|
427 else{ //if it is not the last word in a phrase
|
Chris@634
|
428
|
Chris@634
|
429 highlight_end_time = (i+1)*(11/numwords);//change the value '11' in order to increase o decrease the speed of highlight
|
Chris@634
|
430 mdat->data= highlight_end_time;
|
Chris@634
|
431 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
432 mdat->data=0xFF;
|
Chris@634
|
433 fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time
|
Chris@634
|
434
|
Chris@634
|
435
|
Chris@634
|
436 }
|
Chris@634
|
437
|
Chris@634
|
438 mdat->data=0x00;
|
Chris@634
|
439 fwrite(&mdat->data,sizeof(char),1,imf);//startcharoffset
|
Chris@634
|
440 mdat->data=initposition[i];
|
Chris@634
|
441 fwrite(&mdat->data,sizeof(char),1,imf);//startcharoffset
|
Chris@634
|
442 mdat->data=0x00;
|
Chris@634
|
443 fwrite(&mdat->data,sizeof(char),1,imf);//endcharoffset
|
Chris@634
|
444 mdat->data=endposition[i]+1;
|
Chris@634
|
445 fwrite(&mdat->data,sizeof(char),1,imf);//endcharoffset
|
Chris@634
|
446
|
Chris@634
|
447 }//close for
|
Chris@634
|
448
|
Chris@634
|
449 cnt=cnt+26+(numwords*8);//cnt is the number of bytes of the whole text including modifiers
|
Chris@634
|
450 cnt2=cnt2+26+(numwords*8); //cnt2 is the number of bytes of a phrase including the modifiers
|
Chris@634
|
451
|
Chris@634
|
452 size_phrase[phrases-1]=cnt2 ;
|
Chris@634
|
453
|
Chris@634
|
454 } //close while
|
Chris@634
|
455
|
Chris@634
|
456 sizeMDAT = size*totaltracks + 8 + cnt + imagesize; // size value must include image and text sizes
|
Chris@634
|
457 swap = bytereverse(sizeMDAT);
|
Chris@634
|
458 fseek(imf,-(sizeMDAT-imagesize),SEEK_CUR); //overwrittes sizeMDAT with the total size (Image is yet to be written in the file at this point)
|
Chris@634
|
459 fwrite(&swap, sizeof(u32), 1, imf);
|
Chris@634
|
460 fseek(imf,(sizeMDAT-imagesize)-4,SEEK_CUR); // (Image is yet to be written in the file at this point)
|
Chris@634
|
461 } // close if (numtr==totaltracks-1)
|
Chris@636
|
462 }//close if sizetext
|
Chris@634
|
463 fclose(song);
|
Chris@634
|
464
|
Chris@634
|
465 return size;
|
Chris@634
|
466 }
|
Chris@634
|
467
|
Chris@634
|
468 int samplecontainer(MovieBox *moov, int numtrack, int sizemdat, const char *name){
|
Chris@634
|
469
|
Chris@634
|
470 u32 sizeSTSD, sizeSTSZ, swap, num_samples, dat=0;
|
Chris@634
|
471 u32 sizetime, sizeSTTS; //Time to Sample Box
|
Chris@634
|
472 u32 sizeSTSC = 28; //Sample to Chunck
|
Chris@634
|
473 u32 sizeSTCO = 20; //Chunck offset
|
Chris@634
|
474 u32 sizeSTBL; //Sample Table Box //
|
Chris@634
|
475
|
Chris@634
|
476 //Sample Description Box//
|
Chris@634
|
477 sizeSTSD = sampledescription(moov, numtrack);
|
Chris@634
|
478
|
Chris@634
|
479 //Sample size box//
|
Chris@634
|
480 swap = bytereverse('stsz');
|
Chris@634
|
481 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
482 SampleSizeBox.type = swap;
|
Chris@634
|
483 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
484 SampleSizeBox.version = 0;
|
Chris@634
|
485 //Read Track: Frame size and Decoder Times
|
Chris@634
|
486 num_samples = readTrack(moov, numtrack, name);
|
Chris@634
|
487 sizeSTSZ = num_samples*4 + 20;
|
Chris@634
|
488 swap = bytereverse(sizeSTSZ);
|
Chris@634
|
489 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
490 SampleSizeBox.size = swap;
|
Chris@634
|
491
|
Chris@634
|
492 //Time To Sample Box//
|
Chris@634
|
493 sizetime = bytereverse(moov->TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
494 SampleTableBox.TimeToSampleBox.entry_count);
|
Chris@634
|
495 sizeSTTS = 16 + sizetime*4*2;
|
Chris@634
|
496 swap = bytereverse(sizeSTTS);
|
Chris@634
|
497 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
498 TimeToSampleBox.size = swap;
|
Chris@634
|
499 swap = bytereverse('stts');
|
Chris@634
|
500 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
501 TimeToSampleBox.type = swap;
|
Chris@634
|
502 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
503 TimeToSampleBox.version = 0;
|
Chris@634
|
504
|
Chris@634
|
505 //Sample To Chunk//
|
Chris@634
|
506 swap = bytereverse(sizeSTSC);
|
Chris@634
|
507 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
508 SampleToChunk.size = swap;
|
Chris@634
|
509 swap = bytereverse('stsc');
|
Chris@634
|
510 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
511 SampleToChunk.type = swap;
|
Chris@634
|
512 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
513 SampleToChunk.version = 0;
|
Chris@634
|
514 swap = bytereverse(1);
|
Chris@634
|
515 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
516 SampleToChunk.entry_count = swap;
|
Chris@634
|
517 swap = bytereverse(1);
|
Chris@634
|
518 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
519 SampleToChunk.first_chunk = swap;
|
Chris@634
|
520 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
521 SampleToChunk.samples_per_chunk = moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count;
|
Chris@634
|
522 swap = bytereverse(1);
|
Chris@634
|
523 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
524 SampleToChunk.sample_description_index = swap;
|
Chris@634
|
525
|
Chris@634
|
526 //Chunk Offset Box//
|
Chris@634
|
527 swap = bytereverse(sizeSTCO);
|
Chris@634
|
528 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
529 ChunkOffsetBox.size = swap;
|
Chris@634
|
530 swap = bytereverse('stco');
|
Chris@634
|
531 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
532 ChunkOffsetBox.type = swap;
|
Chris@634
|
533 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
534 ChunkOffsetBox.version = 0;
|
Chris@634
|
535 swap = bytereverse(1);
|
Chris@634
|
536 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
537 ChunkOffsetBox.entry_count = swap;
|
Chris@634
|
538 dat = 32 + sizemdat*numtrack;
|
Chris@634
|
539 swap = bytereverse(dat);
|
Chris@634
|
540 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
541 ChunkOffsetBox.chunk_offset[numtrack] = swap;
|
Chris@634
|
542
|
Chris@634
|
543 //Sample Table Box //
|
Chris@634
|
544 sizeSTBL = 8 + sizeSTSD + sizeSTSZ + sizeSTSC + sizeSTCO + sizeSTTS;
|
Chris@634
|
545 swap = bytereverse(sizeSTBL);
|
Chris@634
|
546 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size = swap;
|
Chris@634
|
547 swap = bytereverse('stbl');
|
Chris@634
|
548 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type =swap;
|
Chris@634
|
549
|
Chris@634
|
550 return sizeSTBL;
|
Chris@634
|
551 }
|
Chris@634
|
552
|
Chris@634
|
553 int sampledescription(MovieBox *moov, int numtrack){
|
Chris@634
|
554
|
Chris@634
|
555 u32 swap, sizeESD = 35;
|
Chris@634
|
556
|
Chris@634
|
557 u32 sizeMP4a; //Audio Sample Entry//
|
Chris@634
|
558 u32 sizeSTSD; //Sample description box //
|
Chris@634
|
559
|
Chris@634
|
560
|
Chris@634
|
561 swap = bytereverse(sizeESD);
|
Chris@634
|
562 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
563 SampleDescriptionBox.AudioSampleEntry.ESbox.size = swap;
|
Chris@634
|
564 swap = bytereverse('esds');
|
Chris@634
|
565 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
566 SampleDescriptionBox.AudioSampleEntry.ESbox.type = swap;
|
Chris@634
|
567 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
568 SampleDescriptionBox.AudioSampleEntry.ESbox.version = 0;
|
Chris@634
|
569
|
Chris@634
|
570 //ES Descriptor//
|
Chris@634
|
571 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
572 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.tag = 3;
|
Chris@634
|
573 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
574 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.length = 21;
|
Chris@634
|
575 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
576 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.ES_ID = 0;
|
Chris@634
|
577 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
578 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.mix = 0;
|
Chris@634
|
579
|
Chris@634
|
580 //Decoder config descriptor//
|
Chris@634
|
581 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
582 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
583 DecoderConfigDescriptor.tag = 4;
|
Chris@634
|
584 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
585 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
586 DecoderConfigDescriptor.length = 13;
|
Chris@634
|
587 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
588 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
589 DecoderConfigDescriptor.objectProfileInd = 0x6B;
|
Chris@634
|
590 swap = bytereverse(0x150036B0);
|
Chris@634
|
591 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
592 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
593 DecoderConfigDescriptor.mix = swap;
|
Chris@634
|
594 swap = bytereverse(128);
|
Chris@634
|
595 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
596 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
597 DecoderConfigDescriptor.maxBitRate = swap;
|
Chris@634
|
598 swap = bytereverse(128);
|
Chris@634
|
599 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
600 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
601 DecoderConfigDescriptor.avgBitrate = swap;
|
Chris@634
|
602
|
Chris@634
|
603 //SLConfig Descriptor//
|
Chris@634
|
604 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
605 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
606 SLConfigDescriptor.tag = 6;
|
Chris@634
|
607 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
608 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
609 SLConfigDescriptor.length = 1;
|
Chris@634
|
610 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
611 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.
|
Chris@634
|
612 SLConfigDescriptor.predifined = 2;
|
Chris@634
|
613
|
Chris@634
|
614 //Audio Sample Entry//
|
Chris@634
|
615 sizeMP4a = 36 + sizeESD;
|
Chris@634
|
616 swap = bytereverse(sizeMP4a);
|
Chris@634
|
617 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
618 SampleDescriptionBox.AudioSampleEntry.size = swap;
|
Chris@634
|
619 swap = bytereverse('mp4a');
|
Chris@634
|
620 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
621 SampleDescriptionBox.AudioSampleEntry.type =swap;
|
Chris@634
|
622 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
623 SampleDescriptionBox.AudioSampleEntry.reserved[0] = 0;
|
Chris@634
|
624 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
625 SampleDescriptionBox.AudioSampleEntry.reserved[1] = 0;
|
Chris@634
|
626 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
627 SampleDescriptionBox.AudioSampleEntry.reserved[2] = 0;
|
Chris@634
|
628 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
629 SampleDescriptionBox.AudioSampleEntry.reserved[3] = 0;
|
Chris@634
|
630 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
631 SampleDescriptionBox.AudioSampleEntry.reserved[4] = 0;
|
Chris@634
|
632 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
633 SampleDescriptionBox.AudioSampleEntry.reserved[5] = 0;
|
Chris@634
|
634 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
635 SampleDescriptionBox.AudioSampleEntry.data_reference_index = bytereverse16(1);
|
Chris@634
|
636 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
637 SampleDescriptionBox.AudioSampleEntry.reserved2[0] = 0;
|
Chris@634
|
638 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
639 SampleDescriptionBox.AudioSampleEntry.reserved2[1] = 0;
|
Chris@634
|
640 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
641 SampleDescriptionBox.AudioSampleEntry.channelcount = 512;
|
Chris@634
|
642 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
643 SampleDescriptionBox.AudioSampleEntry.samplesize = 4096; // 16 bits
|
Chris@634
|
644 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
645 SampleDescriptionBox.AudioSampleEntry.reserved3 = 0;
|
Chris@634
|
646 swap = 44100 << 16;
|
Chris@634
|
647 swap = bytereverse(swap);
|
Chris@634
|
648 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
649 SampleDescriptionBox.AudioSampleEntry.samplerate = swap;
|
Chris@634
|
650
|
Chris@634
|
651 //Sample description box //
|
Chris@634
|
652 sizeSTSD = 16 + sizeMP4a;
|
Chris@634
|
653 swap = bytereverse(sizeSTSD);
|
Chris@634
|
654 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
655 SampleDescriptionBox.size = swap;
|
Chris@634
|
656 swap = bytereverse('stsd');
|
Chris@634
|
657 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
658 SampleDescriptionBox.type = swap;
|
Chris@634
|
659 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
660 SampleDescriptionBox.version = 0;
|
Chris@634
|
661 swap = bytereverse(1);
|
Chris@634
|
662 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
663 SampleDescriptionBox.entry_count = swap;
|
Chris@634
|
664
|
Chris@634
|
665 return sizeSTSD;
|
Chris@634
|
666 }
|
Chris@634
|
667
|
Chris@634
|
668 int readTrack (MovieBox *moov, int numtrack,const char *name){
|
Chris@634
|
669
|
Chris@634
|
670 int t=0,k=1, l =0;
|
Chris@634
|
671
|
Chris@634
|
672 FILE *song;
|
Chris@634
|
673 int d=0, cnt = 0, i=0, j=0, cnt2 = 0, find = 0, swap, num_entr = 0;
|
Chris@634
|
674 int dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, num_frame = 0, end =0, pos = 0;
|
Chris@634
|
675 u32 size[9000];
|
Chris@634
|
676
|
Chris@634
|
677 //Open the audio file with the name introduced by the user
|
Chris@634
|
678 song = fopen (name,"rb");
|
Chris@634
|
679 if (song == NULL) {
|
Chris@634
|
680 printf("Error opening input file\n");
|
Chris@634
|
681 system("pause");
|
Chris@634
|
682 exit(1);
|
Chris@634
|
683 }
|
Chris@634
|
684 //Calculate the size of the track
|
Chris@634
|
685 fseek(song, 0, SEEK_END);
|
Chris@634
|
686 end = ftell(song);
|
Chris@634
|
687 fseek(song, 0, SEEK_SET);
|
Chris@634
|
688 d=0, i=0;
|
Chris@634
|
689 //Search for each frame one by one, and extratcs the information
|
Chris@634
|
690 while (d == 0) {
|
Chris@634
|
691 find = 0;
|
Chris@634
|
692 fread(&dat, sizeof(unsigned char), 1, song);
|
Chris@634
|
693 cnt++;
|
Chris@634
|
694
|
Chris@634
|
695 if (dat == 0xFF) {
|
Chris@634
|
696 cnt++;
|
Chris@634
|
697 fread(&dat1, sizeof(unsigned char), 1, song);
|
Chris@634
|
698 cnt++;
|
Chris@634
|
699 fread(&dat2, sizeof(unsigned char), 1, song);
|
Chris@634
|
700 cnt++;
|
Chris@634
|
701 fread(&dat3, sizeof(unsigned char), 1, song);
|
Chris@634
|
702 if (dat1 == 0xFB && dat2 == 146 && dat3 == 64 ) {
|
Chris@634
|
703 pos = cnt - 4; //Pos of the beginning of the frame
|
Chris@634
|
704 size[num_frame] = pos - cnt2; //Size of one frame
|
Chris@634
|
705 cnt2 = pos; //Pos of the next frame
|
Chris@634
|
706 find = 1;
|
Chris@634
|
707 num_frame ++; //Number of frames
|
Chris@634
|
708 }
|
Chris@634
|
709 if (dat1 == 0xFB && dat2 == 146 && dat3 == 96 ) {
|
Chris@634
|
710 pos = cnt - 4;
|
Chris@634
|
711 size[num_frame] = pos - cnt2;
|
Chris@634
|
712 cnt2 = pos;
|
Chris@634
|
713 find = 1;
|
Chris@634
|
714 num_frame ++;
|
Chris@634
|
715 }
|
Chris@634
|
716 if (dat1 == 0xFB && dat2 == 144 && dat3 == 64 ) {
|
Chris@634
|
717 pos = cnt - 4;
|
Chris@634
|
718 size[num_frame] = pos - cnt2;
|
Chris@634
|
719 cnt2 = pos;
|
Chris@634
|
720 find = 1;
|
Chris@634
|
721 num_frame ++;
|
Chris@634
|
722 }
|
Chris@634
|
723 if (dat1 == 0xFB && dat2 == 144 && dat3 == 96 ) {
|
Chris@634
|
724 pos = cnt - 4;
|
Chris@634
|
725 size[num_frame] = pos - cnt2;
|
Chris@634
|
726 cnt2 = pos;
|
Chris@634
|
727 find = 1;
|
Chris@634
|
728 num_frame ++;
|
Chris@634
|
729 }
|
Chris@634
|
730 if (dat1 == 0xFB && dat2 == 146 && dat3 == 100 ) {
|
Chris@634
|
731 pos = cnt - 4;
|
Chris@634
|
732 size[num_frame] = pos - cnt2;
|
Chris@634
|
733 cnt2 = pos;
|
Chris@634
|
734 find = 1;
|
Chris@634
|
735 num_frame ++;
|
Chris@634
|
736 }
|
Chris@634
|
737 if (dat1 == 0xFB && dat2 == 144 && dat3 == 100 ) {
|
Chris@634
|
738 pos = cnt - 4;
|
Chris@634
|
739 size[num_frame] = pos - cnt2;
|
Chris@634
|
740 cnt2 = pos;
|
Chris@634
|
741 find = 1;
|
Chris@634
|
742 num_frame ++;
|
Chris@634
|
743 }
|
Chris@634
|
744 if (dat1 == 0xFA && dat2 == 146 && dat3 == 64 ) {
|
Chris@634
|
745 pos = cnt - 4;
|
Chris@634
|
746 size[num_frame] = pos - cnt2;
|
Chris@634
|
747 cnt2 = pos;
|
Chris@634
|
748 find = 1;
|
Chris@634
|
749 num_frame ++;
|
Chris@634
|
750 }
|
Chris@634
|
751 if (dat1 == 0xFA && dat2 == 146 && dat3 == 96 ) {
|
Chris@634
|
752 pos = cnt - 4;
|
Chris@634
|
753 size[num_frame] = pos - cnt2;
|
Chris@634
|
754 cnt2 = pos;
|
Chris@634
|
755 find = 1;
|
Chris@634
|
756 num_frame ++;
|
Chris@634
|
757 }
|
Chris@634
|
758 if (dat1 == 0xFA && dat2 == 144 && dat3 == 64 ) {
|
Chris@634
|
759 pos = cnt - 4;
|
Chris@634
|
760 size[num_frame] = pos - cnt2;
|
Chris@634
|
761 cnt2 = pos;
|
Chris@634
|
762 find = 1;
|
Chris@634
|
763 num_frame ++;
|
Chris@634
|
764 }
|
Chris@634
|
765 if (dat1 == 0xFA && dat2 == 144 && dat3 == 96 ) {
|
Chris@634
|
766 pos = cnt - 4;
|
Chris@634
|
767 size[num_frame] = pos - cnt2;
|
Chris@634
|
768 cnt2 = pos;
|
Chris@634
|
769 find = 1;
|
Chris@634
|
770 num_frame ++;
|
Chris@634
|
771 }
|
Chris@634
|
772 if (dat1 == 0xFA && dat2 == 146 && dat3 == 100 ) {
|
Chris@634
|
773 pos = cnt - 4;
|
Chris@634
|
774 size[num_frame] = pos - cnt2;
|
Chris@634
|
775 cnt2 = pos;
|
Chris@634
|
776 find = 1;
|
Chris@634
|
777 num_frame ++;
|
Chris@634
|
778 }
|
Chris@634
|
779 if (dat1 == 0xFA && dat2 == 144 && dat3 == 100 ) {
|
Chris@634
|
780 pos = cnt - 4;
|
Chris@634
|
781 size[num_frame] = pos - cnt2;
|
Chris@634
|
782 cnt2 = pos;
|
Chris@634
|
783 find = 1;
|
Chris@634
|
784 num_frame ++;
|
Chris@634
|
785 }
|
Chris@634
|
786 if (find == 0) { //In case it does not find the header.
|
Chris@634
|
787 //It keeps reading next data without jump any position
|
Chris@634
|
788 fseek(song, -3, SEEK_CUR);
|
Chris@634
|
789 cnt = cnt - 3;
|
Chris@634
|
790 }
|
Chris@634
|
791 }
|
Chris@634
|
792
|
Chris@634
|
793 if (cnt == end) {
|
Chris@634
|
794 pos = cnt;
|
Chris@634
|
795 size[num_frame] = pos - cnt2;
|
Chris@634
|
796 d = 1;
|
Chris@634
|
797 }
|
Chris@634
|
798 }
|
Chris@634
|
799
|
Chris@634
|
800 //Save Samples size//
|
Chris@634
|
801 swap = bytereverse(num_frame);
|
Chris@634
|
802 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
803 SampleSizeBox.sample_count = swap;
|
Chris@634
|
804 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
805 SampleSizeBox.sample_size = 0;
|
Chris@634
|
806
|
Chris@634
|
807 for (i=0; i< num_frame; i++) {
|
Chris@634
|
808 swap = bytereverse(size[i+1]);
|
Chris@634
|
809 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
810 SampleSizeBox.entry_size[i] = swap;
|
Chris@634
|
811 }
|
Chris@634
|
812
|
Chris@634
|
813 //Save Decoding Times//
|
Chris@634
|
814 //Writes manually the duration of each frame.
|
Chris@634
|
815 //Follows the following structure:
|
Chris@634
|
816 // 7 frames of 26 ms
|
Chris@634
|
817 // 1 frame of 27 ms
|
Chris@634
|
818 // ...
|
Chris@634
|
819 // And each 13 rows it writes
|
Chris@634
|
820 // 8 frames of 26 ms
|
Chris@634
|
821 // 1 frame of 27 ms
|
Chris@634
|
822 //It is done for adjusting the different durations of each frame.
|
Chris@634
|
823 // as they vary between 26.125 ms and 26.075 ms
|
Chris@634
|
824
|
Chris@634
|
825 swap = bytereverse(1);
|
Chris@634
|
826 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
827 TimeToSampleBox.sample_count[0] = swap;
|
Chris@634
|
828 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
829 TimeToSampleBox.sample_delta[0] =0;
|
Chris@634
|
830 // int t=0,k=1, l =0;
|
Chris@634
|
831 num_entr = 1;
|
Chris@634
|
832 j = 0;
|
Chris@634
|
833 for (i = 1; i< num_frame; i++) {
|
Chris@634
|
834 if (j == 8 && l == 0) {
|
Chris@634
|
835 swap = bytereverse(7);
|
Chris@634
|
836 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
837 TimeToSampleBox.sample_count[num_entr] = swap;
|
Chris@634
|
838 swap = bytereverse(26);
|
Chris@634
|
839 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
840 TimeToSampleBox.sample_delta[num_entr] =swap;
|
Chris@634
|
841 num_entr ++;
|
Chris@634
|
842
|
Chris@634
|
843 swap = bytereverse(1);
|
Chris@634
|
844 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
845 TimeToSampleBox.sample_count[num_entr] = swap;
|
Chris@634
|
846 swap = bytereverse(27);
|
Chris@634
|
847 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
848 TimeToSampleBox.sample_delta[num_entr] =swap;
|
Chris@634
|
849 num_entr++;
|
Chris@634
|
850 j=0;
|
Chris@634
|
851 dat = i;
|
Chris@634
|
852 if (k == 6 && t == 0) {
|
Chris@634
|
853 l = 1;
|
Chris@634
|
854 t = 1;
|
Chris@634
|
855 k = 1;
|
Chris@634
|
856 }
|
Chris@634
|
857 if (k == 6 && t ==1) {
|
Chris@634
|
858 l = 1;
|
Chris@634
|
859 k = 1;
|
Chris@634
|
860 }
|
Chris@634
|
861 k++;
|
Chris@634
|
862 }
|
Chris@634
|
863
|
Chris@634
|
864 if (j == 9 && l == 1) {
|
Chris@634
|
865
|
Chris@634
|
866 swap = bytereverse(8);
|
Chris@634
|
867 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
868 TimeToSampleBox.sample_count[num_entr] = swap;
|
Chris@634
|
869 swap = bytereverse(26);
|
Chris@634
|
870 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
871 TimeToSampleBox.sample_delta[num_entr] =swap;
|
Chris@634
|
872 num_entr ++;
|
Chris@634
|
873
|
Chris@634
|
874 swap = bytereverse(1);
|
Chris@634
|
875 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
876 TimeToSampleBox.sample_count[num_entr] = swap;
|
Chris@634
|
877 swap = bytereverse(27);
|
Chris@634
|
878 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
879 TimeToSampleBox.sample_delta[num_entr] =swap;
|
Chris@634
|
880 num_entr++;
|
Chris@634
|
881 j=0;
|
Chris@634
|
882 dat = i;
|
Chris@634
|
883 l = 0;
|
Chris@634
|
884 }
|
Chris@634
|
885 j++;
|
Chris@634
|
886 }
|
Chris@634
|
887
|
Chris@634
|
888 dat = num_frame - dat;
|
Chris@634
|
889
|
Chris@634
|
890 swap = bytereverse(dat);
|
Chris@634
|
891 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
892 TimeToSampleBox.sample_count[num_entr] = swap;
|
Chris@634
|
893 swap = bytereverse(26);
|
Chris@634
|
894 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
895 TimeToSampleBox.sample_delta[num_entr] =swap;
|
Chris@634
|
896 num_entr++;
|
Chris@634
|
897 swap = bytereverse(num_entr);
|
Chris@634
|
898 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
899 TimeToSampleBox.entry_count = swap;
|
Chris@634
|
900
|
Chris@634
|
901 fclose(song);
|
Chris@634
|
902 return num_frame;
|
Chris@634
|
903
|
Chris@634
|
904 }
|
Chris@634
|
905
|
Chris@634
|
906 int trackstructure (MovieBox *moov, int numtrack, int clock,
|
Chris@634
|
907 int durationTrack, int sizemdat,const char *name){
|
Chris@634
|
908 int swap;
|
Chris@634
|
909
|
Chris@634
|
910 int sizeSTBL; //Sample Table Box
|
Chris@634
|
911 u32 sizeURL; //Data Entry Url Box
|
Chris@634
|
912 u32 sizeDREF; //Data Reference
|
Chris@634
|
913 u32 sizeSMHD; //Sound Header Box
|
Chris@634
|
914 u32 sizeDINF; //Data information Box
|
Chris@634
|
915 u32 sizeMINF; //Media Information Box//
|
Chris@634
|
916 u32 sizeHDLR; //Handler Box//
|
Chris@634
|
917 u32 sizeMDHD; //Media Header Box//
|
Chris@634
|
918 u32 sizeMDIA; //Media Box//
|
Chris@634
|
919 u32 sizeTKHD; //Track Header//
|
Chris@634
|
920 u32 sizeTRAK; //Track container
|
Chris@634
|
921
|
Chris@634
|
922 //Sample Table Box
|
Chris@634
|
923 sizeSTBL = 0;
|
Chris@634
|
924 sizeSTBL = samplecontainer(moov, numtrack,sizemdat, name);
|
Chris@634
|
925
|
Chris@634
|
926 //Data Entry Url Box
|
Chris@634
|
927 sizeURL = 12;
|
Chris@634
|
928 swap = bytereverse(sizeURL);
|
Chris@634
|
929 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
930 DataReferenceBox.DataEntryUrlBox.size = swap;
|
Chris@634
|
931 swap = bytereverse('url ');
|
Chris@634
|
932 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
933 DataReferenceBox.DataEntryUrlBox.type = swap;
|
Chris@634
|
934 swap = bytereverse(1);
|
Chris@634
|
935 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
936 DataReferenceBox.DataEntryUrlBox.flags = swap; // =1 Track in same file as movie atom.
|
Chris@634
|
937
|
Chris@634
|
938 //Data Reference
|
Chris@634
|
939 sizeDREF = sizeURL+ 16;
|
Chris@634
|
940 swap = bytereverse(sizeDREF);
|
Chris@634
|
941 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
942 DataReferenceBox.size = swap;
|
Chris@634
|
943 swap = bytereverse('dref');
|
Chris@634
|
944 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
945 DataReferenceBox.type = swap;
|
Chris@634
|
946 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
947 DataReferenceBox.flags = 0;
|
Chris@634
|
948 swap = bytereverse(1);
|
Chris@634
|
949 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
950 DataReferenceBox.entry_count = swap;
|
Chris@634
|
951
|
Chris@634
|
952 //Data information Box//
|
Chris@634
|
953 sizeDINF = sizeDREF + 8;
|
Chris@634
|
954 swap = bytereverse(sizeDINF);
|
Chris@634
|
955 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.size = swap;
|
Chris@634
|
956 swap = bytereverse('dinf');
|
Chris@634
|
957 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.type = swap;
|
Chris@634
|
958
|
Chris@634
|
959 //Sound Header Box //
|
Chris@634
|
960 sizeSMHD = 16;
|
Chris@634
|
961 swap = bytereverse(sizeSMHD);
|
Chris@634
|
962 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.size = swap;
|
Chris@634
|
963 swap = bytereverse('smhd');
|
Chris@634
|
964 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.type = swap;
|
Chris@634
|
965 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.version = 0;
|
Chris@634
|
966 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.balance = 0;
|
Chris@634
|
967 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.reserved = 0;
|
Chris@634
|
968
|
Chris@634
|
969 //Media Information Box//
|
Chris@634
|
970 sizeMINF = sizeDINF + sizeSMHD + sizeSTBL + 8;
|
Chris@634
|
971 swap = bytereverse(sizeMINF);
|
Chris@634
|
972 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.size = swap;
|
Chris@634
|
973 swap = bytereverse('minf');
|
Chris@634
|
974 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.type = swap;
|
Chris@634
|
975
|
Chris@634
|
976 //Handler Box//
|
Chris@634
|
977 sizeHDLR = 37;
|
Chris@634
|
978 swap = bytereverse(sizeHDLR);
|
Chris@634
|
979 moov->TrackBox[numtrack].MediaBox.HandlerBox.size = swap;
|
Chris@634
|
980 swap = bytereverse('hdlr');
|
Chris@634
|
981 moov->TrackBox[numtrack].MediaBox.HandlerBox.type = swap;
|
Chris@634
|
982 moov->TrackBox[numtrack].MediaBox.HandlerBox.version = 0;
|
Chris@634
|
983 moov->TrackBox[numtrack].MediaBox.HandlerBox.pre_defined = 0;
|
Chris@634
|
984 swap = bytereverse('soun');
|
Chris@634
|
985 moov->TrackBox[numtrack].MediaBox.HandlerBox.handler_type = swap;
|
Chris@634
|
986 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[0] = 0;
|
Chris@634
|
987 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[1] = 0;
|
Chris@634
|
988 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[2] = 0;
|
Chris@634
|
989 //swap = bytereverse('soun');
|
Chris@634
|
990 //moov->TrackBox[numtrack].MediaBox.HandlerBox.data = swap;
|
Chris@634
|
991 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[0] = 's';
|
Chris@634
|
992 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[1] = 'o';
|
Chris@634
|
993 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[2] = 'u';
|
Chris@634
|
994 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[3] = 'n';
|
Chris@634
|
995 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[4] = '\0';
|
Chris@634
|
996
|
Chris@634
|
997 //Media Header Box//
|
Chris@634
|
998 sizeMDHD = 32;
|
Chris@634
|
999 swap = bytereverse(sizeMDHD);
|
Chris@634
|
1000 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.size = swap;
|
Chris@634
|
1001 swap = bytereverse('mdhd');
|
Chris@634
|
1002 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.type = swap;
|
Chris@634
|
1003 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.version = 0;
|
Chris@634
|
1004 swap = bytereverse(clock);
|
Chris@634
|
1005 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.creation_time = swap;
|
Chris@634
|
1006 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.modification_time = swap;
|
Chris@634
|
1007 swap = bytereverse(1000);
|
Chris@634
|
1008 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.timescale = swap;
|
Chris@634
|
1009 swap = bytereverse(durationTrack);
|
Chris@634
|
1010 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.duration = swap;
|
Chris@634
|
1011 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.language = 0xC455;
|
Chris@634
|
1012 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.pre_defined = 0;
|
Chris@634
|
1013
|
Chris@634
|
1014 //Media Box//
|
Chris@634
|
1015 sizeMDIA = sizeMDHD + sizeHDLR + sizeMINF + 8;
|
Chris@634
|
1016 swap = bytereverse(sizeMDIA);
|
Chris@634
|
1017 moov->TrackBox[numtrack].MediaBox.size = swap;
|
Chris@634
|
1018 swap = bytereverse('mdia');
|
Chris@634
|
1019 moov->TrackBox[numtrack].MediaBox.type = swap;
|
Chris@634
|
1020
|
Chris@634
|
1021 //Track Header//
|
Chris@634
|
1022 sizeTKHD = 92;
|
Chris@634
|
1023 swap = bytereverse (sizeTKHD);
|
Chris@634
|
1024 moov->TrackBox[numtrack].TrackHeaderBox.size = swap;
|
Chris@634
|
1025 swap = bytereverse ('tkhd');
|
Chris@634
|
1026 moov->TrackBox[numtrack].TrackHeaderBox.type = swap ;
|
Chris@634
|
1027 swap = bytereverse (0x00000006);
|
Chris@634
|
1028 moov->TrackBox[numtrack].TrackHeaderBox.version = swap;
|
Chris@634
|
1029 swap = bytereverse (clock);
|
Chris@634
|
1030 moov->TrackBox[numtrack].TrackHeaderBox.creation_time = swap;
|
Chris@634
|
1031 moov->TrackBox[numtrack].TrackHeaderBox.modification_time = swap;
|
Chris@634
|
1032 swap = bytereverse (numtrack+1);
|
Chris@634
|
1033 moov->TrackBox[numtrack].TrackHeaderBox.track_ID = swap; //From 0x00000001 - 0x7FFFFFFF (dec 2147483647)
|
Chris@634
|
1034 moov->TrackBox[numtrack].TrackHeaderBox.reserved = 0;
|
Chris@634
|
1035 swap = bytereverse (durationTrack);
|
Chris@634
|
1036 moov->TrackBox[numtrack].TrackHeaderBox.duration = swap;
|
Chris@634
|
1037 moov->TrackBox[numtrack].TrackHeaderBox.reserved2[0] = 0;
|
Chris@634
|
1038 moov->TrackBox[numtrack].TrackHeaderBox.reserved2[1] = 0;
|
Chris@634
|
1039 moov->TrackBox[numtrack].TrackHeaderBox.layer = 0;
|
Chris@634
|
1040 moov->TrackBox[numtrack].TrackHeaderBox.alternate_group = 0;
|
Chris@634
|
1041 moov->TrackBox[numtrack].TrackHeaderBox.volume = 0x1;
|
Chris@634
|
1042 moov->TrackBox[numtrack].TrackHeaderBox.reserved3 = 0;
|
Chris@634
|
1043 swap = bytereverse (0x00010000);
|
Chris@634
|
1044 moov->TrackBox[numtrack].TrackHeaderBox.matrix[0] = swap;
|
Chris@634
|
1045 moov->TrackBox[numtrack].TrackHeaderBox.matrix[1] = 0;
|
Chris@634
|
1046 moov->TrackBox[numtrack].TrackHeaderBox.matrix[2] = 0;
|
Chris@634
|
1047 moov->TrackBox[numtrack].TrackHeaderBox.matrix[3] = 0;
|
Chris@634
|
1048 moov->TrackBox[numtrack].TrackHeaderBox.matrix[4] = swap;
|
Chris@634
|
1049 moov->TrackBox[numtrack].TrackHeaderBox.matrix[5] = 0;
|
Chris@634
|
1050 moov->TrackBox[numtrack].TrackHeaderBox.matrix[6] = 0;
|
Chris@634
|
1051 moov->TrackBox[numtrack].TrackHeaderBox.matrix[7] = 0;
|
Chris@634
|
1052 swap = bytereverse(0x40000000);
|
Chris@634
|
1053 moov->TrackBox[numtrack].TrackHeaderBox.matrix[8] = swap;
|
Chris@634
|
1054 moov->TrackBox[numtrack].TrackHeaderBox.width = 0; //just for video
|
Chris@634
|
1055 moov->TrackBox[numtrack].TrackHeaderBox.height = 0; //just for video
|
Chris@634
|
1056
|
Chris@634
|
1057 //Track container
|
Chris@634
|
1058 sizeTRAK = sizeTKHD + sizeMDIA + 8;
|
Chris@634
|
1059 swap = bytereverse (sizeTRAK); // Size of one track
|
Chris@634
|
1060 moov->TrackBox[numtrack].size = swap;
|
Chris@634
|
1061 swap = bytereverse ('trak');
|
Chris@634
|
1062 moov->TrackBox[numtrack].type = swap;
|
Chris@634
|
1063 return sizeTRAK;
|
Chris@634
|
1064
|
Chris@634
|
1065 }
|
Chris@634
|
1066
|
Chris@634
|
1067 int groupcontainer(MovieBox *moov, int *group_tracks, int grp_vol, QString grp_name,
|
Chris@634
|
1068 QString grp_description, int totaltracks) {
|
Chris@634
|
1069
|
Chris@634
|
1070 int i, j, k, numgroups, sizeCont;
|
Chris@634
|
1071 int numel = 0;
|
Chris@634
|
1072 int sizeBox = 0;
|
Chris@634
|
1073 int tempsize = 0;
|
Chris@634
|
1074 int active, activenum, addsize;
|
Chris@634
|
1075
|
Chris@634
|
1076 // ADDED FOR SV
|
Chris@634
|
1077 for (j=0; j<totaltracks; j++){
|
Chris@634
|
1078 if (group_tracks[j]==1){
|
Chris@634
|
1079 numel++;
|
Chris@634
|
1080 }
|
Chris@634
|
1081 }
|
Chris@634
|
1082
|
Chris@634
|
1083 if (numel==0){
|
Chris@634
|
1084 numgroups = 0;
|
Chris@634
|
1085 }else{
|
Chris@634
|
1086 numgroups = 1;
|
Chris@634
|
1087 }
|
Chris@634
|
1088 //
|
Chris@634
|
1089
|
Chris@634
|
1090 moov->GroupContainerBox.num_groups = bytereverse16(numgroups);
|
Chris@634
|
1091
|
Chris@634
|
1092 for (i=0; i<numgroups; i++){
|
Chris@634
|
1093 addsize = 0;
|
Chris@634
|
1094 tempsize = 0;
|
Chris@634
|
1095 moov->GroupContainerBox.GroupBox[i].group_ID = bytereverse(2147483649+i+1); // group_ID shall be represented from 0x80000000 to 0xFFFFFFFF
|
Chris@634
|
1096 strcpy(moov->GroupContainerBox.GroupBox[i].group_name, grp_name.toStdString().c_str());
|
Chris@634
|
1097 strcpy(moov->GroupContainerBox.GroupBox[i].group_description, grp_description.toStdString().c_str());
|
Chris@634
|
1098
|
Chris@634
|
1099 // numel = 0; // uncomment for more than one group and remove initial "for" with numel
|
Chris@634
|
1100 k = 0;
|
Chris@634
|
1101 for (j=0; j<totaltracks; j++){
|
Chris@634
|
1102 if (group_tracks[j]==1){
|
Chris@634
|
1103 moov->GroupContainerBox.GroupBox[i].groupElemId[k].element_ID = bytereverse(j+1);
|
Chris@634
|
1104 // numel++; // uncomment for more than one group and remove initial "for" with numel
|
Chris@634
|
1105 addsize += 4;
|
Chris@634
|
1106 k++;
|
Chris@634
|
1107 }
|
Chris@634
|
1108 }
|
Chris@634
|
1109 moov->GroupContainerBox.GroupBox[i].num_elements = bytereverse16(numel);
|
Chris@634
|
1110
|
Chris@634
|
1111 // printf("Choose the activation mode: ");
|
Chris@634
|
1112 // printf("Activation mode\n");
|
Chris@634
|
1113 // printf(" - Switch on the MINIMUN number of elements (0, if no Min/Max rule) [0]\n");
|
Chris@634
|
1114 // printf(" - Switch on the MAXIMUM number of elements (All tracks, if no Min/Max rule) [1]\n");
|
Chris@634
|
1115 // printf(" - Switch on the defined number of elements (ONLY IF there is Min/Max rule) [2]\n");
|
Chris@634
|
1116 // scanf("%d",&active);
|
Chris@634
|
1117 // fflush(stdin);
|
Chris@634
|
1118
|
Chris@634
|
1119 active = 1; // ADDED FOR SV, All tracks enabled
|
Chris@634
|
1120
|
Chris@634
|
1121 moov->GroupContainerBox.GroupBox[i].group_activation_mode = active;
|
Chris@634
|
1122 activenum = 0;
|
Chris@634
|
1123 moov->GroupContainerBox.GroupBox[i].group_activation_elements_number = activenum;
|
Chris@634
|
1124 if (active==2){
|
Chris@634
|
1125 printf("Activation elements number: ");
|
Chris@634
|
1126 scanf("%d",&activenum);
|
Chris@634
|
1127 moov->GroupContainerBox.GroupBox[i].group_activation_elements_number = bytereverse16(activenum);
|
Chris@634
|
1128 addsize += 2;
|
Chris@634
|
1129 }
|
Chris@634
|
1130
|
Chris@634
|
1131 moov->GroupContainerBox.GroupBox[i].group_reference_volume = bytereverse16(grp_vol*256/100); // define 8.8 fixed point
|
Chris@634
|
1132
|
Chris@634
|
1133 tempsize = 75 + addsize; // ---> before was 66 + addsize;
|
Chris@634
|
1134 moov->GroupContainerBox.GroupBox[i].size = bytereverse(tempsize);
|
Chris@634
|
1135 moov->GroupContainerBox.GroupBox[i].type = bytereverse('grup');
|
Chris@634
|
1136 moov->GroupContainerBox.GroupBox[i].version = bytereverse(0x02); // flags = Display enable, Edit disable
|
Chris@634
|
1137
|
Chris@634
|
1138 sizeBox += tempsize;
|
Chris@634
|
1139
|
Chris@634
|
1140 } // close for (numgroups)
|
Chris@634
|
1141
|
Chris@634
|
1142 sizeCont = sizeBox + 10;
|
Chris@634
|
1143
|
Chris@634
|
1144 moov->GroupContainerBox.size = bytereverse(sizeCont);
|
Chris@634
|
1145 moov->GroupContainerBox.type = bytereverse('grco');
|
Chris@634
|
1146
|
Chris@634
|
1147 return sizeCont;
|
Chris@634
|
1148 }
|
Chris@634
|
1149
|
Chris@634
|
1150 int presetcontainer(MovieBox *moov, int totaltracks, int *vol_values, int prestype, int fade_in){
|
Chris@634
|
1151
|
Chris@634
|
1152 int temp, i, j, k, m, t, vol;
|
Chris@634
|
1153 int numpres, eq;
|
Chris@634
|
1154 //char name[50];
|
Chris@634
|
1155 u32 sizePRST = 0;
|
Chris@634
|
1156 u32 sizePRCO = 0;
|
Chris@634
|
1157 u32 sizeEQ;
|
Chris@634
|
1158 u32 addsize = 0;
|
Chris@634
|
1159 int updates = 0;
|
Chris@634
|
1160
|
Chris@634
|
1161 numpres = 1; // ADDED FOR SV
|
Chris@634
|
1162
|
Chris@634
|
1163 //Preset Box//
|
Chris@634
|
1164 for (i=0; i<numpres; i++) {
|
Chris@634
|
1165 // printf("\nPRESET LIST:\n");
|
Chris@634
|
1166 // printf(" - Static track volume [0]\n");
|
Chris@634
|
1167 // printf(" - Static object volume [1]\n");
|
Chris@634
|
1168 // printf(" - Dynamic track volume [2]\n");
|
Chris@634
|
1169 // printf(" - Dynamic object volume [3]\n");
|
Chris@634
|
1170 // printf(" - Dynamic track approximated volume [4]\n");
|
Chris@634
|
1171 // printf(" - Dynamic object approximated volume [5]\n");
|
Chris@634
|
1172 // printf(" - Static track volume with Equalization [6]\n"); // count preset_type from 8
|
Chris@634
|
1173 // printf(" - Static object volume with Equalization [7]\n");
|
Chris@634
|
1174 // printf(" - Dynamic track volume with Equalization [8]\n");
|
Chris@634
|
1175 // printf(" - Dynamic object volume with Equalization [9]\n");
|
Chris@634
|
1176 // printf(" - Dynamic track approximated with Equalization [10]\n");
|
Chris@634
|
1177 // printf(" - Dynamic object approximated with Equalization [11]\n");
|
Chris@634
|
1178 // printf("\nPlease make your choice: ");
|
Chris@634
|
1179 // scanf("%d", &prestype);
|
Chris@634
|
1180 // fflush(stdin);
|
Chris@634
|
1181
|
Chris@634
|
1182 //PresetBOX
|
Chris@634
|
1183 // Box size specified in respective case
|
Chris@634
|
1184 moov->PresetContainerBox.PresetBox[i].type = bytereverse('prst');
|
Chris@634
|
1185 moov->PresetContainerBox.PresetBox[i].flags = bytereverse(0x02); // Display Enable Edit Disable
|
Chris@634
|
1186 moov->PresetContainerBox.PresetBox[i].preset_ID = i+1;
|
Chris@634
|
1187 moov->PresetContainerBox.PresetBox[i].num_preset_elements = totaltracks; // All the tracks are involved in the preset
|
Chris@634
|
1188 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1189 moov->PresetContainerBox.PresetBox[i].presElemId[j].preset_element_ID = bytereverse(j+1);
|
Chris@634
|
1190 }
|
Chris@634
|
1191 moov->PresetContainerBox.PresetBox[i].preset_global_volume = 100;
|
Chris@634
|
1192
|
Chris@634
|
1193 // prestype = 0; // ADDED FOR SV
|
Chris@634
|
1194
|
Chris@634
|
1195 switch (prestype) {
|
Chris@634
|
1196 case 0: moov->PresetContainerBox.PresetBox[i].preset_type = 0;
|
Chris@634
|
1197 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static track volume preset");
|
Chris@634
|
1198
|
Chris@634
|
1199 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1200 vol = vol_values[j]*2;
|
Chris@634
|
1201 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].preset_volume_element = vol/2; //*0.02
|
Chris@634
|
1202 }
|
Chris@634
|
1203
|
Chris@634
|
1204 addsize = totaltracks;
|
Chris@634
|
1205 break;
|
Chris@634
|
1206 case 1: moov->PresetContainerBox.PresetBox[i].preset_type = 1;
|
Chris@634
|
1207 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static object volume preset");
|
Chris@634
|
1208
|
Chris@634
|
1209 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1210 moov->PresetContainerBox.PresetBox[i].StaticObjectVolume.InputCH[j].num_input_channel = num_ch;
|
Chris@634
|
1211 }
|
Chris@634
|
1212 moov->PresetContainerBox.PresetBox[i].StaticObjectVolume.output_channel_type = 1; // STEREO (2 output channels)
|
Chris@634
|
1213 for (j=0; j<totaltracks; j++){
|
Chris@634
|
1214 for (k=0; k<num_ch; k++){
|
Chris@634
|
1215 for (m=0; m<num_ch; m++){
|
Chris@634
|
1216 moov->PresetContainerBox.PresetBox[i].StaticObjectVolume.presElVol[j].
|
Chris@634
|
1217 Input[k].Output[m].preset_volume_element = (100-(20*m))/2; // INPUT BY USER
|
Chris@634
|
1218 }
|
Chris@634
|
1219 }
|
Chris@634
|
1220 }
|
Chris@634
|
1221
|
Chris@634
|
1222 addsize = totaltracks + 1+ totaltracks*num_ch*num_ch;
|
Chris@634
|
1223 break;
|
Chris@634
|
1224 case 2: moov->PresetContainerBox.PresetBox[i].preset_type = 2;
|
Chris@634
|
1225 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track volume preset");
|
Chris@634
|
1226
|
Chris@634
|
1227 updates = 2; // volume changes
|
Chris@634
|
1228 moov->PresetContainerBox.PresetBox[i].DynamicTrackVolume.num_updates = bytereverse16(updates);
|
Chris@634
|
1229 for (j=0; j<updates; j++){ // INPUT BY USER
|
Chris@634
|
1230 moov->PresetContainerBox.PresetBox[i].DynamicTrackVolume.
|
Chris@634
|
1231 DynamicChange[j].updated_sample_number = bytereverse16(100+(j*100)); // *0.026 = time in seconds
|
Chris@634
|
1232 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1233 moov->PresetContainerBox.PresetBox[i].DynamicTrackVolume.
|
Chris@634
|
1234 DynamicChange[j].presVolumElem[k].preset_volume_element = (50*j)/2; // INPUT BY USER
|
Chris@634
|
1235 }
|
Chris@634
|
1236 }
|
Chris@634
|
1237
|
Chris@634
|
1238 addsize = 2 + updates*(2 + totaltracks);
|
Chris@634
|
1239 break;
|
Chris@634
|
1240 case 3: moov->PresetContainerBox.PresetBox[i].preset_type = 3;
|
Chris@634
|
1241 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object volume preset");
|
Chris@634
|
1242
|
Chris@634
|
1243 updates = 2; // volume changes
|
Chris@634
|
1244 moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.num_updates = bytereverse16(updates); // INPUT BY USER (maybe...)
|
Chris@634
|
1245 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1246 moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.InputCH[j].num_input_channel = 2;
|
Chris@634
|
1247 }
|
Chris@634
|
1248 moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.output_channel_type = 1; // STEREO (2 output channels)
|
Chris@634
|
1249 for (j=0; j<updates; j++){ // INPUT BY USER
|
Chris@634
|
1250 moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.
|
Chris@634
|
1251 DynamicChange[j].updated_sample_number = bytereverse16(0+(j*500)); // *0.026 = time in seconds
|
Chris@634
|
1252 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1253 for (m=0; m<num_ch; m++){
|
Chris@634
|
1254 for (t=0; t<num_ch; t++){
|
Chris@634
|
1255 moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.DynamicChange[j].
|
Chris@634
|
1256 presElVol[k].Input[m].Output[t].preset_volume_element = (25*(j+1)); // INPUT BY USER
|
Chris@634
|
1257 }
|
Chris@634
|
1258 }
|
Chris@634
|
1259 }
|
Chris@634
|
1260 }
|
Chris@634
|
1261
|
Chris@634
|
1262 addsize = 2 + totaltracks + 1 + updates*(2 + totaltracks*num_ch*num_ch);
|
Chris@634
|
1263 break;
|
Chris@634
|
1264 case 4: moov->PresetContainerBox.PresetBox[i].preset_type = 4;
|
Chris@634
|
1265 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track approximated volume");
|
Chris@634
|
1266
|
Chris@634
|
1267 updates = 2; // volume changes
|
Chris@634
|
1268 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates = bytereverse16(updates);
|
Chris@634
|
1269 for (j=0; j<updates; j++){
|
Chris@634
|
1270 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1271 DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER
|
Chris@634
|
1272 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1273 DynamicChange[j].duration_update = bytereverse16(500); // *0.026 = time in seconds -INPUT BY USER
|
Chris@634
|
1274 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1275 if (fade_in){
|
Chris@634
|
1276 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j].
|
Chris@634
|
1277 presElVol[k].end_preset_volume_element = (50*j); // Fade IN
|
Chris@634
|
1278 } else {
|
Chris@634
|
1279 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j].
|
Chris@634
|
1280 presElVol[k].end_preset_volume_element = (100-(100*j))/2; // Fade OUT
|
Chris@634
|
1281 }
|
Chris@634
|
1282 }
|
Chris@634
|
1283 }
|
Chris@634
|
1284
|
Chris@634
|
1285 /* // some code for test
|
Chris@634
|
1286 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].start_sample_number = bytereverse16(1100);
|
Chris@634
|
1287 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].duration_update = bytereverse16(250);
|
Chris@634
|
1288 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].presElVol[0].end_preset_volume_element = 50;
|
Chris@634
|
1289 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].presElVol[1].end_preset_volume_element = 50;
|
Chris@634
|
1290 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].start_sample_number = bytereverse16(1100);
|
Chris@634
|
1291 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].duration_update = bytereverse16(250);
|
Chris@634
|
1292 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].presElVol[0].end_preset_volume_element = 1;
|
Chris@634
|
1293 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].presElVol[1].end_preset_volume_element = 1;
|
Chris@634
|
1294 */
|
Chris@634
|
1295
|
Chris@634
|
1296 addsize = 2 + updates*(2 + 2 + totaltracks);
|
Chris@634
|
1297 break;
|
Chris@634
|
1298 case 5: moov->PresetContainerBox.PresetBox[i].preset_type = 5; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1299 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object approximated volume");
|
Chris@634
|
1300
|
Chris@634
|
1301 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1302
|
Chris@634
|
1303 updates = 2; // volume changes
|
Chris@634
|
1304 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.num_updates = bytereverse16(updates);
|
Chris@634
|
1305 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1306 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.InputCH[j].num_input_channel = 2;
|
Chris@634
|
1307 }
|
Chris@634
|
1308 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.output_channel_type = 1; // STEREO (2 output channels)
|
Chris@634
|
1309 for (j=0; j<updates; j++){
|
Chris@634
|
1310 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.
|
Chris@634
|
1311 DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER
|
Chris@634
|
1312 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.
|
Chris@634
|
1313 DynamicChange[j].duration_update = bytereverse16(250); // *0.026 = time in seconds - INPUT BY USER
|
Chris@634
|
1314 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1315 for (m=0; m<num_ch; m++){
|
Chris@634
|
1316 for (t=0; t<num_ch; t++){
|
Chris@634
|
1317 moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.DynamicChange[j].
|
Chris@634
|
1318 presElVol[k].Input[m].Output[t].preset_volume_element = (100*j)/2; // INPUT BY USER
|
Chris@634
|
1319 }
|
Chris@634
|
1320 }
|
Chris@634
|
1321 }
|
Chris@634
|
1322 }
|
Chris@634
|
1323
|
Chris@634
|
1324 addsize = 2 + totaltracks + 1 + updates*( 2 + 2 + totaltracks*num_ch*num_ch);
|
Chris@634
|
1325 break;
|
Chris@634
|
1326 case 6: moov->PresetContainerBox.PresetBox[i].preset_type = 8;
|
Chris@634
|
1327 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static track volume with Equalization");
|
Chris@634
|
1328
|
Chris@634
|
1329 eq = 0; addsize = 0;
|
Chris@634
|
1330 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1331 //printf("Enter volume for %s : ",namet[j].title);
|
Chris@634
|
1332 scanf("%d",&vol);
|
Chris@634
|
1333 fflush(stdin);
|
Chris@634
|
1334 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].preset_volume_element = vol/2; //*0.02
|
Chris@634
|
1335
|
Chris@634
|
1336 // Equalization
|
Chris@634
|
1337 printf("EQ Filter on this element? [1] Yes - [0] No : ");
|
Chris@634
|
1338 scanf("%d",&eq);
|
Chris@634
|
1339 fflush(stdin);
|
Chris@634
|
1340
|
Chris@634
|
1341 if (eq == 1){
|
Chris@634
|
1342 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters = 1;
|
Chris@634
|
1343 for (k=0; k<moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters; k++){
|
Chris@634
|
1344 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_type = 4; // HPF
|
Chris@634
|
1345 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].
|
Chris@634
|
1346 filter_reference_frequency = bytereverse16(5000); // 10kHz
|
Chris@634
|
1347 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_gain = -10;
|
Chris@634
|
1348 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_bandwidth = 4;
|
Chris@634
|
1349 addsize += 5;
|
Chris@634
|
1350 } //close for
|
Chris@634
|
1351 }else{
|
Chris@634
|
1352 moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters = 0;
|
Chris@634
|
1353 } //close if/else
|
Chris@634
|
1354 } //close for
|
Chris@634
|
1355
|
Chris@634
|
1356 addsize += totaltracks + totaltracks; //add preset_volume and num_eq_filters size
|
Chris@634
|
1357 break;
|
Chris@634
|
1358 case 7: moov->PresetContainerBox.PresetBox[i].preset_type = 9; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1359 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static object volume with Equalization");
|
Chris@634
|
1360 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1361 break;
|
Chris@634
|
1362 case 8: moov->PresetContainerBox.PresetBox[i].preset_type = 10; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1363 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track volume with Equalization");
|
Chris@634
|
1364 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1365 break;
|
Chris@634
|
1366 case 9: moov->PresetContainerBox.PresetBox[i].preset_type = 11; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1367 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object volume with Equalization");
|
Chris@634
|
1368 break;
|
Chris@634
|
1369 case 10: moov->PresetContainerBox.PresetBox[i].preset_type = 12; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1370 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track approximated with Equalization");
|
Chris@634
|
1371 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1372
|
Chris@634
|
1373 eq = 0; addsize = 0;
|
Chris@634
|
1374 updates = 2; // volume changes
|
Chris@634
|
1375 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates = bytereverse16(updates);
|
Chris@634
|
1376 for (j=0; j<updates; j++){
|
Chris@634
|
1377 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1378 DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER
|
Chris@634
|
1379 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1380 DynamicChange[j].duration_update = bytereverse16(500); // *0.026 = time in seconds -INPUT BY USER
|
Chris@634
|
1381 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1382 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j].
|
Chris@634
|
1383 presElVol[k].end_preset_volume_element = (50*j); // Fade IN, change in (100-(100*j))/2 for Fade OUT -INPUT BY USER
|
Chris@634
|
1384
|
Chris@634
|
1385 // Equalization
|
Chris@634
|
1386 //printf("EQ Filter on %s ? [1] Yes - [0] No : ",namet[k].title);
|
Chris@634
|
1387 scanf("%d",&eq);
|
Chris@634
|
1388 fflush(stdin);
|
Chris@634
|
1389
|
Chris@634
|
1390 if (eq == 1){
|
Chris@634
|
1391 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1392 DynamicChange[j].presElVol[k].EQ.num_eq_filters = 1;
|
Chris@634
|
1393 for (t=0; t<moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1394 DynamicChange[j].presElVol[k].EQ.num_eq_filters; t++){
|
Chris@634
|
1395 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1396 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_type = 4; // HPF
|
Chris@634
|
1397 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1398 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_reference_frequency = bytereverse16(5000); // 10kHz
|
Chris@634
|
1399 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1400 DynamicChange[j].presElVol[k].EQ.Filter[t].end_filter_gain = -10;
|
Chris@634
|
1401 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1402 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_bandwidth = 4;
|
Chris@634
|
1403 addsize += 5;
|
Chris@634
|
1404 } //close for
|
Chris@634
|
1405 }else{
|
Chris@634
|
1406 moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1407 DynamicChange[j].presElVol[k].EQ.num_eq_filters = 0;
|
Chris@634
|
1408 } //close if/else
|
Chris@634
|
1409 } //close for (k)
|
Chris@634
|
1410 } //close for (j)
|
Chris@634
|
1411
|
Chris@634
|
1412 addsize += 2 + updates*(2 + 2 + totaltracks*(1+1));
|
Chris@634
|
1413 break;
|
Chris@634
|
1414 case 11: moov->PresetContainerBox.PresetBox[i].preset_type = 13; // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1415 strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object approximated with Equalization");
|
Chris@634
|
1416 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1417 break;
|
Chris@634
|
1418 default: printf("ERROR in PRESET CONTAINER");
|
Chris@634
|
1419 system("pause");
|
Chris@634
|
1420 exit(1);
|
Chris@634
|
1421 break;
|
Chris@634
|
1422
|
Chris@634
|
1423 } //close switch
|
Chris@634
|
1424
|
Chris@634
|
1425 temp = 16 + 50 + 4*totaltracks + addsize; // size PresetBox[i]
|
Chris@634
|
1426 moov->PresetContainerBox.PresetBox[i].size = bytereverse(temp);
|
Chris@634
|
1427
|
Chris@634
|
1428 sizePRST += temp; // size of all Preset Boxes
|
Chris@634
|
1429
|
Chris@634
|
1430 } //close for
|
Chris@634
|
1431
|
Chris@634
|
1432 //Preset Container//
|
Chris@634
|
1433 sizePRCO += sizePRST + 10;
|
Chris@634
|
1434 moov->PresetContainerBox.size = bytereverse(sizePRCO);
|
Chris@634
|
1435 moov->PresetContainerBox.type = bytereverse('prco');
|
Chris@634
|
1436 moov->PresetContainerBox.default_preset_ID = 1; // Indicates initial preset activated.
|
Chris@634
|
1437 moov->PresetContainerBox.num_preset = numpres;
|
Chris@634
|
1438
|
Chris@634
|
1439 return sizePRCO;
|
Chris@634
|
1440
|
Chris@634
|
1441 } //close function
|
Chris@634
|
1442
|
Chris@634
|
1443 int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
|
Chris@634
|
1444 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2,
|
Chris@634
|
1445 int MixRule_PAR3, int MixRule_PAR4) {
|
Chris@634
|
1446
|
Chris@634
|
1447 int swap;
|
Chris@634
|
1448 u32 add_size = 0; //for SelectionRulesBox
|
Chris@634
|
1449 u32 sizeRUSC, sizeRUCO, sizeRUMX;
|
Chris@634
|
1450
|
Chris@634
|
1451
|
Chris@634
|
1452 //Selection Rules
|
Chris@634
|
1453 moov->RulesContainer.num_selection_rules = bytereverse16(1);
|
Chris@634
|
1454 moov->RulesContainer.SelectionRules.selection_rule_ID = bytereverse16(1);
|
Chris@634
|
1455
|
Chris@634
|
1456 switch (SelRuleType) {
|
Chris@634
|
1457
|
Chris@634
|
1458 case 0: moov->RulesContainer.SelectionRules.selection_rule_type = 0;
|
Chris@634
|
1459 moov->RulesContainer.SelectionRules.element_ID = bytereverse(2147483649+1); // Must be the same ID of the group
|
Chris@634
|
1460 moov->RulesContainer.SelectionRules.min_num_elements = bytereverse16(SelRule_PAR1);
|
Chris@634
|
1461 moov->RulesContainer.SelectionRules.max_num_elements = bytereverse16(SelRule_PAR2);
|
Chris@634
|
1462 strcpy(moov->RulesContainer.SelectionRules.rule_description,"Min/Max Rule");
|
Chris@634
|
1463 add_size = 4;
|
Chris@634
|
1464 break;
|
Chris@634
|
1465 case 1: moov->RulesContainer.SelectionRules.selection_rule_type = 1;
|
Chris@634
|
1466 moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1);
|
Chris@634
|
1467 moov->RulesContainer.SelectionRules.key_element_ID =bytereverse(SelRule_PAR2);
|
Chris@634
|
1468 strcpy(moov->RulesContainer.SelectionRules.rule_description,"Exclusion Rule");
|
Chris@634
|
1469 add_size = 4;
|
Chris@634
|
1470 break;
|
Chris@634
|
1471 case 2: moov->RulesContainer.SelectionRules.selection_rule_type = 2;
|
Chris@634
|
1472 moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1);
|
Chris@634
|
1473 strcpy(moov->RulesContainer.SelectionRules.rule_description,"Not mute Rule");
|
Chris@634
|
1474 add_size = 0;
|
Chris@634
|
1475 break;
|
Chris@634
|
1476 case 3: moov->RulesContainer.SelectionRules.selection_rule_type = 3;
|
Chris@634
|
1477 moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1);
|
Chris@634
|
1478 moov->RulesContainer.SelectionRules.key_element_ID =bytereverse(SelRule_PAR2);
|
Chris@634
|
1479 strcpy(moov->RulesContainer.SelectionRules.rule_description,"Implication Rule");
|
Chris@634
|
1480 add_size = 4;
|
Chris@634
|
1481 break;
|
Chris@634
|
1482 default: printf("ERROR in RULES CONTAINER/Selection Rules");
|
Chris@634
|
1483 system("pause");
|
Chris@634
|
1484 break;
|
Chris@634
|
1485 }
|
Chris@634
|
1486
|
Chris@634
|
1487 sizeRUSC = 19 + 20 + add_size;
|
Chris@634
|
1488 moov->RulesContainer.SelectionRules.size = bytereverse(sizeRUSC);
|
Chris@634
|
1489 moov->RulesContainer.SelectionRules.type = bytereverse('rusc');
|
Chris@634
|
1490 moov->RulesContainer.SelectionRules.version = 0;
|
Chris@634
|
1491
|
Chris@634
|
1492 //Mixing Rule
|
Chris@634
|
1493 moov->RulesContainer.num_mixing_rules = bytereverse16(1);
|
Chris@634
|
1494 moov->RulesContainer.MixingRules.mixing_rule_ID = bytereverse16(1);
|
Chris@634
|
1495
|
Chris@634
|
1496 switch (MixRuleType) {
|
Chris@634
|
1497
|
Chris@634
|
1498 case 0: moov->RulesContainer.MixingRules.mixing_type = 0;
|
Chris@634
|
1499 moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR1);
|
Chris@634
|
1500 moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR2);
|
Chris@634
|
1501 strcpy(moov->RulesContainer.MixingRules.mix_description, "Equivalence rule");
|
Chris@634
|
1502 break;
|
Chris@634
|
1503 case 1: moov->RulesContainer.MixingRules.mixing_type = 1;
|
Chris@634
|
1504 moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR2);
|
Chris@634
|
1505 moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR1);
|
Chris@634
|
1506 strcpy(moov->RulesContainer.MixingRules.mix_description, "Upper rule");
|
Chris@634
|
1507 break;
|
Chris@634
|
1508 case 2: moov->RulesContainer.MixingRules.mixing_type = 2;
|
Chris@634
|
1509 moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR2);
|
Chris@634
|
1510 moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR1);
|
Chris@634
|
1511 strcpy(moov->RulesContainer.MixingRules.mix_description, "Lower rule");
|
Chris@634
|
1512 break;
|
Chris@634
|
1513 case 3: moov->RulesContainer.MixingRules.mixing_type = 3;
|
Chris@634
|
1514 moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR1);
|
Chris@634
|
1515 moov->RulesContainer.MixingRules.min_volume = bytereverse16(1 + MixRule_PAR3*2.5); // 8.8 fixed point
|
Chris@634
|
1516 moov->RulesContainer.MixingRules.max_volume = bytereverse16(1 + MixRule_PAR4*2.5); // 8.8 fixed point
|
Chris@634
|
1517 strcpy(moov->RulesContainer.MixingRules.mix_description, "Limit rule");
|
Chris@634
|
1518 break;
|
Chris@634
|
1519 default: printf("ERROR in RULES CONTAINER/Mixing Rules");
|
Chris@634
|
1520 system("pause");
|
Chris@634
|
1521 exit(1);
|
Chris@634
|
1522 break;
|
Chris@634
|
1523 }
|
Chris@634
|
1524
|
Chris@634
|
1525 sizeRUMX = 23 + 17;
|
Chris@634
|
1526 moov->RulesContainer.MixingRules.size = bytereverse(sizeRUMX);
|
Chris@634
|
1527 moov->RulesContainer.MixingRules.type = bytereverse('rumx');
|
Chris@634
|
1528 moov->RulesContainer.MixingRules.version = 0;
|
Chris@634
|
1529
|
Chris@634
|
1530 //Rule container
|
Chris@634
|
1531 sizeRUCO = 12 + sizeRUSC + sizeRUMX;
|
Chris@634
|
1532 swap = bytereverse(sizeRUCO);
|
Chris@634
|
1533 moov->RulesContainer.size = swap;
|
Chris@634
|
1534 swap = bytereverse('ruco');
|
Chris@634
|
1535 moov->RulesContainer.type = swap;
|
Chris@634
|
1536
|
Chris@634
|
1537 return sizeRUCO;
|
Chris@634
|
1538
|
Chris@634
|
1539 } // close function
|
Chris@634
|
1540
|
Chris@634
|
1541 void moovheaderbox (MovieBox *moov, int clock, int sizeTRAK, int sizePRCO, int totaltracks,
|
Chris@634
|
1542 int durationTrack, int sizeRUCO, int sizeGRCO) {
|
Chris@634
|
1543 int swap;
|
Chris@634
|
1544 u32 sizeMOOV; //MovieBox
|
Chris@634
|
1545
|
Chris@634
|
1546 //MovieHeader
|
Chris@634
|
1547 u32 sizeMVHD = 108;
|
Chris@634
|
1548 swap = bytereverse (sizeMVHD);
|
Chris@634
|
1549 moov->MovieHeaderBox.size = swap;
|
Chris@634
|
1550 swap = bytereverse ('mvhd');
|
Chris@634
|
1551 moov->MovieHeaderBox.type = swap;
|
Chris@634
|
1552 moov->MovieHeaderBox.version = 0;
|
Chris@634
|
1553 swap = bytereverse (clock);
|
Chris@634
|
1554 moov->MovieHeaderBox.creation_time = swap;
|
Chris@634
|
1555 moov->MovieHeaderBox.modification_time = swap;
|
Chris@634
|
1556 swap = bytereverse (1000);
|
Chris@634
|
1557 moov->MovieHeaderBox.timescale = swap;
|
Chris@634
|
1558 swap = bytereverse (durationTrack);
|
Chris@634
|
1559 moov->MovieHeaderBox.duration = swap;
|
Chris@634
|
1560 swap = bytereverse (0x00010000);
|
Chris@634
|
1561 moov->MovieHeaderBox.rate = swap;
|
Chris@634
|
1562 swap = bytereverse (1);
|
Chris@634
|
1563 moov->MovieHeaderBox.volume = 1;
|
Chris@634
|
1564 moov->MovieHeaderBox.reserved=0;
|
Chris@634
|
1565 moov->MovieHeaderBox.reserved2[0] = 0;
|
Chris@634
|
1566 moov->MovieHeaderBox.reserved2[1] = 0;
|
Chris@634
|
1567 swap = bytereverse (0x00010000);
|
Chris@634
|
1568 moov->MovieHeaderBox.matrix[0] = swap;
|
Chris@634
|
1569 moov->MovieHeaderBox.matrix[1] = 0;
|
Chris@634
|
1570 moov->MovieHeaderBox.matrix[2] = 0;
|
Chris@634
|
1571 moov->MovieHeaderBox.matrix[3] = 0;
|
Chris@634
|
1572 moov->MovieHeaderBox.matrix[4] = swap;
|
Chris@634
|
1573 moov->MovieHeaderBox.matrix[5] = 0;
|
Chris@634
|
1574 moov->MovieHeaderBox.matrix[6] = 0;
|
Chris@634
|
1575 moov->MovieHeaderBox.matrix[7] = 0;
|
Chris@634
|
1576 swap = bytereverse (0x40000000);
|
Chris@634
|
1577 moov->MovieHeaderBox.matrix[8] = 0x40000000;
|
Chris@634
|
1578 moov->MovieHeaderBox.pre_defined[0] = 0;
|
Chris@634
|
1579 moov->MovieHeaderBox.pre_defined[1] = 0;
|
Chris@634
|
1580 moov->MovieHeaderBox.pre_defined[2] = 0;
|
Chris@634
|
1581 moov->MovieHeaderBox.pre_defined[3] = 0;
|
Chris@634
|
1582 moov->MovieHeaderBox.pre_defined[4] = 0;
|
Chris@634
|
1583 moov->MovieHeaderBox.pre_defined[5] = 0;
|
Chris@634
|
1584 swap = bytereverse (totaltracks + 1);
|
Chris@634
|
1585 moov->MovieHeaderBox.next_track_ID = swap;
|
Chris@634
|
1586
|
Chris@634
|
1587 //MovieBox
|
Chris@634
|
1588 sizeMOOV = sizeMVHD + sizeTRAK + sizePRCO + sizeRUCO + sizeGRCO + 8;
|
Chris@634
|
1589 swap = bytereverse (sizeMOOV); //Size movie: Taking into account number tracks
|
Chris@634
|
1590 moov->size = swap;
|
Chris@634
|
1591 swap = bytereverse ('moov');
|
Chris@634
|
1592 moov->type = swap;
|
Chris@634
|
1593 }
|
Chris@634
|
1594
|
Chris@634
|
1595
|
Chris@636
|
1596 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile)
|
Chris@634
|
1597 {
|
Chris@634
|
1598 int i, j, k, m, t, swap, pos, temp, type;
|
Chris@634
|
1599 int cnt = 0, cnt2 = 0, d = 0, dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, size = 0;
|
Chris@634
|
1600 u16 numgroups, numel;
|
Chris@634
|
1601
|
Chris@634
|
1602
|
Chris@634
|
1603 //Write movie box//
|
Chris@634
|
1604 fwrite(&moov.size, sizeof(u32), 1, imf);
|
Chris@634
|
1605 fwrite(&moov.type, sizeof(u32), 1, imf);
|
Chris@634
|
1606 //Movie header//
|
Chris@634
|
1607 fwrite(&moov.MovieHeaderBox, sizeof(moov.MovieHeaderBox), 1, imf);
|
Chris@634
|
1608 //Track container//
|
Chris@634
|
1609 for (numtrack = 0; numtrack < totaltracks; numtrack++) {
|
Chris@634
|
1610 fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf);
|
Chris@634
|
1611 fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf);
|
Chris@634
|
1612 //Trck header//
|
Chris@634
|
1613 fwrite(&moov.TrackBox[numtrack].TrackHeaderBox, sizeof(moov.TrackBox[numtrack].TrackHeaderBox), 1, imf);
|
Chris@634
|
1614 //Media Box//
|
Chris@634
|
1615 fwrite(&moov.TrackBox[numtrack].MediaBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1616 fwrite(&moov.TrackBox[numtrack].MediaBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1617 //Media Header//
|
Chris@634
|
1618 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaHeaderBox,
|
Chris@634
|
1619 sizeof(moov.TrackBox[numtrack].MediaBox.MediaHeaderBox), 1, imf);
|
Chris@634
|
1620 //Handler Box//
|
Chris@634
|
1621 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1622 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1623 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1624 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.pre_defined, sizeof(u32), 1, imf);
|
Chris@634
|
1625 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.handler_type, sizeof(u32), 1, imf);
|
Chris@634
|
1626 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[0], sizeof(u32), 1, imf);
|
Chris@634
|
1627 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[1], sizeof(u32), 1, imf);
|
Chris@634
|
1628 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[2], sizeof(u32), 1, imf);
|
Chris@634
|
1629 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[0], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1630 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[1], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1631 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[2], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1632 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[3], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1633 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[4], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1634 //Media inforamtion box//
|
Chris@634
|
1635 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1636 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1637 //Sound media header//
|
Chris@634
|
1638 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox,
|
Chris@634
|
1639 sizeof(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox), 1, imf);
|
Chris@634
|
1640 //Data reference//
|
Chris@634
|
1641 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox,
|
Chris@634
|
1642 sizeof(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox), 1, imf);
|
Chris@634
|
1643 //Sample table box//
|
Chris@634
|
1644 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1645 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1646
|
Chris@634
|
1647 //Time to sample box//
|
Chris@634
|
1648 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1649 TimeToSampleBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1650 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1651 TimeToSampleBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1652 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1653 TimeToSampleBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1654 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1655 TimeToSampleBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
1656
|
Chris@634
|
1657 swap = bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1658 TimeToSampleBox.entry_count);
|
Chris@634
|
1659 pos = swap;
|
Chris@634
|
1660
|
Chris@634
|
1661 for (i=0; i<pos; i++) {
|
Chris@634
|
1662
|
Chris@634
|
1663 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1664 TimeToSampleBox.sample_count[i], sizeof(u32), 1, imf);
|
Chris@634
|
1665 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1666 TimeToSampleBox.sample_delta[i], sizeof(u32), 1, imf);
|
Chris@634
|
1667 }
|
Chris@634
|
1668
|
Chris@634
|
1669 //Sample description box//
|
Chris@634
|
1670 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1671 SampleDescriptionBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1672 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1673 SampleDescriptionBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1674 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1675 SampleDescriptionBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1676 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1677 SampleDescriptionBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
1678 //Audio Sample entry//
|
Chris@634
|
1679 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1680 SampleDescriptionBox.AudioSampleEntry.size, sizeof(u32), 1, imf);
|
Chris@634
|
1681 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1682 SampleDescriptionBox.AudioSampleEntry.type, sizeof(u32), 1, imf);
|
Chris@634
|
1683 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1684 SampleDescriptionBox.AudioSampleEntry.reserved[0], sizeof(unsigned char), 6, imf);
|
Chris@634
|
1685 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1686 SampleDescriptionBox.AudioSampleEntry.data_reference_index, sizeof(u16), 1, imf);
|
Chris@634
|
1687 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1688 SampleDescriptionBox.AudioSampleEntry.reserved2[0], sizeof(u32), 2, imf);
|
Chris@634
|
1689 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1690 SampleDescriptionBox.AudioSampleEntry.channelcount, sizeof(u16), 1, imf);
|
Chris@634
|
1691 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1692 SampleDescriptionBox.AudioSampleEntry.samplesize, sizeof(u16), 1, imf);
|
Chris@634
|
1693 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1694 SampleDescriptionBox.AudioSampleEntry.reserved3, sizeof(u32), 1, imf);
|
Chris@634
|
1695 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1696 SampleDescriptionBox.AudioSampleEntry.samplerate, sizeof(u32), 1, imf);
|
Chris@634
|
1697 //ESDBox//
|
Chris@634
|
1698 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1699 SampleDescriptionBox.AudioSampleEntry.ESbox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1700 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1701 SampleDescriptionBox.AudioSampleEntry.ESbox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1702 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1703 SampleDescriptionBox.AudioSampleEntry.ESbox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1704 //ES Descriptor//
|
Chris@634
|
1705 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1706 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.tag
|
Chris@634
|
1707 , sizeof(unsigned char), 1, imf);
|
Chris@634
|
1708 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1709 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.length
|
Chris@634
|
1710 , sizeof(unsigned char), 1, imf);
|
Chris@634
|
1711 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1712 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.ES_ID
|
Chris@634
|
1713 , sizeof(u16), 1, imf);
|
Chris@634
|
1714 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1715 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.mix
|
Chris@634
|
1716 , sizeof(unsigned char), 1, imf);
|
Chris@634
|
1717 //Decoder Config//
|
Chris@634
|
1718 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1719 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1720 tag, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1721 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1722 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1723 length, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1724 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1725 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1726 objectProfileInd, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1727 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1728 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1729 mix, sizeof(u32), 1, imf);
|
Chris@634
|
1730 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1731 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1732 maxBitRate, sizeof(u32), 1, imf);
|
Chris@634
|
1733 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1734 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1735 avgBitrate, sizeof(u32), 1, imf);
|
Chris@634
|
1736 /* //DecoderSpecificInfo//
|
Chris@634
|
1737 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1738 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1739 DecoderSpecificInfo.tag, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1740 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1741 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1742 DecoderSpecificInfo.length, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1743 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1744 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1745 DecoderSpecificInfo.decSpecificInfoData[0], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1746 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1747 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.DecoderConfigDescriptor.
|
Chris@634
|
1748 DecoderSpecificInfo.decSpecificInfoData[1], sizeof(unsigned char), 1, imf);
|
Chris@634
|
1749 */ //SLConfig//
|
Chris@634
|
1750 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1751 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.SLConfigDescriptor.
|
Chris@634
|
1752 tag, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1753 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1754 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.SLConfigDescriptor.
|
Chris@634
|
1755 length, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1756 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1757 SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.SLConfigDescriptor.
|
Chris@634
|
1758 predifined, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1759
|
Chris@634
|
1760
|
Chris@634
|
1761 //Sample Size box//
|
Chris@634
|
1762 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1763 SampleSizeBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1764 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1765 SampleSizeBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1766 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1767 SampleSizeBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1768 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1769 SampleSizeBox.sample_size, sizeof(u32), 1, imf);
|
Chris@634
|
1770 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1771 SampleSizeBox.sample_count, sizeof(u32), 1, imf);
|
Chris@634
|
1772 swap = bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1773 SampleSizeBox.sample_count);
|
Chris@634
|
1774 for(i=0; i<swap; i++){
|
Chris@634
|
1775 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1776 SampleSizeBox.entry_size[i], sizeof(u32), 1, imf);
|
Chris@634
|
1777 }
|
Chris@634
|
1778
|
Chris@634
|
1779 //Sample to chunk box//
|
Chris@634
|
1780 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1781 SampleToChunk.size, sizeof(u32), 1, imf);
|
Chris@634
|
1782 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1783 SampleToChunk.type, sizeof(u32), 1, imf);
|
Chris@634
|
1784 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1785 SampleToChunk.version, sizeof(u32), 1, imf);
|
Chris@634
|
1786 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1787 SampleToChunk.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
1788 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1789 SampleToChunk.first_chunk, sizeof(u32), 1, imf);
|
Chris@634
|
1790 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1791 SampleToChunk.samples_per_chunk, sizeof(u32), 1, imf);
|
Chris@634
|
1792 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1793 SampleToChunk.sample_description_index, sizeof(u32), 1, imf);
|
Chris@634
|
1794
|
Chris@634
|
1795 //Chunk offset//
|
Chris@634
|
1796 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1797 ChunkOffsetBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1798 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1799 ChunkOffsetBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1800 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1801 ChunkOffsetBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
1802 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1803 ChunkOffsetBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
1804 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
1805 ChunkOffsetBox.chunk_offset[numtrack], sizeof(u32), 1, imf);
|
Chris@634
|
1806 }
|
Chris@634
|
1807
|
Chris@634
|
1808 //Group Container
|
Chris@634
|
1809 fwrite(&moov.GroupContainerBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1810 fwrite(&moov.GroupContainerBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1811 fwrite(&moov.GroupContainerBox.num_groups, sizeof(u16), 1, imf);
|
Chris@634
|
1812 //Group Box
|
Chris@634
|
1813 numgroups = bytereverse16(moov.GroupContainerBox.num_groups);
|
Chris@634
|
1814 for(i=0; i<numgroups; i++){
|
Chris@634
|
1815 fwrite(&moov.GroupContainerBox.GroupBox[i].size, sizeof(u32), 1, imf);
|
Chris@634
|
1816 fwrite(&moov.GroupContainerBox.GroupBox[i].type, sizeof(u32), 1, imf);
|
Chris@634
|
1817 fwrite(&moov.GroupContainerBox.GroupBox[i].version, sizeof(u32), 1, imf);
|
Chris@634
|
1818 fwrite(&moov.GroupContainerBox.GroupBox[i].group_ID, sizeof(u32), 1, imf);
|
Chris@634
|
1819 fwrite(&moov.GroupContainerBox.GroupBox[i].num_elements, sizeof(u16), 1, imf);
|
Chris@634
|
1820 numel = bytereverse16(moov.GroupContainerBox.GroupBox[i].num_elements);
|
Chris@634
|
1821 for(j=0; j<numel; j++){
|
Chris@634
|
1822 fwrite(&moov.GroupContainerBox.GroupBox[i].groupElemId[j].element_ID, sizeof(u32), 1, imf);
|
Chris@634
|
1823 }
|
Chris@634
|
1824 fwrite(&moov.GroupContainerBox.GroupBox[i].group_activation_mode, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1825 if(moov.GroupContainerBox.GroupBox[i].group_activation_mode==2){
|
Chris@634
|
1826 fwrite(&moov.GroupContainerBox.GroupBox[i].group_activation_elements_number, sizeof(u16), 1, imf);
|
Chris@634
|
1827 }
|
Chris@634
|
1828 fwrite(&moov.GroupContainerBox.GroupBox[i].group_reference_volume, sizeof(u16), 1, imf);
|
Chris@634
|
1829 for (j=0; j<22; j++) {
|
Chris@634
|
1830 fwrite(&moov.GroupContainerBox.GroupBox[i].group_name[j], sizeof(char), 1, imf);
|
Chris@634
|
1831 }
|
Chris@634
|
1832 for (j=0; j<32; j++) {
|
Chris@634
|
1833 fwrite(&moov.GroupContainerBox.GroupBox[i].group_description[j], sizeof(char), 1, imf);
|
Chris@634
|
1834 }
|
Chris@634
|
1835
|
Chris@634
|
1836 }
|
Chris@634
|
1837
|
Chris@634
|
1838 //PresetContainerBox
|
Chris@634
|
1839 fwrite(&moov.PresetContainerBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
1840 fwrite(&moov.PresetContainerBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
1841 fwrite(&moov.PresetContainerBox.num_preset, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1842 fwrite(&moov.PresetContainerBox.default_preset_ID, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1843
|
Chris@634
|
1844 //Preset Box
|
Chris@634
|
1845 for (i=0; i<moov.PresetContainerBox.num_preset; i++) {
|
Chris@634
|
1846 fwrite(&moov.PresetContainerBox.PresetBox[i].size, sizeof(u32), 1, imf);
|
Chris@634
|
1847 fwrite(&moov.PresetContainerBox.PresetBox[i].type, sizeof(u32), 1, imf);
|
Chris@634
|
1848 fwrite(&moov.PresetContainerBox.PresetBox[i].flags, sizeof(u32), 1, imf);
|
Chris@634
|
1849 fwrite(&moov.PresetContainerBox.PresetBox[i].preset_ID, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1850 fwrite(&moov.PresetContainerBox.PresetBox[i].num_preset_elements, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1851 for (j=0; j< moov.PresetContainerBox.PresetBox[i].num_preset_elements; j++) {
|
Chris@634
|
1852 fwrite(&moov.PresetContainerBox.PresetBox[i].presElemId[j].
|
Chris@634
|
1853 preset_element_ID, sizeof(u32), 1, imf);
|
Chris@634
|
1854 }
|
Chris@634
|
1855 fwrite(&moov.PresetContainerBox.PresetBox[i].preset_type , sizeof(unsigned char), 1, imf);
|
Chris@634
|
1856 fwrite(&moov.PresetContainerBox.PresetBox[i].preset_global_volume, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1857
|
Chris@634
|
1858 type = moov.PresetContainerBox.PresetBox[i].preset_type;
|
Chris@634
|
1859
|
Chris@634
|
1860 switch(type){
|
Chris@634
|
1861
|
Chris@634
|
1862 case 0: for (j=0; j< moov.PresetContainerBox.PresetBox[i].num_preset_elements; j++) {
|
Chris@634
|
1863 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].
|
Chris@634
|
1864 preset_volume_element,sizeof(unsigned char), 1, imf);
|
Chris@634
|
1865 }
|
Chris@634
|
1866 break;
|
Chris@634
|
1867 case 1: for (j=0; j<num_ch; j++){
|
Chris@634
|
1868 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticObjectVolume.InputCH[j].
|
Chris@634
|
1869 num_input_channel,sizeof(unsigned char), 1, imf);
|
Chris@634
|
1870 }
|
Chris@634
|
1871 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticObjectVolume.output_channel_type, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1872 for (j=0; j<totaltracks; j++){
|
Chris@634
|
1873 for (k=0; k<num_ch; k++){
|
Chris@634
|
1874 for (m=0; m<num_ch; m++){
|
Chris@634
|
1875 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticObjectVolume.presElVol[j].
|
Chris@634
|
1876 Input[k].Output[m].preset_volume_element, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1877 }
|
Chris@634
|
1878 }
|
Chris@634
|
1879 }
|
Chris@634
|
1880 break;
|
Chris@634
|
1881 case 2: fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackVolume.num_updates, sizeof(u16), 1, imf);
|
Chris@634
|
1882 temp = bytereverse16(moov.PresetContainerBox.PresetBox[i].DynamicTrackVolume.num_updates);
|
Chris@634
|
1883 for (j=0; j<temp; j++){
|
Chris@634
|
1884 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackVolume.
|
Chris@634
|
1885 DynamicChange[j].updated_sample_number, sizeof(u16), 1, imf);
|
Chris@634
|
1886 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1887 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackVolume.DynamicChange[j].
|
Chris@634
|
1888 presVolumElem[k].preset_volume_element, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1889 }
|
Chris@634
|
1890 }
|
Chris@634
|
1891 break;
|
Chris@634
|
1892 case 3: fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.num_updates, sizeof(u16), 1, imf);
|
Chris@634
|
1893 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1894 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.InputCH[j].num_input_channel, sizeof(u8), 1, imf);
|
Chris@634
|
1895 }
|
Chris@634
|
1896 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.output_channel_type, sizeof(u8), 1, imf);
|
Chris@634
|
1897 temp = bytereverse16(moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.num_updates);
|
Chris@634
|
1898 for (j=0; j<temp; j++){
|
Chris@634
|
1899 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.
|
Chris@634
|
1900 DynamicChange[j].updated_sample_number, sizeof(u16), 1, imf);
|
Chris@634
|
1901 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1902 for (m=0; m<num_ch; m++){
|
Chris@634
|
1903 for (t=0; t<num_ch; t++){
|
Chris@634
|
1904 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectVolume.DynamicChange[j].
|
Chris@634
|
1905 presElVol[k].Input[m].Output[t].preset_volume_element, sizeof(u8), 1, imf);
|
Chris@634
|
1906 }
|
Chris@634
|
1907 }
|
Chris@634
|
1908 }
|
Chris@634
|
1909 }
|
Chris@634
|
1910 break;
|
Chris@634
|
1911 case 4: fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates, sizeof(u16), 1, imf);
|
Chris@634
|
1912 temp = bytereverse16(moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates);
|
Chris@634
|
1913 for (j=0; j<temp; j++){
|
Chris@634
|
1914 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1915 DynamicChange[j].start_sample_number, sizeof(u16), 1, imf);
|
Chris@634
|
1916 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1917 DynamicChange[j].duration_update, sizeof(u16), 1, imf);
|
Chris@634
|
1918 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1919 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j].
|
Chris@634
|
1920 presElVol[k].end_preset_volume_element, sizeof(unsigned char), 1, imf);
|
Chris@634
|
1921 }
|
Chris@634
|
1922 }
|
Chris@634
|
1923 break;
|
Chris@634
|
1924 case 5: // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1925 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1926 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.num_updates, sizeof(u16), 1, imf);
|
Chris@634
|
1927 for (j=0; j<totaltracks; j++) {
|
Chris@634
|
1928 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.InputCH[j].num_input_channel, sizeof(u8), 1, imf);
|
Chris@634
|
1929 }
|
Chris@634
|
1930 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.output_channel_type, sizeof(u8), 1, imf);
|
Chris@634
|
1931 temp = bytereverse16(moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.num_updates);
|
Chris@634
|
1932 for (j=0; j<temp; j++){
|
Chris@634
|
1933 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.
|
Chris@634
|
1934 DynamicChange[j].start_sample_number, sizeof(u16), 1, imf);
|
Chris@634
|
1935 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.
|
Chris@634
|
1936 DynamicChange[j].duration_update, sizeof(u16), 1, imf);
|
Chris@634
|
1937 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1938 for (m=0; m<num_ch; m++){
|
Chris@634
|
1939 for (t=0; t<num_ch; t++){
|
Chris@634
|
1940 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.DynamicChange[j].
|
Chris@634
|
1941 presElVol[k].Input[m].Output[t].preset_volume_element, sizeof(u8), 1, imf);
|
Chris@634
|
1942 }
|
Chris@634
|
1943 }
|
Chris@634
|
1944 }
|
Chris@634
|
1945 }
|
Chris@634
|
1946 break;
|
Chris@634
|
1947 case 6: printf("\nERROR WRITING PRESET CONTAINER IN OUTPUT FILE - Not valid case (6)\n");
|
Chris@634
|
1948 system("pause");
|
Chris@634
|
1949 exit(1);
|
Chris@634
|
1950 break;
|
Chris@634
|
1951 case 7: printf("\nERROR WRITING PRESET CONTAINER IN OUTPUT FILE - Not valid case (7)\n");
|
Chris@634
|
1952 system("pause");
|
Chris@634
|
1953 exit(1);
|
Chris@634
|
1954 break;
|
Chris@634
|
1955 case 8: for (j=0; j< moov.PresetContainerBox.PresetBox[i].num_preset_elements; j++) {
|
Chris@634
|
1956 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].
|
Chris@634
|
1957 preset_volume_element,sizeof(unsigned char), 1, imf);
|
Chris@634
|
1958 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters, sizeof(u8), 1, imf);
|
Chris@634
|
1959 //EQ
|
Chris@634
|
1960 if (moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters != 0) {
|
Chris@634
|
1961 for (k=0; k<moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters; k++){
|
Chris@634
|
1962 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.
|
Chris@634
|
1963 presVolumElem[j].EQ.Filter[k].filter_type, sizeof(u8), 1, imf);
|
Chris@634
|
1964 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.
|
Chris@634
|
1965 presVolumElem[j].EQ.Filter[k].filter_reference_frequency, sizeof(u16), 1, imf);
|
Chris@634
|
1966 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.
|
Chris@634
|
1967 presVolumElem[j].EQ.Filter[k].filter_gain, sizeof(u8), 1, imf);
|
Chris@634
|
1968 fwrite(&moov.PresetContainerBox.PresetBox[i].StaticTrackVolume.
|
Chris@634
|
1969 presVolumElem[j].EQ.Filter[k].filter_bandwidth, sizeof(u8), 1, imf);
|
Chris@634
|
1970 } //close for
|
Chris@634
|
1971 } //close if
|
Chris@634
|
1972 }
|
Chris@634
|
1973 break;
|
Chris@634
|
1974 case 9: // NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1975 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1976 break;
|
Chris@634
|
1977 case 10:// NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1978 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1979 break;
|
Chris@634
|
1980 case 11:// NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1981 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1982 break;
|
Chris@634
|
1983 case 12:// NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
1984 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
1985 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates, sizeof(u16), 1, imf);
|
Chris@634
|
1986 temp = bytereverse16(moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates);
|
Chris@634
|
1987 for (j=0; j<temp; j++){
|
Chris@634
|
1988 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1989 DynamicChange[j].start_sample_number, sizeof(u16), 1, imf);
|
Chris@634
|
1990 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1991 DynamicChange[j].duration_update, sizeof(u16), 1, imf);
|
Chris@634
|
1992 for (k=0; k<totaltracks; k++){
|
Chris@634
|
1993 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j].
|
Chris@634
|
1994 presElVol[k].end_preset_volume_element, sizeof(u8), 1, imf);
|
Chris@634
|
1995 //EQ
|
Chris@634
|
1996 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1997 DynamicChange[j].presElVol[k].EQ.num_eq_filters, sizeof(u8), 1, imf);
|
Chris@634
|
1998 if(moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
1999 DynamicChange[j].presElVol[k].EQ.num_eq_filters != 0){
|
Chris@634
|
2000 for (t=0; t<moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
2001 DynamicChange[j].presElVol[k].EQ.num_eq_filters; t++){
|
Chris@634
|
2002 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
2003 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_type, sizeof(u8), 1, imf);
|
Chris@634
|
2004 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
2005 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_reference_frequency, sizeof(u16), 1, imf);
|
Chris@634
|
2006 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
2007 DynamicChange[j].presElVol[k].EQ.Filter[t].end_filter_gain, sizeof(u8), 1, imf);
|
Chris@634
|
2008 fwrite(&moov.PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.
|
Chris@634
|
2009 DynamicChange[j].presElVol[k].EQ.Filter[t].filter_bandwidth, sizeof(u8), 1, imf);
|
Chris@634
|
2010 } // close for (t)
|
Chris@634
|
2011 }//close if
|
Chris@634
|
2012
|
Chris@634
|
2013 }// close for (k)
|
Chris@634
|
2014 } //close for (j)
|
Chris@634
|
2015 break;
|
Chris@634
|
2016 case 13:// NOT YET IMPLEMENTED INTO THE PLAYER!
|
Chris@634
|
2017 printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n");
|
Chris@634
|
2018 break;
|
Chris@634
|
2019 default: printf("\nERROR WRITING PRESET CONTAINER IN OUTPUT FILE - Not valid case (default)\n");
|
Chris@634
|
2020 system("pause");
|
Chris@634
|
2021 exit(1);
|
Chris@634
|
2022 break;
|
Chris@634
|
2023
|
Chris@634
|
2024 } // close switch
|
Chris@634
|
2025
|
Chris@634
|
2026 for (j=0; j<50; j++) {
|
Chris@634
|
2027 fwrite(&moov.PresetContainerBox.PresetBox[i].preset_name[j], sizeof(char), 1, imf);
|
Chris@634
|
2028 }
|
Chris@634
|
2029
|
Chris@634
|
2030 } // close for
|
Chris@634
|
2031
|
Chris@634
|
2032
|
Chris@634
|
2033 //Rules Container//
|
Chris@634
|
2034 fwrite(&moov.RulesContainer.size, sizeof(u32), 1, imf);
|
Chris@634
|
2035 fwrite(&moov.RulesContainer.type, sizeof(u32), 1, imf);
|
Chris@634
|
2036 fwrite(&moov.RulesContainer.num_selection_rules, sizeof(u16), 1, imf);
|
Chris@634
|
2037 fwrite(&moov.RulesContainer.num_mixing_rules, sizeof(u16), 1, imf);
|
Chris@634
|
2038 //Selection Rules//
|
Chris@634
|
2039 fwrite(&moov.RulesContainer.SelectionRules.size, sizeof(u32), 1, imf);
|
Chris@634
|
2040 fwrite(&moov.RulesContainer.SelectionRules.type, sizeof(u32), 1, imf);
|
Chris@634
|
2041 fwrite(&moov.RulesContainer.SelectionRules.version, sizeof(u32), 1, imf);
|
Chris@634
|
2042 fwrite(&moov.RulesContainer.SelectionRules.selection_rule_ID, sizeof(u16), 1, imf);
|
Chris@634
|
2043 fwrite(&moov.RulesContainer.SelectionRules.selection_rule_type, sizeof(unsigned char), 1, imf);
|
Chris@634
|
2044 fwrite(&moov.RulesContainer.SelectionRules.element_ID, sizeof(u32), 1, imf);
|
Chris@634
|
2045
|
Chris@634
|
2046 swap = moov.RulesContainer.SelectionRules.selection_rule_type;
|
Chris@634
|
2047 if ( swap==0 ) {
|
Chris@634
|
2048 fwrite(&moov.RulesContainer.SelectionRules.min_num_elements, sizeof(u16), 1, imf);
|
Chris@634
|
2049 fwrite(&moov.RulesContainer.SelectionRules.max_num_elements, sizeof(u16), 1, imf);
|
Chris@634
|
2050 }
|
Chris@634
|
2051 if ( swap==1 || swap ==3 ){
|
Chris@634
|
2052 fwrite(&moov.RulesContainer.SelectionRules.key_element_ID, sizeof(u32), 1, imf);
|
Chris@634
|
2053 }
|
Chris@634
|
2054
|
Chris@634
|
2055 for(i=0; i<20; i++){
|
Chris@634
|
2056 fwrite(&moov.RulesContainer.SelectionRules.rule_description[i], sizeof(char), 1, imf);
|
Chris@634
|
2057 }
|
Chris@634
|
2058
|
Chris@634
|
2059 //Mixing Rules//
|
Chris@634
|
2060 fwrite(&moov.RulesContainer.MixingRules.size, sizeof(u32), 1, imf);
|
Chris@634
|
2061 fwrite(&moov.RulesContainer.MixingRules.type, sizeof(u32), 1, imf);
|
Chris@634
|
2062 fwrite(&moov.RulesContainer.MixingRules.version, sizeof(u32), 1, imf);
|
Chris@634
|
2063 fwrite(&moov.RulesContainer.MixingRules.mixing_rule_ID, sizeof(u16), 1, imf);
|
Chris@634
|
2064 fwrite(&moov.RulesContainer.MixingRules.mixing_type,sizeof(unsigned char), 1, imf);
|
Chris@634
|
2065 fwrite(&moov.RulesContainer.MixingRules.element_ID, sizeof(u32), 1, imf);
|
Chris@634
|
2066
|
Chris@634
|
2067 swap = moov.RulesContainer.MixingRules.mixing_type;
|
Chris@634
|
2068 if( swap==3 ){
|
Chris@634
|
2069 fwrite(&moov.RulesContainer.MixingRules.min_volume, sizeof(u16), 1, imf);
|
Chris@634
|
2070 fwrite(&moov.RulesContainer.MixingRules.max_volume, sizeof(u16), 1, imf);
|
Chris@634
|
2071 } else {
|
Chris@634
|
2072 fwrite(&moov.RulesContainer.MixingRules.key_elem_ID, sizeof(u32), 1, imf);
|
Chris@634
|
2073 }
|
Chris@634
|
2074 for(i=0; i<17; i++){
|
Chris@634
|
2075 fwrite(&moov.RulesContainer.MixingRules.mix_description[i],
|
Chris@634
|
2076 sizeof(char), 1, imf);
|
Chris@634
|
2077 }
|
Chris@634
|
2078
|
Chris@634
|
2079 //TIMED TEXT
|
Chris@636
|
2080
|
Chris@636
|
2081 if (HasTextFile){
|
Chris@634
|
2082 fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf);
|
Chris@634
|
2083 fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf);
|
Chris@634
|
2084 //Track header//
|
Chris@634
|
2085 fwrite(&moov.TrackBox[numtrack].TrackHeaderBox,
|
Chris@634
|
2086 sizeof(moov.TrackBox[numtrack].TrackHeaderBox), 1, imf);
|
Chris@634
|
2087 //Media Box//
|
Chris@634
|
2088 fwrite(&moov.TrackBox[numtrack].MediaBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2089 fwrite(&moov.TrackBox[numtrack].MediaBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2090 //Media Header//
|
Chris@634
|
2091 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaHeaderBox,
|
Chris@634
|
2092 sizeof(moov.TrackBox[numtrack].MediaBox.MediaHeaderBox), 1, imf);
|
Chris@634
|
2093 //Handler Box//
|
Chris@634
|
2094 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2095 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2096 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2097 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.pre_defined, sizeof(u32), 1, imf);
|
Chris@634
|
2098 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.handler_type, sizeof(u32), 1, imf);
|
Chris@634
|
2099 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[0], sizeof(u32), 1, imf);
|
Chris@634
|
2100 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[1], sizeof(u32), 1, imf);
|
Chris@634
|
2101 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[2], sizeof(u32), 1, imf);
|
Chris@634
|
2102 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[0], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2103 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[1], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2104 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[2], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2105 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[3], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2106 fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[4], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2107 //Media information box//
|
Chris@634
|
2108 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2109 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2110 //Null media header//
|
Chris@634
|
2111 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.size,
|
Chris@634
|
2112 sizeof(u32), 1, imf);
|
Chris@634
|
2113 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.type,
|
Chris@634
|
2114 sizeof(u32), 1, imf);
|
Chris@634
|
2115 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.flags,
|
Chris@634
|
2116 sizeof(u32), 1, imf);
|
Chris@634
|
2117 //Data Information
|
Chris@634
|
2118 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.size,sizeof(u32),1,imf);
|
Chris@634
|
2119 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.type,sizeof(u32),1,imf);
|
Chris@634
|
2120 //Data Reference
|
Chris@634
|
2121 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.size,sizeof(u32),1,imf);
|
Chris@634
|
2122 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.type,sizeof(u32),1,imf);
|
Chris@634
|
2123 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.flags,sizeof(u32),1,imf);
|
Chris@634
|
2124 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.entry_count,sizeof(u32),1,imf);
|
Chris@634
|
2125 //Data Entry URL
|
Chris@634
|
2126 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryUrlBox.size,sizeof(u32),1,imf);
|
Chris@634
|
2127 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryUrlBox.type,sizeof(u32),1,imf);
|
Chris@634
|
2128 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryUrlBox.flags,sizeof(u32),1,imf);
|
Chris@634
|
2129 //Sample table box//
|
Chris@634
|
2130 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2131 size, sizeof(u32), 1, imf);
|
Chris@634
|
2132 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2133 type, sizeof(u32), 1, imf);
|
Chris@634
|
2134 //Time to sample box//
|
Chris@634
|
2135 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2136 TimeToSampleBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2137 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2138 TimeToSampleBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2139 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2140 TimeToSampleBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2141 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2142 TimeToSampleBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
2143 swap = bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2144 TimeToSampleBox.entry_count);
|
Chris@634
|
2145 pos = swap;
|
Chris@634
|
2146
|
Chris@634
|
2147 for (i=0; i<pos; i++) {
|
Chris@634
|
2148 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2149 TimeToSampleBox.sample_count[i], sizeof(u32), 1, imf);
|
Chris@634
|
2150 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2151 TimeToSampleBox.sample_delta[i], sizeof(u32), 1, imf);
|
Chris@634
|
2152 }
|
Chris@634
|
2153
|
Chris@634
|
2154 //Sample description box//
|
Chris@634
|
2155 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2156 SampleDescriptionBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2157 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2158 SampleDescriptionBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2159 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2160 SampleDescriptionBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2161 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2162 SampleDescriptionBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
2163 //tx3g
|
Chris@634
|
2164 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2165 SampleTableBox.SampleDescriptionBox.TextSampleEntry.size,sizeof(u32),1,imf);
|
Chris@634
|
2166 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2167 SampleTableBox.SampleDescriptionBox.TextSampleEntry.type,sizeof(u32),1,imf);
|
Chris@634
|
2168 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2169 SampleTableBox.SampleDescriptionBox.TextSampleEntry.a,sizeof(u32),1,imf);
|
Chris@634
|
2170 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2171 SampleTableBox.SampleDescriptionBox.TextSampleEntry.b,sizeof(u32),1,imf);
|
Chris@634
|
2172 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2173 SampleTableBox.SampleDescriptionBox.TextSampleEntry.displayFlags,sizeof(u32),1,imf);
|
Chris@634
|
2174 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2175 SampleTableBox.SampleDescriptionBox.TextSampleEntry.horizontaljustification,sizeof(u8),1,imf);
|
Chris@634
|
2176 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2177 SampleTableBox.SampleDescriptionBox.TextSampleEntry.verticaljustification,sizeof(u8),1,imf);
|
Chris@634
|
2178 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2179 SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[0],sizeof(u8),1,imf);
|
Chris@634
|
2180 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2181 SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[1],sizeof(u8),1,imf);
|
Chris@634
|
2182 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2183 SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[2],sizeof(u8),1,imf);
|
Chris@634
|
2184 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2185 SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[3],sizeof(u8),1,imf);
|
Chris@634
|
2186 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2187 SampleTableBox.SampleDescriptionBox.TextSampleEntry.top,sizeof(u16),1,imf);
|
Chris@634
|
2188 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2189 SampleTableBox.SampleDescriptionBox.TextSampleEntry.left,sizeof(u16),1,imf);
|
Chris@634
|
2190 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2191 SampleTableBox.SampleDescriptionBox.TextSampleEntry.bottom,sizeof(u16),1,imf);
|
Chris@634
|
2192 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2193 SampleTableBox.SampleDescriptionBox.TextSampleEntry.right,sizeof(u16),1,imf);
|
Chris@634
|
2194 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2195 SampleTableBox.SampleDescriptionBox.TextSampleEntry.startChar,sizeof(u16),1,imf);
|
Chris@634
|
2196 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2197 SampleTableBox.SampleDescriptionBox.TextSampleEntry.endChar,sizeof(u16),1,imf);
|
Chris@634
|
2198 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2199 SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontID,sizeof(u16),1,imf);
|
Chris@634
|
2200 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2201 SampleTableBox.SampleDescriptionBox.TextSampleEntry.facestyleflags,sizeof(u8),1,imf);
|
Chris@634
|
2202 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2203 SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontsize,sizeof(u8),1,imf);
|
Chris@634
|
2204 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2205 SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[0],sizeof(u8),1,imf);
|
Chris@634
|
2206 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2207 SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[1],sizeof(u8),1,imf);
|
Chris@634
|
2208 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2209 SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[2],sizeof(u8),1,imf);
|
Chris@634
|
2210 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2211 SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[3],sizeof(u8),1,imf);
|
Chris@634
|
2212 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2213 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.size,sizeof(u32),1,imf);
|
Chris@634
|
2214 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2215 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.type,sizeof(u32),1,imf);
|
Chris@634
|
2216 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2217 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.entrycount,sizeof(u16),1,imf);
|
Chris@634
|
2218 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2219 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontID,sizeof(u16),1,imf);
|
Chris@634
|
2220 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2221 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontnamelenght,sizeof(u8),1,imf);
|
Chris@634
|
2222 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2223 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[0],sizeof(u8),1,imf);
|
Chris@634
|
2224 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2225 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[1],sizeof(u8),1,imf);
|
Chris@634
|
2226 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2227 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[2],sizeof(u8),1,imf);
|
Chris@634
|
2228 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2229 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[3],sizeof(u8),1,imf);
|
Chris@634
|
2230 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.
|
Chris@634
|
2231 SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[4],sizeof(u8),1,imf);
|
Chris@634
|
2232 //Sample Size box//
|
Chris@634
|
2233 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2234 SampleSizeBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2235 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2236 SampleSizeBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2237 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2238 SampleSizeBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2239 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2240 SampleSizeBox.sample_size, sizeof(u32), 1, imf);
|
Chris@634
|
2241 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2242 SampleSizeBox.sample_count, sizeof(u32), 1, imf);
|
Chris@634
|
2243 swap = bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2244 SampleSizeBox.sample_count);
|
Chris@634
|
2245
|
Chris@634
|
2246 for(i=0; i<swap; i++){
|
Chris@634
|
2247 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2248 SampleSizeBox.entry_size[i], sizeof(u32), 1, imf);
|
Chris@634
|
2249 }
|
Chris@634
|
2250
|
Chris@634
|
2251 //Sample to chunk box//
|
Chris@634
|
2252 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2253 SampleToChunk.size, sizeof(u32), 1, imf);
|
Chris@634
|
2254 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2255 SampleToChunk.type, sizeof(u32), 1, imf);
|
Chris@634
|
2256 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2257 SampleToChunk.version, sizeof(u32), 1, imf);
|
Chris@634
|
2258 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2259 SampleToChunk.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
2260 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2261 SampleToChunk.first_chunk, sizeof(u32), 1, imf);
|
Chris@634
|
2262 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2263 SampleToChunk.samples_per_chunk, sizeof(u32), 1, imf);
|
Chris@634
|
2264 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2265 SampleToChunk.sample_description_index, sizeof(u32), 1, imf);
|
Chris@634
|
2266
|
Chris@634
|
2267 //Chunk offset//
|
Chris@634
|
2268 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2269 ChunkOffsetBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2270 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2271 ChunkOffsetBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2272 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2273 ChunkOffsetBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2274 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2275 ChunkOffsetBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
2276 swap=0x00;
|
Chris@634
|
2277 fwrite(&swap,sizeof(u32),1,imf);
|
Chris@634
|
2278 for (i=0;i<bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2279 ChunkOffsetBox.entry_count);i++){
|
Chris@634
|
2280
|
Chris@634
|
2281 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2282 ChunkOffsetBox.chunk_offset[i], sizeof(u32), 1, imf);
|
Chris@634
|
2283 }
|
Chris@636
|
2284 } // end if HasTextFile
|
Chris@634
|
2285 //Song Image//
|
Chris@634
|
2286 /* Go to function "writemeta" */
|
Chris@634
|
2287
|
Chris@634
|
2288 }
|
Chris@634
|
2289
|
Chris@634
|
2290
|
Chris@634
|
2291 void writepresets(MovieBox moov, int numtrack,int totaltracks, FILE *imf) {
|
Chris@634
|
2292
|
Chris@634
|
2293 //int i, j, k, m, t, temp, type;
|
Chris@634
|
2294
|
Chris@634
|
2295 // this function is executed in "writemoovbox";
|
Chris@634
|
2296 // to be implemented as standalone
|
Chris@634
|
2297 }
|
Chris@634
|
2298
|
Chris@634
|
2299 // Fill the MetaBox
|
Chris@634
|
2300
|
Chris@634
|
2301 int metacontainer(MetaBox *meta) {
|
Chris@634
|
2302 //int swap;
|
Chris@634
|
2303
|
Chris@634
|
2304 u32 sizeMETA;
|
Chris@634
|
2305 u32 sizeHDLR = 36;
|
Chris@634
|
2306 u32 sizeDINF;
|
Chris@634
|
2307 u32 sizeDREF = 0; //16
|
Chris@634
|
2308 u32 sizeURL = 0; //12
|
Chris@634
|
2309 u32 sizeILOC = 36 - 2;
|
Chris@634
|
2310 u32 sizeIINF;
|
Chris@634
|
2311 u32 sizeINFE = 44;
|
Chris@634
|
2312 u32 sizeXML = 12 + 2000;
|
Chris@634
|
2313 char name[6] = "image";
|
Chris@634
|
2314 char type_content[18] = "application/other";
|
Chris@634
|
2315 char encoding[4] = "jpg";
|
Chris@634
|
2316
|
Chris@634
|
2317 //METADATA
|
Chris@634
|
2318 char xml[2000] = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Mpeg7 xmlns=\"urn:mpeg:mpeg7:schema:2001\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mpeg7=\"urn:mpeg:mpeg7:schema:2001\"xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"xsi:schemaLocation=\"urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd\"><Description xsi:type=\"CreationDescriptionType\"><CreationInformation><Creation><Title type=\"songTitle\">IMAF Song</Title><Title type=\"albumTitle\">Encoder</Title><Abstract><FreeTextAnnotation>QMUL</FreeTextAnnotation></Abstract><Creator><Role href=\"urn:mpeg:mpeg7:RoleCS:2001:PERFORMER\"/><Agent xsi:type=\"PersonType\"><Name><FamilyName></FamilyName><GivenName>Frank Sinatra</GivenName></Name></Agent></Creator><CreationCoordinates><Date><TimePoint>2013</TimePoint></Date></CreationCoordinates><CopyrightString></CopyrightString></Creation><Classification><Genre href=\"urn:id3:cs:ID3genreCS:v1:12\"><Name>Electro</Name></Genre></Classification></CreationInformation></Description><Description xsi:type=\"SemanticDescriptionType\"> <Semantics> <SemanticBase xsi:type=\"SemanticStateType\"><AttributeValuePair><Attribute><TermUse href=\"urn:mpeg:maf:cs:musicplayer:CollectionElementsCS:2007:assetNum\"/></Attribute><IntegerValue>07</IntegerValue></AttributeValuePair><AttributeValuePair><Attribute><TermUse href=\"urn:mpeg:maf:cs:musicplayer:CollectionElementsCS:2013:assetTot\"/></Attribute><IntegerValue>11</IntegerValue></AttributeValuePair></SemanticBase></Semantics></Description><Description xsi:type=\"SemanticDescriptionType\"><MediaInformation><MediaIdentification><EntityIdentifier></EntityIdentifier></MediaIdentification></MediaInformation></Description></Mpeg7>";
|
Chris@634
|
2319
|
Chris@634
|
2320 sizeDINF = 8;// + sizeDREF + sizeURL;
|
Chris@634
|
2321 sizeIINF = 14 + sizeINFE;
|
Chris@634
|
2322 sizeMETA = 12 + sizeHDLR + sizeDINF + sizeILOC + sizeIINF + sizeXML;
|
Chris@634
|
2323
|
Chris@634
|
2324 meta->size = bytereverse(sizeMETA);
|
Chris@634
|
2325 meta->type = bytereverse('meta');
|
Chris@634
|
2326 meta->version = 0;
|
Chris@634
|
2327 //HandlerBox
|
Chris@634
|
2328 meta->theHandler.size = bytereverse(sizeHDLR);
|
Chris@634
|
2329 meta->theHandler.type = bytereverse('hdlr');
|
Chris@634
|
2330 meta->theHandler.version = 0;
|
Chris@634
|
2331 meta->theHandler.pre_defined = 0;
|
Chris@634
|
2332 meta->theHandler.handler_type = bytereverse('meta');
|
Chris@634
|
2333 meta->theHandler.reserved[0] = 0;
|
Chris@634
|
2334 meta->theHandler.reserved[1] = 0;
|
Chris@634
|
2335 meta->theHandler.reserved[2] = 0;
|
Chris@634
|
2336 meta->theHandler.name[0] = bytereverse('m');
|
Chris@634
|
2337 meta->theHandler.name[1] = bytereverse('p');
|
Chris@634
|
2338 meta->theHandler.name[2] = bytereverse('7');
|
Chris@634
|
2339 meta->theHandler.name[3] = bytereverse('t');
|
Chris@634
|
2340 //DataInformationBox
|
Chris@634
|
2341 meta->file_locations.size = bytereverse(sizeDINF);
|
Chris@634
|
2342 meta->file_locations.type = bytereverse('dinf');
|
Chris@634
|
2343 /*
|
Chris@634
|
2344 //DataReferenceBox
|
Chris@634
|
2345 meta->file_locations.DataReferenceBox.size = bytereverse(sizeDREF);
|
Chris@634
|
2346 meta->file_locations.DataReferenceBox.type = bytereverse('dref');
|
Chris@634
|
2347 meta->file_locations.DataReferenceBox.flags = bytereverse(0); // CHECK THIS VALUE
|
Chris@634
|
2348 meta->file_locations.DataReferenceBox.entry_count = bytereverse(1);
|
Chris@634
|
2349 //DataEntryUrlBox
|
Chris@634
|
2350 meta->file_locations.DataReferenceBox.DataEntryUrlBox.size = bytereverse(sizeURL);
|
Chris@634
|
2351 meta->file_locations.DataReferenceBox.DataEntryUrlBox.type = bytereverse('url '); // 'url ' with blank space
|
Chris@634
|
2352 meta->file_locations.DataReferenceBox.DataEntryUrlBox.flags = bytereverse(0); // CHECK THIS VALUE
|
Chris@634
|
2353 */
|
Chris@634
|
2354 //item_location
|
Chris@634
|
2355 meta->item_locations.size = bytereverse(sizeILOC);
|
Chris@634
|
2356 meta->item_locations.type = bytereverse('iloc');
|
Chris@634
|
2357 meta->item_locations.version = 0;
|
Chris@634
|
2358 meta->item_locations.offset_size = 68; // 0100|0100 offset_size = 4 + lenght_size = 4
|
Chris@634
|
2359 //meta->item_locations.lenght_size = 4; //already included
|
Chris@634
|
2360 meta->item_locations.base_offset_size = 64; // 0100|0000 base_offset_size = 4 + reserved = 0
|
Chris@634
|
2361 //meta->item_locations.reserved = 0; //already included
|
Chris@634
|
2362 meta->item_locations.item_count = bytereverse16(1);
|
Chris@634
|
2363 meta->item_locations.item_ID = bytereverse16(1);
|
Chris@634
|
2364 meta->item_locations.data_reference_index = 0;
|
Chris@634
|
2365 //meta->item_locations.base_offset = bytereverse(); // corresponding to iloc_offset in insertImage function
|
Chris@634
|
2366 meta->item_locations.extent_count = bytereverse16(1);
|
Chris@634
|
2367 //meta->item_locations.extent_offset = bytereverse(); // corresponding to iloc_offset in insertImage function
|
Chris@634
|
2368 //meta->item_locations.extent_length = bytereverse(); // corresponding to imagesize in insertImage function
|
Chris@634
|
2369
|
Chris@634
|
2370 //ItemInfoBox
|
Chris@634
|
2371 meta->item_infos.size = bytereverse(sizeIINF);
|
Chris@634
|
2372 meta->item_infos.type = bytereverse('iinf');
|
Chris@634
|
2373 meta->item_infos.version = 0;
|
Chris@634
|
2374 meta->item_infos.entry_count = bytereverse16(1);
|
Chris@634
|
2375
|
Chris@634
|
2376 //info_entry
|
Chris@634
|
2377 meta->item_infos.info_entry.size = bytereverse(sizeINFE);
|
Chris@634
|
2378 meta->item_infos.info_entry.type = bytereverse('infe');
|
Chris@634
|
2379 meta->item_infos.info_entry.version = 0;
|
Chris@634
|
2380 meta->item_infos.info_entry.item_ID = bytereverse16(1);
|
Chris@634
|
2381 meta->item_infos.info_entry.item_protection_index = 0;
|
Chris@634
|
2382 strcpy(meta->item_infos.info_entry.item_name, name);
|
Chris@634
|
2383 strcpy(meta->item_infos.info_entry.content_type, type_content);
|
Chris@634
|
2384 strcpy(meta->item_infos.info_entry.content_encoding, encoding);
|
Chris@634
|
2385
|
Chris@634
|
2386 //XMLBox (MetaData)
|
Chris@634
|
2387 meta->XMLBox.size = bytereverse(sizeXML);
|
Chris@634
|
2388 meta->XMLBox.type = bytereverse('xml ');
|
Chris@634
|
2389 meta->XMLBox.version = 0;
|
Chris@634
|
2390 strcpy(meta->XMLBox.string, xml);
|
Chris@634
|
2391
|
Chris@634
|
2392 return sizeMETA;
|
Chris@634
|
2393 }
|
Chris@634
|
2394
|
Chris@634
|
2395 //Read the image's size
|
Chris@634
|
2396 u32 getImageSize(const char *imagedir){
|
Chris@634
|
2397 u32 size;
|
Chris@634
|
2398 FILE *img;
|
Chris@634
|
2399
|
Chris@634
|
2400 img = fopen(imagedir,"rb");
|
Chris@634
|
2401
|
Chris@634
|
2402 //Calculate size of the picture
|
Chris@634
|
2403 fseek(img,0,SEEK_END);
|
Chris@634
|
2404 size = ftell(img);
|
Chris@634
|
2405 fclose(img);
|
Chris@634
|
2406
|
Chris@634
|
2407 return size;
|
Chris@634
|
2408 }
|
Chris@634
|
2409 //Read the text´s size
|
Chris@634
|
2410 int getTextSize (FILE *text){
|
Chris@634
|
2411
|
Chris@634
|
2412 int d=0,sizetext=0,dat=0,dat1=0,dat2=0,dat3=0;
|
Chris@634
|
2413
|
Chris@634
|
2414 //TEXT-FILE
|
Chris@634
|
2415 //Find mdat in text file in order to know the size of the text file
|
Chris@634
|
2416 d=0;
|
Chris@634
|
2417 while(d==0){
|
Chris@634
|
2418
|
Chris@634
|
2419 fread (&dat,sizeof(unsigned char),1,text); //read a byte and saves it in dat
|
Chris@634
|
2420 fread (&dat1,sizeof(unsigned char),1,text);
|
Chris@634
|
2421 fread (&dat2,sizeof(unsigned char),1,text);
|
Chris@634
|
2422 fread (&dat3,sizeof(unsigned char),1,text);
|
Chris@634
|
2423 fseek(text,-3,SEEK_CUR);
|
Chris@634
|
2424
|
Chris@634
|
2425 if(dat == 0x6D && dat1 == 0x64 && dat2 == 0x61 && dat3 == 0x74){ // 6D646174 = mdat
|
Chris@634
|
2426 d=1;
|
Chris@634
|
2427 }
|
Chris@634
|
2428
|
Chris@634
|
2429 } //close while
|
Chris@634
|
2430
|
Chris@634
|
2431 fseek (text,-5,SEEK_CUR);//positionate the pointer at the first byte of size
|
Chris@634
|
2432 fread (&dat,sizeof(unsigned char),1,text); //first byte of size
|
Chris@634
|
2433 fread (&dat1,sizeof(unsigned char),1,text);//second byte of size
|
Chris@634
|
2434 fread (&dat2,sizeof(unsigned char),1,text);//third byte of size
|
Chris@634
|
2435 fread (&dat3,sizeof(unsigned char),1,text);//fourth byte of size
|
Chris@634
|
2436
|
Chris@634
|
2437 sizetext = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2438 sizetext = sizetext-8-16; //4 bytes of size and 4 bytes of type and 16 bytes of padding
|
Chris@634
|
2439
|
Chris@634
|
2440 fseek (text,20,SEEK_CUR);//Advance 20 bytes, because the pointer must advance 20 bytes to read the size of the first string.This is because of the way that Quicktime creates the 3gp
|
Chris@634
|
2441
|
Chris@634
|
2442 return sizetext;
|
Chris@634
|
2443
|
Chris@634
|
2444
|
Chris@634
|
2445 }
|
Chris@634
|
2446
|
Chris@634
|
2447 //Read the JPEG file
|
Chris@634
|
2448
|
Chris@634
|
2449 void insertImage (MetaBox *meta, FILE **imf, u32 imagesize, const char *imagedir) {
|
Chris@634
|
2450
|
Chris@634
|
2451 FILE *img;
|
Chris@634
|
2452 u64 iloc_offset = 0;
|
Chris@634
|
2453 unsigned char *imgbuffer;
|
Chris@634
|
2454
|
Chris@634
|
2455 img = fopen(imagedir,"rb");
|
Chris@634
|
2456
|
Chris@634
|
2457 // Binary reading
|
Chris@634
|
2458 fseek(img,0,SEEK_SET);
|
Chris@634
|
2459 imgbuffer= (unsigned char*)malloc(sizeof(unsigned char)*imagesize);
|
Chris@634
|
2460 fread(imgbuffer, 1, imagesize, img);
|
Chris@634
|
2461 fclose(img);
|
Chris@634
|
2462
|
Chris@634
|
2463 // Find position in the IMAF file and write the image
|
Chris@634
|
2464 iloc_offset = ftell(*imf);
|
Chris@634
|
2465 fwrite(imgbuffer,1,imagesize, *imf);
|
Chris@634
|
2466
|
Chris@634
|
2467 // Set image size and offset values
|
Chris@634
|
2468 meta->item_locations.base_offset = bytereverse(iloc_offset);
|
Chris@634
|
2469 meta->item_locations.extent_length = bytereverse(imagesize);
|
Chris@634
|
2470 meta->item_locations.extent_offset = bytereverse(iloc_offset);
|
Chris@634
|
2471
|
Chris@634
|
2472 }
|
Chris@634
|
2473
|
Chris@634
|
2474
|
Chris@634
|
2475 void writemetabox(MetaBox meta, FILE *imf) {
|
Chris@634
|
2476
|
Chris@634
|
2477 int i=0;
|
Chris@634
|
2478
|
Chris@634
|
2479 //MetaBox
|
Chris@634
|
2480 fwrite(&meta.size, sizeof(u32), 1, imf);
|
Chris@634
|
2481 fwrite(&meta.type, sizeof(u32), 1, imf);
|
Chris@634
|
2482 fwrite(&meta.version, sizeof(u32), 1, imf);
|
Chris@634
|
2483 //Handler
|
Chris@634
|
2484 fwrite(&meta.theHandler.size, sizeof(u32), 1, imf);
|
Chris@634
|
2485 fwrite(&meta.theHandler.type, sizeof(u32), 1, imf);
|
Chris@634
|
2486 fwrite(&meta.theHandler.version, sizeof(u32), 1, imf);
|
Chris@634
|
2487 fwrite(&meta.theHandler.pre_defined, sizeof(u32), 1, imf);
|
Chris@634
|
2488 fwrite(&meta.theHandler.handler_type, sizeof(u32), 1, imf);
|
Chris@634
|
2489 fwrite(&meta.theHandler.reserved[0], sizeof(u32), 1, imf);
|
Chris@634
|
2490 fwrite(&meta.theHandler.reserved[1], sizeof(u32), 1, imf);
|
Chris@634
|
2491 fwrite(&meta.theHandler.reserved[2], sizeof(u32), 1, imf);
|
Chris@634
|
2492 fwrite(&meta.theHandler.name[0], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2493 fwrite(&meta.theHandler.name[1], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2494 fwrite(&meta.theHandler.name[2], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2495 fwrite(&meta.theHandler.name[3], sizeof(unsigned char), 1, imf);
|
Chris@634
|
2496 //Data Information Box
|
Chris@634
|
2497 fwrite(&meta.file_locations.size, sizeof(u32), 1, imf);
|
Chris@634
|
2498 fwrite(&meta.file_locations.type, sizeof(u32), 1, imf);
|
Chris@634
|
2499 /*
|
Chris@634
|
2500 //Data Reference
|
Chris@634
|
2501 fwrite(&meta.file_locations.DataReferenceBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2502 fwrite(&meta.file_locations.DataReferenceBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2503 fwrite(&meta.file_locations.DataReferenceBox.flags, sizeof(u32), 1, imf);
|
Chris@634
|
2504 fwrite(&meta.file_locations.DataReferenceBox.entry_count, sizeof(u32), 1, imf);
|
Chris@634
|
2505
|
Chris@634
|
2506 fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2507 fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2508 fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.flags, sizeof(u32), 1, imf);
|
Chris@634
|
2509 */
|
Chris@634
|
2510 //Item Location Box
|
Chris@634
|
2511 fwrite(&meta.item_locations.size, sizeof(u32), 1, imf);
|
Chris@634
|
2512 fwrite(&meta.item_locations.type, sizeof(u32), 1, imf);
|
Chris@634
|
2513 fwrite(&meta.item_locations.version, sizeof(u32), 1, imf);
|
Chris@634
|
2514 fwrite(&meta.item_locations.offset_size, sizeof(unsigned char), 1, imf);
|
Chris@634
|
2515 //fwrite(&meta.item_locations.lenght_size, sizeof(unsigned char), 1, imf);
|
Chris@634
|
2516 fwrite(&meta.item_locations.base_offset_size, sizeof(unsigned char), 1, imf);
|
Chris@634
|
2517 //fwrite(&meta.item_locations.reserved, sizeof(unsigned char), 1, imf);
|
Chris@634
|
2518 fwrite(&meta.item_locations.item_count, sizeof(u16), 1, imf);
|
Chris@634
|
2519 fwrite(&meta.item_locations.item_ID, sizeof(u16), 1, imf);
|
Chris@634
|
2520 fwrite(&meta.item_locations.data_reference_index, sizeof(u16), 1, imf);
|
Chris@634
|
2521 fwrite(&meta.item_locations.base_offset, sizeof(u32), 1, imf);
|
Chris@634
|
2522 fwrite(&meta.item_locations.extent_count, sizeof(u16), 1, imf);
|
Chris@634
|
2523 fwrite(&meta.item_locations.extent_offset, sizeof(u32), 1, imf);
|
Chris@634
|
2524 fwrite(&meta.item_locations.extent_length, sizeof(u32), 1, imf);
|
Chris@634
|
2525 //Item Info
|
Chris@634
|
2526 fwrite(&meta.item_infos.size, sizeof(u32), 1, imf);
|
Chris@634
|
2527 fwrite(&meta.item_infos.type, sizeof(u32), 1, imf);
|
Chris@634
|
2528 fwrite(&meta.item_infos.version, sizeof(u32), 1, imf);
|
Chris@634
|
2529 fwrite(&meta.item_infos.entry_count, sizeof(u16), 1, imf);
|
Chris@634
|
2530 //Info Entry
|
Chris@634
|
2531 fwrite(&meta.item_infos.info_entry.size, sizeof(u32), 1, imf);
|
Chris@634
|
2532 fwrite(&meta.item_infos.info_entry.type, sizeof(u32), 1, imf);
|
Chris@634
|
2533 fwrite(&meta.item_infos.info_entry.version, sizeof(u32), 1, imf);
|
Chris@634
|
2534 fwrite(&meta.item_infos.info_entry.item_ID, sizeof(u16), 1, imf);
|
Chris@634
|
2535 fwrite(&meta.item_infos.info_entry.item_protection_index, sizeof(u16), 1, imf);
|
Chris@634
|
2536 for (i=0; i<6; i++){
|
Chris@634
|
2537 fwrite(&meta.item_infos.info_entry.item_name[i], sizeof(char), 1, imf);
|
Chris@634
|
2538 }
|
Chris@634
|
2539 for (i=0; i<18; i++){
|
Chris@634
|
2540 fwrite(&meta.item_infos.info_entry.content_type[i], sizeof(char), 1, imf);
|
Chris@634
|
2541 }
|
Chris@634
|
2542 for (i=0; i<4; i++){
|
Chris@634
|
2543 fwrite(&meta.item_infos.info_entry.content_encoding[i], sizeof(char), 1, imf);
|
Chris@634
|
2544 }
|
Chris@634
|
2545 //XML for metadata
|
Chris@634
|
2546 fwrite(&meta.XMLBox.size, sizeof(u32), 1, imf);
|
Chris@634
|
2547 fwrite(&meta.XMLBox.type, sizeof(u32), 1, imf);
|
Chris@634
|
2548 fwrite(&meta.XMLBox.version, sizeof(u32), 1, imf);
|
Chris@634
|
2549 for(i=0; i<2000; i++){
|
Chris@634
|
2550 fwrite(&meta.XMLBox.string[i], sizeof(char), 1, imf);
|
Chris@634
|
2551 }
|
Chris@634
|
2552
|
Chris@634
|
2553 }
|
Chris@634
|
2554
|
Chris@634
|
2555 //TIMED-TEXT's funcionts
|
Chris@634
|
2556 int trackstructure_text (MovieBox *moov, int numtrack, int clock,
|
Chris@634
|
2557 int durationTrack, int sizemdat, const char *textfile,FILE *text,int totaltracks ) { // creates the text trak structure
|
Chris@634
|
2558 int swap;
|
Chris@634
|
2559 u32 sizeURL;
|
Chris@634
|
2560 u32 sizeDREF;
|
Chris@634
|
2561 u32 sizeDINF;
|
Chris@634
|
2562 u32 sizeSMHD;
|
Chris@634
|
2563 u32 sizeMINF;
|
Chris@634
|
2564 u32 sizeHDLR;
|
Chris@634
|
2565 u32 sizeMDHD;
|
Chris@634
|
2566 u32 sizeMDIA;
|
Chris@634
|
2567 u32 sizeTKHD;
|
Chris@634
|
2568 u32 sizeTRAK;
|
Chris@634
|
2569
|
Chris@634
|
2570
|
Chris@634
|
2571 //Sample Table Box
|
Chris@634
|
2572 int sizeSTBL = 0;
|
Chris@634
|
2573
|
Chris@634
|
2574 sizeSTBL = samplecontainer_text(moov, numtrack,sizemdat, textfile,totaltracks);
|
Chris@634
|
2575
|
Chris@634
|
2576 //Data Entry Url Box
|
Chris@634
|
2577 sizeURL = 12;
|
Chris@634
|
2578 swap = bytereverse(sizeURL);
|
Chris@634
|
2579 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2580 DataReferenceBox.DataEntryUrlBox.size = swap;
|
Chris@634
|
2581 swap = bytereverse('url ');
|
Chris@634
|
2582 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2583 DataReferenceBox.DataEntryUrlBox.type = swap;
|
Chris@634
|
2584 swap = bytereverse(1);
|
Chris@634
|
2585 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2586 DataReferenceBox.DataEntryUrlBox.flags = swap; // =1 Track in same file as movie atom.
|
Chris@634
|
2587
|
Chris@634
|
2588 //Data Reference
|
Chris@634
|
2589 sizeDREF = sizeURL+ 16;
|
Chris@634
|
2590 swap = bytereverse(sizeDREF);
|
Chris@634
|
2591 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2592 DataReferenceBox.size = swap;
|
Chris@634
|
2593 swap = bytereverse('dref');
|
Chris@634
|
2594 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2595 DataReferenceBox.type = swap;
|
Chris@634
|
2596 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2597 DataReferenceBox.flags = 0;
|
Chris@634
|
2598 swap = bytereverse(1);
|
Chris@634
|
2599 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.
|
Chris@634
|
2600 DataReferenceBox.entry_count = swap;
|
Chris@634
|
2601
|
Chris@634
|
2602 //Data information Box//
|
Chris@634
|
2603 sizeDINF = sizeDREF + 8;
|
Chris@634
|
2604 swap = bytereverse(sizeDINF);
|
Chris@634
|
2605 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.size = swap;
|
Chris@634
|
2606 swap = bytereverse('dinf');
|
Chris@634
|
2607 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.type = swap;
|
Chris@634
|
2608
|
Chris@634
|
2609
|
Chris@634
|
2610 //Null Media Header Box
|
Chris@634
|
2611 swap = bytereverse(12);
|
Chris@634
|
2612 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.size = swap ;
|
Chris@634
|
2613 swap = bytereverse ('nmhd');
|
Chris@634
|
2614 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.type = swap;
|
Chris@634
|
2615 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.flags = 0;
|
Chris@634
|
2616
|
Chris@634
|
2617 //Media Information Box//
|
Chris@634
|
2618 sizeMINF = sizeDINF + sizeSTBL + 8 + 12;
|
Chris@634
|
2619 swap = bytereverse(sizeMINF);
|
Chris@634
|
2620 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.size = swap;
|
Chris@634
|
2621 swap = bytereverse('minf');
|
Chris@634
|
2622 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.type = swap;
|
Chris@634
|
2623
|
Chris@634
|
2624 //Handler Box//
|
Chris@634
|
2625 sizeHDLR = 37;
|
Chris@634
|
2626 swap = bytereverse(sizeHDLR);
|
Chris@634
|
2627 moov->TrackBox[numtrack].MediaBox.HandlerBox.size = swap;
|
Chris@634
|
2628 swap = bytereverse('hdlr');
|
Chris@634
|
2629 moov->TrackBox[numtrack].MediaBox.HandlerBox.type = swap;
|
Chris@634
|
2630 moov->TrackBox[numtrack].MediaBox.HandlerBox.version = 0;
|
Chris@634
|
2631 moov->TrackBox[numtrack].MediaBox.HandlerBox.pre_defined = 0;
|
Chris@634
|
2632 swap = bytereverse('text');
|
Chris@634
|
2633 moov->TrackBox[numtrack].MediaBox.HandlerBox.handler_type = swap;
|
Chris@634
|
2634 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[0] = 0;
|
Chris@634
|
2635 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[1] = 0;
|
Chris@634
|
2636 moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[2] = 0;
|
Chris@634
|
2637 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[0] = 't';
|
Chris@634
|
2638 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[1] = 'e';
|
Chris@634
|
2639 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[2] = 'x';
|
Chris@634
|
2640 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[3] = 't';
|
Chris@634
|
2641 moov->TrackBox[numtrack].MediaBox.HandlerBox.data[4] = '\0';
|
Chris@634
|
2642
|
Chris@634
|
2643 //Media Header Box//
|
Chris@634
|
2644 sizeMDHD = 32;
|
Chris@634
|
2645 swap = bytereverse(sizeMDHD);
|
Chris@634
|
2646 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.size = swap;
|
Chris@634
|
2647 swap = bytereverse('mdhd');
|
Chris@634
|
2648 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.type = swap;
|
Chris@634
|
2649 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.version = 0;
|
Chris@634
|
2650 swap = bytereverse(clock);
|
Chris@634
|
2651 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.creation_time = swap;
|
Chris@634
|
2652 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.modification_time = swap;
|
Chris@634
|
2653 swap = bytereverse(1000);
|
Chris@634
|
2654 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.timescale = swap;
|
Chris@634
|
2655 swap = bytereverse(durationTrack);
|
Chris@634
|
2656 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.duration = swap;
|
Chris@634
|
2657 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.language = 0xC455;
|
Chris@634
|
2658 moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.pre_defined = 0;
|
Chris@634
|
2659
|
Chris@634
|
2660 //Media Box//
|
Chris@634
|
2661 sizeMDIA = sizeMDHD + sizeHDLR + sizeMINF + 8;
|
Chris@634
|
2662 swap = bytereverse(sizeMDIA);
|
Chris@634
|
2663 moov->TrackBox[numtrack].MediaBox.size = swap;
|
Chris@634
|
2664 swap = bytereverse('mdia');
|
Chris@634
|
2665 moov->TrackBox[numtrack].MediaBox.type = swap;
|
Chris@634
|
2666
|
Chris@634
|
2667 //Track Header//
|
Chris@634
|
2668 sizeTKHD = 92;
|
Chris@634
|
2669 swap = bytereverse (sizeTKHD);
|
Chris@634
|
2670 moov->TrackBox[numtrack].TrackHeaderBox.size = swap;
|
Chris@634
|
2671 swap = bytereverse ('tkhd');
|
Chris@634
|
2672 moov->TrackBox[numtrack].TrackHeaderBox.type = swap ;
|
Chris@634
|
2673 swap = bytereverse (0x00000007);
|
Chris@634
|
2674 moov->TrackBox[numtrack].TrackHeaderBox.version = swap;
|
Chris@634
|
2675 swap = bytereverse (clock);
|
Chris@634
|
2676 moov->TrackBox[numtrack].TrackHeaderBox.creation_time = swap;
|
Chris@634
|
2677 moov->TrackBox[numtrack].TrackHeaderBox.modification_time = swap;
|
Chris@634
|
2678 moov->TrackBox[numtrack].TrackHeaderBox.track_ID = bytereverse(12345678);
|
Chris@634
|
2679 moov->TrackBox[numtrack].TrackHeaderBox.reserved = 0;
|
Chris@634
|
2680 swap = bytereverse (durationTrack);
|
Chris@634
|
2681 moov->TrackBox[numtrack].TrackHeaderBox.duration = swap;
|
Chris@634
|
2682 moov->TrackBox[numtrack].TrackHeaderBox.reserved2[0] = 0;
|
Chris@634
|
2683 moov->TrackBox[numtrack].TrackHeaderBox.reserved2[1] = 0;
|
Chris@634
|
2684 moov->TrackBox[numtrack].TrackHeaderBox.layer = 0;
|
Chris@634
|
2685 moov->TrackBox[numtrack].TrackHeaderBox.alternate_group = 0;
|
Chris@634
|
2686 moov->TrackBox[numtrack].TrackHeaderBox.volume = 0;
|
Chris@634
|
2687 moov->TrackBox[numtrack].TrackHeaderBox.reserved3 = 0;
|
Chris@634
|
2688 swap = bytereverse (0x00010000);
|
Chris@634
|
2689 moov->TrackBox[numtrack].TrackHeaderBox.matrix[0] = swap;
|
Chris@634
|
2690 moov->TrackBox[numtrack].TrackHeaderBox.matrix[1] = 0;
|
Chris@634
|
2691 moov->TrackBox[numtrack].TrackHeaderBox.matrix[2] = 0;
|
Chris@634
|
2692 moov->TrackBox[numtrack].TrackHeaderBox.matrix[3] = 0;
|
Chris@634
|
2693 moov->TrackBox[numtrack].TrackHeaderBox.matrix[4] = swap;
|
Chris@634
|
2694 moov->TrackBox[numtrack].TrackHeaderBox.matrix[5] = 0;
|
Chris@634
|
2695 moov->TrackBox[numtrack].TrackHeaderBox.matrix[6] = 0;
|
Chris@634
|
2696 moov->TrackBox[numtrack].TrackHeaderBox.matrix[7] = 0;
|
Chris@634
|
2697 swap = bytereverse(0x40000000);
|
Chris@634
|
2698 moov->TrackBox[numtrack].TrackHeaderBox.matrix[8] = swap;
|
Chris@634
|
2699 moov->TrackBox[numtrack].TrackHeaderBox.width =0;
|
Chris@634
|
2700 moov->TrackBox[numtrack].TrackHeaderBox.height = 0;
|
Chris@634
|
2701
|
Chris@634
|
2702 //Track container
|
Chris@634
|
2703 sizeTRAK = sizeTKHD + sizeMDIA + 8;
|
Chris@634
|
2704 swap = bytereverse (sizeTRAK); // Size of one track
|
Chris@634
|
2705 moov->TrackBox[numtrack].size = swap;
|
Chris@634
|
2706 swap = bytereverse ('trak');
|
Chris@634
|
2707 moov->TrackBox[numtrack].type = swap;
|
Chris@634
|
2708
|
Chris@634
|
2709 return sizeTRAK;
|
Chris@634
|
2710 }
|
Chris@634
|
2711
|
Chris@634
|
2712
|
Chris@634
|
2713 int aux (FILE *text,int num,int num1,int num2,int num3,int *sal) {
|
Chris@634
|
2714 int dat=0,dat1=0,dat2=0,dat3=0,size=0,d=0,cnt=0,i=0;
|
Chris@634
|
2715 fseek(text,0,SEEK_SET);
|
Chris@634
|
2716 d=0;
|
Chris@634
|
2717 while(d==0){
|
Chris@634
|
2718
|
Chris@634
|
2719 fread (&dat,sizeof(unsigned char),1,text);
|
Chris@634
|
2720 cnt++;
|
Chris@634
|
2721 fread (&dat1,sizeof(unsigned char),1,text);
|
Chris@634
|
2722 cnt++;
|
Chris@634
|
2723 fread (&dat2,sizeof(unsigned char),1,text);
|
Chris@634
|
2724 cnt++;
|
Chris@634
|
2725 fread (&dat3,sizeof(unsigned char),1,text);
|
Chris@634
|
2726 cnt++;
|
Chris@634
|
2727 fseek(text, -3 ,SEEK_CUR);
|
Chris@634
|
2728 if(dat == num && dat1 == num1 && dat2 == num2 && dat3 == num3){
|
Chris@634
|
2729
|
Chris@634
|
2730 d=1;
|
Chris@634
|
2731 }
|
Chris@634
|
2732
|
Chris@634
|
2733 else{
|
Chris@634
|
2734
|
Chris@634
|
2735 cnt=cnt-3;
|
Chris@634
|
2736 }
|
Chris@634
|
2737
|
Chris@634
|
2738 } //end while
|
Chris@634
|
2739
|
Chris@634
|
2740
|
Chris@634
|
2741 fseek (text,0,SEEK_SET);//positionate the pointer at first
|
Chris@634
|
2742
|
Chris@634
|
2743 cnt=cnt-7;//size is located 7 bytes before type
|
Chris@634
|
2744 for (d=1;d<=cnt;d++){
|
Chris@634
|
2745
|
Chris@634
|
2746 fread (&dat,sizeof(unsigned char),1,text);
|
Chris@634
|
2747
|
Chris@634
|
2748 }
|
Chris@634
|
2749 fread (&dat1,sizeof(unsigned char),1,text);
|
Chris@634
|
2750 fread (&dat2,sizeof(unsigned char),1,text);
|
Chris@634
|
2751 fread (&dat3,sizeof(unsigned char),1,text);
|
Chris@634
|
2752
|
Chris@634
|
2753 size = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2754
|
Chris@634
|
2755 for (i=1;i<=8;i++) { //advance sample_size
|
Chris@634
|
2756 fread (&dat,sizeof(unsigned char),1,text);
|
Chris@634
|
2757 }
|
Chris@634
|
2758 fread(&dat,1,1,text);
|
Chris@634
|
2759 fread(&dat1,1,1,text);
|
Chris@634
|
2760 fread(&dat2,1,1,text);
|
Chris@634
|
2761 fread(&dat3,1,1,text);
|
Chris@634
|
2762
|
Chris@634
|
2763 *sal = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2764
|
Chris@634
|
2765
|
Chris@634
|
2766 return size;
|
Chris@634
|
2767
|
Chris@634
|
2768 }
|
Chris@634
|
2769
|
Chris@634
|
2770 int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat,const char *textfiles,int totaltracks) {
|
Chris@634
|
2771
|
Chris@634
|
2772 u32 sizeSTSD, sizeSTSZ, swap,i=0;
|
Chris@634
|
2773 u32 sizeSTTS;
|
Chris@634
|
2774 u32 sizeSTSC = 0;
|
Chris@634
|
2775 u32 sizeSTCO = 0;
|
Chris@634
|
2776 u32 sizeSTBL=0;
|
Chris@634
|
2777 int dat=0,dat1=0,dat2=0,dat3=0,sal=0, samplecount=0;
|
Chris@634
|
2778
|
Chris@634
|
2779 //Sample Description Box//
|
Chris@634
|
2780 FILE *text;
|
Chris@634
|
2781
|
Chris@634
|
2782 text=fopen ( textfiles,"rb");
|
Chris@634
|
2783 fseek(text,0,SEEK_CUR);
|
Chris@634
|
2784
|
Chris@634
|
2785 //stsd
|
Chris@634
|
2786
|
Chris@634
|
2787 sizeSTSD =16+64;
|
Chris@634
|
2788 swap = bytereverse(sizeSTSD);
|
Chris@634
|
2789 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2790 SampleDescriptionBox.size = swap;
|
Chris@634
|
2791 swap = bytereverse('stsd');
|
Chris@634
|
2792 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2793 SampleDescriptionBox.type = swap;
|
Chris@634
|
2794 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2795 SampleDescriptionBox.version = 0;
|
Chris@634
|
2796 swap = bytereverse(1);
|
Chris@634
|
2797 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2798 SampleDescriptionBox.entry_count = swap;
|
Chris@634
|
2799
|
Chris@634
|
2800
|
Chris@634
|
2801 //tx3g
|
Chris@634
|
2802 swap = bytereverse(64);
|
Chris@634
|
2803 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.size=swap;
|
Chris@634
|
2804 swap = bytereverse('tx3g');
|
Chris@634
|
2805 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.type=swap;
|
Chris@634
|
2806 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.a=0;
|
Chris@634
|
2807 swap=bytereverse(1);
|
Chris@634
|
2808 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.b=swap;
|
Chris@634
|
2809 swap = bytereverse(0x00000800);//continuous karaoke
|
Chris@634
|
2810 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.displayFlags = swap;
|
Chris@634
|
2811 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.horizontaljustification=0x01;
|
Chris@634
|
2812 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.verticaljustification=0x01;
|
Chris@634
|
2813 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[0]= 0x00;
|
Chris@634
|
2814 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[1]= 0x00;
|
Chris@634
|
2815 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[2]= 0x00;
|
Chris@634
|
2816 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[3]= 0xFF;
|
Chris@634
|
2817 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.top=0;
|
Chris@634
|
2818 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.left=0;
|
Chris@634
|
2819 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.bottom=0x6400;
|
Chris@634
|
2820 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.right=0x2C01;
|
Chris@634
|
2821 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.startChar=0;
|
Chris@634
|
2822 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.endChar=0;
|
Chris@634
|
2823 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontID=0x0100;
|
Chris@634
|
2824 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.facestyleflags=0x01;
|
Chris@634
|
2825 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontsize=0x0A;
|
Chris@634
|
2826 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[0]=0xFF;
|
Chris@634
|
2827 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[1]=0xFF;
|
Chris@634
|
2828 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[2]=0xFF;
|
Chris@634
|
2829 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[3]=0xFF;
|
Chris@634
|
2830 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.size =0x12000000;
|
Chris@634
|
2831 swap =bytereverse('ftab');
|
Chris@634
|
2832 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.type =swap;
|
Chris@634
|
2833 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.entrycount=0x0100;
|
Chris@634
|
2834 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontID =0x0200;
|
Chris@634
|
2835 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontnamelenght =0x05;
|
Chris@634
|
2836 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[0] =0x53;
|
Chris@634
|
2837 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[1] =0x65;
|
Chris@634
|
2838 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[2] =0x72;
|
Chris@634
|
2839 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[3] =0x69;
|
Chris@634
|
2840 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[4] =0x66;
|
Chris@634
|
2841
|
Chris@634
|
2842 //stsz
|
Chris@634
|
2843
|
Chris@634
|
2844 sizeSTSZ=aux(text,0x73,0x74,0x73,0x7A,&sal)+4; // the function aux looks for the box stsz in 3gp file and returns the size
|
Chris@634
|
2845 swap = bytereverse('stsz');
|
Chris@634
|
2846 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2847 SampleSizeBox.type = swap;
|
Chris@634
|
2848 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2849 SampleSizeBox.version = 0;
|
Chris@634
|
2850 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_size=0;
|
Chris@634
|
2851
|
Chris@634
|
2852 fseek(text,0,SEEK_CUR);
|
Chris@634
|
2853
|
Chris@634
|
2854 fread(&dat,1,1,text); //read sample_count
|
Chris@634
|
2855 fread(&dat1,1,1,text);
|
Chris@634
|
2856 fread(&dat2,1,1,text);
|
Chris@634
|
2857 fread(&dat3,1,1,text);
|
Chris@634
|
2858
|
Chris@634
|
2859 samplecount = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2860
|
Chris@634
|
2861 swap= bytereverse(samplecount);
|
Chris@634
|
2862 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count=swap;
|
Chris@634
|
2863
|
Chris@634
|
2864 for (i=1;i<=samplecount;i++){
|
Chris@634
|
2865
|
Chris@634
|
2866 swap = bytereverse(size_phrase[i-1]);
|
Chris@634
|
2867 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.entry_size[i-1]=swap;
|
Chris@634
|
2868 }
|
Chris@634
|
2869
|
Chris@634
|
2870 sizeSTSZ= 20 + bytereverse(moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count)*4;
|
Chris@634
|
2871 swap = bytereverse(sizeSTSZ);
|
Chris@634
|
2872 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2873 SampleSizeBox.size = swap;
|
Chris@634
|
2874
|
Chris@634
|
2875
|
Chris@634
|
2876 //Time To Sample Box//
|
Chris@634
|
2877
|
Chris@634
|
2878 fseek (text,0,SEEK_SET);//positionate the pointer at first
|
Chris@634
|
2879 sizeSTTS=aux(text,0x73,0x74,0x74,0x73,&sal);
|
Chris@634
|
2880
|
Chris@634
|
2881 swap = bytereverse(sizeSTTS);
|
Chris@634
|
2882 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2883 TimeToSampleBox.size = swap;
|
Chris@634
|
2884 swap = bytereverse('stts');
|
Chris@634
|
2885 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2886 TimeToSampleBox.type = swap;
|
Chris@634
|
2887 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2888 TimeToSampleBox.version = 0;
|
Chris@634
|
2889 swap = bytereverse(sal);
|
Chris@634
|
2890 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.entry_count=swap;
|
Chris@634
|
2891 fseek(text,0,SEEK_CUR);
|
Chris@634
|
2892 for(i=1;i<=sal;i++){
|
Chris@634
|
2893
|
Chris@634
|
2894 fread(&dat,1,1,text);//read count
|
Chris@634
|
2895 fread(&dat1,1,1,text);
|
Chris@634
|
2896 fread(&dat2,1,1,text);
|
Chris@634
|
2897 fread(&dat3,1,1,text);
|
Chris@634
|
2898
|
Chris@634
|
2899 dat = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2900
|
Chris@634
|
2901
|
Chris@634
|
2902 swap = bytereverse(dat);
|
Chris@634
|
2903 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.sample_count[i-1]=swap;
|
Chris@634
|
2904 fread(&dat,1,1,text);//read delta
|
Chris@634
|
2905
|
Chris@634
|
2906 fread(&dat1,1,1,text);
|
Chris@634
|
2907
|
Chris@634
|
2908 fread(&dat2,1,1,text);
|
Chris@634
|
2909
|
Chris@634
|
2910 fread(&dat3,1,1,text);
|
Chris@634
|
2911
|
Chris@634
|
2912
|
Chris@634
|
2913 dat = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
|
Chris@634
|
2914
|
Chris@634
|
2915 swap = bytereverse(dat/0.6);// the input text file has time_scale = 600 but the audio has time scale=1000
|
Chris@634
|
2916 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.sample_delta[i-1]=swap;
|
Chris@634
|
2917 }
|
Chris@634
|
2918
|
Chris@634
|
2919 //Sample To Chunk//
|
Chris@634
|
2920
|
Chris@634
|
2921 dat=0;
|
Chris@634
|
2922 fseek (text,0,SEEK_SET);//positionate the pointer at first
|
Chris@634
|
2923 sizeSTSC = aux(text,0x73,0x74,0x73,0x63,&sal);
|
Chris@634
|
2924 dat=sal;
|
Chris@634
|
2925 swap = bytereverse(sizeSTSC);
|
Chris@634
|
2926 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2927 SampleToChunk.size = swap;
|
Chris@634
|
2928 swap = bytereverse('stsc');
|
Chris@634
|
2929 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2930 SampleToChunk.type = swap;
|
Chris@634
|
2931 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2932 SampleToChunk.version = 0;
|
Chris@634
|
2933 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2934 SampleToChunk.entry_count = bytereverse(1);
|
Chris@634
|
2935 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.first_chunk=bytereverse(1);
|
Chris@634
|
2936 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.samples_per_chunk=moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count;
|
Chris@634
|
2937 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.sample_description_index = bytereverse(1);
|
Chris@634
|
2938
|
Chris@634
|
2939 //Chunk Offset Box//
|
Chris@634
|
2940 sizeSTCO=24;
|
Chris@634
|
2941 swap = bytereverse(sizeSTCO);
|
Chris@634
|
2942 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2943 ChunkOffsetBox.size = swap;
|
Chris@634
|
2944 swap = bytereverse('co64');
|
Chris@634
|
2945 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2946 ChunkOffsetBox.type = swap;
|
Chris@634
|
2947 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2948 ChunkOffsetBox.version = 0;
|
Chris@634
|
2949 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2950 ChunkOffsetBox.entry_count = bytereverse(1);
|
Chris@634
|
2951 dat=32+sizemdat*totaltracks;
|
Chris@634
|
2952 swap=bytereverse(dat);
|
Chris@634
|
2953 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
|
Chris@634
|
2954 ChunkOffsetBox.chunk_offset [0]= swap;
|
Chris@634
|
2955
|
Chris@634
|
2956 //Sample Table Box //
|
Chris@634
|
2957 sizeSTBL = 8 + sizeSTSD + sizeSTSZ + sizeSTSC + sizeSTCO + sizeSTTS;
|
Chris@634
|
2958 swap = bytereverse(sizeSTBL);
|
Chris@634
|
2959 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size = swap;
|
Chris@634
|
2960 swap = bytereverse('stbl');
|
Chris@634
|
2961 moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type =swap;
|
Chris@634
|
2962 return sizeSTBL;
|
Chris@634
|
2963 }
|
Chris@634
|
2964
|
Chris@634
|
2965 //AUX Functions for endianness
|
Chris@634
|
2966
|
Chris@634
|
2967 int bytereverse(int num) {
|
Chris@634
|
2968 int swapped;
|
Chris@634
|
2969 swapped = ((num>>24)&0xff) | // move byte 3 to byte 0
|
Chris@634
|
2970 ((num<<8)&0xff0000) | // move byte 1 to byte 2
|
Chris@634
|
2971 ((num>>8)&0xff00) | // move byte 2 to byte 1
|
Chris@634
|
2972 ((num<<24)&0xff000000); // byte 0 to byte 3
|
Chris@634
|
2973 return swapped;
|
Chris@634
|
2974 }
|
Chris@634
|
2975 int bytereverse16(int num) {
|
Chris@634
|
2976 int swapped;
|
Chris@634
|
2977 swapped = ( ((num<<8)&0xff00) | // move byte 1 to byte 2
|
Chris@634
|
2978 ((num>>8)&0x00ff) ); // byte 2 to byte 1
|
Chris@634
|
2979 return swapped;
|
Chris@634
|
2980 }
|