[vorbis-dev] ogg123: close_dsp_on_suspend and next_on_SIGUSR1 patches submission

Guillaume Cottenceau gc at mandrakesoft.com
Tue Jan 2 05:20:40 PST 2001



Hi,

A developper of MandrakeSoft needed for some reason to ameliorate ogg123
in a way: with the patch when you issue a Ctrl+Z (suspending the app) the
dsp is freed. Ofcourse the app can still continue when SIGCONT is
received.

Apparently he chose to separate the actual code into more functions.

Please note that this code uses local functions, it thus needs gcc to
compile.

-=-=--

--- vorbis-tools-1.0beta3/ogg123/ogg123.c.pix	Thu Dec 28 17:46:53 2000
+++ vorbis-tools-1.0beta3/ogg123/ogg123.c	Fri Dec 29 07:55:25 2000
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
 #include <sys/socket.h> /* !!! */
 #include <sys/types.h>
 #include <unistd.h>
@@ -198,6 +199,57 @@
         return -1;
 }
 
+void
+open_devices(void)
+{
+  int bits, rate, channels;
+  devices *current;
+
+  /* Open all of the devices */
+  bits = 16;
+  rate = 44100;
+  channels = 2;
+  current = param.outdevices;
+
+  if (param.quiet < 1)
+	  fprintf(stderr, "Opening devices...\n");
+
+  while (current != NULL) {
+    ao_info_t *info = ao_get_driver_info(current->driver_id);
+
+    if (param.quiet < 1) {
+    	fprintf(stderr, "Device:   %s\n", info->name);
+    	fprintf(stderr, "Author:   %s\n", info->author);
+    	fprintf(stderr, "Comments: %s\n", info->comment);
+    }
+    
+    current->device = ao_open(current->driver_id,bits,rate,channels,
+			     current->options);
+    if (current->device == NULL)
+      {
+	fprintf(stderr, "Error opening device.\n");
+	exit(1);
+      }
+    if (param.quiet < 1)
+    	fprintf(stderr, "\n"); // Gotta keep 'em separated ...
+ 
+    current = current->next_device;
+  }
+}
+
+void close_devices(void)
+{
+  devices *current;
+
+  current = param.outdevices;
+
+  while(current != NULL)
+  {
+	  ao_close(current->device);
+	  current = current->next_device;
+  }
+}
+
 int
 main (int argc, char **argv)
 {
@@ -207,8 +259,6 @@
   int option_index = 1;
   ao_option_t *temp_options = NULL;
   int temp_driver_id = -1;
-  devices *current;
-  int bits, rate, channels;
 
   ao_initialize();
 
@@ -291,37 +341,22 @@
       exit (1);
     }
 
-  /* Open all of the devices */
-  bits = 16;
-  rate = 44100;
-  channels = 2;
-  current = param.outdevices;
-
-  if (param.quiet < 1)
-	  fprintf(stderr, "Opening devices...\n");
-
-  while (current != NULL) {
-    ao_info_t *info = ao_get_driver_info(current->driver_id);
-
-    if (param.quiet < 1) {
-    	fprintf(stderr, "Device:   %s\n", info->name);
-    	fprintf(stderr, "Author:   %s\n", info->author);
-    	fprintf(stderr, "Comments: %s\n", info->comment);
+  {
+    void stop(int i) { 
+      close_devices(); 
+      signal(SIGTSTP, SIG_DFL);
+      kill(getpid(), SIGTSTP);
     }
-    
-    current->device = ao_open(current->driver_id,bits,rate,channels,
-			     current->options);
-    if (current->device == NULL)
-      {
-	fprintf(stderr, "Error opening device.\n");
-	exit(1);
-      }
-    if (param.quiet < 1)
-    	fprintf(stderr, "\n"); // Gotta keep 'em separated ...
- 
-    current = current->next_device;
+    void cont(int i) {
+      signal(SIGTSTP, stop);
+      open_devices();
+    }
+    signal(SIGTSTP, stop);
+    signal(SIGCONT, cont);
   }
 
+  open_devices();
+
   if (param.shuffle)
     {
       int i;
@@ -351,13 +386,7 @@
         }
     }
 
-  current = param.outdevices;
-
-  while(current != NULL)
-  {
-	  ao_close(current->device);
-	  current = current->next_device;
-  }
+  close_devices();
 
   ao_shutdown();
 

-=-=--

After that he missed the facility of asking for next song. He added it
with the signal mechanism, using SIGUSR1. Here it is. Same limitations
with local functions.

-=-=--

--- vorbis-tools-1.0beta3/ogg123/ogg123.c.pix	Sat Dec 30 09:46:40 2000
+++ vorbis-tools-1.0beta3/ogg123/ogg123.c	Sat Dec 30 09:50:38 2000
@@ -502,6 +502,10 @@
         /* Throw the comments plus a few lines about the bitstream we're
         ** decoding */
 
+	{
+	  void next(int i) { eof = eos = 1; }
+	  signal(SIGUSR1, next);
+	}
         while (!eof) {
                 int i;
                 vorbis_comment *vc = ov_comment(&vf, -1);
@@ -581,6 +585,7 @@
                         }
                 }
         }
+	signal(SIGUSR1, SIG_DFL);
 
         ov_clear(&vf);
       

-=-=--


-- 
Guillaume Cottenceau - http://us.mandrakesoft.com/~gc/

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Vorbis-dev mailing list