#include <unistd.h>
#include <fcntl.h>
#include <time.h>
-#include <dmalloc.h>
#include "wx/app.h"
#include "wx/utils.h"
bool wxUssSound::DoInput(wxSndBuffer *buf)
{
wxUint32 bufsize;
- wxSoundCodec *codec = buf->GetFormat().GetCodec();
+ wxSoundCodec *codec = buf->GetCurrentCodec();
m_sndbuf->ResetBuffer();
- codec->SetInStream(m_sndbuf);
- codec->InitIO(m_ussformat);
bufsize = codec->Available();
if (bufsize > m_max_bufsize)
buf->Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
return false;
}
- read(m_fd, m_sndbuf, bufsize);
+ read(m_fd, m_sndbuf->GetBufferStart(), bufsize);
codec->Encode();
return true;
wxSoundCodec *codec = buf->GetCurrentCodec();
m_sndbuf->ResetBuffer();
- codec->SetOutStream(m_sndbuf);
- codec->InitIO(m_ussformat);
if (!codec->Available()) {
buf->Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
- return false;
+ return FALSE;
}
codec->Decode();
- write(m_fd, m_sndbuf, m_sndbuf->GetIntPosition());
+ write(m_fd, m_sndbuf->GetBufferStart(), m_sndbuf->GetIntPosition());
// Well ... it's not accurate ! :-|
buf->OnBufferOutFinished();
- return true;
+ return TRUE;
+}
+
+bool wxUssSound::InitBuffer(wxSndBuffer *buf)
+{
+ wxSoundCodec *codec;
+
+ if (!OnSetupDriver(*buf, buf->GetMode())) {
+ if (buf->IsNotSet(wxSND_BUFREADY))
+ return FALSE;
+ }
+
+ codec = buf->GetCurrentCodec();
+ switch (m_mode) {
+ case wxSND_INPUT:
+ codec->SetInStream(m_sndbuf);
+ codec->InitIO(m_ussformat);
+ codec->InitMode(wxSoundCodec::ENCODING);
+ break;
+ case wxSND_OUTPUT:
+ codec->SetOutStream(m_sndbuf);
+ codec->InitIO(m_ussformat);
+ codec->InitMode(wxSoundCodec::DECODING);
+ break;
+ }
+ return TRUE;
}
void *wxUssSound::Entry()
wxNode *node;
wxSndBuffer *buf;
- while (!m_stop_thrd) {
- node = m_buffers.First();
- if (!node) {
- USS_Sleep();
- continue;
- }
- buf = (wxSndBuffer *)node->Data();
- if (!OnSetupDriver(*buf, buf->GetMode()))
- continue;
+ node = m_buffers.First();
+ if (!node) {
+ m_stop_thrd = FALSE;
+ return NULL;
+ }
+
+ buf = (wxSndBuffer *)node->Data();
+ InitBuffer(buf);
+ while (!m_stop_thrd) {
buf->HardLock();
if (buf->IsSet(wxSND_BUFSTOP)) {
buf->HardUnlock();
- delete node;
- continue;
+ goto sound_clean_buffer;
}
switch(m_mode) {
case wxSND_INPUT:
if (!DoInput(buf))
- delete node;
+ goto sound_clean_buffer;
break;
case wxSND_OUTPUT:
if (!DoOutput(buf))
- delete node;
+ goto sound_clean_buffer;
break;
case wxSND_DUPLEX:
case wxSND_OTHER_IO:
+ goto sound_clean_buffer;
break;
}
buf->HardUnlock();
+ continue;
+ sound_clean_buffer:
+ buf->GetCurrentCodec()->ExitMode();
+ delete node;
+ node = m_buffers.First();
+ if (!node)
+ USS_Sleep();
+ if (node)
+ buf = (wxSndBuffer *)node->Data();
}
return NULL;
}
wxSoundDataFormat format;
wxSoundCodec *codec;
- codec = buf.GetFormat().GetCodec();
+ codec = buf.GetCurrentCodec();
format = codec->GetPreferredFormat(WXSOUND_PCM);
if ((format.GetSampleRate() != m_srate) ||
m_buffers.DeleteObject(&buf);
buf.Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
buf.SetError(wxSND_CANTSET);
- return false;
+ return FALSE;
}
m_mode = wxSND_OTHER_IO;
}
if (buf.GetMode() != m_mode) {
m_mode = buf.GetMode();
- return false;
+ return FALSE;
}
- return true;
+ return TRUE;
}
wxUint32 wxUssSound::GetNbFragments()