[pulseaudio-commits] r2337 - /branches/coling/raop_play/orig/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 1 17:16:11 PDT 2008


Author: coling
Date: Fri May  2 02:16:10 2008
New Revision: 2337

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2337&root=pulseaudio&view=rev
Log:
Copy of upstream raop_play for reference

Added:
    branches/coling/raop_play/orig/
    branches/coling/raop_play/orig/.cvsignore
    branches/coling/raop_play/orig/Makefile   (with props)
    branches/coling/raop_play/orig/Makefile.in   (with props)
    branches/coling/raop_play/orig/README   (with props)
    branches/coling/raop_play/orig/aac_stream.c   (with props)
    branches/coling/raop_play/orig/aac_stream.h   (with props)
    branches/coling/raop_play/orig/aes.c   (with props)
    branches/coling/raop_play/orig/aes.h   (with props)
    branches/coling/raop_play/orig/aexcl_lib.c   (with props)
    branches/coling/raop_play/orig/aexcl_lib.h   (with props)
    branches/coling/raop_play/orig/alsadev.pls
    branches/coling/raop_play/orig/audio_stream.c   (with props)
    branches/coling/raop_play/orig/audio_stream.h   (with props)
    branches/coling/raop_play/orig/base64.c   (with props)
    branches/coling/raop_play/orig/base64.h   (with props)
    branches/coling/raop_play/orig/flac_stream.c   (with props)
    branches/coling/raop_play/orig/flac_stream.h   (with props)
    branches/coling/raop_play/orig/m4a_stream.c   (with props)
    branches/coling/raop_play/orig/m4a_stream.h   (with props)
    branches/coling/raop_play/orig/mp3_stream.c   (with props)
    branches/coling/raop_play/orig/mp3_stream.h   (with props)
    branches/coling/raop_play/orig/ogg_stream.c   (with props)
    branches/coling/raop_play/orig/ogg_stream.h   (with props)
    branches/coling/raop_play/orig/pcm_stream.c   (with props)
    branches/coling/raop_play/orig/pcm_stream.h   (with props)
    branches/coling/raop_play/orig/pls_stream.c   (with props)
    branches/coling/raop_play/orig/pls_stream.h   (with props)
    branches/coling/raop_play/orig/raop_client.c   (with props)
    branches/coling/raop_play/orig/raop_client.h   (with props)
    branches/coling/raop_play/orig/raop_play.c   (with props)
    branches/coling/raop_play/orig/raop_play.h   (with props)
    branches/coling/raop_play/orig/rtsp_client.c   (with props)
    branches/coling/raop_play/orig/rtsp_client.h   (with props)
    branches/coling/raop_play/orig/wav_stream.c   (with props)
    branches/coling/raop_play/orig/wav_stream.h   (with props)

Added: branches/coling/raop_play/orig/.cvsignore
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/.cvsignore?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/.cvsignore (added)
+++ branches/coling/raop_play/orig/.cvsignore Fri May  2 02:16:10 2008
@@ -1,0 +1,2 @@
+Makefile
+raop_play

Added: branches/coling/raop_play/orig/Makefile
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/Makefile?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/Makefile (added)
+++ branches/coling/raop_play/orig/Makefile Fri May  2 02:16:10 2008
@@ -1,0 +1,47 @@
+SHELL = /bin/sh
+CC = gcc
+DEFS = -DHAVE_CONFIG_H
+LIBS = -lid3tag -lfltk -lsamplerate -lssl  -lz
+prefix = /usr/local
+exec_prefix = ${prefix}
+bindir = ${exec_prefix}/bin
+INSTALL = install
+top_srcdir = ..
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+
+TARGET=raop_play
+DESTDIR =
+
+CFLAGS=-Wall
+OBJS := raop_play.o raop_client.o rtsp_client.o aexcl_lib.o base64.o aes.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
+
+all: $(TARGET)
+
+raop_play: $(OBJS)
+	$(CC) -o $@  -lssl -lsamplerate -lid3tag $^
+
+install:
+	$(mkinstalldirs) $(DESTDIR)$(bindir)/
+	$(INSTALL) -s $(TARGET) $(DESTDIR)$(bindir)
+
+uninstall:
+	rm -f $(DESTDIR)$(bindir)/$(TARGET)
+
+clean:
+	rm -f *.o $(TARGET)
+
+distclean:
+
+%.o : %.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
+COMMONE_HEADERS := aexcl_lib.h raop_play.h raop_client.h rtsp_client.h m4a_stream.h \
+pls_stream.h
+
+aexcl_lib.o: $(COMMONE_HEADERS)
+raop_play.o: $(COMMONE_HEADERS)
+raop_client.o: $(COMMONE_HEADERS)
+rtsp_client.o: $(COMMONE_HEADERS)
+m4a_stream.o: $(COMMONE_HEADERS)

Propchange: branches/coling/raop_play/orig/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/coling/raop_play/orig/Makefile
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/coling/raop_play/orig/Makefile.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/Makefile.in?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/Makefile.in (added)
+++ branches/coling/raop_play/orig/Makefile.in Fri May  2 02:16:10 2008
@@ -1,0 +1,47 @@
+SHELL = @SHELL@
+CC = @CC@
+DEFS = @DEFS@
+LIBS = @LIBS@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+INSTALL = @INSTALL@
+top_srcdir = @top_srcdir@
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+
+TARGET=raop_play
+DESTDIR =
+
+CFLAGS=-Wall
+OBJS := raop_play.o raop_client.o rtsp_client.o aexcl_lib.o base64.o aes.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
+
+all: $(TARGET)
+
+raop_play: $(OBJS)
+	$(CC) -o $@  -lssl -lsamplerate -lid3tag $^
+
+install:
+	$(mkinstalldirs) $(DESTDIR)$(bindir)/
+	$(INSTALL) -s $(TARGET) $(DESTDIR)$(bindir)
+
+uninstall:
+	rm -f $(DESTDIR)$(bindir)/$(TARGET)
+
+clean:
+	rm -f *.o $(TARGET)
+
+distclean:
+
+%.o : %.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
+COMMONE_HEADERS := aexcl_lib.h raop_play.h raop_client.h rtsp_client.h m4a_stream.h \
+pls_stream.h
+
+aexcl_lib.o: $(COMMONE_HEADERS)
+raop_play.o: $(COMMONE_HEADERS)
+raop_client.o: $(COMMONE_HEADERS)
+rtsp_client.o: $(COMMONE_HEADERS)
+m4a_stream.o: $(COMMONE_HEADERS)

Propchange: branches/coling/raop_play/orig/Makefile.in
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/coling/raop_play/orig/Makefile.in
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/coling/raop_play/orig/README
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/README?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/README (added)
+++ branches/coling/raop_play/orig/README Fri May  2 02:16:10 2008
@@ -1,0 +1,64 @@
+"raop_play"
+
+This is originally a ported version of "JustePort" which is programed
+by Jon Lech Johansen.  I've rewritten it in C code using openssl, so
+this can run without mono.
+
+This program works under aexcl_play which makes GUI.
+
+Thomas Butter gave me information how to play pcm data, and now this
+can play wave files.
+
+The original information about alac format from alac_decoder
+by David Hamilton.  http://craz.net/programs/itunes/alac.html
+
+mp3, ogg, aac data are supported by using commandline program:
+"mpg321","ogg123" and "faad".
+
+
+TO COMPILE:
+Make sure you have libssl library and header file.
+Then just run "make", you'll get an executable "raop_play".
+No installer is there, If you want to put into a executable path, you
+need to manually copy it.
+
+TO PLAY:
+$ raop_play [--port port_number] [--vol volume(0-100)] [-i] AirporExpree_IP [ filename ]
+
+Supported filetypes:
+.pcm .wav, .mp3, .m4a, .ogg, .aac, .pls, http://*
+  .pls is playlist which includes other type of file as a list.
+  if filename start with "http://", which is plyed by mpg321.  Only mp3 type streams can be played
+  files without extension are played as raw pcm data file, which can be fifo or file device.
+
+
+if -i option is used, the program stops after making a connection, and
+wait a command from stdin.
+
+INTERACTIVE MODE COMMAND:
+
+  play [m4a_filename] # play-after-pause doesn't need m4a_filename
+  pause
+  stop
+  quit
+  volume VALUE # VALUE is 0 to 100
+
+INTERACTIVE MODE CONSOLE PRINTOUT:
+  connected # when it gets a connection with the host
+  done # when one file play finished
+  error # non fatal error. if it is fatal, disconnect and quit the program.
+
+
+
+Original "JustePort" by Jon Lech Johansen
+http://nanocrew.net/software/
+
+base64.c, base64.h
+are picked up from "krb-1.2.2" by Kungliga Tekniska HNvgskolan 
+
+aes.c, aes.h
+are picked up from "sbd-1.31" by Michel Blomgren
+
+
+27 July, 2005
+Shiro Ninomiya <shiron at snino.com>

Propchange: branches/coling/raop_play/orig/README
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/coling/raop_play/orig/README
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/coling/raop_play/orig/aac_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aac_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aac_stream.c (added)
+++ branches/coling/raop_play/orig/aac_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,143 @@
+/*****************************************************************************
+ * aac_stream.c: aac file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <sys/wait.h>
+#define AAC_STREAM_C
+#include "audio_stream.h"
+#include "aac_stream.h"
+#include "aexcl_lib.h"
+
+
+#define AAC_DECODER "faad"
+#define FIFO_NAME "/tmp/aac_stream"
+static int run_decoder(aac_t *aac)
+{
+  char *darg[8]={AAC_DECODER,"-f","2","-o", NULL, NULL, NULL};
+  darg[4]=FIFO_NAME;
+  darg[5]=aac->fname;
+  aac->dpid=child_start(darg,NULL,NULL,NULL);
+  if(!(aac->inf=fopen(FIFO_NAME,"r"))) {
+    ERRMSG("can't open fifo\n");
+    return -1;
+  }
+  return 0;
+}
+
+static int stop_decoder(aac_t *aac)
+{
+  int i;
+
+  if(!aac->dpid) return 0;
+  kill(aac->dpid,SIGTERM);
+  for(i=0;i<10;i++){
+    if(!aac->dpid) return 0;
+    usleep(10*1000);
+  }
+  ERRMSG("decoder process can't be terminated\n");
+  return 0;
+}
+
+static void sigchld_callback(void *p, siginfo_t *siginfo)
+{
+  aac_t *aac=(aac_t*)p;
+  if(siginfo->si_pid==aac->dpid){
+    waitpid(aac->dpid,NULL,0);
+    aac->dpid=0;
+  }
+}
+
+static int read_header(auds_t *auds, char *fname)
+{
+  // Seems not easy to read aac or mp4 header, go easy way here
+  char cmdstr[1024];
+  snprintf(cmdstr, sizeof(cmdstr), "%s -i %s 2>&1 | sed -n 's/.* \\([0-9]*\\) Hz.*/\\1/p'",
+    AAC_DECODER, fname);
+  FILE *inf=popen(cmdstr,"r");
+  char data[16];
+  int srate;
+  memset(data,0,16);
+  fread(data,1,16,inf);
+  if((srate=atoi(data))>=8000){
+    auds->sample_rate=srate;
+    DBGMSG("sample rate=%d\n",srate);
+  }
+  pclose(inf);
+  return 0;
+}
+
+int aac_open(auds_t *auds, char *fname)
+{
+  aac_t *aac=malloc(sizeof(aac_t));
+  if(!aac) return -1;
+  memset(aac,0,sizeof(aac_t));
+  auds->stream=(aac_t*)aac;
+  aac->fname=(char *)malloc(strlen(fname)+1);
+  if(!aac->fname) goto erexit;
+  strcpy(aac->fname,fname);
+  aac->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!aac->buffer) goto erexit;
+  auds->sigchld_cb=sigchld_callback;
+  auds->sample_rate=DEFAULT_SAMPLE_RATE;
+  read_header(auds, fname);
+  if(access(FIFO_NAME,F_OK) && mkfifo(FIFO_NAME,0600)<0){
+    ERRMSG("can't make a named fifo:%s\n",FIFO_NAME);
+    goto erexit;
+  }
+  run_decoder(aac);
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  return 0;
+ erexit:
+  aac_close(auds);
+  return -1;
+}
+
+int aac_close(auds_t *auds)
+{
+  aac_t *aac=(aac_t *)auds->stream;
+  if(!aac) return -1;
+  if(aac->inf) fclose(aac->inf);
+  stop_decoder(aac);
+  unlink(FIFO_NAME);
+  if(aac->buffer) free(aac->buffer);
+  if(aac->fname) free(aac->fname);
+  free(aac);
+  return 0;
+}
+
+int aac_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  aac_t *aac=(aac_t *)auds->stream;
+  stop_decoder(aac);
+  run_decoder(aac);
+  return aac_get_next_sample(auds, data, size);
+}
+
+
+int aac_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  aac_t *aac=(aac_t *)auds->stream;
+  data_source_t ds={.type=STREAM, .u.inf=aac->inf};
+  return auds_write_pcm(auds, aac->buffer, data, size, auds->chunk_size, &ds);
+}
+

