changeset 636:767789a78984 imaf_enc

Fix from Jesus Corral Garcia (for crashes etc)
author Chris Cannam
date Mon, 04 Nov 2013 17:17:09 +0000
parents 8e64cebd38c0
children f45af8d8091e
files main/IMAFencoder.c main/MainWindow.cpp
diffstat 2 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/main/IMAFencoder.c	Mon Nov 04 17:16:49 2013 +0000
+++ b/main/IMAFencoder.c	Mon Nov 04 17:17:09 2013 +0000
@@ -36,7 +36,7 @@
 int presetcontainer(MovieBox *moov, int, int *vol_values, int type, int fade_in);
 int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
                    int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4);
-void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text);
+void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile);
 int readTrack(MovieBox *moov, int,const char *name);
 
 // Timed Text Functions
@@ -81,7 +81,7 @@
 
 int mainIMAFencoder (int totaltracks, QString files_path[maxtracks],QString outimaf,
                      QString picturefile, QString textfile, int vol_values[maxtracks], bool HasImageFile,
-                     int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
+                     bool HasTextFile, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2,
                      int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4,
                      int group_tracks[maxtracks], int group_volume, QString group_name, QString group_description,
                      int pres_type, int fade_in)
@@ -124,13 +124,14 @@
     }
 
     //INPUT: Timed-Text
-    c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
-    text = fopen(c_str2, "rb");
-    sizetext= getTextSize (text); //calculate the size of the text
-    if((text)==NULL) {
-            // do something
-        }
-
+    if (HasTextFile){
+        c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
+        text = fopen(c_str2, "rb");
+        sizetext= getTextSize (text); //calculate the size of the text
+    }
+    else{
+        sizetext = 0;
+    }
     //Create OUTPUT file (.ima)
     imf = fopen (outimaf.toStdString().c_str(),"wb");
 
@@ -179,14 +180,15 @@
                               MixRuleType, MixRule_PAR1, MixRule_PAR2, MixRule_PAR3, MixRule_PAR4); // Creates the rules, returns the size of the box.
 
     //Text track
-    c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
-    sizeTRAK = trackstructure_text (&moov, numtrack, clock, durationTrack, sizemdat, c_str2, text, totaltracks) + sizeTRAK;
-
+    if (HasTextFile){
+        c_str2= textfile.toStdString().c_str(); //convert Qstring to const char
+        sizeTRAK = trackstructure_text (&moov, numtrack, clock, durationTrack, sizemdat, c_str2, text, totaltracks) + sizeTRAK;
+    }
     //Movie Header - Overall declarations
     moovheaderbox(&moov, clock, sizeTRAK, sizePRCO, totaltracks, durationTrack, sizeRUCO, sizeGRCO); // -> enter sizeGRCO instead of 0
 
     //Writes the movie box into the file
-    writemoovbox(moov, numtrack, totaltracks, imf, text);
+    writemoovbox(moov, numtrack, totaltracks, imf, text, HasTextFile);
 
     //Writes the meta box into the IMAF file
     if (HasImageFile){
@@ -321,7 +323,7 @@
     }
 
     // copy the text in the 3gp to the ima and add the text modifiers
-
+  if (sizetext !=0){
     cnt=0;// the total number of bytes of the whole text including modifiers
     fseek(text,0,SEEK_CUR);
     sizestring=0;//number of bytes of a phrase (without modifiers)
@@ -457,7 +459,7 @@
         fwrite(&swap, sizeof(u32), 1, imf);
         fseek(imf,(sizeMDAT-imagesize)-4,SEEK_CUR);	// (Image is yet to be written in the file at this point)
     } // close if (numtr==totaltracks-1)
-
+}//close if sizetext
     fclose(song);
 
     return size;
@@ -1591,7 +1593,7 @@
 }
 
 
-void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text)
+void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile)
 {
     int i, j, k, m, t, swap, pos, temp, type;
     int cnt = 0, cnt2 = 0, d = 0, dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, size = 0;
@@ -2075,6 +2077,8 @@
     }
 
     //TIMED TEXT
+
+    if (HasTextFile){
     fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf);
     fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf);
     //Track header//
@@ -2277,7 +2281,7 @@
         fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.
                 ChunkOffsetBox.chunk_offset[i], sizeof(u32), 1, imf);
     }
-
+    } // end if HasTextFile
     //Song Image//
     /* Go to function "writemeta" */
 
--- a/main/MainWindow.cpp	Mon Nov 04 17:16:49 2013 +0000
+++ b/main/MainWindow.cpp	Mon Nov 04 17:17:09 2013 +0000
@@ -145,6 +145,7 @@
 QString group_descr, group_name;
 int preset_type, fade_in;
 
+bool isIMAF;
 
 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
     MainWindowBase(withAudioOutput, withOSCSupport, true),
@@ -4700,7 +4701,7 @@
 
     if( ImafFileName != "" ){   //if the user press cancel the function mainIMAFencoder won´t be called
         mainIMAFencoder(numtracks, files_paths, ImafFileName, ImageFileName, TextFileName,
-                        ImafVolumeValues, has_image, selrule_type, selrule_par1, selrule_par2,
+                        ImafVolumeValues, has_image, has_lyrics, selrule_type, selrule_par1, selrule_par2,
                         mixrule_type, mixrule_par1, mixrule_par2, mixrule_par3, mixrule_par4,
                         group_tracks, group_volume, group_name, group_descr, preset_type, fade_in);
     }
@@ -4834,6 +4835,9 @@
     filename = QFileDialog::getOpenFileName(this,
               tr("Import IMAF"), "/", tr("IMAF (*.ima)"));
 
+    if (filename.isEmpty()) return;
+    isIMAF = true;
+
     haslyrics = mainIMAFdecoder(filename);
 
     openMP3IMAF();
@@ -4861,7 +4865,6 @@
 
           //text decoder
           unsigned char dat,dat1,dat2,dat3;
-          QTextStream out(stdout);
           FILE *imf;
           imf = fopen (filename.toStdString().c_str(),"rb");