From 485a597194d373aa233017be47c8cfa1b92748d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:15:26 +0100 Subject: Don't test for the pointer before freeing. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index b46cbc593..f9b14f9e8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -651,8 +651,7 @@ static void free_qt_info(qt_info *info) { for (j = 0; j < info->traks[i].stsd_atoms_count; j++) { if (info->traks[i].type == MEDIA_AUDIO) { free(info->traks[i].stsd_atoms[j].audio.properties_atom); - if (info->traks[i].stsd_atoms[j].audio.wave) - free(info->traks[i].stsd_atoms[j].audio.wave); + free(info->traks[i].stsd_atoms[j].audio.wave); } else if (info->traks[i].type == MEDIA_VIDEO) free(info->traks[i].stsd_atoms[j].video.properties_atom); } -- cgit v1.2.3 From 38b08ea4a1a3130eb05139b7121ece98a4c3d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:04 +0100 Subject: Alloc preview only when needed; use zeroed allocation rather than memset. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index f9b14f9e8..e2db5855a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -686,13 +686,12 @@ static int is_qt_file(input_plugin_t *qt_file) { int64_t moov_atom_size = -1; int i; unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; - unsigned char preview[MAX_PREVIEW_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying * a QT file: In this case, the moov must be the first atom in the file */ if ((qt_file->get_capabilities(qt_file) & INPUT_CAP_SEEKABLE) == 0) { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; len = qt_file->get_optional_data(qt_file, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; -- cgit v1.2.3 From ccb545fca89e270271b9ace18289db433e2e1d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:52 +0100 Subject: Don't use an if when returning a comparison. --- src/demuxers/demux_qt.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index e2db5855a..402b7be99 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -706,10 +706,7 @@ static int is_qt_file(input_plugin_t *qt_file) { i = moov_atom_size + ATOM_PREAMBLE_SIZE; if (i >= MAX_PREVIEW_SIZE) return 0; - if (_X_BE_32(&preview[i - 4]) == MOOV_ATOM) - return 1; - else - return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } else return 0; } -- cgit v1.2.3 From 8d1a32f1880988b27a1da296d0670f24e89954cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:21:41 +0100 Subject: Return right away if the atom is not an FTYP. --- src/demuxers/demux_qt.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 402b7be99..3e5faf390 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -696,19 +696,19 @@ static int is_qt_file(input_plugin_t *qt_file) { if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; else { - if (_X_BE_32(&preview[4]) == FTYP_ATOM) { - /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the - * next atom; if the size is within the range on the preview buffer - * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) - return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; - } else - return 0; + if (_X_BE_32(&preview[4]) != FTYP_ATOM) + return 0; + + /* show some lenience if the first atom is 'ftyp'; the second atom + * could be 'moov' */ + moov_atom_size = _X_BE_32(&preview[0]); + /* compute the size of the current atom plus the preamble of the + * next atom; if the size is within the range on the preview buffer + * then the next atom's preamble is in the preview buffer */ + i = moov_atom_size + ATOM_PREAMBLE_SIZE; + if (i >= MAX_PREVIEW_SIZE) + return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 0deccd94faa1565e28bebefafed7fe32b369d2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:25:38 +0100 Subject: Simplify code, set ftyp_atom_size at once. --- src/demuxers/demux_qt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3e5faf390..2fb79fe2a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -700,15 +700,14 @@ static int is_qt_file(input_plugin_t *qt_file) { return 0; /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the + * could be 'moov' + * compute the size of the current atom plus the preamble of the * next atom; if the size is within the range on the preview buffer * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) + uint64_t ftyp_atom_size = _X_BE_32(&preview[0]) + ATOM_PREAMBLE_SIZE; + if (ftyp_atom_size >= MAX_PREVIEW_SIZE) return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; + return _X_BE_32(&preview[ftyp_atom_size - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 1a366138f0b39cfa1d8586d54f5dfce296a001d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:28:55 +0100 Subject: Allocate atom_preamble only when it's actually going to be used. --- src/demuxers/demux_qt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 2fb79fe2a..3cd573530 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -685,7 +685,6 @@ static int is_qt_file(input_plugin_t *qt_file) { off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; int i; - unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying @@ -715,6 +714,7 @@ static int is_qt_file(input_plugin_t *qt_file) { if (moov_atom_offset == -1) { return 0; } else { + unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; /* check that the next atom in the chunk contains alphanumeric * characters in the atom type field; if not, disqualify the file * as a QT file */ -- cgit v1.2.3 From d3298c9017077d3ea3ea91110dcac349d58448a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:34:40 +0100 Subject: Replace seven calls to parse_data_atom with a single call, and then set the value on the proper structure. This way, parse_data_atom is inlined by GCC. --- src/demuxers/demux_qt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3cd573530..4c9399608 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -801,31 +801,33 @@ static void parse_meta_atom(qt_info *info, unsigned char *meta_atom) { const uint8_t *const sub_atom = &meta_atom[j]; const qt_atom sub_atom_code = _X_BE_32(&sub_atom[4]); const uint32_t sub_atom_size = _X_BE_32(&sub_atom[0]); + char *const data_atom = parse_data_atom(&sub_atom[8]); switch(sub_atom_code) { case ART_ATOM: - info->artist = parse_data_atom(&sub_atom[8]); + info->artist = data_atom; break; case NAM_ATOM: - info->name = parse_data_atom(&sub_atom[8]); + info->name = data_atom; break; case ALB_ATOM: - info->album = parse_data_atom(&sub_atom[8]); + info->album = data_atom; break; case GEN_ATOM: - info->genre = parse_data_atom(&sub_atom[8]); + info->genre = data_atom; break; case CMT_ATOM: - info->comment = parse_data_atom(&sub_atom[8]); + info->comment = data_atom; break; case WRT_ATOM: - info->composer = parse_data_atom(&sub_atom[8]); + info->composer = data_atom; break; case DAY_ATOM: - info->year = parse_data_atom(&sub_atom[8]); + info->year = data_atom; break; default: debug_meta_load("unknown atom %08x in ilst\n", sub_atom_code); + free(data_atom); } j += sub_atom_size; -- cgit v1.2.3 From c57b06b240fd159758f93206726556f31e12a8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:36:37 +0100 Subject: Declare color_* variables only when actually used. --- src/demuxers/demux_qt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 4c9399608..ae657fb66 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1004,18 +1004,17 @@ static qt_error parse_trak_atom (qt_trak *trak, const uint32_t current_stsd_atom_size = _X_BE_32(&trak_atom[atom_pos - 4]); - /* for palette traversal */ - int color_depth; - int color_flag; - int color_start; - int color_count; - int color_end; - int color_index; - int color_dec; - int color_greyscale; - const unsigned char *color_table; - if (trak->type == MEDIA_VIDEO) { + /* for palette traversal */ + int color_depth; + int color_flag; + int color_start; + int color_count; + int color_end; + int color_index; + int color_dec; + int color_greyscale; + const unsigned char *color_table; trak->stsd_atoms[k].video.media_id = k + 1; trak->stsd_atoms[k].video.properties_offset = properties_offset; -- cgit v1.2.3 From 80826e77cf419d92711e175dcc9e40edaecfd7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:43:36 +0100 Subject: Use calloc() when the allocated size would be counted by multiplying the size of an item for the number of items. Also don't memset calloc()ed areas to zero. --- src/demuxers/demux_qt.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index ae657fb66..3fb60c1a8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1459,8 +1459,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stco atom (32-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1487,8 +1486,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt co64 atom (64-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1518,8 +1516,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stsc atom (sample-to-chunk atom): %d entries\n", trak->sample_to_chunk_count); - trak->sample_to_chunk_table = (sample_to_chunk_table_t *)malloc( - trak->sample_to_chunk_count * sizeof(sample_to_chunk_table_t)); + trak->sample_to_chunk_table = calloc(trak->sample_to_chunk_count, sizeof(sample_to_chunk_table_t)); if (!trak->sample_to_chunk_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1553,8 +1550,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stts atom (time-to-sample atom): %d entries\n", trak->time_to_sample_count); - trak->time_to_sample_table = (time_to_sample_table_t *)malloc( - (trak->time_to_sample_count+1) * sizeof(time_to_sample_table_t)); + trak->time_to_sample_table = calloc(trak->time_to_sample_count+1, sizeof(time_to_sample_table_t)); if (!trak->time_to_sample_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1747,8 +1743,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * entries in the sample size table */ trak->frame_count = trak->sample_size_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; trak->current_frame = 0; @@ -1760,10 +1755,9 @@ static qt_error build_frame_table(qt_trak *trak, pts_index_countdown = trak->time_to_sample_table[pts_index].count; - media_id_counts = xine_xmalloc(trak->stsd_atoms_count * sizeof(int)); + media_id_counts = xine_xcalloc(trak->stsd_atoms_count, sizeof(int)); if (!media_id_counts) return QT_NO_MEMORY; - memset(media_id_counts, 0, trak->stsd_atoms_count * sizeof(int)); /* iterate through each start chunk in the stsc table */ for (i = 0; i < trak->sample_to_chunk_count; i++) { @@ -1898,8 +1892,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * chunks */ trak->frame_count = trak->chunk_offset_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; -- cgit v1.2.3 From 8e9cb121101b1b43f6b52cd01e3e0fb841c538c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:46:23 +0100 Subject: Allocate the preview buffer only when actually needed; use zeroed allocation rather than memset(). --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers/demux_qt.c') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3fb60c1a8..8fb554de2 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -2134,7 +2134,6 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, unsigned char *moov_atom = NULL; off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; - unsigned char preview[MAX_PREVIEW_SIZE]; /* zlib stuff */ z_stream z_state; @@ -2157,7 +2156,7 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, if ((input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) find_moov_atom(input, &moov_atom_offset, &moov_atom_size); else { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; input->get_optional_data(input, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) != MOOV_ATOM) { /* special case if there is an ftyp atom first */ -- cgit v1.2.3