]> code.delx.au - pulseaudio/blob - src/modules/rtp/sdp.c
add an RTP sender module
[pulseaudio] / src / modules / rtp / sdp.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <time.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <arpa/inet.h>
32
33 #include <polypcore/util.h>
34
35 #include "sdp.h"
36
37 static const char* map_format(pa_sample_format_t f) {
38 switch (f) {
39 case PA_SAMPLE_S16BE: return "L16";
40 case PA_SAMPLE_U8: return "L8";
41 case PA_SAMPLE_ALAW: return "PCMA";
42 case PA_SAMPLE_ULAW: return "PCMU";
43 default:
44 return NULL;
45 }
46 }
47
48 char *pa_sdp_build(int af, const void *src, const void *dst, const char *name, uint16_t port, uint8_t payload, const pa_sample_spec *ss) {
49 uint32_t ntp;
50 char buf_src[64], buf_dst[64];
51 const char *u, *f, *a;
52
53 assert(src);
54 assert(dst);
55 assert(af == AF_INET || af == AF_INET6);
56
57 f = map_format(ss->format);
58 assert(f);
59
60 if (!(u = getenv("USER")))
61 if (!(u = getenv("USERNAME")))
62 u = "-";
63
64 ntp = time(NULL) + 2208988800;
65
66 a = inet_ntop(af, src, buf_src, sizeof(buf_src));
67 assert(a);
68 a = inet_ntop(af, dst, buf_dst, sizeof(buf_dst));
69 assert(a);
70
71 return pa_sprintf_malloc(
72 "v=0\n"
73 "o=%s %lu 0 IN %s %s\n"
74 "s=%s\n"
75 "c=IN %s %s\n"
76 "t=%lu 0\n"
77 "a=recvonly\n"
78 "m=audio %u RTP/AVP %i\n"
79 "a=rtpmap:%i %s/%u/%u\n"
80 "a=type:broadcast\n",
81 u, (unsigned long) ntp, af == AF_INET ? "IP4" : "IP6", buf_src,
82 name,
83 af == AF_INET ? "IP4" : "IP6", buf_dst,
84 (unsigned long) ntp,
85 port, payload,
86 payload, f, ss->rate, ss->channels);
87 }