Propchange: branches/coling/raop_play/orig/aac_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/aac_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aac_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aac_stream.h (added)
+++ branches/coling/raop_play/orig/aac_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,44 @@
+/*****************************************************************************
+ * mp3_stream.h: mp3 file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __AAC_STREAM_H_
+#define __AAC_STREAM_H_
+
+
+typedef struct aac_t {
+/* public variables */
+/* private variables */
+#ifdef AAC_STREAM_C
+  FILE *inf;
+  int dpid;
+  __u8 *buffer;
+  char *fname;
+#else
+  __u32 dummy;
+#endif
+} aac_t;
+
+
+int aac_open(auds_t *auds, char *fname);
+int aac_close(auds_t *auds);
+int aac_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int aac_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/aac_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/aes.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aes.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aes.c (added)
+++ branches/coling/raop_play/orig/aes.c Fri May  2 02:16:10 2008
@@ -1,0 +1,864 @@
+/*
+ *  FIPS-197 compliant AES implementation
+ *
+ *  Copyright (C) 2001-2004  Christophe Devine
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "aes.h"
+
+/* uncomment the following line to run the test suite */
+
+/* #define TEST */
+
+/* uncomment the following line to use pre-computed tables */
+/* otherwise the tables will be generated at the first run */
+
+/* #define FIXED_TABLES */
+
+#ifndef FIXED_TABLES
+
+/* forward S-box & tables */
+
+uint32 FSb[256];
+uint32 FT0[256];
+uint32 FT1[256];
+uint32 FT2[256];
+uint32 FT3[256];
+
+/* reverse S-box & tables */
+
+uint32 RSb[256];
+uint32 RT0[256];
+uint32 RT1[256];
+uint32 RT2[256];
+uint32 RT3[256];
+
+/* round constants */
+
+uint32 RCON[10];
+
+/* tables generation flag */
+
+int do_init = 1;
+
+/* tables generation routine */
+
+#define ROTR8(x) ( ( ( x << 24 ) & 0xFFFFFFFF ) | \
+                   ( ( x & 0xFFFFFFFF ) >>  8 ) )
+
+#define XTIME(x) ( ( x <<  1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )
+#define MUL(x,y) ( ( x &&  y ) ? aes_gen_tables_pow[(aes_gen_tables_log[x] + aes_gen_tables_log[y]) % 255] : 0 )
+
+void aes_gen_tables( void )
+{
+    int i;
+    uint8 x, y;
+    uint8 aes_gen_tables_pow[256];
+    uint8 aes_gen_tables_log[256];
+
+    /* compute pow and log tables over GF(2^8) */
+
+    for( i = 0, x = 1; i < 256; i++, x ^= XTIME( x ) )
+    {
+        aes_gen_tables_pow[i] = x;
+        aes_gen_tables_log[x] = i;
+    }
+
+    /* calculate the round constants */
+
+    for( i = 0, x = 1; i < 10; i++, x = XTIME( x ) )
+    {
+        RCON[i] = (uint32) x << 24;
+    }
+
+    /* generate the forward and reverse S-boxes */
+
+    FSb[0x00] = 0x63;
+    RSb[0x63] = 0x00;
+
+    for( i = 1; i < 256; i++ )
+    {
+        x = aes_gen_tables_pow[255 - aes_gen_tables_log[i]];
+
+        y = x;  y = ( y << 1 ) | ( y >> 7 );
+        x ^= y; y = ( y << 1 ) | ( y >> 7 );
+        x ^= y; y = ( y << 1 ) | ( y >> 7 );
+        x ^= y; y = ( y << 1 ) | ( y >> 7 );
+        x ^= y ^ 0x63;
+
+        FSb[i] = x;
+        RSb[x] = i;
+    }
+
+    /* generate the forward and reverse tables */
+
+    for( i = 0; i < 256; i++ )
+    {
+        x = FSb[i]; y = XTIME( x );
+
+        FT0[i] =   (uint32) ( x ^ y ) ^
+                 ( (uint32) x <<  8 ) ^
+                 ( (uint32) x << 16 ) ^
+                 ( (uint32) y << 24 );
+
+        FT0[i] &= 0xFFFFFFFF;
+
+        FT1[i] = ROTR8( FT0[i] );
+        FT2[i] = ROTR8( FT1[i] );
+        FT3[i] = ROTR8( FT2[i] );
+
+        y = RSb[i];
+
+        RT0[i] = ( (uint32) MUL( 0x0B, y )       ) ^
+                 ( (uint32) MUL( 0x0D, y ) <<  8 ) ^
+                 ( (uint32) MUL( 0x09, y ) << 16 ) ^
+                 ( (uint32) MUL( 0x0E, y ) << 24 );
+
+        RT0[i] &= 0xFFFFFFFF;
+
+        RT1[i] = ROTR8( RT0[i] );
+        RT2[i] = ROTR8( RT1[i] );
+        RT3[i] = ROTR8( RT2[i] );
+    }
+}
+
+#else
+
+/* forward S-box */
+
+static const uint32 FSb[256] =
+{
+    0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
+    0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
+    0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
+    0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
+    0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
+    0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
+    0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
+    0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
+    0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
+    0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
+    0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
+    0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
+    0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
+    0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
+    0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
+    0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
+    0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
+    0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
+    0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
+    0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
+    0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
+    0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
+    0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
+    0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
+    0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
+    0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
+    0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
+    0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
+    0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
+    0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
+    0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
+    0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
+};
+
+/* forward tables */
+
+#define FT \
+\
+    V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \
+    V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \
+    V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \
+    V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \
+    V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \
+    V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \
+    V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \
+    V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \
+    V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \
+    V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \
+    V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \
+    V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \
+    V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \
+    V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \
+    V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \
+    V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \
+    V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \
+    V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \
+    V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \
+    V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \
+    V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \
+    V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \
+    V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \
+    V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \
+    V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \
+    V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \
+    V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \
+    V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \
+    V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \
+    V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \
+    V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \
+    V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \
+    V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \
+    V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \
+    V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \
+    V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \
+    V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \
+    V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \
+    V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \
+    V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \
+    V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \
+    V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \
+    V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \
+    V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \
+    V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \
+    V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \
+    V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \
+    V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \
+    V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \
+    V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \
+    V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \
+    V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \
+    V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \
+    V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \
+    V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \
+    V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \
+    V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \
+    V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \
+    V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \
+    V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \
+    V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \
+    V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \
+    V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \
+    V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A)
+
+#define V(a,b,c,d) 0x##a##b##c##d
+static const uint32 FT0[256] = { FT };
+#undef V
+
+#define V(a,b,c,d) 0x##d##a##b##c
+static const uint32 FT1[256] = { FT };
+#undef V
+
+#define V(a,b,c,d) 0x##c##d##a##b
+static const uint32 FT2[256] = { FT };
+#undef V
+
+#define V(a,b,c,d) 0x##b##c##d##a
+static const uint32 FT3[256] = { FT };
+#undef V
+
+#undef FT
+
+/* reverse S-box */
+
+static const uint32 RSb[256] =
+{
+    0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
+    0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
+    0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
+    0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
+    0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
+    0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
+    0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
+    0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
+    0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
+    0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
+    0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
+    0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
+    0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
+    0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
+    0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
+    0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
+    0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
+    0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
+    0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
+    0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
+    0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
+    0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
+    0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
+    0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
+    0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
+    0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
+    0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
+    0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
+    0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
+    0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
+    0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
+    0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
+};
+
+/* reverse tables */
+
+#define RT \
+\
+    V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \
+    V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \
+    V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \
+    V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \
+    V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \
+    V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \
+    V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \
+    V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \
+    V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \
+    V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \
+    V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \
+    V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \
+    V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \
+    V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \
+    V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \
+    V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \
+    V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \
+    V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \
+    V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \
+    V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \
+    V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \
+    V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \
+    V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \
+    V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \
+    V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \
+    V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \
+    V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \
+    V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \
+    V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \
+    V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \
+    V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \
+    V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \
+    V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \
+    V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \
+    V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \
+    V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \
+    V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \
+    V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \
+    V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \
+    V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \
+    V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \
+    V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \
+    V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \
+    V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \
+    V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \
+    V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \
+    V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \
+    V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \
+    V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \
+    V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \
+    V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \
+    V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \
+    V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \
+    V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \
+    V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \
+    V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \
+    V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \
+    V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \
+    V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \
+    V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \
+    V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \
+    V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \
+    V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \
+    V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42)
+
+#define V(a,b,c,d) 0x##a##b##c##d
+static const uint32 RT0[256] = { RT };
+#undef V
+
+#define V(a,b,c,d) 0x##d##a##b##c
+static const uint32 RT1[256] = { RT };
+#undef V
+
+#define V(a,b,c,d) 0x##c##d##a##b
+static const uint32 RT2[256] = { RT };
+#undef V
+
+#define V(a,b,c,d) 0x##b##c##d##a
+static const uint32 RT3[256] = { RT };
+#undef V
+
+#undef RT
+
+/* round constants */
+
+static const uint32 RCON[10] =
+{
+    0x01000000, 0x02000000, 0x04000000, 0x08000000,
+    0x10000000, 0x20000000, 0x40000000, 0x80000000,
+    0x1B000000, 0x36000000
+};
+
+int do_init = 0;
+
+void aes_gen_tables( void )
+{
+}
+
+#endif
+
+/* platform-independant 32-bit integer manipulation macros */
+
+#define GET_UINT32(n,b,i)                       \
+{                                               \
+    (n) = ( (uint32) (b)[(i)    ] << 24 )       \
+        | ( (uint32) (b)[(i) + 1] << 16 )       \
+        | ( (uint32) (b)[(i) + 2] <<  8 )       \
+        | ( (uint32) (b)[(i) + 3]       );      \
+}
+
+#define PUT_UINT32(n,b,i)                       \
+{                                               \
+    (b)[(i)    ] = (uint8) ( (n) >> 24 );       \
+    (b)[(i) + 1] = (uint8) ( (n) >> 16 );       \
+    (b)[(i) + 2] = (uint8) ( (n) >>  8 );       \
+    (b)[(i) + 3] = (uint8) ( (n)       );       \
+}
+
+/* decryption key schedule tables */
+
+int KT_init = 1;
+
+uint32 KT0[256];
+uint32 KT1[256];
+uint32 KT2[256];
+uint32 KT3[256];
+
+/* AES key scheduling routine */
+
+int aes_set_key( aes_context *ctx, uint8 *key, int nbits )
+{
+    int i;
+    uint32 *RK, *SK;
+
+    if( do_init )
+    {
+        aes_gen_tables();
+
+        do_init = 0;
+    }
+
+    switch( nbits )
+    {
+        case 128: ctx->nr = 10; break;
+        case 192: ctx->nr = 12; break;
+        case 256: ctx->nr = 14; break;
+        default : return( 1 );
+    }
+
+    RK = ctx->erk;
+
+    for( i = 0; i < (nbits >> 5); i++ )
+    {
+        GET_UINT32( RK[i], key, i * 4 );
+    }
+
+    /* setup encryption round keys */
+
+    switch( nbits )
+    {
+    case 128:
+
+        for( i = 0; i < 10; i++, RK += 4 )
+        {
+            RK[4]  = RK[0] ^ RCON[i] ^
+                        ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^
+                        ( FSb[ (uint8) ( RK[3] >>  8 ) ] << 16 ) ^
+                        ( FSb[ (uint8) ( RK[3]       ) ] <<  8 ) ^
+                        ( FSb[ (uint8) ( RK[3] >> 24 ) ]       );
+
+            RK[5]  = RK[1] ^ RK[4];
+            RK[6]  = RK[2] ^ RK[5];
+            RK[7]  = RK[3] ^ RK[6];
+        }
+        break;
+
+    case 192:
+
+        for( i = 0; i < 8; i++, RK += 6 )
+        {
+            RK[6]  = RK[0] ^ RCON[i] ^
+                        ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^
+                        ( FSb[ (uint8) ( RK[5] >>  8 ) ] << 16 ) ^
+                        ( FSb[ (uint8) ( RK[5]       ) ] <<  8 ) ^
+                        ( FSb[ (uint8) ( RK[5] >> 24 ) ]       );
+
+            RK[7]  = RK[1] ^ RK[6];
+            RK[8]  = RK[2] ^ RK[7];
+            RK[9]  = RK[3] ^ RK[8];
+            RK[10] = RK[4] ^ RK[9];
+            RK[11] = RK[5] ^ RK[10];
+        }
+        break;
+
+    case 256:
+
+        for( i = 0; i < 7; i++, RK += 8 )
+        {
+            RK[8]  = RK[0] ^ RCON[i] ^
+                        ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^
+                        ( FSb[ (uint8) ( RK[7] >>  8 ) ] << 16 ) ^
+                        ( FSb[ (uint8) ( RK[7]       ) ] <<  8 ) ^
+                        ( FSb[ (uint8) ( RK[7] >> 24 ) ]       );
+
+            RK[9]  = RK[1] ^ RK[8];
+            RK[10] = RK[2] ^ RK[9];
+            RK[11] = RK[3] ^ RK[10];
+
+            RK[12] = RK[4] ^
+                        ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^
+                        ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^
+                        ( FSb[ (uint8) ( RK[11] >>  8 ) ] <<  8 ) ^
+                        ( FSb[ (uint8) ( RK[11]       ) ]       );
+
+            RK[13] = RK[5] ^ RK[12];
+            RK[14] = RK[6] ^ RK[13];
+            RK[15] = RK[7] ^ RK[14];
+        }
+        break;
+    }
+
+    /* setup decryption round keys */
+
+    if( KT_init )
+    {
+        for( i = 0; i < 256; i++ )
+        {
+            KT0[i] = RT0[ FSb[i] ];
+            KT1[i] = RT1[ FSb[i] ];
+            KT2[i] = RT2[ FSb[i] ];
+            KT3[i] = RT3[ FSb[i] ];
+        }
+
+        KT_init = 0;
+    }
+
+    SK = ctx->drk;
+
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+
+    for( i = 1; i < ctx->nr; i++ )
+    {
+        RK -= 8;
+
+        *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
+                KT1[ (uint8) ( *RK >> 16 ) ] ^
+                KT2[ (uint8) ( *RK >>  8 ) ] ^
+                KT3[ (uint8) ( *RK       ) ]; RK++;
+
+        *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
+                KT1[ (uint8) ( *RK >> 16 ) ] ^
+                KT2[ (uint8) ( *RK >>  8 ) ] ^
+                KT3[ (uint8) ( *RK       ) ]; RK++;
+
+        *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
+                KT1[ (uint8) ( *RK >> 16 ) ] ^
+                KT2[ (uint8) ( *RK >>  8 ) ] ^
+                KT3[ (uint8) ( *RK       ) ]; RK++;
+
+        *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
+                KT1[ (uint8) ( *RK >> 16 ) ] ^
+                KT2[ (uint8) ( *RK >>  8 ) ] ^
+                KT3[ (uint8) ( *RK       ) ]; RK++;
+    }
+
+    RK -= 8;
+
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+    *SK++ = *RK++;
+
+    return( 0 );
+}
+
+/* AES 128-bit block encryption routine */
+
+void aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] )
+{
+    uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
+
+    RK = ctx->erk;
+
+    GET_UINT32( X0, input,  0 ); X0 ^= RK[0];
+    GET_UINT32( X1, input,  4 ); X1 ^= RK[1];
+    GET_UINT32( X2, input,  8 ); X2 ^= RK[2];
+    GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
+
+#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3)     \
+{                                               \
+    RK += 4;                                    \
+                                                \
+    X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^  \
+                 FT1[ (uint8) ( Y1 >> 16 ) ] ^  \
+                 FT2[ (uint8) ( Y2 >>  8 ) ] ^  \
+                 FT3[ (uint8) ( Y3       ) ];   \
+                                                \
+    X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^  \
+                 FT1[ (uint8) ( Y2 >> 16 ) ] ^  \
+                 FT2[ (uint8) ( Y3 >>  8 ) ] ^  \
+                 FT3[ (uint8) ( Y0       ) ];   \
+                                                \
+    X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^  \
+                 FT1[ (uint8) ( Y3 >> 16 ) ] ^  \
+                 FT2[ (uint8) ( Y0 >>  8 ) ] ^  \
+                 FT3[ (uint8) ( Y1       ) ];   \
+                                                \
+    X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^  \
+                 FT1[ (uint8) ( Y0 >> 16 ) ] ^  \
+                 FT2[ (uint8) ( Y1 >>  8 ) ] ^  \
+                 FT3[ (uint8) ( Y2       ) ];   \
+}
+
+    AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 1 */
+    AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 2 */
+    AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 3 */
+    AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 4 */
+    AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 5 */
+    AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 6 */
+    AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 7 */
+    AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 8 */
+    AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 9 */
+
+    if( ctx->nr > 10 )
+    {
+        AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );   /* round 10 */
+        AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );   /* round 11 */
+    }
+
+    if( ctx->nr > 12 )
+    {
+        AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );   /* round 12 */
+        AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );   /* round 13 */
+    }
+
+    /* last round */
+
+    RK += 4;
+
+    X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
+                 ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
+                 ( FSb[ (uint8) ( Y2 >>  8 ) ] <<  8 ) ^
+                 ( FSb[ (uint8) ( Y3       ) ]       );
+
+    X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
+                 ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
+                 ( FSb[ (uint8) ( Y3 >>  8 ) ] <<  8 ) ^
+                 ( FSb[ (uint8) ( Y0       ) ]       );
+
+    X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
+                 ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
+                 ( FSb[ (uint8) ( Y0 >>  8 ) ] <<  8 ) ^
+                 ( FSb[ (uint8) ( Y1       ) ]       );
+
+    X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
+                 ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
+                 ( FSb[ (uint8) ( Y1 >>  8 ) ] <<  8 ) ^
+                 ( FSb[ (uint8) ( Y2       ) ]       );
+
+    PUT_UINT32( X0, output,  0 );
+    PUT_UINT32( X1, output,  4 );
+    PUT_UINT32( X2, output,  8 );
+    PUT_UINT32( X3, output, 12 );
+}
+
+/* AES 128-bit block decryption routine */
+
+void aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] )
+{
+    uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
+
+    RK = ctx->drk;
+
+    GET_UINT32( X0, input,  0 ); X0 ^= RK[0];
+    GET_UINT32( X1, input,  4 ); X1 ^= RK[1];
+    GET_UINT32( X2, input,  8 ); X2 ^= RK[2];
+    GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
+
+#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3)     \
+{                                               \
+    RK += 4;                                    \
+                                                \
+    X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^  \
+                 RT1[ (uint8) ( Y3 >> 16 ) ] ^  \
+                 RT2[ (uint8) ( Y2 >>  8 ) ] ^  \
+                 RT3[ (uint8) ( Y1       ) ];   \
+                                                \
+    X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^  \
+                 RT1[ (uint8) ( Y0 >> 16 ) ] ^  \
+                 RT2[ (uint8) ( Y3 >>  8 ) ] ^  \
+                 RT3[ (uint8) ( Y2       ) ];   \
+                                                \
+    X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^  \
+                 RT1[ (uint8) ( Y1 >> 16 ) ] ^  \
+                 RT2[ (uint8) ( Y0 >>  8 ) ] ^  \
+                 RT3[ (uint8) ( Y3       ) ];   \
+                                                \
+    X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^  \
+                 RT1[ (uint8) ( Y2 >> 16 ) ] ^  \
+                 RT2[ (uint8) ( Y1 >>  8 ) ] ^  \
+                 RT3[ (uint8) ( Y0       ) ];   \
+}
+
+    AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 1 */
+    AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 2 */
+    AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 3 */
+    AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 4 */
+    AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 5 */
+    AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 6 */
+    AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 7 */
+    AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );       /* round 8 */
+    AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );       /* round 9 */
+
+    if( ctx->nr > 10 )
+    {
+        AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );   /* round 10 */
+        AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );   /* round 11 */
+    }
+
+    if( ctx->nr > 12 )
+    {
+        AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );   /* round 12 */
+        AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );   /* round 13 */
+    }
+
+    /* last round */
+
+    RK += 4;
+
+    X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
+                 ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
+                 ( RSb[ (uint8) ( Y2 >>  8 ) ] <<  8 ) ^
+                 ( RSb[ (uint8) ( Y1       ) ]       );
+
+    X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
+                 ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
+                 ( RSb[ (uint8) ( Y3 >>  8 ) ] <<  8 ) ^
+                 ( RSb[ (uint8) ( Y2       ) ]       );
+
+    X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
+                 ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
+                 ( RSb[ (uint8) ( Y0 >>  8 ) ] <<  8 ) ^
+                 ( RSb[ (uint8) ( Y3       ) ]       );
+
+    X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
+                 ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
+                 ( RSb[ (uint8) ( Y1 >>  8 ) ] <<  8 ) ^
+                 ( RSb[ (uint8) ( Y0       ) ]       );
+
+    PUT_UINT32( X0, output,  0 );
+    PUT_UINT32( X1, output,  4 );
+    PUT_UINT32( X2, output,  8 );
+    PUT_UINT32( X3, output, 12 );
+}
+
+#ifdef TEST
+
+#include <string.h>
+#include <stdio.h>
+
+/*
+ * Rijndael Monte Carlo Test: ECB mode
+ * source: NIST - rijndael-vals.zip
+ */
+
+static unsigned char AES_enc_test[3][16] =
+{
+    { 0xA0, 0x43, 0x77, 0xAB, 0xE2, 0x59, 0xB0, 0xD0,
+      0xB5, 0xBA, 0x2D, 0x40, 0xA5, 0x01, 0x97, 0x1B },
+    { 0x4E, 0x46, 0xF8, 0xC5, 0x09, 0x2B, 0x29, 0xE2,
+      0x9A, 0x97, 0x1A, 0x0C, 0xD1, 0xF6, 0x10, 0xFB },
+    { 0x1F, 0x67, 0x63, 0xDF, 0x80, 0x7A, 0x7E, 0x70,
+      0x96, 0x0D, 0x4C, 0xD3, 0x11, 0x8E, 0x60, 0x1A }
+};
+
+static unsigned char AES_dec_test[3][16] =
+{
+    { 0xF5, 0xBF, 0x8B, 0x37, 0x13, 0x6F, 0x2E, 0x1F,
+      0x6B, 0xEC, 0x6F, 0x57, 0x20, 0x21, 0xE3, 0xBA },
+    { 0xF1, 0xA8, 0x1B, 0x68, 0xF6, 0xE5, 0xA6, 0x27,
+      0x1A, 0x8C, 0xB2, 0x4E, 0x7D, 0x94, 0x91, 0xEF },
+    { 0x4D, 0xE0, 0xC6, 0xDF, 0x7C, 0xB1, 0x69, 0x72,
+      0x84, 0x60, 0x4D, 0x60, 0x27, 0x1B, 0xC5, 0x9A }
+};
+
+int main( void )
+{
+    int m, n, i, j;
+    aes_context ctx;
+    unsigned char buf[16];
+    unsigned char key[32];
+
+    for( m = 0; m < 2; m++ )
+    {
+        printf( "\n Rijndael Monte Carlo Test (ECB mode) - " );
+
+        if( m == 0 ) printf( "encryption\n\n" );
+        if( m == 1 ) printf( "decryption\n\n" );
+
+        for( n = 0; n < 3; n++ )
+        {
+            printf( " Test %d, key size = %3d bits: ",
+                    n + 1, 128 + n * 64 );
+
+            fflush( stdout );
+
+            memset( buf, 0, 16 );
+            memset( key, 0, 16 + n * 8 );
+
+            for( i = 0; i < 400; i++ )
+            {
+                aes_set_key( &ctx, key, 128 + n * 64 );
+
+                for( j = 0; j < 9999; j++ )
+                {
+                    if( m == 0 ) aes_encrypt( &ctx, buf, buf );
+                    if( m == 1 ) aes_decrypt( &ctx, buf, buf );
+                }
+
+                if( n > 0 )
+                {
+                    for( j = 0; j < (n << 3); j++ )
+                    {
+                        key[j] ^= buf[j + 16 - (n << 3)];
+                    }
+                }
+
+                if( m == 0 ) aes_encrypt( &ctx, buf, buf );
+                if( m == 1 ) aes_decrypt( &ctx, buf, buf );
+
+                for( j = 0; j < 16; j++ )
+                {
+                    key[j + (n << 3)] ^= buf[j];
+                }
+            }
+
+            if( ( m == 0 && memcmp( buf, AES_enc_test[n], 16 ) ) ||
+                ( m == 1 && memcmp( buf, AES_dec_test[n], 16 ) ) )
+            {
+                printf( "failed!\n" );
+                return( 1 );
+            }
+
+            printf( "passed.\n" );
+        }
+    }
+
+    printf( "\n" );
+
+    return( 0 );
+}
+
+#endif
+

Propchange: branches/coling/raop_play/orig/aes.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/aes.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aes.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aes.h (added)
+++ branches/coling/raop_play/orig/aes.h Fri May  2 02:16:10 2008
@@ -1,0 +1,24 @@
+#ifndef _AES_H
+#define _AES_H
+
+#ifndef uint8
+#define uint8  unsigned char
+#endif
+
+#ifndef uint32
+#define uint32 unsigned long int
+#endif
+
+typedef struct
+{
+    uint32 erk[64];     /* encryption round keys */
+    uint32 drk[64];     /* decryption round keys */
+    int nr;             /* number of rounds */
+}
+aes_context;
+
+int  aes_set_key( aes_context *ctx, uint8 *key, int nbits );
+void aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
+void aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
+
+#endif /* aes.h */

