00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#ifndef MNRTPBASE_H
00025
#define MNRTPBASE_H
00026
00027
#include <assert.h>
00028
#include "MNList.h"
00029
#include "RefCountingSocket.h"
00030
#include "GCPtr.h"
00031
#include "MNMutex.h"
00032
#include "MNTimer.h"
00033
#include "MNRTPrandom.h"
00034
#include "MNRTPdefs.h"
00035
#include "MNRTPtime.h"
00036
#include "MNRTPcallback.h"
00037
#include "MNShared_RTP_RTCP.h"
00038
#include "MNValid.h"
00039
00040
class MNRTP;
00041
class MNRTCP;
00042
class MNRTPbase;
00043
class MNRope;
00044
00045
00046
00047
00048
00049
00050
00051 class MNRTPbase :
public RefCountingSocket
00052 {
00059
class AlloverStats
00060 {
00061
00062
ProtectedU_int64 bytessent;
00063
struct timeval firsttimesent;
00064
MNMutex send_mutex;
00065
00066
00067
ProtectedU_int64 bytesreceived;
00068
struct timeval firsttimerecv;
00069
struct timeval lasttimerecv;
00070
struct timeval mindelta;
00071
struct timeval maxdelta;
00072
struct timeval averdelta;
00073
MNMutex recv_mutex;
00074
00075
public:
00076 AlloverStats();
00077
00078
void add_bytes_sent(
int len );
00079
void add_bytes_received(
int len );
00080
00081
void collect_recvtime();
00082
00083
u_int64 get_bytes_sent( );
00084
u_int64 get_bytes_recv( );
00085
00086
void get_send_time(
struct timeval& outvar );
00087
void get_recv_time(
struct timeval& outvar );
00088
00089
u_int64 get_send_bandwidth( );
00090
u_int64 get_recv_bandwidth( );
00091
00092
void get_recv_max_delta(
struct timeval& outvar );
00093
void get_recv_min_delta(
struct timeval& outvar );
00094
void get_recv_aver_delta(
struct timeval& outvar );
00095 };
00096
00099
class RTPSendStats
00100 {
00104
ProtectedU_int32 rtp_packet_count;
00105
00108
ProtectedU_int32 rtp_octet_count;
00109
00112
ntp64 first_time_sent;
00113
00116
MNMutex send_stat_mutex;
00117
00120
ProtectedU_int32 rtp_init_ts;
00121
00127
ProtectedU_int32 rtp_last_ts;
00128
00129
public:
00130
00131
00132
00133 RTPSendStats()
00134 {
00135 rtp_packet_count = 0;
00136 rtp_octet_count = 0;
00137 rtp_init_ts = 0;
00138 rtp_last_ts = 0;
00139 }
00140
00141
void rtp_reset()
00142 {
00143 send_stat_mutex.lock();
00144 first_time_sent.upper = 0;
00145 first_time_sent.lower = 0;
00146 rtp_packet_count = 0;
00147 rtp_octet_count = 0;
00148 rtp_init_ts =
random32();
00149 rtp_last_ts = rtp_init_ts;
00150 send_stat_mutex.unlock();
00151 }
00152
00153
void rtcp_reset()
00154 {
00155 send_stat_mutex.lock();
00156 first_time_sent.upper = 0;
00157 first_time_sent.lower = 0;
00158 rtp_packet_count = 0;
00159 rtp_octet_count = 0;
00160 rtp_init_ts = 0;
00161 rtp_last_ts = 0;
00162 send_stat_mutex.unlock();
00163 }
00164
00165
void rtcp_update(
u_int32 packets,
u_int32 octets,
u_int32 ts )
00166 {
00167 send_stat_mutex.lock();
00168
if (first_time_sent.upper == 0)
00169 {
00170 first_time_sent =
getntptime();
00171 }
00172 send_stat_mutex.unlock();
00173 rtp_packet_count = packets;
00174 rtp_octet_count = octets;
00175
if ( (
int)rtp_init_ts == 0 )
00176 {
00177 rtp_init_ts = ts;
00178 }
00179 }
00180
00181
u_int32 get_rtp_packet_count()
00182 {
00183
return rtp_packet_count;
00184 }
00185
00186
u_int32 get_rtp_octet_count()
00187 {
00188
return rtp_octet_count;
00189 }
00190
00191
ntp64 get_first_time_sent()
00192 {
00193 send_stat_mutex.lock();
00194
ntp64 ret = first_time_sent;
00195 send_stat_mutex.unlock();
00196
return ret;
00197 }
00198
00199
u_int32 get_rtp_init_ts()
00200 {
00201
return rtp_init_ts;
00202 }
00203
00204
u_int32 get_rtp_last_ts()
00205 {
00206
return rtp_last_ts;
00207 }
00208
00209
void inc_last_ts(
u_int32 increment,
rtp_math inc_how )
00210 {
00211 assert( (inc_how ==
RTP_ABSOLUTE_INC) ||
00212 (inc_how ==
RTP_INC) );
00213
if ( inc_how ==
RTP_ABSOLUTE_INC )
00214 {
00215 rtp_last_ts = increment;
00216
00217
00218 }
00219
else
00220 {
00221 rtp_last_ts += increment;
00222 }
00223 }
00224
00225
void count_packet(
int bytes )
00226 {
00227 rtp_packet_count += 1;
00228 rtp_octet_count += bytes;
00229 }
00230 };
00231
00234
class RTPRecvStats
00235 {
00236
public:
00238
ProtectedU_int64 bytes_received;
00239
00241
ProtectedU_int64 packets_received;
00242
00243 RTPRecvStats()
00244 {
00245 bytes_received = 0;
00246 packets_received = 0;
00247 }
00248
00249
void count_packet(
int bytes )
00250 {
00251 bytes_received += bytes;
00252 packets_received += 1;
00253 }
00254 };
00255
00256
protected:
00266 OS::GCPtr<MNShared_RTP_RTCP> _shared;
00267
00272 MNRTPcallback _cb;
00273
00276 AlloverStats
allover;
00277
00280 RTPSendStats
sstats;
00281
00284 RTPRecvStats
rstats;
00285
00286
00287 ProtectedU_int32 rt_ssrc;
00288 MNDebugMutex var_mutex;
00289 MNDebugMutex initialized;
00290
00294 bool _running;
00295
00300 bool _connected;
00301
00305 ProtectedBool _shutting_down;
00306
00310 ProtectedBool _force_no_header_check;
00311
00319 RTP_RC _use_mc;
00320
00324 u_int32 _recv_port;
00325
00328 u_int32 _remote_port;
00329
00330
00331
void lock();
00332
void unlock();
00333
00334
00335
00336
public:
00364
MNRTPbase(
MNSelector& sel,
00365
int port,
00366
int remote_port,
00367
int recv_buf_size,
00368
u_int32 ssrc,
00369
OS::GCPtr<MNShared_RTP_RTCP> shared_data );
00370
MNRTPbase(
MNSelector& sel,
00371
MNSocket& sock,
00372
int remote_port,
00373
int recv_buf_size,
00374
u_int32 ssrc,
00375
OS::GCPtr<MNShared_RTP_RTCP> shared_data );
00376
virtual ~MNRTPbase();
00377
00378
00379
00389
RTP_RC rt_start(
bool sender =
false );
00390
00392
RTP_RC rt_connect();
00393
00395
RTP_RC rt_bind();
00396
00398
const char*
rtp_str_err(
int err);
00399
00401
virtual int reader (
MNRope*& rope,
struct sockaddr_in*& dest );
00402
00404
virtual void writer ( );
00405
00410
virtual RTP_RC process_data(
MNRope* rope,
struct sockaddr_in *dest) = 0;
00411
virtual void notify_write_enabled( ) = 0;
00412
00413
#if 0
00414
virtual void set_mc_ttl(
int val);
00415
int get_mc_ttl();
00416
#endif
00417
00419
const char*
rt_get_targetaddr() const;
00420
00422
u_int32 rt_get_octet_count();
00423
00427
u_int64 rt_get_packets_received();
00428
00432
u_int64 rt_get_bytes_received();
00433
00435
MNRTPbase* rt_get_MNRTPbasep();
00436
00437 virtual
MNRTCP* rt_get_rtcp_ptr() {
return NULL;}
00438
00440
int get_remote_port();
00441
00442
00443
00447
int rt_get_payload_type();
00448
00458
void rt_change_pt(
int payload_t);
00459
00461 virtual void rt_set_ssrc(
u_int32 ) {}
00462
00464
u_int32 rt_get_ssrc();
00465
00467
void disable_headercheck();
00469
void enable_headercheck();
00471
bool is_header_check_active();
00472
00474 virtual void enable_rtcp() {};
00476 virtual void disable_rtcp() {};
00477
00478
private:
00480
virtual void do_react_on_bye();
00481
00483
virtual void do_not_react_on_bye();
00484
00487
virtual bool is_react_on_bye_on( ) const;
00488
00489 public:
00490
00491 virtual
u_int64 GetBytesSent();
00492 virtual
u_int64 GetBytesRecv();
00493 struct timeval GetSentTime();
00494 struct timeval GetRecvTime();
00495
u_int64 GetSendBandwidth();
00496
u_int64 GetRecvBandwidth();
00497 struct timeval GetRecvMaxDelta();
00498 struct timeval GetRecvMinDelta();
00499 struct timeval GetRecvAverDelta();
00500
00501 protected:
00507
bool is_multicast() const;
00508
00515
bool is_rtcp_allowed() const;
00516
00517 public:
00523
bool is_running() const;
00524
00528 MNRTPcallback& cb() {
return _cb; }
00529
00530
private:
00543
static RTP_RC is_mc(
const char* hname);
00544 };
00545
00546
#endif
00547