[pulseaudio-commits] r2334 - in /branches/coling/airtunes/src/modules/rtp: base64.c base64.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 1 16:43:35 PDT 2008


Author: coling
Date: Fri May  2 01:43:34 2008
New Revision: 2334

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2334&root=pulseaudio&view=rev
Log:
Add a simple base64 library that will be used by the sink

Added:
    branches/coling/airtunes/src/modules/rtp/base64.c   (with props)
    branches/coling/airtunes/src/modules/rtp/base64.h   (with props)

Added: branches/coling/airtunes/src/modules/rtp/base64.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/airtunes/src/modules/rtp/base64.c?rev=2334&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/airtunes/src/modules/rtp/base64.c (added)
+++ branches/coling/airtunes/src/modules/rtp/base64.c Fri May  2 01:43:34 2008
@@ -1,0 +1,128 @@
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  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
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+
+  PulseAudio 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 Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+/*
+  This file was originally inspired by a file developed by
+    Kungliga Tekniska H�gskolan
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#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 pa_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 pa_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/airtunes/src/modules/rtp/base64.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/coling/airtunes/src/modules/rtp/base64.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/coling/airtunes/src/modules/rtp/base64.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/coling/airtunes/src/modules/rtp/base64.h?rev=2334&root=pulseaudio&view=auto
==============================================================================
--- branches/coling/airtunes/src/modules/rtp/base64.h (added)
+++ branches/coling/airtunes/src/modules/rtp/base64.h Fri May  2 01:43:34 2008
@@ -1,0 +1,35 @@
+#ifndef foobase64hfoo
+#define foobase64hfoo
+
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  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
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+
+  PulseAudio 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 Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+/*
+  This file was originally inspired by a file developed by
+    Kungliga Tekniska Högskolan
+*/
+
+int pa_base64_encode(const void *data, int size, char **str);
+int pa_base64_decode(const char *str, void *data);
+
+#endif

Propchange: branches/coling/airtunes/src/modules/rtp/base64.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/coling/airtunes/src/modules/rtp/base64.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the pulseaudio-commits mailing list