From: Andre P. <at...@us...> - 2004-07-10 10:06:40
|
Update of /cvsroot/xine/xine-lib/src/demuxers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26010 Modified Files: demux_ogg.c Log Message: Split detect_content function into detect_ogg_content and detect_anx_content Scan for "Annodex" header signature in Annodex demuxer Fixed some serious bugs in detect_content at the same time :) Index: demux_ogg.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/demuxers/demux_ogg.c,v retrieving revision 1.148 retrieving revision 1.149 diff -u -r1.148 -r1.149 --- demux_ogg.c 9 Jul 2004 01:27:42 -0000 1.148 +++ demux_ogg.c 10 Jul 2004 10:06:30 -0000 1.149 @@ -1730,9 +1730,9 @@ } } -static int detect_content (int detection_method, demux_class_t *class_gen, - input_plugin_t *input) -{ +static int detect_ogg_content (int detection_method, demux_class_t *class_gen, + input_plugin_t *input) { + switch (detection_method) { case METHOD_BY_CONTENT: { @@ -1741,13 +1741,12 @@ if (_x_demux_read_header(input, buf, 4) != 4) return 0; - if ((buf[0] != 'O') - || (buf[1] != 'g') - || (buf[2] != 'g') - || (buf[3] != 'S')) + if ((buf[0] == 'O') && (buf[1] == 'g') && (buf[2] == 'g') && + (buf[3] == 'S')) + return 1; + else return 0; } - break; case METHOD_BY_EXTENSION: { char *extensions, *mrl; @@ -1755,17 +1754,79 @@ mrl = input->get_mrl (input); extensions = class_gen->get_extensions (class_gen); - if (!_x_demux_check_extension (mrl, extensions)) { + if (!_x_demux_check_extension (mrl, extensions)) return 1; - } + else + return 0; } - break; case METHOD_EXPLICIT: - break; + return 1; default: + return 0; + } +} + +static int detect_anx_content (int detection_method, demux_class_t *class_gen, + input_plugin_t *input) { + + if (detect_ogg_content(detection_method, class_gen, input) == 0) return 0; + + switch (detection_method) { + +#define ANNODEX_SIGNATURE_SEARCH 128 + + case METHOD_BY_CONTENT: { + uint8_t buf[ANNODEX_SIGNATURE_SEARCH]; + int found_annodex_signature = 0; + const char *annodex_signature = "Annodex"; + int annodex_signature_length = 7; /* = strlen(annodex_signature) */ + int i, j; + + if (_x_demux_read_header(input, buf, ANNODEX_SIGNATURE_SEARCH) != + ANNODEX_SIGNATURE_SEARCH) + return 0; + + /* scan for 'Annodex' signature in the first 64 bytes */ + for (i = 0, j = 0; i < ANNODEX_SIGNATURE_SEARCH; i++) { + if (buf[i] == annodex_signature[j]) { + if (j >= annodex_signature_length) { + /* found signature */ + found_annodex_signature = 1; + break; + } else { + j++; + } + } + } + + if (found_annodex_signature) + return 1; + else + return 0; + } + +#undef ANNODEX_SIGNATURE_SEARCH + + case METHOD_BY_EXTENSION: { + char *extensions, *mrl; + + mrl = input->get_mrl (input); + extensions = class_gen->get_extensions (class_gen); + + if (!_x_demux_check_extension (mrl, extensions)) + return 1; + else + return 0; + } + + case METHOD_EXPLICIT: + return 1; + + default: + return 0; } } @@ -1775,7 +1836,7 @@ demux_ogg_t *this; - if (detect_content(stream->content_detection_method, class_gen, input) == 0) + if (detect_anx_content(stream->content_detection_method, class_gen, input) == 0) return NULL; /* @@ -1821,7 +1882,7 @@ demux_ogg_t *this; - if (detect_content(stream->content_detection_method, class_gen, input) == 0) + if (detect_ogg_content(stream->content_detection_method, class_gen, input) == 0) return NULL; /* |