[pulseaudio-commits] r2335 - in /branches/coling/airtunes/src: Makefile.am modules/module-raop-sink.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 1 16:51:46 PDT 2008


Author: coling
Date: Fri May  2 01:51:45 2008
New Revision: 2335

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2335&root=pulseaudio&view=rev
Log:
Start the raop sink. It's based on pipe sink and isn't anywhere near finished. It does however compile.

Added:
    branches/coling/airtunes/src/modules/module-raop-sink.c
      - copied, changed from r2331, branches/coling/airtunes/src/modules/module-pipe-sink.c
Modified:
    branches/coling/airtunes/src/Makefile.am

Modified: branches/coling/airtunes/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/airtunes/src/Makefile.am?rev=2335&root=pulseaudio&r1=2334&r2=2335&view=diff
==============================================================================
--- branches/coling/airtunes/src/Makefile.am (original)
+++ branches/coling/airtunes/src/Makefile.am Fri May  2 01:51:45 2008
@@ -964,7 +964,13 @@
 libsocket_util_la_LDFLAGS = -avoid-version
 libsocket_util_la_LIBADD = $(AM_LIBADD) $(WINSOCK_LIBS) libpulsecore.la
 
-librtp_la_SOURCES = modules/rtp/rtp.c modules/rtp/rtp.h modules/rtp/sdp.c modules/rtp/sdp.h modules/rtp/sap.c modules/rtp/sap.h
+librtp_la_SOURCES = \
+		modules/rtp/rtp.c modules/rtp/rtp.h \
+		modules/rtp/sdp.c modules/rtp/sdp.h \
+		modules/rtp/sap.c modules/rtp/sap.h \
+		modules/rtp/rtsp.c modules/rtp/rtsp.h \
+		modules/rtp/headerlist.c modules/rtp/headerlist.h \
+		modules/rtp/base64.c modules/rtp/base64.h
 librtp_la_LDFLAGS = -avoid-version
 librtp_la_LIBADD = $(AM_LIBADD) libpulsecore.la
 
@@ -1010,6 +1016,7 @@
 		module-remap-sink.la \
 		module-ladspa-sink.la \
 		module-esound-sink.la \
+		module-raop-sink.la \
 		module-tunnel-sink.la \
 		module-tunnel-source.la
 
@@ -1144,6 +1151,7 @@
 		modules/module-esound-compat-spawnfd-symdef.h \
 		modules/module-esound-compat-spawnpid-symdef.h \
 		modules/module-match-symdef.h \
+		modules/module-raop-sink-symdef.h \
 		modules/module-tunnel-sink-symdef.h \
 		modules/module-tunnel-source-symdef.h \
 		modules/module-null-sink-symdef.h \
@@ -1304,6 +1312,10 @@
 module_match_la_LDFLAGS = -module -avoid-version
 module_match_la_LIBADD = $(AM_LIBADD) libpulsecore.la
 
+module_raop_sink_la_SOURCES = modules/module-raop-sink.c
+module_raop_sink_la_LDFLAGS = -module -avoid-version
+module_raop_sink_la_LIBADD = $(AM_LIBADD) libpulsecore.la libiochannel.la librtp.la
+
 module_tunnel_sink_la_SOURCES = modules/module-tunnel.c
 module_tunnel_sink_la_CFLAGS = -DTUNNEL_SINK=1 $(AM_CFLAGS)
 module_tunnel_sink_la_LDFLAGS = -module -avoid-version

Copied: branches/coling/airtunes/src/modules/module-raop-sink.c (from r2331, branches/coling/airtunes/src/modules/module-pipe-sink.c)
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/airtunes/src/modules/module-raop-sink.c?p2=branches/coling/airtunes/src/modules/module-raop-sink.c&p1=branches/coling/airtunes/src/modules/module-pipe-sink.c&r1=2331&r2=2335&rev=2335&root=pulseaudio&view=diff
==============================================================================
--- branches/coling/airtunes/src/modules/module-pipe-sink.c (original)
+++ branches/coling/airtunes/src/modules/module-raop-sink.c Fri May  2 01:51:45 2008
@@ -4,6 +4,7 @@
   This file is part of PulseAudio.
 
   Copyright 2004-2006 Lennart Poettering
