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

#ifndef _AGENT_H
#define _AGENT_H

5 6 7 8

#include "address.h"


Dafydd Harries's avatar
Dafydd Harries committed
9 10
typedef enum media_type MediaType;

Dafydd Harries's avatar
Dafydd Harries committed
11 12 13 14 15 16 17 18 19
enum media_type
{
  MEDIA_TYPE_AUDIO,
  MEDIA_TYPE_VIDEO,
};


/*** candidate ***/

Dafydd Harries's avatar
Dafydd Harries committed
20
typedef enum candidate_type CandidateType;
Dafydd Harries's avatar
Dafydd Harries committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34

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
35
  CandidateType type;
Dafydd Harries's avatar
Dafydd Harries committed
36
  guint id;
37 38
  Address addr;
  Address base_addr;
Dafydd Harries's avatar
Dafydd Harries committed
39 40
  guint16 port;
  guint32 priority;
41 42
  guint stream_id;
  guint component_id;
Dafydd Harries's avatar
Dafydd Harries committed
43 44
  // guint generation;
  // gchar *foundation;
45
  UDPSocket sock;
Dafydd Harries's avatar
Dafydd Harries committed
46 47 48
};


49 50 51 52 53 54
Candidate *
candidate_new (CandidateType type);
void
candidate_free (Candidate *candidate);


Dafydd Harries's avatar
Dafydd Harries committed
55 56 57
/*** event ***/


Dafydd Harries's avatar
Dafydd Harries committed
58 59
typedef enum event_type EventType;

Dafydd Harries's avatar
Dafydd Harries committed
60 61 62 63 64 65 66 67 68 69
enum event_type
{
  EVENT_CANDIDATE_SELECTED,
};


typedef struct _event Event;

struct _event
{
Dafydd Harries's avatar
Dafydd Harries committed
70
  EventType type;
Dafydd Harries's avatar
Dafydd Harries committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

  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
99
  guint next_stream_id;
100
  UDPSocketManager *sockmgr;
Dafydd Harries's avatar
Dafydd Harries committed
101 102
  GSList *local_addresses;
  GSList *local_candidates;
103
  GSList *remote_candidates;
Dafydd Harries's avatar
Dafydd Harries committed
104 105 106 107 108 109
  GSList *streams;
  GSList *events;
};


Agent *
110
ice_agent_new (UDPSocketManager *mgr);
Dafydd Harries's avatar
Dafydd Harries committed
111 112 113 114
Event *
ice_agent_pop_event (Agent *agent);
void
ice_agent_add_local_address (Agent *agent, Address *addr);
Dafydd Harries's avatar
Dafydd Harries committed
115
guint
116 117 118
ice_agent_add_stream (
  Agent *agent,
  MediaType type,
119 120
  void (*handle_recv) (
    Agent *agent, guint stream_id, guint component_id, guint len, gchar *buf));
Dafydd Harries's avatar
Dafydd Harries committed
121 122
void
ice_agent_free (Agent *agent);
123 124 125 126 127 128
void
ice_agent_add_remote_candidate (
  Agent *agent,
  CandidateType type,
  Address *addr,
  guint port);
Dafydd Harries's avatar
Dafydd Harries committed
129 130 131 132
void
ice_agent_recv (
  Agent *agent,
  guint candidate_id);
Dafydd Harries's avatar
Dafydd Harries committed
133 134 135

#endif /* _AGENT_H */