patch: simple recording with artsdsp

Simon Hausmann hausmann at kde.org
Fri Jan 24 12:53:53 GMT 2003


Hi,

the attached patch implements primitive recording capabilities with
artsdsp. It makes it possible to use Teamspeak with arts. I have not
tested recording capabilities with any other applications, which is
why I said 'primitive support' , it works perfect with ts though.

Please review.

Simon
-------------- next part --------------
Index: artsdsp.c
===================================================================
RCS file: /home/kde/arts/artsc/artsdsp.c,v
retrieving revision 1.34
diff -u -p -r1.34 artsdsp.c
--- artsdsp.c	8 Jun 2002 13:42:24 -0000	1.34
+++ artsdsp.c	24 Jan 2003 12:45:00 -0000
@@ -67,6 +67,10 @@ static int sndfd = -1;
 static int settings;
 static int arts_init_done = 0;
 static arts_stream_t stream = 0;
+static arts_stream_t record_stream = 0;
+static int bits = 0;
+static int speed = 0;
+static int channels = 0;
 static int frags;
 
 #if defined(HAVE_IOCTL_INT_INT_DOTS)
@@ -94,6 +98,7 @@ typedef int (*orig_open_ptr)(const char 
 typedef int (*orig_close_ptr)(int fd);
 typedef int (*orig_ioctl_ptr)(int fd, ioctl_request_t request, ...);
 typedef ssize_t (*orig_write_ptr)(int fd, const void *buf, size_t count);
+typedef ssize_t (*orig_read_ptr)(int fd, void *buf, size_t count);
 typedef void* (*orig_mmap_ptr)(void *start, size_t length, int prot,
                                  int flags, int fd, off_t offset);
 typedef int (*orig_munmap_ptr)(void *start, size_t length);
@@ -104,6 +109,7 @@ static orig_open_ptr orig_open;
 static orig_close_ptr orig_close;
 static orig_ioctl_ptr orig_ioctl;
 static orig_write_ptr orig_write;
+static orig_read_ptr orig_read;
 static orig_mmap_ptr orig_mmap;
 static orig_munmap_ptr orig_munmap;
 static orig_fopen_ptr orig_fopen;
@@ -142,6 +148,7 @@ static void artsdsp_doinit()
 	orig_open = (orig_open_ptr)dlsym(RTLD_NEXT,"open");
 	orig_close = (orig_close_ptr)dlsym(RTLD_NEXT,"close");
 	orig_write = (orig_write_ptr)dlsym(RTLD_NEXT,"write");
+	orig_read = (orig_read_ptr)dlsym(RTLD_NEXT,"read");
 	orig_ioctl = (orig_ioctl_ptr)dlsym(RTLD_NEXT,"ioctl");
 	orig_mmap = (orig_mmap_ptr)dlsym(RTLD_NEXT,"mmap");
 	orig_munmap = (orig_munmap_ptr)dlsym(RTLD_NEXT,"munmap");
@@ -209,6 +216,7 @@ int open (const char *pathname, int flag
   settings = 0;
   frags = 0;
   stream = 0;
+  record_stream = 0;
 
   artsdspdebug ("aRts: hijacking /dev/dsp open...\n");
 
@@ -233,9 +241,6 @@ int open (const char *pathname, int flag
 
 int ioctl (int fd, ioctl_request_t request, ...)
 {
-  static int channels;
-  static int bits;
-  static int speed;
   int space, size, latency, odelay;
 
   /*
@@ -385,9 +390,9 @@ int ioctl (int fd, ioctl_request_t reque
 #ifdef SNDCTL_DSP_GETCAPS
         case SNDCTL_DSP_GETCAPS:			/* _SIOR ('P',15, int) */
 		  if(mmapemu)
-			*arg = DSP_CAP_MMAP | DSP_CAP_TRIGGER | DSP_CAP_REALTIME;
+			*arg = DSP_CAP_MMAP | DSP_CAP_TRIGGER | DSP_CAP_REALTIME | DSP_CAP_DUPLEX;
 		  else
-            *arg = 0;
+			*arg = DSP_CAP_DUPLEX;
           break;
 #endif
 
@@ -518,6 +523,11 @@ int close(int fd)
         arts_close_stream(stream);
         stream = 0;
       }
+      if (record_stream)
+      {
+          arts_close_stream(record_stream);
+          record_stream = 0;
+      }
 	  if(mmapemu && mmapemu_obuffer)
 	  {
 		free(mmapemu_obuffer);
@@ -563,6 +573,21 @@ ssize_t write (int fd, const void *buf, 
     }
   }
   return 0;
+}
+
+ssize_t read (int fd, void *buf, size_t count)
+{
+  CHECK_INIT();
+
+  if (fd != sndfd)
+    return orig_read(fd,buf,count);
+  else if (sndfd == -1)
+    return 0;
+
+  if (!record_stream)
+    record_stream = arts_record_stream(speed, bits, channels, "artsdsp");
+  artsdspdebug ( "aRts: /dev/dsp read...\n" );
+  return arts_read(record_stream, buf, count);
 }
 
 void *mmap(void  *start,  size_t length, int prot, int flags,


More information about the kde-multimedia mailing list