Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNRTCP.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MNRTCP_H 00025 #define MNRTCP_H 00026 00027 #include "MNRTPbase.h" 00028 #include "MNRTPList.h" 00029 #include "MNTimer.h" 00030 #include "MNTimerCall.h" 00031 #include "MNMutex.h" 00032 #include "GCPtr.h" 00033 #include "MNSocketQueue.h" 00034 #include "sdp/PayloadTypes.h" 00035 #include "sdp/TransportTypes.h" 00036 00037 class MNRTPPacket; 00038 class MNRTCPPacket; 00039 class MNRTCPPacket_APP; 00040 00041 /*********************************************************************** 00042 * Class: MNRTCPTimer 00043 * Desc: This class encapsulates extracts timer handling from MNRTCP to 00044 * change from one timer thread per RTCP object to one timer for 00045 * all RTCP objects. 00046 * 00047 * Right now, this implementation is extremely simple and maps 00048 * all calls directly to an included timer object. It requires 00049 * the same number of threads as before as well. 00050 * When a central RTCP timer is introduced, the sequence number 00051 * will have to be requested from the central timer, and calls 00052 * will be redirected to that object, but otherwise, the structure 00053 * should remain simple. 00054 ***********************************************************************/ 00055 00056 class MNRTCPTimer 00057 { 00058 /* Timer */ 00059 MNTimer _rtcp_packet_timer; 00060 TimerCallBase* _ptr; 00061 00062 public: 00063 MNRTCPTimer( MNSelector& selector ); 00064 ~MNRTCPTimer( ); 00065 00066 void insert( TimerCallBase* target, 00067 const struct timeval& timeout, 00068 bool inCallback ); 00069 void reschedule( TimerCallBase* target, 00070 const struct timeval& timeout, 00071 bool inCallback ); 00072 void cancel( ); 00073 }; 00074 00075 /*********************************************************************** 00076 * Class: MNRTCPSSrc 00077 * Desc: The list of synchronization sources can perhaps be extracted 00078 * from the core RTCP class. 00079 ***********************************************************************/ 00080 00081 class MNRTCPSSrc 00082 { 00083 /* stats */ 00084 MNRTPList _list; 00085 MNMutex _mutex; 00086 00087 public: 00088 MNRTCPSSrc( u_int32 initial_ssrc ) 00089 { 00090 _list.set_my_ssrc( initial_ssrc ); 00091 } 00092 00093 void set_my_ssrc( u_int32 ssrc, bool lck = false ) 00094 { 00095 if ( lck ) _mutex.lock(); 00096 _list.set_my_ssrc(ssrc); 00097 if ( lck ) _mutex.unlock(); 00098 } 00099 00100 /* 00101 * returns the number of SSRCs in the list 00102 */ 00103 int count( ) 00104 { 00105 return _list.get_sr_count(); 00106 } 00107 00108 /* 00109 * returns the number of SSRCs in the list that 00110 * are labelled RTP_SR_ACTIVE 00111 */ 00112 int active_count( ) 00113 { 00114 return _list.get_active_number(); 00115 } 00116 00117 void lock( ) 00118 { 00119 _mutex.lock(); 00120 } 00121 00122 void unlock( ) 00123 { 00124 _mutex.unlock(); 00125 } 00126 00127 SSRCEntry* entryptr_for_ssrc( u_int32 ssrc ) 00128 { 00129 return _list.get_ssrc_info_ptr( ssrc ); 00130 } 00131 00132 SSRCEntry entry_for_ssrc( u_int32 ssrc ) 00133 { 00134 return _list.get_ssrc_info( ssrc ); 00135 } 00136 00137 u_int32 get_first_ssrc( bool lck ) 00138 { 00139 if ( lck ) { 00140 u_int32 ret; 00141 _mutex.lock(); 00142 ret = _list.get_first_ssrc(); 00143 _mutex.unlock(); 00144 return ret; 00145 } else { 00146 return _list.get_first_ssrc(); 00147 } 00148 } 00149 00150 u_int32 get_first_ssrc() 00151 { 00152 return _list.get_first_ssrc(); 00153 } 00154 00155 u_int32 get_next_ssrc( u_int32 ssrc, bool lck ) 00156 { 00157 if ( lck ) { 00158 u_int32 ret; 00159 _mutex.lock(); 00160 ret = _list.get_next_ssrc( ssrc ); 00161 _mutex.unlock(); 00162 return ret; 00163 } else { 00164 return _list.get_next_ssrc( ssrc ); 00165 } 00166 } 00167 00168 u_int32 get_next_ssrc(u_int32 ssrc) 00169 { 00170 return _list.get_next_ssrc( ssrc ); 00171 } 00172 00173 void make_inactive( ) 00174 { 00175 _list.make_inactive(); 00176 } 00177 00178 void increment_heared_and_check_old( bool lck = false ) 00179 { 00180 if ( lck ) _mutex.lock(); 00181 _list.increment_heared_and_check_old(); 00182 if ( lck ) _mutex.unlock(); 00183 } 00184 00185 bool find_ssrc( u_int32 ssrc, bool lck = false ) 00186 { 00187 if ( lck ) { 00188 bool ret; 00189 _mutex.lock(); 00190 ret = _list.find_ssrc( ssrc ); 00191 _mutex.unlock(); 00192 return ret; 00193 } else { 00194 return _list.find_ssrc( ssrc ); 00195 } 00196 } 00197 00198 struct sockaddr_in get_addr( u_int32 ssrc, bool lck = false ) 00199 { 00200 if ( lck ) { 00201 struct sockaddr_in ret; 00202 _mutex.lock(); 00203 ret = _list.get_addr( ssrc ); 00204 _mutex.unlock(); 00205 return ret; 00206 } else { 00207 return _list.get_addr( ssrc ); 00208 } 00209 } 00210 00211 void update_sr( rtcp_t* sr, 00212 const struct sockaddr_in& dest_, 00213 bool lck = false ) 00214 { 00215 if ( lck ) _mutex.lock(); 00216 _list.update_sr( sr, dest_ ); 00217 if ( lck ) _mutex.unlock(); 00218 } 00219 00220 void update_rr( rtcp_t* rr, 00221 const struct sockaddr_in& dest_, 00222 int& count, 00223 bool lck = false ) 00224 { 00225 if ( lck ) _mutex.lock(); 00226 _list.update_rr( rr, dest_, count ); 00227 if ( lck ) _mutex.unlock(); 00228 } 00229 00230 void update_sdes( rtcp_t *sdes, bool lck = false ) 00231 { 00232 if ( lck ) _mutex.lock(); 00233 _list.update_sdes( sdes ); 00234 if ( lck ) _mutex.unlock(); 00235 } 00236 00237 void update_bye( rtcp_t *bye, bool lck = false ) 00238 { 00239 if ( lck ) _mutex.lock(); 00240 _list.update_bye( bye ); 00241 if ( lck ) _mutex.unlock(); 00242 } 00243 00244 void update_ssrc( rtp_hdr_t* rtp, 00245 ntp64 arr_time, 00246 struct sockaddr_in dest_, 00247 bool lck = false ) 00248 { 00249 if ( lck ) _mutex.lock(); 00250 _list.update_ssrc( rtp, arr_time, dest_ ); 00251 if ( lck ) _mutex.unlock(); 00252 } 00253 00254 void update_ssrc( MNRTPPacketPtr packet, 00255 ntp64 arr_time, 00256 struct sockaddr_in dest_, 00257 bool lck = false ) 00258 { 00259 if ( lck ) _mutex.lock(); 00260 _list.update_ssrc( packet, arr_time, dest_ ); 00261 if ( lck ) _mutex.unlock(); 00262 } 00263 }; 00264 00265 /************************************************************** 00266 * Class: MNRTCP 00267 * Desc: Implementation of RTCP, inherits MNRTPbase for basic 00268 * RTP socket handling and connection to an MNRTP class. 00269 * Inherits MNTimerCall for RTCP timer callbacks. 00270 **************************************************************/ 00271 00272 class MNRTCP: public MNRTPbase 00273 { 00274 private: 00275 /* vars */ 00276 char *rtcp_send_buffer; 00277 size_t rtcp_send_buffer_size; 00278 MNMutex rtcp_send_buffer_mutex; 00279 TimerCall<MNRTCP> _timer_call; 00280 00281 char rtcp_app_name[5]; /* with terminating 0 */ 00282 00288 SDESSchedule _sdes_schedule; 00289 00290 ProtectedInt32 rtcp_last_packet_size; 00291 ProtectedVar<double> rtcp_average_packet_size; 00292 00293 MNMutex rtcp_initialized; 00294 00295 /* stats */ 00296 // MNRTPList ssrc_list; 00297 // MNMutex ssrc_list_mutex; 00298 MNRTCPSSrc _ssrc_list; 00299 00300 /* flags */ 00301 ProtectedBool rtcp_sender_report; /* if true send a sr, else rr */ 00302 00303 MNRTCPTimer _timer; 00304 00305 /* Contains a queue of iovec pointers referring to not sent RTP/TCP data */ 00306 MNSocketQueue* _data_queue; 00307 00308 /* functions */ 00309 00331 int rtcp_send_packet(const char* app, int len, int subtype, bool bye); 00332 00335 struct timeval Timer_sched_cb(); 00336 00337 void rtcp_lock(); 00338 void rtcp_unlock(); 00339 00340 /* call backs */ 00341 00348 virtual void timer_callback( void* ref_data, TimerCallBase* ptr ); 00349 00351 RTSP::TransportTypes _requested_transport; 00352 00353 protected: 00354 friend class MNRTP; 00355 00369 MNRTCP( MNSelector& sel, 00370 u_int32 ssrc, 00371 int port, 00372 int remote_port, 00373 OS::GCPtr<MNShared_RTP_RTCP> shared_data, 00374 RTSP::TransportTypes requested_transport = RTSP::RTP_AVP_UDP ); 00375 00390 MNRTCP( MNSelector& sel, 00391 u_int32 ssrc, 00392 MNSocket& port, 00393 int remote_port, 00394 OS::GCPtr<MNShared_RTP_RTCP> shared_data, 00395 RTSP::TransportTypes requested_transport = RTSP::RTP_AVP_UDP ); 00396 00397 public: 00400 virtual ~MNRTCP(); 00401 00402 /* Standard functions */ 00403 00408 RTP_RC rtcp_start( ); 00409 00415 virtual void rt_set_ssrc(u_int32 ssrc); /* changes the own ssrc */ 00416 00427 virtual RTP_RC process_data( MNRope* rope, struct sockaddr_in *dest); 00428 00432 virtual void notify_write_enabled( ); 00433 00446 int rtcp_send_app( char* app, int len, int subtype ); 00447 00453 int rtcp_send_app( MNRTCPPacket_APP* packet ); 00454 00459 void set_send_buffer( size_t size ); 00460 00467 void rtcp_set_app_name( const char* name ); 00468 00485 void set_send_sdes(rtcp_sdes_type_t type, char* text, int prio); 00486 00496 const sdes_list_item* rtcp_get_sdes_text(rtcp_sdes_type_t type); 00497 00501 virtual MNRTCP* rt_get_rtcp_ptr(); 00502 00509 bool rtcp_find(u_int32 ssrc); 00510 00518 struct sockaddr_in rtcp_get_ssrc_addr(u_int32 ssrc); 00519 00524 void rtcp_reset(u_int32 ssrc); 00525 00528 SSRCEntry* rtcp_get_info_ptr(u_int32 ssrc); 00529 00532 SSRCEntry rtcp_get_info(u_int32 ssrc); 00533 00534 u_int32 rtcp_get_first_ssrc(); 00535 u_int32 rtcp_get_next_ssrc( u_int32 ssrc ); 00536 void rtcp_update_recv( rtp_hdr_t* rtp, 00537 ntp64 time_, 00538 struct sockaddr_in dest ); 00539 void rtcp_update_recv( MNRTPPacketPtr packet, 00540 ntp64 time_, 00541 struct sockaddr_in dest ); 00544 void rtcp_update_send( u_int32 packet_count, 00545 u_int32 octet_count, 00546 u_int32 ts ); 00547 }; 00548 00549 #endif 00550

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8