[pulseaudio-commits] r2375 - in /branches/coling/raop_play/pulsified: Makefile Makefile.in audio_stream.c audio_stream.h raop_client.c raop_client.h raop_play.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Tue May 6 18:14:32 PDT 2008
Author: coling
Date: Wed May 7 03:14:31 2008
New Revision: 2375
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2375&root=pulseaudio&view=rev
Log:
Very hacked version of the command line utility that confirms the asynchronous code in pulse is working :)
Removed:
branches/coling/raop_play/pulsified/raop_client.c
branches/coling/raop_play/pulsified/raop_client.h
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/audio_stream.h
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=2375&root=pulseaudio&r1=2374&r2=2375&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/Makefile (original)
+++ branches/coling/raop_play/pulsified/Makefile Wed May 7 03:14:31 2008
@@ -14,10 +14,10 @@
PULSEDIR = ../../airtunes
CFLAGS=-Wall -I$(PULSEDIR)/src
-OBJS := raop_play.o raop_client.o aexcl_lib.o m4a_stream.o \
+OBJS := raop_play.o aexcl_lib.o m4a_stream.o \
audio_stream.o wav_stream.o mp3_stream.o flac_stream.o ogg_stream.o aac_stream.o pls_stream.o \
pcm_stream.o flac_stream.o
-LIBS=$(PULSEDIR)/src/.libs/libpulse.a $(PULSEDIR)/src/.libs/libpulsecore.a $(PULSEDIR)/src/.libs/librtp.a $(PULSEDIR)/src/.libs/libsocket-util.a
+LIBS=$(PULSEDIR)/src/.libs/libpulse.a $(PULSEDIR)/src/.libs/libpulsecore.a $(PULSEDIR)/src/.libs/librtp.a $(PULSEDIR)/src/.libs/libsocket-util.a $(PULSEDIR)/src/.libs/libioline.a
all: $(TARGET)
@@ -39,10 +39,9 @@
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
-COMMONE_HEADERS := aexcl_lib.h raop_play.h raop_client.h m4a_stream.h \
+COMMONE_HEADERS := aexcl_lib.h raop_play.h m4a_stream.h \
pls_stream.h
aexcl_lib.o: $(COMMONE_HEADERS)
raop_play.o: $(COMMONE_HEADERS)
-raop_client.o: $(COMMONE_HEADERS)
m4a_stream.o: $(COMMONE_HEADERS)
Modified: branches/coling/raop_play/pulsified/Makefile.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/Makefile.in?rev=2375&root=pulseaudio&r1=2374&r2=2375&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/Makefile.in (original)
+++ branches/coling/raop_play/pulsified/Makefile.in Wed May 7 03:14:31 2008
@@ -14,10 +14,10 @@
PULSEDIR = ../../airtunes
CFLAGS=-Wall -I$(PULSEDIR)/src
-OBJS := raop_play.o raop_client.o aexcl_lib.o m4a_stream.o \
+OBJS := raop_play.o aexcl_lib.o m4a_stream.o \
audio_stream.o wav_stream.o mp3_stream.o flac_stream.o ogg_stream.o aac_stream.o pls_stream.o \
pcm_stream.o flac_stream.o
-LIBS=$(PULSEDIR)/src/.libs/libpulse.a $(PULSEDIR)/src/.libs/libpulsecore.a $(PULSEDIR)/src/.libs/librtp.a $(PULSEDIR)/src/.libs/libsocket-util.a
+LIBS=$(PULSEDIR)/src/.libs/libpulse.a $(PULSEDIR)/src/.libs/libpulsecore.a $(PULSEDIR)/src/.libs/librtp.a $(PULSEDIR)/src/.libs/libsocket-util.a $(PULSEDIR)/src/.libs/libioline.a
all: $(TARGET)
@@ -39,10 +39,9 @@
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
-COMMONE_HEADERS := aexcl_lib.h raop_play.h raop_client.h m4a_stream.h \
+COMMONE_HEADERS := aexcl_lib.h raop_play.h m4a_stream.h \
pls_stream.h
aexcl_lib.o: $(COMMONE_HEADERS)
raop_play.o: $(COMMONE_HEADERS)
-raop_client.o: $(COMMONE_HEADERS)
m4a_stream.o: $(COMMONE_HEADERS)
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=2375&root=pulseaudio&r1=2374&r2=2375&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/audio_stream.c (original)
+++ branches/coling/raop_play/pulsified/audio_stream.c Wed May 7 03:14:31 2008
@@ -259,7 +259,7 @@
{
__u8 one[4];
int count=0;
- int bpos=0;
+ __u8 bpos=0;
__u8 *bp=buffer;
int i,nodata=0;
__s16 *resamp=NULL, *pr=NULL;
@@ -271,21 +271,22 @@
if(!resamp) return -1;
pr=resamp;
}
- bits_write(&bp,1,3,&bpos); // channel=1, stereo
- bits_write(&bp,0,4,&bpos); // unknown
- bits_write(&bp,0,8,&bpos); // unknown
- bits_write(&bp,0,4,&bpos); // unknown
+ *size = 0;
+ bit_writer(&bp,&bpos,size,1,3); // channel=1, stereo
+ bit_writer(&bp,&bpos,size,0,4); // unknown
+ bit_writer(&bp,&bpos,size,0,8); // unknown
+ bit_writer(&bp,&bpos,size,0,4); // unknown
if(bsize!=4096)
- bits_write(&bp,1,1,&bpos); // hassize
+ bit_writer(&bp,&bpos,size,1,1); // hassize
else
- bits_write(&bp,0,1,&bpos); // hassize
- bits_write(&bp,0,2,&bpos); // unused
- bits_write(&bp,1,1,&bpos); // is-not-compressed
+ bit_writer(&bp,&bpos,size,0,1); // hassize
+ bit_writer(&bp,&bpos,size,0,2); // unused
+ bit_writer(&bp,&bpos,size,1,1); // is-not-compressed
if(bsize!=4096){
- bits_write(&bp,(bsize>>24)&0xff,8,&bpos); // size of data, integer, big endian
- bits_write(&bp,(bsize>>16)&0xff,8,&bpos);
- bits_write(&bp,(bsize>>8)&0xff,8,&bpos);
- bits_write(&bp,bsize&0xff,8,&bpos);
+ bit_writer(&bp,&bpos,size,(bsize>>24)&0xff,8); // size of data, integer, big endian
+ bit_writer(&bp,&bpos,size,(bsize>>16)&0xff,8);
+ bit_writer(&bp,&bpos,size,(bsize>>8)&0xff,8);
+ bit_writer(&bp,&bpos,size,bsize&0xff,8);
}
while(1){
if(pr){
@@ -327,19 +328,17 @@
}
if(nodata) break;
- bits_write(&bp,one[1],8,&bpos);
- bits_write(&bp,one[0],8,&bpos);
- bits_write(&bp,one[3],8,&bpos);
- bits_write(&bp,one[2],8,&bpos);
+ bit_writer(&bp,&bpos,size,one[1],8);
+ bit_writer(&bp,&bpos,size,one[0],8);
+ bit_writer(&bp,&bpos,size,one[3],8);
+ bit_writer(&bp,&bpos,size,one[2],8);
if(++count==bsize) break;
}
if(!count) return -1; // when no data at all, it should stop playing
/* when readable size is less than bsize, fill 0 at the bottom */
for(i=0;i<(bsize-count)*4;i++){
- bits_write(&bp,0,8,&bpos);
- }
- *size=bp-buffer;
- if(bpos) *size+=1;
+ bit_writer(&bp,&bpos,size,0,8);
+ }
*data=buffer;
return 0;
}
Modified: branches/coling/raop_play/pulsified/audio_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/pulsified/audio_stream.h?rev=2375&root=pulseaudio&r1=2374&r2=2375&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/audio_stream.h (original)
+++ branches/coling/raop_play/pulsified/audio_stream.h Wed May 7 03:14:31 2008
@@ -94,28 +94,49 @@
int auds_poll_next_sample(auds_t *auds);
-/* write bits filed data, *bpos=0 for msb, *bpos=7 for lsb
- d=data, blen=length of bits field
- */
-static inline void bits_write(__u8 **p, __u8 d, int blen, int *bpos)
-{
- int lb,rb,bd;
- lb=7-*bpos;
- rb=lb-blen+1;
- if(rb>=0){
- bd=d<<rb;
- if(*bpos)
- **p|=bd;
- else
- **p=bd;
- *bpos+=blen;
- }else{
- bd=d>>-rb;
- **p|=bd;
- *p+=1;
- **p=d<<(8+rb);
- *bpos=-rb;
- }
+typedef __u8 uint8_t;
+static inline void bit_writer(uint8_t **buffer, uint8_t *bit_pos, int *size, uint8_t data, uint8_t data_bit_len) {
+ int bits_left, bit_overflow;
+ uint8_t bit_data;
+
+ if (!data_bit_len)
+ return;
+
+ /* If bit pos is zero, we will definatly use at least one bit from the current byte so size increments. */
+ if (!*bit_pos)
+ *size = 1;
+
+ /* Calc the number of bits left in the current byte of buffer */
+ bits_left = 7 - *bit_pos + 1;
+ /* Calc the overflow of bits in relation to how much space we have left... */
+ bit_overflow = bits_left - data_bit_len;
+ if (bit_overflow >= 0) {
+ /* We can fit the new data in our current byte */
+ /* As we write from MSB->LSB we need to left shift by the overflow amount */
+ bit_data = data << bit_overflow;
+ if (*bit_pos)
+ **buffer |= bit_data;
+ else
+ **buffer = bit_data;
+ /* If our data fits exactly into the current byte, we need to increment our pointer */
+ if (0 == bit_overflow) {
+ /* Do not increment size as it will be incremeneted on next call as bit_pos is zero */
+ *buffer += 1;
+ *bit_pos = 0;
+ } else {
+ *bit_pos += data_bit_len;
+ }
+ } else {
+ /* bit_overflow is negative, there for we will need a new byte from our buffer */
+ /* Firstly fill up what's left in the current byte */
+ bit_data = data >> -bit_overflow;
+ **buffer |= bit_data;
+ /* Increment our buffer pointer and size counter*/
+ *buffer += 1;
+ *size += 1;
+ **buffer = data << (8 + bit_overflow);
+ *bit_pos = -bit_overflow;
+ }
}
#endif
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=2375&root=pulseaudio&r1=2374&r2=2375&view=diff
==============================================================================
--- branches/coling/raop_play/pulsified/raop_play.c (original)
+++ branches/coling/raop_play/pulsified/raop_play.c Wed May 7 03:14:31 2008
@@ -21,15 +21,15 @@
#include <stdio.h>
#include <signal.h>
#include "aexcl_lib.h"
-#include "raop_client.h"
#include "audio_stream.h"
#include "raop_play.h"
#include "../../airtunes/config.h"
-#include <pulsecore/macro.h>
-#include <pulsecore/thread.h>
-#include <pulse/mainloop.h>
-#include <pulse/mainloop-signal.h>
+#include "pulsecore/macro.h"
+#include "pulsecore/thread.h"
+#include "pulse/mainloop.h"
+#include "pulse/mainloop-signal.h"
+#include "modules/rtp/raop_client.h"
#define SERVER_PORT 5000
#define MAX_NUM_OF_FDS 4
@@ -41,7 +41,7 @@
}dfev_t;
typedef struct raopld_t{
- raopcl_t *raopcl;
+ pa_raop_client *raopcl;
auds_t *auds;
dfev_t fds[MAX_NUM_OF_FDS];
}raopld_t;
@@ -75,8 +75,8 @@
FD_SET(raopld->fds[i].fd, &wrfds);
fdmax=(fdmax<raopld->fds[i].fd)?raopld->fds[i].fd:fdmax;
}
- if(raopcl_wait_songdone(raopld->raopcl,0))
- raopcl_aexbuf_time(raopld->raopcl, &tout);
+ /*if(raopcl_wait_songdone(raopld->raopcl,0))
+ raopcl_aexbuf_time(raopld->raopcl, &tout);*/
select(fdmax+1,&rdfds,&wrfds,NULL,&tout);
@@ -96,7 +96,7 @@
}
}
- if(raopcl_wait_songdone(raopld->raopcl,0)){
+ /*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.
@@ -107,6 +107,7 @@
}
raopcl_pause_check(raopld->raopcl);
+ */
return 0;
}
@@ -117,10 +118,10 @@
char *ps=NULL;
if(strstr(cstr,"play")==cstr){
- if(raopcl_get_pause(raopld->raopcl)) {
+ /*if(raopcl_get_pause(raopld->raopcl)) {
raopcl_set_pause(raopld->raopcl,NO_PAUSE);
return 0;
- }
+ }*/
for(i=0;i<strlen(cstr);i++) {
if(cstr[i]==' ') {
ps=cstr+i+1;
@@ -134,25 +135,25 @@
fflush(stdout);
return -1;
}
- raopcl_flush_stream(raopld->raopcl);
+ /*raopcl_flush_stream(raopld->raopcl);*/
return 0;
}else if(!strcmp(cstr,"pause")){
- if(raopcl_wait_songdone(raopld->raopcl,0)){
+ /*if(raopcl_wait_songdone(raopld->raopcl,0)){
INFMSG("in this period, pause can't work\n");
return -2;
}
if(raopld->auds) {
raopcl_set_pause(raopld->raopcl,OP_PAUSE);
- }
+ }*/
}else if(!strcmp(cstr,"stop")){
- if(raopcl_get_pause(raopld->raopcl)) raopcl_set_pause(raopld->raopcl,NO_PAUSE);
+ /*if(raopcl_get_pause(raopld->raopcl)) raopcl_set_pause(raopld->raopcl,NO_PAUSE);*/
if(raopld->auds) auds_close(raopld->auds);
raopld->auds=NULL;
}else if(!strcmp(cstr,"quit")){
return -2;
}else if((ps=strstr(cstr,"volume"))){
i=atoi(ps+7);
- return raopcl_update_volume(raopld->raopcl,i);
+ /*return raopcl_update_volume(raopld->raopcl,i);*/
}
return -1;
}
@@ -188,21 +189,69 @@
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;
+ }*/
+ }
+}
+
int main(int argc, char *argv[])
{
char *host=NULL;
char *fname=NULL;
int port=SERVER_PORT;
int rval=-1,i;
- int size;
int volume=100;
- __u8 *buf;
int iact=0;
struct sigaction act;
pa_mainloop* mainloop;
int ret = 1;
-
+ pa_log_set_maximal_level(PA_LOG_DEBUG);
/* Assign sig_term as our SIGTERM handler */
act.sa_sigaction = sig_action;
sigemptyset(&act.sa_mask); // no other signals are blocked
@@ -248,55 +297,23 @@
signal(SIGPIPE, SIG_IGN);
#endif
- raopld->raopcl=raopcl_open();
+
+ raopld->raopcl = pa_raop_client_new();
if(!raopld->raopcl) goto erexit;
- if(raopcl_connect(mainloop, mainloop_api, raopld->raopcl,host,port)) goto erexit;
+ pa_raop_client_connect(raopld->raopcl, mainloop_api, host);
+ pa_raop_client_set_callback(raopld->raopcl, io_callback, 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);
+ printf("%s\n",RAOP_CONNECTED);*/
fflush(stdout);
if(fname && !(raopld->auds=auds_open(fname,0))) goto erexit;
set_fd_event(0,RAOP_FD_READ,console_read,NULL);
rval=0;
while(!rval){
- if(pa_mainloop_iterate(mainloop, 0, &ret) < 0) goto erexit;
- if(!raopld->auds){
- // if audio data is not opened, just check events
- rval=main_event_handler(raopld);
- continue;
- }
- 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)){
- // no next data, turn into pause status
- raopcl_set_pause(raopld->raopcl,NODATA_PAUSE);
- continue;
- }
- if(auds_get_next_sample(raopld->auds, &buf, &size)){
- auds_close(raopld->auds);
- raopld->auds=NULL;
- raopcl_wait_songdone(raopld->raopcl,1);
- }
- if(raopcl_send_sample(raopld->raopcl,buf,size)) break;
- do{
- if((rval=main_event_handler())) break;
- }while(raopld->auds && raopcl_sample_remsize(raopld->raopcl));
- break;
- default:
- rval=-1;
- break;
- }
- }
- rval=raopcl_close(raopld->raopcl);
+ if(pa_mainloop_iterate(mainloop, 1, &ret) < 0) goto erexit;
+ printf("Looping\n");
+ }
+ /*rval=raopcl_close(raopld->raopcl);*/
erexit:
if (mainloop) {
pa_signal_done();
More information about the pulseaudio-commits
mailing list