Propchange: branches/coling/raop_play/orig/aes.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/aexcl_lib.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aexcl_lib.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aexcl_lib.c (added)
+++ branches/coling/raop_play/orig/aexcl_lib.c Fri May  2 02:16:10 2008
@@ -1,0 +1,313 @@
+/*****************************************************************************
+ * socket interface library
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/poll.h>
+#include "aexcl_lib.h"
+
+
+/*
+ * open tcp port
+ */
+int open_tcp_socket(char *hostname, unsigned short *port)
+{
+  int sd;
+
+  /* socket creation */
+  sd = socket(AF_INET, SOCK_STREAM, 0);
+  if(sd<0) {
+    ERRMSG("cannot create tcp socket\n");
+    return -1;
+  }
+  if(bind_host(sd, hostname,0, port)) {
+    close(sd);
+    return -1;
+  }
+
+  return sd;
+}
+
+/*
+ * create tcp connection
+ * as long as the socket is not non-blocking, this can block the process
+ * nsport is network byte order
+ */
+int get_tcp_connect(int sd, struct sockaddr_in dest_addr)
+{
+
+  if(connect(sd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))){
+    SLEEP_MSEC(100L);
+    // try one more time
+    if(connect(sd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr))){
+      ERRMSG("error:get_tcp_nconnect addr=%s, port=%d\n",
+             inet_ntoa(dest_addr.sin_addr), ntohs(dest_addr.sin_port));
+      return -1;
+    }
+  }
+  return 0;
+}
+
+
+int get_tcp_connect_by_host(int sd, char *host, __u16 destport)
+{
+  struct sockaddr_in addr;
+  struct hostent *h;
+
+  h = gethostbyname(host);
+  if(h) {
+    addr.sin_family = h->h_addrtype;
+    memcpy((char *) &addr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
+  }else{
+    addr.sin_family = AF_INET;
+    if((addr.sin_addr.s_addr=inet_addr(host))==0xFFFFFFFF){
+      ERRMSG("gethostbyname: '%s' \n", host);
+      return -1;
+    }
+  }
+  addr.sin_port=htons(destport);
+
+  return get_tcp_connect(sd, addr);
+}
+
+/* bind an opened socket to specified hostname and port.
+ * if hostname=NULL, use INADDR_ANY.
+ * if *port=0, use dynamically assigned port
+ */
+int bind_host(int sd, char *hostname, unsigned long ulAddr,unsigned short *port)
+{
+  struct sockaddr_in my_addr;
+  socklen_t nlen=sizeof(struct sockaddr);
+  struct hostent *h;
+
+  memset(&my_addr, 0, sizeof(my_addr));
+  /* use specified hostname */
+  if(hostname){
+    /* get server IP address (no check if input is IP address or DNS name */
+    h = gethostbyname(hostname);
+    if(h==NULL) {
+      if(strstr(hostname, "255.255.255.255")==hostname){
+        my_addr.sin_addr.s_addr=-1;
+      }else{
+        if((my_addr.sin_addr.s_addr=inet_addr(hostname))==0xFFFFFFFF){
+          ERRMSG("gethostbyname: '%s' \n", hostname);
+          return -1;
+        }
+      }
+      my_addr.sin_family = AF_INET;
+    }else{
+      my_addr.sin_family = h->h_addrtype;
+      memcpy((char *) &my_addr.sin_addr.s_addr,
+             h->h_addr_list[0], h->h_length);
+    }
+  } else {
+    // if hostname=NULL, use INADDR_ANY
+    if(ulAddr)
+      my_addr.sin_addr.s_addr = ulAddr;
+    else
+      my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    my_addr.sin_family = AF_INET;
+  }
+
+  /* bind a specified port */
+  my_addr.sin_port = htons(*port);
+
+  if(bind(sd, (struct sockaddr *) &my_addr, sizeof(my_addr))<0){
+    ERRMSG("bind error: %s\n", strerror(errno));
+    return -1;
+  }
+
+  if(*port==0){
+    getsockname(sd, (struct sockaddr *) &my_addr, &nlen);
+    *port=ntohs(my_addr.sin_port);
+  }
+
+  return 0;
+}
+
+/*
+ * read one line from the file descriptor
+ * timeout: msec unit, -1 for infinite
+ * if CR comes then following LF is expected
+ * returned string in line is always null terminated, maxlen-1 is maximum string length
+ */
+int read_line(int fd, char *line, int maxlen, int timeout, int no_poll)
+{
+  int i,rval;
+  int count=0;
+  struct pollfd pfds={events:POLLIN};
+  char ch;
+  *line=0;
+  pfds.fd=fd;
+  for(i=0;i<maxlen;i++){
+    if(no_poll || poll(&pfds, 1, timeout))
+      rval=read(fd,&ch,1);
+    else return 0;
+
+    if(rval==-1){
+      if(errno==EAGAIN) return 0;
+      ERRMSG("%s:read error: %s\n", __func__, strerror(errno));
+      return -1;
+    }
+    if(rval==0){
+      INFMSG("%s:disconnected on the other end\n", __func__);
+      return -1;
+    }
+    if(ch=='\n'){
+      *line=0;
+      return count;
+    }
+    if(ch=='\r') continue;
+    *line++=ch;
+    count++;
+    if(count>=maxlen-1) break;
+  }
+  *line=0;
+  return count;
+}
+
+/*
+ * key_data type data look up
+ */
+char *kd_lookup(key_data_t *kd, char *key)
+{
+  int i=0;
+  while(kd && kd[i].key){
+    if(!strcmp((char*)kd[i].key,key)) return (char*)kd[i].data;
+    i++;
+  }
+  return NULL;
+}
+
+void free_kd(key_data_t *kd)
+{
+  int i=0;
+  while(kd && kd[i].key){
+    free(kd[i].key);
+    if(kd[i].data) free(kd[i].data);
+    i++;
+  }
+  free(kd);
+}
+
+/*
+ * remove one character from a string
+ * return the number of deleted characters
+ */
+int remove_char_from_string(char *str, char rc)
+{
+  int i=0,j=0,len;
+  int num=0;
+  len=strlen(str);
+  while(i<len){
+    if(str[i]==rc){
+      for(j=i;j<len;j++) str[j]=str[j+1];
+      len--;
+      num++;
+    }else{
+      i++;
+    }
+  }
+  return num;
+}
+
+/*
+ * invoke a new child process
+ */
+int child_start(char* const argv[], int *infd, int *outfd, int *errfd)
+{
+  int infds[2];
+  int errfds[2];
+  int outfds[2];
+  int pid;
+  pipe(infds);
+  pipe(outfds);
+  pipe(errfds);
+  pid=fork();
+  if(pid==0){
+    // this is a child
+    if(infd){
+      dup2(infds[1],1);// copy output pipe to standard output
+    }else{
+      close(infds[1]);
+    }
+    close(infds[0]);
+
+    if(errfd){
+      dup2(errfds[1],2);// copy output pipe to standard error
+    }else{
+      close(errfds[1]);
+    }
+    close(infds[0]);
+
+    if(outfd){
+      dup2(outfds[0],0);// copy input pipe to standard input
+    }else{
+      close(outfds[0]);
+    }
+    close(outfds[1]);
+
+    execvp(argv[0], argv);
+    exit(0);
+  }
+
+  if(infd)
+    *infd=infds[0];
+  else
+    close(infds[0]);
+  close(infds[1]);//close output pipe
+
+  if(errfd)
+    *errfd=errfds[0];
+  else
+    close(errfds[0]);
+  close(errfds[1]);//close output pipe
+
+  if(outfd)
+    *outfd=outfds[1];
+  else
+    close(outfds[1]);
+  close(outfds[0]);// close read pipe
+
+  return pid;
+}
+
+
+#if 0 // for debugging
+void hex_dump(unsigned char *buf, int size, int addr)
+{
+  int i;
+  int p=0;
+  while(size){
+    fprintf(stderr,"%08X - ", addr);
+    for(i=addr&0xf;i>0;i--) fprintf(stderr,"   ");
+    if((addr&0xf)>0x8) fprintf(stderr," ");
+    for(i=addr&0xf;i<0x10;i++){
+      if(i==0x8) fprintf(stderr," ");
+      fprintf(stderr,"%02x ", buf[p++]);
+      if(! --size) break;
+    }
+    addr=(addr+0x10)&~0xf;
+    fprintf(stderr,"\n");
+  }
+}
+#endif

Propchange: branches/coling/raop_play/orig/aexcl_lib.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/aexcl_lib.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/aexcl_lib.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/aexcl_lib.h (added)
+++ branches/coling/raop_play/orig/aexcl_lib.h Fri May  2 02:16:10 2008
@@ -1,0 +1,108 @@
+#include <stdio.h>
+#include <asm/types.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <string.h>
+
+#ifndef __AEXCL_LIB_H_
+#define __AEXCL_LIB_H_
+
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#define ERRMSG(args...) syslog(LOG_ERR, args)
+#define INFMSG(args...) syslog(LOG_INFO, args)
+#define DBGMSG(args...) syslog(LOG_DEBUG, args)
+#else
+#define ERRMSG(args...) fprintf(stderr,"ERR: " args)
+#define INFMSG(args...) fprintf(stderr,"INFO: " args)
+#define DBGMSG(args...) fprintf(stderr,"DBG: " args)
+#endif
+
+#define SLEEP_SEC(val) sleep(val)
+#define SLEEP_MSEC(val) usleep(val*1000)
+#define SLEEP_USEC(val) usleep(val)
+
+#undef BEGIN_C_DECLS
+#undef END_C_DECLS
+#ifdef __cplusplus
+#define BEGIN_C_DECLS extern "C" {
+#define END_C_DECLS }
+#else
+#define BEGIN_C_DECLS
+#define END_C_DECLS
+#endif
+
+
+BEGIN_C_DECLS
+
+static inline int get_10munit_time(void)
+{
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+  return (tv.tv_sec&0x00FFFFFF)*100+tv.tv_usec/10000;
+}
+
+static inline int lf_to_null(char *sline, int linelen)
+{
+  int i;
+  for(i=0;i<linelen;i++) {
+    if(sline[i]=='\n') {
+      sline[i]=0;
+      return i;
+    }else if(sline[i]==0){
+      return i;
+    }
+  }
+  return -1;
+}
+
+
+/*
+ * if newsize < 4096, align the size to power of 2
+ */
+static inline int realloc_memory(void **p, int newsize, const char *func)
+{
+  void *np;
+  int i=0;
+  int n=16;
+  for(i=0;i<8;i++){
+    if(newsize<=n){
+      newsize=n;
+      break;
+    }
+    n=n<<1;
+  }
+  newsize=newsize;
+  np=realloc(*p,newsize);
+  if(!np){
+    ERRMSG("%s: realloc failed: %s\n",func,strerror(errno));
+    return -1;
+  }
+  *p=np;
+  return 0;
+}
+
+#define GET_BIGENDIAN_INT(x) (*(__u8*)(x)<<24)|(*((__u8*)(x)+1)<<16)|(*((__u8*)(x)+2)<<8)|(*((__u8*)(x)+3))
+
+typedef struct key_data_t {
+  __u8 *key;
+  __u8 *data;
+}key_data_t;
+
+
+int open_tcp_socket(char *hostname, unsigned short *port);
+int get_tcp_connect_by_host(int sd, char *host, __u16 destport);
+int get_tcp_connect(int sd, struct sockaddr_in dest_addr);
+int bind_host(int sd, char *hostname, unsigned long ulAddr,unsigned short *port);
+int read_line(int fd, char *line, int maxlen, int timeout, int no_poll);
+char *kd_lookup(key_data_t *kd, char *key);
+void free_kd(key_data_t *kd);
+int remove_char_from_string(char *str, char rc);
+int child_start(char* const argv[], int *infd, int *outfd, int *errfd);
+
+END_C_DECLS
+
+#endif

Propchange: branches/coling/raop_play/orig/aexcl_lib.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/alsadev.pls
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/alsadev.pls?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/alsadev.pls (added)
+++ branches/coling/raop_play/orig/alsadev.pls Fri May  2 02:16:10 2008
@@ -1,0 +1,1 @@
+File1=/tmp/pcmout

Added: branches/coling/raop_play/orig/audio_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/audio_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/audio_stream.c (added)
+++ branches/coling/raop_play/orig/audio_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,415 @@
+/*****************************************************************************
+ * audio_stream.c: audio file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <samplerate.h>
+#define AUDIO_STREAM_C
+#include "audio_stream.h"
+#include "m4a_stream.h"
+#include "wav_stream.h"
+#include "mp3_stream.h"
+#include "aac_stream.h"
+#include "ogg_stream.h"
+#include "flac_stream.h"
+#include "pls_stream.h"
+#include "pcm_stream.h"
+#include "aexcl_lib.h"
+
+
+static data_type_t get_data_type(char *fname);
+static __s16 *pcm_resample(__s16 *ps, SRC_STATE *st, SRC_DATA *sd,
+         data_source_t *ds, int *bsize, int channels);
+
+auds_t *auds_open(char *fname, data_type_t adt)
+{
+  auds_t *auds=malloc(sizeof(auds_t));
+  if(!auds) return NULL;
+  memset(auds, 0, sizeof(auds_t));
+  int rval=-1;
+  int err;
+
+  auds->channels=2; //default is stereo
+  if(adt==AUD_TYPE_NONE)
+    auds->data_type=get_data_type(fname);
+  else
+    auds->data_type=adt;
+  switch(auds->data_type){
+  case AUD_TYPE_ALAC:
+    rval=m4a_open(auds,fname);
+    if(rval) { // retry AAC
+      rval=aac_open(auds,fname);
+      auds->data_type = AUD_TYPE_AAC;
+    }
+    break;
+  case AUD_TYPE_WAV:
+    rval=wav_open(auds,fname);
+    break;
+  case AUD_TYPE_URLMP3:
+  case AUD_TYPE_MP3:
+    rval=mp3_open(auds, fname);
+    break;
+  case AUD_TYPE_OGG:
+    rval=ogg_open(auds, fname);
+    break;
+  case AUD_TYPE_FLAC:
+    rval=flac_open(auds, fname);
+    break;
+  case AUD_TYPE_AAC:
+    rval=aac_open(auds,fname);
+    break;
+  case AUD_TYPE_PLS:
+    rval=pls_open(auds, fname);
+    break;
+  case AUD_TYPE_PCM:
+    rval=pcm_open(auds, fname);
+    break;
+  case AUD_TYPE_NONE:
+    ERRMSG("unknown audio data type\n");
+    break;
+  }
+  if(rval) goto erexit;
+  if(auds->sample_rate != DEFAULT_SAMPLE_RATE){
+    auds->resamp_st=src_new(SRC_SINC_FASTEST, auds->channels, &err);
+    if(!auds->resamp_st) {
+      ERRMSG("can't open libsamplerate\n");
+      goto erexit;
+    }
+    auds->resamp_buf=(__u16*)malloc(MAX_SAMPLES_IN_CHUNK*2*2);
+    auds->resamp_sd.data_in=(float *)malloc(sizeof(float)*MAX_SAMPLES_IN_CHUNK*2);
+    auds->resamp_sd.data_out=(float *)malloc(sizeof(float)*MAX_SAMPLES_IN_CHUNK*2);
+    auds->resamp_sd.src_ratio=(double)DEFAULT_SAMPLE_RATE/(double)auds->sample_rate;
+    if(!auds->resamp_buf || !auds->resamp_sd.data_in || !auds->resamp_sd.data_out)
+      goto erexit;
+  }
+  return auds;
+ erexit:
+  ERRMSG("errror: %s\n",__func__);
+  auds_close(auds);
+  return NULL;
+}
+
+int auds_close(auds_t *auds)
+{
+  if(auds->stream){
+    switch(auds->data_type){
+    case AUD_TYPE_ALAC:
+      m4a_close(auds);
+      break;
+    case AUD_TYPE_WAV:
+      wav_close(auds);
+      break;
+    case AUD_TYPE_URLMP3:
+    case AUD_TYPE_MP3:
+      mp3_close(auds);
+      break;
+    case AUD_TYPE_OGG:
+      ogg_close(auds);
+      break;
+    case AUD_TYPE_FLAC:
+      flac_close(auds);
+      break;
+    case AUD_TYPE_AAC:
+      aac_close(auds);
+      break;
+    case AUD_TYPE_PLS:
+      pls_close(auds);
+      break;
+    case AUD_TYPE_PCM:
+      pcm_close(auds);
+      break;
+    case AUD_TYPE_NONE:
+      ERRMSG("### shouldn't come here\n");
+      break;
+    }
+  }
+  if(auds->resamp_st){
+    if(auds->resamp_buf) free(auds->resamp_buf);
+    if(auds->resamp_sd.data_in) free(auds->resamp_sd.data_in);
+    if(auds->resamp_sd.data_out) free(auds->resamp_sd.data_out);
+    src_delete(auds->resamp_st);
+  }
+  free(auds);
+  return 0;
+}
+
+int auds_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  if(auds->data_type==AUD_TYPE_PLS){
+    // move to the top song first
+    if(pls_top_song(auds)) return -1;
+    auds=auds->auds;
+  }
+  switch(auds->data_type){
+  case AUD_TYPE_ALAC:
+    return m4a_get_top_sample(auds, data, size);
+  case AUD_TYPE_WAV:
+    return wav_get_top_sample(auds, data, size);
+  case AUD_TYPE_URLMP3:
+  case AUD_TYPE_MP3:
+    return mp3_get_top_sample(auds, data, size);
+  case AUD_TYPE_OGG:
+    return ogg_get_top_sample(auds, data, size);
+  case AUD_TYPE_FLAC:
+    return flac_get_top_sample(auds, data, size);
+  case AUD_TYPE_AAC:
+    return aac_get_top_sample(auds, data, size);
+  case AUD_TYPE_PCM:
+  case AUD_TYPE_PLS:
+  case AUD_TYPE_NONE:
+    ERRMSG("%s:### shouldn't come here\n",__func__);
+    return -1;
+  }
+  return -1;
+}
+
+int auds_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  int rval;
+  auds_t *lauds=auds;
+  if(auds->auds) lauds=auds->auds;
+  switch(lauds->data_type){
+  case AUD_TYPE_ALAC:
+    rval=m4a_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_WAV:
+    rval=wav_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_URLMP3:
+  case AUD_TYPE_MP3:
+    rval=mp3_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_OGG:
+    rval=ogg_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_FLAC:
+    rval=flac_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_AAC:
+    rval=aac_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_PCM:
+    rval=pcm_get_next_sample(lauds, data, size);
+    break;
+  case AUD_TYPE_PLS:
+  case AUD_TYPE_NONE:
+    ERRMSG("%s:### shouldn't come here\n",__func__);
+    return -1;
+  }
+  if(rval && auds->data_type==AUD_TYPE_PLS){
+    // move to the next song
+    if(!pls_next_song(auds)){
+      return auds_get_next_sample(auds, data, size);
+    }
+  }
+  return rval;
+}
+
+/* return -- 1: the next sample exists, 0: it doesn't */
+int auds_poll_next_sample(auds_t *auds)
+{
+  if(auds->data_type==AUD_TYPE_PLS){
+    auds=auds->auds;
+  }
+  switch(auds->data_type){
+  case AUD_TYPE_PCM:
+    return pcm_poll_next_sample(auds);
+  default:
+    break;
+  }
+  return 1;
+}
+
+int auds_sigchld(auds_t *auds, siginfo_t *siginfo)
+{
+  if(!auds) return 0;
+  if(auds->auds && auds->auds->sigchld_cb){
+    auds->auds->sigchld_cb(auds->auds->stream, siginfo);
+    return 0;
+  }
+  if(auds->sigchld_cb){
+    auds->sigchld_cb(auds->stream, siginfo);
+    return 0;
+  }
+  return 0;
+}
+
+
+int auds_write_pcm(auds_t *auds, __u8 *buffer, __u8 **data, int *size,
+       int bsize, data_source_t *ds)
+{
+  __u8 one[4];
+  int count=0;
+  int bpos=0;
+  __u8 *bp=buffer;
+  int i,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;
+  }
+  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
+  if(bsize!=4096)
+    bits_write(&bp,1,1,&bpos); // 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
+  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);
+  }
+  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;
+
+    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);
+    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;
+  *data=buffer;
+  return 0;
+}
+
+int aud_clac_chunk_size(int sample_rate)
+{
+  int bsize=MAX_SAMPLES_IN_CHUNK;
+  int ratio=DEFAULT_SAMPLE_RATE*100/sample_rate;
+  // to make suer the resampled size is <= 4096
+  if(ratio>100) bsize=bsize*100/ratio-1;
+  return bsize;
+}
+
+
+static data_type_t get_data_type(char *fname)
+{
+  int i;
+  for(i=strlen(fname)-1;i>=0;i--)
+    if(fname[i]=='.') break;
+  if(i<0) return AUD_TYPE_PCM;
+  if(i>=strlen(fname)-1) return AUD_TYPE_NONE;
+  if(!strcasecmp(fname+i+1,"wav")) return AUD_TYPE_WAV;
+  if(!strcasecmp(fname+i+1,"m4a")) return AUD_TYPE_ALAC;
+  if(!strcasecmp(fname+i+1,"mp3")) return AUD_TYPE_MP3;
+  if(!strcasecmp(fname+i+1,"ogg")) return AUD_TYPE_OGG;
+  if(!strcasecmp(fname+i+1,"flac")) return AUD_TYPE_FLAC;
+  if(!strcasecmp(fname+i+1,"aac")) return AUD_TYPE_AAC;
+  if(!strcasecmp(fname+i+1,"pls")) return AUD_TYPE_PLS;
+  if(!strcasecmp(fname+i+1,"pcm")) return AUD_TYPE_PCM;
+  if(strstr(fname,"http")==fname) return AUD_TYPE_URLMP3;
+  return AUD_TYPE_NONE;
+}
+
+static __s16 *pcm_resample(__s16 *ps, SRC_STATE *st, SRC_DATA *sd,
+         data_source_t *ds, int *bsize, int channels)
+{
+  int samples, tsamples=0;
+
+
+  if(!ps || !sd->data_in || !sd->data_out) return NULL;
+
+  while(tsamples<MINIMUM_SAMPLE_SIZE && tsamples<*bsize){
+    switch(ds->type){
+    case DESCRIPTOR:
+      samples=read(ds->u.fd,ps+channels*tsamples,*bsize*2*channels);
+      samples=samples/(2*channels);
+      break;
+    case STREAM:
+      samples=fread(ps+channels*tsamples,2,*bsize*channels,ds->u.inf);
+      samples=samples/channels;
+      break;
+    case MEMORY:
+      return NULL; // reample doesn't support MEMORY
+    }
+    if(samples<=0) return NULL;
+    tsamples+=samples;
+  }
+
+  src_short_to_float_array (ps, sd->data_in, tsamples*channels);
+  sd->input_frames=tsamples;
+  sd->output_frames=MAX_SAMPLES_IN_CHUNK;
+#if 0
+  if(tsamples<*bsize)
+    sd->end_of_input=1;
+  else
+    sd->end_of_input=0;
+#endif
+  if(src_process(st,sd)) return NULL;
+  //DBGMSG("tsamples=%d, *bsize=%d, used=%ld, gen=%ld\n",tsamples, *bsize, sd->input_frames_used, sd->output_frames_gen);
+  *bsize=sd->output_frames_gen;
+  src_float_to_short_array(sd->data_out,ps,sd->output_frames_gen*channels);
+  return ps;
+}

