00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 #ifndef __OPAL_MEDIAFMT_H
00143 #define __OPAL_MEDIAFMT_H
00144
00145 #ifdef P_USE_PRAGMA
00146 #pragma interface
00147 #endif
00148
00149
00150 #include "rtp.h"
00151
00152 #include <limits>
00153
00154 #ifdef min
00155 #undef min
00156 #endif
00157 #ifdef max
00158 #undef max
00159 #endif
00160
00161 class OpalMediaFormat;
00162
00163
00165
00168 class OpalMediaOption : public PObject
00169 {
00170 PCLASSINFO(OpalMediaOption, PObject);
00171 public:
00172 enum MergeType {
00173 NoMerge,
00174 MinMerge,
00175 MaxMerge,
00176 EqualMerge,
00177 NotEqualMerge,
00178 AlwaysMerge,
00179
00180
00181 AndMerge = MaxMerge,
00182 OrMerge = MinMerge,
00183 XorMerge = NotEqualMerge,
00184 NotXorMerge = EqualMerge
00185 };
00186
00187 protected:
00188 OpalMediaOption(
00189 const char * name,
00190 bool readOnly,
00191 MergeType merge
00192 );
00193
00194 public:
00195 virtual Comparison Compare(const PObject & obj) const;
00196
00197 bool Merge(
00198 const OpalMediaOption & option
00199 );
00200 virtual Comparison CompareValue(
00201 const OpalMediaOption & option
00202 ) const = 0;
00203 virtual void Assign(
00204 const OpalMediaOption & option
00205 ) = 0;
00206
00207 PString AsString() const;
00208 bool FromString(const PString & value);
00209
00210 const PString & GetName() const { return m_name; }
00211
00212 bool IsReadOnly() const { return m_readOnly; }
00213 void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
00214
00215 MergeType GetMerge() const { return m_merge; }
00216 void SetMerge(MergeType merge) { m_merge = merge; }
00217
00218 const PString & GetFMTPName() const { return m_FMTPName; }
00219 void SetFMTPName(const char * name) { m_FMTPName = name; }
00220
00221 const PString & GetFMTPDefault() const { return m_FMTPDefault; }
00222 void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
00223
00224 struct H245GenericInfo {
00225 unsigned ordinal:16;
00226 enum Modes {
00227 None,
00228 Collapsing,
00229 NonCollapsing
00230 } mode:3;
00231 enum IntegerTypes {
00232 UnsignedInt,
00233 Unsigned32,
00234 BooleanArray
00235 } integerType:3;
00236 bool excludeTCS:1;
00237 bool excludeOLC:1;
00238 bool excludeReqMode:1;
00239 };
00240
00241 const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
00242 void SetH245Generic(const H245GenericInfo & generic) { m_H245Generic = generic; }
00243
00244 protected:
00245 PCaselessString m_name;
00246 bool m_readOnly;
00247 MergeType m_merge;
00248 PCaselessString m_FMTPName;
00249 PString m_FMTPDefault;
00250 H245GenericInfo m_H245Generic;
00251 };
00252
00253 #ifndef __USE_STL__
00254 __inline istream & operator>>(istream & strm, bool& b)
00255 {
00256 int i;strm >> i;b = i; return strm;
00257 }
00258 #endif
00259
00260 template <typename T>
00261 class OpalMediaOptionValue : public OpalMediaOption
00262 {
00263 PCLASSINFO(OpalMediaOptionValue, OpalMediaOption);
00264 public:
00265 OpalMediaOptionValue(
00266 const char * name,
00267 bool readOnly,
00268 MergeType merge = MinMerge,
00269 T value = 0,
00270 T minimum = std::numeric_limits<T>::min(),
00271 T maximum = std::numeric_limits<T>::max()
00272 ) : OpalMediaOption(name, readOnly, merge),
00273 m_value(value),
00274 m_minimum(minimum),
00275 m_maximum(maximum)
00276 { }
00277
00278 virtual PObject * Clone() const
00279 {
00280 return new OpalMediaOptionValue(*this);
00281 }
00282
00283 virtual void PrintOn(ostream & strm) const
00284 {
00285 strm << m_value;
00286 }
00287
00288 virtual void ReadFrom(istream & strm)
00289 {
00290 T temp;
00291 strm >> temp;
00292 if (temp >= m_minimum && temp <= m_maximum)
00293 m_value = temp;
00294 else {
00295 #ifdef __USE_STL__
00296 strm.setstate(ios::badbit);
00297 #else
00298 strm.setf(ios::badbit , ios::badbit);
00299 #endif
00300 }
00301 }
00302
00303 virtual Comparison CompareValue(const OpalMediaOption & option) const {
00304 const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00305 if (otherOption == NULL)
00306 return GreaterThan;
00307 if (m_value < otherOption->m_value)
00308 return LessThan;
00309 if (m_value > otherOption->m_value)
00310 return GreaterThan;
00311 return EqualTo;
00312 }
00313
00314 virtual void Assign(
00315 const OpalMediaOption & option
00316 ) {
00317 const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00318 if (otherOption != NULL)
00319 m_value = otherOption->m_value;
00320 }
00321
00322 T GetValue() const { return m_value; }
00323 void SetValue(T value) { m_value = value; }
00324
00325 protected:
00326 T m_value;
00327 T m_minimum;
00328 T m_maximum;
00329 };
00330
00331
00332 typedef OpalMediaOptionValue<bool> OpalMediaOptionBoolean;
00333 typedef OpalMediaOptionValue<int> OpalMediaOptionInteger;
00334 typedef OpalMediaOptionValue<unsigned> OpalMediaOptionUnsigned;
00335 typedef OpalMediaOptionValue<double> OpalMediaOptionReal;
00336
00337
00338 class OpalMediaOptionEnum : public OpalMediaOption
00339 {
00340 PCLASSINFO(OpalMediaOptionEnum, OpalMediaOption);
00341 public:
00342 OpalMediaOptionEnum(
00343 const char * name,
00344 bool readOnly,
00345 const char * const * enumerations,
00346 PINDEX count,
00347 MergeType merge = EqualMerge,
00348 PINDEX value = 0
00349 );
00350
00351 virtual PObject * Clone() const;
00352 virtual void PrintOn(ostream & strm) const;
00353 virtual void ReadFrom(istream & strm);
00354
00355 virtual Comparison CompareValue(const OpalMediaOption & option) const;
00356 virtual void Assign(const OpalMediaOption & option);
00357
00358 PINDEX GetValue() const { return m_value; }
00359 void SetValue(PINDEX value);
00360
00361 protected:
00362 PStringArray m_enumerations;
00363 PINDEX m_value;
00364 };
00365
00366
00367 class OpalMediaOptionString : public OpalMediaOption
00368 {
00369 PCLASSINFO(OpalMediaOptionString, OpalMediaOption);
00370 public:
00371 OpalMediaOptionString(
00372 const char * name,
00373 bool readOnly
00374 );
00375 OpalMediaOptionString(
00376 const char * name,
00377 bool readOnly,
00378 const PString & value
00379 );
00380
00381 virtual PObject * Clone() const;
00382 virtual void PrintOn(ostream & strm) const;
00383 virtual void ReadFrom(istream & strm);
00384
00385 virtual Comparison CompareValue(const OpalMediaOption & option) const;
00386 virtual void Assign(const OpalMediaOption & option);
00387
00388 const PString & GetValue() const { return m_value; }
00389 void SetValue(const PString & value);
00390
00391 protected:
00392 PString m_value;
00393 };
00394
00395
00396 class OpalMediaOptionOctets : public OpalMediaOption
00397 {
00398 PCLASSINFO(OpalMediaOptionOctets, OpalMediaOption);
00399 public:
00400 OpalMediaOptionOctets(
00401 const char * name,
00402 bool readOnly,
00403 bool base64
00404 );
00405 OpalMediaOptionOctets(
00406 const char * name,
00407 bool readOnly,
00408 bool base64,
00409 const PBYTEArray & value
00410 );
00411 OpalMediaOptionOctets(
00412 const char * name,
00413 bool readOnly,
00414 bool base64,
00415 const BYTE * data,
00416 PINDEX length
00417 );
00418
00419 virtual PObject * Clone() const;
00420 virtual void PrintOn(ostream & strm) const;
00421 virtual void ReadFrom(istream & strm);
00422
00423 virtual Comparison CompareValue(const OpalMediaOption & option) const;
00424 virtual void Assign(const OpalMediaOption & option);
00425
00426 const PBYTEArray & GetValue() const { return m_value; }
00427 void SetValue(const PBYTEArray & value);
00428 void SetValue(const BYTE * data, PINDEX length);
00429
00430 protected:
00431 PBYTEArray m_value;
00432 bool m_base64;
00433 };
00434
00435
00437
00443 class OpalMediaFormat : public PCaselessString
00444 {
00445 PCLASSINFO(OpalMediaFormat, PCaselessString);
00446
00447 public:
00448 PLIST(List, OpalMediaFormat);
00449
00452 OpalMediaFormat();
00453
00458 OpalMediaFormat(
00459 const char * search,
00460 BOOL exact = TRUE
00461 );
00462
00467 BOOL IsValid() const { return rtpPayloadType <= RTP_DataFrame::MaxPayloadType; }
00468
00471 OpalMediaFormat & operator=(
00472 const OpalMediaFormat & fmt
00473 );
00474
00485 virtual bool Merge(
00486 const OpalMediaFormat & mediaFormat
00487 );
00488
00494 RTP_DataFrame::PayloadTypes GetPayloadType() const { return rtpPayloadType; }
00495
00496 void SetPayloadType(RTP_DataFrame::PayloadTypes type) { rtpPayloadType = type; }
00497 enum {
00498 FirstSessionID = 1,
00499 DefaultAudioSessionID = 1,
00500 DefaultVideoSessionID = 2,
00501 DefaultDataSessionID = 3,
00502 DefaultH224SessionID = 4,
00503 DefaultExtVideoSessionID = 5,
00504 LastSessionID = 5
00505 };
00506
00509 unsigned GetDefaultSessionID() const { return defaultSessionID; }
00510
00514 BOOL NeedsJitterBuffer() const { return needsJitter; }
00515
00518 unsigned GetBandwidth() const { return bandwidth; }
00519
00524 PINDEX GetFrameSize() const { return frameSize; }
00525 void SetFrameSize(PINDEX size) { frameSize = size; }
00526
00530 unsigned GetFrameTime() const { return frameTime; }
00531
00534 void SetFrameTime(unsigned ft) { frameTime = ft; }
00535
00538 virtual unsigned GetTimeUnits() const { return timeUnits; }
00539 virtual void SetTimeUnits(unsigned units) { timeUnits = units; }
00540
00541 enum StandardTimeUnits {
00542 AudioTimeUnits = 8,
00543 VideoTimeUnits = 90
00544 };
00545
00548 static List GetRegisteredMediaFormats();
00549 static void GetRegisteredMediaFormats(List & list);
00550
00551 friend class OpalStaticMediaFormat;
00552
00566 OpalMediaFormat(
00567 const char * fullName,
00568 unsigned defaultSessionID,
00569 RTP_DataFrame::PayloadTypes rtpPayloadType,
00570 BOOL needsJitter,
00571 unsigned bandwidth,
00572 PINDEX frameSize = 0,
00573 unsigned frameTime = 0,
00574 unsigned timeUnits = 0,
00575 time_t timeStamp = 0
00576
00577 );
00578
00579 bool GetOptionValue(
00580 const PString & name,
00581 PString & value
00582 ) const;
00583
00590 bool SetOptionValue(
00591 const PString & name,
00592 const PString & value
00593 );
00594
00598 bool GetOptionBoolean(
00599 const PString & name,
00600 bool dflt = FALSE
00601 ) const;
00602
00609 bool SetOptionBoolean(
00610 const PString & name,
00611 bool value
00612 );
00613
00617 int GetOptionInteger(
00618 const PString & name,
00619 int dflt = 0
00620 ) const;
00621
00629 bool SetOptionInteger(
00630 const PString & name,
00631 int value
00632 );
00633
00637 double GetOptionReal(
00638 const PString & name,
00639 double dflt = 0
00640 ) const;
00641
00648 bool SetOptionReal(
00649 const PString & name,
00650 double value
00651 );
00652
00657 PINDEX GetOptionEnum(
00658 const PString & name,
00659 PINDEX dflt = 0
00660 ) const;
00661
00668 bool SetOptionEnum(
00669 const PString & name,
00670 PINDEX value
00671 );
00672
00676 PString GetOptionString(
00677 const PString & name,
00678 const PString & dflt = PString::Empty()
00679 ) const;
00680
00687 bool SetOptionString(
00688 const PString & name,
00689 const PString & value
00690 );
00691
00695 bool GetOptionOctets(
00696 const PString & name,
00697 PBYTEArray & octets
00698 ) const;
00699
00706 bool SetOptionOctets(
00707 const PString & name,
00708 const PBYTEArray & octets
00709 );
00710 bool SetOptionOctets(
00711 const PString & name,
00712 const BYTE * data,
00713 PINDEX length
00714 );
00715
00719 static bool SetRegisteredMediaFormat(
00720 const OpalMediaFormat & mediaFormat
00721 );
00722
00726 bool AddOption(
00727 OpalMediaOption * option,
00728 BOOL overwrite = FALSE
00729 );
00730
00734 bool HasOption(const PString & name) const
00735 { return FindOption(name) != NULL; }
00736
00741 OpalMediaOption * FindOption(
00742 const PString & name
00743 ) const;
00744
00745 OpalMediaOption & GetOption(PINDEX i) const
00746 { return options[i]; }
00747
00748 PINDEX GetOptionCount() const
00749 { return options.GetSize(); }
00750
00751 #if PTRACING
00752 static void DebugOptionList(const OpalMediaFormat & fmt);
00753 #endif
00754
00755 protected:
00756 RTP_DataFrame::PayloadTypes rtpPayloadType;
00757 unsigned defaultSessionID;
00758 BOOL needsJitter;
00759 unsigned bandwidth;
00760 PINDEX frameSize;
00761 unsigned frameTime;
00762 unsigned timeUnits;
00763 PMutex media_format_mutex;
00764 PSortedList<OpalMediaOption> options;
00765 time_t codecBaseTime;
00766
00767 };
00768
00769 #ifdef H323_VIDEO
00770 class OpalVideoFormat : public OpalMediaFormat
00771 {
00772 friend class OpalPluginCodecManager;
00773 PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
00774 public:
00775 OpalVideoFormat(
00776 const char * fullName,
00777 RTP_DataFrame::PayloadTypes rtpPayloadType,
00778 unsigned frameWidth,
00779 unsigned frameHeight,
00780 unsigned frameRate,
00781 unsigned bitRate,
00782 time_t timeStamp = 0
00783 );
00784
00785 virtual PObject * Clone() const;
00786
00787 virtual bool Merge(const OpalMediaFormat & mediaFormat);
00788
00789 static const char * const FrameWidthOption;
00790 static const char * const FrameHeightOption;
00791 static const char * const EncodingQualityOption;
00792 static const char * const TargetBitRateOption;
00793 static const char * const DynamicVideoQualityOption;
00794 static const char * const AdaptivePacketDelayOption;
00795
00796 static const char * const NeedsJitterOption;
00797 static const char * const MaxBitRateOption;
00798 static const char * const MaxFrameSizeOption;
00799 static const char * const FrameTimeOption;
00800 static const char * const ClockRateOption;
00801
00802 };
00803 #endif
00804
00805
00806 #define OPAL_PCM16 "PCM-16"
00807 #define OPAL_G711_ULAW_64K "G.711-uLaw-64k"
00808 #define OPAL_G711_ALAW_64K "G.711-ALaw-64k"
00809 #define OPAL_G711_ULAW_56K "G.711-uLaw-56k"
00810 #define OPAL_G711_ALAW_56K "G.711-ALaw-56k"
00811 #define OPAL_G728 "G.728"
00812 #define OPAL_G729 "G.729"
00813 #define OPAL_G729A "G.729A"
00814 #define OPAL_G729B "G.729B"
00815 #define OPAL_G729AB "G.729A/B"
00816 #define OPAL_G7231 "G.723.1"
00817 #define OPAL_G7231_6k3 OPAL_G7231
00818 #define OPAL_G7231_5k3 "G.723.1(5.3k)"
00819 #define OPAL_G7231A_6k3 "G.723.1A(6.3k)"
00820 #define OPAL_G7231A_5k3 "G.723.1A(5.3k)"
00821 #define OPAL_GSM0610 "GSM-06.10"
00822
00823 extern char OpalPCM16[];
00824 extern char OpalG711uLaw64k[];
00825 extern char OpalG711ALaw64k[];
00826 extern char OpalG728[];
00827 extern char OpalG729[];
00828 extern char OpalG729A[];
00829 extern char OpalG729B[];
00830 extern char OpalG729AB[];
00831 extern char OpalG7231_6k3[];
00832 extern char OpalG7231_5k3[];
00833 extern char OpalG7231A_6k3[];
00834 extern char OpalG7231A_5k3[];
00835 extern char OpalGSM0610[];
00836
00837 #define OpalG711uLaw OpalG711uLaw64k
00838 #define OpalG711ALaw OpalG711ALaw64k
00839 #define OpalG7231 OpalG7231_6k3
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884 typedef PFactory<OpalMediaFormat, std::string> OpalMediaFormatFactory;
00885
00886 #define OPAL_MEDIA_FORMAT_DECLARE(classname, _fullName, _defaultSessionID, _rtpPayloadType, _needsJitter,_bandwidth, _frameSize, _frameTime, _timeUnits, _timeStamp) \
00887 class classname : public OpalMediaFormat \
00888 { \
00889 public: \
00890 classname() \
00891 : OpalMediaFormat(_fullName, _defaultSessionID, _rtpPayloadType, _needsJitter, _bandwidth, \
00892 _frameSize, _frameTime, _timeUnits, _timeStamp){} \
00893 }; \
00894 OpalMediaFormatFactory::Worker<classname> classname##Factory(_fullName, true); \
00895
00896
00897 #endif // __OPAL_MEDIAFMT_H
00898
00899
00900