Commit 9c8c246d authored by Dafydd Harries's avatar Dafydd Harries

add agent/ subdirectory

darcs-hash:20070109175616-c9803-f537be0381966922b3a33ce453fed2eedea70c75.gz
parent 4c4b0689
AM_CFLAGS = -Wall -Werror $(GLIB_CFLAGS)
libagent_a_SOURCES = agent.h agent.c
noinst_LIBRARIES = libagent.a
noinst_PROGRAMS = test
test_LDADD = libagent.a $(GLIB_LIBS)
TESTS = test
This diff is collapsed.
#ifndef _AGENT_H
#define _AGENT_H
enum media_type
{
MEDIA_TYPE_AUDIO,
MEDIA_TYPE_VIDEO,
};
/*** address ***/
typedef struct _address Address;
Address *
address_new_ipv4_from_string (gchar *str);
gboolean
address_equal (Address *a, Address *b);
void
address_free (Address *addr);
/*** candidate ***/
enum candidate_type
{
CANDIDATE_TYPE_HOST,
CANDIDATE_TYPE_SERVER_REFLEXIVE,
CANDIDATE_TYPE_PEER_REFLEXIVE,
CANDIDATE_TYPE_RELAYED,
};
typedef struct _candidate Candidate;
struct _candidate
{
enum candidate_type type;
guint id;
Address *addr;
Address *base_addr;
// guint sock;
guint16 port;
guint32 priority;
// Stream *stream;
// guint component_id;
// guint generation;
// gchar *foundation;
};
/*** event ***/
enum event_type
{
EVENT_REQUEST_PORT,
EVENT_LOCAL_CANDIDATES_READY,
EVENT_REQUEST_STUN_QUERY,
EVENT_CANDIDATE_SELECTED,
};
typedef struct _event Event;
struct _event
{
enum event_type type;
union {
struct {
Address *addr;
guint candidate_id;
} request_port;
struct {
Address *from;
guint from_port;
Address *to;
guint to_port;
} request_stun_query;
};
};
void
event_free (Event *ev);
/*** agent ***/
typedef struct _agent Agent;
struct _agent
{
guint next_candidate_id;
GSList *local_addresses;
GSList *local_candidates;
GSList *streams;
GSList *events;
};
Agent *
ice_agent_new ();
Event *
ice_agent_pop_event (Agent *agent);
void
ice_agent_add_local_address (Agent *agent, Address *addr);
void
ice_agent_add_stream (Agent *agent, enum media_type type);
void
ice_agent_set_candidate_port (Agent *agent, guint candidate_id, guint port);
void
ice_agent_free (Agent *agent);
#endif /* _AGENT_H */
#include <glib.h>
#include <agent.h>
gint
main (void)
{
Agent *agent;
Address *addr;
Candidate *candidate;
Event *event;
agent = ice_agent_new ();
g_assert (agent->local_addresses == NULL);
g_assert (agent->local_candidates == NULL);
g_assert (ice_agent_pop_event (agent) == NULL);
/* add one local address */
addr = address_new_ipv4_from_string ("192.168.0.1");
ice_agent_add_local_address (agent, addr);
g_assert (agent->local_addresses != NULL);
g_assert (g_slist_length (agent->local_addresses) == 1);
g_assert (address_equal ((Address *) agent->local_addresses->data, addr));
/* no candidates should be generated until we have a stream */
g_assert (agent->local_candidates == NULL);
/* add an audio stream */
ice_agent_add_stream (agent, MEDIA_TYPE_AUDIO);
/* adding a stream should cause host candidates to be generated */
g_assert (agent->local_candidates != NULL);
g_assert (g_slist_length (agent->local_candidates) == 1);
candidate = (Candidate *) agent->local_candidates->data;
g_assert (candidate->id == 1);
g_assert (candidate->port == 0);
/* there should be a port request for the new candidate */
event = ice_agent_pop_event (agent);
g_assert (ice_agent_pop_event (agent) == NULL);
g_assert (event != NULL);
g_assert (event->type == EVENT_REQUEST_PORT);
g_assert (address_equal (event->request_port.addr, addr));
g_assert (event->request_port.candidate_id == 1);
event_free (event);
/* assign a port */
ice_agent_set_candidate_port (agent, 1, 1234);
g_assert (candidate->port == 1234);
/* expect event: local candidates ready */
event = ice_agent_pop_event (agent);
g_assert (ice_agent_pop_event (agent) == NULL);
g_assert (event != NULL);
g_assert (event->type == EVENT_LOCAL_CANDIDATES_READY);
event_free (event);
/* add remote candidate */
/* check there's no unexpected events, and clean up */
g_assert (ice_agent_pop_event (agent) == NULL);
address_free (addr);
ice_agent_free (agent);
return 0;
}
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