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 @@
* filereader.cpp: file reader
*-------------------------------------------------------------------------------
* (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>
*
......@@ -119,10 +119,10 @@ void C_FileMpegReader::Close()
//------------------------------------------------------------------------------
s64 C_FileMpegReader::Read(byte* pBuff, s64 iSize)
{
try
try
{
s64 iRc = m_cFile.Read(pBuff, iSize);
// check for end of stream
if ((iRc == FILE_EOF) || (iRc != iSize)) {
m_bEndOfStream = true;
......
......@@ -2,7 +2,7 @@
* ps2ts.cpp: threaded PS to TS converter
*-------------------------------------------------------------------------------
* (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>
*
......@@ -106,7 +106,8 @@ C_Ps2TsMpegConverter::C_Ps2TsMpegConverter(C_Module* pModule,
m_cConverter(cConfig.m_pReader,
cConfig.m_pTsProvider, 2,
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");
......
......@@ -2,7 +2,7 @@
* ps2ts.cpp: MPEG1 and MPEG2 PS to MPEG2 TS converter
*-------------------------------------------------------------------------------
* (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>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -44,6 +44,7 @@
#define UNKNOWN_DATA -98
#define END_OF_STREAM -99
#define SYNC_MAX_LENGTH (1024*1024)
//------------------------------------------------------------------------------
//
......@@ -52,7 +53,8 @@ template <class Reader, class TsProvider>
C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider,
unsigned int iMaxBufferedTs,
unsigned int iMpegVersion,
bool bLooping) :
bool bLooping,
handle hLog) :
m_cPgrmDescriptor(iMpegVersion),
m_cPat(0, 0, 0), m_cPmt(0, 0, 0, 0, 0x50),
m_cPendingTS(NO)
......@@ -79,6 +81,7 @@ C_Ps2Ts<Reader, TsProvider>::C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider,
m_bLooping = bLooping;
m_bInMiddleOfPES = false;
m_bJustSynched = false;
m_hLog = hLog;
if(iMpegVersion == 1)
m_iPackHeaderLen = MPEG1_PACK_HEADER_LEN - START_CODE_LEN;
......@@ -111,7 +114,7 @@ C_Ps2Ts<Reader, TsProvider>::~C_Ps2Ts()
template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::Synch()
{
int iRc;
int iRc = NO_ERR;
u8 headerCode[4];
u64 startPos;
......@@ -144,8 +147,8 @@ template <class Reader, class TsProvider>
memcpy(headerCode, headerCode+1, 3);
// just give up if we haven't found one within a reasonable distance
if ((m_pReader->GetPos() - startPos) > 1024 * 1024) {
printf("Failed to find a PACK_HEADER within 1Mb.\n");
if ((m_pReader->GetPos() - startPos) > SYNC_MAX_LENGTH) {
Log(m_hLog, LOG_ERROR, "Failed to find start of MPEG file");
m_iStatus = GEN_ERR;
break;
}
......@@ -161,7 +164,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider>
C_TsPacket* C_Ps2Ts<Reader, TsProvider>::GetPacket(bool bPreparsing)
{
int iRc;
int iRc = NO_ERR;
bool bStreamLooped = false;
// if there's nothing left in the buffer. we need to fill it
......@@ -253,7 +256,7 @@ template <class Reader, class TsProvider>
// try and reset the stream
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.
if (m_pReader->EndOfStream()) {
break;
......@@ -298,7 +301,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider>
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,
// just do that immediately with no further ado
......@@ -313,7 +316,7 @@ template <class Reader, class TsProvider>
}
m_iDataType = U32_AT(m_bBuff);
} 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.
m_bJustSynched = false;
return ParsePackHeader(bPreparsing);
......@@ -357,7 +360,7 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::ParsePackHeader(bool bPreparsing)
{
int iRc;
int iRc = NO_ERR;
// try to read in the data for the pack header
if (iRc = ReadData(m_bBuff, m_iPackHeaderLen)) {
......@@ -421,11 +424,11 @@ template <class Reader, class TsProvider>
template <class Reader, class TsProvider>
int C_Ps2Ts<Reader, TsProvider>::ParseSystemHeader()
{
int iRc;
int iRc = NO_ERR;
// read size of the system header
if (iRc = ReadDataLength(&m_iDataLen)) {
return iRc;
return iRc;
}
// skip the data
......@@ -441,7 +444,7 @@ template <class Reader, class TsProvider>
{
int iPos = 0;
int iPesPos = 0;
int iRc;
int iRc = NO_ERR;
// read size of the PES packet
if (!m_bInMiddleOfPES) {
......@@ -454,9 +457,9 @@ template <class Reader, class TsProvider>
C_ElementDescriptor* curDesc;
if ((m_iDataType & 0xff) != PES_ID_PRIVATE_1) {
curDesc = m_cPgrmDescriptor.GetDescriptor(m_iDataType & 0xFF);
} else {
} else {
// 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
if (!m_bInMiddleOfPES) {
// read in the start of the PES header
......@@ -487,19 +490,19 @@ template <class Reader, class TsProvider>
}
// 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.
// The caller will take care of generating it and possibly calling us
// again to add in more PES data
if ((!bPreparsing) && (m_cPgrmDescriptor.m_bNewPmt)) {
break;
}
}
// Grab a new TS packet to use
C_TsPacket* pPacket = m_pTsProvider->GetPacket();
// 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
u16 iPid = curDesc->GetPid();
u8 iCounter = curDesc->GetCounter();
......@@ -513,7 +516,7 @@ template <class Reader, class TsProvider>
m_bNeedToSendPCR = false;
// handle any discontinuity
if(m_bDiscontinuity) {
if (m_bDiscontinuity) {
pPacket->SetDiscontinuityFlag();
m_bDiscontinuity = false;
}
......@@ -536,7 +539,7 @@ template <class Reader, class TsProvider>
// calculate how much data we can send
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
if((m_iDataLen+iPesPos) < readSize) {
// add enough stuffing bytes
......@@ -548,7 +551,7 @@ template <class Reader, class TsProvider>
if (!m_bInMiddleOfPES) {
byte* pTsPayload = (byte*)(*pPacket);
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;
}
}
......@@ -572,14 +575,22 @@ template <class Reader, class TsProvider>
// OK, read the data from the stream into the TS packet
if (readSize) {
if (iRc = ReadData(((byte*)(*pPacket)+iPos), readSize)) {
m_pTsProvider->ReleasePacket(pPacket);
return iRc;
if (iRc == END_OF_STREAM) {
// 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;
}
// Put the TS packet in the list of pending TS
m_cPendingTS.PushEnd(pPacket);
// Put the TS packet in the list of pending TS
m_cPendingTS.PushEnd(pPacket);
// Update TS counters
if (!bPreparsing) {
......@@ -587,11 +598,14 @@ template <class Reader, class TsProvider>
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;
// if we're preparsing, we only ever deal with one packet at a time
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
......@@ -599,8 +613,8 @@ template <class Reader, class TsProvider>
m_bInMiddleOfPES = false;
}
// if we get here, there isn't a problem
return NO_ERR;
// OK, return the status. This will be either NO_ERR or END_OF_STREAM
return iRc;
}
......
......@@ -2,7 +2,7 @@
* ps2ts.h: MPEG1 and MPEG2 PS to TS converter
*-------------------------------------------------------------------------------
* (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>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -37,7 +37,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
{
public:
C_Ps2Ts(Reader* pReader, TsProvider* pTsProvider, unsigned int iMaxBufferedTs,
unsigned int iMpegVersion, bool bLooping);
unsigned int iMpegVersion, bool bLooping, handle hLog);
~C_Ps2Ts();
// Find the first pack header in the stream
......@@ -45,7 +45,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
//
C_TsPacket* GetPacket(bool bPreparsing = false);
// To check whenever GetPacket returns NULL
int GetStatus() { return m_iStatus; };
......@@ -67,10 +67,11 @@ template <class Reader, class TsProvider> class C_Ps2Ts
Reader* m_pReader;
TsProvider* m_pTsProvider;
unsigned int m_iMaxBufferedTs;
handle m_hLog;
// Parser configuration
u8 m_iPackHeaderLen;
// Parser state
u32 m_iDataType;
u16 m_iDataLen;
......@@ -80,7 +81,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
bool m_bJustSynched;
// Output state
u32 m_iTSCounter;
u32 m_iTSCounter;
bool m_bSendPSI;
bool m_bGenPat;
bool m_bGenPmt;
......@@ -99,7 +100,7 @@ template <class Reader, class TsProvider> class C_Ps2Ts
u64 m_iNextPCR;
bool m_bNeedToSendPCR;
bool m_bLooping;
u8 m_bCache[512];
int m_iCacheLen;
bool m_bInMiddleOfPES;
......
......@@ -2,7 +2,7 @@
* tsstreamer.cpp:
*-------------------------------------------------------------------------------
* (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>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -188,8 +188,8 @@ void C_TsStreamer::DoWork()
// buffer is ready to be send
if(m_iHowMany == m_pOutput->GetBuffCapacity())
{
if (!m_bFirstPCR)
WaitSendDate();
if (!m_bFirstPCR)
WaitSendDate();
m_iHowMany = 0;
}
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