mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-17 12:51:36 +00:00
qt-faststart: Use the error_out cleanup code path for all error returns
Originally committed as revision 23125 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
7a0e859cdb
commit
c937454d89
@ -75,14 +75,14 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *infile;
|
FILE *infile = NULL;
|
||||||
FILE *outfile;
|
FILE *outfile = NULL;
|
||||||
unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
|
unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
|
||||||
uint32_t atom_type = 0;
|
uint32_t atom_type = 0;
|
||||||
uint64_t atom_size = 0;
|
uint64_t atom_size = 0;
|
||||||
uint64_t atom_offset = 0;
|
uint64_t atom_offset = 0;
|
||||||
uint64_t last_offset;
|
uint64_t last_offset;
|
||||||
unsigned char *moov_atom;
|
unsigned char *moov_atom = NULL;
|
||||||
unsigned char *ftyp_atom = 0;
|
unsigned char *ftyp_atom = 0;
|
||||||
uint64_t moov_atom_size;
|
uint64_t moov_atom_size;
|
||||||
uint64_t ftyp_atom_size = 0;
|
uint64_t ftyp_atom_size = 0;
|
||||||
@ -101,7 +101,7 @@ int main(int argc, char *argv[])
|
|||||||
infile = fopen(argv[1], "rb");
|
infile = fopen(argv[1], "rb");
|
||||||
if (!infile) {
|
if (!infile) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
return 1;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* traverse through the atoms in the file to make sure that 'moov' is
|
/* traverse through the atoms in the file to make sure that 'moov' is
|
||||||
@ -121,15 +121,12 @@ int main(int argc, char *argv[])
|
|||||||
if (!ftyp_atom) {
|
if (!ftyp_atom) {
|
||||||
printf ("could not allocate %"PRIu64" byte for ftyp atom\n",
|
printf ("could not allocate %"PRIu64" byte for ftyp atom\n",
|
||||||
atom_size);
|
atom_size);
|
||||||
fclose(infile);
|
goto error_out;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
|
fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
|
||||||
if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
|
if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
free(ftyp_atom);
|
goto error_out;
|
||||||
fclose(infile);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
start_offset = ftello(infile);
|
start_offset = ftello(infile);
|
||||||
} else {
|
} else {
|
||||||
@ -184,30 +181,23 @@ int main(int argc, char *argv[])
|
|||||||
if (!moov_atom) {
|
if (!moov_atom) {
|
||||||
printf ("could not allocate %"PRIu64" byte for moov atom\n",
|
printf ("could not allocate %"PRIu64" byte for moov atom\n",
|
||||||
atom_size);
|
atom_size);
|
||||||
free(ftyp_atom);
|
goto error_out;
|
||||||
fclose(infile);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
if (fread(moov_atom, atom_size, 1, infile) != 1) {
|
if (fread(moov_atom, atom_size, 1, infile) != 1) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
free(moov_atom);
|
goto error_out;
|
||||||
free(ftyp_atom);
|
|
||||||
fclose(infile);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this utility does not support compressed atoms yet, so disqualify
|
/* this utility does not support compressed atoms yet, so disqualify
|
||||||
* files with compressed QT atoms */
|
* files with compressed QT atoms */
|
||||||
if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
|
if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
|
||||||
printf ("this utility does not support compressed moov atoms yet\n");
|
printf ("this utility does not support compressed moov atoms yet\n");
|
||||||
free(moov_atom);
|
goto error_out;
|
||||||
free(ftyp_atom);
|
|
||||||
fclose(infile);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close; will be re-opened later */
|
/* close; will be re-opened later */
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
infile = NULL;
|
||||||
|
|
||||||
/* crawl through the moov chunk in search of stco or co64 atoms */
|
/* crawl through the moov chunk in search of stco or co64 atoms */
|
||||||
for (i = 4; i < moov_atom_size - 4; i++) {
|
for (i = 4; i < moov_atom_size - 4; i++) {
|
||||||
@ -217,9 +207,7 @@ int main(int argc, char *argv[])
|
|||||||
atom_size = BE_32(&moov_atom[i - 4]);
|
atom_size = BE_32(&moov_atom[i - 4]);
|
||||||
if (i + atom_size - 4 > moov_atom_size) {
|
if (i + atom_size - 4 > moov_atom_size) {
|
||||||
printf (" bad atom size\n");
|
printf (" bad atom size\n");
|
||||||
free(moov_atom);
|
goto error_out;
|
||||||
free(ftyp_atom);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
offset_count = BE_32(&moov_atom[i + 8]);
|
offset_count = BE_32(&moov_atom[i + 8]);
|
||||||
for (j = 0; j < offset_count; j++) {
|
for (j = 0; j < offset_count; j++) {
|
||||||
@ -236,9 +224,7 @@ int main(int argc, char *argv[])
|
|||||||
atom_size = BE_32(&moov_atom[i - 4]);
|
atom_size = BE_32(&moov_atom[i - 4]);
|
||||||
if (i + atom_size - 4 > moov_atom_size) {
|
if (i + atom_size - 4 > moov_atom_size) {
|
||||||
printf (" bad atom size\n");
|
printf (" bad atom size\n");
|
||||||
free(moov_atom);
|
goto error_out;
|
||||||
free(ftyp_atom);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
offset_count = BE_32(&moov_atom[i + 8]);
|
offset_count = BE_32(&moov_atom[i + 8]);
|
||||||
for (j = 0; j < offset_count; j++) {
|
for (j = 0; j < offset_count; j++) {
|
||||||
@ -261,9 +247,7 @@ int main(int argc, char *argv[])
|
|||||||
infile = fopen(argv[1], "rb");
|
infile = fopen(argv[1], "rb");
|
||||||
if (!infile) {
|
if (!infile) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
free(moov_atom);
|
goto error_out;
|
||||||
free(ftyp_atom);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_offset > 0) { /* seek after ftyp atom */
|
if (start_offset > 0) { /* seek after ftyp atom */
|
||||||
@ -274,10 +258,7 @@ int main(int argc, char *argv[])
|
|||||||
outfile = fopen(argv[2], "wb");
|
outfile = fopen(argv[2], "wb");
|
||||||
if (!outfile) {
|
if (!outfile) {
|
||||||
perror(argv[2]);
|
perror(argv[2]);
|
||||||
fclose(outfile);
|
goto error_out;
|
||||||
free(moov_atom);
|
|
||||||
free(ftyp_atom);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dump the same ftyp atom */
|
/* dump the same ftyp atom */
|
||||||
@ -324,7 +305,9 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_out:
|
error_out:
|
||||||
|
if (infile)
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
if (outfile)
|
||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
free(moov_atom);
|
free(moov_atom);
|
||||||
free(ftyp_atom);
|
free(ftyp_atom);
|
||||||
|
Loading…
Reference in New Issue
Block a user