Browse Source

use new struct stream_input where appropriate

git.mgm/mediaproxy-ng/2.2
Richard Fuchs 13 years ago
parent
commit
b66809bb8c
3 changed files with 41 additions and 37 deletions
  1. +30
    -29
      daemon/call.c
  2. +4
    -1
      daemon/call.h
  3. +7
    -7
      daemon/sdp.c

+ 30
- 29
daemon/call.c View File

@ -450,7 +450,7 @@ static void info_parse(const char *s, struct call *c) {
static int streams_parse_func(char **a, void **ret, void *p) { static int streams_parse_func(char **a, void **ret, void *p) {
struct stream *st;
struct stream_input *st;
u_int32_t ip; u_int32_t ip;
int *i; int *i;
@ -461,11 +461,11 @@ static int streams_parse_func(char **a, void **ret, void *p) {
if (ip == -1) if (ip == -1)
goto fail; goto fail;
in4_to_6(&st->ip46, ip);
st->port = atoi(a[1]);
st->num = ++(*i);
in4_to_6(&st->stream.ip46, ip);
st->stream.port = atoi(a[1]);
st->stream.num = ++(*i);
if (!st->port && strcmp(a[1], "0"))
if (!st->stream.port && strcmp(a[1], "0"))
goto fail; goto fail;
*ret = st; *ret = st;
@ -485,7 +485,7 @@ static void streams_parse(const char *s, struct callmaster *m, GQueue *q) {
} }
static void streams_free(GQueue *q) { static void streams_free(GQueue *q) {
struct stream *s;
struct stream_input *s;
while ((s = g_queue_pop_head(q))) { while ((s = g_queue_pop_head(q))) {
g_slice_free1(sizeof(*s), s); g_slice_free1(sizeof(*s), s);
@ -986,7 +986,7 @@ fail:
} }
/* caller is responsible for appropriate locking */ /* caller is responsible for appropriate locking */
static int setup_peer(struct peer *p, struct stream *s, const str *tag) {
static int setup_peer(struct peer *p, struct stream_input *s, const str *tag) {
struct streamrelay *a, *b; struct streamrelay *a, *b;
struct callstream *cs; struct callstream *cs;
struct call *ca; struct call *ca;
@ -997,16 +997,17 @@ static int setup_peer(struct peer *p, struct stream *s, const str *tag) {
a = &p->rtps[0]; a = &p->rtps[0];
b = &p->rtps[1]; b = &p->rtps[1];
if (a->peer_advertised.port != s->port || !IN6_ARE_ADDR_EQUAL(&a->peer_advertised.ip46, &s->ip46)) {
if (a->peer_advertised.port != s->stream.port
|| !IN6_ARE_ADDR_EQUAL(&a->peer_advertised.ip46, &s->stream.ip46)) {
cs->peers[0].confirmed = 0; cs->peers[0].confirmed = 0;
unkernelize(&cs->peers[0]); unkernelize(&cs->peers[0]);
cs->peers[1].confirmed = 0; cs->peers[1].confirmed = 0;
unkernelize(&cs->peers[1]); unkernelize(&cs->peers[1]);
} }
a->peer.ip46 = s->ip46;
b->peer.ip46 = s->ip46;
a->peer.port = b->peer.port = s->port;
a->peer.ip46 = s->stream.ip46;
b->peer.ip46 = s->stream.ip46;
a->peer.port = b->peer.port = s->stream.port;
if (b->peer.port) if (b->peer.port)
b->peer.port++; b->peer.port++;
a->peer_advertised = a->peer; a->peer_advertised = a->peer;
@ -1173,7 +1174,7 @@ static void callstream_free(void *ptr) {
static int call_streams(struct call *c, GQueue *s, const str *tag, int opmode) { static int call_streams(struct call *c, GQueue *s, const str *tag, int opmode) {
GQueue *q; GQueue *q;
GList *i, *l; GList *i, *l;
struct stream *t;
struct stream_input *t;
int x; int x;
struct streamrelay *r; struct streamrelay *r;
struct callstream *cs, *cs_o; struct callstream *cs, *cs_o;
@ -1194,12 +1195,12 @@ static int call_streams(struct call *c, GQueue *s, const str *tag, int opmode) {
for (x = 0; x < 2; x++) { for (x = 0; x < 2; x++) {
r = &cs_o->peers[x].rtps[0]; r = &cs_o->peers[x].rtps[0];
DBG("comparing new ["IP6F"]:%u/%.*s to old ["IP6F"]:%u/%.*s", DBG("comparing new ["IP6F"]:%u/%.*s to old ["IP6F"]:%u/%.*s",
IP6P(&t->ip46), t->port, STR_FMT(tag),
IP6P(&t->stream.ip46), t->stream.port, STR_FMT(tag),
IP6P(&r->peer_advertised.ip46), r->peer_advertised.port, STR_FMT(&cs_o->peers[x].tag)); IP6P(&r->peer_advertised.ip46), r->peer_advertised.port, STR_FMT(&cs_o->peers[x].tag));
if (!IN6_ARE_ADDR_EQUAL(&r->peer_advertised.ip46, &t->ip46))
if (!IN6_ARE_ADDR_EQUAL(&r->peer_advertised.ip46, &t->stream.ip46))
continue; continue;
if (r->peer_advertised.port != t->port)
if (r->peer_advertised.port != t->stream.port)
continue; continue;
if (str_cmp_str0(&cs_o->peers[x].tag, tag)) if (str_cmp_str0(&cs_o->peers[x].tag, tag))
continue; continue;
@ -1219,7 +1220,7 @@ found:
if (!opmode) { /* request */ if (!opmode) { /* request */
DBG("creating new callstream"); DBG("creating new callstream");
cs = callstream_new(c, t->num);
cs = callstream_new(c, t->stream.num);
mutex_lock(&cs->lock); mutex_lock(&cs->lock);
if (!r) { if (!r) {
@ -1255,8 +1256,8 @@ found:
cs = l->data; cs = l->data;
if (cs != cs_o) if (cs != cs_o)
mutex_lock(&cs->lock); mutex_lock(&cs->lock);
DBG("hunting for callstream, %i <> %i", cs->num, t->num);
if (cs->num == t->num)
DBG("hunting for callstream, %i <> %i", cs->num, t->stream.num);
if (cs->num == t->stream.num)
goto got_cs; goto got_cs;
if (cs != cs_o) if (cs != cs_o)
mutex_unlock(&cs->lock); mutex_unlock(&cs->lock);
@ -1312,7 +1313,7 @@ got_cs:
if (cs_o && cs_o != cs) if (cs_o && cs_o != cs)
mutex_unlock(&cs_o->lock); mutex_unlock(&cs_o->lock);
cs_o = cs; cs_o = cs;
cs = callstream_new(c, t->num);
cs = callstream_new(c, t->stream.num);
mutex_lock(&cs->lock); mutex_lock(&cs->lock);
callstream_init(cs, 0, 0); callstream_init(cs, 0, 0);
steal_peer(&cs->peers[0], &cs_o->peers[0]); steal_peer(&cs->peers[0], &cs_o->peers[0]);
@ -1602,7 +1603,7 @@ restart:
return c; return c;
} }
static int addr_parse_udp(struct stream *st, char **out) {
static int addr_parse_udp(struct stream_input *st, char **out) {
u_int32_t ip4; u_int32_t ip4;
const char *cp; const char *cp;
char c; char c;
@ -1613,17 +1614,17 @@ static int addr_parse_udp(struct stream *st, char **out) {
ip4 = inet_addr(out[RE_UDP_UL_ADDR4]); ip4 = inet_addr(out[RE_UDP_UL_ADDR4]);
if (ip4 == -1) if (ip4 == -1)
goto fail; goto fail;
in4_to_6(&st->ip46, ip4);
in4_to_6(&st->stream.ip46, ip4);
} }
else if (out[RE_UDP_UL_ADDR6] && *out[RE_UDP_UL_ADDR6]) { else if (out[RE_UDP_UL_ADDR6] && *out[RE_UDP_UL_ADDR6]) {
if (inet_pton(AF_INET6, out[RE_UDP_UL_ADDR6], &st->ip46) != 1)
if (inet_pton(AF_INET6, out[RE_UDP_UL_ADDR6], &st->stream.ip46) != 1)
goto fail; goto fail;
} }
else else
goto fail; goto fail;
st->port = atoi(out[RE_UDP_UL_PORT]);
if (!st->port && strcmp(out[RE_UDP_UL_PORT], "0"))
st->stream.port = atoi(out[RE_UDP_UL_PORT]);
if (!st->stream.port && strcmp(out[RE_UDP_UL_PORT], "0"))
goto fail; goto fail;
if (out[RE_UDP_UL_FLAGS] && *out[RE_UDP_UL_FLAGS]) { if (out[RE_UDP_UL_FLAGS] && *out[RE_UDP_UL_FLAGS]) {
@ -1638,9 +1639,9 @@ static int addr_parse_udp(struct stream *st, char **out) {
} }
if (out[RE_UDP_UL_NUM] && *out[RE_UDP_UL_NUM]) if (out[RE_UDP_UL_NUM] && *out[RE_UDP_UL_NUM])
st->num = atoi(out[RE_UDP_UL_NUM]);
if (!st->num)
st->num = 1;
st->stream.num = atoi(out[RE_UDP_UL_NUM]);
if (!st->stream.num)
st->stream.num = 1;
return 0; return 0;
fail: fail:
@ -1650,7 +1651,7 @@ fail:
str *call_update_udp(char **out, struct callmaster *m) { str *call_update_udp(char **out, struct callmaster *m) {
struct call *c; struct call *c;
GQueue q = G_QUEUE_INIT; GQueue q = G_QUEUE_INIT;
struct stream st;
struct stream_input st;
int num; int num;
str *ret, callid, viabranch, fromtag; str *ret, callid, viabranch, fromtag;
@ -1691,7 +1692,7 @@ fail:
str *call_lookup_udp(char **out, struct callmaster *m) { str *call_lookup_udp(char **out, struct callmaster *m) {
struct call *c; struct call *c;
GQueue q = G_QUEUE_INIT; GQueue q = G_QUEUE_INIT;
struct stream st;
struct stream_input st;
int num; int num;
str *ret, callid, branch, totag; str *ret, callid, branch, totag;


+ 4
- 1
daemon/call.h View File

@ -45,12 +45,15 @@ struct stats {
struct stream { struct stream {
struct in6_addr ip46; struct in6_addr ip46;
u_int16_t port; u_int16_t port;
int num;
};
struct stream_input {
struct stream stream;
enum { enum {
DIR_UNKNOWN = 0, DIR_UNKNOWN = 0,
DIR_INTERNAL, DIR_INTERNAL,
DIR_EXTERNAL, DIR_EXTERNAL,
} direction[2]; } direction[2];
int num;
}; };
struct streamrelay { struct streamrelay {
int fd; int fd;


+ 7
- 7
daemon/sdp.c View File

@ -305,7 +305,7 @@ void sdp_free(GQueue *sessions) {
int sdp_streams(const GQueue *sessions, GQueue *streams) { int sdp_streams(const GQueue *sessions, GQueue *streams) {
struct sdp_session *session; struct sdp_session *session;
struct sdp_media *media; struct sdp_media *media;
struct stream *stream;
struct stream_input *si;
GList *l, *k; GList *l, *k;
const char *errstr; const char *errstr;
int i, num; int i, num;
@ -318,22 +318,22 @@ int sdp_streams(const GQueue *sessions, GQueue *streams) {
media = k->data; media = k->data;
for (i = 0; i < media->port_count; i++) { for (i = 0; i < media->port_count; i++) {
stream = g_slice_alloc0(sizeof(*stream));
si = g_slice_alloc0(sizeof(*si));
errstr = "No address info found for stream"; errstr = "No address info found for stream";
if (media->connection.parsed) if (media->connection.parsed)
stream->ip46 = media->connection.address.parsed;
si->stream.ip46 = media->connection.address.parsed;
else if (session->connection.parsed) else if (session->connection.parsed)
stream->ip46 = session->connection.address.parsed;
si->stream.ip46 = session->connection.address.parsed;
else else
goto error; goto error;
/* XXX ports must be consecutive */ /* XXX ports must be consecutive */
/* XXX check for RTP type */ /* XXX check for RTP type */
stream->port = (media->port_num + (i * 2)) & 0xffff;
stream->num = ++num;
si->stream.port = (media->port_num + (i * 2)) & 0xffff;
si->stream.num = ++num;
g_queue_push_tail(streams, stream);
g_queue_push_tail(streams, si);
} }
} }
} }


Loading…
Cancel
Save