Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using snd_pcm_prepare for bad file descriptor

  • Loading branch information...
commit ad62fe43883e64de431aa18e469f73c137e86c46 1 parent bdbff81
@wedesoft authored
Showing with 6 additions and 28 deletions.
  1. +1 −1  Rakefile
  2. +5 −25 ext/alsaoutput.cc
  3. +0 −2  ext/alsaoutput.hh
View
2  Rakefile
@@ -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' ]
View
30 ext/alsaoutput.cc
@@ -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);
@@ -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;
@@ -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));
};
@@ -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 );
@@ -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 );
View
2  ext/alsaoutput.hh
@@ -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);
@@ -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 );
Please sign in to comment.
Something went wrong with that request. Please try again.