sources.h
Go to the documentation of this file.
// Copyright (C) 2001,2002,2003,2004 Federico Montesino Pouzols <fedemp@altern.org>.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// This exception applies only to the code released under the name GNU
// ccRTP. If you copy code from other releases into a copy of GNU
// ccRTP, as the General Public License permits, the exception does
// not apply to the code that you add in this way. To avoid misleading
// anyone as to the status of such modified files, you must delete
// this exception notice from them.
//
// If you write modifications of your own for GNU ccRTP, it is your choice
// whether to permit this exception to apply to your modifications.
// If you do not wish that, delete this exception notice.
//
#ifndef CCXX_RTP_SOURCES_H_
#define CCXX_RTP_SOURCES_H_
#include <string>
#include <ccrtp/rtcppkt.h>
#include <cstddef>
NAMESPACE_COMMONCPP
class __EXPORT SDESItemsHolder
{
public:
const std::string&
getItem(SDESItemType type) const;
inline const std::string&
getPRIVPrefix() const
{ return sdesItems[SDESItemTypeEND]; }
void
setItem(SDESItemType item, const std::string& val);
inline void
setPRIVPrefix(const std::string& val)
{ sdesItems[SDESItemTypeEND] = val; }
protected:
SDESItemsHolder()
{ }
inline virtual ~SDESItemsHolder()
{ }
private:
// SDES items for a participant.
// sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix
// value for the PRIV item. The rest of entries hold the
// correponding SDES item value.
std::string sdesItems[SDESItemTypeLast + 1];
};
class __EXPORT Participant : private SDESItemsHolder
{
public:
const std::string&
getSDESItem(SDESItemType type) const
{ return SDESItemsHolder::getItem(type); }
inline const std::string&
getPRIVPrefix() const
{ return SDESItemsHolder::getPRIVPrefix(); }
Participant(const std::string& cname);
~Participant();
private:
friend class ParticipantHandler;
inline void
setSDESItem(SDESItemType item, const std::string& val)
{ SDESItemsHolder::setItem(item,val); }
inline void
setPRIVPrefix(const std::string val)
{ SDESItemsHolder::setPRIVPrefix(val); }
};
class __EXPORT SyncSource
{
public:
typedef enum {
stateUnknown,
statePrevalid,
stateActive,
stateInactive,
stateLeaving
} State;
SyncSource(uint32 ssrc);
~SyncSource();
State
getState() const
{ return state; }
bool isSender() const
{ return activeSender; }
uint32 getID() const
{ return SSRC; }
inline Participant*
getParticipant() const
{ return participant; }
tpport_t getDataTransportPort() const
{ return dataTransportPort; }
tpport_t getControlTransportPort() const
{ return controlTransportPort; }
const InetAddress& getNetworkAddress() const
{ return networkAddress; }
protected:
SyncSource(const SyncSource& source);
SyncSource&
operator=(const SyncSource& source);
private:
friend class SyncSourceHandler;
inline void
setState(State st)
{ state = st; }
inline void
setSender(bool active)
{ activeSender = active; }
inline void
setParticipant(Participant& p)
{ participant = &p; }
void setDataTransportPort(tpport_t p)
{ dataTransportPort = p; }
void setControlTransportPort(tpport_t p)
{ controlTransportPort = p; }
void setNetworkAddress(InetAddress addr)
{ networkAddress = addr; }
inline void
setLink(void *l)
{ link = l; }
void *getLink() const
{ return link; }
// validity state of this source
State state;
// 32-bit SSRC identifier.
uint32 SSRC;
// A valid source not always is active
bool activeSender;
// The corresponding participant.
Participant* participant;
// Network protocol address for data and control connection
// (both are assumed to be the same).
InetAddress networkAddress;
tpport_t dataTransportPort;
tpport_t controlTransportPort;
// Pointer to the SyncSourceLink or similar object in the
// service queue. Saves a lot of searches in the membership
// table.
void* link;
};
class __EXPORT RTPApplication : private SDESItemsHolder
{
private:
struct ParticipantLink;
public:
RTPApplication(const std::string& cname);
~RTPApplication();
inline void
setSDESItem(SDESItemType item, const std::string& val)
{ SDESItemsHolder::setItem(item,val); }
inline void
setPRIVPrefix(const std::string& val)
{ SDESItemsHolder::setPRIVPrefix(val); }
const std::string&
getSDESItem(SDESItemType item) const
{ return SDESItemsHolder::getItem(item); }
inline const std::string&
getPRIVPrefix() const
{ return SDESItemsHolder::getPRIVPrefix(); }
class ParticipantsIterator
{
public:
typedef std::forward_iterator_tag iterator_category;
typedef Participant value_type;
typedef std::ptrdiff_t difference_type;
typedef const Participant* pointer;
typedef const Participant& reference;
ParticipantsIterator(ParticipantLink* p = NULL) :
link(p)
{ }
ParticipantsIterator(const ParticipantsIterator& pi) :
link(pi.link)
{ }
reference operator*() const
{ return *(link->getParticipant()); }
pointer operator->() const
{ return link->getParticipant(); }
ParticipantsIterator& operator++() {
link = link->getNext();
return *this;
}
ParticipantsIterator operator++(int) {
ParticipantsIterator result(*this);
++(*this);
return result;
}
friend bool operator==(const ParticipantsIterator& l,
const ParticipantsIterator& r)
{ return l.link == r.link; }
friend bool operator!=(const ParticipantsIterator& l,
const ParticipantsIterator& r)
{ return l.link != r.link; }
private:
ParticipantLink *link;
};
ParticipantsIterator begin()
{ return ParticipantsIterator(firstPart); }
ParticipantsIterator end()
{ return ParticipantsIterator(NULL); }
const Participant*
getParticipant(const std::string& cname) const;
private:
friend class ApplicationHandler;
struct ParticipantLink {
ParticipantLink(Participant& p,
ParticipantLink* l) :
participant(&p), next(l)
{ }
inline ~ParticipantLink() { delete participant; }
inline Participant* getParticipant() { return participant; }
inline ParticipantLink* getPrev() { return prev; }
inline ParticipantLink* getNext() { return next; }
inline void setPrev(ParticipantLink* l) { prev = l; }
inline void setNext(ParticipantLink* l) { next = l; }
Participant* participant;
ParticipantLink* next, *prev;
};
void
addParticipant(Participant& part);
void
removeParticipant(ParticipantLink* part);
void
findCNAME();
static const size_t defaultParticipantsNum;
Participant** participants;
ParticipantLink* firstPart, * lastPart;
};
__EXPORT RTPApplication& defaultApplication();
// sources
END_NAMESPACE
#endif //CCXX_RTP_SOURCES_H_
Participant
A class of objects representing remote participants (RTP applications) in a multimedia session.
Definition sources.h:127
Participant::getSDESItem
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition sources.h:142
Participant::Participant
Participant(const std::string &cname)
Construct a new participant.
Participant::getPRIVPrefix
const std::string & getPRIVPrefix() const
Get the prefix value for the PRIV SDES item.
Definition sources.h:153
Participant::ParticipantHandler
friend class ParticipantHandler
Definition sources.h:166
Participant::~Participant
~Participant()
RTPApplication::ParticipantsIterator
Iterator through the list of participants in this session.
Definition sources.h:404
RTPApplication::ParticipantsIterator::ParticipantsIterator
ParticipantsIterator(const ParticipantsIterator &pi)
Definition sources.h:416
RTPApplication::ParticipantsIterator::operator->
pointer operator->() const
Definition sources.h:423
RTPApplication::ParticipantsIterator::operator++
ParticipantsIterator operator++(int)
Definition sources.h:431
RTPApplication::ParticipantsIterator::operator*
reference operator*() const
Definition sources.h:420
RTPApplication::ParticipantsIterator::ParticipantsIterator
ParticipantsIterator(ParticipantLink *p=NULL)
Definition sources.h:412
RTPApplication::ParticipantsIterator::reference
const Participant & reference
Definition sources.h:410
RTPApplication::ParticipantsIterator::pointer
const Participant * pointer
Definition sources.h:409
RTPApplication::ParticipantsIterator::value_type
Participant value_type
Definition sources.h:407
RTPApplication::ParticipantsIterator::operator!=
friend bool operator!=(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition sources.h:440
RTPApplication::ParticipantsIterator::difference_type
std::ptrdiff_t difference_type
Definition sources.h:408
RTPApplication::ParticipantsIterator::operator==
friend bool operator==(const ParticipantsIterator &l, const ParticipantsIterator &r)
Definition sources.h:436
RTPApplication::ParticipantsIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition sources.h:406
RTPApplication::ParticipantsIterator::operator++
ParticipantsIterator & operator++()
Definition sources.h:426
RTPApplication
An RTP application, holding identifying RTCP SDES item values.
Definition sources.h:367
RTPApplication::~RTPApplication
~RTPApplication()
RTPApplication::getSDESItem
const std::string & getSDESItem(SDESItemType item) const
Definition sources.h:392
RTPApplication::setPRIVPrefix
void setPRIVPrefix(const std::string &val)
Definition sources.h:388
RTPApplication::getParticipant
const Participant * getParticipant(const std::string &cname) const
RTPApplication::getPRIVPrefix
const std::string & getPRIVPrefix() const
Definition sources.h:396
RTPApplication::end
ParticipantsIterator end()
Definition sources.h:450
RTPApplication::ApplicationHandler
friend class ApplicationHandler
Definition sources.h:457
RTPApplication::begin
ParticipantsIterator begin()
Definition sources.h:447
RTPApplication::setSDESItem
void setSDESItem(SDESItemType item, const std::string &val)
Definition sources.h:384
RTPApplication::RTPApplication
RTPApplication(const std::string &cname)
Create a new RTP application.
SDESItemsHolder::getItem
const std::string & getItem(SDESItemType type) const
SDESItemsHolder::~SDESItemsHolder
virtual ~SDESItemsHolder()
Definition sources.h:87
SDESItemsHolder::setItem
void setItem(SDESItemType item, const std::string &val)
SDESItemsHolder::setPRIVPrefix
void setPRIVPrefix(const std::string &val)
Definition sources.h:80
SDESItemsHolder::SDESItemsHolder
SDESItemsHolder()
Definition sources.h:84
SDESItemsHolder::getPRIVPrefix
const std::string & getPRIVPrefix() const
Definition sources.h:73
SyncSource::getDataTransportPort
tpport_t getDataTransportPort() const
Definition sources.h:273
SyncSource::getControlTransportPort
tpport_t getControlTransportPort() const
Definition sources.h:276
SyncSource::getParticipant
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition sources.h:270
SyncSource::getState
State getState() const
Definition sources.h:250
SyncSource::SyncSource
SyncSource(const SyncSource &source)
SyncSource::getID
uint32 getID() const
Definition sources.h:259
SyncSource::isSender
bool isSender() const
Whether this source sends RTP data packets.
Definition sources.h:256
SyncSource::~SyncSource
~SyncSource()
SyncSource::getNetworkAddress
const InetAddress & getNetworkAddress() const
Definition sources.h:279
SyncSource::operator=
SyncSource & operator=(const SyncSource &source)
SyncSource::State
State
Synchronization source states during an RTP session.
Definition sources.h:227
SyncSource::statePrevalid
@ statePrevalid
Some packets have been.
Definition sources.h:229
SyncSource::stateInactive
@ stateInactive
(data or control) from this source.
Definition sources.h:234
SyncSource::stateActive
@ stateActive
received, but source validity not yet guaranteed.
Definition sources.h:232
SyncSource::stateUnknown
@ stateUnknown
No valid packet has been received.
Definition sources.h:228
SyncSource::stateLeaving
@ stateLeaving
no packet from this source has been received lately.
Definition sources.h:237
SyncSource::SyncSource
SyncSource(uint32 ssrc)
SyncSource::SyncSourceHandler
friend class SyncSourceHandler
Definition sources.h:292
SDESItemType
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
Definition rtcppkt.h:66
SDESItemTypeEND
@ SDESItemTypeEND
END of SDES item list.
Definition rtcppkt.h:67
SDESItemTypeLast
@ SDESItemTypeLast
Last defined code.
Definition rtcppkt.h:77
defaultApplication
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
rtcppkt.h
RTCP packets handling.