agent.h 2.52 KB
Newer Older
Dafydd Harries's avatar
Dafydd Harries committed
1 2 3 4

#ifndef _AGENT_H
#define _AGENT_H

Dafydd Harries's avatar
Dafydd Harries committed
5 6
typedef enum media_type MediaType;

Dafydd Harries's avatar
Dafydd Harries committed
7 8 9 10 11 12 13 14 15 16
enum media_type
{
  MEDIA_TYPE_AUDIO,
  MEDIA_TYPE_VIDEO,
};


/*** address ***/


17 18 19 20 21 22 23 24
typedef enum address_type AddressType;

enum address_type
{
  ADDRESS_TYPE_IPV4,
  ADDRESS_TYPE_IPV6,
};

Dafydd Harries's avatar
Dafydd Harries committed
25 26
typedef struct _address Address;

27 28 29 30 31 32 33 34 35 36
/* XXX: need access to fields to convert to sockaddr_in */
struct _address
{
  AddressType type;
  union
  {
    guint32 addr_ipv4;
    guchar addr_ipv6[16];
  };
};
Dafydd Harries's avatar
Dafydd Harries committed
37

38
Address *
39 40 41 42 43 44 45
address_new (void);
void
address_free (Address *addr);
void
address_set_ipv4 (Address *addr, guint32 addr_ipv4);
gboolean
address_set_ipv4_from_string (Address *addr, gchar *str);
Dafydd Harries's avatar
Dafydd Harries committed
46 47
gboolean
address_equal (Address *a, Address *b);
48 49
gchar *
address_to_string (Address *addr);
Dafydd Harries's avatar
Dafydd Harries committed
50 51 52 53


/*** candidate ***/

Dafydd Harries's avatar
Dafydd Harries committed
54
typedef enum candidate_type CandidateType;
Dafydd Harries's avatar
Dafydd Harries committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68

enum candidate_type
{
  CANDIDATE_TYPE_HOST,
  CANDIDATE_TYPE_SERVER_REFLEXIVE,
  CANDIDATE_TYPE_PEER_REFLEXIVE,
  CANDIDATE_TYPE_RELAYED,
};


typedef struct _candidate Candidate;

struct _candidate
{
Dafydd Harries's avatar
Dafydd Harries committed
69
  CandidateType type;
Dafydd Harries's avatar
Dafydd Harries committed
70 71 72 73 74 75 76
  guint id;
  Address *addr;
  Address *base_addr;
  // guint sock;
  guint16 port;
  guint32 priority;
  // Stream *stream;
77 78
  guint stream_id;
  guint component_id;
Dafydd Harries's avatar
Dafydd Harries committed
79 80
  // guint generation;
  // gchar *foundation;
81
  UDPSocket sock;
Dafydd Harries's avatar
Dafydd Harries committed
82 83 84
};


85 86 87 88 89 90
Candidate *
candidate_new (CandidateType type);
void
candidate_free (Candidate *candidate);


Dafydd Harries's avatar
Dafydd Harries committed
91 92 93
/*** event ***/


Dafydd Harries's avatar
Dafydd Harries committed
94 95
typedef enum event_type EventType;

Dafydd Harries's avatar
Dafydd Harries committed
96 97 98 99 100 101 102 103 104 105
enum event_type
{
  EVENT_CANDIDATE_SELECTED,
};


typedef struct _event Event;

struct _event
{
Dafydd Harries's avatar
Dafydd Harries committed
106
  EventType type;
Dafydd Harries's avatar
Dafydd Harries committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

  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;
Dafydd Harries's avatar
Dafydd Harries committed
135
  guint next_stream_id;
136
  UDPSocketManager *sockmgr;
Dafydd Harries's avatar
Dafydd Harries committed
137 138
  GSList *local_addresses;
  GSList *local_candidates;
139
  GSList *remote_candidates;
Dafydd Harries's avatar
Dafydd Harries committed
140 141 142 143 144 145
  GSList *streams;
  GSList *events;
};


Agent *
146
ice_agent_new (UDPSocketManager *mgr);
Dafydd Harries's avatar
Dafydd Harries committed
147 148 149 150
Event *
ice_agent_pop_event (Agent *agent);
void
ice_agent_add_local_address (Agent *agent, Address *addr);
Dafydd Harries's avatar
Dafydd Harries committed
151
guint
152 153 154 155
ice_agent_add_stream (
  Agent *agent,
  MediaType type,
  void (*handle_recv) (Agent *agent, guint stream_id, guint len, gchar *buf));
Dafydd Harries's avatar
Dafydd Harries committed
156 157
void
ice_agent_free (Agent *agent);
158 159 160 161 162 163
void
ice_agent_add_remote_candidate (
  Agent *agent,
  CandidateType type,
  Address *addr,
  guint port);
Dafydd Harries's avatar
Dafydd Harries committed
164 165 166 167
void
ice_agent_recv (
  Agent *agent,
  guint candidate_id);
Dafydd Harries's avatar
Dafydd Harries committed
168 169 170

#endif /* _AGENT_H */