+  Copyright 2008      Colin Guthrie
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
@@ -35,6 +36,11 @@
 #include <limits.h>
 #include <sys/ioctl.h>
 #include <poll.h>
+#include <openssl/err.h>
+#include <openssl/rand.h>
+#include <openssl/aes.h>
+#include <openssl/rsa.h>
+#include <openssl/engine.h>
 
 #include <pulse/xmalloc.h>
 
@@ -46,24 +52,43 @@
 #include <pulsecore/log.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
+#include <pulsecore/random.h>
 #include <pulsecore/rtpoll.h>
 
-#include "module-pipe-sink-symdef.h"
-
-PA_MODULE_AUTHOR("Lennart Poettering");
-PA_MODULE_DESCRIPTION("UNIX pipe sink");
+#include "rtp.h"
+#include "sdp.h"
+#include "sap.h"
+#include "rtsp.h"
+#include "base64.h"
+
+
+#include "module-raop-sink-symdef.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
+
+
+PA_MODULE_AUTHOR("Colin Guthrie");
+PA_MODULE_DESCRIPTION("RAOP Sink (Apple Airport)");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(FALSE);
 PA_MODULE_USAGE(
+        "server=<address> "
         "sink_name=<name for the sink> "
-        "file=<path of the FIFO> "
         "format=<sample format> "
         "channels=<number of channels> "
         "rate=<sample rate>"
         "channel_map=<channel map>");
 
-#define DEFAULT_FILE_NAME "/tmp/music.output"
-#define DEFAULT_SINK_NAME "fifo_output"
+#define DEFAULT_SINK_NAME "airtunes"
+#define AES_CHUNKSIZE 16
 
 struct userdata {
     pa_core *core;
@@ -74,16 +99,23 @@
     pa_thread_mq thread_mq;
     pa_rtpoll *rtpoll;
 
-    char *filename;
-    int fd;
-
+    char *server_name;
+
+    // Encryption Related bits
+    AES_KEY aes;
+    uint8_t aes_iv[AES_CHUNKSIZE]; // initialization vector for aes-cbc
+    uint8_t aes_nv[AES_CHUNKSIZE]; // next vector for aes-cbc
+    uint8_t aes_key[AES_CHUNKSIZE]; // key for aes-cbc
+
+    pa_rtsp_context *rtsp;
+    //pa_socket_client *client;
     pa_memchunk memchunk;
 
     pa_rtpoll_item *rtpoll_item;
 };
 
 static const char* const valid_modargs[] = {
-    "file",
+    "server",
     "rate",
     "format",
     "channels",
@@ -92,6 +124,51 @@
     NULL
 };
 