Propchange: branches/coling/raop_play/orig/audio_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/audio_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/audio_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/audio_stream.h (added)
+++ branches/coling/raop_play/orig/audio_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,121 @@
+/*****************************************************************************
+ * audio_stream.h: audio file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __AUDIO_STREAM_H_
+#define __AUDIO_STREAM_H_
+
+#include <signal.h>
+
+typedef enum data_type_t {
+  AUD_TYPE_NONE = 0,
+  AUD_TYPE_ALAC,
+  AUD_TYPE_WAV,
+  AUD_TYPE_MP3,
+  AUD_TYPE_OGG,
+  AUD_TYPE_AAC,
+  AUD_TYPE_URLMP3,
+  AUD_TYPE_PLS,
+  AUD_TYPE_PCM,
+  AUD_TYPE_FLAC,
+} data_type_t;
+
+typedef struct auds_t {
+/* public variables */
+  void *stream;
+  int sample_rate;
+  void (*sigchld_cb)(void *, siginfo_t *);
+  int chunk_size;
+  data_type_t data_type;
+  int channels;
+  struct auds_t *auds;
+/* private variables */
+#ifdef AUDIO_STREAM_C
+  SRC_STATE *resamp_st;
+  SRC_DATA resamp_sd;
+  __u16 *resamp_buf;
+#else
+  __u32 dummy;
+#endif
+} auds_t;
+
+
+typedef enum data_source_type_t {
+  DESCRIPTOR=0,
+  STREAM,
+  MEMORY,
+}data_source_type_t;
+typedef struct mem_source_t {
+  int size;
+  __s16 *data;
+}mem_source_t;
+typedef struct data_source_t {
+  data_source_type_t type;
+  union{
+    int fd;
+    FILE *inf;
+    mem_source_t mem;
+  }u;
+}data_source_t;
+
+
+#define DEFAULT_SAMPLE_RATE 44100
+#define MAX_SAMPLES_IN_CHUNK 4096
+
+/*
+ * if I send very small chunk of data, AEX is going to disconnect.
+ * To avoid it, apply this size as the minimum size of chunk.
+ */
+#define MINIMUM_SAMPLE_SIZE 32
+
+auds_t *auds_open(char *fname, data_type_t adt);
+int auds_close(auds_t *auds);
+int auds_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int auds_get_next_sample(auds_t *auds, __u8 **data, int *size);
+int auds_write_pcm(auds_t *auds, __u8 *buffer, __u8 **data, int *size,
+       int bsize, data_source_t *ds);
+int auds_sigchld(auds_t *auds, siginfo_t *siginfo);
+int aud_clac_chunk_size(int sample_rate);
+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;
+  }
+}
+
+#endif

Propchange: branches/coling/raop_play/orig/audio_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/base64.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/base64.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/base64.c (added)
+++ branches/coling/raop_play/orig/base64.c Fri May  2 02:16:10 2008
@@ -1,0 +1,136 @@
+/*
+ * Copyright (c) 1995-2001 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+RCSID("$Id: base64.c,v 1.1.1.1 2005/07/23 13:57:04 shiro Exp $");
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include "base64.h"
+
+static char base64_chars[] =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static int
+pos(char c)
+{
+    char *p;
+    for (p = base64_chars; *p; p++)
+  if (*p == c)
+      return p - base64_chars;
+    return -1;
+}
+
+int
+base64_encode(const void *data, int size, char **str)
+{
+    char *s, *p;
+    int i;
+    int c;
+    const unsigned char *q;
+
+    p = s = (char *) malloc(size * 4 / 3 + 4);
+    if (p == NULL)
+  return -1;
+    q = (const unsigned char *) data;
+    i = 0;
+    for (i = 0; i < size;) {
+  c = q[i++];
+  c *= 256;
+  if (i < size)
+      c += q[i];
+  i++;
+  c *= 256;
+  if (i < size)
+      c += q[i];
+  i++;
+  p[0] = base64_chars[(c & 0x00fc0000) >> 18];
+  p[1] = base64_chars[(c & 0x0003f000) >> 12];
+  p[2] = base64_chars[(c & 0x00000fc0) >> 6];
+  p[3] = base64_chars[(c & 0x0000003f) >> 0];
+  if (i > size)
+      p[3] = '=';
+  if (i > size + 1)
+      p[2] = '=';
+  p += 4;
+    }
+    *p = 0;
+    *str = s;
+    return strlen(s);
+}
+
+#define DECODE_ERROR 0xffffffff
+
+static unsigned int
+token_decode(const char *token)
+{
+    int i;
+    unsigned int val = 0;
+    int marker = 0;
+    if (strlen(token) < 4)
+  return DECODE_ERROR;
+    for (i = 0; i < 4; i++) {
+  val *= 64;
+  if (token[i] == '=')
+      marker++;
+  else if (marker > 0)
+      return DECODE_ERROR;
+  else
+      val += pos(token[i]);
+    }
+    if (marker > 2)
+  return DECODE_ERROR;
+    return (marker << 24) | val;
+}
+
+int
+base64_decode(const char *str, void *data)
+{
+    const char *p;
+    unsigned char *q;
+
+    q = data;
+    for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
+  unsigned int val = token_decode(p);
+  unsigned int marker = (val >> 24) & 0xff;
+  if (val == DECODE_ERROR)
+      return -1;
+  *q++ = (val >> 16) & 0xff;
+  if (marker < 2)
+      *q++ = (val >> 8) & 0xff;
+  if (marker < 1)
+      *q++ = val & 0xff;
+    }
+    return q - (unsigned char *) data;
+}

Propchange: branches/coling/raop_play/orig/base64.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/base64.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/base64.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/base64.h (added)
+++ branches/coling/raop_play/orig/base64.h Fri May  2 02:16:10 2008
@@ -1,0 +1,42 @@
+/*
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id: base64.h,v 1.1.1.1 2005/07/23 13:57:04 shiro Exp $ */
+
+#ifndef _BASE64_H_
+#define _BASE64_H_
+
+int base64_encode(const void *data, int size, char **str);
+int base64_decode(const char *str, void *data);
+
+#endif

Propchange: branches/coling/raop_play/orig/base64.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/flac_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/flac_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/flac_stream.c (added)
+++ branches/coling/raop_play/orig/flac_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,187 @@
+/*****************************************************************************
+ * flac_stream.c: flac file stream
+ *
+ * Copyright (C) 2005 Graziano Obertelli <graziano at acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <netinet/in.h>
+#include <asm/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#define FLAC_STREAM_C
+#include "audio_stream.h"
+#include "flac_stream.h"
+#include "aexcl_lib.h"
+
+#define FLAC_DECODER "flac"
+#define FIFO_NAME "/tmp/flac_stream"
+static int run_decoder(flac_t *flac)
+{
+  char *darg[10]={FLAC_DECODER,"-d","--force-raw-format",
+    "--endian=little", "--sign=signed", "-f", "-o", NULL, NULL, NULL};
+  darg[7]=FIFO_NAME;
+  darg[8]=flac->fname;
+  flac->dpid=child_start(darg,NULL,NULL,NULL);
+  if(!(flac->inf=fopen(FIFO_NAME,"r"))) {
+    ERRMSG("can't open fifo\n");
+    return -1;
+  }
+  return 0;
+}
+
+static int stop_decoder(flac_t *flac)
+{
+  int i;
+
+  if(!flac->dpid) return 0;
+  kill(flac->dpid,SIGTERM);
+  for(i=0;i<10;i++){
+    if(!flac->dpid) return 0;
+    usleep(10*1000);
+  }
+  ERRMSG("decoder process can't be terminated\n");
+  return 0;
+}
+
+static void sigchld_callback(void *p, siginfo_t *siginfo)
+{
+  flac_t *flac=(flac_t*)p;
+  if(siginfo->si_pid==flac->dpid){
+    waitpid(flac->dpid,NULL,0);
+    flac->dpid=0;
+  }
+}
+
+#define NEEDED_LEN (1 + 3 + 10 + 8)
+static int read_header(auds_t *auds, char *fname)
+{
+  FILE *inf;
+  __u8 head[128], tmp;
+  int rsize,i;
+  unsigned int j;
+
+  inf=fopen(fname, "r");
+  if(!inf) return -1;
+  rsize=fread(head,1,128,inf);
+  fclose(inf);
+  for(i=0;i<rsize-4;i++){
+    if(!memcmp(head+i,"fLaC",4)) break;
+  }
+  i += 4;
+  if(rsize-i<NEEDED_LEN){
+    INFMSG("looks not flac file\n");
+    return -1;
+  }
+
+  /* let's mask the first bit to get the metablock type: needs to
+   * be streaminfo (0) */
+  memcpy(&tmp, head+i, 1);
+  if ((tmp & 0x40) != 0) {
+    INFMSG("it's not a streaminfo metablock!\n");
+    return -1;
+  }
+  i += 14;
+
+  /* now the first 20 bits is the sample rate: flac encodes in
+   * big-endian so we might need to translate */
+  memcpy(&j, head+i, 4);
+  j = ntohl(j);
+  j = j >> 12;
+  j = j & 0xFFFFF;
+  if (j < 0) {
+    INFMSG("trouble in getting the sample rate!\n");
+    return -1;
+  }
+  auds->sample_rate=j;
+  i += 2;
+
+  /* and the next 3 bit is the # of channels */
+  memcpy(&tmp, head+i, 1);
+  tmp &= 0xE;
+  tmp = tmp >> 1;
+  DBGMSG("number of channels=%d\n", tmp + 1);
+  auds->channels=tmp + 1;
+
+  /* # encoding bit are in the next 5 bit */
+  memcpy(&j, head+i, 1);
+  j &= 0x1;
+  j = j << 5;
+  memcpy(&tmp, head+i+1, 1);
+  tmp &= 0xF0;
+  tmp = tmp >> 4;
+  tmp = j | tmp;
+  DBGMSG("%d bit\n", tmp + 1);
+
+  return 0;
+}
+
+int flac_open(auds_t *auds, char *fname)
+{
+  flac_t *flac=malloc(sizeof(flac_t));
+  if(!flac) return -1;
+  memset(flac,0,sizeof(flac_t));
+  auds->stream=(void*)flac;
+  flac->fname=(char *)malloc(strlen(fname)+1);
+  if(!flac->fname) goto erexit;
+  strcpy(flac->fname,fname);
+  flac->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!flac->buffer) goto erexit;
+  auds->sigchld_cb=sigchld_callback;
+  if(access(FIFO_NAME,F_OK) && mkfifo(FIFO_NAME,0600)<0){
+    ERRMSG("can't make a named fifo:%s\n",FIFO_NAME);
+    goto erexit;
+  }
+  auds->sample_rate=DEFAULT_SAMPLE_RATE;
+  read_header(auds, fname);
+  if(run_decoder(flac)) goto erexit;
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  return 0;
+ erexit:
+  flac_close(auds);
+  return -1;
+}
+
+int flac_close(auds_t *auds)
+{
+  flac_t *flac=(flac_t *)auds->stream;
+  if(!flac) return -1;
+  if(flac->inf) fclose(flac->inf);
+  stop_decoder(flac);
+  unlink(FIFO_NAME);
+  if(flac->buffer) free(flac->buffer);
+  if(flac->fname) free(flac->fname);
+  free(flac);
+  auds->stream=NULL;
+  return 0;
+}
+
+int flac_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  flac_t *flac=(flac_t *)auds->stream;
+  stop_decoder(flac);
+  run_decoder(flac);
+  return flac_get_next_sample(auds, data, size);
+}
+
+int flac_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  flac_t *flac=(flac_t *)auds->stream;
+  data_source_t ds={.type=STREAM, .u.inf=flac->inf};
+  return auds_write_pcm(auds, flac->buffer, data, size, auds->chunk_size, &ds);
+}
+

