alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* issues with pulse plugin
@ 2007-11-08 22:21 Mike Gorse
  2007-11-12  7:55 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Gorse @ 2007-11-08 22:21 UTC (permalink / raw)
  To: alsa-devel

I have run into what is basically another instance of bug 3470 
(pulse_hw_params asserting because the stream is already initialized). 
The application that I am working with is calling snd_pcm_hw_params each 
time it plays a sample.  The following patch makes things work for me 
(actually the app still doesn't work because it uses poll() in a way that 
is incompatible with the pulse plugin, but that is a separate issue, and I 
don't know if it should be considered a bug in the plugin.)

--- pulse/pcm_pulse.c.orig	2007-11-08 15:13:12.000000000 -0500
+++ pulse/pcm_pulse.c	2007-11-08 15:13:12.000000000 -0500
@@ -497,7 +497,7 @@
      assert(pcm->p);

      //Resolving bugtrack ID 0003470
-    if(!(base && snd_pcm_state(base) == SND_PCM_STATE_PREPARED))
+    if(!(base && (snd_pcm_state(base) == SND_PCM_STATE_PREPARED || snd_pcm_state(base) == SND_PCM_STATE_SETUP)))
      	assert(!pcm->stream);

      pa_threaded_mainloop_lock(pcm->p->mainloop);

--

I couldn't add this to the bug because it was marked as resolved.

Any comments?  Or is the app behaving in a way that is counter to the 
specification?

Also, I'm still encountering bug 2601 (a separate assert failure that 
happens if period_size == 0) even with the patch to pcm_ioplug.c.  I think 
that PERIOD_TIME and PERIODS need to be constrained; I added a couple of 
comments to the bug.

Thanks,

-- Mike Gorse / AIM:linvortex / http://mgorse.freeshell.org --

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: issues with pulse plugin
  2007-11-08 22:21 issues with pulse plugin Mike Gorse
@ 2007-11-12  7:55 ` Takashi Iwai
  2007-11-12 12:03   ` Mike Gorse
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2007-11-12  7:55 UTC (permalink / raw)
  To: Mike Gorse; +Cc: alsa-devel

At Thu, 8 Nov 2007 17:21:20 -0500 (EST),
Mike Gorse wrote:
> 
> I have run into what is basically another instance of bug 3470 
> (pulse_hw_params asserting because the stream is already initialized). 
> The application that I am working with is calling snd_pcm_hw_params each 
> time it plays a sample.  The following patch makes things work for me 
> (actually the app still doesn't work because it uses poll() in a way that 
> is incompatible with the pulse plugin, but that is a separate issue, and I 
> don't know if it should be considered a bug in the plugin.)
> 
> --- pulse/pcm_pulse.c.orig	2007-11-08 15:13:12.000000000 -0500
> +++ pulse/pcm_pulse.c	2007-11-08 15:13:12.000000000 -0500
> @@ -497,7 +497,7 @@
>       assert(pcm->p);
> 
>       //Resolving bugtrack ID 0003470
> -    if(!(base && snd_pcm_state(base) == SND_PCM_STATE_PREPARED))
> +    if(!(base && (snd_pcm_state(base) == SND_PCM_STATE_PREPARED || snd_pcm_state(base) == SND_PCM_STATE_SETUP)))
>       	assert(!pcm->stream);
> 
>       pa_threaded_mainloop_lock(pcm->p->mainloop);
> 
> --

I fixed it on HG tree now.

> 
> I couldn't add this to the bug because it was marked as resolved.

Can't you reopen (as feedback)?

> Any comments?  Or is the app behaving in a way that is counter to the 
> specification?
> 
> Also, I'm still encountering bug 2601 (a separate assert failure that 
> happens if period_size == 0) even with the patch to pcm_ioplug.c.  I think 
> that PERIOD_TIME and PERIODS need to be constrained; I added a couple of 
> comments to the bug.

Hm, does it happen with the latest HG tree, too?


Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: issues with pulse plugin
  2007-11-12  7:55 ` Takashi Iwai
@ 2007-11-12 12:03   ` Mike Gorse
  2007-11-13 11:34     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Gorse @ 2007-11-12 12:03 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 633 bytes --]

Hi Takashi,

> Can't you reopen (as feedback)?

Oh, perhaps I could; I haven't used Mantis before and didn't look that 
carefully :(

>> Also, I'm still encountering bug 2601 (a separate assert failure that
>> happens if period_size == 0) even with the patch to pcm_ioplug.c.  I think
>> that PERIOD_TIME and PERIODS need to be constrained; I added a couple of
>> comments to the bug.
>
> Hm, does it happen with the latest HG tree, too?

