[pulseaudio-commits] r2395 - in /branches/coling/raop_play/pulsified: Makefile Makefile.in audio_stream.c raop_play.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sat May 10 16:04:36 PDT 2008


Author: coling
Date: Sun May 11 01:04:35 2008
New Revision: 2395

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2395&root=pulseaudio&view=rev
Log:
Fix the example app to work with the updated code.
This really hacks up the mainloop controller and it does fail sometimes, but this is just to test things and it does that job ;)

Modified:
    branches/coling/raop_play/pulsified/Makefile
    branches/coling/raop_play/pulsified/Makefile.in
    branches/coling/raop_play/pulsified/audio_stream.c
    branches/coling/raop_play/pulsified/raop_play.c

Modified: branches/coling/raop_play/pulsified/Makefile
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/Makefile?rev=2395&root=pulseaudio&r1=2394&r2=2395&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/Makefile (original)
+++ branches/coling/raop_play/pulsified/Makefile Sun May 11 01:04:35 2008
@@ -22,7 +22,7 @@
 all: $(TARGET)
 
 raop_play: $(OBJS) $(LIBS)
-	$(CC) -o $@  -lssl -lsamplerate -lid3tag -lpthread $^ $(LIBS)
+	$(CC) -o $@  -lssl -lsamplerate -lid3tag -lpthread -lrt $^ $(LIBS)
 
 install:
 	$(mkinstalldirs) $(DESTDIR)$(bindir)/

Modified: branches/coling/raop_play/pulsified/Makefile.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/Makefile.in?rev=2395&root=pulseaudio&r1=2394&r2=2395&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/Makefile.in (original)
+++ branches/coling/raop_play/pulsified/Makefile.in Sun May 11 01:04:35 2008
@@ -22,7 +22,7 @@
 all: $(TARGET)
 
 raop_play: $(OBJS) $(LIBS)
-	$(CC) -o $@  -lssl -lsamplerate -lid3tag -lpthread $^ $(LIBS)
+	$(CC) -o $@  -lssl -lsamplerate -lid3tag -lpthread -lrt $^ $(LIBS)
 
 install:
 	$(mkinstalldirs) $(DESTDIR)$(bindir)/

Modified: branches/coling/raop_play/pulsified/audio_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/audio_stream.c?rev=2395&root=pulseaudio&r1=2394&r2=2395&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/audio_stream.c (original)
+++ branches/coling/raop_play/pulsified/audio_stream.c Sun May 11 01:04:35 2008
@@ -259,6 +259,70 @@
 {
   __u8 one[4];
   int count=0;
+  __u8 *bp=buffer;
+  int nodata=0;
+  __s16 *resamp=NULL, *pr=NULL;
+  int channels=2;
+  if(auds) channels=auds->channels;
+  if(auds && auds->sample_rate != DEFAULT_SAMPLE_RATE){
+    resamp=pcm_resample((__s16*)auds->resamp_buf, auds->resamp_st,
+            &auds->resamp_sd, ds, &bsize, channels);
+    if(!resamp) return -1;
+    pr=resamp;
+  }
+  while(1){
+    if(pr){
+      if(channels==1)
+        *((__s16*)one)=*pr;
+      else
+        *((__s16*)one)=*pr++;
+      *((__s16*)one+1)=*pr++;
+    }else {
+      switch(ds->type){
+      case DESCRIPTOR:
+        if(channels==1){
+          if(read(ds->u.fd, one, 2)!=2) nodata=1;
+          *((__s16*)one+1)=*((__s16*)one);
+        }else{
+          if(read(ds->u.fd, one, 4)!=4) nodata=1;
+        }
+        break;
+      case STREAM:
+        if(channels==1){
+          if(fread(one,1,2,ds->u.inf)!=2) nodata=1;
+          *((__s16*)one+1)=*((__s16*)one);
+        }else{
+          if(fread(one,1,4,ds->u.inf)!=4) nodata=1;
+        }
+        break;
+      case MEMORY:
+        if(channels==1){
+          if(ds->u.mem.size<=count*2) nodata=1;
+          *((__s16*)one)=ds->u.mem.data[count];
+          *((__s16*)one+1)=*((__s16*)one);
+        }else{
+          if(ds->u.mem.size<=count*4) nodata=1;
+          *((__s16*)one)=ds->u.mem.data[count*2];
+          *((__s16*)one+1)=ds->u.mem.data[count*2+1];
+        }
+        break;
+      }
+    }
+    if(nodata) break;
+    memcpy(bp, &one, 4);
+    bp+=4;
+    if(++count==bsize) break;
+  }
+  *size = count*4;
+  *data = buffer;
+  return 0;
+}
+
+int auds_write_pcmx(auds_t *auds, __u8 *buffer, __u8 **data, int *size,
+       int bsize, data_source_t *ds)
+{
+  __u8 one[4];
+  int count=0;
   __u8 bpos=0;
   __u8 *bp=buffer;
   int i,nodata=0;

Modified: branches/coling/raop_play/pulsified/raop_play.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/raop_play.c?rev=2395&root=pulseaudio&r1=2394&r2=2395&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/raop_play.c (original)
+++ branches/coling/raop_play/pulsified/raop_play.c Sun May 11 01:04:35 2008
@@ -27,6 +27,7 @@
 #include "../../airtunes/config.h"
 #include "pulsecore/macro.h"
 #include "pulsecore/thread.h"
+#include "pulsecore/core-util.h"
 #include "pulse/mainloop.h"
 #include "pulse/mainloop-signal.h"
 #include "modules/rtp/raop_client.h"
@@ -42,6 +43,10 @@
 
 typedef struct raopld_t{
   pa_raop_client *raopcl;
+  pa_mempool* pool;
+  pa_memchunk raw;
+  pa_memchunk encoded;
+  int fd;
   auds_t *auds;
   dfev_t fds[MAX_NUM_OF_FDS];
 }raopld_t;
@@ -57,13 +62,17 @@
   return -1;
 }
 
