Commit d7cb8786 authored by Damien Lucas's avatar Damien Lucas

. Rewrote the command line parsing

  New syntaxes are: (not yet updated in the help)
        dvb:program[:devicenumber]   -- not tested yet
        dvd:[device][@chapter,title] -- works fine
        file:file[:format]           -- works fine
        video:[device:format]        -- not tested
        v4l:[videodev[@codec,bitrate]][:audiodev[@codec,bitrate]]
             [{extraparam1=value1,extraparam2=value2}]
                                    -- not implemented yet

. Option -l/--loop should work correctly

. --rtp and --end options are not handled yet
parent ce606b90
......@@ -2,7 +2,7 @@
* parsers.cpp: Command line and configuration files parsers
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: parsers.cpp,v 1.22 2003/08/23 12:33:05 nitrox Exp $
* $Id: parsers.cpp,v 1.23 2003/08/23 14:53:57 nitrox Exp $
*
* Authors: Benoit Steiner <benny@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -371,93 +371,253 @@ void C_CfgFileParser::AddCmdLineSetting(unsigned char sOption, C_String sValue)
void C_CfgFileParser::AddCmdLineTarget(C_String sTarget, C_String sTags)
{
C_String sMeth; /* First part of the tager definition */
C_String sFile; /* Second part of the target definition */
C_String sOptions; /* Third part of the target definition */
C_String sProgramLaunch; /* Name of the program to be launch at startup */
/*
* Target Parsing
* XXX - it is done in a really non generic way
*/
/*
* Gets the Method
*/
if(sTarget.Find(':', 1)==GEN_ERR)
{
throw E_Parser(GEN_ERR, "Syntax error in target definition");
}
/* Target Parsing */
if(sTarget.Find(':', 1)!=GEN_ERR)
C_String sMeth=sTarget.SubString(0,sTarget.Find(':', 1));
try
{
sMeth=sTarget.SubString(0,sTarget.Find(':', 1));
sFile=sTarget.SubString(sTarget.Find(':', 1)+1, strlen(sTarget.GetString()));
if(sFile.Find(':', 1)!=GEN_ERR)
if(sMeth=="dvb") sProgramLaunch = ParseDVBTarget(sTarget);
else if(sMeth=="dvd") sProgramLaunch = ParseDVDTarget(sTarget);
else if(sMeth=="file") sProgramLaunch = ParseFILETarget(sTarget);
else if(sMeth=="v4l") sProgramLaunch = ParseV4LTarget(sTarget);
else if(sMeth=="video") sProgramLaunch = ParseVIDEOTarget(sTarget);
}
catch(E_Exception e)
{
throw E_Parser(GEN_ERR, e.Dump());
}
/* Automatic start section */
C_String sNewTags="";
if (sTags.Find("--loop", 0) != GEN_ERR) sNewTags += " -1";
// TODO nitrox
// handle sTags (rtp, loop, end, ...)
m_pCallBack->OnStartSection("launchonstartup");
m_pCallBack->OnProperty("command1", "broadcast_start broadcast1");
m_pCallBack->OnProperty("command2", "broadcast_add broadcast1 output1 "
+ sProgramLaunch +" input1"+sNewTags);
m_pCallBack->OnEndSection("launchonstartup");
}
C_String C_CfgFileParser::ParseDVBTarget(C_String sT)
{
/*
* dvb:program[:devicenumber]
*/
C_String sP;
unsigned int iN = 0;
sP = sT.SubString(sT.Find(':', 1)+1, sT.Length());
if(sP.Find(':', 1)!=GEN_ERR)
{
sOptions=sFile.SubString(sFile.Find(':', 1)+1, strlen(sFile.GetString()));
sFile=sFile.SubString(0,sFile.Find(':', 1));
iN=sP.SubString(sP.Find(':', 1)+1, sP.Length()).ToInt();
sP=sP.SubString(0,sP.Find(':', 1));
}
else
m_pCallBack->OnStartSection("inputs");
m_pCallBack->OnProperty("input1", "dvb");
m_pCallBack->OnEndSection("inputs");
m_pCallBack->OnStartSection("input1");
m_pCallBack->OnProperty("devicenumber", iN);
m_pCallBack->OnProperty("sendmethod", 0);
m_pCallBack->OnEndSection("input1");
return sP.Replace(' ', '_');
}
C_String C_CfgFileParser::ParseDVDTarget(C_String sT)
{
/*
* dvd:[device][@chapter,title]
*/
C_String sD="/dev/dvd";
unsigned int uiC=1;
unsigned int uiT=1;
sD = sT.SubString(sT.Find(':', 1)+1, sT.Length());
if(sD.Find('@', 0)!=GEN_ERR)
{
sOptions="";
sscanf(sD.SubString(sD.Find('@', 0)+1, sD.Length()).GetString(),
"%u,%u", &uiC, &uiT);
sD=sD.SubString(0,sD.Find('@', 0));
}
}
else
throw E_Parser(GEN_ERR, "Syntax error in target definition");
if(sMeth=="") throw E_Parser(GEN_ERR, "No method specified");
if(sFile=="") throw E_Parser(GEN_ERR, "No file/device specified");
/* Input section */
m_pCallBack->OnStartSection("input1");
m_pCallBack->OnProperty("programcount", "1");
m_pCallBack->OnEndSection("input1");
/* Inputs section */
m_pCallBack->OnStartSection("inputs");
if(sMeth == "dvd" || sMeth == "file")
{
if(sD=="")
{
sD = "/dev/dvd"; // TODO - very linux specific
}
m_pCallBack->OnStartSection("inputs");
m_pCallBack->OnProperty("input1", "local");
}
else if(sMeth=="dvb")
{
m_pCallBack->OnProperty("input1", "dvb");
}
m_pCallBack->OnEndSection("inputs");
/* Input Section */
if(sMeth == "dvd")
{
m_pCallBack->OnEndSection("inputs");
m_pCallBack->OnStartSection("input1");
m_pCallBack->OnProperty("programcount", "1");
m_pCallBack->OnEndSection("input1");
m_pCallBack->OnStartSection("input1.1");
m_pCallBack->OnProperty("name", "program1");
m_pCallBack->OnProperty("device", sFile);
m_pCallBack->OnProperty("type", "Dvd");
sProgramLaunch = "program1";
m_pCallBack->OnEndSection("input1.1");
}
else if(sMeth == "dvb")
{
m_pCallBack->OnProperty("device", sD);
m_pCallBack->OnProperty("type", "dvd");
m_pCallBack->OnProperty("dvdtitle", uiT);
m_pCallBack->OnProperty("dvdchapter", uiC);
m_pCallBack->OnEndSection("input1.1");
return "program1";
}
C_String C_CfgFileParser::ParseFILETarget(C_String sT)
{
/*
* file:file[:format]
*/
C_String sFile;
C_String sFmt;
sFile = sT.SubString(sT.Find(':', 1)+1, sT.Length());
if(sFile.Find(':', 1)!=GEN_ERR)
{
sFmt = sFile.SubString(sFile.Find(':', 1)+1, sFile.Length());
sFile = sFile.SubString(0,sFile.Find(':', 1));
}
else
{
/* Format is not specified - let's try to guess it */
C_File fFile = C_File(sFile);
fFile.Open("r");
byte bFormat;
fFile.Read(&bFormat,(s64) 1);
/*
* Wow ! that's ugly, isn't it ?
* I am not really proud of it but it works in most of usual cases
* -- nitrox
*/
if(bFormat==0x47)
{
sFmt = "mpeg2-ts";
}
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();
}
m_pCallBack->OnStartSection("inputs");
m_pCallBack->OnProperty("input1", "local");
m_pCallBack->OnEndSection("inputs");
m_pCallBack->OnStartSection("input1");
m_pCallBack->OnProperty("deviceNumber", sOptions.ToInt());
m_pCallBack->OnProperty("sendmethod", 0);
sProgramLaunch = sFile;
sProgramLaunch.Replace(' ', '_');
m_pCallBack->OnEndSection("input1");
}
else if(sMeth == "file")
{
m_pCallBack->OnProperty("programcount", "1");
m_pCallBack->OnEndSection("input1");
m_pCallBack->OnStartSection("input1.1");
m_pCallBack->OnProperty("name", "program1");
m_pCallBack->OnProperty("type", sFmt.ToLower());
m_pCallBack->OnProperty("filename", sFile);
C_File fFile = C_File(sFile);
fFile.Open("r");
byte bFormat;
fFile.Read(&bFormat,(s64) 1);
if(bFormat==0x47) m_pCallBack->OnProperty("type", "mpeg2-ts");
fFile.Seek((s64)(4+1), SEEK_CUR);
fFile.Read(&bFormat, (s64) 1);
if(bFormat==0x01) m_pCallBack->OnProperty("type", "mpeg1-ps");
else if(bFormat==0x04) m_pCallBack->OnProperty("type", "mpeg2-ps");
fFile.Close();
sProgramLaunch = "program1";
m_pCallBack->OnEndSection("input1.1");
}
m_pCallBack->OnEndSection("input1.1");
/* Automatic start section */
m_pCallBack->OnStartSection("launchonstartup");
m_pCallBack->OnProperty("command1", "broadcast_start broadcast1");
m_pCallBack->OnProperty("command2", "broadcast_add broadcast1 output1 "
+ sProgramLaunch +" input1 ");
// TODO nitrox
// handle sTags (rtp, loop, end, ...)
m_pCallBack->OnEndSection("launchonstartup");
return "program1";
}
C_String C_CfgFileParser::ParseVIDEOTarget(C_String sT)
{
/*
* video:[device:format]
*/
C_String sD="";
C_String sF="";
sD = sT.SubString(sT.Find(':', 1)+1, sT.Length());
if(sD.Find(':', 1)!=GEN_ERR)
{
sF = sD.SubString(sD.Find(':', 1)+1, sD.Length());
sD = sD.SubString(0,sD.Find(':', 1));
}
m_pCallBack->OnStartSection("inputs");
m_pCallBack->OnProperty("input1", "video");
m_pCallBack->OnEndSection("inputs");
m_pCallBack->OnStartSection("input1");
if ( sD != "" ) m_pCallBack->OnProperty("device", sD);
if ( sF != "" ) m_pCallBack->OnProperty("type", sF);
m_pCallBack->OnEndSection("input1");
return "video";
}
C_String C_CfgFileParser::ParseV4LTarget(C_String sT)
{
/*
* v4l:[videodev[@codec,bitrate]][:audiodev[@codec,bitrate]]
* [{extraparam1=value1,extraparam2=value2}]
*/
/*
* Grmbl, that command line is quite a nightmare !
* Tooney, if you ever write another input with that many
* options, I won't write any command line for it !
* -- nitrox
*/
C_String sVideo="";
C_String sAudio="";
C_String sExtra="";
/* Let's get the 3 main parts */
sVideo = sT.SubString(sT.Find(':', 1)+1, sT.Length());
if ( sVideo.Find(':', 1) != GEN_ERR)
{
sAudio = sVideo.SubString(sVideo.Find(':', 1)+1, sVideo.Length());
sVideo = sVideo.SubString(0,sVideo.Find(':', 1));
if ( sAudio.Find('{', 1) != GEN_ERR )
{
sExtra = sAudio.SubString(sAudio.Find('{', 1)+1, sAudio.Length()-1);
sAudio = sAudio.SubString(0, sAudio.Find('{', 1));
}
}
else if ( sVideo.Find('{', 1) != GEN_ERR )
{
sExtra = sVideo.SubString(sVideo.Find('{', 1)+1, sVideo.Length()-1);
sVideo = sVideo.SubString(0,sVideo.Find(':', 1));
}
/* Let's analyze video part */
if(sVideo != "")
{
//TODO !!!
}
throw E_Parser(GEN_ERR, "V4L command line not implemented !");
return "";
}
......@@ -2,7 +2,7 @@
* parsers.h: Command line and configuration files parsers
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: parsers.h,v 1.5 2002/12/09 01:36:24 nitrox Exp $
* $Id: parsers.h,v 1.6 2003/08/23 14:53:57 nitrox Exp $
*
* Authors: Benoit Steiner <benny@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -88,7 +88,14 @@ class C_CfgFileParser
C_Vector<C_String> Parse(const C_String& strFileName, bool bCompletePath, const C_String& strRoot);
void AddCmdLineSetting(unsigned char sOption, C_String sValue);
void AddCmdLineTarget(C_String sTarget, C_String sTags);
protected:
C_String ParseDVBTarget(C_String);
C_String ParseDVDTarget(C_String);
C_String ParseFILETarget(C_String);
C_String ParseVIDEOTarget(C_String);
C_String ParseV4LTarget(C_String);
// Callback
C_ParserHandler* m_pCallBack;
......@@ -105,4 +112,3 @@ class C_CfgFileParser
#else
#error "Multiple inclusions of parsers.h"
#endif
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