# mediatype.h

Go to the documentation of this file.

    00001 /*
    00002  * mediatype.h
    00003  *
    00004  * Media Format Type descriptions
    00005  *
    00006  * Open Phone Abstraction Library (OPAL)
    00007  *
    00008  * Copyright (C) 2007 Post Increment and Hannes Friederich
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * The Original Code is OPAL
    00021  *
    00022  * The Initial Developer of the Original Code is Hannes Friederich and Post Increment
    00023  *
    00024  * Contributor(s): ______________________________________.
    00025  *
    00026  * $Revision: 20942 $
    00027  * $Author: ms30002000 $
    00028  * $Date: 2008-09-12 17:44:53 +0000 (Fri, 12 Sep 2008) $
    00029  */
    00030
    00031 #ifndef __OPAL_MEDIATYPE_H
    00032 #define __OPAL_MEDIATYPE_H
    00033
    00034 #include <ptbuildopts.h>
    00035 #include <ptlib/pfactory.h>
    00036 #include <opal/buildopts.h>
    00037
    00038 #ifdef P_USE_PRAGMA
    00039 #pragma interface
    00040 #endif
    00041
    00042 namespace PWLibStupidLinkerHacks {
    00043 extern int mediaTypeLoader;
    00044 }; // namespace PWLibStupidLinkerHacks
    00045
    00046 class OpalMediaTypeDefinition;
    00047 class OpalSecurityMode;
    00048
    00050 //
    00051 //  define the factory used for keeping track of OpalMediaTypeDefintions
    00052 //
    00053 typedef PFactory<OpalMediaTypeDefinition> OpalMediaTypeFactory;
    00054 typedef OpalMediaTypeFactory::KeyList_T OpalMediaTypeList;
    00055
    00057 //
    00058 //  define the type used to hold the media type identifiers, i.e. "audio", "video", "h.224", "fax" etc
    00059 //
    00060
    00061 class OpalMediaType : public std::string     // do not make this PCaselessString as that type does not work as index for std::map etc
    00062 {
    00063   public:
    00064     OpalMediaType()
    00065     { }
    00066
    00067     virtual ~OpalMediaType()
    00068     { }
    00069
    00070     OpalMediaType(const std::string & _str)
    00071       : std::string(_str) { }
    00072
    00073     OpalMediaType(const char * _str)
    00074       : std::string(_str) { }
    00075
    00076     OpalMediaType(const PString & _str)
    00077       : std::string((const char *)_str) { }
    00078
    00079     static const char * Audio();
    00080     static const char * Video();
    00081     static const char * Fax();
    00082     static const char * UserInput();
    00083
    00084     void PrintOn(ostream & strm) const { strm << (std::string &)*this; }
    00085
    00086     OpalMediaTypeDefinition * GetDefinition() const;
    00087     static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
    00088
    00089     static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
    00090
    00091 #if OPAL_SIP
    00092   public:
    00093     static OpalMediaType GetMediaTypeFromSDP(const std::string & key);
    00094     static PString       GetSDPFromFromMediaType(const OpalMediaType & type);
    00095     static OpalMediaTypeDefinition * GetDefinitionFromSDP(const std::string & key);
    00096 #endif  // OPAL_SIP
    00097 };
    00098
    00099 ostream & operator << (ostream & strm, const OpalMediaType & mediaType);
    00100
    00101
    00103 //
    00104 //  this class defines the functions needed to work with the media type, i.e.
    00105 //
    00106 class OpalRTPConnection;
    00107 class RTP_UDP;
    00108
    00109 #if OPAL_RTP_AGGREGATE
    00110 class PHandleAggregator;
    00111 #else
    00112 typedef void * PHandleAggregator;
    00113 #endif
    00114
    00115 #if OPAL_SIP
    00116 class SDPMediaDescription;
    00117 class OpalTransportAddress;
    00118 #endif
    00119
    00121 //
    00122 //  this class defines the type used to define the attributes of a media type
    00123 //
    00124
    00125 class OpalMediaTypeDefinition  {
    00126   public:
    00127     //
    00128     //  create a new media type definition
    00129     //
    00130     OpalMediaTypeDefinition(
    00131       const char * mediaType,          // name of the media type (audio, video etc)
    00132       const char * sdpType,            // name of the SDP type
    00133       unsigned preferredSessionId      // preferred session ID
    00134     );
    00135
    00136     //
    00137     //  needed to avoid gcc warning about classes with virtual functions and
    00138     //  without a virtual destructor
    00139     //
    00140     virtual ~OpalMediaTypeDefinition() { }
    00141
    00142     //
    00143     //  get the string used for the RTP_FormatHandler PFactory which is used
    00144     //  to create the RTP handler for the this media type
    00145     //  possible values include "rtp/avp" and "udptl"
    00146     //
    00147     virtual PString GetRTPEncoding() const = 0;
    00148
    00149     //
    00150     //  create an RTP session for this media format
    00151     //  By default, this will create a RTP_UDP session with the correct initial format
    00152     //
    00153     virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
    00154 #if OPAL_RTP_AGGREGATE
    00155                                        PHandleAggregator * agg,
    00156 #endif
    00157                                         OpalSecurityMode * securityMode,
    00158                                                   unsigned sessionID,
    00159                                                       bool remoteIsNAT);
    00160
    00161     //
    00162     // return the default session ID for a media type
    00163     //
    00164     unsigned GetDefaultSessionId()   { return GetDefaultSessionId(mediaType); }
    00165
    00166     static unsigned GetDefaultSessionId(
    00167       const OpalMediaType & mediaType
    00168     );
    00169
    00170     //
    00171     // return the media type associated with a default media type
    00172     //
    00173     static OpalMediaType GetMediaTypeForSessionId(
    00174       unsigned sessionId
    00175     );
    00176
    00177   protected:
    00178     static PMutex & GetMapMutex();
    00179
    00180     typedef std::map<OpalMediaType, unsigned> MediaTypeToSessionIDMap_T;
    00181     static MediaTypeToSessionIDMap_T & GetMediaTypeToSessionIDMap();
    00182
    00183     typedef std::map<unsigned, OpalMediaType> SessionIDToMediaTypeMap_T;
    00184     static SessionIDToMediaTypeMap_T & GetSessionIDToMediaTypeMap();
    00185
    00186     std::string mediaType;
    00187
    00188 #if OPAL_SIP
    00189   public:
    00190     //
    00191     //  return the SDP type for this media type
    00192     //
    00193     virtual std::string GetSDPType() const
    00194     { return sdpType; }
    00195
    00196     //
    00197     //  create an SDP media description entry for this media type
    00198     //
    00199     virtual SDPMediaDescription * CreateSDPMediaDescription(
    00200       const OpalTransportAddress & localAddress
    00201     ) = 0;
    00202
    00203   protected:
    00204     std::string sdpType;
    00205 #endif
    00206 };
    00207
    00208
    00210 //
    00211 //  define a macro for declaring a new OpalMediaTypeDefinition factory
    00212 //
    00213
    00214 #define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
    00215 namespace OpalMediaTypeSpace { \
    00216   static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##type##_##cls(#type, true); \
    00217 }; \
    00218
    00219
    00220 #ifdef SOLARIS
    00221 template <char * Type, char * sdp>
    00222 #else
    00223 template <char * Type, const char * sdp>
    00224 #endif
    00225 class SimpleMediaType : public OpalMediaTypeDefinition
    00226 {
    00227   public:
    00228     SimpleMediaType()
    00229       : OpalMediaTypeDefinition(Type, sdp, 0)
    00230     { }
    00231
    00232     virtual ~SimpleMediaType()                     { }
    00233
    00234     virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,
    00235 #if OPAL_RTP_AGGREGATE
    00236                                        PHandleAggregator * ,
    00237 #endif
    00238                                        unsigned , bool ) { return NULL; }
    00239
    00240   PString GetRTPEncoding() const { return PString::Empty(); }
    00241
    00242 #if OPAL_SIP
    00243   public:
    00244     virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
    00245 #endif
    00246 };
    00247
    00248
    00249 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
    00250 namespace OpalMediaTypeSpace { \
    00251   char type##_type_string[] = #type; \
    00252   char type##_sdp_string[] = #sdp; \
    00253   typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
    00254 }; \
    00255 OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
    00256
    00257 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "")
    00258
    00260 //
    00261 //  common ancestor for audio and video OpalMediaTypeDefinitions
    00262 //
    00263
    00264 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
    00265   public:
    00266     OpalRTPAVPMediaType(
    00267       const char * mediaType,
    00268       const char * sdpType,
    00269           unsigned preferredSessionId
    00270     );
    00271
    00272     virtual PString GetRTPEncoding() const;
    00273 };
    00274
    00275
    00276 class OpalAudioMediaType : public OpalRTPAVPMediaType {
    00277   public:
    00278     OpalAudioMediaType();
    00279
    00280 #if OPAL_SIP
    00281     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
    00282 #endif
    00283 };
    00284
    00285
    00286 #if OPAL_VIDEO
    00287
    00288 class OpalVideoMediaType : public OpalRTPAVPMediaType {
    00289   public:
    00290     OpalVideoMediaType();
    00291
    00292 #if OPAL_SIP
    00293     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
    00294 #endif
    00295 };
    00296
    00297 #endif // OPAL_VIDEO
    00298
    00299
    00300 #if OPAL_T38_CAPABILITY
    00301
    00302 #include <opal/mediatype.h>
    00303
    00304 class OpalFaxMediaType : public OpalMediaTypeDefinition
    00305 {
    00306   public:
    00307     OpalFaxMediaType();
    00308
    00309     PString GetRTPEncoding(void) const;
    00310     RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
    00311 #if OPAL_RTP_AGGREGATE
    00312                                PHandleAggregator * agg,
    00313 #endif
    00314                                unsigned sessionID, bool remoteIsNAT);
    00315
    00316 #if OPAL_SIP
    00317     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
    00318 #endif
    00319 };
    00320
    00321 #endif // OPAL_T38_CAPABILITY
    00322
    00323
    00324 #endif // __OPAL_MEDIATYPE_H