All of lore.kernel.org
 help / color / mirror / Atom feed
* reopen with "plug:dmix" failure
@ 2003-07-15 10:09 Konstantin Stepaniuk
  2003-07-15 19:15 ` Jaroslav Kysela
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Stepaniuk @ 2003-07-15 10:09 UTC (permalink / raw)
  To: alsa-devel

Dear Jaroslav Kysela.

I wrote some example which illustrates problem described in previous message. 
Also I want you to make some fixes in your library which can avoid this 
problem. First of all I discommented lines 325-326 in file pcm_direct.c 
(because even after application stopped server still process and device 
/dev/snd/pcmC0D0p locked). After that I added one line, which unlink 
temporary file /tmp/alsa-dmix*.

//----------- example ------------------------------
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *thread_routine( void *param ) {
  snd_pcm_t *pcm;
  int err;

  printf( "%d: start\n", getpid() );

  err = snd_pcm_open( &pcm,
		      "plug:dmix",
		      SND_PCM_STREAM_PLAYBACK,
		      SND_PCM_NONBLOCK );

  if( err < 0 ) {
    fprintf( stderr, "%s\n", snd_strerror(err) );
    return NULL;
  }

  snd_pcm_close( pcm );

  printf( "%d: finish\n", getpid() );
  return NULL;
}

int main( void ) {
  pthread_t thread;
  int i =0;

  printf( "main pid: %d\n", getpid() );

  for( i=0; i<2; ++i ) {
    if( pthread_create( &thread, 0, thread_routine, NULL ) ) {
      fprintf( stderr, "pthread_create failure\n" );
      exit( -1 );
    }
    pthread_join( thread, 0 );
  }

  return 0;
}

//----------- patch ------------------------------

--- pcm_direct.c.orig	2003-07-15 13:48:56.000000000 +0400
+++ pcm_direct.c	2003-07-15 13:50:37.000000000 +0400
@@ -322,13 +322,14 @@
 int snd_pcm_direct_server_discard(snd_pcm_direct_t *dmix)
 {
 	if (dmix->server) {
-		//kill(dmix->server_pid, SIGTERM);
-		//waitpid(dmix->server_pid, NULL, 0);
+		kill(dmix->server_pid, SIGTERM);
+		waitpid(dmix->server_pid, NULL, 0);
 		dmix->server_pid = (pid_t)-1;
 	}
 	if (dmix->server_fd > 0) {
 		close(dmix->server_fd);
 		dmix->server_fd = -1;
+    unlink( dmix->shmptr->socket_name );
 	}
 	dmix->server = 0;
 	return 0;

-- 
Cheers, Konstantin Stepaniuk



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1

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

* Re: reopen with "plug:dmix" failure
  2003-07-15 10:09 reopen with "plug:dmix" failure Konstantin Stepaniuk
@ 2003-07-15 19:15 ` Jaroslav Kysela
  0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Kysela @ 2003-07-15 19:15 UTC (permalink / raw)
  To: Konstantin Stepaniuk; +Cc: alsa-devel

On Tue, 15 Jul 2003, Konstantin Stepaniuk wrote:

> Dear Jaroslav Kysela.
> 
> I wrote some example which illustrates problem described in previous message. 
> Also I want you to make some fixes in your library which can avoid this 
> problem. First of all I discommented lines 325-326 in file pcm_direct.c 
> (because even after application stopped server still process and device 
> /dev/snd/pcmC0D0p locked). After that I added one line, which unlink 
> temporary file /tmp/alsa-dmix*.

Your fixes does not solve the real problem and causes another deadlock.

I have tried to solve the problem. Could you try the current CVS code?

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs




-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1

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

* reopen with "plug:dmix" failure
@ 2003-07-10  8:39 Konstantin Stepaniuk
  0 siblings, 0 replies; 3+ messages in thread
From: Konstantin Stepaniuk @ 2003-07-10  8:39 UTC (permalink / raw)
  To: alsa-devel

My application should play some tracks simultaneously and work in a common 
system in which sound card is not supplying hardware mixing. Tracks may have 
different bitrate and channels count. So I'm opening alsa handle for the each 
track by calling function snd_pcm_open( &pcm, "plug:dmix", 
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );

After closing last alsa handle (snd_pcm_close) and trying to open the new one, 
it's failed with error:

ALSA lib pcm_hw.c:1055snd_pcm_hw_open) open /dev/snd/pcmC0D0p failed: Device 
or resource busy
ALSA lib pcm_dmix.c:948snd_pcm_dmix_open) unable to open slave

How can I solve this problem?



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps

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

end of thread, other threads:[~2003-07-15 19:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15 10:09 reopen with "plug:dmix" failure Konstantin Stepaniuk
2003-07-15 19:15 ` Jaroslav Kysela
  -- strict thread matches above, loose matches on Subject: below --
2003-07-10  8:39 Konstantin Stepaniuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.