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  * $Log: mediafmt.h,v $
00028  * Revision 2.61  2007/09/25 19:35:30  csoutheren
00029  * Fix compilation when using --disable-audio
00030  *
00031  * Revision 2.60  2007/09/21 00:51:38  rjongbloed
00032  * Fixed weird divide by zero error on clock rate.
00033  *
00034  * Revision 2.59  2007/09/18 12:52:34  rjongbloed
00035  * Removed duplicate change logs
00036  *
00037  * Revision 2.58  2007/09/12 04:19:53  rjongbloed
00038  * CHanges to avoid creation of long duration OpalMediaFormat instances, eg in
00039  *   the plug in capabilities, that then do not get updated values from the master
00040  *   list, or worse from the user modified master list, causing much confusion.
00041  *
00042  * Revision 2.57  2007/09/10 00:11:13  rjongbloed
00043  * AddedOpalMediaFormat::IsTransportable() function as better test than simply
00044  *   checking the payload type, condition is more complex.
00045  *
00046  * Revision 2.56  2007/08/10 09:30:18  rjongbloed
00047  * Fixed typos in comments
00048  *
00049  * Revision 2.55  2007/08/07 01:38:40  csoutheren
00050  * Fix problem with rtpEncodingName member going out of scope
00051  *
00052  * Revision 2.54  2007/08/02 07:54:15  csoutheren
00053  * Add function to print options on media format
00054  *
00055  * Revision 2.53  2007/07/24 12:51:26  rjongbloed
00056  * Fixed odd problem where need to allow for sign bit on an unsigned enum in a struct bitfield.
00057  *
00058  * Revision 2.52  2007/06/27 07:56:08  rjongbloed
00059  * Add new OpalMediaOption for octet strings (simple block of bytes).
00060  *
00061  * Revision 2.51  2007/06/22 05:41:47  rjongbloed
00062  * Major codec API update:
00063  *   Automatically map OpalMediaOptions to SIP/SDP FMTP parameters.
00064  *   Automatically map OpalMediaOptions to H.245 Generic Capability parameters.
00065  *   Largely removed need to distinguish between SIP and H.323 codecs.
00066  *   New mechanism for setting OpalMediaOptions from within a plug in.
00067  *
00068  * Revision 2.50  2007/06/16 21:36:59  dsandras
00069  * Added H.264 support thanks to Matthias Schneider <ma30002000 yahoo de>.
00070  * Thanks a lot !
00071  *
00072  * Baseline Profile:
00073  * no B-frames
00074  * We make use of the baseline profile (which is the designated profile for interactive vide) ,
00075  * that means:
00076  * no B-Frames (too much latency in interactive video)
00077  * CBR (we want to get the max. quality making use of all the bitrate that is available)
00078  * We allow one exeption: configuring a bitrate of > 786 kbit/s
00079  *
00080  * This plugin implements
00081  * - Single Time Aggregation Packets A
00082  * - Single NAL units
00083  * - Fragmentation Units
00084  * like described in RFC3984
00085  *
00086  * It requires x264 and ffmpeg.
00087  *
00088  * Revision 2.49  2007/04/10 05:15:53  rjongbloed
00089  * Fixed issue with use of static C string variables in DLL environment,
00090  *   must use functional interface for correct initialisation.
00091  *
00092  * Revision 2.48  2007/03/13 00:32:16  csoutheren
00093  * Simple but messy changes to allow compile time removal of protocol
00094  * options such as H.450 and H.460
00095  * Fix MakeConnection overrides
00096  *
00097  * Revision 2.47  2007/02/14 06:51:28  csoutheren
00098  * Extended FindFormat to allow finding multiple matching formats
00099  *
00100  * Revision 2.46  2007/02/10 18:14:31  hfriederich
00101  * Add copy constructor to have consistent code with assignment operator.
00102  * Only make options unique when they actually differ
00103  *
00104  * Revision 2.45  2006/12/08 07:33:13  csoutheren
00105  * Fix problem with wideband audio plugins and sound channel
00106  *
00107  * Revision 2.44  2006/11/21 01:00:59  csoutheren
00108  * Ensure SDP only uses codecs that are valid for SIP
00109  *
00110  * Revision 2.43  2006/08/20 03:45:54  csoutheren
00111  * Add OpalMediaFormat::IsValidForProtocol to allow plugin codecs to be enabled only for certain protocols
00112  * rather than relying on the presence of the IANA rtp encoding name field
00113  *
00114  * Revision 2.42  2006/08/11 07:52:01  csoutheren
00115  * Fix problem with media format factory in VC 2005
00116  * Fixing problems with Speex codec
00117  * Remove non-portable usages of PFactory code
00118  *
00119  * Revision 2.41  2006/07/24 14:03:38  csoutheren
00120  * Merged in audio and video plugins from CVS branch PluginBranch
00121  *
00122  * Revision 2.40  2006/07/14 04:22:42  csoutheren
00123  * Applied 1517397 - More Phobos stability fix
00124  * Thanks to Dinis Rosario
00125  *
00126  * Revision 2.39  2006/04/20 16:52:22  hfriederich
00127  * Adding support for H.224/H.281
00128  *
00129  * Revision 2.38  2006/04/09 12:01:43  rjongbloed
00130  * Added missing Clone() functions so media options propagate correctly.
00131  *
00132  * Revision 2.37.4.6  2006/04/26 05:05:59  csoutheren
00133  * H.263 decoding working via codec plugin
00134  *
00135  * Revision 2.37.4.5  2006/04/19 04:58:56  csoutheren
00136  * Debugging and testing of new video plugins
00137  * H.261 working in both CIF and QCIF modes in H.323
00138  *
00139  * Revision 2.37.4.4  2006/04/10 06:24:30  csoutheren
00140  * Backport from CVS head up to Plugin_Merge3
00141  *
00142  * Revision 2.37.4.3  2006/04/06 01:21:17  csoutheren
00143  * More implementation of video codec plugins
00144  *
00145  * Revision 2.37.4.2  2006/03/16 07:06:00  csoutheren
00146  * Initial support for audio plugins
00147  *
00148  * Revision 2.37.4.1  2006/03/13 07:20:28  csoutheren
00149  * Added OpalMediaFormat clone function
00150  *
00151 
00152  * Revision 2.37  2005/12/27 20:46:09  dsandras
00153  * Added clockRate to the media format. Added "AlwaysMerge" method for merging
00154  * media format options.
00155  *
00156  * Revision 2.36  2005/12/24 17:51:02  dsandras
00157  * Added clockRate parameter to allow wideband audio codecs.
00158  *
00159  * Revision 2.35  2005/11/30 13:35:26  csoutheren
00160  * Changed tags for Doxygen
00161  *
00162  * Revision 2.34  2005/09/13 20:48:22  dominance
00163  * minor cleanups needed to support mingw compilation. Thanks goes to Julien Puydt.
00164  *
00165  * Revision 2.33  2005/09/06 12:44:49  rjongbloed
00166  * Many fixes to finalise the video processing: merging remote media
00167  *
00168  * Revision 2.32  2005/08/31 13:19:25  rjongbloed
00169  * Added mechanism for controlling media (especially codecs) including
00170  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00171  *   new OpalMediaCommand abstraction for things like video fast update.
00172  *
00173  * Revision 2.31  2005/08/28 07:59:17  rjongbloed
00174  * Converted OpalTranscoder to use factory, requiring sme changes in making sure
00175  *   OpalMediaFormat instances are initialised before use.
00176  *
00177  * Revision 2.30  2005/08/24 02:07:56  dereksmithies
00178  * Put guard around a MSVC pragma, so GCC does not generate zillions of warnings.
00179  *
00180  * Revision 2.29  2005/08/22 01:26:25  shorne
00181  * Removed warning on numeric_limits on MSVC6
00182  *
00183  * Revision 2.28  2005/08/20 07:32:49  rjongbloed
00184  * Added video specific OpalMediaFormat
00185  *
00186  * Revision 2.27  2005/07/11 01:42:21  csoutheren
00187  * Fixed problems with some constants names not being available
00188  *
00189  * Revision 2.26  2005/06/20 16:47:52  shorne
00190  * Fix STL compatibility issue on MSVC6
00191  *
00192  * Revision 2.25  2005/06/02 13:20:45  rjongbloed
00193  * Added minimum and maximum check to media format options.
00194  * Added ability to set the options on the primordial media format list.
00195  *
00196  * Revision 2.24  2005/03/12 00:33:26  csoutheren
00197  * Fixed problems with STL compatibility on MSVC 6
00198  * Fixed problems with video streams
00199  * Thanks to Adrian Sietsma
00200  *
00201  * Revision 2.23  2005/02/21 12:19:47  rjongbloed
00202  * Added new "options list" to the OpalMediaFormat class.
00203  *
00204  * Revision 2.22  2004/07/11 12:32:51  rjongbloed
00205  * Added functions to add/subtract lists of media formats from a media format list
00206  *
00207  * Revision 2.21  2004/05/03 00:59:18  csoutheren
00208  * Fixed problem with OpalMediaFormat::GetMediaFormatsList
00209  * Added new version of OpalMediaFormat::GetMediaFormatsList that minimses copying
00210  *
00211  * Revision 2.20  2004/03/22 11:32:41  rjongbloed
00212  * Added new codec type for 16 bit Linear PCM as must distinguish between the internal
00213  *   format used by such things as the sound card and the RTP payload format which
00214  *   is always big endian.
00215  *
00216  * Revision 2.19  2004/03/11 06:54:27  csoutheren
00217  * Added ability to disable SIP or H.323 stacks
00218  *
00219  * Revision 2.18  2004/02/07 02:18:18  rjongbloed
00220  * Improved searching for media format to use payload type AND the encoding name.
00221  *
00222  * Revision 2.17  2003/03/17 10:12:02  robertj
00223  * Fixed mutex problem with media format database.
00224  *
00225  * Revision 2.16  2003/01/07 04:39:53  robertj
00226  * Updated to OpenH323 v1.11.2
00227  *
00228  * Revision 2.15  2002/11/10 11:33:17  robertj
00229  * Updated to OpenH323 v1.10.3
00230  *
00231  * Revision 2.14  2002/09/16 02:52:35  robertj
00232  * Added #define so can select if #pragma interface/implementation is used on
00233  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00234  *
00235  * Revision 2.13  2002/09/04 06:01:47  robertj
00236  * Updated to OpenH323 v1.9.6
00237  *
00238  * Revision 2.12  2002/07/01 04:56:31  robertj
00239  * Updated to OpenH323 v1.9.1
00240  *
00241  * Revision 2.11  2002/03/22 06:57:49  robertj
00242  * Updated to OpenH323 version 1.8.2
00243  *
00244  * Revision 2.10  2002/02/19 07:36:28  robertj
00245  * Added OpalRFC2833 as a OpalMediaFormat variable.
00246  *
00247  * Revision 2.9  2002/02/11 09:32:12  robertj
00248  * Updated to openH323 v1.8.0
00249  *
00250  * Revision 2.8  2002/01/22 05:06:30  robertj
00251  * Added RTP encoding name string to media format database.
00252  * Changed time units to clock rate in Hz.
00253  *
00254  * Revision 2.7  2002/01/14 06:35:57  robertj
00255  * Updated to OpenH323 v1.7.9
00256  *
00257  * Revision 2.6  2001/10/05 00:22:13  robertj
00258  * Updated to PWLib 1.2.0 and OpenH323 1.7.0
00259  *
00260  * Revision 2.5  2001/10/04 00:42:12  robertj
00261  * Added function to remove wildcard from list.
00262  * Added constructor to make a list with one format in it.
00263  *
00264  * Revision 2.4  2001/08/23 05:51:17  robertj
00265  * Completed implementation of codec reordering.
00266  *
00267  * Revision 2.3  2001/08/22 03:51:31  robertj
00268  * Added functions to look up media format by payload type.
00269  *
00270  * Revision 2.2  2001/08/17 08:23:02  robertj
00271  * Put in missing dots in G.729 media formats.
00272  *
00273  * Revision 2.1  2001/08/01 05:51:39  robertj
00274  * Made OpalMediaFormatList class global to help with documentation.
00275  *
00276  * Revision 2.0  2001/07/27 15:48:24  robertj
00277  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00278  *
00279  * Revision 1.13  2002/12/02 03:06:26  robertj
00280  * Fixed over zealous removal of code when NO_AUDIO_CODECS set.
00281  *
00282  * Revision 1.12  2002/09/16 01:14:15  robertj
00283  * Added #define so can select if #pragma interface/implementation is used on
00284  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00285  *
00286  * Revision 1.11  2002/09/03 06:19:37  robertj
00287  * Normalised the multi-include header prevention ifdef/define symbol.
00288  *
00289  * Revision 1.10  2002/08/05 10:03:47  robertj
00290  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00291  *
00292  * Revision 1.9  2002/06/25 08:30:08  robertj
00293  * Changes to differentiate between stright G.723.1 and G.723.1 Annex A using
00294  *   the OLC dataType silenceSuppression field so does not send SID frames
00295  *   to receiver codecs that do not understand them.
00296  *
00297  * Revision 1.8  2002/03/21 02:39:15  robertj
00298  * Added backward compatibility define
00299  *
00300  * Revision 1.7  2002/02/11 04:15:56  robertj
00301  * Put G.723.1 at 6.3kbps back to old string value of "G.723.1" to improve
00302  *   backward compatibility. New #define is a synonym for it.
00303  *
00304  * Revision 1.6  2002/01/22 07:08:26  robertj
00305  * Added IllegalPayloadType enum as need marker for none set
00306  *   and MaxPayloadType is a legal value.
00307  *
00308  * Revision 1.5  2001/12/11 04:27:50  craigs
00309  * Added support for 5.3kbps G723.1
00310  *
00311  * Revision 1.4  2001/09/21 02:49:44  robertj
00312  * Implemented static object for all "known" media formats.
00313  * Added default session ID to media format description.
00314  *
00315  * Revision 1.3  2001/05/11 04:43:41  robertj
00316  * Added variable names for standard PCM-16 media format name.
00317  *
00318  * Revision 1.2  2001/02/09 05:16:24  robertj
00319  * Added #pragma interface for GNU C++.
00320  *
00321  * Revision 1.1  2001/01/25 07:27:14  robertj
00322  * Major changes to add more flexible OpalMediaFormat class to normalise
00323  *   all information about media types, especially codecs.
00324  *
00325  */
00326 
00327 #ifndef __OPAL_MEDIAFMT_H
00328 #define __OPAL_MEDIAFMT_H
00329 
00330 #ifdef P_USE_PRAGMA
00331 #pragma interface
00332 #endif
00333 
00334 #ifdef _MSC_VER
00335 #if _MSC_VER < 1300   
00336 #pragma warning(disable:4663)
00337 #endif
00338 #endif
00339 
00340 #include <opal/buildopts.h>
00341 
00342 #include <rtp/rtp.h>
00343 
00344 #include <limits>
00345 
00346 #ifdef min
00347 #undef min
00348 #endif
00349 #ifdef max
00350 #undef max
00351 #endif
00352 
00353 class OpalMediaFormat;
00354 
00355 
00357 
00358 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
00359 
00362 class OpalMediaFormatList : public OpalMediaFormatBaseList
00363 {
00364   PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
00365   public:
00370     OpalMediaFormatList();
00371 
00374     OpalMediaFormatList(
00375       const OpalMediaFormat & format    
00376     );
00377 
00380     OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
00382 
00388     OpalMediaFormatList & operator+=(
00389       const OpalMediaFormat & format    
00390     );
00391 
00395     OpalMediaFormatList & operator+=(
00396       const OpalMediaFormatList & formats    
00397     );
00398 
00402     OpalMediaFormatList & operator-=(
00403       const OpalMediaFormat & format    
00404     );
00405 
00409     OpalMediaFormatList & operator-=(
00410       const OpalMediaFormatList & formats    
00411     );
00412 
00417     PINDEX FindFormat(
00418       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00419       const unsigned clockRate,                   
00420       const char * rtpEncodingName = NULL,        
00421       const char * protocol = NULL                
00422     ) const;
00423 
00431     PINDEX FindFormat(
00432       const PString & wildcard,    
00433       PINDEX pos = 0
00434     ) const;
00435 
00438     BOOL HasFormat(
00439       RTP_DataFrame::PayloadTypes rtpPayloadType 
00440     ) const { return FindFormat(rtpPayloadType) != P_MAX_INDEX; }
00441 
00447     BOOL HasFormat(
00448       const PString & wildcard    
00449     ) const { return FindFormat(wildcard) != P_MAX_INDEX; }
00450 
00453     void Remove(
00454       const PStringArray & mask
00455     );
00456 
00461     void Reorder(
00462       const PStringArray & order
00463     );
00465 
00466   private:
00467     virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
00468     virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
00469     virtual PINDEX InsertAt(PINDEX, PObject *) { return P_MAX_INDEX; }
00470     virtual BOOL SetAt(PINDEX, PObject *) { return FALSE; }
00471 };
00472 
00473 
00475 
00478 class OpalMediaOption : public PObject
00479 {
00480     PCLASSINFO(OpalMediaOption, PObject);
00481   public:
00482     enum MergeType {
00483       NoMerge,
00484       MinMerge,
00485       MaxMerge,
00486       EqualMerge,
00487       NotEqualMerge,
00488       AlwaysMerge,
00489 
00490       // Synonyms
00491       AndMerge = MinMerge,
00492       OrMerge  = MaxMerge
00493     };
00494 
00495   protected:
00496     OpalMediaOption(
00497       const char * name,
00498       bool readOnly,
00499       MergeType merge
00500     );
00501 
00502   public:
00503     virtual Comparison Compare(const PObject & obj) const;
00504 
00505     bool Merge(
00506       const OpalMediaOption & option
00507     );
00508     virtual Comparison CompareValue(
00509       const OpalMediaOption & option
00510     ) const = 0;
00511     virtual void Assign(
00512       const OpalMediaOption & option
00513     ) = 0;
00514 
00515     PString AsString() const;
00516     bool FromString(const PString & value);
00517 
00518     const PString & GetName() const { return m_name; }
00519 
00520     bool IsReadOnly() const { return m_readOnly; }
00521     void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
00522 
00523     MergeType GetMerge() const { return m_merge; }
00524     void SetMerge(MergeType merge) { m_merge = merge; }
00525 
00526     const PString & GetFMTPName() const { return m_FMTPName; }
00527     void SetFMTPName(const char * name) { m_FMTPName = name; }
00528 
00529     const PString & GetFMTPDefault() const { return m_FMTPDefault; }
00530     void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
00531 
00532     struct H245GenericInfo {
00533       unsigned ordinal:16;
00534       enum Modes {
00535         None,
00536         Collapsing,
00537         NonCollapsing
00538       } mode:3;
00539       enum IntegerTypes {
00540         UnsignedInt,
00541         Unsigned32,
00542         BooleanArray
00543       } integerType:3;
00544       bool excludeTCS:1;
00545       bool excludeOLC:1;
00546       bool excludeReqMode:1;
00547     };
00548 
00549     const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
00550     void SetH245Generic(const H245GenericInfo & generic) { m_H245Generic = generic; }
00551 
00552   protected:
00553     PCaselessString m_name;
00554     bool            m_readOnly;
00555     MergeType       m_merge;
00556     PCaselessString m_FMTPName;
00557     PString         m_FMTPDefault;
00558     H245GenericInfo m_H245Generic;
00559 };
00560 
00561 #ifndef __USE_STL__
00562 __inline istream & operator>>(istream & strm, bool& b)
00563 {
00564    int i;strm >> i;b = i; return strm;
00565 }
00566 #endif
00567 
00568 template <typename T>
00569 class OpalMediaOptionValue : public OpalMediaOption
00570 {
00571     PCLASSINFO(OpalMediaOptionValue, OpalMediaOption);
00572   public:
00573     OpalMediaOptionValue(
00574       const char * name,
00575       bool readOnly,
00576       MergeType merge = MinMerge,
00577       T value = 0,
00578       T minimum = std::numeric_limits<T>::min(),
00579       T maximum = std::numeric_limits<T>::max()
00580     ) : OpalMediaOption(name, readOnly, merge),
00581         m_value(value),
00582         m_minimum(minimum),
00583         m_maximum(maximum)
00584     { }
00585 
00586     virtual PObject * Clone() const
00587     {
00588       return new OpalMediaOptionValue(*this);
00589     }
00590 
00591     virtual void PrintOn(ostream & strm) const
00592     {
00593       strm << m_value;
00594     }
00595 
00596     virtual void ReadFrom(istream & strm)
00597     {
00598       T temp;
00599       strm >> temp;
00600       if (temp >= m_minimum && temp <= m_maximum)
00601         m_value = temp;
00602       else {
00603 #ifdef __USE_STL__
00604            strm.setstate(ios::badbit);
00605 #else
00606            strm.setf(ios::badbit , ios::badbit);
00607 #endif
00608        }
00609     }
00610 
00611     virtual Comparison CompareValue(const OpalMediaOption & option) const {
00612       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00613       if (otherOption == NULL)
00614         return GreaterThan;
00615       if (m_value < otherOption->m_value)
00616         return LessThan;
00617       if (m_value > otherOption->m_value)
00618         return GreaterThan;
00619       return EqualTo;
00620     }
00621 
00622     virtual void Assign(
00623       const OpalMediaOption & option
00624     ) {
00625       const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00626       if (otherOption != NULL)
00627         m_value = otherOption->m_value;
00628     }
00629 
00630     T GetValue() const { return m_value; }
00631     void SetValue(T value) { m_value = value; }
00632 
00633   protected:
00634     T m_value;
00635     T m_minimum;
00636     T m_maximum;
00637 };
00638 
00639 
00640 typedef OpalMediaOptionValue<bool>     OpalMediaOptionBoolean;
00641 typedef OpalMediaOptionValue<int>      OpalMediaOptionInteger;
00642 typedef OpalMediaOptionValue<unsigned> OpalMediaOptionUnsigned;
00643 typedef OpalMediaOptionValue<double>   OpalMediaOptionReal;
00644 
00645 
00646 class OpalMediaOptionEnum : public OpalMediaOption
00647 {
00648     PCLASSINFO(OpalMediaOptionEnum, OpalMediaOption);
00649   public:
00650     OpalMediaOptionEnum(
00651       const char * name,
00652       bool readOnly,
00653       const char * const * enumerations,
00654       PINDEX count,
00655       MergeType merge = EqualMerge,
00656       PINDEX value = 0
00657     );
00658 
00659     virtual PObject * Clone() const;
00660     virtual void PrintOn(ostream & strm) const;
00661     virtual void ReadFrom(istream & strm);
00662 
00663     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00664     virtual void Assign(const OpalMediaOption & option);
00665 
00666     PINDEX GetValue() const { return m_value; }
00667     void SetValue(PINDEX value);
00668 
00669   protected:
00670     PStringArray m_enumerations;
00671     PINDEX       m_value;
00672 };
00673 
00674 
00675 class OpalMediaOptionString : public OpalMediaOption
00676 {
00677     PCLASSINFO(OpalMediaOptionString, OpalMediaOption);
00678   public:
00679     OpalMediaOptionString(
00680       const char * name,
00681       bool readOnly
00682     );
00683     OpalMediaOptionString(
00684       const char * name,
00685       bool readOnly,
00686       const PString & value
00687     );
00688 
00689     virtual PObject * Clone() const;
00690     virtual void PrintOn(ostream & strm) const;
00691     virtual void ReadFrom(istream & strm);
00692 
00693     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00694     virtual void Assign(const OpalMediaOption & option);
00695 
00696     const PString & GetValue() const { return m_value; }
00697     void SetValue(const PString & value);
00698 
00699   protected:
00700     PString m_value;
00701 };
00702 
00703 
00704 class OpalMediaOptionOctets : public OpalMediaOption
00705 {
00706     PCLASSINFO(OpalMediaOptionOctets, OpalMediaOption);
00707   public:
00708     OpalMediaOptionOctets(
00709       const char * name,
00710       bool readOnly,
00711       bool base64
00712     );
00713     OpalMediaOptionOctets(
00714       const char * name,
00715       bool readOnly,
00716       bool base64,
00717       const PBYTEArray & value
00718     );
00719     OpalMediaOptionOctets(
00720       const char * name,
00721       bool readOnly,
00722       bool base64,
00723       const BYTE * data,
00724       PINDEX length
00725     );
00726 
00727     virtual PObject * Clone() const;
00728     virtual void PrintOn(ostream & strm) const;
00729     virtual void ReadFrom(istream & strm);
00730 
00731     virtual Comparison CompareValue(const OpalMediaOption & option) const;
00732     virtual void Assign(const OpalMediaOption & option);
00733 
00734     const PBYTEArray & GetValue() const { return m_value; }
00735     void SetValue(const PBYTEArray & value);
00736     void SetValue(const BYTE * data, PINDEX length);
00737 
00738   protected:
00739     PBYTEArray m_value;
00740     bool       m_base64;
00741 };
00742 
00743 
00745 
00751 class OpalMediaFormat : public PCaselessString
00752 {
00753   friend class OpalPluginCodecManager;
00754   PCLASSINFO(OpalMediaFormat, PCaselessString);
00755 
00756   public:
00759     OpalMediaFormat();
00760 
00774     OpalMediaFormat(
00775       const char * fullName,      
00776       unsigned defaultSessionID,  
00777       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00778       const char * encodingName,  
00779       BOOL     needsJitter,       
00780       unsigned bandwidth,         
00781       PINDEX   frameSize,         
00782       unsigned frameTime,         
00783       unsigned clockRate,         
00784       time_t timeStamp = 0        
00785     );
00786 
00796     OpalMediaFormat(
00797       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00798       unsigned clockRate,                         
00799       const char * rtpEncodingName = NULL,        
00800       const char * protocol = NULL                
00801     );
00802 
00816     OpalMediaFormat(
00817       const char * wildcard  
00818     );
00819 
00833     OpalMediaFormat(
00834       const PString & wildcard  
00835     );
00836     
00839     OpalMediaFormat(
00840       const OpalMediaFormat & mediaFormat 
00841     );
00842 
00847     virtual BOOL IsValid() const { return rtpPayloadType < RTP_DataFrame::IllegalPayloadType && !IsEmpty(); }
00848 
00852     BOOL IsTransportable() const { return rtpPayloadType < RTP_DataFrame::MaxPayloadType && !rtpEncodingName.IsEmpty(); }
00853 
00856     OpalMediaFormat & operator=(
00857       const OpalMediaFormat & fmt 
00858     );
00859 
00863     OpalMediaFormat & operator=(
00864       RTP_DataFrame::PayloadTypes rtpPayloadType 
00865     );
00866 
00870     OpalMediaFormat & operator=(
00871       const char * wildcard  
00872     );
00873 
00877     OpalMediaFormat & operator=(
00878       const PString & wildcard  
00879     );
00880 
00883     virtual PObject * Clone() const;
00884 
00895     virtual bool Merge(
00896       const OpalMediaFormat & mediaFormat
00897     );
00898 
00904     RTP_DataFrame::PayloadTypes GetPayloadType() const { return rtpPayloadType; }
00905 
00908     const char * GetEncodingName() const { return rtpEncodingName; }
00909 
00910     enum {
00911       DefaultAudioSessionID = 1,
00912       DefaultVideoSessionID = 2,
00913       DefaultDataSessionID  = 3,
00914       DefaultH224SessionID  = 4
00915     };
00916 
00919     unsigned GetDefaultSessionID() const { return defaultSessionID; }
00920 
00924     bool NeedsJitterBuffer() const { return GetOptionBoolean(NeedsJitterOption()); }
00925     static const PString & NeedsJitterOption();
00926 
00929     unsigned GetBandwidth() const { return GetOptionInteger(MaxBitRateOption()); }
00930     static const PString & MaxBitRateOption();
00931 
00936     PINDEX GetFrameSize() const { return GetOptionInteger(MaxFrameSizeOption()); }
00937     static const PString & MaxFrameSizeOption();
00938 
00942     unsigned GetFrameTime() const { return GetOptionInteger(FrameTimeOption()); }
00943     static const PString & FrameTimeOption();
00944 
00947     unsigned GetTimeUnits() const { return GetClockRate()/1000; }
00948 
00949     enum StandardClockRate {
00950       AudioClockRate = 8000,  
00951       VideoClockRate = 90000  
00952     };
00953 
00956     unsigned GetClockRate() const { return GetOptionInteger(ClockRateOption(), 1000); }
00957     static const PString & ClockRateOption();
00958 
00961     PINDEX GetOptionCount() const { return options.GetSize(); }
00962 
00966     const OpalMediaOption & GetOption(
00967       PINDEX index   
00968     ) const { return options[index]; }
00969 
00974     bool GetOptionValue(
00975       const PString & name,   
00976       PString & value         
00977     ) const;
00978 
00985     bool SetOptionValue(
00986       const PString & name,   
00987       const PString & value   
00988     );
00989 
00993     bool GetOptionBoolean(
00994       const PString & name,   
00995       bool dflt = FALSE       
00996     ) const;
00997 
01004     bool SetOptionBoolean(
01005       const PString & name,   
01006       bool value              
01007     );
01008 
01012     int GetOptionInteger(
01013       const PString & name,   
01014       int dflt = 0            
01015     ) const;
01016 
01024     bool SetOptionInteger(
01025       const PString & name,   
01026       int value               
01027     );
01028 
01032     double GetOptionReal(
01033       const PString & name,   
01034       double dflt = 0         
01035     ) const;
01036 
01043     bool SetOptionReal(
01044       const PString & name,   
01045       double value            
01046     );
01047 
01052     PINDEX GetOptionEnum(
01053       const PString & name,   
01054       PINDEX dflt = 0         
01055     ) const;
01056 
01063     bool SetOptionEnum(
01064       const PString & name,   
01065       PINDEX value            
01066     );
01067 
01071     PString GetOptionString(
01072       const PString & name,                   
01073       const PString & dflt = PString::Empty() 
01074     ) const;
01075 
01082     bool SetOptionString(
01083       const PString & name,   
01084       const PString & value   
01085     );
01086 
01090     bool GetOptionOctets(
01091       const PString & name, 
01092       PBYTEArray & octets   
01093     ) const;
01094 
01101     bool SetOptionOctets(
01102       const PString & name,       
01103       const PBYTEArray & octets   
01104     );
01105     bool SetOptionOctets(
01106       const PString & name,       
01107       const BYTE * data,          
01108       PINDEX length               
01109     );
01110 
01113     static OpalMediaFormatList GetAllRegisteredMediaFormats();
01114     static void GetAllRegisteredMediaFormats(
01115       OpalMediaFormatList & copy    
01116     );
01117 
01121     static bool SetRegisteredMediaFormat(
01122       const OpalMediaFormat & mediaFormat  
01123     );
01124 
01128     bool AddOption(
01129       OpalMediaOption * option,
01130       BOOL overwrite = FALSE
01131     );
01132 
01136     bool HasOption(const PString & name) const
01137     { return FindOption(name) != NULL; }
01138 
01143     OpalMediaOption * FindOption(
01144       const PString & name
01145     ) const;
01146 
01152     virtual bool IsValidForProtocol(const PString & protocol) const;
01153 
01154     virtual time_t GetCodecBaseTime() const;
01155 
01156     virtual ostream & PrintOptions(ostream & strm) const;
01157 
01158   protected:
01159     RTP_DataFrame::PayloadTypes  rtpPayloadType;
01160     PString                      rtpEncodingName;
01161     unsigned                     defaultSessionID;
01162     PMutex                       media_format_mutex;
01163     PSortedList<OpalMediaOption> options;
01164     time_t codecBaseTime;
01165 
01166     friend class OpalMediaFormatList;
01167 };
01168 
01169 
01170 // A pair of macros to simplify cration of OpalMediFormat instances.
01171 
01172 #define OPAL_MEDIA_FORMAT(name, fullName, defaultSessionID, rtpPayloadType, encodingName, needsJitter, bandwidth, frameSize, frameTime, timeUnits) \
01173 const class name##_Class : public OpalMediaFormat \
01174 { \
01175   public: \
01176     name##_Class(); \
01177 } name; \
01178 name##_Class::name##_Class() \
01179       : OpalMediaFormat(fullName, defaultSessionID, rtpPayloadType, encodingName, needsJitter, bandwidth, frameSize, frameTime, timeUnits) \
01180 
01181 #if OPAL_AUDIO
01182 class OpalAudioFormat : public OpalMediaFormat
01183 {
01184   friend class OpalPluginCodecManager;
01185     PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
01186   public:
01187     OpalAudioFormat(
01188       const char * fullName,    
01189       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01190       const char * encodingName,
01191       PINDEX   frameSize,       
01192       unsigned frameTime,       
01193       unsigned rxFrames,        
01194       unsigned txFrames,        
01195       unsigned maxFrames = 256, 
01196       unsigned clockRate = 8000, 
01197       time_t timeStamp = 0       
01198     );
01199 
01200     static const PString & RxFramesPerPacketOption();
01201     static const PString & TxFramesPerPacketOption();
01202 };
01203 #endif
01204 
01205 #if OPAL_VIDEO
01206 class OpalVideoFormat : public OpalMediaFormat
01207 {
01208   friend class OpalPluginCodecManager;
01209     PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
01210   public:
01211     OpalVideoFormat(
01212       const char * fullName,    
01213       RTP_DataFrame::PayloadTypes rtpPayloadType, 
01214       const char * encodingName,
01215       unsigned frameWidth,      
01216       unsigned frameHeight,     
01217       unsigned frameRate,       
01218       unsigned bitRate,         
01219       time_t timeStamp = 0        
01220     );
01221 
01222     virtual PObject * Clone() const;
01223 
01224     virtual bool Merge(const OpalMediaFormat & mediaFormat);
01225 
01226     static const PString & FrameWidthOption();
01227     static const PString & FrameHeightOption();
01228     static const PString & EncodingQualityOption();
01229     static const PString & TargetBitRateOption();
01230     static const PString & DynamicVideoQualityOption();
01231     static const PString & AdaptivePacketDelayOption();
01232 };
01233 #endif
01234 
01235 // List of known media formats
01236 
01237 #define OPAL_PCM16          "PCM-16"
01238 #define OPAL_PCM16_16KHZ    "PCM-16-16kHz"
01239 #define OPAL_L16_MONO_8KHZ  "Linear-16-Mono-8kHz"
01240 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
01241 #define OPAL_G711_ULAW_64K  "G.711-uLaw-64k"
01242 #define OPAL_G711_ALAW_64K  "G.711-ALaw-64k"
01243 #define OPAL_G728           "G.728"
01244 #define OPAL_G729           "G.729"
01245 #define OPAL_G729A          "G.729A"
01246 #define OPAL_G729B          "G.729B"
01247 #define OPAL_G729AB         "G.729A/B"
01248 #define OPAL_G7231          "G.723.1"
01249 #define OPAL_G7231_6k3      OPAL_G7231
01250 #define OPAL_G7231_5k3      "G.723.1(5.3k)"
01251 #define OPAL_G7231A_6k3     "G.723.1A(6.3k)"
01252 #define OPAL_G7231A_5k3     "G.723.1A(5.3k)"
01253 #define OPAL_GSM0610        "GSM-06.10"
01254 #define OPAL_RFC2833        "UserInput/RFC2833"
01255 #define OPAL_CISCONSE       "NamedSignalEvent"
01256 
01257 #if OPAL_AUDIO
01258 extern const OpalAudioFormat & GetOpalPCM16();
01259 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
01260 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
01261 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
01262 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
01263 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
01264 extern const OpalAudioFormat & GetOpalG728();
01265 extern const OpalAudioFormat & GetOpalG729();
01266 extern const OpalAudioFormat & GetOpalG729A();
01267 extern const OpalAudioFormat & GetOpalG729B();
01268 extern const OpalAudioFormat & GetOpalG729AB();
01269 extern const OpalAudioFormat & GetOpalG7231_6k3();
01270 extern const OpalAudioFormat & GetOpalG7231_5k3();
01271 extern const OpalAudioFormat & GetOpalG7231A_6k3();
01272 extern const OpalAudioFormat & GetOpalG7231A_5k3();
01273 extern const OpalAudioFormat & GetOpalGSM0610();
01274 #endif
01275 
01276 extern const OpalMediaFormat & GetOpalRFC2833();
01277 extern const OpalMediaFormat & GetOpalCiscoNSE();
01278 
01279 #define OpalPCM16          GetOpalPCM16()
01280 #define OpalPCM16_16KHZ    GetOpalPCM16_16KHZ()
01281 #define OpalL16_MONO_8KHZ  GetOpalL16_MONO_8KHZ()
01282 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
01283 #define OpalG711_ULAW_64K  GetOpalG711_ULAW_64K()
01284 #define OpalG711_ALAW_64K  GetOpalG711_ALAW_64K()
01285 #define OpalG728           GetOpalG728()
01286 #define OpalG729           GetOpalG729()
01287 #define OpalG729A          GetOpalG729A()
01288 #define OpalG729B          GetOpalG729B()
01289 #define OpalG729AB         GetOpalG729AB()
01290 #define OpalG7231_6k3      GetOpalG7231_6k3()
01291 #define OpalG7231_5k3      GetOpalG7231_5k3()
01292 #define OpalG7231A_6k3     GetOpalG7231A_6k3()
01293 #define OpalG7231A_5k3     GetOpalG7231A_5k3()
01294 #define OpalGSM0610        GetOpalGSM0610()
01295 #define OpalRFC2833        GetOpalRFC2833()
01296 #define OpalCiscoNSE       GetOpalCiscoNSE()
01297 
01298 #define OpalL16Mono8kHz    OpalL16_MONO_8KHZ
01299 #define OpalL16Mono16kHz   OpalL16_MONO_16KHZ
01300 #define OpalG711uLaw       OpalG711_ULAW_64K
01301 #define OpalG711ALaw       OpalG711_ALAW_64K
01302 
01303 
01304 #ifdef _MSC_VER
01305 #if _MSC_VER < 1300
01306 #pragma warning(default:4663)
01307 #endif
01308 #endif
01309 
01310 #endif  // __OPAL_MEDIAFMT_H
01311 
01312 
01313 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:33:40 2008 for OPAL by  doxygen 1.5.1