mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-11 09:40:26 +00:00
Fixed esdout buffer problem, added esdout pause/resume
This commit is contained in:
parent
75c166ec9e
commit
80e6f08745
@ -38,31 +38,19 @@ EsdOut::EsdOut()
|
||||
,currentVolume(1.0)
|
||||
,currentBits(16)
|
||||
,addToRemovedBuffers(false)
|
||||
,host(NULL)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::EsdOut() called" << std::endl;
|
||||
#endif
|
||||
//const char* host;
|
||||
/*int esd;
|
||||
this->host = getenv("ESPEAKER");
|
||||
esd_server_info_t *info;
|
||||
if ((esd = esd_open_sound(NULL)) >= 0)
|
||||
if ((this->esd = esd_open_sound(this->host)) < 0)
|
||||
{
|
||||
info = esd_get_server_info(esd);
|
||||
esd_rate = info->rate;
|
||||
fmt = info->format;
|
||||
esd_free_server_info(info);
|
||||
esd_close(esd);
|
||||
}*/
|
||||
std::cerr << "Couldn't connect to esd server" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
EsdOut::~EsdOut(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::~EsdOut()" << std::endl;
|
||||
#endif
|
||||
this->ClearBuffers();
|
||||
|
||||
esd_close( this->waveHandle );
|
||||
//esd_close( this->waveHandle );
|
||||
esd_close( this->esd );
|
||||
|
||||
}
|
||||
|
||||
@ -71,24 +59,15 @@ int* EsdOut::getWaveHandle() {
|
||||
}
|
||||
|
||||
void EsdOut::Destroy(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::Destroy()" << std::endl;
|
||||
#endif
|
||||
delete this;
|
||||
}
|
||||
|
||||
void EsdOut::Pause(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::Pause()" << std::endl;
|
||||
#endif
|
||||
esd_standby(this->waveHandle);
|
||||
esd_standby(this->esd);
|
||||
}
|
||||
|
||||
void EsdOut::Resume(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::Resume()" << std::endl;
|
||||
#endif
|
||||
esd_resume(this->waveHandle);
|
||||
esd_resume(this->esd);
|
||||
}
|
||||
|
||||
void EsdOut::SetVolume(double volume){
|
||||
@ -102,59 +81,15 @@ void EsdOut::SetVolume(double volume){
|
||||
waveOutSetVolume(this->waveHandle,newVolume);
|
||||
}*/
|
||||
this->currentVolume = volume; //TODO: Write Esd SetVolume() function
|
||||
//Will probably involve adjusting the data manually to be quieter
|
||||
}
|
||||
|
||||
void EsdOut::ClearBuffers(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::ClearBuffers()" << std::endl;
|
||||
#endif
|
||||
//snd_pcm_drop(this->waveHandle);
|
||||
//snd_pcm_reset(this->waveHandle);
|
||||
//TODO: check nothing needs doing here
|
||||
}
|
||||
|
||||
void EsdOut::RemoveBuffer(EsdOutBuffer *buffer){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::RemoveBuffer()" << std::endl;
|
||||
#endif
|
||||
BufferList clearBuffers;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
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);
|
||||
// }
|
||||
clearBuffers.push_back(*buf);
|
||||
buf=this->buffers.erase(buf);
|
||||
found=true;
|
||||
}else{
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EsdOut::ReleaseBuffers(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOut::ReleaseBuffers()" << std::endl;
|
||||
#endif
|
||||
BufferList clearBuffers;
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: check nothing needs doing here
|
||||
}
|
||||
|
||||
bool EsdOut::PlayBuffer(IBuffer *buffer,IPlayer *player){
|
||||
@ -182,11 +117,12 @@ bool EsdOut::PlayBuffer(IBuffer *buffer,IPlayer *player){
|
||||
|
||||
// Header should now be prepared, lets add to waveout
|
||||
if( EsdBuffer->AddToOutput() ){
|
||||
//Don't think this is necessary as the esd server deals with its own buffers
|
||||
// Add to the buffer list
|
||||
{
|
||||
/*{
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
this->buffers.push_back(EsdBuffer);
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -230,9 +166,7 @@ void EsdOut::SetFormat(IBuffer *buffer){
|
||||
this->waveFormat |= ESD_STREAM;
|
||||
this->waveFormat |= ESD_PLAY;
|
||||
|
||||
char* host = getenv("ESPEAKER");
|
||||
|
||||
this->waveHandle = esd_play_stream(this->waveFormat, (int)this->currentSampleRate, host, "musik");
|
||||
this->waveHandle = esd_play_stream(this->waveFormat, (int)this->currentSampleRate, this->host, "musik");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ class EsdOut : public IOutput{
|
||||
//IPlayer *player;
|
||||
|
||||
// Audio stuff
|
||||
char* host;
|
||||
int esd;
|
||||
int waveHandle;
|
||||
esd_format_t waveFormat;
|
||||
|
||||
@ -90,7 +92,6 @@ class EsdOut : public IOutput{
|
||||
int currentBits;
|
||||
int currentChannels;
|
||||
long currentSampleRate;
|
||||
char* host;
|
||||
double currentVolume;
|
||||
|
||||
typedef std::list<EsdOutBufferPtr> BufferList;
|
||||
|
@ -51,10 +51,7 @@ void EsdOutBuffer::PrepareBuffer(){
|
||||
|
||||
EsdOutBuffer::~EsdOutBuffer(void)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "EsdOutBuffer::~EsdOutBuffer()" << std::endl;
|
||||
#endif
|
||||
this->player->ReleaseBuffer(this->buffer);
|
||||
|
||||
}
|
||||
|
||||
bool EsdOutBuffer::AddToOutput(){
|
||||
|
@ -143,9 +143,6 @@ int Player::State(){
|
||||
}
|
||||
|
||||
void Player::ThreadLoop(){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Player::ThreadLoop started" << std::endl;
|
||||
#endif
|
||||
// First start the stream
|
||||
this->stream = Stream::Create();
|
||||
if(this->stream->OpenStream(this->url)){
|
||||
@ -237,13 +234,9 @@ void Player::ThreadLoop(){
|
||||
|
||||
}
|
||||
}else{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "send buffer to output" << std::endl;
|
||||
#endif
|
||||
// Buffer send to output
|
||||
boost::mutex::scoped_lock lock(this->mutex);
|
||||
if(!this->bufferQueue.empty()){
|
||||
this->output->RemoveBuffer()
|
||||
this->bufferQueue.pop_front();
|
||||
|
||||
// Set currentPosition
|
||||
@ -254,9 +247,6 @@ void Player::ThreadLoop(){
|
||||
|
||||
}
|
||||
}else{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "has got no more buffer" << std::endl;
|
||||
#endif
|
||||
// We have no more to decode
|
||||
finished = true;
|
||||
}
|
||||
|
@ -48,9 +48,6 @@ Stream::Stream(unsigned int options)
|
||||
,decoderSampleRate(0)
|
||||
,decoderSamplePosition(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Stream::Stream()" << std::endl;
|
||||
#endif
|
||||
// Get all DSPs
|
||||
// TODO: fixing PluginFactory
|
||||
if( (this->options&NoDSP)==0){
|
||||
@ -96,18 +93,12 @@ void Stream::SetPreferedBufferSampleSize(long samples){
|
||||
}
|
||||
*/
|
||||
bool Stream::OpenStream(utfstring uri){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Stream::OpenStream()" << std::endl;
|
||||
#endif
|
||||
|
||||
// Open the filestream
|
||||
this->fileStream = musik::core::filestreams::Factory::OpenFile(uri.c_str());
|
||||
if(!this->fileStream){
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "File opened" << std::endl;
|
||||
#endif
|
||||
|
||||
// Look up what DecoderFactory to use
|
||||
StreamHelper::DecoderFactoryPtr decoderFactory;
|
||||
@ -117,17 +108,10 @@ bool Stream::OpenStream(utfstring uri){
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "File decoder looked for" << std::endl;
|
||||
#endif
|
||||
|
||||
if(!decoderFactory){
|
||||
// We have failed to get a working decoderFactory
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Found file decoder" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
// Create the decoder
|
||||
@ -136,9 +120,6 @@ bool Stream::OpenStream(utfstring uri){
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Decoder opened" << std::endl;
|
||||
#endif
|
||||
|
||||
// Open the decoder
|
||||
typedef musik::core::PluginFactory::DestroyDeleter<IDecoder> IDecoderDeleter;
|
||||
@ -146,9 +127,6 @@ bool Stream::OpenStream(utfstring uri){
|
||||
if( !this->decoder->Open(this->fileStream.get()) ){
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "File opened by decoder" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,9 @@
|
||||
namespace musik { namespace core { namespace audio {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Interface between application and Player objects
|
||||
*/
|
||||
class Transport : public sigslot::has_slots<>{
|
||||
public:
|
||||
Transport();
|
||||
@ -77,13 +80,13 @@ class Transport : public sigslot::has_slots<>{
|
||||
PlaybackEvent PlaybackEnded;
|
||||
PlaybackEvent PlaybackPause;
|
||||
PlaybackEvent PlaybackResume;
|
||||
PlaybackEvent PlaybackError;
|
||||
PlaybackEvent PlaybackError;
|
||||
|
||||
private:
|
||||
void OnPlaybackStarted(Player *player);
|
||||
void OnPlaybackAlmostEnded(Player *player);
|
||||
void OnPlaybackEnded(Player *player);
|
||||
void OnPlaybackError(Player *player);
|
||||
void OnPlaybackStarted(Player *player);
|
||||
void OnPlaybackAlmostEnded(Player *player);
|
||||
void OnPlaybackEnded(Player *player);
|
||||
void OnPlaybackError(Player *player);
|
||||
|
||||
private:
|
||||
double volume;
|
||||
|
@ -49,6 +49,7 @@ using namespace musik::square;
|
||||
ConsoleUI::ConsoleUI()
|
||||
: shouldQuit(false)
|
||||
, audioEventHandler(this)
|
||||
, paused(false)
|
||||
{
|
||||
// this->transport.EventPlaybackStartedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
|
||||
// this->transport.EventPlaybackStartedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedFail);
|
||||
@ -63,6 +64,7 @@ ConsoleUI::ConsoleUI()
|
||||
|
||||
this->transport.PlaybackStarted.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
|
||||
this->transport.PlaybackAlmostDone.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackAlmostEnded);
|
||||
this->transport.PlaybackEnded.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedOk);
|
||||
this->transport.PlaybackError.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
|
||||
}
|
||||
|
||||
@ -121,14 +123,22 @@ void ConsoleUI::ProcessCommand(utfstring commandString)
|
||||
{
|
||||
this->PlayFile(args);
|
||||
}
|
||||
else if (command == UTF("pa"))
|
||||
{
|
||||
this->Pause();
|
||||
}
|
||||
else if (command == UTF("s"))
|
||||
{
|
||||
this->Stop(args);
|
||||
}
|
||||
/*else if (command == UTF("l"))
|
||||
else if (command == UTF("sp"))
|
||||
{
|
||||
this->SetPosition(args);
|
||||
}
|
||||
else if (command == UTF("l"))
|
||||
{
|
||||
this->ListPlaying();
|
||||
}*/
|
||||
}
|
||||
else if (command == UTF("lp"))
|
||||
{
|
||||
this->ListPlugins();
|
||||
@ -188,6 +198,19 @@ void ConsoleUI::PlayFile(Args args)
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleUI::Pause()
|
||||
{
|
||||
if (this->paused) {
|
||||
transport.Resume();
|
||||
this->paused = !this->paused;
|
||||
}
|
||||
else
|
||||
{
|
||||
transport.Pause();
|
||||
this->paused = !this->paused;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleUI::Stop(Args args)
|
||||
{
|
||||
this->Stop();
|
||||
@ -197,10 +220,11 @@ void ConsoleUI::Stop()
|
||||
{
|
||||
transport.Stop();
|
||||
}
|
||||
/*
|
||||
|
||||
void ConsoleUI::ListPlaying()
|
||||
{
|
||||
/*AudioStreamOverview overview = transport.StreamsOverview();
|
||||
/*
|
||||
AudioStreamOverview overview = transport.StreamsOverview();
|
||||
AudioStreamOverviewIterator it;
|
||||
|
||||
|
||||
@ -210,8 +234,8 @@ void ConsoleUI::ListPlaying()
|
||||
}
|
||||
|
||||
utfcout << "------------------\n";
|
||||
utfcout << transport.NumOfStreams() << " playing" << std::std::endl;
|
||||
}*/
|
||||
utfcout << transport.NumOfStreams() << " playing" << std::std::endl;*/
|
||||
}
|
||||
|
||||
void ConsoleUI::ListPlugins()
|
||||
{
|
||||
@ -231,6 +255,16 @@ void ConsoleUI::ListPlugins()
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleUI::SetPosition(Args args)
|
||||
{
|
||||
if (args.size() > 0) {
|
||||
double newPosition = 0;
|
||||
if (convertString<double>(newPosition, args[0])) {
|
||||
transport.SetPosition(newPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleUI::SetVolume(Args args)
|
||||
{
|
||||
if (args.size() > 0)
|
||||
|
@ -65,16 +65,19 @@ public: void Print(utfstring s);
|
||||
|
||||
// Commands
|
||||
private: void PlayFile(Args args);
|
||||
private: void Pause();
|
||||
private: void Stop(Args args);
|
||||
private: void Stop();
|
||||
private: void ListPlaying();
|
||||
private: void ListPlugins();
|
||||
private: void SetPosition(Args args);
|
||||
private: void SetVolume(Args args);
|
||||
private: void SetVolume(short volume);
|
||||
private: void Quit();
|
||||
|
||||
// Members
|
||||
private: bool shouldQuit;
|
||||
private: bool paused;
|
||||
private: Transport transport;
|
||||
private: DummyAudioEventHandler audioEventHandler;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user