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