mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Nearly fixed all the bugs in Esd output plugin
This commit is contained in:
parent
6c597b4f78
commit
75c166ec9e
@ -67,9 +67,6 @@ EsdOut::~EsdOut(){
|
||||
}
|
||||
|
||||
int* EsdOut::getWaveHandle() {
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::getWaveHandle()" << std::endl;
|
||||
#endif
|
||||
return &this->waveHandle;
|
||||
}
|
||||
|
||||
@ -126,6 +123,9 @@ void EsdOut::RemoveBuffer(EsdOutBuffer *buffer){
|
||||
bool found(false);
|
||||
for(BufferList::iterator buf=this->buffers.begin();buf!=this->buffers.end() && !found;){
|
||||
if(buf->get()==buffer){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Remove loop" << std::endl;
|
||||
#endif
|
||||
// if( !(*buf)->ReadyToRelease() ){
|
||||
this->removedBuffers.push_back(*buf);
|
||||
// }
|
||||
@ -147,6 +147,9 @@ void EsdOut::ReleaseBuffers(){
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
for(BufferList::iterator buf=this->removedBuffers.begin();buf!=this->removedBuffers.end();){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Release loop" << std::endl;
|
||||
#endif
|
||||
clearBuffers.push_back(*buf);
|
||||
buf = this->removedBuffers.erase(buf);
|
||||
}
|
||||
@ -155,9 +158,6 @@ void EsdOut::ReleaseBuffers(){
|
||||
}
|
||||
|
||||
bool EsdOut::PlayBuffer(IBuffer *buffer,IPlayer *player){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::PlayBuffer()" << std::endl;
|
||||
#endif
|
||||
|
||||
size_t bufferSize = 0;
|
||||
{
|
||||
@ -196,17 +196,11 @@ bool EsdOut::PlayBuffer(IBuffer *buffer,IPlayer *player){
|
||||
}
|
||||
|
||||
void EsdOut::SetFormat(IBuffer *buffer){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::SetFormat()" << std::endl;
|
||||
#endif
|
||||
|
||||
if(this->currentChannels!=buffer->Channels() || this->currentSampleRate!=buffer->SampleRate() ||this->waveHandle==NULL){
|
||||
this->currentChannels = buffer->Channels();
|
||||
this->currentSampleRate = buffer->SampleRate();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Channels: " << this->currentChannels << std::endl;
|
||||
std::cerr << "Rate: " << this->currentSampleRate << std::endl;
|
||||
std::cerr << "Bits: " << this->currentBits << std::endl;
|
||||
#endif
|
||||
|
||||
if (this->waveHandle) {
|
||||
esd_close(this->waveHandle);
|
||||
}
|
||||
@ -235,16 +229,10 @@ void EsdOut::SetFormat(IBuffer *buffer){
|
||||
|
||||
this->waveFormat |= ESD_STREAM;
|
||||
this->waveFormat |= ESD_PLAY;
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "waveFormat: " << this->waveFormat << std::endl;
|
||||
#endif
|
||||
char* host = getenv("ESPEAKER");
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "host: " << host << std::endl;
|
||||
#endif
|
||||
|
||||
char* host = getenv("ESPEAKER");
|
||||
|
||||
this->waveHandle = esd_play_stream(this->waveFormat, (int)this->currentSampleRate, host, "musik");
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "waveHandle: " << this->waveHandle << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -40,37 +40,13 @@ EsdOutBuffer::EsdOutBuffer(EsdOut *EsdOut,IBuffer *buffer,IPlayer *player)
|
||||
,buffer(buffer)
|
||||
,player(player)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOutBuffer::EsdOutBuffer()" << std::endl;
|
||||
#endif
|
||||
this->PrepareBuffer();
|
||||
}
|
||||
|
||||
void EsdOutBuffer::PrepareBuffer(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOutBuffer::PrepareBuffer()" << std::endl;
|
||||
#endif
|
||||
//unsigned float bufSize = this->buffer->Samples()*this->buffer->Channels()*sizeof(float);
|
||||
/*// Prepare the header
|
||||
this->header.dwBufferLength = this->buffer->Samples()*this->buffer->Channels()*sizeof(float);
|
||||
this->header.lpData = (LPSTR)this->buffer->BufferPointer();
|
||||
this->header.dwUser = (DWORD_PTR)this;
|
||||
this->header.dwBytesRecorded = 0;
|
||||
this->header.dwFlags = 0;
|
||||
this->header.dwLoops = 0;
|
||||
this->header.lpNext = NULL;
|
||||
this->header.reserved = NULL;
|
||||
|
||||
MMRESULT result = waveOutPrepareHeader(this->waveOut->waveHandle,&this->header,sizeof(WAVEHDR));
|
||||
if(result!=MMSYSERR_NOERROR){
|
||||
throw;
|
||||
}
|
||||
this->header.dwFlags |= WHDR_DONE;
|
||||
*/
|
||||
data = (char*)this->buffer->BufferPointer();
|
||||
bufferLength = this->buffer->Samples()*this->buffer->Channels()*sizeof(float);
|
||||
//TODO: Check data types.
|
||||
|
||||
}
|
||||
|
||||
EsdOutBuffer::~EsdOutBuffer(void)
|
||||
@ -82,28 +58,15 @@ EsdOutBuffer::~EsdOutBuffer(void)
|
||||
}
|
||||
|
||||
bool EsdOutBuffer::AddToOutput(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOutBuffer::AddToOutput()" << std::endl;
|
||||
#endif
|
||||
//int err;
|
||||
int* wHandle = waveOut->getWaveHandle();
|
||||
if (wHandle == NULL) {
|
||||
printf("Error. No device handle \n");
|
||||
return false;
|
||||
}
|
||||
/*frames = snd_pcm_writei(wHandle, (void*)data, bufferLength);
|
||||
if (frames < 0)
|
||||
frames = snd_pcm_recover(wHandle, frames, 0);
|
||||
if (frames < 0) {
|
||||
printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
|
||||
return false;
|
||||
}
|
||||
if (frames > 0 && frames < (long)bufferLength) {
|
||||
printf("Short write (expected %li, wrote %li)\n", (long)bufferLength, frames);
|
||||
return false;
|
||||
}*/
|
||||
if ( write( *wHandle, data, bufferLength ) <= 0 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -175,15 +175,9 @@ void Player::ThreadLoop(){
|
||||
// Player should be started or quit by now
|
||||
bool finished(false);
|
||||
while(!finished && !this->Exited()){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "while loop" << std::endl;
|
||||
#endif
|
||||
if(this->setPosition!=-1){
|
||||
// Set a new position
|
||||
this->output->ClearBuffers();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Buffers cleared" << std::endl;
|
||||
#endif
|
||||
this->stream->SetPosition(this->setPosition);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
@ -193,14 +187,8 @@ void Player::ThreadLoop(){
|
||||
this->totalBufferSize = 0;
|
||||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "position set" << std::endl;
|
||||
#endif
|
||||
|
||||
this->output->ReleaseBuffers();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "buffers released" << std::endl;
|
||||
#endif
|
||||
|
||||
// Get a buffer, either from the bufferQueue, or from the stream
|
||||
BufferPtr buffer;
|
||||
@ -214,22 +202,13 @@ void Player::ThreadLoop(){
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
this->bufferQueue.push_back(buffer);
|
||||
this->totalBufferSize += buffer->Bytes();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "got buffer" << std::endl;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "not got buffer :(" << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "good buffer" << std::endl;
|
||||
#endif
|
||||
|
||||
{
|
||||
// Add the buffer to locked buffers so the output do not have time to play and
|
||||
@ -237,15 +216,9 @@ void Player::ThreadLoop(){
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
this->lockedBuffers.push_back(buffer);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "locked buffer" << std::endl;
|
||||
#endif
|
||||
|
||||
// Try to play the buffer
|
||||
if(!this->output->PlayBuffer(buffer.get(),this)){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "couldn't play buffer" << std::endl;
|
||||
#endif
|
||||
{
|
||||
// We didn't manage to play the buffer, remove it from the locked buffer queue
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
@ -253,7 +226,9 @@ void Player::ThreadLoop(){
|
||||
}
|
||||
|
||||
if(!this->PreBuffer()){
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "!this->PreBuffer" << std::endl;
|
||||
#endif
|
||||
// Wait for buffersize to become smaller
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
if(this->totalBufferSize>this->maxBufferSize){
|
||||
@ -268,6 +243,7 @@ void Player::ThreadLoop(){
|
||||
// Buffer send to output
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
if(!this->bufferQueue.empty()){
|
||||
this->output->RemoveBuffer()
|
||||
this->bufferQueue.pop_front();
|
||||
|
||||
// Set currentPosition
|
||||
@ -279,7 +255,7 @@ void Player::ThreadLoop(){
|
||||
}
|
||||
}else{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "has got more buffer" << std::endl;
|
||||
std::cerr << "has got no more buffer" << std::endl;
|
||||
#endif
|
||||
// We have no more to decode
|
||||
finished = true;
|
||||
@ -295,9 +271,6 @@ void Player::ThreadLoop(){
|
||||
bool buffersEmpty=false;
|
||||
do{
|
||||
this->output->ReleaseBuffers();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "release buffer" << std::endl;
|
||||
#endif
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
buffersEmpty = this->lockedBuffers.empty();
|
||||
@ -357,6 +330,9 @@ void Player::ReleaseBuffer(IBuffer *buffer){
|
||||
// Remove the buffer from lockedBuffers
|
||||
for(BufferList::iterator foundBuffer=this->lockedBuffers.begin();foundBuffer!=this->lockedBuffers.end();++foundBuffer){
|
||||
if(foundBuffer->get()==buffer){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Found buffer to delete in locked buffer list" << std::endl;
|
||||
#endif
|
||||
this->totalBufferSize -= buffer->Bytes();
|
||||
if( this->stream ){
|
||||
this->stream->DeleteBuffer(*foundBuffer);
|
||||
|
Loading…
Reference in New Issue
Block a user