jrtplib  3.7.1
rtpsession.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2007 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale Media"
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTPSESSION_H
38 
39 #define RTPSESSION_H
40 
41 #include "rtpconfig.h"
42 #include "rtplibraryversion.h"
43 #include "rtppacketbuilder.h"
44 #include "rtpsessionsources.h"
45 #include "rtptransmitter.h"
46 #include "rtpcollisionlist.h"
47 #include "rtcpscheduler.h"
48 #include "rtcppacketbuilder.h"
49 #include "rtptimeutilities.h"
51 #include "rtpmemoryobject.h"
52 #include <list>
53 
54 #ifdef RTP_SUPPORT_THREAD
55  #include <jmutex.h>
56 #endif // RTP_SUPPORT_THREAD
57 
58 class RTPTransmitter;
59 class RTPSessionParams;
61 class RTPAddress;
62 class RTPSourceData;
63 class RTPPacket;
64 class RTPPollThread;
66 class RTCPCompoundPacket;
67 class RTCPPacket;
68 class RTCPAPPPacket;
69 
76 class RTPSession : public RTPMemoryObject
77 {
78 public:
80  RTPSession(RTPMemoryManager *mgr = 0);
81  virtual ~RTPSession();
82 
90 
98  int Create(const RTPSessionParams &sessparams,RTPTransmitter *transmitter);
99 
101  void Destroy();
102 
108  void BYEDestroy(const RTPTime &maxwaittime,const void *reason,size_t reasonlength);
109 
111  bool IsActive();
112 
114  uint32_t GetLocalSSRC();
115 
117  int AddDestination(const RTPAddress &addr);
118 
120  int DeleteDestination(const RTPAddress &addr);
121 
123  void ClearDestinations();
124 
126  bool SupportsMulticasting();
127 
129  int JoinMulticastGroup(const RTPAddress &addr);
130 
132  int LeaveMulticastGroup(const RTPAddress &addr);
133 
136 
142  int SendPacket(const void *data,size_t len);
143 
148  int SendPacket(const void *data,size_t len,
149  uint8_t pt,bool mark,uint32_t timestampinc);
150 
157  int SendPacketEx(const void *data,size_t len,
158  uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords);
159 
166  int SendPacketEx(const void *data,size_t len,
167  uint8_t pt,bool mark,uint32_t timestampinc,
168  uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords);
169 #ifdef RTP_SUPPORT_SENDAPP
170 
177  int SendRTCPAPPPacket(uint8_t subtype, const uint8_t name[4], const void *appdata, size_t appdatalen);
178 #endif // RTP_SUPPORT_SENDAPP
179 
181  int SetDefaultPayloadType(uint8_t pt);
182 
184  int SetDefaultMark(bool m);
185 
187  int SetDefaultTimestampIncrement(uint32_t timestampinc);
188 
195  int IncrementTimestamp(uint32_t inc);
196 
205 
212  int SetPreTransmissionDelay(const RTPTime &delay);
213 
222 
225 
229  int Poll();
230 
236  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
237 
241  int AbortWait();
242 
247 
254  int BeginDataAccess();
255 
260  bool GotoFirstSource();
261 
266  bool GotoNextSource();
267 
272  bool GotoPreviousSource();
273 
281 
288  bool GotoNextSourceWithData();
289 
297 
300 
304  RTPSourceData *GetSourceInfo(uint32_t ssrc);
305 
313 
315  void DeletePacket(RTPPacket *p);
316 
318  int EndDataAccess();
319 
325 
327  int AddToIgnoreList(const RTPAddress &addr);
328 
330  int DeleteFromIgnoreList(const RTPAddress &addr);
331 
333  void ClearIgnoreList();
334 
336  int AddToAcceptList(const RTPAddress &addr);
337 
339  int DeleteFromAcceptList(const RTPAddress &addr);
340 
342  void ClearAcceptList();
343 
345  int SetMaximumPacketSize(size_t s);
346 
348  int SetSessionBandwidth(double bw);
349 
356  int SetTimestampUnit(double u);
357 
364  void SetNameInterval(int count);
365 
372  void SetEMailInterval(int count);
373 
380  void SetLocationInterval(int count);
381 
388  void SetPhoneInterval(int count);
389 
396  void SetToolInterval(int count);
397 
404  void SetNoteInterval(int count);
405 
407  int SetLocalName(const void *s,size_t len);
408 
410  int SetLocalEMail(const void *s,size_t len);
411 
413  int SetLocalLocation(const void *s,size_t len);
414 
416  int SetLocalPhone(const void *s,size_t len);
417 
419  int SetLocalTool(const void *s,size_t len);
420 
422  int SetLocalNote(const void *s,size_t len);
423 
424 #ifdef RTPDEBUG
425  void DumpSources();
426  void DumpTransmitter();
427 #endif // RTPDEBUG
428 protected:
436  virtual RTPTransmitter *NewUserDefinedTransmitter() { return 0; }
437 
439  virtual void OnRTPPacket(RTPPacket *pack,const RTPTime &receivetime,
440  const RTPAddress *senderaddress) { }
441 
443  virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack,const RTPTime &receivetime,
444  const RTPAddress *senderaddress) { }
445 
451  virtual void OnSSRCCollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp) { }
452 
454  virtual void OnCNAMECollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,
455  const uint8_t *cname,size_t cnamelength) { }
456 
458  virtual void OnNewSource(RTPSourceData *srcdat) { }
459 
461  virtual void OnRemoveSource(RTPSourceData *srcdat) { }
462 
464  virtual void OnTimeout(RTPSourceData *srcdat) { }
465 
467  virtual void OnBYETimeout(RTPSourceData *srcdat) { }
468 
472  virtual void OnAPPPacket(RTCPAPPPacket *apppacket,const RTPTime &receivetime,
473  const RTPAddress *senderaddress) { }
474 
476  virtual void OnUnknownPacketType(RTCPPacket *rtcppack,const RTPTime &receivetime,
477  const RTPAddress *senderaddress) { }
478 
480  virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack,const RTPTime &receivetime,
481  const RTPAddress *senderaddress) { }
482 
484  virtual void OnNoteTimeout(RTPSourceData *srcdat) { }
485 
487  virtual void OnBYEPacket(RTPSourceData *srcdat) { }
488 
491 #ifdef RTP_SUPPORT_THREAD
492 
493  virtual void OnPollThreadError(int errcode) { }
494 
499  virtual void OnPollThreadStep() { }
500 #endif // RTP_SUPPORT_THREAD
501 private:
502  int InternalCreate(const RTPSessionParams &sessparams);
503  int CreateCNAME(uint8_t *buffer,size_t *bufferlength,bool resolve);
504  int ProcessPolledData();
505  int ProcessRTCPCompoundPacket(RTCPCompoundPacket &rtcpcomppack,RTPRawPacket *pack);
506 
507  RTPTransmitter *rtptrans;
508  bool created;
509  bool deletetransmitter;
510  bool usingpollthread;
511  bool acceptownpackets;
512  bool useSR_BYEifpossible;
513  size_t maxpacksize;
514  double sessionbandwidth;
515  double controlfragment;
516  double sendermultiplier;
517  double byemultiplier;
518  double membermultiplier;
519  double collisionmultiplier;
520  double notemultiplier;
521  bool sentpackets;
522 
523  RTPSessionSources sources;
524  RTPPacketBuilder packetbuilder;
525  RTCPScheduler rtcpsched;
526  RTCPPacketBuilder rtcpbuilder;
527  RTPCollisionList collisionlist;
528 
529  std::list<RTCPCompoundPacket *> byepackets;
530 
531 #ifdef RTP_SUPPORT_THREAD
532  RTPPollThread *pollthread;
533  JMutex sourcesmutex,buildermutex,schedmutex,packsentmutex;
534 
535  friend class RTPPollThread;
536 #endif // RTP_SUPPORT_THREAD
537  friend class RTPSessionSources;
538  friend class RTCPSessionPacketBuilder;
539 };
540 
541 #endif // RTPSESSION_H
542