1 /*
2 * Copyright (C) 2004 Nathan Lutchansky <lutchann@litech.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include <sys/types.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/time.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 #include <fcntl.h>
29 #include <errno.h>
30
31 #include <event.h>
32 #include <log.h>
33 #include <frame.h>
34 #include <stream.h>
35 #include <outputs.h>
36 #include <rtp.h>
37 #include <rtp_media.h>
38 #include <conf_parse.h>
39
40 static struct session *sess_list = NULL;
41
new_rtp_media(rtp_media_get_sdp_func get_sdp,rtp_media_get_payload_func get_payload,rtp_media_frame_func frame,rtp_media_send_func send,void * private)42 struct rtp_media *new_rtp_media( rtp_media_get_sdp_func get_sdp,
43 rtp_media_get_payload_func get_payload, rtp_media_frame_func frame,
44 rtp_media_send_func send, void *private )
45 {
46 struct rtp_media *m;
47
48 if( ! ( m = (struct rtp_media *)malloc( sizeof( *m ) ) ) )
49 return NULL;
50 m->get_sdp = get_sdp;
51 m->get_payload = get_payload;
52 m->frame = frame;
53 m->send = send;
54 m->private = private;
55 return m;
56 }
57
del_session(struct session * sess)58 void del_session( struct session *sess )
59 {
60 if( sess->next ) sess->next->prev = sess->prev;
61 if( sess->prev ) sess->prev->next = sess->next;
62 else sess_list = sess->next;
63 if( sess->control_close ) sess->control_close( sess );
64 free( sess );
65 }
66
new_session(void)67 struct session *new_session(void)
68 {
69 struct session *sess;
70 int i;
71
72 sess = (struct session *)malloc( sizeof( struct session ) );
73 sess->next = sess_list;
74 sess->prev = NULL;
75 if( sess->next ) sess->next->prev = sess;
76 sess_list = sess;
77 sess->get_sdp = NULL;
78 sess->setup = NULL;
79 sess->play = NULL;
80 sess->pause = NULL;
81 sess->private = NULL;
82 sess->control_private = NULL;
83 sess->control_close = NULL;
84 gettimeofday( &sess->open_time, NULL );
85 strcpy( sess->addr, "(unconnected)" );
86 for( i = 0; i < MAX_TRACKS; ++i ) sess->ep[i] = NULL;
87 return sess;
88 }
89
print_session_list(char * s,int maxlen)90 int print_session_list( char *s, int maxlen )
91 {
92 struct session *sess;
93 int i = 0;
94
95 for( sess = sess_list; sess; sess = sess->next )
96 i += sprintf( s + i, "%s %ld\n",
97 sess->addr, sess->open_time.tv_sec );
98 return i;
99 }
100