Re: most of the deadlock fixes
Ed Sweetman <[email protected]>
| Newsgroups | gmane.comp.audio.zinf.devel |
|---|---|
| Message-ID | <[email protected]> |
Ed Sweetman wrote: > This is everything but the vorbis lmc fixes. As you can see not much > needed to be done. Some alsa fixes and mostly just locking up the > localfileinput plugin and pipeline interfaces where it's needed. This > should give you the ability to fast track in a non-ogg playlist etc etc. > > > yea, it helps to attach the patch.
top.patch
(text/plain, 11.7 KB)
diff -Naur -x '*.lo' -x .deps -x .libs -x 'auto*' -x 'Make*' -x 'make*' -x zinf -x '*.la' -x '*.lai' -x CVS -x po -x '*.so' -x '*.o' -x 'config*' ./zinf_cvs-test/io/alsa/unix/linux/src/alsapmo.cpp ./zinf/io/alsa/unix/linux/src/alsapmo.cpp
--- ./zinf_cvs-test/io/alsa/unix/linux/src/alsapmo.cpp 2003-03-20 17:27:03.000000000 -0500
+++ ./zinf/io/alsa/unix/linux/src/alsapmo.cpp 2003-03-21 17:02:39.000000000 -0500
@@ -68,6 +68,7 @@
m_iBytesPerSample = 0;
m_iBaseTime = -1;
m_iDataSize = 0;
+ pfds = NULL;
snd_mixer_t *pMixer;
if (!m_pBufferThread){
@@ -113,20 +114,22 @@
AlsaPMO::~AlsaPMO()
{
- m_bExit = true;
m_pSleepSem->Signal();
m_pPauseSem->Signal();
+ m_pMutex->Acquire();
+ m_bExit = true;
+ if(pfds) free(pfds);
+ m_pMutex->Release();
+
if (m_pBufferThread){
m_pBufferThread->Join();
delete m_pBufferThread;
+ m_pBufferThread = NULL;
}
if(m_handle)
snd_pcm_close(m_handle);
- else
- m_bExit = true;
- if(pfds) free(pfds);
}
void AlsaPMO::SetVolume(int32_t left, int32_t right)
@@ -215,6 +218,7 @@
alsa_dev += m_adev.c_str()[0];
err=snd_pcm_open(&m_handle, alsa_dev.c_str() , SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK);
+
if (err < 0){
ReportError(_("Audio device is busy. Please make sure that "
"another program is not using the device."));
@@ -227,7 +231,6 @@
m_iBytesPerSample = (m_channels*(info->bits_per_sample) / 8);
snd_pcm_hw_params_malloc(¶ms);
-
err = snd_pcm_hw_params_any(m_handle, params);
err = snd_pcm_hw_params_set_access(m_handle, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
@@ -240,13 +243,12 @@
err = snd_pcm_hw_params_set_rate_near(m_handle, params, m_samples, 0);
err = snd_pcm_hw_params_set_period_size(m_handle, params,m_iDataSize/16, 0);
err = snd_pcm_hw_params(m_handle, params);
+ snd_pcm_hw_params_free (params);
+
if (err < 0){
ReportError(_("Cannot initialize audio device."));
return (Error)pmoError_DeviceOpenFailed;
}
- snd_pcm_hw_params_free (params);
-
-
snd_pcm_sw_params_malloc(&sw_params);
snd_pcm_sw_params_current(m_handle, sw_params);
snd_pcm_sw_params_set_avail_min(m_handle, sw_params,m_iDataSize/8);
@@ -260,11 +262,13 @@
#endif
snd_pcm_prepare(m_handle);
-
+
// Sets up our polling timings that are used when writing to driver.
+ m_pMutex->Acquire();
nfds = snd_pcm_poll_descriptors_count (m_handle);
pfds = (struct pollfd *)malloc(sizeof(struct pollfd) * nfds);
snd_pcm_poll_descriptors (m_handle, pfds, nfds);
+ m_pMutex->Release();
m_properlyInitialized = true;
return kError_NoErr;
@@ -286,6 +290,7 @@
// pfds = NULL;
// m_properlyInitialized = false;
// m_bExit=true;
+ WasteTime();
}
return kError_NoErr;
}
@@ -399,7 +404,6 @@
// Don't do anything until resume is called.
m_pPauseSem->Wait();
-
// Sleep for a pre buffer period
PreBuffer();
@@ -428,10 +432,12 @@
if (pEvent->Type() == PMO_Init){
if (IsError(Init(((PMOInitEvent *)pEvent)->GetInfo()))){
delete pEvent;
+ pEvent = NULL;
break;
}
}
delete pEvent;
+ pEvent = NULL;
continue;
}
// RK: after each begin/endread combo we should come back here
@@ -482,10 +488,12 @@
HandleTimeInfoEvent((PMOTimeInfoEvent *)pEvent);
if (pEvent->Type() == PMO_Quit){
delete pEvent;
+ pEvent = NULL;
m_pTarget->AcceptEvent(new Event(INFO_DoneOutputting));
return;
}
delete pEvent;
+ pEvent = NULL;
continue;
}
if (IsError(eErr)){
diff -Naur -x '*.lo' -x .deps -x .libs -x 'auto*' -x 'Make*' -x 'make*' -x zinf -x '*.la' -x '*.lai' -x CVS -x po -x '*.so' -x '*.o' -x 'config*' ./zinf_cvs-test/io/local/localfileinput.cpp ./zinf/io/local/localfileinput.cpp
--- ./zinf_cvs-test/io/local/localfileinput.cpp 2003-03-17 13:42:49.000000000 -0500
+++ ./zinf/io/local/localfileinput.cpp 2003-03-21 18:15:02.000000000 -0500
@@ -87,31 +87,30 @@
LocalFileInput::~LocalFileInput()
{
- m_bExit = true;
- m_bPause = false;
m_pSleepSem->Signal();
m_pPauseSem->Signal();
-
- if (m_pBufferThread)
- {
- m_pBufferThread->Join();
- delete m_pBufferThread;
- }
-
- if (m_fpFile)
- {
+ m_pMutex->Acquire();
+ m_bExit = true;
+ m_bPause = false;
+ if (m_fpFile) {
fclose(m_fpFile);
m_fpFile = NULL;
}
+ m_pMutex->Release();
+ if (m_pBufferThread) {
+ m_pBufferThread->Join();
+ delete m_pBufferThread;
+ m_pBufferThread = NULL;
+ }
+
}
Error LocalFileInput::Prepare(PullBuffer *&pBuffer)
{
int32_t iBufferSize = iDefaultBufferSize;
Error result;
-
- if (m_pOutputBuffer)
- {
+ m_pMutex->Acquire();
+ if (m_pOutputBuffer){
delete m_pOutputBuffer;
m_pOutputBuffer = NULL;
}
@@ -122,7 +121,7 @@
m_pOutputBuffer = new PullBuffer(iBufferSize, iDefaultOverflowSize,
m_pContext);
assert(m_pOutputBuffer);
-
+ m_pMutex->Release();
result = Open();
if (!IsError(result))
{
@@ -139,8 +138,9 @@
ReportError(_("Cannot open file %s."), m_path.c_str());
return result;
}
-
+ m_pMutex->Acquire();
pBuffer = m_pOutputBuffer;
+ m_pMutex->Release();
return kError_NoErr;
}
@@ -160,24 +160,26 @@
Error LocalFileInput::SetTo(const char *url)
{
Error result = kError_NoErr;
+ m_pMutex->Acquire();
m_path = "";
if (strncmp(url, "file://", 7) == 0){
URLToFilePath(url, m_path);
} else
m_path = url;
+ m_pMutex->Release();
return result;
}
Error LocalFileInput::Close(void)
{
- if (m_fpFile)
- {
+ m_pMutex->Acquire();
+ if (m_fpFile) {
fclose(m_fpFile);
m_fpFile = NULL;
}
-
+ m_pMutex->Release();
PipelineUnit::Clear();
-
+
return kError_NoErr;
}
@@ -189,6 +191,7 @@
Error LocalFileInput::Tell(int32_t &iRet)
{
+
iRet = ftell(m_fpFile);
if (iRet < 0)
return kError_SeekFailed;
@@ -206,12 +209,9 @@
return Tell(iRet);
iRet = fseek(m_fpFile, iPos, iFrom);
- if (iRet < 0)
- {
+ if (iRet < 0){
eRet = kError_SeekFailed;
- }
- else
- {
+ } else {
eRet = Tell(iRet);
}
@@ -222,11 +222,14 @@
void LocalFileInput::Clear(void)
{
+ m_pMutex->Acquire();
if (m_fpFile)
fseek(m_fpFile, SEEK_SET, 0);
if (m_pOutputBuffer)
m_pOutputBuffer->Clear();
+ m_pMutex->Release();
PipelineUnit::Clear();
+
}
#define iID3TagSize 128
@@ -235,6 +238,7 @@
{
char pBuffer[iID3TagSize];
+ m_pMutex->Acquire();
if(!m_path.compare("-")){
m_fpFile = stdin;
}
@@ -247,25 +251,30 @@
{
case EACCES:
m_pContext->log->Error(_("Access to the file was denied.\n"));
+ m_pMutex->Release();
return kError_FileNoAccess;
break;
case EINVAL:
m_pContext->log->Error(_("Internal error: The file could not be opened.\n"));
+ m_pMutex->Release();
return kError_FileInvalidArg;
break;
case EMFILE:
m_pContext->log->Error(_("Internal error: The file could not be opened.\n"));
+ m_pMutex->Release();
return kError_FileNoHandles;
break;
case ENOENT:
m_pContext->log->Error(_("File not found.\n"));
+ m_pMutex->Release();
return kError_FileNotFound;
break;
default:
+ m_pMutex->Release();
return kError_UnknownErr;
break;
}
@@ -289,7 +298,7 @@
fseek(m_fpFile, 0, SEEK_SET);
SkipID3v2Tag();
-
+ m_pMutex->Release();
return kError_NoErr;
}
@@ -369,12 +378,15 @@
m_pPauseSem->Wait();
continue;
}
+ if(!m_pOutputBuffer){
+ m_pSleepSem->Wait();
+ continue;
+ }
if (m_pOutputBuffer->IsEndOfStream())
{
m_pSleepSem->Wait();
continue;
- }
-
+ }
eError = m_pOutputBuffer->BeginWrite(pBuffer, iReadBlock);
if (eError == kError_Interrupt)
break;
diff -Naur -x '*.lo' -x .deps -x .libs -x 'auto*' -x 'Make*' -x 'make*' -x zinf -x '*.la' -x '*.lai' -x CVS -x po -x '*.so' -x '*.o' -x 'config*' ./zinf_cvs-test/io/src/pipeline.cpp ./zinf/io/src/pipeline.cpp
--- ./zinf_cvs-test/io/src/pipeline.cpp 2003-03-14 20:01:51.000000000 -0500
+++ ./zinf/io/src/pipeline.cpp 2003-03-21 18:00:18.000000000 -0500
@@ -66,18 +66,15 @@
PipelineUnit::~PipelineUnit()
{
- m_pMutex->Acquire();
-
- m_bExit = true;
- m_bPause = false;
-
m_pPauseSem->Signal();
m_pSleepSem->Signal();
- m_pMutex->Release();
-
+ m_pMutex->Acquire();
+ m_bExit = true;
+ m_bPause = false;
if (m_pOutputBuffer)
delete m_pOutputBuffer;
+ m_pMutex->Release();
delete m_pMutex;
delete m_pPauseSem;
@@ -132,41 +129,35 @@
void PipelineUnit::Pause(void)
{
+ Wake();
+
m_pMutex->Acquire();
-
m_bPause = true;
- Wake();
-
m_pMutex->Release();
}
void PipelineUnit::Resume(void)
{
- m_pMutex->Acquire();
-
- m_bPause = false;
m_pPauseSem->Signal();
+ m_pMutex->Acquire();
+ m_bPause = false;
m_pMutex->Release();
}
void PipelineUnit::Clear(void)
{
- m_pMutex->Acquire();
+ m_pMutex->Acquire();
if (m_pOutputBuffer)
- m_pOutputBuffer->Clear();
-
+ m_pOutputBuffer->Clear();
m_pMutex->Release();
+
}
void PipelineUnit::Wake(void)
{
- m_pMutex->Acquire();
-
m_pSleepSem->Signal();
-
- m_pMutex->Release();
}
bool PipelineUnit::Sleep(void)
diff -Naur -x '*.lo' -x .deps -x .libs -x 'auto*' -x 'Make*' -x 'make*' -x zinf -x '*.la' -x '*.lai' -x CVS -x po -x '*.so' -x '*.o' -x 'config*' ./zinf_cvs-test/io/src/pmi.cpp ./zinf/io/src/pmi.cpp
--- ./zinf_cvs-test/io/src/pmi.cpp 2003-03-14 20:01:51.000000000 -0500
+++ ./zinf/io/src/pmi.cpp 2003-03-21 17:06:31.000000000 -0500
@@ -58,27 +58,32 @@
PhysicalMediaInput::~PhysicalMediaInput()
{
+ m_pSleepSem->Signal();
+ m_pPauseSem->Signal();
+ m_pMutex->Acquire();
m_bExit = true;
m_bPause = false;
- m_pSleepSem->Signal();
- m_pPauseSem->Signal();
+ m_pMutex->Release();
}
Error PhysicalMediaInput::SetTo(const char *url)
{
- m_path = "";
+ m_pMutex->Acquire();
+ m_path = "";
m_path = url;
-
+ m_pMutex->Release();
+
return kError_NoErr;
}
Error PhysicalMediaInput::Close(void)
{
+ m_pMutex->Acquire();
if (m_pOutputBuffer)
m_pOutputBuffer->Clear();
-
+ m_pMutex->Release();
return kError_NoErr;
}
diff -Naur -x '*.lo' -x .deps -x .libs -x 'auto*' -x 'Make*' -x 'make*' -x zinf -x '*.la' -x '*.lai' -x CVS -x po -x '*.so' -x '*.o' -x 'config*' ./zinf_cvs-test/io/src/pmo.cpp ./zinf/io/src/pmo.cpp
--- ./zinf_cvs-test/io/src/pmo.cpp 2003-03-14 20:01:51.000000000 -0500
+++ ./zinf/io/src/pmo.cpp 2003-03-21 17:04:18.000000000 -0500
@@ -60,16 +60,15 @@
PhysicalMediaOutput::~PhysicalMediaOutput()
{
+ m_pPauseSem->Signal();
+ m_pSleepSem->Signal();
+ m_pMutex->Acquire();
m_bExit = true;
-
if (m_pLmc)
m_pLmc->Pause();
if (m_pPmi)
m_pPmi->Pause();
- m_pPauseSem->Signal();
- m_pSleepSem->Signal();
-
//Debug_v("Clear PMO");
Clear();
//Debug_v("Clear LMC");
@@ -78,9 +77,10 @@
//Debug_v("Clear PMI");
if (m_pPmi)
m_pPmi->Clear();
-
+ m_pMutex->Release();
delete m_pLmc;
delete m_pPmi;
+
}
Error PhysicalMediaOutput::SetTo(const char *url)