Skip to content

Commit

Permalink
Using snd_pcm_prepare for bad file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
wedesoft committed Nov 14, 2012
1 parent bdbff81 commit ad62fe4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
require 'rbconfig'

PKG_NAME = 'hornetseye-alsa'
PKG_VERSION = '1.1.1'
PKG_VERSION = '1.1.2'
CFG = RbConfig::CONFIG
CXX = ENV[ 'CXX' ] || 'g++'
RB_FILES = FileList[ 'lib/**/*.rb' ]
Expand Down
30 changes: 5 additions & 25 deletions ext/alsaoutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ AlsaOutput::AlsaOutput(const string &pcmName, unsigned int rate,
snd_pcm_hw_params_t *hwParams;
snd_pcm_hw_params_alloca(&hwParams);
int err = snd_pcm_open(&m_pcmHandle, m_pcmName.c_str(), SND_PCM_STREAM_PLAYBACK,
0);//SND_PCM_NONBLOCK);
SND_PCM_NONBLOCK);
ERRORMACRO(err >= 0, Error, , "Error opening PCM device \"" << m_pcmName
<< "\": " << snd_strerror(err));
err = snd_pcm_hw_params_any(m_pcmHandle, hwParams);
Expand Down Expand Up @@ -145,17 +145,6 @@ void AlsaOutput::drain(void) throw (Error)
snd_pcm_drain(m_pcmHandle);
}

void AlsaOutput::prepare(void) throw (Error)
{
ERRORMACRO( m_pcmHandle != NULL, Error, , "PCM device \"" << m_pcmName
<< "\" is not open. Did you call \"close\" before?" );

int err = snd_pcm_prepare( m_pcmHandle );
ERRORMACRO( err >= 0, Error, , "Error preparing PCM device \"" << m_pcmName
<< "\": " << snd_strerror( err ) );
// pthread_mutex_lock( &m_mutex );
}

unsigned int AlsaOutput::rate(void)
{
return m_rate;
Expand Down Expand Up @@ -214,7 +203,10 @@ void AlsaOutput::writei(short int *data, int count) throw (Error)
{
int err;
while ((err = snd_pcm_writei(m_pcmHandle, data, count)) < 0) {
err = snd_pcm_recover(m_pcmHandle, err, 1);
if (err == -EBADFD)
err = snd_pcm_prepare(m_pcmHandle);
else
err = snd_pcm_recover(m_pcmHandle, err, 1);
ERRORMACRO(err >= 0, Error, , "Error writing audio frames to PCM device \""
<< m_pcmName << "\": " << snd_strerror(err));
};
Expand Down Expand Up @@ -265,7 +257,6 @@ VALUE AlsaOutput::registerRubyClass( VALUE rbModule )
rb_define_method( cRubyClass, "write", RUBY_METHOD_FUNC( wrapWrite ), 1 );
rb_define_method( cRubyClass, "drop", RUBY_METHOD_FUNC( wrapDrop ), 0 );
rb_define_method( cRubyClass, "drain", RUBY_METHOD_FUNC( wrapDrain ), 0 );
rb_define_method( cRubyClass, "prepare", RUBY_METHOD_FUNC( wrapPrepare ), 0 );
rb_define_method( cRubyClass, "rate", RUBY_METHOD_FUNC( wrapRate ), 0 );
rb_define_method( cRubyClass, "channels", RUBY_METHOD_FUNC( wrapChannels ), 0 );
rb_define_method( cRubyClass, "delay", RUBY_METHOD_FUNC( wrapDelay ), 0 );
Expand Down Expand Up @@ -332,17 +323,6 @@ VALUE AlsaOutput::wrapDrain( VALUE rbSelf )
return rbSelf;
}

VALUE AlsaOutput::wrapPrepare( VALUE rbSelf )
{
try {
AlsaOutputPtr *self; Data_Get_Struct( rbSelf, AlsaOutputPtr, self );
(*self)->prepare();
} catch ( exception &e ) {
rb_raise( rb_eRuntimeError, "%s", e.what() );
};
return rbSelf;
}

VALUE AlsaOutput::wrapRate( VALUE rbSelf )
{
AlsaOutputPtr *self; Data_Get_Struct( rbSelf, AlsaOutputPtr, self );
Expand Down
2 changes: 0 additions & 2 deletions ext/alsaoutput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public:
void write( SequencePtr sequence ) throw (Error);
void drop(void) throw (Error);
void drain(void) throw (Error);
void prepare(void) throw (Error);
unsigned int rate(void);
unsigned int channels(void);
int delay(void) throw (Error);
Expand All @@ -47,7 +46,6 @@ public:
static VALUE wrapWrite( VALUE rbSelf, VALUE rbSequence );
static VALUE wrapDrop( VALUE rbSelf );
static VALUE wrapDrain( VALUE rbSelf );
static VALUE wrapPrepare( VALUE rbSelf );
static VALUE wrapRate( VALUE rbSelf );
static VALUE wrapChannels( VALUE rbSelf );
static VALUE wrapDelay( VALUE rbSelf );
Expand Down

0 comments on commit ad62fe4

Please sign in to comment.