# 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: 21004 $
    00028  * $Author: rjongbloed $
    00029  * $Date: 2008-09-16 07:08:56 +0000 (Tue, 16 Sep 2008) $
    00030  */
    00031
    00032 #ifndef __OPAL_MEDIAFMT_H
    00033 #define __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
    00049 #include <rtp/rtp.h>
    00050
    00051 #include <limits>
    00052
    00053 #ifdef min
    00054 #undef min
    00055 #endif
    00056 #ifdef max
    00057 #undef max
    00058 #endif
    00059
    00060 class OpalMediaFormat;
    00061
    00062
    00064
    00065 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
    00066
    00069 class OpalMediaFormatList : public OpalMediaFormatBaseList
    00070 {
    00071   PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
    00072   public:
    00077     OpalMediaFormatList();
    00078
    00081     OpalMediaFormatList(
    00082       const OpalMediaFormat & format
    00083     );
    00084
    00087     OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
    00089
    00095     OpalMediaFormatList & operator+=(
    00096       const OpalMediaFormat & format
    00097     );
    00098
    00102     OpalMediaFormatList & operator+=(
    00103       const OpalMediaFormatList & formats
    00104     );
    00105
    00109     OpalMediaFormatList & operator-=(
    00110       const OpalMediaFormat & format
    00111     );
    00112
    00116     OpalMediaFormatList & operator-=(
    00117       const OpalMediaFormatList & formats
    00118     );
    00119
    00124     const_iterator FindFormat(
    00125       RTP_DataFrame::PayloadTypes rtpPayloadType,
    00126       const unsigned clockRate,
    00127       const char * rtpEncodingName = NULL,
    00128       const char * protocol = NULL
    00129     ) const;
    00130
    00138     const_iterator FindFormat(
    00139       const PString & wildcard,
    00140       const_iterator start = const_iterator()
    00141     ) const;
    00142
    00145     PBoolean HasFormat(
    00146       RTP_DataFrame::PayloadTypes rtpPayloadType
    00147     ) const { return FindFormat(rtpPayloadType) != end(); }
    00148
    00154     PBoolean HasFormat(
    00155       const PString & wildcard
    00156     ) const { return FindFormat(wildcard) != end(); }
    00157
    00160     void Remove(
    00161       const PStringArray & mask
    00162     );
    00163
    00168     void Reorder(
    00169       const PStringArray & order
    00170     );
    00172
    00173   private:
    00174     virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
    00175     virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
    00176     virtual PINDEX InsertAt(PINDEX, PObject *) { return P_MAX_INDEX; }
    00177     virtual PBoolean SetAt(PINDEX, PObject *) { return PFalse; }
    00178 };
    00179
    00180
    00182
    00185 class OpalMediaOption : public PObject
    00186 {
    00187     PCLASSINFO(OpalMediaOption, PObject);
    00188   public:
    00189     enum MergeType {
    00190       NoMerge,
    00191       MinMerge,
    00192       MaxMerge,
    00193       EqualMerge,
    00194       NotEqualMerge,
    00195       AlwaysMerge,
    00196
    00197       // Synonyms
    00198       AndMerge = MinMerge,
    00199       OrMerge  = MaxMerge
    00200     };
    00201
    00202   protected:
    00203     OpalMediaOption(
    00204       const PString & name
    00205     );
    00206     OpalMediaOption(
    00207       const char * name,
    00208       bool readOnly,
    00209       MergeType merge
    00210     );
    00211
    00212   public:
    00213     virtual Comparison Compare(const PObject & obj) const;
    00214
    00215     virtual bool Merge(
    00216       const OpalMediaOption & option
    00217     );
    00218     virtual Comparison CompareValue(
    00219       const OpalMediaOption & option
    00220     ) const = 0;
    00221     virtual void Assign(
    00222       const OpalMediaOption & option
    00223     ) = 0;
    00224
    00225     PString AsString() const;
    00226     bool FromString(const PString & value);
    00227
    00228     const PString & GetName() const { return m_name; }
    00229
    00230     bool IsReadOnly() const { return m_readOnly; }
    00231     void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
    00232
    00233     MergeType GetMerge() const { return m_merge; }
    00234     void SetMerge(MergeType merge) { m_merge = merge; }
    00235
    00236 #if OPAL_SIP
    00237     const PString & GetFMTPName() const { return m_FMTPName; }
    00238     void SetFMTPName(const char * name) { m_FMTPName = name; }
    00239
    00240     const PString & GetFMTPDefault() const { return m_FMTPDefault; }
    00241     void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
    00242 #endif // OPAL_SIP
    00243
    00244 #if OPAL_H323
    00245     struct H245GenericInfo {
    00246       H245GenericInfo() { memset(this, 0, sizeof(*this)); }
    00247       unsigned ordinal:16;
    00248       enum Modes {
    00249         None,
    00250         Collapsing,
    00251         NonCollapsing
    00252       } mode:3;
    00253       enum IntegerTypes {
    00254         UnsignedInt,
    00255         Unsigned32,
    00256         BooleanArray
    00257       } integerType:3;
    00258       bool excludeTCS:1;
    00259       bool excludeOLC:1;
    00260       bool excludeReqMode:1;
    00261     };
    00262
    00263     const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
    00264     void SetH245Generic(const H245GenericInfo & generic) { m_H245Generic = generic; }
    00265 #endif // OPAL_H323
    00266
    00267   protected:
    00268     PCaselessString m_name;
    00269     bool            m_readOnly;
    00270     MergeType       m_merge;
    00271
    00272 #if OPAL_SIP
    00273     PCaselessString m_FMTPName;
    00274     PString         m_FMTPDefault;
    00275 #endif // OPAL_SIP
    00276
    00277 #if OPAL_H323
    00278     H245GenericInfo m_H245Generic;
    00279 #endif // OPAL_H323
    00280 };
    00281
    00282
    00283 template <typename T>
    00284 class OpalMediaOptionValue : public OpalMediaOption
    00285 {
    00286     PCLASSINFO(OpalMediaOptionValue, OpalMediaOption);
    00287   public:
    00288     OpalMediaOptionValue(
    00289       const char * name,
    00290       bool readOnly,
    00291       MergeType merge = MinMerge,
    00292       T value = 0,
    00293       T minimum = std::numeric_limits<T>::min(),
    00294       T maximum = std::numeric_limits<T>::max()
    00295     ) : OpalMediaOption(name, readOnly, merge),
    00296         m_value(value),
    00297         m_minimum(minimum),
    00298         m_maximum(maximum)
    00299     { }
    00300
    00301     virtual PObject * Clone() const
    00302     {
    00303       return new OpalMediaOptionValue(*this);
    00304     }
    00305
    00306     virtual void PrintOn(ostream & strm) const
    00307     {
    00308       strm << m_value;
    00309     }
    00310
    00311     virtual void ReadFrom(istream & strm)
    00312     {
    00313       T temp;
    00314       strm >> temp;
    00315       if (temp >= m_minimum && temp <= m_maximum)
    00316         m_value = temp;
    00317       else
    00318         strm.setstate(ios::badbit);
    00319     }
    00320
    00321     virtual Comparison CompareValue(const OpalMediaOption & option) const
    00322     {
    00323       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
    00324       if (otherOption == NULL)
    00325         return GreaterThan;
    00326       if (m_value < otherOption->m_value)
    00327         return LessThan;
    00328       if (m_value > otherOption->m_value)
    00329         return GreaterThan;
    00330       return EqualTo;
    00331     }
    00332
    00333     virtual void Assign(
    00334       const OpalMediaOption & option
    00335     ) {
    00336       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
    00337       if (otherOption != NULL)
    00338         m_value = otherOption->m_value;
    00339     }
    00340
    00341     T GetValue() const
    00342     {
    00343       return m_value;
    00344     }
    00345
    00346     void SetValue(T value)
    00347     {
    00348       if (value < m_minimum)
    00349         m_value = m_minimum;
    00350       else if (value > m_maximum)
    00351         m_value = m_maximum;
    00352       else
    00353         m_value = value;
    00354     }
    00355
    00356     void SetMinimum(T m)
    00357     {
    00358       m_minimum = m;
    00359     }
    00360
    00361     void SetMaximum(T m)
    00362     {
    00363       m_maximum = m;
    00364     }
    00365
    00366   protected:
    00367     T m_value;
    00368     T m_minimum;
    00369     T m_maximum;
    00370 };
    00371
    00372
    00373 typedef OpalMediaOptionValue<bool>     OpalMediaOptionBoolean;
    00374 typedef OpalMediaOptionValue<int>      OpalMediaOptionInteger;
    00375 typedef OpalMediaOptionValue<unsigned> OpalMediaOptionUnsigned;
    00376 typedef OpalMediaOptionValue<double>   OpalMediaOptionReal;
    00377
    00378
    00379 class OpalMediaOptionEnum : public OpalMediaOption
    00380 {
    00381     PCLASSINFO(OpalMediaOptionEnum, OpalMediaOption);
    00382   public:
    00383     OpalMediaOptionEnum(
    00384       const char * name,
    00385       bool readOnly
    00386     );
    00387     OpalMediaOptionEnum(
    00388       const char * name,
    00389       bool readOnly,
    00390       const char * const * enumerations,
    00391       PINDEX count,
    00392       MergeType merge = EqualMerge,
    00393       PINDEX value = 0
    00394     );
    00395
    00396     virtual PObject * Clone() const;
    00397     virtual void PrintOn(ostream & strm) const;
    00398     virtual void ReadFrom(istream & strm);
    00399
    00400     virtual Comparison CompareValue(const OpalMediaOption & option) const;
    00401     virtual void Assign(const OpalMediaOption & option);
    00402
    00403     PINDEX GetValue() const { return m_value; }
    00404     void SetValue(PINDEX value);
    00405
    00406     void SetEnumerations(const PStringArray & e)
    00407     {
    00408       m_enumerations = e;
    00409     }
    00410
    00411   protected:
    00412     PStringArray m_enumerations;
    00413     PINDEX       m_value;
    00414 };
    00415
    00416
    00417 class OpalMediaOptionString : public OpalMediaOption
    00418 {
    00419     PCLASSINFO(OpalMediaOptionString, OpalMediaOption);
    00420   public:
    00421     OpalMediaOptionString(
    00422       const char * name,
    00423       bool readOnly
    00424     );
    00425     OpalMediaOptionString(
    00426       const char * name,
    00427       bool readOnly,
    00428       const PString & value
    00429     );
    00430
    00431     virtual PObject * Clone() const;
    00432     virtual void PrintOn(ostream & strm) const;
    00433     virtual void ReadFrom(istream & strm);
    00434
    00435     virtual Comparison CompareValue(const OpalMediaOption & option) const;
    00436     virtual void Assign(const OpalMediaOption & option);
    00437
    00438     const PString & GetValue() const { return m_value; }
    00439     void SetValue(const PString & value);
    00440
    00441   protected:
    00442     PString m_value;
    00443 };
    00444
    00445
    00446 class OpalMediaOptionOctets : public OpalMediaOption
    00447 {
    00448     PCLASSINFO(OpalMediaOptionOctets, OpalMediaOption);
    00449   public:
    00450     OpalMediaOptionOctets(
    00451       const char * name,
    00452       bool readOnly,
    00453       bool base64 = false
    00454     );
    00455     OpalMediaOptionOctets(
    00456       const char * name,
    00457       bool readOnly,
    00458       bool base64,
    00459       const PBYTEArray & value
    00460     );
    00461     OpalMediaOptionOctets(
    00462       const char * name,
    00463       bool readOnly,
    00464       bool base64,
    00465       const BYTE * data,
    00466       PINDEX length
    00467     );
    00468
    00469     virtual PObject * Clone() const;
    00470     virtual void PrintOn(ostream & strm) const;
    00471     virtual void ReadFrom(istream & strm);
    00472
    00473     virtual Comparison CompareValue(const OpalMediaOption & option) const;
    00474     virtual void Assign(const OpalMediaOption & option);
    00475
    00476     const PBYTEArray & GetValue() const { return m_value; }
    00477     void SetValue(const PBYTEArray & value);
    00478     void SetValue(const BYTE * data, PINDEX length);
    00479
    00480     void SetBase64(bool b)
    00481     {
    00482       m_base64 = b;
    00483     }
    00484
    00485   protected:
    00486     PBYTEArray m_value;
    00487     bool       m_base64;
    00488 };
    00489
    00490
    00492
    00493 class OpalMediaFormatInternal : public PObject
    00494 {
    00495     PCLASSINFO(OpalMediaFormatInternal, PObject);
    00496   public:
    00497     OpalMediaFormatInternal(
    00498       const char * fullName,
    00499       const OpalMediaType & mediaType,
    00500       RTP_DataFrame::PayloadTypes rtpPayloadType,
    00501       const char * encodingName,
    00502       PBoolean     needsJitter,
    00503       unsigned bandwidth,
    00504       PINDEX   frameSize,
    00505       unsigned frameTime,
    00506       unsigned clockRate,
    00507       time_t timeStamp
    00508     );
    00509
    00510     virtual PObject * Clone() const;
    00511     virtual void PrintOn(ostream & strm) const;
    00512
    00513     virtual PBoolean IsValid() const { return rtpPayloadType < RTP_DataFrame::IllegalPayloadType && !formatName.IsEmpty(); }
    00514     virtual PBoolean IsTransportable() const { return rtpPayloadType < RTP_DataFrame::MaxPayloadType && !rtpEncodingName.IsEmpty(); }
    00515
    00516     virtual PStringToString GetOptions() const;
    00517     virtual bool GetOptionValue(const PString & name, PString & value) const;
    00518     virtual bool SetOptionValue(const PString & name, const PString & value);
    00519     virtual bool GetOptionBoolean(const PString & name, bool dflt) const;
    00520     virtual bool SetOptionBoolean(const PString & name, bool value);
    00521     virtual int GetOptionInteger(const PString & name, int dflt) const;
    00522     virtual bool SetOptionInteger(const PString & name, int value);
    00523     virtual double GetOptionReal(const PString & name, double dflt) const;
    00524     virtual bool SetOptionReal(const PString & name, double value);
    00525     virtual PINDEX GetOptionEnum(const PString & name, PINDEX dflt) const;
    00526     virtual bool SetOptionEnum(const PString & name, PINDEX value);
    00527     virtual PString GetOptionString(const PString & name, const PString & dflt) const;
    00528     virtual bool SetOptionString(const PString & name, const PString & value);
    00529     virtual bool GetOptionOctets(const PString & name, PBYTEArray & octets) const;
    00530     virtual bool SetOptionOctets(const PString & name, const PBYTEArray & octets);
    00531     virtual bool SetOptionOctets(const PString & name, const BYTE * data, PINDEX length);
    00532     virtual bool AddOption(OpalMediaOption * option, PBoolean overwrite = PFalse);
    00533     virtual OpalMediaOption * FindOption(const PString & name) const;
    00534
    00535     virtual bool ToNormalisedOptions();
    00536     virtual bool ToCustomisedOptions();
    00537     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
    00538     virtual bool IsValidForProtocol(const PString & protocol) const;
    00539
    00540   protected:
    00541     PCaselessString              formatName;
    00542     RTP_DataFrame::PayloadTypes  rtpPayloadType;
    00543     PString                      rtpEncodingName;
    00544     OpalMediaType                mediaType;
    00545     PMutex                       media_format_mutex;
    00546     PSortedList<OpalMediaOption> options;
    00547     time_t                       codecVersionTime;
    00548
    00549   friend bool operator==(const char * other, const OpalMediaFormat & fmt);
    00550   friend bool operator!=(const char * other, const OpalMediaFormat & fmt);
    00551   friend bool operator==(const PString & other, const OpalMediaFormat & fmt);
    00552   friend bool operator!=(const PString & other, const OpalMediaFormat & fmt);
    00553
    00554   friend class OpalMediaFormat;
    00555   friend class OpalMediaFormatList;
    00556   friend class OpalAudioFormatInternal;
    00557 };
    00558
    00559
    00561
    00567 class OpalMediaFormat : public PContainer
    00568 {
    00569   PCONTAINERINFO(OpalMediaFormat, PContainer);
    00570
    00571   public:
    00574     OpalMediaFormat(
    00575       OpalMediaFormatInternal * info = NULL
    00576     );
    00577
    00591     OpalMediaFormat(
    00592       const char * fullName,
    00593       const OpalMediaType & mediaType,
    00594       RTP_DataFrame::PayloadTypes rtpPayloadType,
    00595       const char * encodingName,
    00596       PBoolean     needsJitter,
    00597       unsigned bandwidth,
    00598       PINDEX   frameSize,
    00599       unsigned frameTime,
    00600       unsigned clockRate,
    00601       time_t timeStamp = 0
    00602     );
    00603
    00613     OpalMediaFormat(
    00614       RTP_DataFrame::PayloadTypes rtpPayloadType,
    00615       unsigned clockRate,
    00616       const char * rtpEncodingName = NULL,
    00617       const char * protocol = NULL
    00618     );
    00619
    00633     OpalMediaFormat(
    00634       const char * wildcard
    00635     );
    00636
    00650     OpalMediaFormat(
    00651       const PString & wildcard
    00652     );
    00653
    00657     OpalMediaFormat & operator=(
    00658       RTP_DataFrame::PayloadTypes rtpPayloadType
    00659     );
    00660
    00664     OpalMediaFormat & operator=(
    00665       const char * wildcard
    00666     );
    00667
    00671     OpalMediaFormat & operator=(
    00672       const PString & wildcard
    00673     );
    00674
    00677     virtual PObject * Clone() const;
    00678
    00681     virtual Comparison Compare(const PObject & obj) const;
    00682
    00687     virtual void PrintOn(ostream & strm) const;
    00688
    00691     virtual void ReadFrom(istream & strm);
    00692
    00697     bool ToNormalisedOptions();
    00698
    00702     bool ToCustomisedOptions();
    00703
    00714     bool Merge(
    00715       const OpalMediaFormat & mediaFormat
    00716     );
    00717
    00720     PString GetName() const { PWaitAndSignal m(_mutex); return m_info == NULL ? "" : m_info->formatName; }
    00721
    00726     PBoolean IsValid() const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->IsValid(); }
    00727
    00731     PBoolean IsTransportable() const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->IsTransportable(); }
    00732
    00738     RTP_DataFrame::PayloadTypes GetPayloadType() const { PWaitAndSignal m(_mutex); return m_info == NULL ? RTP_DataFrame::IllegalPayloadType : m_info->rtpPayloadType; }
    00739     void SetPayloadType(RTP_DataFrame::PayloadTypes type) { PWaitAndSignal m(_mutex); MakeUnique(); if (m_info != NULL) m_info->rtpPayloadType = type; }
    00740
    00743     const char * GetEncodingName() const { PWaitAndSignal m(_mutex); return m_info == NULL ? "" : m_info->rtpEncodingName.GetPointer(); }
    00744
    00745     enum {
    00746       DefaultAudioSessionID = 1,
    00747       DefaultVideoSessionID = 2,
    00748       DefaultDataSessionID  = 3,
    00749       DefaultH224SessionID  = 4
    00750     };
    00751
    00754     unsigned GetDefaultSessionID() const {
    00755       PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : OpalMediaTypeDefinition::GetDefaultSessionId(m_info->mediaType);
    00756     }
    00757
    00760     OpalMediaType GetMediaType() const { PWaitAndSignal m(_mutex); return m_info == NULL ? OpalMediaType() : m_info->mediaType; }
    00761
    00765     bool NeedsJitterBuffer() const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->GetOptionBoolean(NeedsJitterOption(), PFalse); }
    00766     static const PString & NeedsJitterOption();
    00767
    00770     unsigned GetBandwidth() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxBitRateOption(), 0); }
    00771     static const PString & MaxBitRateOption();
    00772     static const PString & TargetBitRateOption();
    00773
    00778     PINDEX GetFrameSize() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxFrameSizeOption(), 0); }
    00779     static const PString & MaxFrameSizeOption();
    00780
    00784     unsigned GetFrameTime() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(FrameTimeOption(), 0); }
    00785     static const PString & FrameTimeOption();
    00786
    00789     unsigned GetTimeUnits() const { return GetClockRate()/1000; }
    00790
    00791     enum StandardClockRate {
    00792       AudioClockRate = 8000,
    00793       VideoClockRate = 90000
    00794     };
    00795
    00798     unsigned GetClockRate() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(ClockRateOption(), 1000); }
    00799     static const PString & ClockRateOption();
    00800
    00804     PStringToString GetOptions() const { PWaitAndSignal m(_mutex); return m_info == NULL ? PStringToString() : m_info->GetOptions(); }
    00805
    00808     PINDEX GetOptionCount() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->options.GetSize(); }
    00809
    00813     const OpalMediaOption & GetOption(
    00814       PINDEX index
    00815     ) const { PWaitAndSignal m(_mutex); return m_info->options[index]; }
    00816
    00821     bool GetOptionValue(
    00822       const PString & name,
    00823       PString & value
    00824     ) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->GetOptionValue(name, value); }
    00825
    00832     bool SetOptionValue(
    00833       const PString & name,
    00834       const PString & value
    00835     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionValue(name, value); }
    00836
    00840     bool GetOptionBoolean(
    00841       const PString & name,
    00842       bool dflt = PFalse
    00843     ) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->GetOptionBoolean(name, dflt); }
    00844
    00851     bool SetOptionBoolean(
    00852       const PString & name,
    00853       bool value
    00854     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionBoolean(name, value); }
    00855
    00859     int GetOptionInteger(
    00860       const PString & name,
    00861       int dflt = 0
    00862     ) const { PWaitAndSignal m(_mutex); return m_info == NULL ? dflt : m_info->GetOptionInteger(name, dflt); }
    00863
    00871     bool SetOptionInteger(
    00872       const PString & name,
    00873       int value
    00874     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionInteger(name, value); }
    00875
    00879     double GetOptionReal(
    00880       const PString & name,
    00881       double dflt = 0
    00882     ) const { PWaitAndSignal m(_mutex); return m_info == NULL ? dflt : m_info->GetOptionReal(name, dflt); }
    00883
    00890     bool SetOptionReal(
    00891       const PString & name,
    00892       double value
    00893     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionReal(name, value); }
    00894
    00899     PINDEX GetOptionEnum(
    00900       const PString & name,
    00901       PINDEX dflt = 0
    00902     ) const { PWaitAndSignal m(_mutex); return m_info == NULL ? dflt : m_info->GetOptionEnum(name, dflt); }
    00903
    00910     bool SetOptionEnum(
    00911       const PString & name,
    00912       PINDEX value
    00913     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionEnum(name, value); }
    00914
    00918     PString GetOptionString(
    00919       const PString & name,
    00920       const PString & dflt = PString::Empty()
    00921     ) const { PWaitAndSignal m(_mutex); return m_info == NULL ? dflt : m_info->GetOptionString(name, dflt); }
    00922
    00929     bool SetOptionString(
    00930       const PString & name,
    00931       const PString & value
    00932     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionString(name, value); }
    00933
    00937     bool GetOptionOctets(
    00938       const PString & name,
    00939       PBYTEArray & octets
    00940     ) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->GetOptionOctets(name, octets); }
    00941
    00948     bool SetOptionOctets(
    00949       const PString & name,
    00950       const PBYTEArray & octets
    00951     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, octets); }
    00952     bool SetOptionOctets(
    00953       const PString & name,
    00954       const BYTE * data,
    00955       PINDEX length
    00956     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, data, length); }
    00957
    00960     static OpalMediaFormatList GetAllRegisteredMediaFormats();
    00961     static void GetAllRegisteredMediaFormats(
    00962       OpalMediaFormatList & copy
    00963     );
    00964
    00968     static bool SetRegisteredMediaFormat(
    00969       const OpalMediaFormat & mediaFormat
    00970     );
    00971
    00975     bool AddOption(
    00976       OpalMediaOption * option,
    00977       PBoolean overwrite = PFalse
    00978     ) { PWaitAndSignal m(_mutex); MakeUnique(); return m_info != NULL && m_info->AddOption(option, overwrite); }
    00979
    00983     bool HasOption(const PString & name) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->FindOption(name) != NULL; }
    00984
    00989     OpalMediaOption * FindOption(
    00990       const PString & name
    00991     ) const { PWaitAndSignal m(_mutex); return m_info == NULL ? NULL : m_info->FindOption(name); }
    00992
    00998     bool IsValidForProtocol(const PString & protocol) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->IsValidForProtocol(protocol); }
    00999
    01000     time_t GetCodecVersionTime() const { PWaitAndSignal m(_mutex); return m_info == NULL ? 0 : m_info->codecVersionTime; }
    01001
    01002     ostream & PrintOptions(ostream & strm) const
    01003     {
    01004       PWaitAndSignal m(_mutex);
    01005       if (m_info != NULL)
    01006         strm << setw(-1) << *m_info;
    01007       return strm;
    01008     }
    01009
    01010     // Backward compatibility
    01011     virtual PBoolean IsEmpty() const { PWaitAndSignal m(_mutex); return m_info == NULL || !m_info->IsValid(); }
    01012     operator PString() const { PWaitAndSignal m(_mutex); return m_info == NULL ? "" : m_info->formatName; }
    01013     operator const char *() const { PWaitAndSignal m(_mutex); return m_info == NULL ? "" : m_info->formatName; }
    01014     bool operator==(const char * other) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->formatName == other; }
    01015     bool operator!=(const char * other) const { PWaitAndSignal m(_mutex); return m_info == NULL || m_info->formatName == other; }
    01016     bool operator==(const PString & other) const { PWaitAndSignal m(_mutex); return m_info != NULL && m_info->formatName == other; }
    01017     bool operator!=(const PString & other) const { PWaitAndSignal m(_mutex); return m_info == NULL || m_info->formatName == other; }
    01018     bool operator==(const OpalMediaFormat & other) const { PWaitAndSignal m(_mutex); return Compare(other) == EqualTo; }
    01019     bool operator!=(const OpalMediaFormat & other) const { PWaitAndSignal m(_mutex); return Compare(other) != EqualTo; }
    01020     friend bool operator==(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
    01021     friend bool operator!=(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName == other; }
    01022     friend bool operator==(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
    01023     friend bool operator!=(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName == other; }
    01024
    01025 #if OPAL_H323
    01026     static const PString & MediaPacketizationOption();
    01027 #endif
    01028
    01029   private:
    01030     PBoolean SetSize(PINDEX) { return PTrue; }
    01031
    01032   protected:
    01033     PMutex _mutex;
    01034     void Construct(OpalMediaFormatInternal * info);
    01035     OpalMediaFormatInternal * m_info;
    01036
    01037   friend class OpalMediaFormatInternal;
    01038   friend class OpalMediaFormatList;
    01039 };
    01040
    01041
    01042 class OpalAudioFormatInternal : public OpalMediaFormatInternal
    01043 {
    01044   public:
    01045     OpalAudioFormatInternal(
    01046       const char * fullName,
    01047       RTP_DataFrame::PayloadTypes rtpPayloadType,
    01048       const char * encodingName,
    01049       PINDEX   frameSize,
    01050       unsigned frameTime,
    01051       unsigned rxFrames,
    01052       unsigned txFrames,
    01053       unsigned maxFrames,
    01054       unsigned clockRate,
    01055       time_t timeStamp
    01056     );
    01057     virtual PObject * Clone() const;
    01058     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
    01059 };
    01060
    01061 class OpalAudioFormat : public OpalMediaFormat
    01062 {
    01063     PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
    01064   public:
    01065     OpalAudioFormat(
    01066       const char * fullName,
    01067       RTP_DataFrame::PayloadTypes rtpPayloadType,
    01068       const char * encodingName,
    01069       PINDEX   frameSize,
    01070       unsigned frameTime,
    01071       unsigned rxFrames,
    01072       unsigned txFrames,
    01073       unsigned maxFrames = 256,
    01074       unsigned clockRate = 8000,
    01075       time_t timeStamp = 0
    01076     );
    01077
    01078     static const PString & RxFramesPerPacketOption();
    01079     static const PString & TxFramesPerPacketOption();
    01080     static const PString & MaxFramesPerPacketOption();
    01081     static const PString & ChannelsOption();
    01082 };
    01083
    01084 #if OPAL_VIDEO
    01085 class OpalVideoFormatInternal : public OpalMediaFormatInternal
    01086 {
    01087   public:
    01088     OpalVideoFormatInternal(
    01089       const char * fullName,
    01090       RTP_DataFrame::PayloadTypes rtpPayloadType,
    01091       const char * encodingName,
    01092       unsigned maxFrameWidth,
    01093       unsigned maxFrameHeight,
    01094       unsigned maxFrameRate,
    01095       unsigned maxBitRate,
    01096       time_t timeStamp
    01097     );
    01098     virtual PObject * Clone() const;
    01099     virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
    01100 };
    01101
    01102
    01103 class OpalVideoFormat : public OpalMediaFormat
    01104 {
    01105     PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
    01106   public:
    01107     OpalVideoFormat(
    01108       const char * fullName,
    01109       RTP_DataFrame::PayloadTypes rtpPayloadType,
    01110       const char * encodingName,
    01111       unsigned maxFrameWidth,
    01112       unsigned maxFrameHeight,
    01113       unsigned maxFrameRate,
    01114       unsigned maxBitRate,
    01115       time_t timeStamp = 0
    01116     );
    01117
    01118     static const PString & FrameWidthOption();
    01119     static const PString & FrameHeightOption();
    01120     static const PString & MinRxFrameWidthOption();
    01121     static const PString & MinRxFrameHeightOption();
    01122     static const PString & MaxRxFrameWidthOption();
    01123     static const PString & MaxRxFrameHeightOption();
    01124     static const PString & TemporalSpatialTradeOffOption();
    01125     static const PString & TxKeyFramePeriodOption();
    01126     static const PString & RateControlEnableOption();
    01127     static const PString & RateControlWindowSizeOption();
    01128     static const PString & RateControlMaxFramesSkipOption();
    01129 };
    01130 #endif
    01131
    01132 // List of known media formats
    01133
    01134 #define OPAL_PCM16          "PCM-16"
    01135 #define OPAL_PCM16_16KHZ    "PCM-16-16kHz"
    01136 #define OPAL_L16_MONO_8KHZ  "Linear-16-Mono-8kHz"
    01137 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
    01138 #define OPAL_G711_ULAW_64K  "G.711-uLaw-64k"
    01139 #define OPAL_G711_ALAW_64K  "G.711-ALaw-64k"
    01140 #define OPAL_G726_40K       "G.726-40K"
    01141 #define OPAL_G726_32K       "G.726-32K"
    01142 #define OPAL_G726_24K       "G.726-24K"
    01143 #define OPAL_G726_16K       "G.726-16K"
    01144 #define OPAL_G728           "G.728"
    01145 #define OPAL_G729           "G.729"
    01146 #define OPAL_G729A          "G.729A"
    01147 #define OPAL_G729B          "G.729B"
    01148 #define OPAL_G729AB         "G.729A/B"
    01149 #define OPAL_G7231          "G.723.1"
    01150 #define OPAL_G7231_6k3      OPAL_G7231
    01151 #define OPAL_G7231_5k3      "G.723.1(5.3k)"
    01152 #define OPAL_G7231A_6k3     "G.723.1A(6.3k)"
    01153 #define OPAL_G7231A_5k3     "G.723.1A(5.3k)"
    01154 #define OPAL_GSM0610        "GSM-06.10"
    01155 #define OPAL_GSMAMR         "GSM-AMR"
    01156 #define OPAL_iLBC           "iLBC"
    01157 #define OPAL_RFC2833        "UserInput/RFC2833"
    01158 #define OPAL_CISCONSE       "NamedSignalEvent"
    01159 #define OPAL_T38            "T.38"
    01160 #define OPAL_H224            "H.224"
    01161
    01162 extern const OpalAudioFormat & GetOpalPCM16();
    01163 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
    01164 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
    01165 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
    01166 extern const OpalAudioFormat & GetOpalL16_STEREO_48KHZ();
    01167 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
    01168 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
    01169 extern const OpalAudioFormat & GetOpalG726_40K();
    01170 extern const OpalAudioFormat & GetOpalG726_32K();
    01171 extern const OpalAudioFormat & GetOpalG726_24K();
    01172 extern const OpalAudioFormat & GetOpalG726_16K();
    01173 extern const OpalAudioFormat & GetOpalG728();
    01174 extern const OpalAudioFormat & GetOpalG729();
    01175 extern const OpalAudioFormat & GetOpalG729A();
    01176 extern const OpalAudioFormat & GetOpalG729B();
    01177 extern const OpalAudioFormat & GetOpalG729AB();
    01178 extern const OpalAudioFormat & GetOpalG7231_6k3();
    01179 extern const OpalAudioFormat & GetOpalG7231_5k3();
    01180 extern const OpalAudioFormat & GetOpalG7231A_6k3();
    01181 extern const OpalAudioFormat & GetOpalG7231A_5k3();
    01182 extern const OpalAudioFormat & GetOpalGSM0610();
    01183 extern const OpalAudioFormat & GetOpalGSMAMR();
    01184 extern const OpalAudioFormat & GetOpaliLBC();
    01185
    01186 extern const OpalMediaFormat & GetOpalRFC2833();
    01187 #if OPAL_T38_CAPABILITY
    01188 extern const OpalMediaFormat & GetOpalCiscoNSE();
    01189 extern const OpalMediaFormat & GetOpalT38();
    01190 #endif
    01191
    01192 #define OpalPCM16          GetOpalPCM16()
    01193 #define OpalPCM16_16KHZ    GetOpalPCM16_16KHZ()
    01194 #define OpalL16_MONO_8KHZ  GetOpalL16_MONO_8KHZ()
    01195 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
    01196 #define OpalL16_STEREO_48KHZ GetOpalL16_STEREO_48KHZ()
    01197 #define OpalG711_ULAW_64K  GetOpalG711_ULAW_64K()
    01198 #define OpalG711_ALAW_64K  GetOpalG711_ALAW_64K()
    01199 #define OpalG726_40K       GetOpalG726_40K()
    01200 #define OpalG726_32K       GetOpalG726_32K()
    01201 #define OpalG726_24K       GetOpalG726_24K()
    01202 #define OpalG726_16K       GetOpalG726_16K()
    01203 #define OpalG728           GetOpalG728()
    01204 #define OpalG729           GetOpalG729()
    01205 #define OpalG729A          GetOpalG729A()
    01206 #define OpalG729B          GetOpalG729B()
    01207 #define OpalG729AB         GetOpalG729AB()
    01208 #define OpalG7231_6k3      GetOpalG7231_6k3()
    01209 #define OpalG7231_5k3      GetOpalG7231_5k3()
    01210 #define OpalG7231A_6k3     GetOpalG7231A_6k3()
    01211 #define OpalG7231A_5k3     GetOpalG7231A_5k3()
    01212 #define OpalGSM0610        GetOpalGSM0610()
    01213 #define OpalGSMAMR         GetOpalGSMAMR()
    01214 #define OpaliLBC           GetOpaliLBC()
    01215 #define OpalRFC2833        GetOpalRFC2833()
    01216 #define OpalCiscoNSE       GetOpalCiscoNSE()
    01217 #define OpalT38            GetOpalT38()
    01218
    01219 #define OpalL16Mono8kHz    OpalL16_MONO_8KHZ
    01220 #define OpalL16Mono16kHz   OpalL16_MONO_16KHZ
    01221 #define OpalG711uLaw       OpalG711_ULAW_64K
    01222 #define OpalG711ALaw       OpalG711_ALAW_64K
    01223
    01224 #ifdef _MSC_VER
    01225 #if _MSC_VER < 1300
    01226 #pragma warning(default:4663)
    01227 #endif
    01228 #endif
    01229
    01230 #endif  // __OPAL_MEDIAFMT_H
    01231
    01232
    01233 // End of File ///////////////////////////////////////////////////////////////