Propchange: branches/coling/raop_play/orig/flac_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/flac_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/flac_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/flac_stream.h (added)
+++ branches/coling/raop_play/orig/flac_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,44 @@
+/*****************************************************************************
+ * flac_stream.h: flac file stream, header file
+ *
+ * Copyright (C) 2005 Graziano Obertelli <graziano at acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __FLAC_STREAM_H_
+#define __FLAC_STREAM_H_
+
+
+typedef struct flac_t {
+/* public variables */
+/* private variables */
+#ifdef FLAC_STREAM_C
+  FILE *inf;
+  int dpid;
+  __u8 *buffer;
+  char *fname;
+#else
+  __u32 dummy;
+#endif
+} flac_t;
+
+
+int flac_open(auds_t *auds, char *fname);
+int flac_close(auds_t *auds);
+int flac_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int flac_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/flac_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/m4a_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/m4a_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/m4a_stream.c (added)
+++ branches/coling/raop_play/orig/m4a_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,327 @@
+/*****************************************************************************
+ * m4a_stream.c: .m4a file stream
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <asm/types.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "aexcl_lib.h"
+#include "audio_stream.h"
+#include "m4a_stream.h"
+
+#define BUF_SIZE (8*1024)
+#define CROSS_RECOVER_SIZE 4
+
+#define AtomALAC "alac"
+#define AtomSTSZ "stsz"
+#define AtomSTCO "stco"
+#define AtomCO64 "co64"
+#define AtomSTSC "stsc"
+
+typedef struct m4asd_t {
+  __u8 buf[BUF_SIZE+CROSS_RECOVER_SIZE];
+  int bufp;
+  int vdata_size;
+  __u8 *sst; // sample size table
+  __u8 *cot; // chunk offset table
+  __u8 *cst; // chunk samples table
+  int nsst; // number of data in sst
+  int ncot; // number of data in cot
+  int ncst; // number of data in cst
+  int cur_chunk; // current chunk number
+  int cur_sp; // current sample number
+  int cur_sp_in_chunk; // current sample number in chunk
+  int cur_cst_index; // current chunk size table index
+  int cur_pos; // current file position
+  int co_size; // chunk offset data size, 4:32 bits, 8:64 bits
+  __u8 *read_data;
+  int read_data_size;
+  FILE *inf;
+}m4asd_t;
+
+static inline int big_end_int(__u8 *p)
+{
+  return (*p<<24) | (*(p+1)<<16) | (*(p+2)<<8) | *(p+3);
+}
+
+static int read_buf(m4asd_t *m4asd, int cover_copy)
+{
+  int size;
+  if(cover_copy){
+    memcpy(m4asd->buf, m4asd->buf+BUF_SIZE, CROSS_RECOVER_SIZE);
+    m4asd->bufp=0;
+  }else{
+    m4asd->bufp=CROSS_RECOVER_SIZE;
+  }
+  size=fread(m4asd->buf+CROSS_RECOVER_SIZE,1,BUF_SIZE,m4asd->inf);
+  if(size==-1){
+    ERRMSG("%s: read error: %s\n",__func__,strerror(errno));
+    return -1;
+  }
+  m4asd->vdata_size=size+CROSS_RECOVER_SIZE;
+  return size;
+}
+
+static int find_atom_pos(m4asd_t *m4asd, char *atom)
+{
+  while(1){
+    if(m4asd->vdata_size-m4asd->bufp<4) {
+      if(read_buf(m4asd, 1)<=0) {
+        ERRMSG("%s: %s can't be found in the file\n",__func__,atom);
+        return -1;
+      }
+    }
+    while(m4asd->bufp<m4asd->vdata_size-3){
+      if(m4asd->buf[m4asd->bufp]==atom[0] &&
+         m4asd->buf[m4asd->bufp+1]==atom[1] &&
+         m4asd->buf[m4asd->bufp+2]==atom[2] &&
+         m4asd->buf[m4asd->bufp+3]==atom[3] ) {
+        return 0;
+      }
+      m4asd->bufp++;
+    }
+  }
+  return -1;
+}
+
+static int get_atom_data(m4asd_t *m4asd, __u8 **data)
+{
+  int dsize, size,cpsize;
+  __u8 *dp;
+  size=big_end_int(m4asd->buf+m4asd->bufp-4);
+  dsize=size;
+  if(size<8) return -1;
+  size-=8;
+  if(realloc_memory((void**)data, size, __func__)) return -1;
+  dp=*data;
+  m4asd->bufp+=4;
+  while(size>0){
+    if(m4asd->vdata_size-m4asd->bufp <= 0){
+      if(read_buf(m4asd, 0)<=0) {
+        ERRMSG("%s: reached bottom of the file\n",__func__);
+        return -1;
+      }
+    }
+    cpsize=(size < m4asd->vdata_size-m4asd->bufp)?size:m4asd->vdata_size-m4asd->bufp;
+    memcpy(dp,m4asd->buf+m4asd->bufp,cpsize);
+    size-=cpsize;
+    dp+=cpsize;
+    m4asd->bufp+=cpsize;
+  }
+  return dsize;
+}
+
+/*
+ * return sample size table data in *data which is allocated in this function
+ * number of data at data+8 (big endian)
+ * sample size at data+12+4*i (big endian)
+ * return value : number of data, -1 if error
+ */
+static int get_sample_size_table(m4asd_t *m4asd, __u8 **data)
+{
+  int rval=-1;
+  int size;
+  if(find_atom_pos(m4asd, AtomSTSZ)) return -1;
+  if((size=get_atom_data(m4asd, data))<0) goto erexit;
+  return big_end_int(*data+8);
+ erexit:
+  if(*data) free(*data);
+  *data=NULL;
+  return rval;
+}
+
+/*
+ * return chunk offset table data in *data which is allocated in this function
+ * number of data at data+4 (big endian)
+ * chunk offset at data+8+4*i (big endian)
+ *              at data+8+8*i if *co64==1 (32 bits big endian)
+ * return value : number of data, -1 if error
+ */
+static int get_chunk_offset_table(m4asd_t *m4asd, __u8 **data)
+{
+  int rval=-1;
+  int size;
+
+  m4asd->co_size=4;
+  if(find_atom_pos(m4asd, AtomSTCO)){
+    if(find_atom_pos(m4asd, AtomCO64)) goto erexit;
+    m4asd->co_size=8;
+  }
+  if((size=get_atom_data(m4asd, data))<0) goto erexit;
+  return big_end_int(*data+4);
+ erexit:
+  if(*data) free(*data);
+  *data=NULL;
+  return rval;
+}
+
+
+/*
+ * return chunk samples table data in *data which is allocated in this function
+ * number of data at data+4 (big endian)
+ * first chunk number table: data+8+(i*12), (big endian)
+ * "number of sample in a chunk" table: data+12+(i*12), (big endian)
+ * return value : number of data, -1 if error
+ */
+static int get_chunk_samples_table(m4asd_t *m4asd, __u8 **data)
+{
+  int rval=-1;
+  int size;
+  if(find_atom_pos(m4asd, AtomSTSC)) return -1;
+  if((size=get_atom_data(m4asd, data))<0) goto erexit;
+  return big_end_int(*data+4);
+ erexit:
+  if(*data) free(*data);
+  *data=NULL;
+  return rval;
+}
+
+static int get_next_pos(m4asd_t *m4asd, int *pos, int *size)
+{
+  int sinc;
+  int next_first_chunk;
+  __u8 *co;
+
+  if(m4asd->cur_chunk>=m4asd->ncot) return -1;
+  if(!m4asd->cur_pos){
+    if(m4asd->co_size==4){
+      m4asd->cur_pos=big_end_int(m4asd->cot+8);
+    }else{
+      // ignore upper 4 bytes
+      m4asd->cur_pos=big_end_int(m4asd->cot+8+4);
+    }
+  }
+  *pos=m4asd->cur_pos;
+  *size=big_end_int(m4asd->sst+12+4*m4asd->cur_sp);
+  sinc=big_end_int(m4asd->cst+12+m4asd->cur_cst_index*12);
+
+  m4asd->cur_pos+=*size;
+  m4asd->cur_sp_in_chunk++;
+  m4asd->cur_sp++;
+  if(m4asd->cur_sp_in_chunk>=sinc){
+    // the sample reached to the end of this chunk, increment it
+    m4asd->cur_chunk++;
+    m4asd->cur_sp_in_chunk=0;
+    if(m4asd->cur_chunk>=m4asd->ncot) return 0; // this will fail at the next time
+    if(m4asd->cur_cst_index<m4asd->ncst-1){
+      // check if sample per chunk data need to be updated
+      next_first_chunk=big_end_int(m4asd->cst+8+(m4asd->cur_cst_index+1)*12);
+      if(m4asd->cur_chunk>=next_first_chunk)
+        m4asd->cur_cst_index++;
+    }
+
+    co=m4asd->cot+8+m4asd->co_size*m4asd->cur_chunk;
+    if(m4asd->co_size==4){
+      m4asd->cur_pos=big_end_int(co);
+    }else{
+      // ignore upper 4 bytes
+      m4asd->cur_pos=big_end_int(co+4);
+    }
+    //DBGMSG("%s:chunk is updated next pos=0x%x\n",__func__,m4asd->cur_pos);
+  }
+  return 0;
+}
+
+
+int m4a_open(auds_t *auds, char *fname)
+{
+  m4asd_t *m4asd;
+
+  m4asd=(m4asd_t *)malloc(sizeof(m4asd_t));
+  if(!m4asd) return -1;
+  memset(m4asd, 0, sizeof(m4asd_t));
+  auds->stream=(void *)m4asd;
+
+  m4asd->inf=fopen(fname,"r");
+  if(!m4asd->inf){
+    ERRMSG("%s can't open %s\n",__func__,fname);
+    goto erexit;
+  }
+
+  if(read_buf(m4asd, 0)<0) goto erexit;
+  if(find_atom_pos(m4asd, AtomALAC)) goto erexit;
+  if((m4asd->ncst=get_chunk_samples_table(m4asd,&m4asd->cst))==-1) goto erexit;
+  if((m4asd->nsst=get_sample_size_table(m4asd,&m4asd->sst))==-1) goto erexit;
+  if((m4asd->ncot=get_chunk_offset_table(m4asd,&m4asd->cot))==-1) goto erexit;
+  return 0;
+
+ erexit:
+  m4a_close(auds);
+  return -1;
+}
+
+int m4a_close(auds_t *auds)
+{
+  m4asd_t *m4asd=(m4asd_t *)auds->stream;
+  if(!m4asd) return -1;
+  if(m4asd->inf) fclose(m4asd->inf);
+  if(m4asd->sst) free(m4asd->sst);
+  if(m4asd->cot) free(m4asd->cot);
+  if(m4asd->cst) free(m4asd->cst);
+  if(m4asd->read_data) free(m4asd->read_data);
+  free(m4asd);
+  auds->stream=NULL;
+  return 0;
+}
+
+
+int m4a_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  m4asd_t *m4asd=(m4asd_t *)auds->stream;
+
+  if(!m4asd) return -1;
+  m4asd->cur_chunk=0;
+  m4asd->cur_sp=0;
+  m4asd->cur_sp_in_chunk=0;
+  m4asd->cur_pos=0;
+  return m4a_get_next_sample(auds, data, size);
+}
+
+int m4a_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  m4asd_t *m4asd=(m4asd_t *)auds->stream;
+  int pos;
+  int rsize;
+
+  if(!m4asd) return -1;
+  if(get_next_pos(m4asd, &pos, size)) return -1;
+  //DBGMSG("%s:next pos=0x%x, size=0x%x(%d)\n",__func__,pos,*size,*size);
+  if(*size<=0) return -1;
+  if(*size>0x80000) return -1; // shouldn't be this big
+  fseek(m4asd->inf,pos,SEEK_SET);
+  if(m4asd->read_data_size<*size) {
+    if(realloc_memory((void**)&m4asd->read_data,*size,__func__)) return -1;
+    m4asd->read_data_size=*size;
+  }
+  rsize=fread(m4asd->read_data,1,*size,m4asd->inf);
+  if(*size!=rsize){
+    ERRMSG("%s:can't read the size of data, indicated size=%d, read size=%d\n",
+           __func__,*size,rsize);
+    return -1;
+  }
+  *data=m4asd->read_data;
+  return 0;
+}
+
+
+
+

Propchange: branches/coling/raop_play/orig/m4a_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/m4a_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/m4a_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/m4a_stream.h (added)
+++ branches/coling/raop_play/orig/m4a_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,31 @@
+/*****************************************************************************
+ * m4a_stream.h: .m4a file stream, header file
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __M4A_STREAM_H_
+#define __M4A_STREAM_H_
+
+typedef struct m4a_t {__u32 dummy;} m4a_t;
+
+int m4a_open(auds_t *auds, char *fname);
+int m4a_close(auds_t *auds);
+int m4a_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int m4a_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/m4a_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/mp3_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/mp3_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/mp3_stream.c (added)
+++ branches/coling/raop_play/orig/mp3_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,212 @@
+/*****************************************************************************
+ * mp3_stream.c: mp3 file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <id3tag.h>
+#define MP3_STREAM_C
+#include "audio_stream.h"
+#include "mp3_stream.h"
+#include "aexcl_lib.h"
+
+#define MP3_DECODER "mpg321"
+static int run_decoder(auds_t *auds, mp3_t *mp3)
+{
+  char *darg[4]={MP3_DECODER,"-s",NULL, NULL};
+  int efd;
+  char buf[1024];
+  char *bufp;
+  int rsize,tsize=0,i;
+  int rval=-1;
+
+  darg[2]=mp3->fname;
+  if(auds->data_type==AUD_TYPE_MP3){
+    mp3->dpid=child_start(darg,&mp3->dfd,NULL,NULL);
+    return 0;
+  }
+  /* for AUD_TYPE_URLMP3, get sample rate from the stderr
+     message of the decoder. This way may work for all and I don't need read_header. */
+  mp3->dpid=child_start(darg,&mp3->dfd,NULL,&efd);
+  i=0;
+  while(1){
+    // need some time to start getting data from http://..., 3 sec should be enough
+    if(i==30 || tsize>=1023){
+      INFMSG("can't get sample rate from %s\n",mp3->fname);
+      goto erexit;
+    }
+    rsize=read(efd,buf+tsize,1023-tsize);
+    if(rsize<=0) goto erexit;
+    tsize+=rsize;
+    buf[tsize]=0;
+    if((bufp=strstr(buf,"Hz"))) break;
+    usleep(100000); // 100msec
+    i++;
+  }
+  if(!memcmp(bufp+3,"mono",4)){
+    auds->channels=1;
+  }
+  bufp--;
+  while(bufp-- > buf)
+    if(*(bufp)>'9' || *(bufp)<'0') break;
+  auds->sample_rate=atoi(++bufp);
+  DBGMSG("sample rate=%d, channels=%d\n",auds->sample_rate, auds->channels);
+  rval=0;
+ erexit:
+  close(efd);
+  return rval;
+}
+
+static int stop_decoder(mp3_t *mp3)
+{
+  int i;
+
+  if(!mp3->dpid) return 0;
+  kill(mp3->dpid,SIGTERM);
+  for(i=0;i<10;i++){
+    if(!mp3->dpid) return 0;
+    usleep(10*1000);
+  }
+  ERRMSG("decoder process can't be terminated\n");
+  return 0;
+}
+
+static void sigchld_callback(void *p, siginfo_t *siginfo)
+{
+  mp3_t *mp3=(mp3_t*)p;
+  if(siginfo->si_pid==mp3->dpid){
+    waitpid(mp3->dpid,NULL,0);
+    mp3->dpid=0;
+  }
+}
+
+static int read_header(auds_t *auds, char *fname)
+{
+  FILE *inf;
+  __u8 head[4];
+  int ver, srate;
+  int rnum[3][3]={{44100,48000,32000},
+          {22050,24000,16000},
+          {11025,12000,8000},
+  };
+  id3_length_t headerStart = 0;
+  struct id3_file *id3file;
+  struct id3_tag *id3tag;
+
+  /* get id3tag size */
+  id3file = id3_file_open(fname,ID3_FILE_MODE_READONLY);
+  if (id3file) {
+    id3tag = id3_file_tag(id3file);
+    if (id3tag) {
+      headerStart = id3tag->paddedsize;
+      DBGMSG("id3 tagsize: %d\n", (int)id3tag->paddedsize);
+    }
+    id3_file_close(id3file);
+  }else{
+    INFMSG("id3_file_open can't open file, go ahead anyway\n");
+  }
+
+  inf=fopen(fname, "r");
+  if(!inf) return -1;
+
+  fseek(inf,headerStart,SEEK_SET);
+  fread(head,1,4,inf);
+  fclose(inf);
+
+  ver=(head[1]>>3)&0x3;
+  srate=(head[2]>>2)&0x3;
+  if(ver==1 || srate==3){
+    INFMSG("mp3 frame header can't be read, go with default sample rate\n");
+    return -1;
+  }
+  switch(ver){
+  case 0:
+    // 2.5
+    auds->sample_rate=rnum[2][srate];
+    break;
+  case 1:
+    // reserved
+    break;
+  case 2:
+    // 2
+    auds->sample_rate=rnum[1][srate];
+    break;
+  case 3:
+    // 1
+    auds->sample_rate=rnum[0][srate];
+    break;
+  }
+  DBGMSG("sample rate=%d\n",auds->sample_rate);
+  return 0;
+}
+
+
+int mp3_open(auds_t *auds, char *fname)
+{
+  mp3_t *mp3=malloc(sizeof(mp3_t));
+  if(!mp3) return -1;
+  memset(mp3,0,sizeof(mp3_t));
+  auds->stream=(void*)mp3;
+  mp3->fname=(char *)malloc(strlen(fname)+1);
+  if(!mp3->fname) goto erexit;
+  strcpy(mp3->fname,fname);
+  mp3->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!mp3->buffer) goto erexit;
+  auds->sigchld_cb=sigchld_callback;
+  auds->sample_rate=DEFAULT_SAMPLE_RATE;
+  if(auds->data_type==AUD_TYPE_MP3)
+    read_header(auds, fname);
+  run_decoder(auds, mp3);
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  return 0;
+ erexit:
+  mp3_close(auds);
+  return -1;
+}
+
+int mp3_close(auds_t *auds)
+{
+  mp3_t *mp3=(mp3_t *)auds->stream;
+  if(!mp3) return -1;
+  if(mp3->dfd>=0) close(mp3->dfd);
+  stop_decoder(mp3);
+  if(mp3->buffer) free(mp3->buffer);
+  if(mp3->fname) free(mp3->fname);
+  free(mp3);
+  auds->stream=NULL;
+  return 0;
+}
+
+int mp3_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  mp3_t *mp3=(mp3_t *)auds->stream;
+  stop_decoder(mp3);
+  run_decoder(auds, mp3);
+  return mp3_get_next_sample(auds, data, size);
+}
+
+int mp3_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  mp3_t *mp3=(mp3_t *)auds->stream;
+  data_source_t ds={.type=DESCRIPTOR, .u.fd=mp3->dfd};
+  return auds_write_pcm(auds, mp3->buffer, data, size, auds->chunk_size, &ds);
+}
+

