From: Diego 'F. P. <fla...@gm...> - 2008-05-08 05:24:18
|
# HG changeset patch # User Diego 'Flameeyes' Pettenò <fla...@gm...> # Date 1210224235 -7200 # Node ID 15750fdf65fb9958f3f932826ff76eb4988a2286 # Parent 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 More split out, qt_parser.c and qt_debug.h Use the first to keep the generic parsing functions for atoms, like parse_atom. The latter instead to keep debug system declarations and definitions. Also add some unused attribute to shut up warnings. diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/Makefile.am --- a/src/demuxers/quicktime/Makefile.am Thu May 08 07:23:55 2008 +0200 +++ b/src/demuxers/quicktime/Makefile.am Thu May 08 07:12:11 2008 +0200 @@ -9,6 +9,8 @@ xineplug_dmx_qt_la_SOURCES = \ atoms.h \ demux_qt.c \ metadata.c \ + qt_debug.h \ + qt_parser.c \ qt_parser.h \ qtpalette.h diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/demux_qt.c --- a/src/demuxers/quicktime/demux_qt.c Thu May 08 07:23:55 2008 +0200 +++ b/src/demuxers/quicktime/demux_qt.c Thu May 08 07:12:11 2008 +0200 @@ -52,6 +52,7 @@ #include "qtpalette.h" #include "atoms.h" #include "qt_parser.h" +#include "qt_debug.h" #define ATOM_PREAMBLE_SIZE 8 @@ -94,86 +95,6 @@ typedef struct { xine_t *xine; config_values_t *config; } demux_qt_class_t; - -/********************************************************************** - * lazyqt special debugging functions - **********************************************************************/ - -/* define DEBUG_ATOM_LOAD as 1 to get a verbose parsing of the relevant - * atoms */ -#define DEBUG_ATOM_LOAD 1 - -/* define DEBUG_EDIT_LIST as 1 to get a detailed look at how the demuxer is - * handling edit lists */ -#define DEBUG_EDIT_LIST 0 - -/* define DEBUG_FRAME_TABLE as 1 to dump the complete frame table that the - * demuxer plans to use during file playback */ -#define DEBUG_FRAME_TABLE 0 - -/* define DEBUG_VIDEO_DEMUX as 1 to see details about the video chunks the - * demuxer is sending off to the video decoder */ -#define DEBUG_VIDEO_DEMUX 0 - -/* define DEBUG_AUDIO_DEMUX as 1 to see details about the audio chunks the - * demuxer is sending off to the audio decoder */ -#define DEBUG_AUDIO_DEMUX 0 - -/* Define DEBUG_DUMP_MOOV as 1 to dump the raw moov atom to disk. This is - * particularly useful in debugging a file with a compressed moov (cmov) - * atom. The atom will be dumped to the filename specified as - * RAW_MOOV_FILENAME. */ -#define DEBUG_DUMP_MOOV 0 -#define RAW_MOOV_FILENAME "moovatom.raw" - -#if DEBUG_ATOM_LOAD -#define debug_atom_load(...) fprintf(stderr, __VA_ARGS__) -#else -static inline void XINE_FORMAT_PRINTF(1, 2) debug_atom_load(const char *format, ...) {} -#endif - -#if DEBUG_EDIT_LIST -#define debug_edit_list printf -#else -static inline void XINE_FORMAT_PRINTF(1, 2) debug_edit_list(const char *format, ...) {} -#endif - -#if DEBUG_FRAME_TABLE -#define debug_frame_table printf -#else -static inline void XINE_FORMAT_PRINTF(1, 2) debug_frame_table(const char *format, ...) {} -#endif - -#if DEBUG_VIDEO_DEMUX -#define debug_video_demux printf -#else -static inline void XINE_FORMAT_PRINTF(1, 2) debug_video_demux(const char *format, ...) {} -#endif - -#if DEBUG_AUDIO_DEMUX -#define debug_audio_demux printf -#else -static inline void XINE_FORMAT_PRINTF(1, 2) debug_audio_demux(const char *format, ...) {} -#endif - -static inline void dump_moov_atom(unsigned char *moov_atom, int moov_atom_size) { -#if DEBUG_DUMP_MOOV - - FILE *f; - - f = fopen(RAW_MOOV_FILENAME, "w"); - if (!f) { - perror(RAW_MOOV_FILENAME); - return; - } - - if (fwrite(moov_atom, moov_atom_size, 1, f) != 1) - printf (" qt debug: could not write moov atom to disk\n"); - - fclose(f); - -#endif -} /********************************************************************** * lazyqt functions @@ -440,36 +361,6 @@ static int is_qt_file(input_plugin_t *qt } } -/** - * @brief Read a string from a 'data' atom. - * @param atom Pointer to the 'data' atom (included signature) - * @return A copy of the string as read from the atom. - * - * This function will discard the signature data for the string, and - * return a copy of the string. - */ -char *qt_data_read_string(const uint8_t *atom) { - const size_t atom_size = _X_BE_32(&atom[0]); - /* We want it to be a 'data' atom for the string to be read. */ - _x_assert(_X_BE_32(&atom[4]) == DATA_ATOM); - - /* The data atom will contain: - * - 4 bytes size; - * - 4 bytes signature; - * - 1 byte version; - * - 3 bytes flags; - * - 4 bytes reserved; - * - N bytes actual data - * - * Make sure that the size is big enough. - */ - static const size_t data_atom_preamble = 4 + 4 + 1 + 3 + 4; - if ( atom_size <= data_atom_preamble ) - return NULL; - - return strndup(&atom[data_atom_preamble], atom_size - data_atom_preamble); -} - /* fetch interesting information from the movie header atom */ static void parse_mvhd_atom(qt_info *info, size_t atom_size, uint8_t *mvhd_atom, void *data __attr_unused) { @@ -488,40 +379,7 @@ static void parse_reference_atom(qt_info static void parse_reference_atom(qt_info *info, size_t atom_size, uint8_t *trak_atom, void *data __attr_unused); -/** - * @brief Parse a generic atom - * @param info The instance info for the QT parser - * @param size Size of the current atom - * @param atom Start of the current atom - * @param handler Table for handling of sub-atoms - */ -void parse_atom(qt_info *info, size_t size, const uint8_t *atom, const atom_handler *handler) { - size_t i = handler->preamble; - - while (i < size) { - const size_t sub_atom_size = _X_BE_32(&atom[i]); - const qt_atom sub_atom_type = _X_BE_32(&atom[i+4]); - - atom_handler_entry *entry = &handler->entries; - while (entry->atom) { - if (entry->atom == sub_atom_type) { - if (entry->handler != NULL) - entry->handler(info, sub_atom_size-8, &atom[i+8], entry->data); - break; - } - entry++; - } - - if (entry->atom == 0) { - debug_atom_load(" qt: unknown atom %08x [%*s] found in %s atom (%tu [%p])\n", - sub_atom_type, 4, &atom[i+4], handler->name, i, &atom[i]); - } - - i += sub_atom_size; - } -} - -static const atom_handler moov_atom_handler = { +static const qt_atom_handler moov_atom_handler = { .preamble = 0, .name = "moov", .entries = { @@ -529,9 +387,9 @@ static const atom_handler moov_atom_hand { RMDA_ATOM, parse_reference_atom, NULL }, { RMRA_ATOM, parse_reference_atom, NULL }, { TRAK_ATOM, parse_trak_atom, NULL }, - { UDTA_ATOM, parse_atom, &udta_atom_handler }, - METADATA_HANDLER_ENTRIES, - ATOM_HANDLER_END_ENTRIES + { UDTA_ATOM, qt_parse_atom, &udta_atom_handler }, + QT_METADATA_HANDLER_ENTRIES, + QT_ATOM_HANDLER_END_ENTRIES } }; @@ -1672,7 +1530,7 @@ static void parse_moov_atom(qt_info *inf } /* prowl through the moov atom looking for very specific targets */ - parse_atom(info, moov_atom_size-8, &moov_atom[ATOM_PREAMBLE_SIZE], &moov_atom_handler); + qt_parse_atom(info, moov_atom_size-8, &moov_atom[ATOM_PREAMBLE_SIZE], &moov_atom_handler); /* build frame tables corresponding to each trak */ debug_frame_table(" qt: preparing to build %d frame tables\n", diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/metadata.c --- a/src/demuxers/quicktime/metadata.c Thu May 08 07:23:55 2008 +0200 +++ b/src/demuxers/quicktime/metadata.c Thu May 08 07:12:11 2008 +0200 @@ -33,7 +33,7 @@ * @param atom Pointer to the first byte of the atom's data * @param key_ptr Metadata key to set, casted to void* */ -void parse_metadata_entry(qt_info *info, size_t atom_size __attr_unused, const uint8_t *atom, void *key_ptr) { +void qt_parse_metadata_entry(qt_info *info, size_t atom_size __attr_unused, const uint8_t *atom, void *key_ptr) { /* Ignore unknown keys */ if ( (unsigned long)key_ptr >= QT_META_LAST ) @@ -59,29 +59,33 @@ void parse_metadata_entry(qt_info *info, *(keys[(unsigned long)key_ptr]) = str; } -static const atom_handler ilst_atom_handler = { +static const qt_atom_handler ilst_atom_handler = { .preamble = 0, .name = "ilst", .entries = { - METADATA_HANDLER_ENTRIES, - ATOM_HANDLER_END_ENTRIES + QT_METADATA_HANDLER_ENTRIES, + QT_ATOM_HANDLER_END_ENTRIES } }; -static const atom_handler meta_atom_handler = { +static const qt_atom_handler meta_atom_handler = { .preamble = 4, .name = "meta", .entries = { - { ILST_ATOM, parse_atom, &ilst_atom_handler }, - ATOM_HANDLER_END_ENTRIES + { ILST_ATOM, qt_parse_atom, &ilst_atom_handler }, + QT_ATOM_HANDLER_END_ENTRIES } }; -const atom_handler udta_atom_handler = { +/** + * @ingroup qt_metadata + * @brief Handlers table for the 'udta' atom + */ +const qt_atom_handler udta_atom_handler = { .preamble = 0, .name = "udta", .entries = { - { META_ATOM, parse_atom, &meta_atom_handler }, - ATOM_HANDLER_END_ENTRIES + { META_ATOM, qt_parse_atom, &meta_atom_handler }, + QT_ATOM_HANDLER_END_ENTRIES } }; diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/qt_parser.h --- a/src/demuxers/quicktime/qt_parser.h Thu May 08 07:23:55 2008 +0200 +++ b/src/demuxers/quicktime/qt_parser.h Thu May 08 07:12:11 2008 +0200 @@ -237,14 +237,14 @@ typedef struct { qt_error last_error; } qt_info; -typedef void (*atom_handler_cb)(qt_info *, size_t, const uint8_t *, - void*); +typedef void (*qt_atom_handler_cb)(qt_info *, size_t, const uint8_t *, + void*); typedef struct { qt_atom atom; - atom_handler_cb handler; + qt_atom_handler_cb handler; void *data; -} atom_handler_entry; +} qt_atom_handler_entry; /** * @brief Handler for parsing of an MP4/QuickTime atom @@ -260,16 +260,16 @@ typedef struct { /**< Size of the preamble for the atom. */ const char *name; /**< Name of the atom (for debug purposes). */ - atom_handler_entry entries[]; + qt_atom_handler_entry entries[]; /**< Handlers for the various atoms. */ -} atom_handler; - -#define ATOM_HANDLER_END_ENTRIES \ +} qt_atom_handler; + +#define QT_ATOM_HANDLER_END_ENTRIES \ { FREE_ATOM, NULL, NULL }, \ { 0, NULL, NULL } -void parse_atom(qt_info *info, size_t size, const uint8_t *atom, - const atom_handler *handler); +void qt_parse_atom(qt_info *info, size_t size, const uint8_t *atom, + const qt_atom_handler *handler); char *qt_data_read_string(const uint8_t *atom); @@ -297,21 +297,21 @@ enum qt_metadata_keys { QT_META_LAST }; -#define METADATA_HANDLER_ENTRIES \ - { ALB_ATOM, parse_metadata_entry, (void*)QT_META_ALBUM }, \ - { ART_ATOM, parse_metadata_entry, (void*)QT_META_ARTIST }, \ - { CMT_ATOM, parse_metadata_entry, (void*)QT_META_COMMENT }, \ - { CPY_ATOM, parse_metadata_entry, (void*)QT_META_COPYRIGHT }, \ - { DAY_ATOM, parse_metadata_entry, (void*)QT_META_YEAR }, \ - { DES_ATOM, parse_metadata_entry, (void*)QT_META_DESCRIPTION }, \ - { GEN_ATOM, parse_metadata_entry, (void*)QT_META_GENRE }, \ - { NAM_ATOM, parse_metadata_entry, (void*)QT_META_NAME }, \ - { TOO_ATOM, parse_metadata_entry, (void*)QT_META_COMMENT }, \ - { WRT_ATOM, parse_metadata_entry, (void*)QT_META_COMPOSER } - -void parse_metadata_entry(qt_info *info, size_t atom_size, const uint8_t *atom, - void *key_ptr); - -extern const atom_handler udta_atom_handler; +#define QT_METADATA_HANDLER_ENTRIES \ + { ALB_ATOM, qt_parse_metadata_entry, (void*)QT_META_ALBUM }, \ + { ART_ATOM, qt_parse_metadata_entry, (void*)QT_META_ARTIST }, \ + { CMT_ATOM, qt_parse_metadata_entry, (void*)QT_META_COMMENT }, \ + { CPY_ATOM, qt_parse_metadata_entry, (void*)QT_META_COPYRIGHT }, \ + { DAY_ATOM, qt_parse_metadata_entry, (void*)QT_META_YEAR }, \ + { DES_ATOM, qt_parse_metadata_entry, (void*)QT_META_DESCRIPTION }, \ + { GEN_ATOM, qt_parse_metadata_entry, (void*)QT_META_GENRE }, \ + { NAM_ATOM, qt_parse_metadata_entry, (void*)QT_META_NAME }, \ + { TOO_ATOM, qt_parse_metadata_entry, (void*)QT_META_COMMENT }, \ + { WRT_ATOM, qt_parse_metadata_entry, (void*)QT_META_COMPOSER } + +void qt_parse_metadata_entry(qt_info *info, size_t atom_size, const uint8_t *atom, + void *key_ptr); + +extern const qt_atom_handler udta_atom_handler; #endif diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/qt_debug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demuxers/quicktime/qt_debug.h Thu May 08 07:12:11 2008 +0200 @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2001-2008 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + */ + +/** + * @file + * @brief Declarations and definitions for QuickTime/MPEG4 debugging + */ + +#ifndef QT_DEBUG_H__ +#define QT_DEBUG_H__ + +#include "xine_internal.h" + +/* define DEBUG_ATOM_LOAD as 1 to get a verbose parsing of the relevant + * atoms */ +#define DEBUG_ATOM_LOAD 1 + +/* define DEBUG_EDIT_LIST as 1 to get a detailed look at how the demuxer is + * handling edit lists */ +#define DEBUG_EDIT_LIST 0 + +/* define DEBUG_FRAME_TABLE as 1 to dump the complete frame table that the + * demuxer plans to use during file playback */ +#define DEBUG_FRAME_TABLE 0 + +/* define DEBUG_VIDEO_DEMUX as 1 to see details about the video chunks the + * demuxer is sending off to the video decoder */ +#define DEBUG_VIDEO_DEMUX 0 + +/* define DEBUG_AUDIO_DEMUX as 1 to see details about the audio chunks the + * demuxer is sending off to the audio decoder */ +#define DEBUG_AUDIO_DEMUX 0 + +/* Define DEBUG_DUMP_MOOV as 1 to dump the raw moov atom to disk. This is + * particularly useful in debugging a file with a compressed moov (cmov) + * atom. The atom will be dumped to the filename specified as + * RAW_MOOV_FILENAME. */ +#define DEBUG_DUMP_MOOV 0 +#define RAW_MOOV_FILENAME "moovatom.raw" + +#if DEBUG_ATOM_LOAD +#define debug_atom_load(...) fprintf(stderr, __VA_ARGS__) +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_atom_load(const char *format __attr_unused, ...) {} +#endif + +#if DEBUG_EDIT_LIST +#define debug_edit_list(...) fprintf(stderr, __VA_ARGS__) +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_edit_list(const char *format __attr_unused, ...) {} +#endif + +#if DEBUG_FRAME_TABLE +#define debug_frame_table(...) fprintf(stderr, __VA_ARGS__) +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_frame_table(const char *format __attr_unused, ...) {} +#endif + +#if DEBUG_VIDEO_DEMUX +#define debug_video_demux(...) fprintf(stderr, __VA_ARGS__) +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_video_demux(const char *format __attr_unused, ...) {} +#endif + +#if DEBUG_AUDIO_DEMUX +#define debug_audio_demux(...) fprintf(stderr, __VA_ARGS__) +#else +static inline void XINE_FORMAT_PRINTF(1, 2) debug_audio_demux(const char *format __attr_unused, ...) {} +#endif + +#if DEBUG_DUMP_MOOV +static inline void dump_moov_atom(unsigned char *moov_atom, int moov_atom_size) { + + FILE *f; + + f = fopen(RAW_MOOV_FILENAME, "w"); + if (!f) { + perror(RAW_MOOV_FILENAME); + return; + } + + if (fwrite(moov_atom, moov_atom_size, 1, f) != 1) + printf (" qt debug: could not write moov atom to disk\n"); + + fclose(f); + +} +#else +#define dump_moov_atom(x, y) +#endif + +#endif diff -r 15750fdf65fb9958f3f932826ff76eb4988a2286 -r 33f1f6b08c16656901ce7658a9d2bdbdf27fa805 src/demuxers/quicktime/qt_parser.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demuxers/quicktime/qt_parser.c Thu May 08 07:12:11 2008 +0200 @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2001-2008 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + */ + +/** + * @file + * @brief Definition of generic functions for QuickTime/MPEG4 parsing + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "qt_parser.h" +#include "qt_debug.h" +#include <string.h> + +/** + * @brief Read a string from a 'data' atom. + * @param atom Pointer to the 'data' atom (included signature) + * @return A copy of the string as read from the atom. + * + * This function will discard the signature data for the string, and + * return a copy of the string. + */ +char *qt_data_read_string(const uint8_t *atom) { + const size_t atom_size = _X_BE_32(&atom[0]); + /* We want it to be a 'data' atom for the string to be read. */ + _x_assert(_X_BE_32(&atom[4]) == DATA_ATOM); + + /* The data atom will contain: + * - 4 bytes size; + * - 4 bytes signature; + * - 1 byte version; + * - 3 bytes flags; + * - 4 bytes reserved; + * - N bytes actual data + * + * Make sure that the size is big enough. + */ + static const size_t data_atom_preamble = 4 + 4 + 1 + 3 + 4; + if ( atom_size <= data_atom_preamble ) + return NULL; + + return strndup(&atom[data_atom_preamble], atom_size - data_atom_preamble); +} + +/** + * @brief Parse a generic QuickTime atom + * @param info The instance info for the QT parser + * @param size Size of the current atom + * @param atom Start of the current atom + * @param handler Table for handling of sub-atoms + */ +void qt_parse_atom(qt_info *info, size_t size, const uint8_t *atom, + const qt_atom_handler *handler) { + size_t i = handler->preamble; + + while (i < size) { + const size_t sub_atom_size = _X_BE_32(&atom[i]); + const qt_atom sub_atom_type = _X_BE_32(&atom[i+4]); + + const qt_atom_handler_entry *entry = &handler->entries[0]; + while (entry->atom) { + if (entry->atom == sub_atom_type) { + if (entry->handler != NULL) + entry->handler(info, sub_atom_size-8, &atom[i+8], entry->data); + break; + } + entry++; + } + + if (entry->atom == 0) { + debug_atom_load(" qt: unknown atom %08x [%*s] found in %s atom (%tu [%p])\n", + sub_atom_type, 4, &atom[i+4], handler->name, i, &atom[i]); + } + + i += sub_atom_size; + } +} |