+static int rsa_encrypt(uint8_t *text, int len, uint8_t *res) {
+    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";
+    uint8_t modules[256];
+    uint8_t exponent[8];
+    int size;
+    RSA *rsa;
+
+    rsa = RSA_new();
+    size = pa_base64_decode(n, modules);
+    rsa->n = BN_bin2bn(modules, size, NULL);
+    size = pa_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 aes_encrypt(struct userdata *u, uint8_t *data, int size)
+{
+    uint8_t *buf;
+    int i=0, j;
+
+    pa_assert(u);
+
+    memcpy(u->aes_nv, u->aes_iv, AES_CHUNKSIZE);
+    while (i+AES_CHUNKSIZE <= size) {
+        buf = data + i;
+        for (j=0; j<AES_CHUNKSIZE; ++j)
+            buf[j] ^= u->aes_nv[j];
+
+        AES_encrypt(buf, buf, &u->aes);
+        memcpy(u->aes_nv, buf, AES_CHUNKSIZE);
+        i += AES_CHUNKSIZE;
+    }
+    return i;
+}
+
 static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
     struct userdata *u = PA_SINK(o)->userdata;
 
@@ -99,11 +176,13 @@
 
         case PA_SINK_MESSAGE_GET_LATENCY: {
             size_t n = 0;
-            int l;
+            //int l;
 
 #ifdef TIOCINQ
+            /*
             if (ioctl(u->fd, TIOCINQ, &l) >= 0 && l > 0)
                 n = (size_t) l;
+            */
 #endif
 
             n += u->memchunk.length;
@@ -118,7 +197,7 @@
 
 static void thread_func(void *userdata) {
     struct userdata *u = userdata;
-    int write_type = 0;
+    //int write_type = 0;
 
     pa_assert(u);
 
@@ -144,7 +223,9 @@
             pa_assert(u->memchunk.length > 0);
 
             p = pa_memblock_acquire(u->memchunk.memblock);
-            l = pa_write(u->fd, (uint8_t*) p + u->memchunk.index, u->memchunk.length, &write_type);
+            //l = pa_write(u->fd, (uint8_t*) p + u->memchunk.index, u->memchunk.length, &write_type);
+            // Fake the length of the "write".
+            l = u->memchunk.length;
             pa_memblock_release(u->memchunk.memblock);
 
             pa_assert(l != 0);
@@ -201,7 +282,7 @@
 
 int pa__init(pa_module*m) {
     struct userdata *u;
-    struct stat st;
+    //struct stat st;
     pa_sample_spec ss;
     pa_channel_map map;
     pa_modargs *ma;
@@ -225,13 +306,23 @@
     u->core = m->core;
     u->module = m;
     m->userdata = u;
+
+    // Initialise the AES encryption system
+    pa_random_seed();
+    pa_random(u->aes_iv, sizeof(u->aes_iv));
+    pa_random(u->aes_key, sizeof(u->aes_key));
+    memcpy(u->aes_nv, u->aes_iv, sizeof(u->aes_nv));
+    AES_set_encrypt_key(u->aes_key, 128, &u->aes);
+
     pa_memchunk_reset(&u->memchunk);
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop);
     u->rtpoll = pa_rtpoll_new();
     pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY, u->thread_mq.inq);
 
-    u->filename = pa_xstrdup(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
-
+    u->server_name = pa_xstrdup(pa_modargs_get_value(ma, "server", NULL));
+
+    // Open a connection to the server... this is just to connect and test....
+    /*
     mkfifo(u->filename, 0666);
     if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) {
         pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno));
@@ -250,7 +341,7 @@
         pa_log("'%s' is not a FIFO.", u->filename);
         goto fail;
     }
-
+    */
     if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
         pa_log("Failed to create sink.");
         goto fail;
@@ -263,12 +354,12 @@
     pa_sink_set_module(u->sink, m);
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
     pa_sink_set_rtpoll(u->sink, u->rtpoll);
-    pa_sink_set_description(u->sink, t = pa_sprintf_malloc("Unix FIFO sink '%s'", u->filename));
+    pa_sink_set_description(u->sink, t = pa_sprintf_malloc("Airtunes sink '%s'", u->server_name));
     pa_xfree(t);
 
     u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
     pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
-    pollfd->fd = u->fd;
+    //pollfd->fd = u->fd;
     pollfd->events = pollfd->revents = 0;
 
     if (!(u->thread = pa_thread_new(thread_func, u))) {
@@ -321,13 +412,6 @@
     if (u->rtpoll)
         pa_rtpoll_free(u->rtpoll);
 
-    if (u->filename) {
-        unlink(u->filename);
-        pa_xfree(u->filename);
-    }
-
-    if (u->fd >= 0)
-        pa_assert_se(pa_close(u->fd) == 0);
-
+    pa_xfree(u->server_name);
     pa_xfree(u);
 }




More information about the pulseaudio-commits mailing list