aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/pdp_debug.h16
-rw-r--r--include/pdp_mem.h46
-rw-r--r--include/pdp_net.h197
-rw-r--r--include/pdp_pd.h7
-rw-r--r--include/pdp_post.h29
-rw-r--r--include/pdp_symbol.h136
-rw-r--r--include/pdp_xvideo.h78
7 files changed, 509 insertions, 0 deletions
diff --git a/include/pdp_debug.h b/include/pdp_debug.h
new file mode 100644
index 0000000..a5e48fc
--- /dev/null
+++ b/include/pdp_debug.h
@@ -0,0 +1,16 @@
+#ifndef __PDP_DEBUG_H_
+#define __PDP_DEBUG_H_
+
+#include "pdp_config.h" // needed for PDP_DEBUG define
+
+void pdp_assert_hook (char *condition, char *file, int line);
+
+
+
+#if PDP_DEBUG
+#define PDP_ASSERT(x) if (!(x)) {pdp_assert_hook(#x, __FILE__, __LINE__);}
+#else
+#define PDP_ASSERT(x)
+#endif
+
+#endif //__PDP_DEBUG_H_
diff --git a/include/pdp_mem.h b/include/pdp_mem.h
new file mode 100644
index 0000000..3301655
--- /dev/null
+++ b/include/pdp_mem.h
@@ -0,0 +1,46 @@
+/*
+ * Pure Data Packet header file: memory allocation
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _PDP_MEM_H_
+#define _PDP_MEM_H_
+
+#include <pthread.h>
+
+/* a wrapper around malloc and free to keep track of pdp's memory usage */
+void *pdp_alloc(int size);
+void pdp_dealloc(void *stuff);
+
+
+/* fast allocator object (for lists and atoms) */
+#define PDP_FASTALLOC_BLOCK_ELEMENTS 4096
+typedef struct _pdp_fastalloc
+{
+ unsigned int atom_size;
+ unsigned int block_elements;
+ pthread_mutex_t mut;
+ struct _fastalloc *freelist;
+
+} t_pdp_fastalloc;
+
+void *pdp_fastalloc_new_atom(t_pdp_fastalloc *x);
+void pdp_fastalloc_save_atom(t_pdp_fastalloc *x, void *atom);
+t_pdp_fastalloc *pdp_fastalloc_new(unsigned int size);
+
+#endif
diff --git a/include/pdp_net.h b/include/pdp_net.h
new file mode 100644
index 0000000..ddc3f7f
--- /dev/null
+++ b/include/pdp_net.h
@@ -0,0 +1,197 @@
+#ifndef __PDP_UDP_H_
+#define __PDP_UDP_H_
+
+/*
+ * Pure Data Packet header: UDP protocol for raw packets
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+
+ This file contains the specification of the pdp UDP transport protocol.
+ It is a very basic binary protocol, not very fool proof.
+
+ The protocol:
+
+ A header packet is transmitted first. This contains mime type information,
+ and the size of and number of packets to be received.
+
+ The connection id:
+
+ Currently it is just a random number from the libc rand() function
+ this should be accurate enough.
+
+
+*/
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* some defs */
+#define MAX_UDP_PACKET 1472
+#define RESEND_MAX_CHUNKS ((MAX_UDP_PACKET - sizeof(t_pdp_udp_header))/sizeof(unsigned int))
+
+#define PDP_UDP_VERSION 1
+
+/* a pdp udp packet is prepended with this header */
+
+typedef struct _pdp_udp_header
+{
+ char signature[4]; /* must be "PDP" */;
+ unsigned int version; /* protocol version */
+ unsigned int connection_id; /* the 'connection' id */
+ unsigned int sequence_number; /* sequence number. negative: control packet: body contains meta info */
+
+} t_pdp_udp_header;
+
+/* the data part for a new connection */
+
+#define PDP_UDP_NEW -1 /* start a new transmission */
+typedef struct _pdp_udp_new
+{
+ unsigned int data_size; /* the size of the packets */
+ unsigned int nb_chunks; /* number of chunks in pdp to be transmitted */
+ unsigned int chunk_size; /* the maximum chunk size */
+ char type[0]; /* the packet type */
+
+ // the tail part is the mime type, for creation and reassembly
+} t_pdp_udp_newpacket;
+
+#define PDP_UDP_DONE -2 /* transmission is done */
+
+#define PDP_UDP_RESEND -3 /* request retransmission of certain chunks. empty: transmission ok */
+#define PDP_UDP_ACKNEW -4 /* acknowledge reception of new packet header */
+
+
+/* receiver and sender classes (transport layer) */
+
+#define PDP_UDP_BUFSIZE 0xF000
+
+/* RECEIVER */
+typedef struct _pdp_udp_receiver
+{
+
+ // buffer for receiving
+ t_pdp_udp_header x_header; //pdp over udp header
+ char x_buf[PDP_UDP_BUFSIZE]; //send buffer
+ unsigned int x_zero_terminator; // to prevent runaway strings
+ unsigned int x_buf_size; //size of the received data in the buffer (excluding the header)
+
+ // buffer for sending
+ t_pdp_udp_header x_resend_header; // header of the resend packet
+ unsigned int x_resend_chunks[RESEND_MAX_CHUNKS]; // body contains the chunks to resend
+ unsigned int x_resend_udp_packet_size;
+
+ // transmission info
+ unsigned int x_connection_id;
+ unsigned int x_nb_chunks;
+ unsigned int x_chunk_size;
+ unsigned int *x_chunk_list;
+ char *x_data_type;
+ unsigned int x_data_size;
+ void *x_data;
+ struct sockaddr_in x_source_socket;
+ int x_sslen;
+ int x_receive_finished;
+ int x_packet_transferred;
+
+ int x_socket; //socket used for sending
+ struct sockaddr_in x_sa; //address struct
+
+} t_pdp_udp_receiver;
+
+/* setup */
+t_pdp_udp_receiver *pdp_udp_receiver_new(int port);
+void pdp_udp_receiver_free(t_pdp_udp_receiver *x);
+
+/* reset connection (wait for new packet) */
+void pdp_udp_receiver_reset(t_pdp_udp_receiver *x);
+
+/* receive, returns 1 on success, 0 on timeout, -1 on error */
+int pdp_udp_receiver_receive(t_pdp_udp_receiver *x, unsigned int timeout_ms);
+
+/* get meta & data */
+char *pdp_udp_receiver_type(t_pdp_udp_receiver *x);
+unsigned int pdp_udp_receiver_size(t_pdp_udp_receiver *x);
+void *pdp_udp_receiver_data(t_pdp_udp_receiver *x);
+
+
+
+/* SENDER */
+typedef struct _pdp_udp_sender
+{
+ // desired udp packet size
+ unsigned int x_udp_payload_size;
+
+ // current packet && communication info
+ unsigned int x_connection_id;
+ char *x_data_type;
+ void *x_data;
+ unsigned int x_data_size;
+ unsigned int x_chunk_size;
+ unsigned int *x_chunk_list;
+ unsigned int x_nb_chunks;
+ unsigned int x_chunk_list_size;
+
+ // connection data
+ int x_socket; //socket used for sending
+ struct sockaddr_in x_sa; //address struct
+ unsigned int x_sleepgrain_us; //pause between sends (the poor man's flow control) (0 == no sleep)
+ unsigned int x_sleep_count;
+ unsigned int x_sleep_period;
+ unsigned int x_timeout_us;
+
+ // temp buffer for sending
+ t_pdp_udp_header x_header;
+ char x_buf[PDP_UDP_BUFSIZE];
+ unsigned int x_buf_size;
+
+ // temp buffer for receiving
+ t_pdp_udp_header x_resend_header;
+ unsigned int x_resend_chunks[RESEND_MAX_CHUNKS];
+ unsigned int x_resend_items;
+
+
+} t_pdp_udp_sender;
+
+/* some flow control variables */
+void pdp_udp_sender_timeout_us(t_pdp_udp_sender *x, unsigned int timeout_us);
+void pdp_udp_sender_sleepgrain_us(t_pdp_udp_sender *x, unsigned int sleepgrain_us);
+void pdp_udp_sender_sleepperiod(t_pdp_udp_sender *x, unsigned int sleepperiod);
+void pdp_udp_sender_udp_packet_size(t_pdp_udp_sender *x, unsigned int udp_packet_size);
+
+/* setup */
+t_pdp_udp_sender *pdp_udp_sender_new(void);
+void pdp_udp_sender_free(t_pdp_udp_sender *x);
+
+/* connect */
+void pdp_udp_sender_connect(t_pdp_udp_sender *x, char *host, unsigned int port);
+
+/* send, returns 1 on success, 0 on error */
+int pdp_udp_sender_send(t_pdp_udp_sender *x, char* type, unsigned int size, void *data);
+
+
+
+#endif
diff --git a/include/pdp_pd.h b/include/pdp_pd.h
new file mode 100644
index 0000000..e200c1e
--- /dev/null
+++ b/include/pdp_pd.h
@@ -0,0 +1,7 @@
+/* pdp_pd.h wrapper */
+
+#ifndef _M_PD_H_
+#define _M_PD_H_
+#include "m_pd.h"
+#endif
+
diff --git a/include/pdp_post.h b/include/pdp_post.h
new file mode 100644
index 0000000..05b5143
--- /dev/null
+++ b/include/pdp_post.h
@@ -0,0 +1,29 @@
+
+/*
+ * Pure Data Packet header file. pdp logging.
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _PDP_POST_H_
+#define _PDP_POST_H_
+
+/* write a message to log (console) */
+void pdp_post_n(char *fmt, ...);
+void pdp_post(char *fmt, ...);
+
+#endif
diff --git a/include/pdp_symbol.h b/include/pdp_symbol.h
new file mode 100644
index 0000000..fe3137a
--- /dev/null
+++ b/include/pdp_symbol.h
@@ -0,0 +1,136 @@
+/*
+ * Pure Data Packet system implementation. : symbol and namespace stuff
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _PDP_SYMBOL_
+#define _PDP_SYMBOL_
+
+
+/* pdp's symbols are derived from pd's symbols
+ there is one symbol hash. each symbol has
+ a meaning in several name spaces.
+
+ * forth words
+ * type description lists (for accelerating type matching)
+
+
+*/
+
+#include "pdp_list.h"
+
+
+
+
+/* the pdp symbol type */
+typedef struct _pdp_symbol
+{
+ /* next */
+ struct _pdp_symbol *s_next;
+
+ /* the symbol name */
+ char *s_name;
+
+ /* forth symbol->atom */
+ struct _pdp_atom s_forth;
+
+ /* packet handling cache */
+ struct _pdp_list *s_type; // a parsed type description: a/b/c -> (a,b,c)
+ struct _pdp_list *s_reusefifo; // packet pool fifo for this type
+
+
+} t_pdp_symbol;
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* namespace stuff */
+int pdp_symbol_set_typelist(t_pdp_symbol *s, struct _pdp_list *typelist);
+
+/* get symbol from char */
+t_pdp_symbol *pdp_gensym(char *s);
+
+/* iterate over all symbols */
+typedef void (*t_pdp_symbol_iterator)(t_pdp_symbol *s);
+void pdp_symbol_apply_all(t_pdp_symbol_iterator ir);
+
+// don't use these directly, use the macros
+extern t_pdp_symbol _pdp_sym_wildcard;
+extern t_pdp_symbol _pdp_sym_float;
+extern t_pdp_symbol _pdp_sym_int;
+extern t_pdp_symbol _pdp_sym_symbol;
+extern t_pdp_symbol _pdp_sym_packet;
+extern t_pdp_symbol _pdp_sym_pointer;
+extern t_pdp_symbol _pdp_sym_list;
+extern t_pdp_symbol _pdp_sym_invalid;
+extern t_pdp_symbol _pdp_sym_question_mark;
+extern t_pdp_symbol _pdp_sym_atom;
+extern t_pdp_symbol _pdp_sym_null;
+extern t_pdp_symbol _pdp_sym_quote_start;
+extern t_pdp_symbol _pdp_sym_quote_end;
+extern t_pdp_symbol _pdp_sym_return;
+extern t_pdp_symbol _pdp_sym_nreturn;
+extern t_pdp_symbol _pdp_sym_defstart;
+extern t_pdp_symbol _pdp_sym_defend;
+extern t_pdp_symbol _pdp_sym_if;
+extern t_pdp_symbol _pdp_sym_then;
+extern t_pdp_symbol _pdp_sym_local;
+extern t_pdp_symbol _pdp_sym_forth;
+extern t_pdp_symbol _pdp_sym_call;
+extern t_pdp_symbol _pdp_sym_push;
+extern t_pdp_symbol _pdp_sym_pop;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+// these symbols are used a lot in critical parts
+// optimize later
+
+#define PDP_SYM_WILDCARD &_pdp_sym_wildcard
+#define PDP_SYM_FLOAT &_pdp_sym_float
+#define PDP_SYM_INT &_pdp_sym_int
+#define PDP_SYM_SYMBOL &_pdp_sym_symbol
+#define PDP_SYM_PACKET &_pdp_sym_packet
+#define PDP_SYM_POINTER &_pdp_sym_pointer
+#define PDP_SYM_LIST &_pdp_sym_list
+#define PDP_SYM_INVALID &_pdp_sym_invalid
+#define PDP_SYM_QUESTION_MARK &_pdp_sym_question_mark
+#define PDP_SYM_ATOM &_pdp_sym_atom
+#define PDP_SYM_NULL &_pdp_sym_null
+#define PDP_SYM_QUOTE_START &_pdp_sym_quote_start
+#define PDP_SYM_QUOTE_END &_pdp_sym_quote_end
+#define PDP_SYM_RETURN &_pdp_sym_return
+#define PDP_SYM_NRETURN &_pdp_sym_nreturn
+#define PDP_SYM_DEF_START &_pdp_sym_defstart
+#define PDP_SYM_DEF_END &_pdp_sym_defend
+#define PDP_SYM_IF &_pdp_sym_if
+#define PDP_SYM_THEN &_pdp_sym_then
+#define PDP_SYM_LOCAL &_pdp_sym_local
+#define PDP_SYM_FORTH &_pdp_sym_forth
+#define PDP_SYM_CALL &_pdp_sym_call
+#define PDP_SYM_PUSH &_pdp_sym_push
+#define PDP_SYM_POP &_pdp_sym_pop
+
+#endif
+
diff --git a/include/pdp_xvideo.h b/include/pdp_xvideo.h
new file mode 100644
index 0000000..c395605
--- /dev/null
+++ b/include/pdp_xvideo.h
@@ -0,0 +1,78 @@
+
+/*
+ * Pure Data Packet header file: xwindow glue code
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+
+// x stuff
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvlib.h>
+
+// image formats for communication with the X Server
+#define FOURCC_YV12 0x32315659 /* YV12 YUV420P */
+#define FOURCC_YUV2 0x32595559 /* YUV2 YUV422 */
+#define FOURCC_I420 0x30323449 /* I420 Intel Indeo 4 */
+
+
+
+/* xvideo class */
+typedef struct _pdp_xvideo
+{
+
+ t_pdp_xdisplay *xdpy;
+ t_pdp_xwindow *xwin;
+ //Display *dpy;
+ //int screen;
+ //Window win;
+
+
+
+ int xv_format;
+ int xv_port;
+
+ XvImage *xvi;
+ unsigned char *data;
+ unsigned int width;
+ unsigned int height;
+ int last_encoding;
+
+ int initialized;
+
+} t_pdp_xvideo;
+
+
+/* cons */
+void pdp_xvideo_init(t_pdp_xvideo *x);
+t_pdp_xvideo *pdp_xvideo_new(void);
+
+/* des */
+void pdp_xvideo_cleanup(t_pdp_xvideo* x);
+void pdp_xvideo_free(t_pdp_xvideo* x);
+
+
+/* open an xv port (and create XvImage) */
+int pdp_xvideo_open_on_display(t_pdp_xvideo *x, t_pdp_xdisplay *d);
+
+/* close xv port (and delete XvImage */
+void pdp_xvideo_close(t_pdp_xvideo* x);
+
+/* display a packet */
+void pdp_xvideo_display_packet(t_pdp_xvideo *x, t_pdp_xwindow *w, int packet);