[xiph-commits] r10358 - trunk/xiph-rtp
lu_zero at svn.xiph.org
lu_zero at svn.xiph.org
Tue Nov 8 16:58:26 PST 2005
Author: lu_zero
Date: 2005-11-08 16:58:18 -0800 (Tue, 08 Nov 2005)
New Revision: 10358
Added:
trunk/xiph-rtp/xiph_rtp.c
trunk/xiph-rtp/xiph_rtp.h
Modified:
trunk/xiph-rtp/vorbisrtp.c
Log:
Generic reimplementation of the current reference code, currently incomplete
Modified: trunk/xiph-rtp/vorbisrtp.c
===================================================================
--- trunk/xiph-rtp/vorbisrtp.c 2005-11-08 11:17:08 UTC (rev 10357)
+++ trunk/xiph-rtp/vorbisrtp.c 2005-11-09 00:58:18 UTC (rev 10358)
@@ -68,9 +68,6 @@
/* Data structs and variables */
/*****************************************************************************/
-#define BUFFER_SIZE 4096
-ogg_int16_t convbuffer [BUFFER_SIZE];
-
struct sockaddr_in rtpsock;
int rtpsocket;
@@ -79,11 +76,11 @@
/* */
/* fragmentation flags work like so: */
/* */
-/* C F */
-/* 0 0 Unfragmented packet (aka multi-packet..packet) */
-/* 0 1 First fragmented packet */
-/* 1 0 Middle fragment */
-/* 1 1 Last fragment. */
+/* frag_type */
+/* 00 Unfragmented packet (aka multi-packet..packet) */
+/* 01 First fragmented packet */
+/* 10 Middle fragment */
+/* 11 Last fragment. */
/* */
/*****************************************************************************/
@@ -544,6 +541,7 @@
char *filename;
FILE *file;
+
ogg_sync_init (&oy);
int i = 0;
Added: trunk/xiph-rtp/xiph_rtp.c
===================================================================
--- trunk/xiph-rtp/xiph_rtp.c 2005-11-08 11:17:08 UTC (rev 10357)
+++ trunk/xiph-rtp/xiph_rtp.c 2005-11-09 00:58:18 UTC (rev 10358)
@@ -0,0 +1,127 @@
+/*
+ Copyright (c) 2005, Fluendo / Xiph.Org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * 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.
+
+ * Neither the name of the Xiph.Org 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+
+ Author: Luca Barbato <lu_zero at gentoo.org>
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <vorbis/codec.h>
+#include <theora/theora.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <xiph_rtp.h>
+
+
+//FIXME remove the exit
+int createsocket (xiph_rtp_t *xr, char *addr, unsigned int port,
+ unsigned char TTL){
+ int socket, ret;
+ int optval = 0;
+ struct sockaddr_in sin;
+ rtp_headers_t *headers= &xr->headers;
+
+
+
+/*===========================================================================*/
+/* Init RTP headers */
+/*===========================================================================*/
+
+/* Sets v=2, p=0, x=0, cc=0 */
+ headers -> flags1 = 0x80;
+
+/* Sets m=0, pt=96 */
+ headers -> flags2 = 0x60;
+
+ headers -> sequence = htonl (rand () & 65535);
+ headers -> timestamp = htonl (rand ());
+ headers -> ssrc = htonl (rand ());
+
+/*===========================================================================*/
+/* Create socket */
+/*===========================================================================*/
+
+ socket = socket (AF_INET, SOCK_DGRAM, 0);
+
+ if (socket < 0) {
+ fprintf (stderr, "Socket creation failed.\n");
+ exit (1);
+ }
+
+ xr->rtpsock.sin_family = sin.sin_family = AF_INET;
+ xr->rtpsock.sin_port = sin.sin_port = htons (port);
+ xr->rtpsock.sin_addr.s_addr = inet_addr (addr);
+
+ ret = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (int));
+
+ if (ret < 0) {
+ fprintf (stderr, "setsockopt SO_REUSEADDR error\n");
+ exit (1);
+ }
+
+/*===========================================================================*/
+/* Set multicast parameters */
+/*===========================================================================*/
+
+ if (IN_MULTICAST (ntohl (xr->rtpsock.sin_addr.s_addr))) {
+
+ ret = setsockopt (socket, IPPROTO_IP, IP_MULTICAST_TTL, &TTL, sizeof (char));
+
+ if (ret < 0) {
+ fprintf (stderr, "Multicast setsockopt TTL failed.\n");
+ exit (1);
+ }
+
+ optval = 1;
+
+ ret = setsockopt (socket, IPPROTO_IP, IP_MULTICAST_LOOP, &optval, sizeof (char));
+
+ if (ret < 0) {
+ fprintf (stderr, "Multicast setsockopt LOOP failed.\n");
+ exit (1);
+ }
+ }
+
+ //FIXME
+ //rx->socket = socket;
+
+ return socket;
+}
+
+
Added: trunk/xiph-rtp/xiph_rtp.h
===================================================================
--- trunk/xiph-rtp/xiph_rtp.h 2005-11-08 11:17:08 UTC (rev 10357)
+++ trunk/xiph-rtp/xiph_rtp.h 2005-11-09 00:58:18 UTC (rev 10358)
@@ -0,0 +1,105 @@
+/*
+ Copyright (c) 2005, Fluendo / Xiph.Org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * 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.
+
+ * Neither the name of the Xiph.Org 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
+
+ Author: Luca Barbato <lu_zero at gentoo.org>
+
+*/
+
+#ifndef XIPH_RTP_H
+#define XIPH_RTP_H
+
+/**
+ * Specific vorbis/theora header
+ */
+
+typedef struct header_bitfield {
+ unsigned int cbident:24;
+ unsigned int frag_type:2;
+ unsigned int data_type:2;
+ unsigned int pkts:4;
+} header_bitfield_t;
+
+/**
+ * Standard rtp header
+ */
+
+typedef struct rtp_headers {
+/* v, p, x, cc flags */
+ unsigned int flags1:8;
+
+/* m, pt flags */
+ unsigned int flags2:8;
+
+ unsigned int sequence:16;
+ unsigned int timestamp:32;
+ unsigned int ssrc:32;
+} rtp_headers_t;
+
+
+/**
+ * Context structure for rtp transmission
+ */
+
+//FIXME restructure with a separate codec struct
+typedef struct xiph_rtp {
+ /* network related */
+ struct sockaddr_in rtpsock;
+ int socket;
+ header_bitfield_t bitfield;
+ rtp_headers_t headers;
+ /* stream related */
+ ogg_sync_state oy;
+ ogg_stream_state os;
+ ogg_page og;
+ ogg_packet op;
+ ogg_packet header[3];
+ /* codec specific (vorbis)*/
+ vorbis_info vi;
+ vorbis_comment vc;
+ vorbis_dsp_state vd;
+ vorbis_block vb;
+ /* codec specific (theora)*/
+ theora_info ti;
+ theora_comment tc;
+ theora_state td;
+ /* codec specific (speex) */
+ //FIXME
+
+} xiph_rtp_t
+
+int createsocket (xiph_rtp_t *xr, char *addr, unsigned int port,
+ unsigned char TTL);
+
+void creatertp (xiph_rtp_t *xr, unsigned char* vorbdata, int length, long timestamp, int type);
+
+int sendrtp (xiph_rtp_t *xr, const void *data, int len);
+
+int makeheader (xiph_rtp_t *xr, unsigned char *packet, int length);
+
+#endif
More information about the commits
mailing list