mediatype.h
Go to the documentation of this file.
/*
* mediatype.h
*
* Media Format Type descriptions
*
* Open Phone Abstraction Library (OPAL)
*
* Copyright (C) 2007 Post Increment and Hannes Friederich
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is OPAL
*
* The Initial Developer of the Original Code is Hannes Friederich and Post Increment
*
* Contributor(s): ______________________________________.
*
* $Revision: 26521 $
* $Author: rjongbloed $
* $Date: 2011-10-04 23:57:06 -0500 (Tue, 04 Oct 2011) $
*/
#ifndef OPAL_OPAL_MEDIATYPE_H
#define OPAL_OPAL_MEDIATYPE_H
#include <ptbuildopts.h>
#include <ptlib/pfactory.h>
#include <opal/buildopts.h>
#ifdef P_USE_PRAGMA
#pragma interface
#endif
class OpalMediaTypeDefinition;
class OpalSecurityMode;
class OpalConnection;
//
// define the factory used for keeping track of OpalMediaTypeDefintions
//
typedef PFactory<OpalMediaTypeDefinition> OpalMediaTypeFactory;
typedef OpalMediaTypeFactory::KeyList_T OpalMediaTypeList;
class OpalMediaType : public std::string // do not make this PCaselessString as that type does not work as index for std::map etc
{
public:
OpalMediaType()
{ }
virtual ~OpalMediaType()
{ }
OpalMediaType(const std::string & str)
: std::string(str) { }
OpalMediaType(const char * str)
: std::string(str) { }
OpalMediaType(const PString & str)
: std::string((const char *)str) { }
static const OpalMediaType & Audio();
static const OpalMediaType & Video();
static const OpalMediaType & Fax();
static const OpalMediaType & UserInput();
OpalMediaTypeDefinition * GetDefinition() const;
static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
static OpalMediaTypeDefinition * GetDefinition(unsigned sessionId);
static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
#if OPAL_SIP
static OpalMediaType GetMediaTypeFromSDP(const std::string & key, const std::string & transport);
#endif // OPAL_SIP
enum AutoStartMode {
// Do not change order of enum as useful for bitmasking rx/tx
OfferInactive,
Receive,
Transmit,
ReceiveTransmit,
DontOffer,
TransmitReceive = ReceiveTransmit
};
__inline friend AutoStartMode operator++(AutoStartMode & mode) { return (mode = (AutoStartMode)(mode+1)); }
__inline friend AutoStartMode operator--(AutoStartMode & mode) { return (mode = (AutoStartMode)(mode-1)); }
__inline friend AutoStartMode operator|=(AutoStartMode & m1, AutoStartMode m2) { return (m1 = (AutoStartMode)((m1 & ~DontOffer) | m2)); }
__inline friend AutoStartMode operator-=(AutoStartMode & m1, AutoStartMode m2) { return (m1 = (AutoStartMode)((int)m1 & ~((int)m2|DontOffer))); }
AutoStartMode GetAutoStart() const;
};
__inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
{
return strm << mediaType.c_str();
}
//
// this class defines the functions needed to work with the media type, i.e.
//
class OpalRTPConnection;
class RTP_UDP;
#if OPAL_SIP
class SDPMediaDescription;
class OpalTransportAddress;
#endif
class OpalMediaSession;
class OpalMediaTypeDefinition
{
public:
OpalMediaTypeDefinition(
const char * mediaType,
const char * sdpType,
unsigned requiredSessionId = 0,
OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
);
// Needed to avoid gcc warning about classes with virtual functions and
// without a virtual destructor
virtual ~OpalMediaTypeDefinition();
OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
void SetAutoStart(OpalMediaType::AutoStartMode v, bool on) { if (on) m_autoStart |= v; else m_autoStart -= v; }
virtual bool UsesRTP() const { return true; }
virtual OpalMediaSession * CreateMediaSession(
OpalConnection & connection,
unsigned sessionID
) const;
virtual PString GetRTPEncoding() const = 0;
virtual RTP_UDP * CreateRTPSession(
OpalRTPConnection & conn,
unsigned sessionID,
bool remoteIsNAT
);
unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
protected:
std::string m_mediaType;
unsigned m_defaultSessionId;
OpalMediaType::AutoStartMode m_autoStart;
#if OPAL_SIP
public:
//
// return the SDP type for this media type
//
virtual std::string GetSDPType() const
{ return m_sdpType; }
//
// create an SDP media description entry for this media type
//
virtual SDPMediaDescription * CreateSDPMediaDescription(
const OpalTransportAddress & localAddress
) = 0;
protected:
std::string m_sdpType;
#endif
};
//
// define a macro for declaring a new OpalMediaTypeDefinition factory
//
#define OPAL_INSTANTIATE_MEDIATYPE2(title, name, cls) \
namespace OpalMediaTypeSpace { \
static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##title##_##cls(name, true); \
}; \
#define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
OPAL_INSTANTIATE_MEDIATYPE2(type, #type, cls) \
#ifdef SOLARIS
template <char * Type, char * sdp>
#else
template <char * Type, const char * sdp>
#endif
class SimpleMediaType : public OpalMediaTypeDefinition
{
public:
SimpleMediaType()
: OpalMediaTypeDefinition(Type, sdp, 0)
{ }
virtual ~SimpleMediaType() { }
virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,unsigned , bool ) { return NULL; }
PString GetRTPEncoding() const { return PString::Empty(); }
#if OPAL_SIP
public:
virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
#endif
};
#define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
namespace OpalMediaTypeSpace { \
char type##_type_string[] = #type; \
char type##_sdp_string[] = #sdp; \
typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
}; \
OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
#define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "")
//
// common ancestor for audio and video OpalMediaTypeDefinitions
//
class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
public:
OpalRTPAVPMediaType(
const char * mediaType,
const char * sdpType,
unsigned requiredSessionId = 0,
OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
);
virtual PString GetRTPEncoding() const;
OpalMediaSession * CreateMediaSession(OpalConnection & /*conn*/, unsigned /* sessionID*/) const;
};
class OpalAudioMediaType : public OpalRTPAVPMediaType {
public:
OpalAudioMediaType();
#if OPAL_SIP
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
#endif
};
#if OPAL_VIDEO
class OpalVideoMediaType : public OpalRTPAVPMediaType {
public:
OpalVideoMediaType();
#if OPAL_SIP
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
#endif
};
#endif // OPAL_VIDEO
#if OPAL_T38_CAPABILITY
class OpalFaxMediaType : public OpalMediaTypeDefinition
{
public:
OpalFaxMediaType();
PString GetRTPEncoding(void) const;
RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
unsigned sessionID, bool remoteIsNAT);
OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned /* sessionID*/) const;
#if OPAL_SIP
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
#endif
};
PFACTORY_LOAD(T38PseudoRTP_Handler);
#endif // OPAL_T38_CAPABILITY
__inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
#endif // OPAL_OPAL_MEDIATYPE_H
OpalMediaTypeDefinition::GetRTPEncoding
virtual PString GetRTPEncoding() const =0
OpalMediaType::OpalMediaType
OpalMediaType(const std::string &str)
Definition: mediatype.h:66
OpalMediaTypeDefinition::GetSDPType
virtual std::string GetSDPType() const
Definition: mediatype.h:201
OpalMediaType::TransmitReceive
Definition: mediatype.h:98
OpalMediaTypeDefinition::GetDefaultSessionId
unsigned GetDefaultSessionId() const
Definition: mediatype.h:189
OpalSecurityMode
Definition: rtpconn.h:525
OpalRTPConnection
Definition: rtpconn.h:247
OpalAudioMediaType::CreateSDPMediaDescription
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &localAddress)
OpalAudioMediaType::OpalAudioMediaType
OpalAudioMediaType()
OpalMediaType::OfferInactive
Definition: mediatype.h:92
OpalMediaType::OpalMediaType
OpalMediaType()
Definition: mediatype.h:60
OpalMediaTypeDefinition::CreateSDPMediaDescription
virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &localAddress)=0
OpalMediaType::operator-=
__inline friend AutoStartMode operator-=(AutoStartMode &m1, AutoStartMode m2)
Definition: mediatype.h:104
OpalMediaTypeDefinition::CreateRTPSession
virtual RTP_UDP * CreateRTPSession(OpalRTPConnection &conn, unsigned sessionID, bool remoteIsNAT)
buildopts.h
OpalMediaTypeDefinition::CreateMediaSession
virtual OpalMediaSession * CreateMediaSession(OpalConnection &connection, unsigned sessionID) const
OpalMediaSession
Definition: rtpconn.h:72
OpalMediaType::OpalMediaType
OpalMediaType(const char *str)
Definition: mediatype.h:69
OpalMediaTypeDefinition::m_sdpType
std::string m_sdpType
Definition: mediatype.h:212
SimpleMediaType::SimpleMediaType
SimpleMediaType()
Definition: mediatype.h:239
OpalMediaType::GetMediaTypeFromSDP
static OpalMediaType GetMediaTypeFromSDP(const std::string &key, const std::string &transport)
OpalMediaTypeDefinition::m_mediaType
std::string m_mediaType
Definition: mediatype.h:192
OpalMediaType::operator|=
__inline friend AutoStartMode operator|=(AutoStartMode &m1, AutoStartMode m2)
Definition: mediatype.h:103
OpalMediaType::Video
static const OpalMediaType & Video()
OpalMediaType
Definition: mediatype.h:57
OpalMediaTypeDefinition::SetAutoStart
void SetAutoStart(OpalMediaType::AutoStartMode v)
Definition: mediatype.h:153
std
STL namespace.
SimpleMediaType::CreateRTPSession
virtual RTP_UDP * CreateRTPSession(OpalRTPConnection &, unsigned, bool)
Definition: mediatype.h:245
OpalMediaType::operator--
__inline friend AutoStartMode operator--(AutoStartMode &mode)
Definition: mediatype.h:102
OpalMediaType::UserInput
static const OpalMediaType & UserInput()
PFACTORY_LOAD
PFACTORY_LOAD(OpalPluginCodecManager)
OpalMediaType::GetAutoStart
AutoStartMode GetAutoStart() const
Definition: mediatype.h:333
OpalMediaTypeList
OpalMediaTypeFactory::KeyList_T OpalMediaTypeList
Definition: mediatype.h:52
OpalMediaType::GetList
static OpalMediaTypeFactory::KeyList_T GetList()
Definition: mediatype.h:84
OpalMediaTypeDefinition::OpalMediaTypeDefinition
OpalMediaTypeDefinition(const char *mediaType, const char *sdpType, unsigned requiredSessionId=0, OpalMediaType::AutoStartMode autoStart=OpalMediaType::DontOffer)
Create a new media type definition.
OpalRTPAVPMediaType
Definition: mediatype.h:271
SDPMediaDescription
Definition: sdp.h:119
OpalMediaTypeFactory
PFactory< OpalMediaTypeDefinition > OpalMediaTypeFactory
Definition: mediatype.h:45
OpalMediaType::AutoStartMode
AutoStartMode
Definition: mediatype.h:90
OpalMediaType::operator++
__inline friend AutoStartMode operator++(AutoStartMode &mode)
Definition: mediatype.h:101
OpalMediaType::ReceiveTransmit
Definition: mediatype.h:95
operator<<
__inline ostream & operator<<(ostream &strm, const OpalMediaType &mediaType)
Definition: mediatype.h:110
OpalMediaType::Audio
static const OpalMediaType & Audio()
SimpleMediaType::CreateSDPMediaDescription
virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &)
Definition: mediatype.h:251
OpalMediaType::Transmit
Definition: mediatype.h:94
OpalMediaType::DontOffer
Definition: mediatype.h:96
OpalMediaType::GetDefinition
OpalMediaTypeDefinition * GetDefinition() const
OpalMediaType::Receive
Definition: mediatype.h:93
OpalMediaType::Fax
static const OpalMediaType & Fax()
OpalRTPAVPMediaType::GetRTPEncoding
virtual PString GetRTPEncoding() const
OpalMediaTypeDefinition::SetAutoStart
void SetAutoStart(OpalMediaType::AutoStartMode v, bool on)
Definition: mediatype.h:154
SimpleMediaType
Definition: mediatype.h:236
OpalMediaType::OpalMediaType
OpalMediaType(const PString &str)
Definition: mediatype.h:72
OpalRTPAVPMediaType::OpalRTPAVPMediaType
OpalRTPAVPMediaType(const char *mediaType, const char *sdpType, unsigned requiredSessionId=0, OpalMediaType::AutoStartMode autoStart=OpalMediaType::DontOffer)
OpalConnection
Definition: connection.h:353
OpalAudioMediaType
Definition: mediatype.h:286
OpalMediaTypeDefinition::~OpalMediaTypeDefinition
virtual ~OpalMediaTypeDefinition()
OpalMediaTypeDefinition::m_autoStart
OpalMediaType::AutoStartMode m_autoStart
Definition: mediatype.h:194
OpalVideoMediaType
Definition: mediatype.h:298
OpalMediaTypeDefinition::GetAutoStart
OpalMediaType::AutoStartMode GetAutoStart() const
Definition: mediatype.h:149
OpalTransportAddress
Definition: transports.h:149
OpalMediaTypeDefinition::UsesRTP
virtual bool UsesRTP() const
Definition: mediatype.h:159
OpalRTPAVPMediaType::CreateMediaSession
OpalMediaSession * CreateMediaSession(OpalConnection &, unsigned) const
SimpleMediaType::GetRTPEncoding
PString GetRTPEncoding() const
Definition: mediatype.h:247
OpalVideoMediaType::OpalVideoMediaType
OpalVideoMediaType()
SimpleMediaType::~SimpleMediaType
virtual ~SimpleMediaType()
Definition: mediatype.h:243
OpalMediaTypeDefinition::m_defaultSessionId
unsigned m_defaultSessionId
Definition: mediatype.h:193
RTP_UDP
Definition: rtp.h:1098
OpalMediaTypeDefinition
Definition: mediatype.h:132
OpalVideoMediaType::CreateSDPMediaDescription
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &localAddress)
OpalMediaType::~OpalMediaType
virtual ~OpalMediaType()
Definition: mediatype.h:63