tk = &movie->tk[i];
if (tk->name_size != 0)
free(tk->name);
- if (tk->jp2_struct.comps != 0)
- free(tk->jp2_struct.comps);
- if (tk->jp2_struct.cl != 0)
- free(tk->jp2_struct.cl);
+ if (tk->track_type == 0) {// Video track
+ if (tk->jp2_struct.comps != 0)
+ free(tk->jp2_struct.comps);
+ if (tk->jp2_struct.cl != 0)
+ free(tk->jp2_struct.cl);
+ if (tk->num_jp2x != 0)
+ free(tk->jp2xdata);
+
+ }
if (tk->num_url != 0)
free(tk->url);
if (tk->num_urn != 0)
free(tk->urn);
if (tk->num_br != 0)
free(tk->br);
- if (tk->num_jp2x != 0)
- free(tk->jp2xdata);
if (tk->num_tts != 0)
free(tk->tts);
if (tk->num_chunks != 0)
/*
*
-* Initialisation of a Standard Video Track
-* with one sample per chunk
+* Initialisation of a Standard Movie, given a simple movie structure defined by the user
+* The movie will have one sample per chunk
+*
+* Arguments: mj2_movie_t * movie
+* Several variables of "movie" must be defined in order to enable a correct execution of
+* this function:
+* - The number of tracks of each type (movie->num_vtk, movie->num_stk, movie->num_htk)
+* - The memory for each must be allocated (movie->tk)
+* - For each track:
+* The track type (tk->track_type)
+* The number of sample (tk->num_samples)
+* The sample rate (tk->sample_rate)
+*
*/
int mj2_init_stdmovie(mj2_movie_t * movie)
int i;
unsigned int j;
time_t ltime;
+
movie->brand = MJ2_MJ2;
movie->minversion = 0;
- if (!((movie->num_cl<100) && (movie->num_cl>-1))) {
- movie->num_cl = 2;
- movie->cl =
- (unsigned int *) malloc(movie->num_cl * sizeof(unsigned int));
- }
+ movie->num_cl = 2;
+ movie->cl =
+ (unsigned int *) malloc(movie->num_cl * sizeof(unsigned int));
movie->cl[0] = MJ2_MJ2;
movie->cl[1] = MJ2_MJ2S;
for (i = 0; i < movie->num_htk + movie->num_stk + movie->num_vtk; i++) {
mj2_tk_t *tk = &movie->tk[i];
movie->next_tk_id++;
+ tk->jp2_struct.comps = NULL;
+ tk->jp2_struct.cl = NULL;
+
if (tk->track_type == 0) {
if (tk->num_samples == 0)
return 1;
tk->sampletochunk[0].first_chunk = 1;
tk->sampletochunk[0].samples_per_chunk = 1;
tk->sampletochunk[0].sample_descr_idx = 1;
+
+ if (tk->sample_rate == 0) {
+ fprintf(stderr,"Error while initializing MJ2 movie: Sample rate of track %d must be different from zero\n",tk->track_ID);
+ return 1;
+ }
- for (j = 0; j < tk->num_samples; j++)
+ for (j = 0; j < tk->num_samples; j++) {
tk->sample[j].sample_delta = tk->timescale / tk->sample_rate;
+ }
tk->num_tts = 1;
tk->tts = (mj2_tts_t *) malloc(tk->num_tts * sizeof(mj2_tts_t));
tk->visual_w = tk->w << 16;
tk->visual_h = tk->h << 16;
}
+ else {
+ tk->num_br = 0;
+ tk->jp2xdata = NULL;
+ }
}
return 0;
}
tk->track_type = 1;
tk->balance = cio_read(2);
+ /* Init variables to zero to avoid problems when freeeing memory
+ The values will possibly be overidded when decoding the track structure */
+ tk->num_br = 0;
+ tk->num_url = 0;
+ tk->num_urn = 0;
+ tk->num_chunks = 0;
+ tk->num_tts = 0;
+ tk->num_samplestochunk = 0;
+ tk->num_samples = 0;
+
cio_skip(2); /* Reserved */
if (cio_tell() - box.init_pos != box.length) {
tk->avgbitrate = cio_read(4);
tk->slidingavgbitrate = cio_read(4);
+ /* Init variables to zero to avoid problems when freeeing memory
+ The values will possibly be overidded when decoding the track structure */
+ tk->num_br = 0;
+ tk->num_url = 0;
+ tk->num_urn = 0;
+ tk->num_chunks = 0;
+ tk->num_tts = 0;
+ tk->num_samplestochunk = 0;
+ tk->num_samples = 0;
+
+
if (cio_tell() - box.init_pos != box.length) {
fprintf(stderr, "Error with HMHD Box size\n");
return 1;
case MJ2_SKIP:
fsresult = fseek(file,foffset+box.length,SEEK_SET);
if( fsresult ) {
- fprintf(stderr, "End of file reached while trying to read SKIP bo\nx" );
+ fprintf(stderr, "End of file reached while trying to read SKIP box\n" );
return 1;
}
foffset += box.length;
fprintf(stderr, "Unknown box in MJ2 stream\n");
fsresult = fseek(file,foffset+box.length,SEEK_SET);
if( fsresult ) {
- fprintf(stderr, "End of file reached while trying to read %s box\n", box.type );
+ fprintf(stderr, "End of file reached while trying to read end of unknown box\n");
return 1;
}
foffset += box.length;