Refactoring Patch 2 and 3 [re-submit]
Ralf Engels <[email protected]>
| Newsgroups | gmane.comp.audio.zinf.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I checked again the patch I send two days ago. It was ok. Only the second patch (still unsend till now) has a problem. Included is the patch to patch the patch. The overall target is to clean up even more. The pmo class should have no reference to pmi. The pmi should not care about pmo. And what I want is to have multiple pmo classes possible so that you can plug in some effects in the pipeline. The patch 2 cleans up different things. The patch three solves the Prepare issues once and for all. The overall line count of these patches is always negative. Zinf gets simpler! PS: my first mail was rejected because it was to big. Can I send just the attachements for the time being? Is there another way short of CVS access?
zinf-refactoring2.diff
(text/plain, 20.7 KB)
diff -ur zinf-compiled/base/src/player.cpp zinf/base/src/player.cpp
--- zinf-compiled/base/src/player.cpp 2003-08-09 19:48:42.000000000 +0200
+++ zinf/base/src/player.cpp 2003-08-11 12:03:50.000000000 +0200
@@ -1404,7 +1404,6 @@
}
lmc->SetPMI(pmi);
- lmc->SetPMO(pmo);
pmo->SetPMI(pmi);
pmo->SetLMC(lmc);
@@ -1423,7 +1422,7 @@
m_lmc = lmc;
lmc = NULL;
- error = pmo->SetTo(pc->URL().c_str());
+ error = pmo->SetUrl(pc->URL());
// If this is a missing file, then just bail out -- the
// pmo that was created will have sent a missing file event
// that will notify the user
diff -ur zinf-compiled/io/include/pmi.h zinf/io/include/pmi.h
--- zinf-compiled/io/include/pmi.h 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/include/pmi.h 2003-08-11 01:56:44.000000000 +0200
@@ -57,10 +57,16 @@
PhysicalMediaInput(FAContext *context);
virtual ~PhysicalMediaInput();
- virtual Error SetTo(const char *url);
+ /** Sets the pmi to get the data from the supplied url.
+ */
+ virtual Error SetUrl(const std::string& url);
+
+ /** Returns the current Url */
+ virtual std::string GetUrl(void)
+ { return m_path; }
+
virtual Error Close(void);
virtual Error Open(void) = 0;
- virtual std::string Url(void) const = 0;
virtual Error Prepare(PullBuffer *&pBuffer) = 0;
/** Moves the current position in the file.
diff -ur zinf-compiled/io/include/pmo.h zinf/io/include/pmo.h
--- zinf-compiled/io/include/pmo.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/include/pmo.h 2003-08-11 02:30:34.000000000 +0200
@@ -81,7 +81,14 @@
virtual void SetLMC(LogicalMediaConverter *pLMC);
virtual void SetPMI(PhysicalMediaInput *pPMI);
- virtual Error SetTo(const char *url);
+
+ /** Sets the pmo to get the data from the supplied url.
+ */
+ virtual Error SetUrl(const std::string& url);
+
+ /** Returns the current Url */
+ virtual std::string GetUrl(void)
+ { return m_pLmc->GetUrl(); }
virtual void ReportError(const char * format, ...);
virtual const char *GetErrorString(int32_t) { return NULL; };
@@ -95,9 +102,14 @@
PhysicalMediaInput *m_pPmi;
LogicalMediaConverter *m_pLmc;
- int32_t m_iPreBuffer;
- int m_iBufferUpdate;
- PullBuffer *m_pPmiBuffer;
+
+ /** Time in ms that PreBuffer waits.
+ */
+ int32_t m_iPreBuffer;
+
+ /** Time of the last buffer update.
+ */
+ time_t m_iBufferUpdate;
};
#endif /* _PMO_H_ */
diff -ur zinf-compiled/io/local/localfileinput.cpp zinf/io/local/localfileinput.cpp
--- zinf-compiled/io/local/localfileinput.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/local/localfileinput.cpp 2003-08-11 02:05:24.000000000 +0200
@@ -157,15 +157,13 @@
return bRet;
}
-Error LocalFileInput::SetTo(const char *url)
+Error LocalFileInput::SetUrl(const std::string& url)
{
- Error result = kError_NoErr;
- m_path = "";
- if (strncmp(url, "file://", 7) == 0){
- URLToFilePath(url, m_path);
+ if (strncmp(url.c_str(), "file://", 7) == 0){
+ URLToFilePath(url.c_str(), m_path);
} else
m_path = url;
- return result;
+ return kError_NoErr;
}
Error LocalFileInput::Close(void)
diff -ur zinf-compiled/io/local/localfileinput.h zinf/io/local/localfileinput.h
--- zinf-compiled/io/local/localfileinput.h 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/local/localfileinput.h 2003-08-11 01:54:05.000000000 +0200
@@ -53,7 +53,11 @@
virtual Error GetLength(size_t &iSize);
virtual Error Prepare(PullBuffer *&pBuffer);
- virtual Error SetTo(const char *url);
+
+ /** Sets the pmi to get the data from the supplied url.
+ */
+ virtual Error SetUrl(const std::string& url);
+
virtual Error Close(void);
virtual void Clear(void);
virtual std::string Url(void) const
diff -ur zinf-compiled/io/src/pmi.cpp zinf/io/src/pmi.cpp
--- zinf-compiled/io/src/pmi.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/src/pmi.cpp 2003-08-11 01:55:13.000000000 +0200
@@ -65,10 +65,8 @@
m_pPauseSem->Signal();
}
-Error PhysicalMediaInput::SetTo(const char *url)
+Error PhysicalMediaInput::SetUrl(const std::string& url)
{
- m_path = "";
-
m_path = url;
return kError_NoErr;
diff -ur zinf-compiled/io/src/pmo.cpp zinf/io/src/pmo.cpp
--- zinf-compiled/io/src/pmo.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/src/pmo.cpp 2003-08-11 02:03:13.000000000 +0200
@@ -51,8 +51,7 @@
{
m_pPmi = NULL;
m_pLmc = NULL;
- m_iBufferUpdate = -1;
- m_pPmiBuffer = NULL;
+ m_iBufferUpdate = -1;
if (context->prefs->GetPrefInt32(kPreBufferPref, &m_iPreBuffer) ==
kError_NoPrefValue)
@@ -84,28 +83,25 @@
delete m_pPmi;
}
-Error PhysicalMediaOutput::SetTo(const char *url)
+Error PhysicalMediaOutput::SetUrl(const std::string& url)
{
- Error eRet;
-
#ifdef IPV6
// printf("Zinf-IPv6: url %s\n", url);
#endif
m_pMutex->Acquire();
- assert(m_pPmi != NULL);
assert(m_pLmc != NULL);
- m_pPmi->SetTo(url);
- eRet = m_pPmi->Prepare(m_pPmiBuffer);
- if (!IsError(eRet))
- {
- eRet = m_pLmc->Prepare(m_pPmiBuffer, m_pInputBuffer);
- }
+ Error eRet = m_pLmc->SetUrl( url );
m_pMutex->Release();
+ if (!IsError(eRet))
+ {
+ eRet = m_pLmc->Prepare(m_pOutputBuffer, m_pInputBuffer);
+ }
+
return eRet;
}
@@ -127,6 +123,7 @@
m_pMutex->Release();
}
+// why does this not also pause Lmc and Pmi?
void PhysicalMediaOutput::Pause(void)
{
PipelineUnit::Pause();
@@ -213,7 +210,7 @@
if (iNow != m_iBufferUpdate)
{
m_pTarget->AcceptEvent(new StreamBufferEvent(false,
- m_pPmiBuffer->GetBufferPercentage(),
+ m_pOutputBuffer->GetBufferPercentage(),
m_pInputBuffer->GetBufferPercentage()));
m_iBufferUpdate = iNow;
}
@@ -224,12 +221,12 @@
int iInPercent, iOutPercent;
if (!m_pPmi->IsStreaming() ||
- m_pPmiBuffer == NULL ||
- m_pPmiBuffer->IsEndOfStream() ||
+ m_pOutputBuffer == NULL ||
+ m_pOutputBuffer->IsEndOfStream() ||
m_pInputBuffer == NULL)
return;
- iInPercent = m_pPmiBuffer->GetBufferPercentage();
+ iInPercent = m_pOutputBuffer->GetBufferPercentage();
iOutPercent = m_pInputBuffer->GetBufferPercentage();
if (bForceBufferUp || (iOutPercent <= 5 && iInPercent <= 5))
@@ -237,11 +234,11 @@
for(; !m_bExit && iInPercent < 75;)
{
usleep(500000);
- iInPercent = m_pPmiBuffer->GetBufferPercentage();
+ iInPercent = m_pOutputBuffer->GetBufferPercentage();
iOutPercent = m_pInputBuffer->GetBufferPercentage();
m_pTarget->AcceptEvent(new StreamBufferEvent(true,
iInPercent, iOutPercent));
- if (m_pPmiBuffer->IsEndOfStream())
+ if (m_pOutputBuffer->IsEndOfStream())
break;
}
}
diff -ur zinf-compiled/io/wavout/src/wavoutpmo.cpp zinf/io/wavout/src/wavoutpmo.cpp
--- zinf-compiled/io/wavout/src/wavoutpmo.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/wavout/src/wavoutpmo.cpp 2003-08-11 02:12:05.000000000 +0200
@@ -120,16 +120,12 @@
format.nBlockAlign = 4;
format.cbSize = 0;
- string path;
- string base;
- string url;
- char *pPtr;
// using the current file, split it apart, and rebuilt
// it, appending an ! to the filename, and changing the extention
// to wav
- url = m_pPmi->Url();
- pPtr = strrchr(url.c_str(), DIR_MARKER);
+ std::string path;
+ char *pPtr = strrchr(GetUrl().c_str(), DIR_MARKER);
if (pPtr){
path = pPtr+1;
pPtr = strrchr(path.c_str(), '.');
@@ -139,6 +135,7 @@
else
path = "unknown.wav";
+ std::string base;
m_pContext->prefs->GetPrefString(kSaveMusicDirPref, &base);
base += DIR_MARKER_STR;
base += path;
diff -ur zinf-compiled/lmc/cd/include/cdlmc.h zinf/lmc/cd/include/cdlmc.h
--- zinf-compiled/lmc/cd/include/cdlmc.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/lmc/cd/include/cdlmc.h 2003-08-11 12:09:01.000000000 +0200
@@ -52,9 +52,6 @@
virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
virtual Error InitDecoder();
- virtual Error SetEQData(float *, float);
- virtual Error SetEQData(bool);
-
virtual Error SetDecodeInfo(DecodeInfo &info);
virtual std::vector<std::string> *GetExtensions(void);
diff -ur zinf-compiled/lmc/cd/src/cdlmc.cpp zinf/lmc/cd/src/cdlmc.cpp
--- zinf-compiled/lmc/cd/src/cdlmc.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/lmc/cd/src/cdlmc.cpp 2003-08-11 12:09:11.000000000 +0200
@@ -51,7 +51,6 @@
m_pContext = context;
m_pmi = NULL;
- m_pmo = NULL;
}
CDLMC::~CDLMC()
@@ -101,16 +100,6 @@
return kError_NoErr;
}
-Error CDLMC::SetEQData(float *arrayEQ, float preamp)
-{
- return kError_NoErr;
-}
-
-Error CDLMC::SetEQData(bool enable)
-{
- return kError_NoErr;
-}
-
Error CDLMC::SetDecodeInfo(DecodeInfo &info)
{
m_decodeInfo = info;
diff -ur zinf-compiled/lmc/include/lmc.h zinf/lmc/include/lmc.h
--- zinf-compiled/lmc/include/lmc.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/lmc/include/lmc.h 2003-08-11 12:12:20.000000000 +0200
@@ -27,6 +27,7 @@
#include <vector>
#include <string>
+#include "pmi.h"
#include "pipeline.h"
#include "errors.h"
#include "eventdata.h"
@@ -54,7 +55,7 @@
class MediaInfoEvent;
class PullBuffer;
class EventBuffer;
-class PhysicalMediaInput;
+// class PhysicalMediaInput;
class PhysicalMediaOutput;
const int32_t iMinimumOutputBufferSize = 64;
@@ -70,7 +71,24 @@
m_decodeInfo.eightbit = false;
};
- virtual ~LogicalMediaConverter() {}
+ virtual ~LogicalMediaConverter() {};
+
+ /** Sets the lmc to get the data from the supplied url.
+ * eventually calls pmi SetTo method.
+ * TODO: move implementation to C-file
+ */
+ virtual Error SetUrl(const std::string& url)
+ {
+ assert(m_pmi != NULL);
+
+ m_pmi->SetUrl(url);
+
+ return m_pmi->Prepare(m_pOutputBuffer);
+ };
+
+ /** Returns the current Url */
+ virtual std::string GetUrl(void)
+ { return m_pmi->GetUrl(); }
virtual Error Prepare(PullBuffer *pInput, PullBuffer *&pOutput) = 0;
virtual Error ChangePosition(int32_t) = 0;
@@ -78,10 +96,16 @@
virtual Error InitDecoder() = 0;
virtual void SetPMI(PhysicalMediaInput *pmi) { m_pmi = pmi; };
- virtual void SetPMO(PhysicalMediaOutput *pmo) { m_pmo = pmo; };
- virtual Error SetEQData(float *, float) = 0;
- virtual Error SetEQData(bool) = 0;
+ /** Set the equalizer data.
+ */
+ virtual Error SetEQData(float *, float)
+ { return kError_YouScrewedUp; };
+
+ /** Set usage of equalizer
+ */
+ virtual Error SetEQData(bool)
+ { return kError_YouScrewedUp; };
virtual Error SetDecodeInfo(DecodeInfo &info) = 0;
@@ -95,7 +119,6 @@
virtual Error ExtractMediaInfo() = 0;
PhysicalMediaInput *m_pmi;
- PhysicalMediaOutput *m_pmo;
DecodeInfo m_decodeInfo;
};
diff -ur zinf-compiled/lmc/vorbis/include/vorbislmc.h zinf/lmc/vorbis/include/vorbislmc.h
--- zinf-compiled/lmc/vorbis/include/vorbislmc.h 2003-08-11 19:26:49.000000000 +0200
+++ zinf/lmc/vorbis/include/vorbislmc.h 2003-08-11 12:57:46.000000000 +0200
@@ -63,9 +63,6 @@
virtual Error InitDecoder();
virtual std::vector<std::string> *GetExtensions(void);
-
- virtual Error SetEQData(float *f, float) { return kError_YouScrewedUp; };
- virtual Error SetEQData(bool b) { return kError_YouScrewedUp; };
virtual Error SetDecodeInfo(DecodeInfo &info);
@@ -86,8 +83,7 @@
Thread *m_decoderThread;
- char *m_szUrl;
- const char *m_szError;
+ const char *m_szError; // marked for removal
bool m_bInit;
int m_channels, m_section, m_rate;
long m_frameCounter, m_newPos;
diff -ur zinf-compiled/lmc/vorbis/src/vorbislmc.cpp zinf/lmc/vorbis/src/vorbislmc.cpp
--- zinf-compiled/lmc/vorbis/src/vorbislmc.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/lmc/vorbis/src/vorbislmc.cpp 2003-08-11 12:34:43.000000000 +0200
@@ -65,8 +65,8 @@
const char *szCannotDecode = N_("Skipped corrupted file.");
VorbisLMC::VorbisLMC(FAContext *context) :
- LogicalMediaConverter(context),m_pmi(NULL),m_pmo(NULL),
- m_decoderThread(NULL),m_szUrl(NULL),m_szError(NULL)
+ LogicalMediaConverter(context),
+ m_decoderThread(NULL),m_szError(NULL)
{
m_pContext = context;
m_bInit = false;
@@ -149,7 +149,7 @@
Error result;
int iNewSize;
- if (!m_pTarget || !m_pmi || !m_pmo || !m_pInputBuffer || !m_pOutputBuffer)
+ if (!m_pTarget || !m_pInputBuffer || !m_pOutputBuffer)
{
return kError_PluginNotInitialized;
}
@@ -289,7 +289,6 @@
int bitrateLoops = 0;
assert(m_pmi);
- assert(m_pmo);
m_pSleepSem->Wait();
m_pmi->Wake();
diff -ur zinf-compiled/lmc/wav/include/wavlmc.h zinf/lmc/wav/include/wavlmc.h
--- zinf-compiled/lmc/wav/include/wavlmc.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/lmc/wav/include/wavlmc.h 2003-08-11 12:57:25.000000000 +0200
@@ -87,14 +87,9 @@
virtual void Clear();
virtual Error ExtractMediaInfo();
- virtual void SetPMI(PhysicalMediaInput *pmi) { m_pPmi = pmi; };
- virtual void SetPMO(PhysicalMediaOutput *pmo) { m_pPmo = pmo; };
virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
virtual Error InitDecoder();
- virtual Error SetEQData(float *, float);
- virtual Error SetEQData(bool);
-
virtual Error SetDecodeInfo(DecodeInfo &info);
virtual std::vector<std::string> *GetExtensions(void);
@@ -108,11 +103,8 @@
Error GetHeadInfo();
Error GetStats(float &fTotalSeconds, int32_t &iTotalFrames);
- PhysicalMediaInput *m_pPmi;
- PhysicalMediaOutput *m_pPmo;
Thread *m_decoderThread;
- char *m_szUrl;
- const char *m_szError;
+ const char *m_szError; // marked for removal...
FILE *m_fpFile;
char *m_pLocalReadBuffer;
diff -ur zinf-compiled/lmc/wav/src/wavlmc.cpp zinf/lmc/wav/src/wavlmc.cpp
--- zinf-compiled/lmc/wav/src/wavlmc.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/lmc/wav/src/wavlmc.cpp 2003-08-11 12:33:37.000000000 +0200
@@ -71,8 +71,8 @@
const char *szCannotDecode = _("Skipped corrupted file.");
WavLMC::WavLMC(FAContext *context) :
- LogicalMediaConverter(context), m_pPmi(NULL), m_pPmo(NULL),
- m_decoderThread(NULL), m_szUrl(NULL), m_szError(NULL), m_fpFile(NULL),
+ LogicalMediaConverter(context),
+ m_decoderThread(NULL), m_szError(NULL), m_fpFile(NULL),
m_pLocalReadBuffer(NULL)
{
m_pContext = context;
@@ -323,7 +323,7 @@
if (IsError(eRet))
return eRet;
- pMIE = new MediaInfoEvent(m_pPmi->Url().c_str(), totalSeconds);
+ pMIE = new MediaInfoEvent(GetUrl().c_str(), totalSeconds);
if (!pMIE)
return kError_OutOfMemory;
@@ -355,9 +355,6 @@
fTotalSeconds = -1.0;
iTotalFrames = 0;
- if (!m_pPmi && !m_fpFile)
- return kError_NullValueInvalid;
-
if (m_frameBytes < 0)
{
Err = GetHeadInfo();
@@ -403,7 +400,7 @@
m_pContext->log->Log(LogDecode, "InitDecoder\n");
- if (!m_pTarget || !m_pPmi || !m_pPmo || !m_pInputBuffer || !m_pOutputBuffer)
+ if (!m_pTarget || !m_pInputBuffer || !m_pOutputBuffer)
{
return kError_NullValueInvalid;
}
@@ -462,15 +459,14 @@
void *pBuffer, *pOutBuffer;
Error Err;
- int32_t iLoop = 0, iValue, iReadSize = 0;
+ int32_t iLoop = 0, iValue, iReadSize = 0;
bool bRestart = false;
- assert(m_pPmi);
- assert(m_pPmo);
+ assert(m_pmi);
m_pSleepSem->Wait();
- m_pPmi->Wake();
+ m_pmi->Wake();
Err = CanDecode();
if (Err == kError_Interrupt)
@@ -643,7 +639,7 @@
}
EndRead(iReadSize);
- m_pPmi->Wake();
+ m_pmi->Wake();
if (m_pOutputBuffer)
{
@@ -705,7 +701,7 @@
eRet = m_pInputBuffer->BeginRead(pBuffer, iBytesNeeded);
if (eRet == kError_NoDataAvail)
{
- m_pPmi->Wake();
+ m_pmi->Wake();
if (Sleep())
return kError_Interrupt;
continue;
@@ -730,16 +726,6 @@
return m_pInputBuffer->EndRead(iBytesUsed);
}
-Error WavLMC::SetEQData(float *arrayEQ, float preamp)
-{
- return kError_NoErr;
-}
-
-Error WavLMC::SetEQData(bool enable)
-{
- return kError_NoErr;
-}
-
Error WavLMC::SetDecodeInfo(DecodeInfo &info)
{
m_decodeInfo = info;
@@ -755,6 +741,6 @@
uint32_t lSeekTo = m_ulWaveHeaderSize + (position * m_frameBytes);
- return m_pPmi->Seek( lSeekTo, SEEK_FROM_START );
+ return m_pmi->Seek( lSeekTo, SEEK_FROM_START );
}
diff -ur zinf-compiled/lmc/xingmp3/include/xinglmc.h zinf/lmc/xingmp3/include/xinglmc.h
--- zinf-compiled/lmc/xingmp3/include/xinglmc.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/lmc/xingmp3/include/xinglmc.h 2003-08-11 13:13:55.000000000 +0200
@@ -86,8 +86,6 @@
virtual void Clear();
virtual Error ExtractMediaInfo();
- virtual void SetPMI(PhysicalMediaInput *pmi) { m_pPmi = pmi; };
- virtual void SetPMO(PhysicalMediaOutput *pmo) { m_pPmo = pmo; };
virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
virtual Error InitDecoder();
@@ -115,9 +113,6 @@
int32_t SeekPoint(unsigned char TOC[100], int32_t file_bytes, float percent);
int ExtractI4(unsigned char *buf);
- PhysicalMediaInput *m_pPmi;
- PhysicalMediaOutput *m_pPmo;
-
int m_iMaxWriteSize;
int32_t m_frameBytes, m_iBufferUpInterval, m_iBufferSize;
size_t m_lFileSize;
@@ -127,8 +122,6 @@
Thread *m_decoderThread;
int32_t m_frameCounter;
- time_t m_iBufferUpdate;
- char *m_szUrl;
const char *m_szError;
XHEADDATA *m_pXingHeader;
diff -ur zinf-compiled/lmc/xingmp3/src/xinglmc.cpp zinf/lmc/xingmp3/src/xinglmc.cpp
--- zinf-compiled/lmc/xingmp3/src/xinglmc.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/lmc/xingmp3/src/xinglmc.cpp 2003-08-11 13:14:14.000000000 +0200
@@ -104,17 +104,13 @@
m_decoderThread = NULL;
m_bBufferingUp = false;
- m_iBufferUpdate = 0;
m_iBitRate = 0;
m_frameBytes = -1;
- m_szUrl = NULL;
m_szError = NULL;
m_iMaxWriteSize = 0;
m_iBufferUpInterval = iDefaultBufferUpInterval;
m_frameCounter = 0;
m_iBufferSize = iStreamingBufferSize * 1024;
- m_pPmi = NULL;
- m_pPmo = NULL;
m_fpFile = NULL;
m_pLocalReadBuffer = NULL;
m_pXingHeader = NULL;
@@ -361,7 +357,7 @@
if (IsError(eRet))
return eRet;
- pMIE = new MediaInfoEvent(m_pPmi->Url().c_str(), totalSeconds);
+ pMIE = new MediaInfoEvent( GetUrl().c_str(), totalSeconds);
if (!pMIE)
return kError_OutOfMemory;
@@ -401,7 +397,7 @@
fTotalSeconds = fMsPerFrame = -1.0;
iTotalFrames = iSampleRate = iLayer = 0;
- if (!m_pPmi && !m_fpFile)
+ if (!m_pmi && !m_fpFile)
return kError_NullValueInvalid;
if (m_frameBytes < 0) {
@@ -415,7 +411,7 @@
m_lFileSize = ftell(m_fpFile);
fseek(m_fpFile, 0, SEEK_SET);
} else
- if (m_pPmi->GetLength(m_lFileSize) == kError_FileSeekNotSupported)
+ if (m_pmi->GetLength(m_lFileSize) == kError_FileSeekNotSupported)
m_lFileSize = 0;
sampRateIndex = 4 * m_sMpegHead.id + m_sMpegHead.sr_index;
@@ -628,7 +624,7 @@
{
Error Err;
- if (!m_pTarget || !m_pPmi || !m_pPmo || !m_pInputBuffer || !m_pOutputBuffer)
+ if (!m_pTarget || !m_pInputBuffer || !m_pOutputBuffer)
return kError_NullValueInvalid;
if (m_frameBytes < 0) {
@@ -747,12 +743,11 @@
IN_OUT x = {0, 0};
bool bRestart = false;
- assert(m_pPmi);
- assert(m_pPmo);
+ assert(m_pmi);
m_pSleepSem->Wait();
- m_pPmi->Wake();
+ m_pmi->Wake();
Err = CanDecode();
if (Err == kError_Interrupt)
@@ -910,7 +905,7 @@
return;
EndRead(min((int32_t)x.in_bytes, iReadSize));
- m_pPmi->Wake();
+ m_pmi->Wake();
if (m_pOutputBuffer) {
#if __BYTE_ORDER != __LITTLE_ENDIAN
@@ -971,7 +966,7 @@
for(; !m_bExit;) {
eRet = m_pInputBuffer->BeginRead(pBuffer, iBytesNeeded);
if (eRet == kError_NoDataAvail) {
- m_pPmi->Wake();
+ m_pmi->Wake();
if (Sleep())
return kError_Interrupt;
continue;
@@ -1031,6 +1026,6 @@
else
lSeekTo = position * m_frameBytes;
- return m_pPmi->Seek( lSeekTo, SEEK_FROM_START );
+ return m_pmi->Seek( lSeekTo, SEEK_FROM_START );
}
zinf-refactoring3.diff
(text/plain, 16 KB)
diff -ur zinf-compiled/io/http/httpinput.cpp zinf/io/http/httpinput.cpp
--- zinf-compiled/io/http/httpinput.cpp 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/http/httpinput.cpp 2003-08-11 20:58:15.000000000 +0200
@@ -211,7 +211,7 @@
}
Error
-HttpInput::Prepare(PullBuffer * &pBuffer)
+HttpInput::GetOutputBuffer(PullBuffer **pBuffer)
{
int32_t iBufferSize = iDefaultBufferSize;
Error result;
@@ -231,8 +231,6 @@
m_pContext);
assert(m_pOutputBuffer);
- pBuffer = m_pOutputBuffer;
-
result = Run();
if (IsError(result))
{
@@ -240,6 +238,8 @@
return result;
}
+ *pBuffer = m_pOutputBuffer;
+
return kError_NoErr;
}
diff -ur zinf-compiled/io/http/httpinput.h zinf/io/http/httpinput.h
--- zinf-compiled/io/http/httpinput.h 2003-08-11 19:26:49.000000000 +0200
+++ zinf/io/http/httpinput.h 2003-08-11 20:58:43.000000000 +0200
@@ -66,7 +66,14 @@
HttpInput(char *path);
virtual ~ HttpInput(void);
- virtual Error Prepare(PullBuffer *&pBuffer);
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
+
virtual Error Run(void);
virtual bool CanHandle(const char *szUrl, char *szTitle);
diff -ur zinf-compiled/io/include/pipeline.h zinf/io/include/pipeline.h
--- zinf-compiled/io/include/pipeline.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/include/pipeline.h 2003-08-11 13:26:38.000000000 +0200
@@ -66,6 +66,7 @@
virtual void ReportStatus(const char * format, ...);
virtual void DebugPrint(void);
+
protected:
virtual bool Sleep(void);
diff -ur zinf-compiled/io/include/pmi.h zinf/io/include/pmi.h
--- zinf-compiled/io/include/pmi.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/io/include/pmi.h 2003-08-11 20:37:12.000000000 +0200
@@ -67,7 +67,14 @@
virtual Error Close(void);
virtual Error Open(void) = 0;
- virtual Error Prepare(PullBuffer *&pBuffer) = 0;
+
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer) = 0;
/** Moves the current position in the file.
* @param offset The pos to move to
diff -ur zinf-compiled/io/local/localfileinput.cpp zinf/io/local/localfileinput.cpp
--- zinf-compiled/io/local/localfileinput.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/io/local/localfileinput.cpp 2003-08-11 21:06:00.000000000 +0200
@@ -105,7 +105,7 @@
}
}
-Error LocalFileInput::Prepare(PullBuffer *&pBuffer)
+Error LocalFileInput::GetOutputBuffer(PullBuffer **pBuffer)
{
int32_t iBufferSize = iDefaultBufferSize;
Error result;
@@ -140,7 +140,7 @@
return result;
}
- pBuffer = m_pOutputBuffer;
+ *pBuffer = m_pOutputBuffer;
return kError_NoErr;
}
diff -ur zinf-compiled/io/local/localfileinput.h zinf/io/local/localfileinput.h
--- zinf-compiled/io/local/localfileinput.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/io/local/localfileinput.h 2003-08-11 20:35:15.000000000 +0200
@@ -52,7 +52,7 @@
virtual Error Tell(int32_t* pos);
virtual Error GetLength(size_t &iSize);
- virtual Error Prepare(PullBuffer *&pBuffer);
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
/** Sets the pmi to get the data from the supplied url.
*/
diff -ur zinf-compiled/io/obs/obsinput.cpp zinf/io/obs/obsinput.cpp
--- zinf-compiled/io/obs/obsinput.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/obs/obsinput.cpp 2003-08-11 21:07:15.000000000 +0200
@@ -124,7 +124,7 @@
return bRet;
}
-Error ObsInput::Prepare(PullBuffer *&pBuffer)
+Error ObsInput::GetOutputBuffer(PullBuffer **pBuffer)
{
int iBufferSize = iDefaultBufferSize;
Error result;
@@ -143,8 +143,6 @@
m_pContext);
assert(m_pOutputBuffer);
- pBuffer = m_pOutputBuffer;
-
result = Run();
if (IsError(result))
{
@@ -152,6 +150,8 @@
return result;
}
+ *pBuffer = m_pOutputBuffer;
+
return kError_NoErr;
}
diff -ur zinf-compiled/io/obs/obsinput.h zinf/io/obs/obsinput.h
--- zinf-compiled/io/obs/obsinput.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/obs/obsinput.h 2003-08-11 20:34:55.000000000 +0200
@@ -80,7 +80,7 @@
ObsInput(char *path);
virtual ~ObsInput(void);
- virtual Error Prepare(PullBuffer *&pBuffer);
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
virtual Error Run(void);
virtual bool CanHandle(const char *szUrl, char *szTitle);
diff -ur zinf-compiled/io/src/pmo.cpp zinf/io/src/pmo.cpp
--- zinf-compiled/io/src/pmo.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/io/src/pmo.cpp 2003-08-11 21:52:14.000000000 +0200
@@ -64,8 +64,6 @@
if (m_pLmc)
m_pLmc->Pause();
- if (m_pPmi)
- m_pPmi->Pause();
m_pPauseSem->Signal();
m_pSleepSem->Signal();
@@ -97,9 +95,10 @@
m_pMutex->Release();
+ // now we have to get a new output buffer
if (!IsError(eRet))
{
- eRet = m_pLmc->Prepare(m_pOutputBuffer, m_pInputBuffer);
+ eRet = m_pLmc->GetOutputBuffer( &m_pInputBuffer );
}
return eRet;
@@ -136,9 +135,7 @@
if (m_pPmi->PauseLoop(false))
{
m_pLmc->Pause();
- m_pPmi->Pause();
m_pLmc->Clear();
- m_pPmi->Resume();
m_pLmc->Resume();
}
@@ -173,8 +170,6 @@
Pause();
//Debug_v("Pause LMC");
m_pLmc->Pause();
- //Debug_v("Pause PMI");
- m_pPmi->Pause();
//Debug_v("Clear PMO");
Clear();
@@ -186,8 +181,6 @@
//Debug_v("Change pos");
m_pLmc->ChangePosition(position);
- //Debug_v("Resume PMI");
- m_pPmi->Resume();
//Debug_v("Resume LMC");
m_pLmc->Resume();
@@ -204,13 +197,17 @@
void PhysicalMediaOutput::UpdateBufferStatus(void)
{
+ if (m_pLmc->GetInputBuffer() == NULL ||
+ m_pInputBuffer == NULL)
+ return;
+
time_t iNow;
time(&iNow);
if (iNow != m_iBufferUpdate)
{
m_pTarget->AcceptEvent(new StreamBufferEvent(false,
- m_pOutputBuffer->GetBufferPercentage(),
+ m_pLmc->GetInputBuffer()->GetBufferPercentage(),
m_pInputBuffer->GetBufferPercentage()));
m_iBufferUpdate = iNow;
}
@@ -221,12 +218,12 @@
int iInPercent, iOutPercent;
if (!m_pPmi->IsStreaming() ||
- m_pOutputBuffer == NULL ||
- m_pOutputBuffer->IsEndOfStream() ||
+ m_pLmc->GetInputBuffer() == NULL ||
+ m_pLmc->GetInputBuffer()->IsEndOfStream() ||
m_pInputBuffer == NULL)
return;
- iInPercent = m_pOutputBuffer->GetBufferPercentage();
+ iInPercent = m_pLmc->GetInputBuffer()->GetBufferPercentage();
iOutPercent = m_pInputBuffer->GetBufferPercentage();
if (bForceBufferUp || (iOutPercent <= 5 && iInPercent <= 5))
@@ -234,11 +231,11 @@
for(; !m_bExit && iInPercent < 75;)
{
usleep(500000);
- iInPercent = m_pOutputBuffer->GetBufferPercentage();
+ iInPercent = m_pLmc->GetInputBuffer()->GetBufferPercentage();
iOutPercent = m_pInputBuffer->GetBufferPercentage();
m_pTarget->AcceptEvent(new StreamBufferEvent(true,
iInPercent, iOutPercent));
- if (m_pOutputBuffer->IsEndOfStream())
+ if (m_pLmc->GetInputBuffer()->IsEndOfStream())
break;
}
}
diff -ur zinf-compiled/lmc/cd/include/cdlmc.h zinf/lmc/cd/include/cdlmc.h
--- zinf-compiled/lmc/cd/include/cdlmc.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/cd/include/cdlmc.h 2003-08-11 20:56:33.000000000 +0200
@@ -46,10 +46,18 @@
virtual Error ChangePosition(int32_t position);
virtual Error CanDecode();
- virtual void Clear();
+
+ virtual void Clear()
+ { };
+
virtual Error ExtractMediaInfo();
- virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
+ /** Gets the output buffer of this stream.
+ * Warning! CDLMC has special functionality. This function does not return anything.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer)
+ { return kError_YouScrewedUp; }
+
virtual Error InitDecoder();
virtual Error SetDecodeInfo(DecodeInfo &info);
diff -ur zinf-compiled/lmc/cd/src/cdlmc.cpp zinf/lmc/cd/src/cdlmc.cpp
--- zinf-compiled/lmc/cd/src/cdlmc.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/cd/src/cdlmc.cpp 2003-08-11 20:44:15.000000000 +0200
@@ -57,15 +57,6 @@
{
}
-Error CDLMC::Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer)
-{
- return kError_NoErr;
-}
-
-void CDLMC::Clear()
-{
-}
-
vector<string> *CDLMC::GetExtensions(void)
{
vector<string> *extList = new vector<string>;
diff -ur zinf-compiled/lmc/include/lmc.h zinf/lmc/include/lmc.h
--- zinf-compiled/lmc/include/lmc.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/include/lmc.h 2003-08-11 21:52:43.000000000 +0200
@@ -73,6 +73,23 @@
virtual ~LogicalMediaConverter() {};
+
+ virtual void Pause(void)
+ {
+ PipelineUnit::Pause();
+ if( m_pmi != NULL )
+ m_pmi->Pause();
+ };
+
+
+ virtual void Resume(void)
+ {
+ if( m_pmi != NULL )
+ m_pmi->Resume();
+ PipelineUnit::Resume();
+ };
+
+
/** Sets the lmc to get the data from the supplied url.
* eventually calls pmi SetTo method.
* TODO: move implementation to C-file
@@ -81,16 +98,33 @@
{
assert(m_pmi != NULL);
- m_pmi->SetUrl(url);
+ Error eRet = m_pmi->SetUrl(url);
+
+ // now we have to get a new output buffer
+ if (!IsError(eRet))
+ eRet = m_pmi->GetOutputBuffer( &m_pInputBuffer );
- return m_pmi->Prepare(m_pOutputBuffer);
+ return eRet;
};
/** Returns the current Url */
virtual std::string GetUrl(void)
{ return m_pmi->GetUrl(); }
- virtual Error Prepare(PullBuffer *pInput, PullBuffer *&pOutput) = 0;
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer) = 0;
+
+ /** Gets the input buffer of this stream.
+ * This is a real get function and does nothing more.
+ */
+ virtual PullBuffer* GetInputBuffer()
+ { return m_pInputBuffer; };
+
virtual Error ChangePosition(int32_t) = 0;
virtual Error InitDecoder() = 0;
diff -ur zinf-compiled/lmc/vorbis/include/vorbislmc.h zinf/lmc/vorbis/include/vorbislmc.h
--- zinf-compiled/lmc/vorbis/include/vorbislmc.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/vorbis/include/vorbislmc.h 2003-08-11 20:51:40.000000000 +0200
@@ -59,7 +59,14 @@
virtual void Clear();
virtual Error ExtractMediaInfo();
- virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
+
virtual Error InitDecoder();
virtual std::vector<std::string> *GetExtensions(void);
diff -ur zinf-compiled/lmc/vorbis/src/vorbislmc.cpp zinf/lmc/vorbis/src/vorbislmc.cpp
--- zinf-compiled/lmc/vorbis/src/vorbislmc.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/vorbis/src/vorbislmc.cpp 2003-08-11 20:53:08.000000000 +0200
@@ -88,11 +88,8 @@
}
}
-Error VorbisLMC::Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer)
+Error VorbisLMC::GetOutputBuffer(PullBuffer **pBuffer);
{
- m_pInputBuffer = pInputBuffer;
-
-
m_pOutputBuffer = new EventBuffer(iInitialOutputBufferSize, 0,
m_pContext);
if (!m_decoderThread)
@@ -105,10 +102,12 @@
m_decoderThread->Create(VorbisLMC::DecodeWorkerThreadFunc, this);
}
- pOutBuffer = m_pOutputBuffer;
+ *pBuffer = m_pOutputBuffer;
- m_pInputBuffer->SetName("Input");
- m_pOutputBuffer->SetName("Output");
+ /** The other lmc's don't do this, why should we?? (Ralf)
+ m_pInputBuffer->SetName("Input");
+ m_pOutputBuffer->SetName("Output");
+ */
return kError_NoErr;
}
diff -ur zinf-compiled/lmc/wav/include/wavlmc.h zinf/lmc/wav/include/wavlmc.h
--- zinf-compiled/lmc/wav/include/wavlmc.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/wav/include/wavlmc.h 2003-08-11 20:48:51.000000000 +0200
@@ -87,7 +87,14 @@
virtual void Clear();
virtual Error ExtractMediaInfo();
- virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
+
virtual Error InitDecoder();
virtual Error SetDecodeInfo(DecodeInfo &info);
diff -ur zinf-compiled/lmc/wav/src/wavlmc.cpp zinf/lmc/wav/src/wavlmc.cpp
--- zinf-compiled/lmc/wav/src/wavlmc.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/wav/src/wavlmc.cpp 2003-08-11 20:48:27.000000000 +0200
@@ -107,11 +107,8 @@
}
}
-Error WavLMC::Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer)
+Error WavLMC::GetOutputBuffer(PullBuffer **pBuffer)
{
- m_pInputBuffer = pInputBuffer;
-
-
m_pOutputBuffer = new EventBuffer(iInitialOutputBufferSize, 0,
m_pContext);
@@ -125,7 +122,7 @@
m_decoderThread->Create(WavLMC::DecodeWorkerThreadFunc, this);
}
- pOutBuffer = m_pOutputBuffer;
+ *pBuffer = m_pOutputBuffer;
return kError_NoErr;
}
diff -ur zinf-compiled/lmc/xingmp3/include/xinglmc.h zinf/lmc/xingmp3/include/xinglmc.h
--- zinf-compiled/lmc/xingmp3/include/xinglmc.h 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/xingmp3/include/xinglmc.h 2003-08-11 20:54:25.000000000 +0200
@@ -86,7 +86,14 @@
virtual void Clear();
virtual Error ExtractMediaInfo();
- virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
+ /** Gets the output buffer of this stream.
+ * Because the output buffer will be prepared for the caller, this function should be called
+ * only once.
+ * @param pBuffer is set to the output buffer. Normally it will be prepared for the caller.
+ * @returns Returns an error if one happened.
+ */
+ virtual Error GetOutputBuffer(PullBuffer **pBuffer);
+
virtual Error InitDecoder();
virtual Error SetEQData(float *, float);
diff -ur zinf-compiled/lmc/xingmp3/src/xinglmc.cpp zinf/lmc/xingmp3/src/xinglmc.cpp
--- zinf-compiled/lmc/xingmp3/src/xinglmc.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/lmc/xingmp3/src/xinglmc.cpp 2003-08-11 20:54:03.000000000 +0200
@@ -145,10 +145,8 @@
mpeg_cleanup(&m_sMPEG);
}
-Error XingLMC::Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer)
+Error XingLMC::GetOutputBuffer(PullBuffer **pBuffer)
{
- m_pInputBuffer = pInputBuffer;
-
m_pOutputBuffer = new EventBuffer(iInitialOutputBufferSize, 0,
m_pContext);
@@ -161,7 +159,7 @@
m_decoderThread->Create(XingLMC::DecodeWorkerThreadFunc, this);
}
- pOutBuffer = m_pOutputBuffer;
+ *pBuffer = m_pOutputBuffer;
return kError_NoErr;
}