Yes (at least with the latest hg tree that was accessible via hg-mirror a 
few minutes ago).  I put a patch on the bug that does make things work. 
Test case attached (adapted from flite mostly)

[-- Attachment #2: Type: TEXT/x-csrc, Size: 2815 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include  <time.h>
#include <string.h>
#include <unistd.h>
#include <alsa/asoundlib.h>

static int getAvailableFrames(snd_pcm_t *pcm, int *xrunOccurred)
{
    snd_pcm_sframes_t framesAvail = snd_pcm_avail_update( pcm );
    *xrunOccurred = 0;

    if( -EPIPE == framesAvail )
    {
        *xrunOccurred = 1;
        framesAvail = 0;
    }

    return framesAvail;
}

static char *buf;

snd_pcm_t *audio_open_alsa(const char *pcm_dev_name, int sps, int channels)
{
  unsigned 	int real_rate;
  int err;
  unsigned long bufSz = 1411;

  snd_pcm_t *pcm_handle;          
  snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
  snd_pcm_hw_params_t *hwparams;
  snd_pcm_format_t format;
  snd_pcm_access_t access = SND_PCM_ACCESS_RW_INTERLEAVED;

  /* Allocate the snd_pcm_hw_params_t structure on the stack. */
  snd_pcm_hw_params_alloca(&hwparams);

  /* Open pcm device */
  err = snd_pcm_open(&pcm_handle, pcm_dev_name, stream, 0);
  if (err < 0) 
  {
	return NULL;
  }

  /* Init hwparams with full configuration space */
  err = snd_pcm_hw_params_any(pcm_handle, hwparams);
  if (err < 0) 
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  /* Set access mode */
  err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, access);
  if (err < 0) 
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  format = SND_PCM_FORMAT_S16_LE;

  /* Set samble format */
  err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format);
  if (err <0) 
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  /* Set sample rate near the disired rate */
  real_rate = sps;
  err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &real_rate, 0);
  if (err < 0)   
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  /* Set number of channels */
  assert(channels >0);
  err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels);
  if (err < 0) 
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &bufSz);

  /* Commit hardware parameters */
  err = snd_pcm_hw_params(pcm_handle, hwparams);
  if (err < 0) 
  {
	snd_pcm_close(pcm_handle);
	return NULL;
  }

  /* Make sure the device is ready to accept data */
  assert(snd_pcm_state(pcm_handle) == SND_PCM_STATE_PREPARED);
  return pcm_handle;
}

main(int argc, const char *argv[])
{
  snd_pcm_t *pcm;
  buf = (char *)malloc(1000000);
  pcm = audio_open_alsa("default", 22050, 1);
  int xrun;
  int result;
  pthread_t th;

  if (!pcm)
  {
    fprintf(stderr, "Couldn't open pcm\n");
    exit(1);
  }
  unsigned long avail = snd_pcm_avail_update(pcm);
  if (avail > 100000) avail = 100000;
  result = snd_pcm_writei(pcm, buf, avail);
}

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: issues with pulse plugin
  2007-11-12 12:03   ` Mike Gorse
@ 2007-11-13 11:34     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2007-11-13 11:34 UTC (permalink / raw)
  To: Mike Gorse; +Cc: alsa-devel

At Mon, 12 Nov 2007 07:03:17 -0500 (EST),
Mike Gorse wrote:
> 
> Hi Takashi,
> 
> > Can't you reopen (as feedback)?
> 
> Oh, perhaps I could; I haven't used Mantis before and didn't look that 
> carefully :(
> 
> >> Also, I'm still encountering bug 2601 (a separate assert failure that
> >> happens if period_size == 0) even with the patch to pcm_ioplug.c.  I think
> >> that PERIOD_TIME and PERIODS need to be constrained; I added a couple of
> >> comments to the bug.
> >
> > Hm, does it happen with the latest HG tree, too?
> 
> Yes (at least with the latest hg tree that was accessible via hg-mirror a 
> few minutes ago).  I put a patch on the bug that does make things work. 
> Test case attached (adapted from flite mostly)

Thanks.  The addition of the two missing parameter constraints look
sane to me.  Now applied to HG tree.


Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-11-13 15:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-08 22:21 issues with pulse plugin Mike Gorse
2007-11-12  7:55 ` Takashi Iwai
2007-11-12 12:03   ` Mike Gorse
2007-11-13 11:34     ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).