+static void noop(void *p){p=p;}
+
 #define MAIN_EVENT_TIMEOUT 3 // sec unit
 static int main_event_handler()
 {
   fd_set rdfds,wrfds;
   int fdmax=0;
   int i;
-  struct timeval tout={.tv_sec=MAIN_EVENT_TIMEOUT, .tv_usec=0};
+  struct timeval tout={.tv_sec=0, .tv_usec=5};
+  __u8* buf;
+  int size;
 
   FD_ZERO(&rdfds);
   FD_ZERO(&wrfds);
@@ -96,18 +105,60 @@
     }
   }
 
-  /*if(raopcl_wait_songdone(raopld->raopcl,0)){
-    raopcl_aexbuf_time(raopld->raopcl, &tout);
-    if(!tout.tv_sec && !tout.tv_usec){
-      // AEX data buffer becomes empty, it means end of playing a song.
-      printf("%s\n",RAOP_SONGDONE);
-      fflush(stdout);
-      raopcl_wait_songdone(raopld->raopcl,-1); // clear wait_songdone
-    }
-  }
-
-  raopcl_pause_check(raopld->raopcl);
-  */
+  if (raopld->fd > 0) {
+    /* Do we have encoded data to write? */
+    //printf("We have %d bytes\n", (int)raopld->encoded.length);
+    if (raopld->encoded.length > 0) {
+      int write_type = 0;
+      uint8_t *p;
+      int l;
+
+      p = pa_memblock_acquire(raopld->encoded.memblock);
+      l = pa_write(raopld->fd, p + raopld->encoded.index, raopld->encoded.length, &write_type);
+      pa_memblock_release(raopld->encoded.memblock);
+
+      if (l > 0) {
+        raopld->encoded.index += l;
+        raopld->encoded.length -= l;
+        //if (raopld->encoded.length > 0) printf("Couldn't write all our data... we'll get it next time.\n");
+        if (raopld->encoded.length <= 0) {
+          pa_memblock_unref(raopld->encoded.memblock);
+          pa_memchunk_reset(&raopld->encoded);
+        }
+      }
+    }
+
+    if (raopld->encoded.length <= 0) {
+      if (raopld->encoded.memblock)
+        pa_memblock_unref(raopld->encoded.memblock);
+      pa_memchunk_reset(&raopld->encoded);
+
+      /* We're hungry - feed me */
+      if (raopld->raw.length <= 0) {
+        if (raopld->raw.memblock)
+            pa_memblock_unref(raopld->raw.memblock);
+        pa_memchunk_reset(&raopld->raw);
+
+        if(!auds_poll_next_sample(raopld->auds)){
+          printf("Client Callback: No data\n");
+          // no next data, turn into pause status
+          /*raopcl_set_pause(raopld->raopcl,NODATA_PAUSE);*/
+          return -1;
+        }
+        if(auds_get_next_sample(raopld->auds, &buf, &size)){
+          auds_close(raopld->auds);
+          raopld->auds=NULL;
+          /*raopcl_wait_songdone(raopld->raopcl,1);*/
+          return -1;
+        }
+        raopld->raw.memblock = pa_memblock_new_user(raopld->pool, buf, size, noop, 1);
+        raopld->raw.length = size;
+      }
+      //printf("Encoding raw data\n");
+      raopld->encoded = pa_raop_client_encode_sample(raopld->raopcl, raopld->pool, &raopld->raw);
+      //printf("We now have %d bytes\n", (int)raopld->encoded.length);
+    }
+  }
 
   return 0;
 }
