mediafmt.h

Go to the documentation of this file.
00001 /*
00002  * mediafmt.h
00003  *
00004  * Media Format descriptions
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  * Formally known as the Open H323 project.
00008  *
00009  * Copyright (c) 2001 Equivalence Pty. Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Open H323 Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Contributor(s): ______________________________________.
00026  *
00027  * $Revision: 24504 $
00028  * $Author: rjongbloed $
00029  * $Date: 2010-06-17 17:49:01 -0500 (Thu, 17 Jun 2010) $
00030  */
00031 
00032 #ifndef OPAL_OPAL_MEDIAFMT_H
00033 #define OPAL_OPAL_MEDIAFMT_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #ifdef _MSC_VER
00040 #if _MSC_VER < 1300   
00041 #pragma warning(disable:4663)
00042 #endif
00043 #endif
00044 
00045 #include <opal/buildopts.h>
00046 
00047 #include <opal/mediatype.h>
00048 #include <rtp/rtp.h>
00049 
00050 #if OPAL_VIDEO
00051 #include <ptlib/videoio.h>
00052 #endif
00053 
00054 #include <limits>
00055 
00056 #ifdef min
00057 #undef min
00058 #endif
00059 #ifdef max
00060 #undef max
00061 #endif
00062 
00063 class OpalMediaFormat;
00064 
00065 
00067 
00068 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
00069 
00072 class OpalMediaFormatList : public OpalMediaFormatBaseList
00073 {
00074   PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
00075   public:
00080     OpalMediaFormatList();
00081 
00084     OpalMediaFormatList(
00085       const OpalMediaFormat & format    
00086     );
00087 
00090     OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
00092 
00098     OpalMediaFormatList & operator+=(
00099       const OpalMediaFormat & format    
00100     );
00101 
00105     OpalMediaFormatList & operator+=(
00106       const OpalMediaFormatList & formats    
00107     );
00108 
00112     OpalMediaFormatList & operator-=(
00113       const OpalMediaFormat & format    
00114     );
00115 
00119     OpalMediaFormatList & operator-=(
00120       const OpalMediaFormatList & formats    
00121     );
00122 
00128     const_iterator FindFormat(
00129       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00130       const unsigned clockRate,                   
00131       const char * rtpEncodingName = NULL,        
00132       const char * protocol = NULL,               
00133       const_iterator start = const_iterator()     
00134     ) const;
00135 
00152     const_iterator FindFormat(
00153       const PString & wildcard,    
00154       const_iterator start = const_iterator()
00155     ) const;
00156 
00159     PBoolean HasFormat(
00160       RTP_DataFrame::PayloadTypes rtpPayloadType 
00161     ) const { return FindFormat(rtpPayloadType) != end(); }
00162 
00168     PBoolean HasFormat(
00169       const PString & wildcard    
00170     ) const { return FindFormat(wildcard) != end(); }
00171 
00190     void Remove(
00191       const PStringArray & mask
00192     );
00193 
00209     void Reorder(
00210       const PStringArray & order
00211     );
00212 
00215     bool HasType(
00216       const OpalMediaType & type,
00217       bool mustBeTransportable = true
00218     ) const;
00220 
00221   private:
00222     virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
00223     virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
00224     virtual PINDEX InsertAt(PINDEX, PObject *) { return P_MAX_INDEX; }
00225     virtual PBoolean SetAt(PINDEX, PObject *) { return PFalse; }
00226 };
00227 
00228 
00230 
00233 class OpalMediaOption : public PObject
00234 {
00235     PCLASSINFO(OpalMediaOption, PObject);
00236   public:
00237     // Note the below enum must be identical to PluginCodec_OptionMerge in opalplugin.h
00238     enum MergeType {
00239       NoMerge,
00240       MinMerge,
00241       MaxMerge,
00242       EqualMerge,
00243       NotEqualMerge,
00244       AlwaysMerge,
00245       CustomMerge,
00246       IntersectionMerge, // Set intersection, applies to numeric (bit wise AND) or string (common substrings)
00247 
00248       // Synonyms
00249       AndMerge = MinMerge,  // Applies to Boolean option or Enum with two elements
00250       OrMerge  = MaxMerge   // Applies to Boolean option or Enum with two elements
00251     };
00252 
00253   protected:
00254     OpalMediaOption(
00255       const PString & name
00256     );
00257     OpalMediaOption(
00258       const char * name,
00259       bool readOnly,
00260       MergeType merge
00261     );
00262 
00263   public:
00264     virtual Comparison Compare(const PObject & obj) const;
00265 
00266     virtual bool Merge(
00267       const OpalMediaOption & option
00268     );
00269 
00270     virtual bool ValidateMerge(
00271       const OpalMediaOption & option
00272     ) const;
00273 
00274     virtual Comparison CompareValue(
00275       const OpalMediaOption & option
00276     ) const = 0;
00277     virtual void Assign(
00278       const OpalMediaOption & option
00279     ) = 0;
00280 
00281     PString AsString() const;
00282     bool FromString(const PString & value);
00283 
00284     const PString & GetName() const { return m_name; }
00285 
00286     bool IsReadOnly() const { return m_readOnly; }
00287     void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
00288 
00289     MergeType GetMerge() const { return m_merge; }
00290     void SetMerge(MergeType merge) { m_merge = merge; }
00291 
00292 #if OPAL_SIP
00293     const PString & GetFMTPName() const { return m_FMTPName; }
00294     void SetFMTPName(const char * name) { m_FMTPName = name; }
00295 
00296     const PString & GetFMTPDefault() const { return m_FMTPDefault; }
00297     void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
00298 #endif // OPAL_SIP
00299 
00300 #if OPAL_H323
00301     struct H245GenericInfo {
00302       H245GenericInfo() { memset(this, 0, sizeof(*this)); }
00303       unsigned ordinal:16;
00304       enum Modes {
00305         None,
00306         Collapsing,
00307         NonCollapsing
00308       } mode:3;
00309       enum IntegerTypes {
00310         UnsignedInt,
00311         Unsigned32,
00312         BooleanArray
00313       } integerType:3;
00314       bool excludeTCS:1;
00315       bool excludeOLC:1;
00316       bool excludeReqMode:1;
00317     };
00318 
00319     const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
00320     void SetH245Generic(const H245GenericInfo & genericInfo) { m_H245Generic = genericInfo; }
00321 #endif // OPAL_H323
00322 
00323   protected:
00324     PCaselessString m_name;
00325     bool            m_readOnly;
00326     MergeType       m_merge;
00327 
00328 #if OPAL_SIP
00329     PCaselessString m_FMTPName;
00330     PString         m_FMTPDefault;
00331 #endif // OPAL_SIP
00332 
00333 #if OPAL_H323
00334     H245GenericInfo m_H245Generic;
00335 #endif // OPAL_H323
00336 };
00337 
00338 
00339 template <typename T>
00340 class OpalMediaOptionValue : public OpalMediaOption
00341 {
00342     PCLASSINFO(OpalMediaOptionValue, OpalMediaOption);
00343   public:
00344     OpalMediaOptionValue(
00345       const char * name,
00346       bool readOnly,
00347       MergeType merge = MinMerge,
00348       T value = 0,
00349       T minimum = std::numeric_limits<T>::min(),
00350       T maximum = std::numeric_limits<T>::max()
00351     ) : OpalMediaOption(name, readOnly, merge),
00352         m_value(value),
00353         m_minimum(minimum),
00354         m_maximum(maximum)
00355     { }
00356 
00357     virtual PObject * Clone() const
00358     {
00359       return new OpalMediaOptionValue(*this);
00360     }
00361 
00362     virtual void PrintOn(ostream & strm) const
00363     {
00364       strm << m_value;
00365     }
00366 
00367     virtual void ReadFrom(istream & strm)
00368     {
00369       T temp = 0;
00370       strm >> temp;
00371       if (temp >= m_minimum && temp <= m_maximum)
00372         m_value = temp;
00373       else
00374         strm.setstate(ios::badbit);
00375     }
00376 
00377     static __inline bool Intersect(bool a, bool b)         { return a && b; }
00378     static __inline bool Intersect(int a, int b)           { return a & b; }
00379     static __inline bool Intersect(unsigned a, unsigned b) { return a & b; }
00380     static __inline bool Intersect(double a, double b)     { return std::min(a, b); }
00381 
00382     virtual bool Merge(const OpalMediaOption & option)
00383     {
00384       if (m_merge != IntersectionMerge)
00385         return OpalMediaOption::Merge(option);
00386       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00387       if (otherOption == NULL)
00388         return false;
00389       SetValue(Intersect(GetValue(), otherOption->GetValue()));
00390       return true;
00391     }
00392 
00393     virtual Comparison CompareValue(const OpalMediaOption & option) const
00394     {
00395       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00396       if (otherOption == NULL)
00397         return GreaterThan;
00398       if (m_value < otherOption->m_value)
00399         return LessThan;
00400       if (m_value > otherOption->m_value)
00401         return GreaterThan;
00402       return EqualTo;
00403     }
00404 
00405     virtual void Assign(
00406       const OpalMediaOption & option
00407     ) {
00408       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00409       if (otherOption != NULL)
00410         m_value = otherOption->m_value;
00411     }
00412 
00413     T GetValue() const
00414     {
00415       return m_value;
00416     }
00417 
00418     void SetValue(T value)
00419     {
00420       if (value < m_minimum)
00421         m_value = m_minimum;
00422       else if (value > m_maximum)
00423         m_value = m_maximum;
00424       else
00425         m_value = value;
00426     }
00427 
00428     void SetMinimum(T m)
00429     {
00430       m_minimum = m;
00431     }
00432 
00433     void SetMaximum(T m)
00434     {
00435       m_maximum = m;
00436     }
00437 
00438   protected:
00439     T m_value;
00440     T m_minimum;
00441     T m_maximum;
00442 };
00443 
00444 
00445 typedef OpalMediaOptionValue<bool>     OpalMediaOptionBoolean;
00446 typedef OpalMediaOptionValue<int>      OpalMediaOptionInteger;
00447 typedef OpalMediaOptionValue<unsigned> OpalMediaOptionUnsigned;
00448 typedef OpalMediaOptionValue<double>   OpalMediaOptionReal;
00449 
00450 
00451 class OpalMediaOptionEnum : public OpalMediaOption
00452 {
00453     PCLASSINFO(OpalMediaOptionEnum, OpalMediaOption);
00454   public:
00455     OpalMediaOptionEnum(
00456       const char * name,
00457       bool readOnly
00458     );
00459     OpalMediaOptionEnum(
00460       const char * name,
00461       bool readOnly,
00462       const char * const * enumerations,
00463       PINDEX count,
00464       MergeType merge = EqualMerge,
00465       PINDEX value = 0
00466     );
00467 
00468     virtual PObject * Clone() const;
00469     virtual void PrintOn(ostream & strm) const;
00470     virtual void ReadFrom(istream & strm);
00471 
00472     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00473     virtual void Assign(const OpalMediaOption & option);
00474 
00475     PINDEX GetValue() const { return m_value; }
00476     void SetValue(PINDEX value);
00477 
00478     const PStringArray & GetEnumerations() const { return m_enumerations; }
00479     void SetEnumerations(const PStringArray & e)
00480     {
00481       m_enumerations = e;
00482     }
00483 
00484   protected:
00485     PStringArray m_enumerations;
00486     PINDEX       m_value;
00487 };
00488 
00489 
00490 class OpalMediaOptionString : public OpalMediaOption
00491 {
00492     PCLASSINFO(OpalMediaOptionString, OpalMediaOption);
00493   public:
00494     OpalMediaOptionString(
00495       const char * name,
00496       bool readOnly
00497     );
00498     OpalMediaOptionString(
00499       const char * name,
00500       bool readOnly,
00501       const PString & value
00502     );
00503 
00504     virtual PObject * Clone() const;
00505     virtual void PrintOn(ostream & strm) const;
00506     virtual void ReadFrom(istream & strm);
00507 
00508     virtual bool Merge(const OpalMediaOption & option);
00509     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00510     virtual void Assign(const OpalMediaOption & option);
00511 
00512     const PString & GetValue() const { return m_value; }
00513     void SetValue(const PString & value);
00514 
00515   protected:
00516     PString m_value;
00517 };
00518 
00519 
00520 class OpalMediaOptionOctets : public OpalMediaOption
00521 {
00522     PCLASSINFO(OpalMediaOptionOctets, OpalMediaOption);
00523   public:
00524     OpalMediaOptionOctets(
00525       const char * name,
00526       bool readOnly,
00527       bool base64 = false
00528     );
00529     OpalMediaOptionOctets(
00530       const char * name,
00531       bool readOnly,
00532       bool base64,
00533       const PBYTEArray & value
00534     );
00535     OpalMediaOptionOctets(
00536       const char * name,
00537       bool readOnly,
00538       bool base64,
00539       const BYTE * data,
00540       PINDEX length
00541     );
00542 
00543     virtual PObject * Clone() const;
00544     virtual void PrintOn(ostream & strm) const;
00545     virtual void ReadFrom(istream & strm);
00546 
00547     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00548     virtual void Assign(const OpalMediaOption & option);
00549 
00550     const PBYTEArray & GetValue() const { return m_value; }
00551     void SetValue(const PBYTEArray & value);
00552     void SetValue(const BYTE * data, PINDEX length);
00553 
00554     void SetBase64(bool b)
00555     {
00556       m_base64 = b;
00557     }
00558 
00559   protected:
00560     PBYTEArray m_value;
00561     bool       m_base64;
00562 };
00563 
00564 
00566 
00567 class OpalMediaFormatInternal : public PObject
00568 {
00569     PCLASSINFO(OpalMediaFormatInternal, PObject);
00570   public:
00571     OpalMediaFormatInternal(
00572       const char * fullName,
00573       const OpalMediaType & mediaType,
00574       RTP_DataFrame::PayloadTypes rtpPayloadType,
00575       const char * encodingName,
00576       PBoolean     needsJitter,
00577       unsigned bandwidth,
00578       PINDEX   frameSize,
00579       unsigned frameTime,
00580       unsigned clockRate,
00581       time_t timeStamp
00582     );
00583 
00584     const PCaselessString & GetName() const { return formatName; }
00585 
00586     virtual PObject * Clone() const;
00587     virtual void PrintOn(ostream & strm) const;
00588 
00589     virtual bool IsValid() const;
00590     virtual bool IsTransportable() const;
00591 
00592     virtual PStringToString GetOptions() const;
00593     virtual bool GetOptionValue(const PString & name, PString & value) const;
00594     virtual bool SetOptionValue(const PString & name, const PString & value);
00595     virtual bool GetOptionBoolean(const PString & name, bool dflt) const;
00596     virtual bool SetOptionBoolean(const PString & name, bool value);
00597     virtual int GetOptionInteger(const PString & name, int dflt) const;
00598     virtual bool SetOptionInteger(const PString & name, int value);
00599     virtual double GetOptionReal(const PString & name, double dflt) const;
00600     virtual bool SetOptionReal(const PString & name, double value);
00601     virtual PINDEX GetOptionEnum(const PString & name, PINDEX dflt) const;
00602     virtual bool SetOptionEnum(const PString & name, PINDEX value);
00603     virtual PString GetOptionString(const PString & name, const PString & dflt) const;
00604     virtual bool SetOptionString(const PString & name, const PString & value);
00605     virtual bool GetOptionOctets(const PString & name, PBYTEArray & octets) const;
00606     virtual bool SetOptionOctets(const PString & name, const PBYTEArray & octets);
00607     virtual bool SetOptionOctets(const PString & name, const BYTE * data, PINDEX length);
00608     virtual bool AddOption(OpalMediaOption * option, PBoolean overwrite = PFalse);
00609     virtual OpalMediaOption * FindOption(const PString & name) const;
00610 
00611     virtual bool ToNormalisedOptions();
00612     virtual bool ToCustomisedOptions();
00613     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
00614 
00615     virtual bool ValidateMerge(const OpalMediaFormatInternal & mediaFormat) const;
00616 
00617     virtual bool IsValidForProtocol(const PString & protocol) const;
00618 
00619   protected:
00620     PCaselessString              formatName;
00621     RTP_DataFrame::PayloadTypes  rtpPayloadType;
00622     PString                      rtpEncodingName;
00623     OpalMediaType                mediaType;
00624     PMutex                       media_format_mutex;
00625     PSortedList<OpalMediaOption> options;
00626     time_t                       codecVersionTime;
00627     bool                         forceIsTransportable;
00628 
00629   friend bool operator==(const char * other, const OpalMediaFormat & fmt);
00630   friend bool operator!=(const char * other, const OpalMediaFormat & fmt);
00631   friend bool operator==(const PString & other, const OpalMediaFormat & fmt);
00632   friend bool operator!=(const PString & other, const OpalMediaFormat & fmt);
00633 
00634   friend class OpalMediaFormat;
00635   friend class OpalMediaFormatList;
00636   friend class OpalAudioFormatInternal;
00637 };
00638 
00639 
00641 
00647 class OpalMediaFormat : public PContainer
00648 {
00649     PCLASSINFO(OpalMediaFormat, PContainer)
00650   public:
00651     OpalMediaFormat(const OpalMediaFormat & c) : PContainer(c), m_info(c.m_info) { }
00652     OpalMediaFormat & operator=(const OpalMediaFormat & c)     { AssignContents(c); return *this; }
00653     virtual ~OpalMediaFormat()                                 { Destruct(); }
00654     virtual PBoolean MakeUnique();
00655   protected:
00656     virtual void DestroyContents();
00657     virtual void AssignContents(const PContainer & c);
00658 
00659   public:
00662     OpalMediaFormat(
00663       OpalMediaFormatInternal * info = NULL
00664     );
00665 
00679     OpalMediaFormat(
00680       const char * fullName,                      
00681       const OpalMediaType & mediaType,            
00682       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00683       const char * encodingName,                  
00684       PBoolean     needsJitter,                   
00685       unsigned bandwidth,                         
00686       PINDEX   frameSize,                         
00687       unsigned frameTime,                         
00688       unsigned clockRate,                         
00689       time_t timeStamp = 0                        
00690     );
00691 
00701     OpalMediaFormat(
00702       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00703       unsigned clockRate,                         
00704       const char * rtpEncodingName = NULL,        
00705       const char * protocol = NULL                
00706     );
00707 
00721     OpalMediaFormat(
00722       const char * wildcard  
00723     );
00724 
00738     OpalMediaFormat(
00739       const PString & wildcard  
00740     );
00741     
00745     OpalMediaFormat & operator=(
00746       RTP_DataFrame::PayloadTypes rtpPayloadType 
00747     );
00748 
00752     OpalMediaFormat & operator=(
00753       const char * wildcard  
00754     );
00755 
00759     OpalMediaFormat & operator=(
00760       const PString & wildcard  
00761     );
00762 
00765     virtual PObject * Clone() const;
00766 
00769     virtual Comparison Compare(const PObject & obj) const;
00770 
00775     virtual void PrintOn(ostream & strm) const;
00776 
00779     virtual void ReadFrom(istream & strm);
00780 
00785     bool ToNormalisedOptions();
00786 
00790     bool ToCustomisedOptions();
00791 
00794     bool Update(
00795       const OpalMediaFormat & mediaFormat
00796     );
00797 
00808     bool Merge(
00809       const OpalMediaFormat & mediaFormat
00810     );
00813     bool ValidateMerge(
00814       const OpalMediaFormat & mediaFormat
00815     ) const;
00816 
00819     PString GetName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
00820 
00825     PBoolean IsValid() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValid(); }
00826 
00830     PBoolean IsTransportable() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsTransportable(); }
00831 
00837     RTP_DataFrame::PayloadTypes GetPayloadType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? RTP_DataFrame::IllegalPayloadType : m_info->rtpPayloadType; }
00838     void SetPayloadType(RTP_DataFrame::PayloadTypes type) { PWaitAndSignal m(m_mutex); MakeUnique(); if (m_info != NULL) m_info->rtpPayloadType = type; }
00839 
00842     const char * GetEncodingName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->rtpEncodingName.GetPointer(); }
00843 
00846     OpalMediaType GetMediaType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? OpalMediaType() : m_info->mediaType; }
00847 
00851     bool NeedsJitterBuffer() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(NeedsJitterOption(), PFalse); }
00852     static const PString & NeedsJitterOption();
00853 
00856     unsigned GetBandwidth() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxBitRateOption(), 0); }
00857     static const PString & MaxBitRateOption();
00858     static const PString & TargetBitRateOption();
00859 
00864     PINDEX GetFrameSize() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxFrameSizeOption(), 0); }
00865     static const PString & MaxFrameSizeOption();
00866 
00870     unsigned GetFrameTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(FrameTimeOption(), 0); }
00871     static const PString & FrameTimeOption();
00872 
00875     unsigned GetTimeUnits() const { return GetClockRate()/1000; }
00876 
00877     enum StandardClockRate {
00878       AudioClockRate = 8000,  
00879       VideoClockRate = 90000  
00880     };
00881 
00884     unsigned GetClockRate() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(ClockRateOption(), 1000); }
00885     static const PString & ClockRateOption();
00886 
00889     static const PString & ProtocolOption();
00890 
00893     static const PString & MaxTxPacketSizeOption();
00894 
00898     PStringToString GetOptions() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? PStringToString() : m_info->GetOptions(); }
00899 
00902     PINDEX GetOptionCount() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->options.GetSize(); }
00903 
00907     const OpalMediaOption & GetOption(
00908       PINDEX index   
00909     ) const { PWaitAndSignal m(m_mutex); return m_info->options[index]; }
00910 
00915     bool GetOptionValue(
00916       const PString & name,   
00917       PString & value         
00918     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionValue(name, value); }
00919 
00926     bool SetOptionValue(
00927       const PString & name,   
00928       const PString & value   
00929     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionValue(name, value); }
00930 
00934     bool GetOptionBoolean(
00935       const PString & name,   
00936       bool dflt = PFalse       
00937     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(name, dflt); }
00938 
00945     bool SetOptionBoolean(
00946       const PString & name,   
00947       bool value              
00948     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionBoolean(name, value); }
00949 
00953     int GetOptionInteger(
00954       const PString & name,   
00955       int dflt = 0            
00956     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionInteger(name, dflt); }
00957 
00965     bool SetOptionInteger(
00966       const PString & name,   
00967       int value               
00968     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionInteger(name, value); }
00969 
00973     double GetOptionReal(
00974       const PString & name,   
00975       double dflt = 0         
00976     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionReal(name, dflt); }
00977 
00984     bool SetOptionReal(
00985       const PString & name,   
00986       double value            
00987     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionReal(name, value); }
00988 
00993     PINDEX GetOptionEnum(
00994       const PString & name,   
00995       PINDEX dflt = 0         
00996     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionEnum(name, dflt); }
00997 
01004     bool SetOptionEnum(
01005       const PString & name,   
01006       PINDEX value            
01007     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionEnum(name, value); }
01008 
01012     PString GetOptionString(
01013       const PString & name,                   
01014       const PString & dflt = PString::Empty() 
01015     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionString(name, dflt); }
01016 
01023     bool SetOptionString(
01024       const PString & name,   
01025       const PString & value   
01026     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionString(name, value); }
01027 
01031     bool GetOptionOctets(
01032       const PString & name, 
01033       PBYTEArray & octets   
01034     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionOctets(name, octets); }
01035 
01042     bool SetOptionOctets(
01043       const PString & name,       
01044       const PBYTEArray & octets   
01045     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, octets); }
01046     bool SetOptionOctets(
01047       const PString & name,       
01048       const BYTE * data,          
01049       PINDEX length               
01050     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, data, length); }
01051 
01055     static OpalMediaFormatList GetMatchingRegisteredMediaFormats(
01056       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01057       const unsigned clockRate,                   
01058       const char * rtpEncodingName = NULL,        
01059       const char * protocol = NULL                
01060     );
01061 
01064     static OpalMediaFormatList GetAllRegisteredMediaFormats();
01065     static void GetAllRegisteredMediaFormats(
01066       OpalMediaFormatList & copy    
01067     );
01068 
01072     static bool SetRegisteredMediaFormat(
01073       const OpalMediaFormat & mediaFormat  
01074     );
01075 
01079     bool AddOption(
01080       OpalMediaOption * option,
01081       PBoolean overwrite = PFalse
01082     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->AddOption(option, overwrite); }
01083 
01087     bool HasOption(const PString & name) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->FindOption(name) != NULL; }
01088 
01093     OpalMediaOption * FindOption(
01094       const PString & name
01095     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? NULL : m_info->FindOption(name); }
01096 
01102     bool IsValidForProtocol(const PString & protocol) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValidForProtocol(protocol); }
01103 
01104     time_t GetCodecVersionTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->codecVersionTime; }
01105 
01106     ostream & PrintOptions(ostream & strm) const
01107     {
01108       PWaitAndSignal m(m_mutex);
01109       if (m_info != NULL)
01110         strm << setw(-1) << *m_info;
01111       return strm;
01112     }
01113 
01114 #if OPAL_VIDEO
01115 
01117     void AdjustVideoArgs(
01118       PVideoDevice::OpenArgs & args  
01119     ) const;
01120 #endif
01121 
01122     // Backward compatibility
01123     virtual PBoolean IsEmpty() const { PWaitAndSignal m(m_mutex); return m_info == NULL || !m_info->IsValid(); }
01124     operator PString() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
01125     operator const char *() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
01126     bool operator==(const char * other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
01127     bool operator!=(const char * other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
01128     bool operator==(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
01129     bool operator!=(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
01130     bool operator==(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) == EqualTo; }
01131     bool operator!=(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) != EqualTo; }
01132     friend bool operator==(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
01133     friend bool operator!=(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
01134     friend bool operator==(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
01135     friend bool operator!=(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
01136 
01137 #if OPAL_H323
01138     static const PString & MediaPacketizationOption();
01139     static const PString & MediaPacketizationsOption();
01140 #endif
01141 
01142   private:
01143     PBoolean SetSize(PINDEX) { return PTrue; }
01144 
01145   protected:
01146     void Construct(OpalMediaFormatInternal * info);
01147 
01148     OpalMediaFormatInternal * m_info;
01149     PMutex                    m_mutex;
01150 
01151   friend class OpalMediaFormatInternal;
01152   friend class OpalMediaFormatList;
01153 };
01154 
01155 
01156 class OpalAudioFormatInternal : public OpalMediaFormatInternal
01157 {
01158   public:
01159     OpalAudioFormatInternal(
01160       const char * fullName,
01161       RTP_DataFrame::PayloadTypes rtpPayloadType,
01162       const char * encodingName,
01163       PINDEX   frameSize,
01164       unsigned frameTime,
01165       unsigned rxFrames,
01166       unsigned txFrames,
01167       unsigned maxFrames,
01168       unsigned clockRate,
01169       time_t timeStamp
01170     );
01171     virtual PObject * Clone() const;
01172     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
01173 };
01174 
01175 class OpalAudioFormat : public OpalMediaFormat
01176 {
01177     PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
01178   public:
01179     OpalAudioFormat(
01180       OpalMediaFormatInternal * info = NULL
01181     ) : OpalMediaFormat(info) { }
01182     OpalAudioFormat(
01183       const char * fullName,    
01184       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01185       const char * encodingName,
01186       PINDEX   frameSize,       
01187       unsigned frameTime,       
01188       unsigned rxFrames,        
01189       unsigned txFrames,        
01190       unsigned maxFrames = 256, 
01191       unsigned clockRate = 8000, 
01192       time_t timeStamp = 0       
01193     );
01194 
01195     static const PString & RxFramesPerPacketOption();
01196     static const PString & TxFramesPerPacketOption();
01197     static const PString & MaxFramesPerPacketOption();
01198     static const PString & ChannelsOption();
01199 };
01200 
01201 #if OPAL_VIDEO
01202 class OpalVideoFormatInternal : public OpalMediaFormatInternal
01203 {
01204   public:
01205     OpalVideoFormatInternal(
01206       const char * fullName,
01207       RTP_DataFrame::PayloadTypes rtpPayloadType,
01208       const char * encodingName,
01209       unsigned maxFrameWidth,
01210       unsigned maxFrameHeight,
01211       unsigned maxFrameRate,
01212       unsigned maxBitRate,
01213       time_t timeStamp
01214     );
01215     virtual PObject * Clone() const;
01216     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
01217 };
01218 
01219 
01220 class OpalVideoFormat : public OpalMediaFormat
01221 {
01222     PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
01223   public:
01224     OpalVideoFormat(
01225       OpalMediaFormatInternal * info = NULL
01226     ) : OpalMediaFormat(info) { }
01227     OpalVideoFormat(
01228       const char * fullName,    
01229       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01230       const char * encodingName,
01231       unsigned maxFrameWidth,   
01232       unsigned maxFrameHeight,  
01233       unsigned maxFrameRate,    
01234       unsigned maxBitRate,      
01235       time_t timeStamp = 0      
01236     );
01237 
01238     static const PString & FrameWidthOption();
01239     static const PString & FrameHeightOption();
01240     static const PString & MinRxFrameWidthOption();
01241     static const PString & MinRxFrameHeightOption();
01242     static const PString & MaxRxFrameWidthOption();
01243     static const PString & MaxRxFrameHeightOption();
01244     static const PString & TemporalSpatialTradeOffOption();
01245     static const PString & TxKeyFramePeriodOption();
01246     static const PString & RateControlEnableOption();
01247     static const PString & RateControllerOption();
01248     static const PString & RateControllerBitRateScalerOption();
01249 
01260     enum ContentRole {
01261       eNoRole,
01262       ePresentation,
01263       eMainRole,
01264       eSpeaker,
01265       eSignLanguage,
01266       eNumRoles
01267     };
01268     enum { ContentRoleMask = 15 };
01269     __inline static unsigned ContentRoleBit(ContentRole contentRole) { return contentRole != eNoRole ? (1<<(contentRole-1)) : 0; }
01270     static const PString & ContentRoleOption();
01271     static const PString & ContentRoleMaskOption();
01272 };
01273 #endif
01274 
01275 // List of known media formats
01276 
01277 #define OPAL_PCM16          "PCM-16"
01278 #define OPAL_PCM16_16KHZ    "PCM-16-16kHz"
01279 #define OPAL_PCM16_32KHZ    "PCM-16-32kHz"
01280 #define OPAL_PCM16_48KHZ    "PCM-16-48kHz"
01281 #define OPAL_L16_MONO_8KHZ  "Linear-16-Mono-8kHz"
01282 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
01283 #define OPAL_L16_MONO_32KHZ "Linear-16-Mono-32kHz"
01284 #define OPAL_L16_MONO_48KHZ "Linear-16-Mono-48kHz"
01285 #define OPAL_G711_ULAW_64K  "G.711-uLaw-64k"
01286 #define OPAL_G711_ALAW_64K  "G.711-ALaw-64k"
01287 #define OPAL_G722           "G.722"
01288 #define OPAL_G7221          "G.722.1"
01289 #define OPAL_G7222          "G.722.2"
01290 #define OPAL_G726_40K       "G.726-40K"
01291 #define OPAL_G726_32K       "G.726-32K"
01292 #define OPAL_G726_24K       "G.726-24K"
01293 #define OPAL_G726_16K       "G.726-16K"
01294 #define OPAL_G728           "G.728"
01295 #define OPAL_G729           "G.729"
01296 #define OPAL_G729A          "G.729A"
01297 #define OPAL_G729B          "G.729B"
01298 #define OPAL_G729AB         "G.729A/B"
01299 #define OPAL_G7231          "G.723.1"
01300 #define OPAL_G7231_6k3      OPAL_G7231
01301 #define OPAL_G7231_5k3      "G.723.1(5.3k)"
01302 #define OPAL_G7231A_6k3     "G.723.1A(6.3k)"
01303 #define OPAL_G7231A_5k3     "G.723.1A(5.3k)"
01304 #define OPAL_GSM0610        "GSM-06.10"
01305 #define OPAL_GSMAMR         "GSM-AMR"
01306 #define OPAL_iLBC           "iLBC"
01307 #define OPAL_H261           "H.261"
01308 #define OPAL_H263           "H.263"
01309 #define OPAL_H264_MODE0     "H.264-0"
01310 #define OPAL_H264_MODE1     "H.264-1"
01311 #define OPAL_MPEG4          "MPEG4"
01312 #define OPAL_RFC2833        "UserInput/RFC2833"
01313 #define OPAL_CISCONSE       "NamedSignalEvent"
01314 #define OPAL_T38            "T.38"
01315 
01316 extern const OpalAudioFormat & GetOpalPCM16();
01317 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
01318 extern const OpalAudioFormat & GetOpalPCM16_32KHZ();
01319 extern const OpalAudioFormat & GetOpalPCM16_48KHZ();
01320 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
01321 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
01322 extern const OpalAudioFormat & GetOpalL16_MONO_32KHZ();
01323 extern const OpalAudioFormat & GetOpalL16_MONO_48KHZ();
01324 extern const OpalAudioFormat & GetOpalL16_STEREO_48KHZ();
01325 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
01326 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
01327 extern const OpalAudioFormat & GetOpalG722();
01328 extern const OpalAudioFormat & GetOpalG7221();
01329 extern const OpalAudioFormat & GetOpalG7222();
01330 extern const OpalAudioFormat & GetOpalG726_40K();
01331 extern const OpalAudioFormat & GetOpalG726_32K();
01332 extern const OpalAudioFormat & GetOpalG726_24K();
01333 extern const OpalAudioFormat & GetOpalG726_16K();
01334 extern const OpalAudioFormat & GetOpalG728();
01335 extern const OpalAudioFormat & GetOpalG729();
01336 extern const OpalAudioFormat & GetOpalG729A();
01337 extern const OpalAudioFormat & GetOpalG729B();
01338 extern const OpalAudioFormat & GetOpalG729AB();
01339 extern const OpalAudioFormat & GetOpalG7231_6k3();
01340 extern const OpalAudioFormat & GetOpalG7231_5k3();
01341 extern const OpalAudioFormat & GetOpalG7231A_6k3();
01342 extern const OpalAudioFormat & GetOpalG7231A_5k3();
01343 extern const OpalAudioFormat & GetOpalGSM0610();
01344 extern const OpalAudioFormat & GetOpalGSMAMR();
01345 extern const OpalAudioFormat & GetOpaliLBC();
01346 
01347 extern const OpalMediaFormat & GetOpalRFC2833();
01348 
01349 #if OPAL_T38_CAPABILITY
01350 extern const OpalMediaFormat & GetOpalCiscoNSE();
01351 extern const OpalMediaFormat & GetOpalT38();
01352 #endif
01353 
01354 
01355 #define OpalPCM16          GetOpalPCM16()
01356 #define OpalPCM16_16KHZ    GetOpalPCM16_16KHZ()
01357 #define OpalPCM16_32KHZ    GetOpalPCM16_32KHZ()
01358 #define OpalPCM16_48KHZ    GetOpalPCM16_48KHZ()
01359 #define OpalL16_MONO_8KHZ  GetOpalL16_MONO_8KHZ()
01360 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
01361 #define OpalL16_MONO_32KHZ GetOpalL16_MONO_32KHZ()
01362 #define OpalL16_MONO_48KHZ GetOpalL16_MONO_48KHZ()
01363 #define OpalL16_STEREO_48KHZ GetOpalL16_STEREO_48KHZ()
01364 #define OpalG711_ULAW_64K  GetOpalG711_ULAW_64K()
01365 #define OpalG711_ALAW_64K  GetOpalG711_ALAW_64K()
01366 #define OpalG722           GetOpalG722()
01367 #define OpalG7221          GetOpalG7221()
01368 #define OpalG7222          GetOpalG7222()
01369 #define OpalG726_40K       GetOpalG726_40K()
01370 #define OpalG726_32K       GetOpalG726_32K()
01371 #define OpalG726_24K       GetOpalG726_24K()
01372 #define OpalG726_16K       GetOpalG726_16K()
01373 #define OpalG728           GetOpalG728()
01374 #define OpalG729           GetOpalG729()
01375 #define OpalG729A          GetOpalG729A()
01376 #define OpalG729B          GetOpalG729B()
01377 #define OpalG729AB         GetOpalG729AB()
01378 #define OpalG7231_6k3      GetOpalG7231_6k3()
01379 #define OpalG7231_5k3      GetOpalG7231_5k3()
01380 #define OpalG7231A_6k3     GetOpalG7231A_6k3()
01381 #define OpalG7231A_5k3     GetOpalG7231A_5k3()
01382 #define OpalGSM0610        GetOpalGSM0610()
01383 #define OpalGSMAMR         GetOpalGSMAMR()
01384 #define OpaliLBC           GetOpaliLBC()
01385 #define OpalRFC2833        GetOpalRFC2833()
01386 #define OpalCiscoNSE       GetOpalCiscoNSE()
01387 #define OpalT38            GetOpalT38()
01388 
01389 #define OpalL16Mono8kHz    OpalL16_MONO_8KHZ
01390 #define OpalL16Mono16kHz   OpalL16_MONO_16KHZ
01391 #define OpalG711uLaw       OpalG711_ULAW_64K
01392 #define OpalG711ALaw       OpalG711_ALAW_64K
01393 
01394 #define OPAL_T140             "T.140"
01395 #define OpalT140              GetOpalT140()
01396 extern const OpalMediaFormat & GetOpalT140();
01397 
01398 #if OPAL_HAS_MSRP
01399 #define OPAL_MSRP           "MSRP"
01400 #define OpalMSRP            GetOpalMSRP()
01401 extern const OpalMediaFormat & GetOpalMSRP();
01402 #endif
01403 
01404 #if OPAL_HAS_SIPIM
01405 #define OPAL_SIPIM             "SIP-IM"
01406 #define OpalSIPIM              GetOpalSIPIM()
01407 extern const OpalMediaFormat & GetOpalSIPIM();
01408 #endif
01409 
01410 #ifdef _MSC_VER
01411 #if _MSC_VER < 1300
01412 #pragma warning(default:4663)
01413 #endif
01414 #endif
01415 
01416 #endif  // OPAL_OPAL_MEDIAFMT_H
01417 
01418 
01419 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:19:21 2011 for OPAL by  doxygen 1.4.7