Commit 4b61c2f2 authored by Dafydd Harries's avatar Dafydd Harries

hoist _stream_lookup; add _candidate_lookup and use it

darcs-hash:20070215173602-c9803-3222fe82da60e3e2dd324f63402295185387cf84.gz
parent 3f4b2f79
...@@ -161,6 +161,51 @@ enum ...@@ -161,6 +161,51 @@ enum
static guint signals[N_SIGNALS]; static guint signals[N_SIGNALS];
static Stream *
_stream_lookup (NiceAgent *agent, guint stream_id)
{
GSList *i;
for (i = agent->streams; i; i = i->next)
{
Stream *s = i->data;
if (s->id == stream_id)
return s;
}
return NULL;
}
static gboolean
_component_lookup (
NiceAgent *agent,
guint stream_id,
guint component_id,
Stream **stream,
Component **component)
{
Stream *s;
if (component_id != 1)
return FALSE;
s = _stream_lookup (agent, stream_id);
if (stream == NULL)
return FALSE;
if (stream)
*stream = s;
if (component)
*component = s->component;
return TRUE;
}
static void static void
nice_agent_dispose (GObject *object); nice_agent_dispose (GObject *object);
...@@ -357,23 +402,6 @@ nice_agent_add_stream ( ...@@ -357,23 +402,6 @@ nice_agent_add_stream (
} }
static Stream *
_stream_lookup (NiceAgent *agent, guint stream_id)
{
GSList *i;
for (i = agent->streams; i; i = i->next)
{
Stream *s = i->data;
if (s->id == stream_id)
return s;
}
return NULL;
}
/** /**
* nice_agent_remove_stream: * nice_agent_remove_stream:
* @agent: a NiceAgent * @agent: a NiceAgent
...@@ -903,13 +931,19 @@ nice_agent_recv ( ...@@ -903,13 +931,19 @@ nice_agent_recv (
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
Stream *stream; Stream *stream;
Component *component;
candidate = _local_candidate_lookup_by_fd (agent, j); candidate = _local_candidate_lookup_by_fd (agent, j);
g_assert (candidate);
stream = _stream_lookup (agent, candidate->stream_id); if (candidate == NULL)
g_assert (stream); continue;
len = _nice_agent_recv (agent, stream, stream->component,
candidate, buf_len, buf); if (!_component_lookup (agent, candidate->stream_id,
candidate->component_id, &stream, &component))
continue;
len = _nice_agent_recv (agent, stream, component, candidate,
buf_len, buf);
if (len > 0) if (len > 0)
return len; return len;
...@@ -932,13 +966,15 @@ nice_agent_recv_sock ( ...@@ -932,13 +966,15 @@ nice_agent_recv_sock (
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
Stream *stream; Stream *stream;
Component *component;
candidate = _local_candidate_lookup_by_fd (agent, sock); candidate = _local_candidate_lookup_by_fd (agent, sock);
g_assert (candidate); g_assert (candidate);
stream = _stream_lookup (agent, candidate->stream_id);
g_assert (stream); if (!_component_lookup (agent, stream_id, component_id, &stream, &component))
return _nice_agent_recv (agent, stream, stream->component, return 0;
candidate, buf_len, buf);
return _nice_agent_recv (agent, stream, component, candidate, buf_len, buf);
} }
...@@ -1009,20 +1045,19 @@ nice_agent_poll_read ( ...@@ -1009,20 +1045,19 @@ nice_agent_poll_read (
if (candidate->sock.fileno == j) if (candidate->sock.fileno == j)
{ {
Stream *stream; Stream *stream;
Component *component;
gchar buf[1024]; gchar buf[1024];
guint len; guint len;
stream = _stream_lookup (agent, candidate->stream_id); if (!_component_lookup (agent, candidate->stream_id,
candidate->component_id, &stream, &component))
if (stream == NULL)
break; break;
len = _nice_agent_recv (agent, stream, stream->component, len = _nice_agent_recv (agent, stream, component, candidate,
candidate, 1024, buf); 1024, buf);
if (len && func != NULL) if (len && func != NULL)
func (agent, stream->id, candidate->component_id, len, buf, func (agent, stream->id, component->id, len, buf, data);
data);
} }
} }
} }
...@@ -1043,8 +1078,8 @@ nice_agent_send ( ...@@ -1043,8 +1078,8 @@ nice_agent_send (
Stream *stream; Stream *stream;
Component *component; Component *component;
stream = _stream_lookup (agent, stream_id); if (!_component_lookup (agent, stream_id, component_id, &stream, &component))
component = stream->component; return;
if (component->active_candidate != NULL) if (component->active_candidate != NULL)
{ {
...@@ -1169,6 +1204,7 @@ nice_agent_g_source_cb ( ...@@ -1169,6 +1204,7 @@ nice_agent_g_source_cb (
NiceAgent *agent = data; NiceAgent *agent = data;
NiceCandidate *candidate; NiceCandidate *candidate;
Stream *stream; Stream *stream;
Component *component;
gchar buf[1024]; gchar buf[1024];
guint len; guint len;
...@@ -1178,17 +1214,15 @@ nice_agent_g_source_cb ( ...@@ -1178,17 +1214,15 @@ nice_agent_g_source_cb (
if (candidate == NULL) if (candidate == NULL)
return TRUE; return TRUE;
stream = _stream_lookup (agent, candidate->stream_id); if (!_component_lookup (agent, candidate->stream_id,
candidate->component_id, &stream, &component))
if (stream == NULL)
return TRUE; return TRUE;
len = _nice_agent_recv (agent, stream, stream->component, candidate, 1024, len = _nice_agent_recv (agent, stream, component, candidate, 1024, buf);
buf);
if (len > 0) if (len > 0)
agent->read_func (agent, candidate->stream_id, candidate->component_id, agent->read_func (agent, stream->id, component->id, len, buf,
len, buf, agent->read_func_data); agent->read_func_data);
return TRUE; return TRUE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment