summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/AV/source.h
blob: b745fe6a359be67ec1b1563b55079937286ab10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
99
100
101
102
103
104
105
106
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* -*- C++ -*- */
// $Id$
/*
 * Copyright (c) 1994 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      California, Berkeley and the Network Research Group at
 *      Lawrence Berkeley Laboratory.
 * 4. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#) $Header$
 */

#ifndef TAO_AV_SOURCE_H
#define TAO_AV_SOURCE_H

#define RTCP_SDES_MAX 7

#include "ace/OS.h"
#include "tao/TAO.h"

class TAO_AV_SourceManager;

extern "C" 
{
  int compare_func (const void* v0, const void* v1);
}


#define TAO_AV_SOURCE_HASH 1024

class TAO_AV_Source
{
public:
  TAO_AV_Source (ACE_UINT32 srcid, ACE_UINT32 ssrc, ACE_UINT32 addr);
  virtual ~TAO_AV_Source (void);
  void deactivate (void);

  void action();
  // @@Naga:My additions.
  char *name ();
  int active (void);
  void active (int active);
  virtual void set_busy();
  ACE_UINT32 delvar () const;
  void delvar (ACE_UINT32 v);

  void lts_done (const timeval& now);
  void lts_data (const timeval& now);
  void lts_ctrl (const timeval& now);
  void sts_data (ACE_UINT32 now);
  void sts_ctrl (ACE_UINT32 now);

  const timeval& lts_ctrl (void) const;
  const timeval& lts_data (void) const;
  const timeval& lts_done (void) const;
  int sts_ctrl (void) const;
  int sts_data (void) const;

  const char* sdes (int t) const;
  virtual void sdes (int t, const char* value);
  ACE_UINT32 addr (void) const;
  void addr (ACE_UINT32 a);
  ACE_UINT32 srcid (void) const;
  void srcid (ACE_UINT32 s);
  ACE_UINT32 ssrc (void) const;
  void ssrc (ACE_UINT32 s);
  void format (int v);
  int format (void) const;
  void mute (int v);
  int mute (void) const;
  void ismixer (int v);
  int ismixer (void) const;
  void clear_counters (void);

  /*XXX should start at random values*/
  ACE_UINT32 nb (void) const;
  ACE_UINT32 nf (void) const;
  ACE_UINT32 np (void) const;
  ACE_UINT32 nm (void) const;
  ACE_UINT32 ns (void) const; /* no. expected */
  ACE_UINT32 ehs (void) const;
  ACE_UINT32 cs (void) const;
  ACE_UINT32 snp (void) const;
  ACE_UINT32 sns (void) const;
  ACE_UINT32 runt (void) const;
  ACE_UINT32 dups (void) const;
  ACE_UINT32 badsesslen (void) const;
  ACE_UINT32 badsessver (void) const;
  ACE_UINT32 badsessopt (void) const;
  ACE_UINT32 badsdes (void) const;
  ACE_UINT32 badbye (void) const;
  void nb (int v);
  void nf (int v);
  void np (int v);
  void nm (int v);
  void snp (int v);
  void sns (int v);
  void fs (int v);
  void runt (int v);
  void badsesslen (int v);
  void badsessver (int v);
  void badsessopt (int v);
  void badsdes (int v);
  void badbye (int v);
  int cs (ACE_UINT16 v);
  int checkseq (ACE_UINT16 v);
  virtual void lost (int);

  TAO_AV_Source* next_;          /* link for TAO_AV_SourceManager TAO_AV_Source list */
  TAO_AV_Source* hlink_;         /* link for TAO_AV_SourceManager hash table */
protected:
  char* stats (char* cp) const;

  // @@Naga:My additions
  int active_;
  char *name_;
  int delvar_;
  ACE_UINT32 srcid_;       /* rtp global src id  (CSRC), net order */
  ACE_UINT32 ssrc_;        /* rtp global sync src id  (SSRC), net order) */
  ACE_UINT32 addr_;        /* address of sender  (net order) */

  ACE_UINT32 sts_data_;    /* sndr ts from last data packet  (net order) */
  ACE_UINT32 sts_ctrl_;    /* sndr ts from last control packet */
  timeval lts_data_;      /* local unix time for last data packet */
  timeval lts_ctrl_;      /* local unix time for last control packet */
  timeval lts_done_;      /* local unix time for bye packet */

  ACE_UINT32 fs_;          /* first seq. no received */
  ACE_UINT32 cs_;          /* current  (most recent) seq. no received */
  ACE_UINT32 np_;          /* no. packets received  */
  ACE_UINT32 nf_;          /* no. video frames received */
  ACE_UINT32 nb_;          /* no. bytes received */
  ACE_UINT32 nm_;          /* no. misordered packets detected */
  ACE_UINT32 snp_;         /* last advertised no. pkts received */
  ACE_UINT32 sns_;         /* last advertised no. pkts exptected */
  ACE_UINT32 ndup_;        /* no. of duplicate packets  (via RTP seqno) */
  ACE_UINT32 nrunt_;       /* count of packets too small */

  /* following errors are from session  (rtcp) processing */
  ACE_UINT32 badsesslen_;  /* bad header length field */
  ACE_UINT32 badsessver_;  /* bad header version number */
  ACE_UINT32 badsessopt_;  /* unrecognized option */
  ACE_UINT32 badsdes_;     /* sdes cnt > available data */
  ACE_UINT32 badbye_;      /* bye cnt > available data */

  int format_;            /* RTP packet type */
  int mute_;              /* true if Source muted */
  int lost_;              /* true when signal lost */
  int busy_;              /* nonzero. during talk spurt */
  int ismixer_;           /* true if TAO_AV_Source has acted as a 'mixer' */

#define TAO_AV_SOURCE_NSEQ 64
  ACE_UINT16 seqno_[TAO_AV_SOURCE_NSEQ];
  char* sdes_[RTCP_SDES_MAX + 1];
};

int sdes_atoi (const char* s);
char* onestat (char* cp, const char* name, u_long v);
class TAO_Base_StreamEndPoint;
class TAO_AV_RTCP_Callback;

class TAO_AV_SourceManager
{
public:
  TAO_AV_SourceManager (TAO_AV_RTCP_Callback *callback);
  void init (ACE_UINT32 localid, ACE_UINT32 localaddr);
  TAO_AV_Source* lookup (ACE_UINT32 srcid, ACE_UINT32 ssrc, ACE_UINT32 addr);
  TAO_AV_Source* demux (ACE_UINT32 srcid, ACE_UINT32 addr, ACE_UINT16 seq);
  TAO_AV_Source* consult (ACE_UINT32 srcid);
  int nsources (void) const;
  TAO_AV_Source* sources (void) const;

  void CheckActiveSources (double msgint);
  void ListSources (void);

  ACE_UINT32 clock (void) const;
  TAO_AV_Source* localsrc (void) const;
  void localsrc (TAO_AV_Source* src);

  void sortactive (char*) const;
  void remove (TAO_AV_Source*);
  void keep_sites (int keep);
  void site_drop_time (int time);
  TAO_AV_Source* enter (TAO_AV_Source* s);
  static int compare (const void*, const void*);
protected:
  void remove_from_hashtable (TAO_AV_Source* s);

  TAO_AV_Source* lookup_duplicate (ACE_UINT32 srcid, ACE_UINT32 addr);

  int nsources_;
  TAO_AV_Source* sources_;
  ACE_UINT32 clock_;
  int keep_sites_;
  u_int site_drop_time_;
  TAO_AV_Source* localsrc_;
  TAO_AV_Source* hashtab_[TAO_AV_SOURCE_HASH];

  TAO_AV_RTCP_Callback *callback_;
};

#if defined (__ACE_INLINE__)
#include "source.i"
#endif /* __ACE_INLINE__ */

#endif /* TAO_AV_Source_H */