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: 24650 $
00028  * $Author: rjongbloed $
00029  * $Date: 2010-08-12 03:52:20 -0500 (Thu, 12 Aug 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 false; }
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 = false);
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     int                          m_channels;
00629 
00630   friend bool operator==(const char * other, const OpalMediaFormat & fmt);
00631   friend bool operator!=(const char * other, const OpalMediaFormat & fmt);
00632   friend bool operator==(const PString & other, const OpalMediaFormat & fmt);
00633   friend bool operator!=(const PString & other, const OpalMediaFormat & fmt);
00634 
00635   friend class OpalMediaFormat;
00636   friend class OpalMediaFormatList;
00637   friend class OpalAudioFormatInternal;
00638 };
00639 
00640 
00642 
00648 class OpalMediaFormat : public PContainer
00649 {
00650     PCLASSINFO(OpalMediaFormat, PContainer)
00651   public:
00652     OpalMediaFormat(const OpalMediaFormat & c) : PContainer(c), m_info(c.m_info) { }
00653     OpalMediaFormat & operator=(const OpalMediaFormat & c)     { AssignContents(c); return *this; }
00654     virtual ~OpalMediaFormat()                                 { Destruct(); }
00655     virtual PBoolean MakeUnique();
00656   protected:
00657     virtual void DestroyContents();
00658     virtual void AssignContents(const PContainer & c);
00659 
00660   public:
00663     OpalMediaFormat(
00664       OpalMediaFormatInternal * info = NULL
00665     );
00666 
00680     OpalMediaFormat(
00681       const char * fullName,                      
00682       const OpalMediaType & mediaType,            
00683       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00684       const char * encodingName,                  
00685       PBoolean     needsJitter,                   
00686       unsigned bandwidth,                         
00687       PINDEX   frameSize,                         
00688       unsigned frameTime,                         
00689       unsigned clockRate,                         
00690       time_t timeStamp = 0                        
00691     );
00692 
00702     OpalMediaFormat(
00703       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00704       unsigned clockRate,                         
00705       const char * rtpEncodingName = NULL,        
00706       const char * protocol = NULL                
00707     );
00708 
00722     OpalMediaFormat(
00723       const char * wildcard  
00724     );
00725 
00739     OpalMediaFormat(
00740       const PString & wildcard  
00741     );
00742     
00746     OpalMediaFormat & operator=(
00747       RTP_DataFrame::PayloadTypes rtpPayloadType 
00748     );
00749 
00753     OpalMediaFormat & operator=(
00754       const char * wildcard  
00755     );
00756 
00760     OpalMediaFormat & operator=(
00761       const PString & wildcard  
00762     );
00763 
00766     virtual PObject * Clone() const;
00767 
00770     virtual Comparison Compare(const PObject & obj) const;
00771 
00776     virtual void PrintOn(ostream & strm) const;
00777 
00780     virtual void ReadFrom(istream & strm);
00781 
00786     bool ToNormalisedOptions();
00787 
00791     bool ToCustomisedOptions();
00792 
00795     bool Update(
00796       const OpalMediaFormat & mediaFormat
00797     );
00798 
00809     bool Merge(
00810       const OpalMediaFormat & mediaFormat
00811     );
00814     bool ValidateMerge(
00815       const OpalMediaFormat & mediaFormat
00816     ) const;
00817 
00820     PString GetName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
00821 
00826     PBoolean IsValid() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValid(); }
00827 
00831     PBoolean IsTransportable() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsTransportable(); }
00832 
00838     RTP_DataFrame::PayloadTypes GetPayloadType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? RTP_DataFrame::IllegalPayloadType : m_info->rtpPayloadType; }
00839     void SetPayloadType(RTP_DataFrame::PayloadTypes type) { PWaitAndSignal m(m_mutex); MakeUnique(); if (m_info != NULL) m_info->rtpPayloadType = type; }
00840 
00843     const char * GetEncodingName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->rtpEncodingName.GetPointer(); }
00844 
00847     OpalMediaType GetMediaType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? OpalMediaType() : m_info->mediaType; }
00848 
00852     bool NeedsJitterBuffer() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(NeedsJitterOption(), false); }
00853     static const PString & NeedsJitterOption();
00854 
00857     unsigned GetBandwidth() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxBitRateOption(), 0); }
00858     static const PString & MaxBitRateOption();
00859     static const PString & TargetBitRateOption();
00860 
00865     PINDEX GetFrameSize() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxFrameSizeOption(), 0); }
00866     static const PString & MaxFrameSizeOption();
00867 
00871     unsigned GetFrameTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(FrameTimeOption(), 0); }
00872     static const PString & FrameTimeOption();
00873 
00876     unsigned GetTimeUnits() const { return GetClockRate()/1000; }
00877 
00878     enum StandardClockRate {
00879       AudioClockRate = 8000,  
00880       VideoClockRate = 90000  
00881     };
00882 
00885     unsigned GetClockRate() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(ClockRateOption(), 1000); }
00886     static const PString & ClockRateOption();
00887 
00890     static const PString & ProtocolOption();
00891 
00894     static const PString & MaxTxPacketSizeOption();
00895 
00899     PStringToString GetOptions() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? PStringToString() : m_info->GetOptions(); }
00900 
00903     PINDEX GetOptionCount() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->options.GetSize(); }
00904 
00908     const OpalMediaOption & GetOption(
00909       PINDEX index   
00910     ) const { PWaitAndSignal m(m_mutex); return m_info->options[index]; }
00911 
00916     bool GetOptionValue(
00917       const PString & name,   
00918       PString & value         
00919     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionValue(name, value); }
00920 
00927     bool SetOptionValue(
00928       const PString & name,   
00929       const PString & value   
00930     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionValue(name, value); }
00931 
00935     bool GetOptionBoolean(
00936       const PString & name,   
00937       bool dflt = false       
00938     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(name, dflt); }
00939 
00946     bool SetOptionBoolean(
00947       const PString & name,   
00948       bool value              
00949     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionBoolean(name, value); }
00950 
00954     int GetOptionInteger(
00955       const PString & name,   
00956       int dflt = 0            
00957     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionInteger(name, dflt); }
00958 
00966     bool SetOptionInteger(
00967       const PString & name,   
00968       int value               
00969     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionInteger(name, value); }
00970 
00974     double GetOptionReal(
00975       const PString & name,   
00976       double dflt = 0         
00977     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionReal(name, dflt); }
00978 
00985     bool SetOptionReal(
00986       const PString & name,   
00987       double value            
00988     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionReal(name, value); }
00989 
00994     PINDEX GetOptionEnum(
00995       const PString & name,   
00996       PINDEX dflt = 0         
00997     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionEnum(name, dflt); }
00998 
01005     bool SetOptionEnum(
01006       const PString & name,   
01007       PINDEX value            
01008     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionEnum(name, value); }
01009 
01013     PString GetOptionString(
01014       const PString & name,                   
01015       const PString & dflt = PString::Empty() 
01016     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionString(name, dflt); }
01017 
01024     bool SetOptionString(
01025       const PString & name,   
01026       const PString & value   
01027     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionString(name, value); }
01028 
01032     bool GetOptionOctets(
01033       const PString & name, 
01034       PBYTEArray & octets   
01035     ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionOctets(name, octets); }
01036 
01043     bool SetOptionOctets(
01044       const PString & name,       
01045       const PBYTEArray & octets   
01046     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, octets); }
01047     bool SetOptionOctets(
01048       const PString & name,       
01049       const BYTE * data,          
01050       PINDEX length               
01051     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, data, length); }
01052 
01055     static OpalMediaFormatList GetAllRegisteredMediaFormats();
01056     static void GetAllRegisteredMediaFormats(
01057       OpalMediaFormatList & copy    
01058     );
01059 
01063     static bool SetRegisteredMediaFormat(
01064       const OpalMediaFormat & mediaFormat  
01065     );
01066 
01070     bool AddOption(
01071       OpalMediaOption * option,
01072       PBoolean overwrite = false
01073     ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->AddOption(option, overwrite); }
01074 
01078     bool HasOption(const PString & name) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->FindOption(name) != NULL; }
01079 
01084     OpalMediaOption * FindOption(
01085       const PString & name
01086     ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? NULL : m_info->FindOption(name); }
01087 
01093     bool IsValidForProtocol(const PString & protocol) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValidForProtocol(protocol); }
01094 
01095     time_t GetCodecVersionTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->codecVersionTime; }
01096 
01097     ostream & PrintOptions(ostream & strm) const
01098     {
01099       PWaitAndSignal m(m_mutex);
01100       if (m_info != NULL)
01101         strm << setw(-1) << *m_info;
01102       return strm;
01103     }
01104 
01105 #if OPAL_VIDEO
01106 
01108     void AdjustVideoArgs(
01109       PVideoDevice::OpenArgs & args  
01110     ) const;
01111 #endif
01112 
01113     // Backward compatibility
01114     virtual PBoolean IsEmpty() const { PWaitAndSignal m(m_mutex); return m_info == NULL || !m_info->IsValid(); }
01115     operator PString() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
01116     operator const char *() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
01117     bool operator==(const char * other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
01118     bool operator!=(const char * other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
01119     bool operator==(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
01120     bool operator!=(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
01121     bool operator==(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) == EqualTo; }
01122     bool operator!=(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) != EqualTo; }
01123     friend bool operator==(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
01124     friend bool operator!=(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
01125     friend bool operator==(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
01126     friend bool operator!=(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
01127 
01128 #if OPAL_H323
01129     static const PString & MediaPacketizationOption();
01130     static const PString & MediaPacketizationsOption();
01131 #endif
01132 
01133   private:
01134     PBoolean SetSize(PINDEX) { return true; }
01135 
01136   protected:
01137     void Construct(OpalMediaFormatInternal * info);
01138 
01139     OpalMediaFormatInternal * m_info;
01140     PMutex                    m_mutex;
01141 
01142   friend class OpalMediaFormatInternal;
01143   friend class OpalMediaFormatList;
01144 };
01145 
01146 
01147 class OpalAudioFormatInternal : public OpalMediaFormatInternal
01148 {
01149   public:
01150     OpalAudioFormatInternal(
01151       const char * fullName,
01152       RTP_DataFrame::PayloadTypes rtpPayloadType,
01153       const char * encodingName,
01154       PINDEX   frameSize,
01155       unsigned frameTime,
01156       unsigned rxFrames,
01157       unsigned txFrames,
01158       unsigned maxFrames,
01159       unsigned clockRate,
01160       time_t timeStamp
01161     );
01162     virtual PObject * Clone() const;
01163     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
01164 };
01165 
01166 class OpalAudioFormat : public OpalMediaFormat
01167 {
01168     PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
01169   public:
01170     OpalAudioFormat(
01171       OpalMediaFormatInternal * info = NULL
01172     ) : OpalMediaFormat(info) { }
01173     OpalAudioFormat(
01174       const char * fullName,    
01175       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01176       const char * encodingName,
01177       PINDEX   frameSize,       
01178       unsigned frameTime,       
01179       unsigned rxFrames,        
01180       unsigned txFrames,        
01181       unsigned maxFrames = 256, 
01182       unsigned clockRate = 8000, 
01183       time_t timeStamp = 0       
01184     );
01185 
01186     static const PString & RxFramesPerPacketOption();
01187     static const PString & TxFramesPerPacketOption();
01188     static const PString & MaxFramesPerPacketOption();
01189     static const PString & ChannelsOption();
01190 };
01191 
01192 #if OPAL_VIDEO
01193 class OpalVideoFormatInternal : public OpalMediaFormatInternal
01194 {
01195   public:
01196     OpalVideoFormatInternal(
01197       const char * fullName,
01198       RTP_DataFrame::PayloadTypes rtpPayloadType,
01199       const char * encodingName,
01200       unsigned maxFrameWidth,
01201       unsigned maxFrameHeight,
01202       unsigned maxFrameRate,
01203       unsigned maxBitRate,
01204       time_t timeStamp
01205     );
01206     virtual PObject * Clone() const;
01207     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
01208 };
01209 
01210 
01211 class OpalVideoFormat : public OpalMediaFormat
01212 {
01213     PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
01214   public:
01215     OpalVideoFormat(
01216       OpalMediaFormatInternal * info = NULL
01217     ) : OpalMediaFormat(info) { }
01218     OpalVideoFormat(
01219       const char * fullName,    
01220       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01221       const char * encodingName,
01222       unsigned maxFrameWidth,   
01223       unsigned maxFrameHeight,  
01224       unsigned maxFrameRate,    
01225       unsigned maxBitRate,      
01226       time_t timeStamp = 0      
01227     );
01228 
01229     static const PString & FrameWidthOption();
01230     static const PString & FrameHeightOption();
01231     static const PString & MinRxFrameWidthOption();
01232     static const PString & MinRxFrameHeightOption();
01233     static const PString & MaxRxFrameWidthOption();
01234     static const PString & MaxRxFrameHeightOption();
01235     static const PString & TemporalSpatialTradeOffOption();
01236     static const PString & TxKeyFramePeriodOption();
01237     static const PString & RateControlEnableOption();
01238     static const PString & RateControllerOption();
01239     static const PString & RateControllerBitRateScalerOption();
01240 
01251     enum ContentRole {
01252       eNoRole,
01253       ePresentation,
01254       eMainRole,
01255       eSpeaker,
01256       eSignLanguage,
01257       eNumRoles
01258     };
01259     enum { ContentRoleMask = 15 };
01260     __inline static unsigned ContentRoleBit(ContentRole contentRole) { return contentRole != eNoRole ? (1<<(contentRole-1)) : 0; }
01261     static const PString & ContentRoleOption();
01262     static const PString & ContentRoleMaskOption();
01263 };
01264 #endif
01265 
01266 // List of known media formats
01267 
01268 #define OPAL_PCM16          "PCM-16"
01269 #define OPAL_PCM16S         "PCM-16S"
01270 #define OPAL_PCM16_16KHZ    "PCM-16-16kHz"
01271 #define OPAL_PCM16S_16KHZ   "PCM-16S-16kHz"
01272 #define OPAL_PCM16_32KHZ    "PCM-16-32kHz"
01273 #define OPAL_PCM16S_32KHZ   "PCM-16S-32kHz"
01274 #define OPAL_PCM16_48KHZ    "PCM-16-48kHz"
01275 #define OPAL_PCM16S_48KHZ   "PCM-16S-48kHz"
01276 #define OPAL_L16_MONO_8KHZ  "Linear-16-Mono-8kHz"
01277 #define OPAL_L16_STEREO_8KHZ "Linear-16-Stereo-8kHz"
01278 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
01279 #define OPAL_L16_STEREO_16KHZ "Linear-16-Stereo-16kHz"
01280 #define OPAL_L16_MONO_32KHZ "Linear-16-Mono-32kHz"
01281 #define OPAL_L16_STEREO_32KHZ "Linear-16-Stereo-32kHz"
01282 #define OPAL_L16_MONO_48KHZ "Linear-16-Mono-48kHz"
01283 #define OPAL_L16_STEREO_48KHZ "Linear-16-Stereo-48kHz"
01284 #define OPAL_G711_ULAW_64K  "G.711-uLaw-64k"
01285 #define OPAL_G711_ALAW_64K  "G.711-ALaw-64k"
01286 #define OPAL_G722           "G.722"
01287 #define OPAL_G7221          "G.722.1"
01288 #define OPAL_G7222          "G.722.2"
01289 #define OPAL_G726_40K       "G.726-40K"
01290 #define OPAL_G726_32K       "G.726-32K"
01291 #define OPAL_G726_24K       "G.726-24K"
01292 #define OPAL_G726_16K       "G.726-16K"
01293 #define OPAL_G728           "G.728"
01294 #define OPAL_G729           "G.729"
01295 #define OPAL_G729A          "G.729A"
01296 #define OPAL_G729B          "G.729B"
01297 #define OPAL_G729AB         "G.729A/B"
01298 #define OPAL_G7231          "G.723.1"
01299 #define OPAL_G7231_6k3      OPAL_G7231
01300 #define OPAL_G7231_5k3      "G.723.1(5.3k)"
01301 #define OPAL_G7231A_6k3     "G.723.1A(6.3k)"
01302 #define OPAL_G7231A_5k3     "G.723.1A(5.3k)"
01303 #define OPAL_GSM0610        "GSM-06.10"
01304 #define OPAL_GSMAMR         "GSM-AMR"
01305 #define OPAL_iLBC           "iLBC"
01306 #define OPAL_H261           "H.261"
01307 #define OPAL_H263           "H.263"
01308 #define OPAL_H264_MODE0     "H.264-0"
01309 #define OPAL_H264_MODE1     "H.264-1"
01310 #define OPAL_MPEG4          "MPEG4"
01311 #define OPAL_RFC2833        "UserInput/RFC2833"
01312 #define OPAL_CISCONSE       "NamedSignalEvent"
01313 #define OPAL_T38            "T.38"
01314 
01315 extern const OpalAudioFormat & GetOpalPCM16();
01316 extern const OpalAudioFormat & GetOpalPCM16S();
01317 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
01318 extern const OpalAudioFormat & GetOpalPCM16S_16KHZ();
01319 extern const OpalAudioFormat & GetOpalPCM16_32KHZ();
01320 extern const OpalAudioFormat & GetOpalPCM16S_32KHZ();
01321 extern const OpalAudioFormat & GetOpalPCM16_48KHZ();
01322 extern const OpalAudioFormat & GetOpalPCM16S_48KHZ();
01323 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
01324 extern const OpalAudioFormat & GetOpalL16_STEREO_8KHZ();
01325 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
01326 extern const OpalAudioFormat & GetOpalL16_STEREO_16KHZ();
01327 extern const OpalAudioFormat & GetOpalL16_MONO_32KHZ();
01328 extern const OpalAudioFormat & GetOpalL16_STEREO_32KHZ();
01329 extern const OpalAudioFormat & GetOpalL16_MONO_48KHZ();
01330 extern const OpalAudioFormat & GetOpalL16_STEREO_48KHZ();
01331 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
01332 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
01333 extern const OpalAudioFormat & GetOpalG722();
01334 extern const OpalAudioFormat & GetOpalG7221();
01335 extern const OpalAudioFormat & GetOpalG7222();
01336 extern const OpalAudioFormat & GetOpalG726_40K();
01337 extern const OpalAudioFormat & GetOpalG726_32K();
01338 extern const OpalAudioFormat & GetOpalG726_24K();
01339 extern const OpalAudioFormat & GetOpalG726_16K();
01340 extern const OpalAudioFormat & GetOpalG728();
01341 extern const OpalAudioFormat & GetOpalG729();
01342 extern const OpalAudioFormat & GetOpalG729A();
01343 extern const OpalAudioFormat & GetOpalG729B();
01344 extern const OpalAudioFormat & GetOpalG729AB();
01345 extern const OpalAudioFormat & GetOpalG7231_6k3();
01346 extern const OpalAudioFormat & GetOpalG7231_5k3();
01347 extern const OpalAudioFormat & GetOpalG7231A_6k3();
01348 extern const OpalAudioFormat & GetOpalG7231A_5k3();
01349 extern const OpalAudioFormat & GetOpalGSM0610();
01350 extern const OpalAudioFormat & GetOpalGSMAMR();
01351 extern const OpalAudioFormat & GetOpaliLBC();
01352 
01353 extern const OpalMediaFormat & GetOpalRFC2833();
01354 
01355 #if OPAL_T38_CAPABILITY
01356 extern const OpalMediaFormat & GetOpalCiscoNSE();
01357 extern const OpalMediaFormat & GetOpalT38();
01358 #endif
01359 
01360 
01361 #define OpalPCM16          GetOpalPCM16()
01362 #define OpalPCM16S         GetOpalPCM16S()
01363 #define OpalPCM16_16KHZ    GetOpalPCM16_16KHZ()
01364 #define OpalPCM16S_16KHZ   GetOpalPCM16S_16KHZ()
01365 #define OpalPCM16_32KHZ    GetOpalPCM16_32KHZ()
01366 #define OpalPCM16S_32KHZ   GetOpalPCM16S_32KHZ()
01367 #define OpalPCM16_48KHZ    GetOpalPCM16_48KHZ()
01368 #define OpalPCM16S_48KHZ   GetOpalPCM16S_48KHZ()
01369 #define OpalL16_MONO_8KHZ  GetOpalL16_MONO_8KHZ()
01370 #define OpalL16_STEREO_8KHZ GetOpalL16_STEREO_8KHZ()
01371 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
01372 #define OpalL16_STEREO_16KHZ GetOpalL16_STEREO_16KHZ()
01373 #define OpalL16_MONO_32KHZ GetOpalL16_MONO_32KHZ()
01374 #define OpalL16_STEREO_32KHZ GetOpalL16_STEREO_32KHZ()
01375 #define OpalL16_MONO_48KHZ GetOpalL16_MONO_48KHZ()
01376 #define OpalL16_STEREO_48KHZ GetOpalL16_STEREO_48KHZ()
01377 #define OpalG711_ULAW_64K  GetOpalG711_ULAW_64K()
01378 #define OpalG711_ALAW_64K  GetOpalG711_ALAW_64K()
01379 #define OpalG722           GetOpalG722()
01380 #define OpalG7221          GetOpalG7221()
01381 #define OpalG7222          GetOpalG7222()
01382 #define OpalG726_40K       GetOpalG726_40K()
01383 #define OpalG726_32K       GetOpalG726_32K()
01384 #define OpalG726_24K       GetOpalG726_24K()
01385 #define OpalG726_16K       GetOpalG726_16K()
01386 #define OpalG728           GetOpalG728()
01387 #define OpalG729           GetOpalG729()
01388 #define OpalG729A          GetOpalG729A()
01389 #define OpalG729B          GetOpalG729B()
01390 #define OpalG729AB         GetOpalG729AB()
01391 #define OpalG7231_6k3      GetOpalG7231_6k3()
01392 #define OpalG7231_5k3      GetOpalG7231_5k3()
01393 #define OpalG7231A_6k3     GetOpalG7231A_6k3()
01394 #define OpalG7231A_5k3     GetOpalG7231A_5k3()
01395 #define OpalGSM0610        GetOpalGSM0610()
01396 #define OpalGSMAMR         GetOpalGSMAMR()
01397 #define OpaliLBC           GetOpaliLBC()
01398 #define OpalRFC2833        GetOpalRFC2833()
01399 #define OpalCiscoNSE       GetOpalCiscoNSE()
01400 #define OpalT38            GetOpalT38()
01401 
01402 #define OpalL16Mono8kHz    OpalL16_MONO_8KHZ
01403 #define OpalL16Mono16kHz   OpalL16_MONO_16KHZ
01404 #define OpalG711uLaw       OpalG711_ULAW_64K
01405 #define OpalG711ALaw       OpalG711_ALAW_64K
01406 
01407 #define OPAL_T140             "T.140"
01408 #define OpalT140              GetOpalT140()
01409 extern const OpalMediaFormat & GetOpalT140();
01410 
01411 #if OPAL_HAS_MSRP
01412 #define OPAL_MSRP           "MSRP"
01413 #define OpalMSRP            GetOpalMSRP()
01414 extern const OpalMediaFormat & GetOpalMSRP();
01415 #endif
01416 
01417 #if OPAL_HAS_SIPIM
01418 #define OPAL_SIPIM             "SIP-IM"
01419 #define OpalSIPIM              GetOpalSIPIM()
01420 extern const OpalMediaFormat & GetOpalSIPIM();
01421 #endif
01422 
01423 #ifdef _MSC_VER
01424 #if _MSC_VER < 1300
01425 #pragma warning(default:4663)
01426 #endif
01427 #endif
01428 
01429 #endif  // OPAL_OPAL_MEDIAFMT_H
01430 
01431 
01432 // End of File ///////////////////////////////////////////////////////////////

Generated on Sun Nov 21 20:20:50 2010 for OPAL by  doxygen 1.4.7