comparison rtpproto.c @ 3228:697a11d7e3cf libavformat

Expose max_packet_size from the rtp protocol
author lu_zero
date Tue, 15 Apr 2008 19:27:39 +0000
parents e17b25e8a34e
children 510fab17efc3
comparison
equal deleted inserted replaced
3227:5b8e94932999 3228:697a11d7e3cf
82 va_end(ap); 82 va_end(ap);
83 } 83 }
84 84
85 static void build_udp_url(char *buf, int buf_size, 85 static void build_udp_url(char *buf, int buf_size,
86 const char *hostname, int port, 86 const char *hostname, int port,
87 int local_port, int ttl) 87 int local_port, int ttl,
88 int max_packet_size)
88 { 89 {
89 snprintf(buf, buf_size, "udp://%s:%d", hostname, port); 90 snprintf(buf, buf_size, "udp://%s:%d", hostname, port);
90 if (local_port >= 0) 91 if (local_port >= 0)
91 url_add_option(buf, buf_size, "localport=%d", local_port); 92 url_add_option(buf, buf_size, "localport=%d", local_port);
92 if (ttl >= 0) 93 if (ttl >= 0)
93 url_add_option(buf, buf_size, "ttl=%d", ttl); 94 url_add_option(buf, buf_size, "ttl=%d", ttl);
95 if (max_packet_size >=0)
96 url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size);
94 } 97 }
95 98
96 /* 99 /*
97 * url syntax: rtp://host:port[?option=val...] 100 * url syntax: rtp://host:port[?option=val...]
98 * option: 'ttl=n' : set the ttl value (for multicast only) 101 * option: 'ttl=n' : set the ttl value (for multicast only)
99 * 'localport=n' : set the local port to n 102 * 'localport=n' : set the local port to n
103 * 'pkt_size=n' : set max packet size
100 * 104 *
101 */ 105 */
102 static int rtp_open(URLContext *h, const char *uri, int flags) 106 static int rtp_open(URLContext *h, const char *uri, int flags)
103 { 107 {
104 RTPContext *s; 108 RTPContext *s;
105 int port, is_output, ttl, local_port; 109 int port, is_output, ttl, local_port, max_packet_size;
106 char hostname[256]; 110 char hostname[256];
107 char buf[1024]; 111 char buf[1024];
108 char path[1024]; 112 char path[1024];
109 const char *p; 113 const char *p;
110 114
118 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, 122 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
119 path, sizeof(path), uri); 123 path, sizeof(path), uri);
120 /* extract parameters */ 124 /* extract parameters */
121 ttl = -1; 125 ttl = -1;
122 local_port = -1; 126 local_port = -1;
127 max_packet_size = -1;
128
123 p = strchr(uri, '?'); 129 p = strchr(uri, '?');
124 if (p) { 130 if (p) {
125 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { 131 if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
126 ttl = strtol(buf, NULL, 10); 132 ttl = strtol(buf, NULL, 10);
127 } 133 }
128 if (find_info_tag(buf, sizeof(buf), "localport", p)) { 134 if (find_info_tag(buf, sizeof(buf), "localport", p)) {
129 local_port = strtol(buf, NULL, 10); 135 local_port = strtol(buf, NULL, 10);
130 } 136 }
137 if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
138 max_packet_size = strtol(buf, NULL, 10);
139 }
131 } 140 }
132 141
133 build_udp_url(buf, sizeof(buf), 142 build_udp_url(buf, sizeof(buf),
134 hostname, port, local_port, ttl); 143 hostname, port, local_port, ttl, max_packet_size);
135 if (url_open(&s->rtp_hd, buf, flags) < 0) 144 if (url_open(&s->rtp_hd, buf, flags) < 0)
136 goto fail; 145 goto fail;
137 local_port = udp_get_local_port(s->rtp_hd); 146 local_port = udp_get_local_port(s->rtp_hd);
138 /* XXX: need to open another connection if the port is not even */ 147 /* XXX: need to open another connection if the port is not even */
139 148
140 /* well, should suppress localport in path */ 149 /* well, should suppress localport in path */
141 150
142 build_udp_url(buf, sizeof(buf), 151 build_udp_url(buf, sizeof(buf),
143 hostname, port + 1, local_port + 1, ttl); 152 hostname, port + 1, local_port + 1, ttl, max_packet_size);
144 if (url_open(&s->rtcp_hd, buf, flags) < 0) 153 if (url_open(&s->rtcp_hd, buf, flags) < 0)
145 goto fail; 154 goto fail;
146 155
147 /* just to ease handle access. XXX: need to suppress direct handle 156 /* just to ease handle access. XXX: need to suppress direct handle
148 access */ 157 access */