Bug with sound and hint tracks fixed

This commit is contained in:
Francois-Olivier Devaux 2004-09-06 15:53:36 +00:00
parent 2ebe5f2c92
commit 7250ce0668
1 changed files with 73 additions and 78 deletions

151
mj2/mj2.c
View File

@ -464,98 +464,93 @@ int mj2_write_mdat(FILE * outfile, mj2_movie_t * movie, j2k_image_t * img,
unsigned int j; unsigned int j;
int pos_correction = 0; int pos_correction = 0;
int tileno; int tileno;
box.init_pos = cio_tell(); box.init_pos = cio_tell();
cio_skip(4); cio_skip(4);
cio_write(MJ2_MDAT, 4); /* MDAT */ cio_write(MJ2_MDAT, 4); /* MDAT */
for (i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) {
for (i = 0; i < movie->num_stk; i++) { if (movie->tk[i].track_type != 0) {
fprintf(stderr, "Unable to write sound tracks\n"); fprintf(stderr, "Unable to write sound or hint tracks\n");
} } else {
j2k_cp_t cp_init;
for (i = 0; i < movie->num_htk; i++) { mj2_tk_t *tk;
fprintf(stderr, "Unable to write hint tracks\n");
} tk = &movie->tk[i];
for (i = 0; i < movie->num_vtk; i++) { fprintf(stderr, "Video Track number %d\n", i + 1);
j2k_cp_t cp_init;
mj2_tk_t *tk; len = cio_tell();
tk = &movie->tk[i];
fprintf(stderr, "Video Track number %d\n", i + 1);
len = cio_tell();
fwrite(outbuf, 1, len, outfile);
pos_correction = cio_tell() + pos_correction;
free(outbuf);
/* Copy the first tile coding parameters (tcp) to cp_init */
cp_init.tcps =
(j2k_tcp_t *) malloc(cp->tw * cp->th * sizeof(j2k_tcp_t));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
for (l = 0; l < cp->tcps[tileno].numlayers; l++) {
cp_init.tcps[tileno].rates[l] = cp->tcps[tileno].rates[l];
//tileno = cp->tcps[tileno].rates[l];
}
}
for (j = 0; j < tk->num_samples; j++) {
outbuf = (char *) malloc(cp->tdx * cp->tdy * cp->th * cp->tw * 2);
cio_init(outbuf, cp->tdx * cp->tdy * cp->th * cp->tw * 2);
fprintf(stderr, "Frame number %d/%d: \n", j + 1, tk->num_samples);
if (!yuvtoimage(tk, img, j)) {
fprintf(stderr, "Error with frame number %d in YUV file\n", j);
return 1;
}
len = jp2_write_jp2c(img, cp, outbuf, index);
for (m = 0; m < img->numcomps; m++) {
free(img->comps[m].data);
}
tk->sample[j].sample_size = len;
tk->sample[j].offset = pos_correction;
tk->chunk[j].offset = pos_correction; /* There is one sample per chunk */
fwrite(outbuf, 1, len, outfile); fwrite(outbuf, 1, len, outfile);
pos_correction = cio_tell() + pos_correction; pos_correction = cio_tell() + pos_correction;
free(outbuf); free(outbuf);
/* Copy the cp_init parameters to cp->tcps */ /* Copy the first tile coding parameters (tcp) to cp_init */
cp_init.tcps =
(j2k_tcp_t *) malloc(cp->tw * cp->th * sizeof(j2k_tcp_t));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
for (k = 0; k < cp->tcps[tileno].numlayers; k++) { for (l = 0; l < cp->tcps[tileno].numlayers; l++) {
cp->tcps[tileno].rates[k] = cp_init.tcps[tileno].rates[k]; cp_init.tcps[tileno].rates[l] = cp->tcps[tileno].rates[l];
//tileno = cp->tcps[tileno].rates[l];
}
}
for (j = 0; j < tk->num_samples; j++) {
outbuf = (char *) malloc(cp->tdx * cp->tdy * cp->th * cp->tw * 2);
cio_init(outbuf, cp->tdx * cp->tdy * cp->th * cp->tw * 2);
fprintf(stderr, "Frame number %d/%d: \n", j + 1, tk->num_samples);
if (!yuvtoimage(tk, img, j)) {
fprintf(stderr, "Error with frame number %d in YUV file\n", j);
return 1;
}
len = jp2_write_jp2c(img, cp, outbuf, index);
for (m = 0; m < img->numcomps; m++) {
free(img->comps[m].data);
}
tk->sample[j].sample_size = len;
tk->sample[j].offset = pos_correction;
tk->chunk[j].offset = pos_correction; /* There is one sample per chunk */
fwrite(outbuf, 1, len, outfile);
pos_correction = cio_tell() + pos_correction;
free(outbuf);
/* Copy the cp_init parameters to cp->tcps */
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
for (k = 0; k < cp->tcps[tileno].numlayers; k++) {
cp->tcps[tileno].rates[k] = cp_init.tcps[tileno].rates[k];
}
} }
} }
} }
box.length = pos_correction - box.init_pos;
fseek(outfile, box.init_pos, SEEK_SET);
cio_init(&box_len_ptr, 4); /* Init a cio to write box length variable in a little endian way */
cio_write(box.length, 4);
fwrite(&box_len_ptr, 4, 1, outfile);
fseek(outfile, box.init_pos + box.length, SEEK_SET);
} }
box.length = pos_correction - box.init_pos;
fseek(outfile, box.init_pos, SEEK_SET);
cio_init(&box_len_ptr, 4); /* Init a cio to write box length variable in a little endian way */
cio_write(box.length, 4);
fwrite(&box_len_ptr, 4, 1, outfile);
fseek(outfile, box.init_pos + box.length, SEEK_SET);
return 0; return 0;
} }
/* /*
* Read the MDAT box * Read the MDAT box
* *