@@ -189,54 +240,10 @@
   return;
 }
 
-static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void *userdata) {
-    raopld_t *r = userdata;
-    __u8 *buf;
-    int size;
-
-    pa_assert(r == raopld);
-
-    printf("Client Callback\n");
-    if(!raopld->auds){
-      // if audio data is not opened, just check events
-      main_event_handler(raopld);
-    }
-    else
-    {
-      /*switch(raopcl_get_pause(raopld->raopcl)){
-      case OP_PAUSE:
-        rval=main_event_handler();
-        continue;
-      case NODATA_PAUSE:
-        if(auds_poll_next_sample(raopld->auds)){
-          raopcl_set_pause(raopld->raopcl,NO_PAUSE);
-        }else{
-          rval=main_event_handler();
-          continue;
-        }
-      case NO_PAUSE:*/
-        if(!auds_poll_next_sample(raopld->auds)){
-          printf("Client Callback: No data\n");
-          // no next data, turn into pause status
-          /*raopcl_set_pause(raopld->raopcl,NODATA_PAUSE);*/
-        } else {
-          if(auds_get_next_sample(raopld->auds, &buf, &size)){
-            auds_close(raopld->auds);
-            raopld->auds=NULL;
-            /*raopcl_wait_songdone(raopld->raopcl,1);*/
-          }
-          printf("Client Callback: Sending sample\n");
-          pa_raop_client_send_sample(raopld->raopcl, buf, size);
-            /*do{
-              if((rval=main_event_handler())) break;
-            }while(raopld->auds && raopcl_sample_remsize(raopld->raopcl));*/
-        }
-        /*break;
-      default:
-        rval=-1;
-        break;
-      }*/
-    }
+static void connection(int fd, void *userdata)
+{
+  printf("We're connected with fd: %d\n", fd);
+  raopld->fd = fd;
 }
 
 int main(int argc, char *argv[])
@@ -298,10 +305,9 @@
 #endif
 
 
-  raopld->raopcl = pa_raop_client_new();
+  raopld->raopcl = pa_raop_client_new(mainloop_api, host);
   if(!raopld->raopcl) goto erexit;
-  pa_raop_client_connect(raopld->raopcl, mainloop_api, host);
-  pa_raop_client_set_callback(raopld->raopcl, io_callback, raopld);
+  pa_raop_client_set_callback(raopld->raopcl, connection, raopld);
   /*if(raopcl_connect(mainloop, mainloop_api, raopld->raopcl,host,port)) goto erexit;
   if(raopcl_update_volume(raopld->raopcl,volume)) goto erexit;
   printf("%s\n",RAOP_CONNECTED);*/
@@ -309,9 +315,15 @@
   if(fname && !(raopld->auds=auds_open(fname,0))) goto erexit;
   set_fd_event(0,RAOP_FD_READ,console_read,NULL);
   rval=0;
+
+  raopld->pool = pa_mempool_new(0);
+  pa_memchunk_reset(&raopld->raw);
+  pa_memchunk_reset(&raopld->encoded);
+  raopld->fd = -1;
+
   while(!rval){
-    if(pa_mainloop_iterate(mainloop, 1, &ret) < 0) goto erexit;
-    printf("Looping\n");
+    if(pa_mainloop_iterate(mainloop, 0, &ret) < 0) goto erexit;
+    main_event_handler();
   }
   /*rval=raopcl_close(raopld->raopcl);*/
  erexit:




More information about the pulseaudio-commits mailing list