Propchange: branches/coling/raop_play/orig/mp3_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/mp3_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/mp3_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/mp3_stream.h (added)
+++ branches/coling/raop_play/orig/mp3_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,44 @@
+/*****************************************************************************
+ * mp3_stream.h: mp3 file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __MP3_STREAM_H_
+#define __MP3_STREAM_H_
+
+
+typedef struct mp3_t {
+/* public variables */
+/* private variables */
+#ifdef MP3_STREAM_C
+  int dfd;
+  int dpid;
+  __u8 *buffer;
+  char *fname;
+#else
+  __u32 dummy;
+#endif
+} mp3_t;
+
+
+int mp3_open(auds_t *auds, char *fname);
+int mp3_close(auds_t *auds);
+int mp3_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int mp3_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/mp3_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/ogg_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/ogg_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/ogg_stream.c (added)
+++ branches/coling/raop_play/orig/ogg_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,168 @@
+/*****************************************************************************
+ * ogg_stream.c: ogg file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#define OGG_STREAM_C
+#include "audio_stream.h"
+#include "ogg_stream.h"
+#include "aexcl_lib.h"
+
+#define OGG_DECODER "ogg123"
+#define FIFO_NAME "/tmp/ogg_stream"
+static int run_decoder(ogg_t *ogg)
+{
+  char *darg[9]={OGG_DECODER,"-d","raw", "-o", "byteorder:little", "-f",
+           NULL, NULL, NULL};
+  darg[6]=FIFO_NAME;
+  darg[7]=ogg->fname;
+  ogg->dpid=child_start(darg,NULL,NULL,NULL);
+  if(!(ogg->inf=fopen(FIFO_NAME,"r"))) {
+    ERRMSG("can't open fifo\n");
+    return -1;
+  }
+  return 0;
+}
+
+static int stop_decoder(ogg_t *ogg)
+{
+  int i;
+
+  if(!ogg->dpid) return 0;
+  kill(ogg->dpid,SIGTERM);
+  for(i=0;i<10;i++){
+    if(!ogg->dpid) return 0;
+    usleep(10*1000);
+  }
+  ERRMSG("decoder process can't be terminated\n");
+  return 0;
+}
+
+static void sigchld_callback(void *p, siginfo_t *siginfo)
+{
+  ogg_t *ogg=(ogg_t*)p;
+  if(siginfo->si_pid==ogg->dpid){
+    waitpid(ogg->dpid,NULL,0);
+    ogg->dpid=0;
+  }
+}
+
+typedef struct vorbis_head_t{
+  __u8 packtype;
+  __u8 name[6];
+  __u32 version;
+  __u8 channel;
+  __u32 rate;
+  __u32 bitrate_upper;
+  __u32 bitrate_nominal;
+  __u32 bitrate_lower;
+  __u32 blocksize[2];
+}__attribute__ ((packed)) vorbis_head_t;
+
+static int read_header(auds_t *auds, char *fname)
+{
+  FILE *inf;
+  __u8 head[1024];
+  vorbis_head_t *vh;
+  int rsize,i,j;
+
+  inf=fopen(fname, "r");
+  if(!inf) return -1;
+  rsize=fread(head,1,1024,inf);
+  fclose(inf);
+  for(i=0;i<rsize-4;i++){
+    if(!memcmp(head+i,"OggS",4)) break;
+  }
+  if(rsize-i-4<sizeof(vorbis_head_t)){
+    INFMSG("looks not ogg file\n");
+    return -1;
+  }
+  for(j=i+4;j<rsize-sizeof(vorbis_head_t);j++){
+    if(!memcmp(head+j,"\001vorbis",7)) break;
+  }
+  if(j==rsize-sizeof(vorbis_head_t)){
+    INFMSG("not vorbis, can't get sample rate info.\n");
+    return -1;
+  }
+  vh=(vorbis_head_t *)(head+j);
+  //DBGMSG("channel=%d, sample rate=%d, bitrate=%d",
+  //       vh->channel, vh->rate, vh->bitrate_nominal);
+  auds->sample_rate=vh->rate;
+  auds->channels=vh->channel;
+  return 0;
+}
+
+int ogg_open(auds_t *auds, char *fname)
+{
+  ogg_t *ogg=malloc(sizeof(ogg_t));
+  if(!ogg) return -1;
+  memset(ogg,0,sizeof(ogg_t));
+  auds->stream=(void*)ogg;
+  ogg->fname=(char *)malloc(strlen(fname)+1);
+  if(!ogg->fname) goto erexit;
+  strcpy(ogg->fname,fname);
+  ogg->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!ogg->buffer) goto erexit;
+  auds->sigchld_cb=sigchld_callback;
+  if(access(FIFO_NAME,F_OK) && mkfifo(FIFO_NAME,0600)<0){
+    ERRMSG("can't make a named fifo:%s\n",FIFO_NAME);
+    goto erexit;
+  }
+  auds->sample_rate=DEFAULT_SAMPLE_RATE;
+  read_header(auds, fname);
+  if(run_decoder(ogg)) goto erexit;
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  return 0;
+ erexit:
+  ogg_close(auds);
+  return -1;
+}
+
+int ogg_close(auds_t *auds)
+{
+  ogg_t *ogg=(ogg_t *)auds->stream;
+  if(!ogg) return -1;
+  if(ogg->inf) fclose(ogg->inf);
+  stop_decoder(ogg);
+  unlink(FIFO_NAME);
+  if(ogg->buffer) free(ogg->buffer);
+  if(ogg->fname) free(ogg->fname);
+  free(ogg);
+  auds->stream=NULL;
+  return 0;
+}
+
+int ogg_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  ogg_t *ogg=(ogg_t *)auds->stream;
+  stop_decoder(ogg);
+  run_decoder(ogg);
+  return ogg_get_next_sample(auds, data, size);
+}
+
+int ogg_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  ogg_t *ogg=(ogg_t *)auds->stream;
+  data_source_t ds={.type=STREAM, .u.inf=ogg->inf};
+  return auds_write_pcm(auds, ogg->buffer, data, size, auds->chunk_size, &ds);
+}
+

Propchange: branches/coling/raop_play/orig/ogg_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/ogg_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/ogg_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/ogg_stream.h (added)
+++ branches/coling/raop_play/orig/ogg_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,44 @@
+/*****************************************************************************
+ * ogg_stream.h: ogg file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __OGG_STREAM_H_
+#define __OGG_STREAM_H_
+
+
+typedef struct ogg_t {
+/* public variables */
+/* private variables */
+#ifdef OGG_STREAM_C
+  FILE *inf;
+  int dpid;
+  __u8 *buffer;
+  char *fname;
+#else
+  __u32 dummy;
+#endif
+} ogg_t;
+
+
+int ogg_open(auds_t *auds, char *fname);
+int ogg_close(auds_t *auds);
+int ogg_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int ogg_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/ogg_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/pcm_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/pcm_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/pcm_stream.c (added)
+++ branches/coling/raop_play/orig/pcm_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,102 @@
+/*****************************************************************************
+ * wav_stream.c: wave file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <unistd.h>
+#include <fcntl.h>
+#include <asm/types.h>
+#include <stdio.h>
+#include <sys/poll.h>
+#define PCM_STREAM_C_
+#include "audio_stream.h"
+#include "pcm_stream.h"
+#include "aexcl_lib.h"
+#include "raop_play.h"
+
+
+int pcm_open(auds_t *auds, char *fname)
+{
+  pcm_t *pcm=malloc(sizeof(pcm_t));
+  if(!pcm) return -1;
+  memset(pcm,0,sizeof(pcm_t));
+  auds->stream=(void *)pcm;
+  pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);
+  if(pcm->dfd<0) goto erexit;
+  auds->sample_rate=DEFAULT_SAMPLE_RATE;
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  pcm->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!pcm->buffer) goto erexit;
+  return 0;
+ erexit:
+  pcm_close(auds);
+  return -1;
+}
+
+int pcm_close(auds_t *auds)
+{
+  pcm_t *pcm=(pcm_t *)auds->stream;
+  if(!pcm) return -1;
+  if(pcm->dfd>=0) close(pcm->dfd);
+  if(pcm->buffer) free(pcm->buffer);
+  free(pcm);
+  auds->stream=NULL;
+  return 0;
+}
+
+int pcm_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  int rval;
+  pcm_t *pcm=(pcm_t *)auds->stream;
+  int bsize=auds->chunk_size;
+  data_source_t ds={.type=MEMORY};
+  __u8 *rbuf=NULL;
+  if(!(rbuf=(__u8*)malloc(bsize*4))) return -1;
+  memset(rbuf,0,bsize*4);
+  /* ds.u.mem.size, ds.u.mem.data */
+  ds.u.mem.size=read(pcm->dfd,rbuf,bsize*4);
+  if(ds.u.mem.size<0){
+    ERRMSG("%s: data read error(%s)\n", __func__, strerror(errno));
+    return -1;
+  }
+  if(ds.u.mem.size<MINIMUM_SAMPLE_SIZE*4){
+    //INFMSG("%s: too small chunk of data(size=%d), add null data\n",__func__, ds.u.mem.size);
+    ds.u.mem.size=MINIMUM_SAMPLE_SIZE*4;
+  }
+  ds.u.mem.data=(__s16*)rbuf;
+  bsize=ds.u.mem.size/4;
+  rval=auds_write_pcm(auds, pcm->buffer, data, size, bsize, &ds);
+  free(rbuf);
+  return rval;
+}
+
+
+int pcm_poll_next_sample(auds_t *auds)
+{
+  struct  pollfd pfds[1];
+  pcm_t *pcm=(pcm_t *)auds->stream;
+  pfds[0].fd=pcm->dfd;
+  pfds[0].events=POLLIN;
+  poll(pfds,1,0);
+  //DBGMSG("%s:revents=0x%x\n",__func__,pfds[0].revents);
+  if(!pfds[0].revents)
+    set_fd_event(pcm->dfd, RAOP_FD_READ, NULL, NULL);
+  else
+    clear_fd_event(pcm->dfd);
+
+  return pfds[0].revents&POLLIN;
+}

Propchange: branches/coling/raop_play/orig/pcm_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/pcm_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/pcm_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/pcm_stream.h (added)
+++ branches/coling/raop_play/orig/pcm_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,40 @@
+/*****************************************************************************
+ * pcm_stream.h: pcme file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __PCM_STREAM_H_
+#define __PCM_STREAM_H_
+
+typedef struct pcm_t {
+/* public variables */
+/* private variables */
+#ifdef PCM_STREAM_C_
+  int dfd;
+  __u8 *buffer;
+#else
+  __u32 dummy;
+#endif
+} pcm_t;
+
+
+int pcm_open(auds_t *auds, char *fname);
+int pcm_close(auds_t *auds);
+int pcm_get_next_sample(auds_t *auds, __u8 **data, int *size);
+int pcm_poll_next_sample(auds_t *auds);
+
+#endif

Propchange: branches/coling/raop_play/orig/pcm_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/pls_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/pls_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/pls_stream.c (added)
+++ branches/coling/raop_play/orig/pls_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,114 @@
+/*****************************************************************************
+ * pls_stream.c: pls file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#define PLS_STREAM_C
+#include "audio_stream.h"
+#include "pls_stream.h"
+#include "aexcl_lib.h"
+
+
+
+static int str_termlf(char *line)
+{
+  int i;
+  for(i=0;i<strlen(line);i++){
+    if(line[i]=='\n'){
+      line[i]=0;
+      return i;
+    }
+  }
+  return 0;
+}
+
+static int pls_next_open(auds_t *auds, pls_t *pls)
+{
+  size_t len=1024;
+  char *line=(char *)malloc(len);
+  int lsize,lp,i, findex;
+
+  if(auds->auds) auds_close(auds->auds);
+  auds->auds=NULL;
+  if(!line) return -1;
+  pls->index++;
+  while((lsize=getline(&line,&len,pls->inf))>0){
+    if(strstr(line,"File")!=line) continue;
+    str_termlf(line);
+    for(i=4;i<lsize;i++){
+      if(line[i]!='=') continue;
+      lp=i+1;
+      line[i]=0;
+      findex=atoi(line+4);
+      if(pls->index!=findex) break;
+      if((auds->auds=auds_open(line+lp, 0))) return 0;
+      return -1;
+    }
+  }
+  return -1;
+}
+
+
+int pls_open(auds_t *auds, char *fname)
+{
+  pls_t *pls=malloc(sizeof(pls_t));
+
+  if(!pls) return -1;
+  memset(pls,0,sizeof(pls_t));
+  auds->stream=(void*)pls;
+  pls->fname=(char *)malloc(strlen(fname)+1);
+  if(!pls->fname) goto erexit;
+  strcpy(pls->fname,fname);
+  if(!(pls->inf=fopen(pls->fname,"r"))) goto erexit;
+  pls->index=0;
+  return pls_next_open(auds, pls);
+ erexit:
+  pls_close(auds);
+  return -1;
+}
+
+int pls_close(auds_t *auds)
+{
+  pls_t *pls=(pls_t *)auds->stream;
+  if(auds->auds) auds_close(auds->auds);
+  if(!pls) return -1;
+  if(pls->inf) fclose(pls->inf);
+  if(pls->fname) free(pls->fname);
+  free(pls);
+  auds->stream=NULL;
+  return 0;
+}
+
+int pls_top_song(auds_t *auds)
+{
+  pls_t *pls=(pls_t *)auds->stream;
+  pls->index=0;
+  fseek(pls->inf, 0, SEEK_SET);
+  return pls_next_open(auds, pls);
+}
+
+int pls_next_song(auds_t *auds)
+{
+  pls_t *pls=(pls_t *)auds->stream;
+  return pls_next_open(auds, pls);
+}

Propchange: branches/coling/raop_play/orig/pls_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/pls_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/pls_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/pls_stream.h (added)
+++ branches/coling/raop_play/orig/pls_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,43 @@
+/*****************************************************************************
+ * pls_stream.h: pls file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __PLS_STREAM_H_
+#define __PLS_STREAM_H_
+
+
+typedef struct pls_t {
+/* public variables */
+/* private variables */
+#ifdef PLS_STREAM_C
+  char *fname;
+  int index;
+  FILE *inf;
+#else
+  __u32 dummy;
+#endif
+} pls_t;
+
+
+int pls_open(auds_t *auds, char *fname);
+int pls_close(auds_t *auds);
+int pls_next_song(auds_t *auds);
+int pls_top_song(auds_t *auds);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/pls_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/raop_client.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/raop_client.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/raop_client.c (added)
+++ branches/coling/raop_play/orig/raop_client.c Fri May  2 02:16:10 2008
@@ -1,0 +1,486 @@
+/*****************************************************************************
+ * rtsp_client.c: RAOP Client
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <stdio.h>
+#include <unistd.h>
+#include <openssl/err.h>
+#include <openssl/rand.h>
+#include <openssl/rsa.h>
+#include <openssl/engine.h>
+
+#include <asm/types.h>
+#include "aexcl_lib.h"
+#include "rtsp_client.h"
+#include "raop_client.h"
+#include "base64.h"
+#include "aes.h"
+#include "raop_play.h"
+#include "audio_stream.h"
+
+#define JACK_STATUS_DISCONNECTED 0
+#define JACK_STATUS_CONNECTED 1
+
+#define JACK_TYPE_ANALOG 0
+#define JACK_TYPE_DIGITAL 1
+
+#define VOLUME_DEF -30
+#define VOLUME_MIN -144
+#define VOLUME_MAX 0
+
+typedef struct raopcl_data_t {
+  rtspcl_t *rtspcl;
+  __u8 iv[16]; // initialization vector for aes-cbc
+  __u8 nv[16]; // next vector for aes-cbc
+  __u8 key[16]; // key for aes-cbc
+  char *addr; // target host address
+  __u16 rtsp_port;
+  int ajstatus;
+  int ajtype;
+  int volume;
+  int sfd; // stream socket fd
+  int wblk_wsize;
+  int wblk_remsize;
+  pause_state_t pause;
+  int wait_songdone;
+  aes_context ctx;
+  __u8 *data;
+  __u8 min_sdata[MINIMUM_SAMPLE_SIZE*4+16];
+  int min_sdata_size;
+  time_t paused_time;
+  int size_in_aex;
+  struct timeval last_read_tv;
+} raopcl_data_t;
+
+static int rsa_encrypt(__u8 *text, int len, __u8 *res)
+{
+  RSA *rsa;
+  __u8 modules[256];
+  __u8 exponent[8];
+  int size;
+
+        char n[] =
+            "59dE8qLieItsH1WgjrcFRKj6eUWqi+bGLOX1HL3U3GhC/j0Qg90u3sG/1CUtwC"
+            "5vOYvfDmFI6oSFXi5ELabWJmT2dKHzBJKa3k9ok+8t9ucRqMd6DZHJ2YCCLlDR"
+            "KSKv6kDqnw4UwPdpOMXziC/AMj3Z/lUVX1G7WSHCAWKf1zNS1eLvqr+boEjXuB"
+            "OitnZ/bDzPHrTOZz0Dew0uowxf/+sG+NCK3eQJVxqcaJ/vEHKIVd2M+5qL71yJ"
+            "Q+87X6oV3eaYvt3zWZYD6z5vYTcrtij2VZ9Zmni/UAaHqn9JdsBWLUEpVviYnh"
+            "imNVvYFZeCXg/IdTQ+x4IRdiXNv5hEew==";
+        char e[] = "AQAB";
+
+  rsa=RSA_new();
+  size=base64_decode(n,modules);
+  rsa->n=BN_bin2bn(modules,size,NULL);
+  size=base64_decode(e,exponent);
+  rsa->e=BN_bin2bn(exponent,size,NULL);
+  size=RSA_public_encrypt(len, text, res, rsa, RSA_PKCS1_OAEP_PADDING);
+  RSA_free(rsa);
+  return size;
+}
+
+static int encrypt(raopcl_data_t *raopcld, __u8 *data, int size)
+{
+  __u8 *buf;
+  //__u8 tmp[16];
+  int i=0,j;
+  memcpy(raopcld->nv,raopcld->iv,16);
+  while(i+16<=size){
+    buf=data+i;
+    for(j=0;j<16;j++) buf[j] ^= raopcld->nv[j];
+    aes_encrypt(&raopcld->ctx, buf, buf);
+    memcpy(raopcld->nv,buf,16);
+    i+=16;
+  }
+  if(i<size){
+#if 0
+    INFMSG("%s: a block less than 16 bytes(%d) is not encrypted\n",__func__, size-i);
+    memset(tmp,0,16);
+    memcpy(tmp,data+i,size-i);
+    for(j=0;j<16;j++) tmp[j] ^= raopcld->nv[j];
+    aes_encrypt(&raopcld->ctx, tmp, tmp);
+    memcpy(raopcld->nv,tmp,16);
+    memcpy(data+i,tmp,16);
+    i+=16;
+#endif
+  }
+  return i;
+}
+
+/*
+ * after I've updated the firmware of my AEX, data from AEX doesn't come
+ * when raop_play is not sending data.
+ * 'rsize=GET_BIGENDIAN_INT(buf+0x2c)' this size stops with 330750.
+ * I think '330750/44100=7.5 sec' is data in the AEX bufeer, so add a timer
+ * to check when the AEX buffer data becomes empty.
+ *
+ * from aexcl_play, it goes down but doesn't become zero.
+ * (12/15/2005)
+ */
+static int fd_event_callback(void *p, int flags)
+{
+  int i;
+  __u8 buf[256];
+  raopcl_data_t *raopcld;
+  int rsize;
+  if(!p) return -1;
+  raopcld=(raopcl_data_t *)p;
+  if(flags&RAOP_FD_READ){
+    i=read(raopcld->sfd,buf,sizeof(buf));
+    if(i>0){
+      rsize=GET_BIGENDIAN_INT(buf+0x2c);
+      raopcld->size_in_aex=rsize;
+      gettimeofday(&raopcld->last_read_tv,NULL);
+      //DBGMSG("%s: read %d bytes, rsize=%d\n", __func__, i,rsize);
+      return 0;
+    }
+    if(i<0) ERRMSG("%s: read error: %s\n", __func__, strerror(errno));
+    if(i==0) INFMSG("%s: read, disconnected on the other end\n", __func__);
+    return -1;
+  }
+
+  if(!flags&RAOP_FD_WRITE){
+    ERRMSG("%s: unknow event flags=%d\n", __func__,flags);
+    return -1;
+  }
+
+  if(!raopcld->wblk_remsize) {
+    ERRMSG("%s: write is called with remsize=0\n", __func__);
+    return -1;
+  }
+  i=write(raopcld->sfd,raopcld->data+raopcld->wblk_wsize,raopcld->wblk_remsize);
+  if(i<0){
+    ERRMSG("%s: write error: %s\n", __func__, strerror(errno));
+    return -1;
+  }
+  if(i==0){
+    INFMSG("%s: write, disconnected on the other end\n", __func__);
+    return -1;
+  }
+  raopcld->wblk_wsize+=i;
+  raopcld->wblk_remsize-=i;
+  if(!raopcld->wblk_remsize) {
+    set_fd_event(raopcld->sfd, RAOP_FD_READ, fd_event_callback,(void*)raopcld);
+  }
+
+  //DBGMSG("%d bytes are sent, remaining size=%d\n",i,raopcld->wblk_remsize);
+  return 0;
+}
+
+static int raopcl_stream_connect(raopcl_data_t *raopcld)
+{
+  __u16 myport=0;
+
+  if((raopcld->sfd=open_tcp_socket(NULL, &myport))==-1) return -1;
+  if(get_tcp_connect_by_host(raopcld->sfd, raopcld->addr,
+           rtspcl_get_server_port(raopcld->rtspcl))) {
+    close(raopcld->sfd);
+    raopcld->sfd=-1;
+    return -1;
+  }
+  return 0;
+}
+
+int raopcl_small_silent(raopcl_t *p)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  raopcl_send_sample(p,raopcld->min_sdata,raopcld->min_sdata_size);
+  //DBGMSG("sent a small silent data\n");
+  return 0;
+}
+
+int raopcl_pause_check(raopcl_t *p)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  // if in puase, keep sending a small silent data every 3 seconds
+  switch(raopcld->pause) {
+  case NO_PAUSE:
+    return 0;
+  case OP_PAUSE:
+    if(time(NULL)-raopcld->paused_time<3) return 0;
+    rtspcl_flush(raopcld->rtspcl);
+    raopcld->paused_time=time(NULL);
+    return 1;
+  case NODATA_PAUSE:
+    if(time(NULL)-raopcld->paused_time<3) return 0;
+    raopcl_small_silent(p);
+    raopcld->paused_time=time(NULL);
+    return 1;
+  }
+  return -1;
+}
+
+int raopcl_wait_songdone(raopcl_t *p, int set)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(set)
+    raopcld->wait_songdone=(set==1);
+  return raopcld->wait_songdone;
+}
+
+int raopcl_sample_remsize(raopcl_t *p)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+  return raopcld->wblk_remsize;
+}
+
+int raopcl_send_sample(raopcl_t *p, __u8 *sample, int count )
+{
+  int rval=-1;
+  __u16 len;
+        __u8 header[] = {
+    0x24, 0x00, 0x00, 0x00,
+    0xF0, 0xFF, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00,
+        };
+  const int header_size=sizeof(header);
+  raopcl_data_t *raopcld;
+  if(!p) return -1;
+
+  raopcld=(raopcl_data_t *)p;
+  if(realloc_memory((void**)&raopcld->data, count+header_size+16, __func__)) goto erexit;
+  memcpy(raopcld->data,header,header_size);
+  len=count+header_size-4;
+  raopcld->data[2]=len>>8;
+  raopcld->data[3]=len&0xff;
+  memcpy(raopcld->data+header_size,sample,count);
+  encrypt(raopcld, raopcld->data+header_size, count);
+  len=count+header_size;
+  raopcld->wblk_remsize=count+header_size;
+  raopcld->wblk_wsize=0;
+  if(set_fd_event(raopcld->sfd, RAOP_FD_READ|RAOP_FD_WRITE, fd_event_callback,(void*)raopcld)) goto erexit;
+  rval=0;
+ erexit:
+  return rval;
+}
+
+
+raopcl_t *raopcl_open()
+{
+  raopcl_data_t *raopcld;
+  __s16 sdata[MINIMUM_SAMPLE_SIZE*2];
+  data_source_t ds={.type=MEMORY};
+  __u8 *bp;
+
+  raopcld=malloc(sizeof(raopcl_data_t));
+  RAND_seed(raopcld,sizeof(raopcl_data_t));
+  memset(raopcld, 0, sizeof(raopcl_data_t));
+  if(!RAND_bytes(raopcld->iv, sizeof(raopcld->iv)) || !RAND_bytes(raopcld->key, sizeof(raopcld->key))){
+    ERRMSG("%s:RAND_bytes error code=%ld\n",__func__,ERR_get_error());
+    return NULL;
+  }
+  memcpy(raopcld->nv,raopcld->iv,sizeof(raopcld->nv));
+  raopcld->volume=VOLUME_DEF;
+        aes_set_key(&raopcld->ctx, raopcld->key, 128);
+  // prepare a small silent data to send during pause period.
+  ds.u.mem.size=MINIMUM_SAMPLE_SIZE*4;
+  ds.u.mem.data=sdata;
+  memset(sdata,0,sizeof(sdata));
+  auds_write_pcm(NULL, raopcld->min_sdata, &bp, &raopcld->min_sdata_size,
+           MINIMUM_SAMPLE_SIZE, &ds);
+  return (raopcl_t *)raopcld;
+}
+
+int raopcl_close(raopcl_t *p)
+{
+  raopcl_data_t *raopcld;
+  if(!p) return -1;
+
+  raopcld=(raopcl_data_t *)p;
+  if(raopcld->rtspcl)
+    rtspcl_close(raopcld->rtspcl);
+  if(raopcld->data) free(raopcld->data);
+  if(raopcld->addr) free(raopcld->addr);
+  free(raopcld);
+  return 0;
+}
+
+int raopcl_connect(raopcl_t *p, char *host,__u16 destport)
+{
+  __u8 buf[4+8+16];
+  char sid[16];
+  char sci[24];
+  char *sac=NULL,*key=NULL,*iv=NULL;
+  char sdp[1024];
+  int rval=-1;
+  key_data_t *setup_kd=NULL;
+  char *aj, *token, *pc;
+  const char delimiters[] = ";";
+  __u8 rsakey[512];
+  int i;
+  raopcl_data_t *raopcld;
+  if(!p) return -1;
+
+  raopcld=(raopcl_data_t *)p;
+  RAND_bytes(buf, sizeof(buf));
+  sprintf(sid, "%d", *((__u32*)buf));
+  sprintf(sci, "%08x%08x",*((__u32*)(buf+4)),*((__u32*)(buf+8)));
+  base64_encode(buf+12,16,&sac);
+  if(!(raopcld->rtspcl=rtspcl_open())) goto erexit;
+  if(rtspcl_set_useragent(raopcld->rtspcl,"iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)")) goto erexit;
+  if(rtspcl_add_exthds(raopcld->rtspcl,"Client-Instance", sci)) goto erexit;
+  if(rtspcl_connect(raopcld->rtspcl, host, destport, sid)) goto erexit;
+
+  i=rsa_encrypt(raopcld->key,16,rsakey);
+  base64_encode(rsakey,i,&key);
+  remove_char_from_string(key,'=');
+  base64_encode(raopcld->iv,16,&iv);
+  remove_char_from_string(iv,'=');
+  sprintf(sdp,
+            "v=0\r\n"
+            "o=iTunes %s 0 IN IP4 %s\r\n"
+            "s=iTunes\r\n"
+            "c=IN IP4 %s\r\n"
+            "t=0 0\r\n"
+            "m=audio 0 RTP/AVP 96\r\n"
+            "a=rtpmap:96 AppleLossless\r\n"
+            "a=fmtp:96 4096 0 16 40 10 14 2 255 0 0 44100\r\n"
+            "a=rsaaeskey:%s\r\n"
+            "a=aesiv:%s\r\n",
+            sid, rtspcl_local_ip(raopcld->rtspcl), host, key, iv);
+  remove_char_from_string(sac,'=');
+  if(rtspcl_add_exthds(raopcld->rtspcl, "Apple-Challenge", sac)) goto erexit;
+  if(rtspcl_annouce_sdp(raopcld->rtspcl, sdp)) goto erexit;
+  if(rtspcl_mark_del_exthds(raopcld->rtspcl, "Apple-Challenge")) goto erexit;
+  if(rtspcl_setup(raopcld->rtspcl, &setup_kd)) goto erexit;
+  if(!(aj=kd_lookup(setup_kd,"Audio-Jack-Status"))) {
+    ERRMSG("%s: Audio-Jack-Status is missing\n",__func__);
+    goto erexit;
+  }
+
+  token=strtok(aj,delimiters);
+  while(token){
+    if((pc=strstr(token,"="))){
+      *pc=0;
+      if(!strcmp(token,"type") && !strcmp(pc+1,"digital")){
+        raopcld->ajtype=JACK_TYPE_DIGITAL;
+      }
+    }else{
+      if(!strcmp(token,"connected")){
+        raopcld->ajstatus=JACK_STATUS_CONNECTED;
+      }
+    }
+    token=strtok(NULL,delimiters);
+  }
+
+  if(rtspcl_record(raopcld->rtspcl)) goto erexit;
+
+  // keep host address and port information
+  if(realloc_memory((void**)&raopcld->addr,strlen(host)+1,__func__)) goto erexit;
+  strcpy(raopcld->addr,host);
+  raopcld->rtsp_port=destport;
+
+  if(raopcl_stream_connect(raopcld)) goto erexit;
+
+  rval=0;
+ erexit:
+  if(sac) free(sac);
+  if(key) free(key);
+  if(iv) free(iv);
+  free_kd(setup_kd);
+  return rval;
+
+
+}
+
+/*
+ * update volume
+ * minimum=0, maximum=100
+ */
+int raopcl_update_volume(raopcl_t *p, int vol)
+{
+
+  char a[128];
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+
+  if(!raopcld->rtspcl) return -1;
+  raopcld->volume=VOLUME_MIN+(VOLUME_MAX-VOLUME_MIN)*vol/100;
+  sprintf(a, "volume: %d.000000\r\n", raopcld->volume);
+  return rtspcl_set_parameter(raopcld->rtspcl,a);
+}
+
+int raopcl_flush_stream(raopcl_t *p)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+  return rtspcl_flush(raopcld->rtspcl);
+}
+
+int raopcl_set_pause(raopcl_t *p, pause_state_t pause)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+
+  raopcld->pause=pause;
+  switch(pause){
+  case OP_PAUSE:
+    rtspcl_flush(raopcld->rtspcl);
+  case NODATA_PAUSE:
+    set_fd_event(raopcld->sfd, RAOP_FD_READ, fd_event_callback,(void*)raopcld);
+    raopcld->paused_time=time(NULL);
+    break;
+  case NO_PAUSE:
+    set_fd_event(raopcld->sfd, RAOP_FD_READ|RAOP_FD_WRITE, fd_event_callback,(void*)raopcld);
+    break;
+  }
+  return 0;
+}
+
+pause_state_t raopcl_get_pause(raopcl_t *p)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+
+  return raopcld->pause;
+}
+
+int raopcl_aexbuf_time(raopcl_t *p, struct timeval *dtv)
+{
+  raopcl_data_t *raopcld=(raopcl_data_t *)p;
+  if(!p) return -1;
+  struct timeval ctv, atv;
+
+  if(raopcld->size_in_aex<=0) {
+    memset(dtv, 0, sizeof(struct timeval));
+    return 1; // not playing?
+  }
+
+  atv.tv_sec=raopcld->size_in_aex/44100;
+  atv.tv_usec=(raopcld->size_in_aex%44100)*10000/441;
+
+  gettimeofday(&ctv,NULL);
+  dtv->tv_sec=ctv.tv_sec - raopcld->last_read_tv.tv_sec;
+  dtv->tv_usec=ctv.tv_usec - raopcld->last_read_tv.tv_usec;
+
+  dtv->tv_sec=atv.tv_sec-dtv->tv_sec;
+  dtv->tv_usec=atv.tv_usec-dtv->tv_usec;
+
+  if(dtv->tv_usec>=1000000){
+    dtv->tv_sec++;
+    dtv->tv_usec-=1000000;
+  }else if(dtv->tv_usec<0){
+    dtv->tv_sec--;
+    dtv->tv_usec+=1000000;
+  }
+
+  if(dtv->tv_sec<0) memset(dtv, 0, sizeof(struct timeval));
+  //DBGMSG("%s:tv_sec=%d, tv_usec=%d\n",__func__,(int)dtv->tv_sec,(int)dtv->tv_usec);
+  return 0;
+}

