Commit 537e940d authored by Loïc Minier's avatar Loïc Minier

* src/core/parsers.cpp: new MPEG autodetection code

  * test/mpeg_detect/test[1-6].*: test cases for the MPEG autodetection code
  * test/mpeg_detect/test.sh: test script, incomplete
  * test/mpeg_detect/list.txt: description of the tests
parent c522aa1c
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
* parsers.cpp: Command line and configuration files parsers * parsers.cpp: Command line and configuration files parsers
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: parsers.cpp,v 1.24 2003/08/24 14:27:15 lool Exp $ * $Id: parsers.cpp,v 1.25 2003/08/24 20:19:26 lool Exp $
* *
* Authors: Benoit Steiner <benny@via.ecp.fr> * Authors: Benoit Steiner <benny@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Cyril Deguet <asmax@via.ecp.fr> * Cyril Deguet <asmax@via.ecp.fr>
* Damien Lucas <nitrox@videolan.org> * Damien Lucas <nitrox@videolan.org>
* Loc Minier <lool@videolan.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -510,26 +511,54 @@ C_String C_CfgFileParser::ParseFILETarget(C_String sT) ...@@ -510,26 +511,54 @@ C_String C_CfgFileParser::ParseFILETarget(C_String sT)
/* Format is not specified - let's try to guess it */ /* Format is not specified - let's try to guess it */
C_File fFile = C_File(sFile); C_File fFile = C_File(sFile);
fFile.Open("r"); fFile.Open("r");
byte bFormat; byte bFormat[4];
fFile.Read(&bFormat,(s64) 1); while (true) {
/* fFile.Read(bFormat,(s64) 4);
* Wow ! that's ugly, isn't it ? // now trying to apply ISO-13818... -- lool
* I am not really proud of it but it works in most of usual cases // TS?
* -- nitrox if( bFormat[0] == 0x47 ) {
*/ #ifdef DEBUG
if(bFormat==0x47) fprintf( stderr, "DEBUG: detected MPEG2-TS\n" );
{ #endif
sFmt = "mpeg2-ts"; sFmt = "mpeg2-ts";
break;
} else if( (bFormat[0] == 0x00) && (bFormat[1] == 0x00)
&& (bFormat[2] == 0x01) ) {
// beginning of a PS system or pack header?
if (bFormat[3] == 0xbb) { // system header
fFile.Read(bFormat, (s64)2);
int iheaderSize = (bFormat[0] << 8) + bFormat[1];
fFile.Seek((s64)(iheaderSize), FILE_SEEK_CURRENT);
continue;
} else if (bFormat[3] == 0xba) { // pack header
fFile.Read(bFormat,(s64) 1);
if (((bFormat[0] >> 6) & 0x03) == 0x01) {
#ifdef DEBUG
fprintf( stderr, "DEBUG: detected MPEG2-PS\n" );
#endif
sFmt = "mpeg2-ps";
break;
} else if ((bFormat[0] & 0xf0) == 0x20) {
#ifdef DEBUG
fprintf( stderr, "DEBUG: detected MPEG1-PS\n" );
#endif
sFmt = "mpeg1-ps";
break;
} else {
throw E_Parser( GEN_ERR, "Automatic format detection "
"of MPEG failed (pack header found)" );
}
} else { // PES?, can not guess right now
#ifdef DEBUG
fprintf( stderr, "DEBUG: detected PES?\n" );
#endif
throw E_Parser( GEN_ERR, "Automatic format detection of "
"MPEG failed (PES found)" );
}
} else {
throw E_Parser( GEN_ERR, "Automatic format detection failed" );
} }
else }
{
fFile.Seek((s64)(4+1), SEEK_CUR);
fFile.Read(&bFormat, (s64) 1);
if(bFormat==0x01) sFmt = "mpeg1-ps";
else if(bFormat==0x04) sFmt = "mpeg2-ps";
else throw E_Parser(GEN_ERR, "Automatic format detection"
" failed");
}
fFile.Close(); fFile.Close();
} }
m_pCallBack->OnStartSection("inputs"); m_pCallBack->OnStartSection("inputs");
......
test1 : a 0x47 byte followed by three bytes
expected result : MPEG-2-TS
test2 : two system headers, the first with 0 length, the second with a length
of 1 and a space, then a MPEG-2-PS pack header with a 0x2? byte
expected result : MPEG-1-PS
test3 : a pack header, with a 0x4? byte
expected result : MPEG-2-PS
test4 : a 0x47 byte
expected result : MPEG2-TS
test5 : 4 random byte
expected result : raw PES, no headers
test6 : a pack header, with a 0x4? byte
expected result : no autodetection
#!/bin/sh
# test script for the mpeg detection test suite
# $Id: test.sh,v 1.1 2003/08/24 20:19:26 lool Exp $
# TODO check the output of the commands
VLS="../../bin/vls"
VLS_OPT="-vvv -d 127.0.0.1"
$VLS $VLS_OPT file:test1.mpeg2-ts
$VLS $VLS_OPT file:test2.mpeg1.ps
$VLS $VLS_OPT file:test3.mpeg2-ps
$VLS $VLS_OPT file:test4.mpeg2-ts
$VLS $VLS_OPT file:test5.pes
$VLS $VLS_OPT file:test6.raw
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment