Commit b29bfda6 authored by Andrew de Quincey's avatar Andrew de Quincey

Fixed some more indentation problems

ps2ts should now cope with PS files which end abruptly
parent a5b1abeb
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* filereader.cpp: file reader * filereader.cpp: file reader
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: filereader.cpp,v 1.9 2003/08/13 23:04:21 adq Exp $ * $Id: filereader.cpp,v 1.10 2003/08/14 14:45:49 adq Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -119,10 +119,10 @@ void C_FileMpegReader::Close() ...@@ -119,10 +119,10 @@ void C_FileMpegReader::Close()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
s64 C_FileMpegReader::Read(byte* pBuff, s64 iSize) s64 C_FileMpegReader::Read(byte* pBuff, s64 iSize)
{ {
try try
{ {
s64 iRc = m_cFile.Read(pBuff, iSize); s64 iRc = m_cFile.Read(pBuff, iSize);
// check for end of stream // check for end of stream
if ((iRc == FILE_EOF) || (iRc != iSize)) { if ((iRc == FILE_EOF) || (iRc != iSize)) {
m_bEndOfStream = true; m_bEndOfStream = true;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ps2ts.cpp: threaded PS to TS converter * ps2ts.cpp: threaded PS to TS converter
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: ps2ts.cpp,v 1.14 2003/08/13 23:04:21 adq Exp $ * $Id: ps2ts.cpp,v 1.15 2003/08/14 14:45:49 adq Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -106,7 +106,8 @@ C_Ps2TsMpegConverter::C_Ps2TsMpegConverter(C_Module* pModule, ...@@ -106,7 +106,8 @@ C_Ps2TsMpegConverter::C_Ps2TsMpegConverter(C_Module* pModule,
m_cConverter(cConfig.m_pReader, m_cConverter(cConfig.m_pReader,
cConfig.m_pTsProvider, 2, cConfig.m_pTsProvider, 2,
cConfig.m_pBroadcast->GetOption("mpegversion").ToInt(), cConfig.m_pBroadcast->GetOption("mpegversion").ToInt(),
cConfig.m_pBroadcast->GetOption("loop").ToInt()) cConfig.m_pBroadcast->GetOption("loop").ToInt(),
m_hLog)
{ {
m_bPreParse = (cConfig.m_pBroadcast->GetOption("preparse") == "1"); m_bPreParse = (cConfig.m_pBroadcast->GetOption("preparse") == "1");
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ps2ts.cpp: MPEG1 and MPEG2 PS to MPEG2 TS converter * ps2ts.cpp: MPEG1 and MPEG2 PS to MPEG2 TS converter
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: ps2ts.cpp,v 1.9 2003/08/13 23:25:13 adq Exp $ * $Id: ps2ts.cpp,v 1.10 2003/08/14 14:45:49 adq 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>
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#define UNKNOWN_DATA -98 #define UNKNOWN_DATA -98
#define END_OF_STREAM -99 #define END_OF_STREAM -99
#define SYNC_MAX_LENGTH (1024*1024)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
...@@ -52,7 +53,8 @@ template <class Reader, class TsProvider> ...@@ -52,7 +53,8 @@ template <class Reader, class TsProvider>
C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider, C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider,
unsigned int iMaxBufferedTs, unsigned int iMaxBufferedTs,
unsigned int iMpegVersion, unsigned int iMpegVersion,
bool bLooping) : bool bLooping,
handle hLog) :
m_cPgrmDescriptor(iMpegVersion), m_cPgrmDescriptor(iMpegVersion),
m_cPat(0, 0, 0), m_cPmt(0, 0, 0, 0, 0x50), m_cPat(0, 0, 0), m_cPmt(0, 0, 0, 0, 0x50),
m_cPendingTS(NO) m_cPendingTS(NO)
...@@ -79,6 +81,7 @@ C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider, ...@@ -79,6 +81,7 @@ C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider,
m_bLooping = bLooping; m_bLooping = bLooping;
m_bInMiddleOfPES = false; m_bInMiddleOfPES = false;
m_bJustSynched = false; m_bJustSynched = false;
m_hLog = hLog;
if(iMpegVersion == 1) if(iMpegVersion == 1)
m_iPackHeaderLen = MPEG1_PACK_HEADER_LEN - START_CODE_LEN; m_iPackHeaderLen = MPEG1_PACK_HEADER_LEN - START_CODE_LEN;
...@@ -111,7 +114,7 @@ C_Ps2Ts<Reader, TsProvider>::~C_Ps2Ts() ...@@ -111,7 +114,7 @@ C_Ps2Ts<Reader, TsProvider>::~C_Ps2Ts()
template <class Reader, class TsProvider> template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::Synch() int C_Ps2Ts<Reader, TsProvider>::Synch()
{ {
int iRc; int iRc = NO_ERR;
u8 headerCode[4]; u8 headerCode[4];
u64 startPos; u64 startPos;
...@@ -144,8 +147,8 @@ template <class Reader, class TsProvider> ...@@ -144,8 +147,8 @@ template <class Reader, class TsProvider>
memcpy(headerCode, headerCode+1, 3); memcpy(headerCode, headerCode+1, 3);
// just give up if we haven't found one within a reasonable distance // just give up if we haven't found one within a reasonable distance
if ((m_pReader->GetPos() - startPos) > 1024 * 1024) { if ((m_pReader->GetPos() - startPos) > SYNC_MAX_LENGTH) {
printf("Failed to find a PACK_HEADER within 1Mb.\n"); Log(m_hLog, LOG_ERROR, "Failed to find start of MPEG file");
m_iStatus = GEN_ERR; m_iStatus = GEN_ERR;
break; break;
} }
...@@ -161,7 +164,7 @@ template <class Reader, class TsProvider> ...@@ -161,7 +164,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider> template <class Reader, class TsProvider>
C_TsPacket* C_Ps2Ts<Reader, TsProvider>::GetPacket(bool bPreparsing) C_TsPacket* C_Ps2Ts<Reader, TsProvider>::GetPacket(bool bPreparsing)
{ {
int iRc; int iRc = NO_ERR;
bool bStreamLooped = false; bool bStreamLooped = false;
// if there's nothing left in the buffer. we need to fill it // if there's nothing left in the buffer. we need to fill it
...@@ -253,7 +256,7 @@ template <class Reader, class TsProvider> ...@@ -253,7 +256,7 @@ template <class Reader, class TsProvider>
// try and reset the stream // try and reset the stream
m_pReader->ResetEndOfStream(); m_pReader->ResetEndOfStream();
// if that failed, the reader must not support // if that failed, the reader must not support
// resetting the end of stream. We have to stop. // resetting the end of stream. We have to stop.
if (m_pReader->EndOfStream()) { if (m_pReader->EndOfStream()) {
break; break;
...@@ -298,7 +301,7 @@ template <class Reader, class TsProvider> ...@@ -298,7 +301,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider> template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::FetchPackets(bool bPreparsing) int C_Ps2Ts<Reader, TsProvider>::FetchPackets(bool bPreparsing)
{ {
int iRc; int iRc = NO_ERR;
// if we're in the middle of parsing a PES packet, // if we're in the middle of parsing a PES packet,
// just do that immediately with no further ado // just do that immediately with no further ado
...@@ -313,7 +316,7 @@ template <class Reader, class TsProvider> ...@@ -313,7 +316,7 @@ template <class Reader, class TsProvider>
} }
m_iDataType = U32_AT(m_bBuff); m_iDataType = U32_AT(m_bBuff);
} else { } else {
// if we've just synched we _know_ we're just after a // if we've just synched we _know_ we're just after a
// PACK_HEADER start code. // PACK_HEADER start code.
m_bJustSynched = false; m_bJustSynched = false;
return ParsePackHeader(bPreparsing); return ParsePackHeader(bPreparsing);
...@@ -357,7 +360,7 @@ template <class Reader, class TsProvider> ...@@ -357,7 +360,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider> template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::ParsePackHeader(bool bPreparsing) int C_Ps2Ts<Reader, TsProvider>::ParsePackHeader(bool bPreparsing)
{ {
int iRc; int iRc = NO_ERR;
// try to read in the data for the pack header // try to read in the data for the pack header
if (iRc = ReadData(m_bBuff, m_iPackHeaderLen)) { if (iRc = ReadData(m_bBuff, m_iPackHeaderLen)) {
...@@ -421,11 +424,11 @@ template <class Reader, class TsProvider> ...@@ -421,11 +424,11 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider> template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::ParseSystemHeader() int C_Ps2Ts<Reader, TsProvider>::ParseSystemHeader()
{ {
int iRc; int iRc = NO_ERR;
// read size of the system header // read size of the system header
if (iRc = ReadDataLength(&m_iDataLen)) { if (iRc = ReadDataLength(&m_iDataLen)) {
return iRc; return iRc;
} }
// skip the data // skip the data
...@@ -441,7 +444,7 @@ template <class Reader, class TsProvider> ...@@ -441,7 +444,7 @@ template <class Reader, class TsProvider>
{ {
int iPos = 0; int iPos = 0;
int iPesPos = 0; int iPesPos = 0;
int iRc; int iRc = NO_ERR;
// read size of the PES packet // read size of the PES packet
if (!m_bInMiddleOfPES) { if (!m_bInMiddleOfPES) {
...@@ -454,9 +457,9 @@ template <class Reader, class TsProvider> ...@@ -454,9 +457,9 @@ template <class Reader, class TsProvider>
C_ElementDescriptor* curDesc; C_ElementDescriptor* curDesc;
if ((m_iDataType & 0xff) != PES_ID_PRIVATE_1) { if ((m_iDataType & 0xff) != PES_ID_PRIVATE_1) {
curDesc = m_cPgrmDescriptor.GetDescriptor(m_iDataType & 0xFF); curDesc = m_cPgrmDescriptor.GetDescriptor(m_iDataType & 0xFF);
} else { } else {
// Is an encapsulated MPEG1 stream.. special handling needed // Is an encapsulated MPEG1 stream.. special handling needed
// if we're at the start of a PES packet, read (and cache) the // if we're at the start of a PES packet, read (and cache) the
// header and find the MPEG1 stream ID // header and find the MPEG1 stream ID
if (!m_bInMiddleOfPES) { if (!m_bInMiddleOfPES) {
// read in the start of the PES header // read in the start of the PES header
...@@ -487,19 +490,19 @@ template <class Reader, class TsProvider> ...@@ -487,19 +490,19 @@ template <class Reader, class TsProvider>
} }
// process the PES data // process the PES data
while((m_iDataLen > 0) && (m_cPendingTS.Size() < m_iMaxBufferedTs)) { while ((m_iDataLen > 0) && (m_cPendingTS.Size() < m_iMaxBufferedTs)) {
// check if a new PMT has appeared. If so, just exit this loop. // check if a new PMT has appeared. If so, just exit this loop.
// The caller will take care of generating it and possibly calling us // The caller will take care of generating it and possibly calling us
// again to add in more PES data // again to add in more PES data
if ((!bPreparsing) && (m_cPgrmDescriptor.m_bNewPmt)) { if ((!bPreparsing) && (m_cPgrmDescriptor.m_bNewPmt)) {
break; break;
} }
// Grab a new TS packet to use // Grab a new TS packet to use
C_TsPacket* pPacket = m_pTsProvider->GetPacket(); C_TsPacket* pPacket = m_pTsProvider->GetPacket();
// build the start of the TS packet // build the start of the TS packet
if(!m_bInMiddleOfPES) { // we're at the start of the PES packet if (!m_bInMiddleOfPES) { // we're at the start of the PES packet
// build the header // build the header
u16 iPid = curDesc->GetPid(); u16 iPid = curDesc->GetPid();
u8 iCounter = curDesc->GetCounter(); u8 iCounter = curDesc->GetCounter();
...@@ -513,7 +516,7 @@ template <class Reader, class TsProvider> ...@@ -513,7 +516,7 @@ template <class Reader, class TsProvider>
m_bNeedToSendPCR = false; m_bNeedToSendPCR = false;
// handle any discontinuity // handle any discontinuity
if(m_bDiscontinuity) { if (m_bDiscontinuity) {
pPacket->SetDiscontinuityFlag(); pPacket->SetDiscontinuityFlag();
m_bDiscontinuity = false; m_bDiscontinuity = false;
} }
...@@ -536,7 +539,7 @@ template <class Reader, class TsProvider> ...@@ -536,7 +539,7 @@ template <class Reader, class TsProvider>
// calculate how much data we can send // calculate how much data we can send
int readSize = TS_PACKET_LEN - iPos; int readSize = TS_PACKET_LEN - iPos;
// If there is not enough data to completely fill the TS packet, // If there is not enough data to completely fill the TS packet,
// add stuffing bytes // add stuffing bytes
if((m_iDataLen+iPesPos) < readSize) { if((m_iDataLen+iPesPos) < readSize) {
// add enough stuffing bytes // add enough stuffing bytes
...@@ -548,7 +551,7 @@ template <class Reader, class TsProvider> ...@@ -548,7 +551,7 @@ template <class Reader, class TsProvider>
if (!m_bInMiddleOfPES) { if (!m_bInMiddleOfPES) {
byte* pTsPayload = (byte*)(*pPacket); byte* pTsPayload = (byte*)(*pPacket);
SET_U32_TO(pTsPayload[iPos], m_iDataType); SET_U32_TO(pTsPayload[iPos], m_iDataType);
SET_U16_TO(pTsPayload[iPos+START_CODE_LEN], m_iDataLen); SET_U16_TO(pTsPayload[iPos+START_CODE_LEN], m_iDataLen);
iPos += START_CODE_LEN + PES_SIZE_LEN; iPos += START_CODE_LEN + PES_SIZE_LEN;
} }
} }
...@@ -572,14 +575,22 @@ template <class Reader, class TsProvider> ...@@ -572,14 +575,22 @@ template <class Reader, class TsProvider>
// OK, read the data from the stream into the TS packet // OK, read the data from the stream into the TS packet
if (readSize) { if (readSize) {
if (iRc = ReadData(((byte*)(*pPacket)+iPos), readSize)) { if (iRc = ReadData(((byte*)(*pPacket)+iPos), readSize)) {
m_pTsProvider->ReleasePacket(pPacket); if (iRc == END_OF_STREAM) {
return iRc; // generate a TS packet with the error flag set to warn
// the decoder
memset(((byte*)(*pPacket)+iPos), 0, readSize);
pPacket->SetErrorFlag();
} else {
// some other more fatal error.. just exit right away
m_pTsProvider->ReleasePacket(pPacket);
return iRc;
}
} }
m_iDataLen -= readSize; m_iDataLen -= readSize;
} }
// Put the TS packet in the list of pending TS // Put the TS packet in the list of pending TS
m_cPendingTS.PushEnd(pPacket); m_cPendingTS.PushEnd(pPacket);
// Update TS counters // Update TS counters
if (!bPreparsing) { if (!bPreparsing) {
...@@ -587,11 +598,14 @@ template <class Reader, class TsProvider> ...@@ -587,11 +598,14 @@ template <class Reader, class TsProvider>
m_iTSCounter++; m_iTSCounter++;
} }
// Update the flag to show we're in the middle of a PES packet // Update the flag to show we're in the middle of a PES packet
m_bInMiddleOfPES = true; m_bInMiddleOfPES = true;
// if we're preparsing, we only ever deal with one packet at a time // if we're preparsing, we only ever deal with one packet at a time
if (bPreparsing) break; if (bPreparsing) break;
// if the stream ended abruptly, abort the loop
if (iRc == END_OF_STREAM) break;
} }
// if we're NOT still in the middle of a PES, clear the flag // if we're NOT still in the middle of a PES, clear the flag
...@@ -599,8 +613,8 @@ template <class Reader, class TsProvider> ...@@ -599,8 +613,8 @@ template <class Reader, class TsProvider>
m_bInMiddleOfPES = false; m_bInMiddleOfPES = false;
} }
// if we get here, there isn't a problem // OK, return the status. This will be either NO_ERR or END_OF_STREAM
return NO_ERR; return iRc;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ps2ts.h: MPEG1 and MPEG2 PS to TS converter * ps2ts.h: MPEG1 and MPEG2 PS to TS converter
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: ps2ts.h,v 1.5 2003/08/13 23:04:22 adq Exp $ * $Id: ps2ts.h,v 1.6 2003/08/14 14:45:49 adq 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>
...@@ -37,7 +37,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts ...@@ -37,7 +37,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
{ {
public: public:
C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider, unsigned int iMaxBufferedTs, C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider, unsigned int iMaxBufferedTs,
unsigned int iMpegVersion, bool bLooping); unsigned int iMpegVersion, bool bLooping, handle hLog);
~C_Ps2Ts(); ~C_Ps2Ts();
// Find the first pack header in the stream // Find the first pack header in the stream
...@@ -45,7 +45,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts ...@@ -45,7 +45,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
// //
C_TsPacket* GetPacket(bool bPreparsing = false); C_TsPacket* GetPacket(bool bPreparsing = false);
// To check whenever GetPacket returns NULL // To check whenever GetPacket returns NULL
int GetStatus() { return m_iStatus; }; int GetStatus() { return m_iStatus; };
...@@ -67,10 +67,11 @@ template <class Reader, class TsProvider> class C_Ps2Ts ...@@ -67,10 +67,11 @@ template <class Reader, class TsProvider> class C_Ps2Ts
Reader* m_pReader; Reader* m_pReader;
TsProvider* m_pTsProvider; TsProvider* m_pTsProvider;
unsigned int m_iMaxBufferedTs; unsigned int m_iMaxBufferedTs;
handle m_hLog;
// Parser configuration // Parser configuration
u8 m_iPackHeaderLen; u8 m_iPackHeaderLen;
// Parser state // Parser state
u32 m_iDataType; u32 m_iDataType;
u16 m_iDataLen; u16 m_iDataLen;
...@@ -80,7 +81,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts ...@@ -80,7 +81,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
bool m_bJustSynched; bool m_bJustSynched;
// Output state // Output state
u32 m_iTSCounter; u32 m_iTSCounter;
bool m_bSendPSI; bool m_bSendPSI;
bool m_bGenPat; bool m_bGenPat;
bool m_bGenPmt; bool m_bGenPmt;
...@@ -99,7 +100,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts ...@@ -99,7 +100,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
u64 m_iNextPCR; u64 m_iNextPCR;
bool m_bNeedToSendPCR; bool m_bNeedToSendPCR;
bool m_bLooping; bool m_bLooping;
u8 m_bCache[512]; u8 m_bCache[512];
int m_iCacheLen; int m_iCacheLen;
bool m_bInMiddleOfPES; bool m_bInMiddleOfPES;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* tsstreamer.cpp: * tsstreamer.cpp:
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: tsstreamer.cpp,v 1.20 2003/08/13 23:04:22 adq Exp $ * $Id: tsstreamer.cpp,v 1.21 2003/08/14 14:45:49 adq 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>
...@@ -188,8 +188,8 @@ void C_TsStreamer::DoWork() ...@@ -188,8 +188,8 @@ void C_TsStreamer::DoWork()
// buffer is ready to be send // buffer is ready to be send
if(m_iHowMany == m_pOutput->GetBuffCapacity()) if(m_iHowMany == m_pOutput->GetBuffCapacity())
{ {
if (!m_bFirstPCR) if (!m_bFirstPCR)
WaitSendDate(); WaitSendDate();
m_iHowMany = 0; m_iHowMany = 0;
} }
else else
......
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