Propchange: branches/coling/raop_play/orig/raop_client.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/raop_client.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/raop_client.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/raop_client.h (added)
+++ branches/coling/raop_play/orig/raop_client.h Fri May  2 02:16:10 2008
@@ -1,0 +1,47 @@
+/*****************************************************************************
+ * rtsp_client.h: RAOP Client
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __RAOP_CLIENT_H_
+#define __RAOP_CLIENT_H
+
+typedef struct raopcl_t {__u32 dummy;} raopcl_t;
+
+typedef enum pause_state_t{
+  NO_PAUSE=0,
+  OP_PAUSE,
+  NODATA_PAUSE,
+}pause_state_t;
+
+raopcl_t *raopcl_open();
+int raopcl_close(raopcl_t *p);
+int raopcl_connect(raopcl_t *p, char *host,__u16 destport);
+int raopcl_disconnect(raopcl_t *p);
+int raopcl_send_sample(raopcl_t *p, __u8 *sample, int count );
+int raopcl_update_volume(raopcl_t *p, int vol);
+int raopcl_sample_remsize(raopcl_t *p);
+int raopcl_set_pause(raopcl_t *p, pause_state_t pause);
+pause_state_t raopcl_get_pause(raopcl_t *p);
+int raopcl_flush_stream(raopcl_t *p);
+int raopcl_wait_songdone(raopcl_t *p, int set);
+int raopcl_small_silent(raopcl_t *p);
+int raopcl_pause_check(raopcl_t *p);
+int raopcl_aexbuf_time(raopcl_t *p, struct timeval *dtv);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/raop_client.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/raop_play.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/raop_play.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/raop_play.c (added)
+++ branches/coling/raop_play/orig/raop_play.c Fri May  2 02:16:10 2008
@@ -1,0 +1,323 @@
+/*****************************************************************************
+ * rtsp_play.c: RAOP Client player
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <signal.h>
+#include "aexcl_lib.h"
+#include "raop_client.h"
+#include "audio_stream.h"
+#include "raop_play.h"
+
+#define SERVER_PORT 5000
+
+#define MAX_NUM_OF_FDS 4
+typedef struct fdev_t{
+  int fd;
+  void *dp;
+  fd_callback_t cbf;
+  int flags;
+}dfev_t;
+
+typedef struct raopld_t{
+  raopcl_t *raopcl;
+  auds_t *auds;
+  dfev_t fds[MAX_NUM_OF_FDS];
+}raopld_t;
+static raopld_t *raopld;
+
+
+static int print_usage(char *argv[])
+{
+  printf("%s [--port port_number] [--vol volume(0-100)] "
+         "[-i interactive mode] server_ip audio_filename\n",argv[0]);
+  return -1;
+}
+
+#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};
+
+  FD_ZERO(&rdfds);
+  FD_ZERO(&wrfds);
+  for(i=0;i<MAX_NUM_OF_FDS;i++){
+    if(raopld->fds[i].fd<0) continue;
+    if(raopld->fds[i].flags&RAOP_FD_READ)
+      FD_SET(raopld->fds[i].fd, &rdfds);
+    if(raopld->fds[i].flags&RAOP_FD_WRITE)
+      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);
+
+  select(fdmax+1,&rdfds,&wrfds,NULL,&tout);
+
+  for(i=0;i<MAX_NUM_OF_FDS;i++){
+    if(raopld->fds[i].fd<0) continue;
+    if((raopld->fds[i].flags&RAOP_FD_READ) &&
+       FD_ISSET(raopld->fds[i].fd,&rdfds)){
+      //DBGMSG("rd event i=%d, flags=%d\n",i,raopld->fds[i].flags);
+      if(raopld->fds[i].cbf &&
+         raopld->fds[i].cbf(raopld->fds[i].dp, RAOP_FD_READ)) return -1;
+    }
+    if((raopld->fds[i].flags&RAOP_FD_WRITE) &&
+       FD_ISSET(raopld->fds[i].fd,&wrfds)){
+      //DBGMSG("wr event i=%d, flags=%d\n",i,raopld->fds[i].flags);
+      if(raopld->fds[i].cbf &&
+         raopld->fds[i].cbf(raopld->fds[i].dp, RAOP_FD_WRITE)) return -1;
+    }
+  }
+
+  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);
+
+  return 0;
+}
+
+static int console_command(char *cstr)
+{
+  int i;
+  char *ps=NULL;
+
+  if(strstr(cstr,"play")==cstr){
+    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;
+        break;
+      }
+    }
+    if(!ps) return 0;
+    // if there is a new song name, open the song
+    if(!(raopld->auds=auds_open(ps, 0))){
+      printf("%s\n",RAOP_ERROR);
+      fflush(stdout);
+      return -1;
+    }
+    raopcl_flush_stream(raopld->raopcl);
+    return 0;
+  }else if(!strcmp(cstr,"pause")){
+    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(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 -1;
+}
+
+static int console_read(void *p, int flags)
+{
+  char line[256];
+  if(read_line(0,line,sizeof(line),100,0)==-1){
+    DBGMSG("stop reading from console\n");
+    clear_fd_event(0);
+  }else{
+    DBGMSG("%s:%s\n",__func__,line);
+  }
+  if(console_command(line)==-2) return -1;
+  // ignore console command errors, and return 0
+  return 0;
+}
+
+static int terminate_cbf(void *p, int flags){
+  return -1;
+}
+
+static void sig_action(int signo, siginfo_t *siginfo, void *extra)
+{
+  // SIGCHLD, a child process is terminated
+  if(signo==SIGCHLD){
+    auds_sigchld(raopld->auds, siginfo);
+    return;
+  }
+  //SIGINT,SIGTERM
+  DBGMSG("SIGINT or SIGTERM\n");
+  set_fd_event(1,RAOP_FD_WRITE,terminate_cbf,NULL);
+  return;
+}
+
+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;
+
+  /* Assign sig_term as our SIGTERM handler */
+  act.sa_sigaction = sig_action;
+  sigemptyset(&act.sa_mask); // no other signals are blocked
+  act.sa_flags = SA_SIGINFO; // use sa_sigaction instead of sa_handler
+  sigaction(SIGTERM, &act, NULL);
+  sigaction(SIGINT, &act, NULL);
+  sigaction(SIGCHLD, &act, NULL);
+
+  for(i=1;i<argc;i++){
+    if(!strcmp(argv[i],"-i")){
+      iact=1;
+      continue;
+    }
+    if(!strcmp(argv[i],"--port")){
+      port=atoi(argv[++i]);
+      continue;
+    }
+    if(!strcmp(argv[i],"--vol")){
+      volume=atoi(argv[++i]);
+      continue;
+    }
+    if(!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
+      return print_usage(argv);
+    if(!host) {host=argv[i]; continue;}
+    if(!fname) {fname=argv[i]; continue;}
+  }
+  if(!host) return print_usage(argv);
+  if(!iact && !fname) return print_usage(argv);
+
+  raopld=(raopld_t*)malloc(sizeof(raopld_t));
+  if(!raopld) goto erexit;
+  memset(raopld,0,sizeof(raopld_t));
+  for(i=0;i<MAX_NUM_OF_FDS;i++) raopld->fds[i].fd=-1;
+
+  raopld->raopcl=raopcl_open();
+  if(!raopld->raopcl) goto erexit;
+  if(raopcl_connect(raopld->raopcl,host,port)) goto erexit;
+  if(raopcl_update_volume(raopld->raopcl,volume)) goto erexit;
+  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(!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);
+ erexit:
+  if(raopld->auds) auds_close(raopld->auds);
+  if(raopld) free(raopld);
+  return rval;
+}
+
+int set_fd_event(int fd, int flags, fd_callback_t cbf, void *p)
+{
+  int i;
+  // check the same fd first. if it exists, update it
+  for(i=0;i<MAX_NUM_OF_FDS;i++){
+    if(raopld->fds[i].fd==fd){
+      raopld->fds[i].dp=p;
+      raopld->fds[i].cbf=cbf;
+      raopld->fds[i].flags=flags;
+      return 0;
+    }
+  }
+  // then create a new one
+  for(i=0;i<MAX_NUM_OF_FDS;i++){
+    if(raopld->fds[i].fd<0){
+      raopld->fds[i].fd=fd;
+      raopld->fds[i].dp=p;
+      raopld->fds[i].cbf=cbf;
+      raopld->fds[i].flags=flags;
+      return 0;
+    }
+  }
+  return -1;
+}
+
+int clear_fd_event(int fd)
+{
+  int i;
+  for(i=0;i<MAX_NUM_OF_FDS;i++){
+    if(raopld->fds[i].fd==fd){
+      raopld->fds[i].fd=-1;
+      raopld->fds[i].dp=NULL;
+      raopld->fds[i].cbf=NULL;
+      raopld->fds[i].flags=0;
+      return 0;
+    }
+  }
+  return -1;
+}
+

Propchange: branches/coling/raop_play/orig/raop_play.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/raop_play.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/raop_play.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/raop_play.h (added)
+++ branches/coling/raop_play/orig/raop_play.h Fri May  2 02:16:10 2008
@@ -1,0 +1,16 @@
+#ifndef __RAOP_PLAY_H_
+#define __RAOP_PLAY_H
+
+
+#define  RAOP_FD_READ (1<<0)
+#define RAOP_FD_WRITE (1<<1)
+
+#define RAOP_CONNECTED "connected"
+#define RAOP_SONGDONE "done"
+#define RAOP_ERROR "error"
+
+typedef int (*fd_callback_t)(void *, int);
+int set_fd_event(int fd, int flags, fd_callback_t cbf, void *p);
+int clear_fd_event(int fd);
+
+#endif

Propchange: branches/coling/raop_play/orig/raop_play.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/rtsp_client.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/rtsp_client.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/rtsp_client.c (added)
+++ branches/coling/raop_play/orig/rtsp_client.c Fri May  2 02:16:10 2008
@@ -1,0 +1,407 @@
+/*****************************************************************************
+ * rtsp_client.c: RTSP Client
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include "aexcl_lib.h"
+#include "rtsp_client.h"
+
+#define MAX_NUM_KD 20
+typedef struct rtspcl_data_t {
+  int fd;
+  char url[128];
+  int cseq;
+  key_data_t *kd;
+  key_data_t *exthds;
+  char *session;
+  char *transport;
+  __u16 server_port;
+  struct in_addr host_addr;
+  struct in_addr local_addr;
+  const char *useragent;
+} rtspcl_data_t;
+
+static int exec_request(rtspcl_data_t *rtspcld, char *cmd, char *content_type,
+       char *content, int get_response, key_data_t *hds, key_data_t **kd);
+
+rtspcl_t *rtspcl_open()
+{
+  rtspcl_data_t *rtspcld;
+  rtspcld=malloc(sizeof(rtspcl_data_t));
+  memset(rtspcld, 0, sizeof(rtspcl_data_t));
+  rtspcld->useragent="RTSPClient";
+  return (rtspcl_t *)rtspcld;
+}
+
+int rtspcl_close(rtspcl_t *p)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  rtspcl_disconnect(p);
+  free(rtspcld);
+  p=NULL;
+  rtspcl_remove_all_exthds(p);
+  return 0;
+}
+
+__u16 rtspcl_get_server_port(rtspcl_t *p)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  return rtspcld->server_port;
+}
+
+int rtspcl_set_useragent(rtspcl_t *p, const char *name)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  rtspcld->useragent=name;
+  return 0;
+}
+
+int rtspcl_add_exthds(rtspcl_t *p, char *key, char *data)
+{
+  int i=0;
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  if(!rtspcld->exthds){
+    if(realloc_memory((void*)&rtspcld->exthds, 17*sizeof(key_data_t),__func__)) return -1;
+  }else{
+    i=0;
+    while(rtspcld->exthds[i].key) {
+      if(rtspcld->exthds[i].key[0]==0xff) break;
+      i++;
+    }
+    if(i && i%16==0 && rtspcld->exthds[i].key[0]!=0xff){
+      if(realloc_memory((void*)&rtspcld->exthds,(16*((i%16)+1)+1)*sizeof(key_data_t),__func__))
+        return -1;
+      memset(rtspcld->exthds+16*(i/16),0,17*sizeof(key_data_t));
+    }
+  }
+  if(realloc_memory((void*)&rtspcld->exthds[i].key,strlen(key),__func__)) return -1;
+  strcpy((char*)rtspcld->exthds[i].key,key);
+  if(realloc_memory((void*)&rtspcld->exthds[i].data,strlen(data),__func__)) return -1;
+  strcpy((char*)rtspcld->exthds[i].data,data);
+  rtspcld->exthds[i+1].key=NULL;
+  return 0;
+}
+
+int rtspcl_mark_del_exthds(rtspcl_t *p, char *key)
+{
+  int i=0;
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  if(!rtspcld->exthds) return -1;
+  while(rtspcld->exthds[i].key) {
+    if(!strcmp((char*)key,(char*)rtspcld->exthds[i].key)){
+      rtspcld->exthds[i].key[0]=0xff;
+      return 0;
+    }
+    i++;
+  }
+  return -1;
+}
+
+int rtspcl_remove_all_exthds(rtspcl_t *p)
+{
+  int i=0;
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  while(rtspcld->exthds && rtspcld->exthds[i].key) {
+    free(rtspcld->exthds[i].key);
+    free(rtspcld->exthds[i].data);
+  }
+  free(rtspcld->exthds);
+  rtspcld->exthds=NULL;
+  return 0;
+}
+
+int rtspcl_connect(rtspcl_t *p, char *host, __u16 destport, char *sid)
+{
+  __u16 myport=0;
+  struct sockaddr_in name;
+  socklen_t namelen=sizeof(name);
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  if((rtspcld->fd=open_tcp_socket(NULL, &myport))==-1) return -1;
+  if(get_tcp_connect_by_host(rtspcld->fd, host, destport)) return -1;
+  getsockname(rtspcld->fd, (struct sockaddr*)&name, &namelen);
+  memcpy(&rtspcld->local_addr,&name.sin_addr,sizeof(struct in_addr));
+  sprintf(rtspcld->url,"rtsp://%s/%s",inet_ntoa(name.sin_addr),sid);
+  getpeername(rtspcld->fd, (struct sockaddr*)&name, &namelen);
+  memcpy(&rtspcld->host_addr,&name.sin_addr,sizeof(struct in_addr));
+  return 0;
+}
+
+char* rtspcl_local_ip(rtspcl_t *p)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return NULL;
+  rtspcld=(rtspcl_data_t *)p;
+  return inet_ntoa(rtspcld->local_addr);
+}
+
+
+int rtspcl_disconnect(rtspcl_t *p)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  if(rtspcld->fd>0) close(rtspcld->fd);
+  rtspcld->fd=0;
+  return 0;
+}
+
+int rtspcl_annouce_sdp(rtspcl_t *p, char *sdp)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  return exec_request(rtspcld, "ANNOUNCE", "application/sdp", sdp, 1, NULL, &rtspcld->kd);
+}
+
+int rtspcl_setup(rtspcl_t *p, key_data_t **kd)
+{
+  key_data_t *rkd=NULL;
+  key_data_t hds[2];
+  const char delimiters[] = ";";
+  char *buf=NULL;
+  char *token,*pc;
+  int rval=-1;
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  hds[0].key=(__u8*)"Transport";
+  hds[0].data=(__u8*)"RTP/AVP/TCP;unicast;interleaved=0-1;mode=record";
+  hds[1].key=NULL;
+  if(exec_request(rtspcld, "SETUP", NULL, NULL, 1, hds, &rkd)) return -1;
+  if(!(rtspcld->session=kd_lookup(rkd, "Session"))){
+    ERRMSG("%s: no session in responce\n",__func__);
+    goto erexit;
+  }
+  if(!(rtspcld->transport=kd_lookup(rkd, "Transport"))){
+    ERRMSG("%s: no transport in responce\n",__func__);
+    goto erexit;
+  }
+  if(realloc_memory((void*)&buf,strlen(rtspcld->transport)+1,__func__)) goto erexit;
+  strcpy(buf,rtspcld->transport);
+  token=strtok(buf,delimiters);
+  rtspcld->server_port=0;
+  while(token){
+    if((pc=strstr(token,"="))){
+      *pc=0;
+      if(!strcmp(token,"server_port")){
+        rtspcld->server_port=atoi(pc+1);
+        break;
+      }
+    }
+    token=strtok(NULL,delimiters);
+  }
+  if(rtspcld->server_port==0){
+    ERRMSG("%s: no server_port in responce\n",__func__);
+    goto erexit;
+  }
+  rval=0;
+ erexit:
+  if(buf) free(buf);
+  if(rval) {
+    free_kd(rkd);
+    rkd=NULL;
+  }
+  *kd=rkd;
+  return rval;
+}
+
+int rtspcl_record(rtspcl_t *p)
+{
+  key_data_t hds[3];
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  if(!rtspcld->session){
+    ERRMSG("%s: no session in progress\n",__func__);
+    return -1;
+  }
+  hds[0].key=(__u8*)"Range";
+  hds[0].data=(__u8*)"npt=0-";
+        hds[1].key=(__u8*)"RTP-Info";
+  hds[1].data=(__u8*)"seq=0;rtptime=0";
+  hds[2].key=NULL;
+  return exec_request(rtspcld,"RECORD",NULL,NULL,1,hds,&rtspcld->kd);
+}
+
+int rtspcl_set_parameter(rtspcl_t *p, char *para)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  return exec_request(rtspcld, "SET_PARAMETER", "text/parameters", para, 1, NULL, &rtspcld->kd);
+}
+
+int rtspcl_flush(rtspcl_t *p)
+{
+  key_data_t hds[2];
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  hds[0].key=(__u8*)"RTP-Info";
+  hds[0].data=(__u8*)"seq=0;rtptime=0";
+  hds[1].key=NULL;
+  return exec_request(rtspcld, "FLUSH", NULL, NULL, 1, hds, &rtspcld->kd);
+}
+
+int rtspcl_teardown(rtspcl_t *p)
+{
+  rtspcl_data_t *rtspcld;
+
+  if(!p) return -1;
+  rtspcld=(rtspcl_data_t *)p;
+  return exec_request(rtspcld, "TEARDOWN", NULL, NULL, 0, NULL, &rtspcld->kd);
+}
+
+/*
+ * send RTSP request, and get responce if it's needed
+ * if this gets a success, *kd is allocated or reallocated (if *kd is not NULL)
+ */
+static int exec_request(rtspcl_data_t *rtspcld, char *cmd, char *content_type,
+        char *content, int get_response, key_data_t *hds, key_data_t **kd)
+{
+        char line[1024];
+  char req[1024];
+  char reql[128];
+  const char delimiters[] = " ";
+  char *token,*dp;
+  int i,j,dsize,rval;
+  int timeout=5000; // msec unit
+
+
+  if(!rtspcld) return -1;
+
+        sprintf(req, "%s %s RTSP/1.0\r\nCSeq: %d\r\n",cmd,rtspcld->url,++rtspcld->cseq );
+
+        if( rtspcld->session != NULL ){
+    sprintf(reql,"Session: %s\r\n", rtspcld->session );
+    strncat(req,reql,sizeof(req));
+  }
+  i=0;
+        while( hds && hds[i].key != NULL ){
+    sprintf(reql,"%s: %s\r\n", hds[i].key, hds[i].data);
+    strncat(req,reql,sizeof(req));
+    i++;
+        }
+
+        if( content_type && content) {
+    sprintf(reql, "Content-Type: %s\r\nContent-Length: %d\r\n",
+      content_type, (int)strlen(content));
+    strncat(req,reql,sizeof(req));
+        }
+
+        sprintf(reql, "User-Agent: %s\r\n", rtspcld->useragent );
+  strncat(req,reql,sizeof(req));
+
+  i=0;
+        while(rtspcld->exthds && rtspcld->exthds[i].key){
+    if(rtspcld->exthds[i].key[0]==0xff) {i++;continue;}
+    sprintf(reql,"%s: %s\r\n", rtspcld->exthds[i].key, rtspcld->exthds[i].data);
+    strncat(req,reql,sizeof(req));
+    i++;
+        }
+  strncat(req,"\r\n",sizeof(req));
+
+        if( content_type && content)
+    strncat(req,content,sizeof(req));
+
+  rval=write(rtspcld->fd,req,strlen(req));
+  //DBGMSG("%s: write %d: %d \n",__func__, strlen(req),rval);
+
+        if( !get_response ) return 0;
+
+  if(read_line(rtspcld->fd,line,sizeof(line),timeout,0)<=0)  {
+    ERRMSG("%s: request failed\n",__func__);
+    return -1;
+  }
+
+  token = strtok(line, delimiters);
+  token = strtok(NULL, delimiters);
+  if(token==NULL || strcmp(token,"200")){
+    ERRMSG("%s: request failed, error %s\n",__func__,token);
+    return -1;
+  }
+
+  i=0;
+  while(read_line(rtspcld->fd,line,sizeof(line),timeout,0)>0){
+    DBGMSG("%s\n",line);
+    timeout=1000; // once it started, it shouldn't take a long time
+    if(i%16==0){
+      if(realloc_memory((void*)kd,(16*(i/16+1)+1)*sizeof(key_data_t),__func__)) return -1;
+      memset(*kd+16*(i/16),0,17*sizeof(key_data_t));
+    }
+
+    if(i && line[0]==' '){
+      for(j=0;j<strlen(line);j++) if(line[j]!=' ') break;
+      dsize+=strlen(line+j);
+      if(realloc_memory((void*)&(*kd)[i].data,dsize,__func__)) return -1;
+      strcat((char*)(*kd)[i].data,line+j);
+      continue;
+    }
+    dp=strstr(line,":");
+    if(!dp){
+      ERRMSG("%s: Request failed, bad header\n",__func__);
+      free_kd(*kd);
+      *kd=NULL;
+      return -1;
+    }
+    *dp=0;
+    if(realloc_memory((void*)&(*kd)[i].key,strlen(line)+1,__func__)) return -1;
+    strcpy((char*)(*kd)[i].key,line);
+    dsize=strlen(dp+1)+1;
+    if(realloc_memory((void*)&(*kd)[i].data,dsize,__func__)) return -1;
+    strcpy((char*)(*kd)[i].data,dp+1);
+    i++;
+  }
+  (*kd)[i].key=NULL;
+  return 0;
+}
+
+

Propchange: branches/coling/raop_play/orig/rtsp_client.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/rtsp_client.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/rtsp_client.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/rtsp_client.h (added)
+++ branches/coling/raop_play/orig/rtsp_client.h Fri May  2 02:16:10 2008
@@ -1,0 +1,44 @@
+/*****************************************************************************
+ * rtsp_client.h: RTSP Client
+ *
+ * Copyright (C) 2004 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#ifndef __RTSP_CLIENT_H_
+#define __RTSP_CLIENT_H
+
+typedef struct rtspcl_t {__u32 dummy;} rtspcl_t;
+
+rtspcl_t *rtspcl_open();
+int rtspcl_close(rtspcl_t *p);
+int rtspcl_set_useragent(rtspcl_t *p, const char *name);
+int rtspcl_connect(rtspcl_t *p, char *host, __u16 destport, char *sid);
+char* rtspcl_local_ip(rtspcl_t *p);
+int rtspcl_disconnect(rtspcl_t *p);
+int rtspcl_annouce_sdp(rtspcl_t *p, char *sdp);
+int rtspcl_setup(rtspcl_t *p, key_data_t **kd);
+int rtspcl_record(rtspcl_t *p);
+int rtspcl_set_parameter(rtspcl_t *p, char *para);
+int rtspcl_flush(rtspcl_t *p);
+int rtspcl_teardown(rtspcl_t *p);
+int rtspcl_remove_all_exthds(rtspcl_t *p);
+int rtspcl_add_exthds(rtspcl_t *p, char *key, char *data);
+int rtspcl_mark_del_exthds(rtspcl_t *p, char *key);
+__u16 rtspcl_get_server_port(rtspcl_t *p);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/rtsp_client.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/wav_stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/wav_stream.c?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/wav_stream.c (added)
+++ branches/coling/raop_play/orig/wav_stream.c Fri May  2 02:16:10 2008
@@ -1,0 +1,111 @@
+/*****************************************************************************
+ * wav_stream.c: wave file stream
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <asm/types.h>
+#include <stdio.h>
+#define WAV_STREAM_C
+#include "audio_stream.h"
+#include "wav_stream.h"
+#include "aexcl_lib.h"
+
+static int read_wave_header(wav_t *wav, int *sample_rate, int *channels);
+
+int wav_open(auds_t *auds, char *fname)
+{
+  wav_t *wav=malloc(sizeof(wav_t));
+  if(!wav) return -1;
+  memset(wav,0,sizeof(wav_t));
+  auds->stream=(void *)wav;
+  wav->inf=fopen(fname,"r");
+  if(!wav->inf) goto erexit;
+  if(read_wave_header(wav, &auds->sample_rate, &auds->channels)==-1) goto erexit;
+  auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
+  wav->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
+  if(!wav->buffer) goto erexit;
+  return 0;
+ erexit:
+  wav_close(auds);
+  return -1;
+}
+
+int wav_close(auds_t *auds)
+{
+  wav_t *wav=(wav_t *)auds->stream;
+  if(!wav) return -1;
+  if(wav->inf) fclose(wav->inf);
+  if(wav->buffer) free(wav->buffer);
+  free(wav);
+  auds->stream=NULL;
+  return 0;
+}
+
+int wav_get_top_sample(auds_t *auds, __u8 **data, int *size)
+{
+  wav_t *wav=(wav_t *)auds->stream;
+  fseek(wav->inf,sizeof(wave_header_t),SEEK_SET);
+  wav->playedbytes=0;
+  return wav_get_next_sample(auds, data, size);
+}
+
+int wav_get_next_sample(auds_t *auds, __u8 **data, int *size)
+{
+  wav_t *wav=(wav_t *)auds->stream;
+  int bsize=(wav->subchunk2size - wav->playedbytes>=auds->chunk_size)?
+    auds->chunk_size:wav->subchunk2size - wav->playedbytes;
+  data_source_t ds={.type=STREAM, .u.inf=wav->inf};
+  if(!bsize) return -1;
+  wav->playedbytes+=bsize;
+  return auds_write_pcm(auds, wav->buffer, data, size, bsize, &ds);
+}
+
+
+static int read_wave_header(wav_t *wav, int *sample_rate, int *channels)
+{
+  wave_header_t head;
+  FILE *infile=wav->inf;
+
+  if(fread(&head,1,sizeof(head),infile)<sizeof(head)) return -1;
+  if(strncmp(head.charChunkID,"RIFF",4) || strncmp(head.Format,"WAVE",4)){
+    ERRMSG("This is not a WAV file\n");
+    return -1;
+  }
+  *channels=head.NumChannels;
+  if(head.NumChannels!=2 && head.NumChannels!=1){
+    ERRMSG("This is neither stereo nor mono, NumChannels=%d\n",head.NumChannels);
+    return -1;
+  }
+  if(head.BitsPerSample!=16){
+    ERRMSG("bits per sample = %d, we need 16 bits data\n", head.BitsPerSample);
+    return -1;
+  }
+  *sample_rate=head.SampleRate;
+#if 0
+  if(head.SampleRate!=DEFAULT_SAMPLE_RATE){
+    ERRMSG("sample rate = %d, we need %d\n", head.SampleRate,DEFAULT_SAMPLE_RATE);
+    return -1;
+  }
+#endif
+  if(strncmp(head.Subchunk2ID,"data",4)){
+    ERRMSG("sub chunk is not \"data\"\n");
+    //return -1;
+  }
+  wav->subchunk2size=head.Subchunk2Size;
+  return 0;
+}
+

Propchange: branches/coling/raop_play/orig/wav_stream.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/coling/raop_play/orig/wav_stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/raop_play/orig/wav_stream.h?rev=2337&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/raop_play/orig/wav_stream.h (added)
+++ branches/coling/raop_play/orig/wav_stream.h Fri May  2 02:16:10 2008
@@ -1,0 +1,59 @@
+/*****************************************************************************
+ * wav_stream.h: wave file stream, header file
+ *
+ * Copyright (C) 2005 Shiro Ninomiya <shiron at snino.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#ifndef __WAV_STREAM_H_
+#define __WAV_STREAM_H_
+
+typedef struct wave_header_t{
+  char charChunkID[4];
+  __u32 ChunkSize;
+  char Format[4];
+  char Subchunk1ID[4];
+  __u32 Subchunk1Size;
+  __u16 AudioFormat;
+  __u16 NumChannels;
+  __u32 SampleRate;
+  __u32 ByteRate;
+  __u16 BlockAlign;
+  __u16 BitsPerSample;
+  char Subchunk2ID[4];
+  __u32 Subchunk2Size;
+} __attribute__ ((packed)) wave_header_t;
+
+typedef struct wav_t {
+/* public variables */
+/* private variables */
+#ifdef WAV_STREAM_C
+  FILE *inf;
+  __u8 *buffer;
+  int subchunk2size;
+  int playedbytes;
+#else
+  __u32 dummy;
+#endif
+} wav_t;
+
+
+int wav_open(auds_t *auds, char *fname);
+int wav_close(auds_t *auds);
+int wav_get_top_sample(auds_t *auds, __u8 **data, int *size);
+int wav_get_next_sample(auds_t *auds, __u8 **data, int *size);
+
+
+#endif

Propchange: branches/coling/raop_play/orig/wav_stream.h
------------------------------------------------------------------------------
    svn:eol-style = native




More information about the pulseaudio-commits mailing list