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
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 #ifndef __OPAL_MEDIAFMT_H
00204 #define __OPAL_MEDIAFMT_H
00205
00206 #ifdef P_USE_PRAGMA
00207 #pragma interface
00208 #endif
00209
00210 #ifdef _MSC_VER
00211 #if _MSC_VER < 1300
00212 #pragma warning(disable:4663)
00213 #endif
00214 #endif
00215
00216 #include <opal/buildopts.h>
00217
00218 #include <rtp/rtp.h>
00219
00220 #include <limits>
00221
00222 #ifdef min
00223 #undef min
00224 #endif
00225 #ifdef max
00226 #undef max
00227 #endif
00228
00229 class OpalMediaFormat;
00230
00231
00233
00234 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
00235
00238 class OpalMediaFormatList : public OpalMediaFormatBaseList
00239 {
00240 PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
00241 public:
00246 OpalMediaFormatList();
00247
00250 OpalMediaFormatList(
00251 const OpalMediaFormat & format
00252 );
00253
00256 OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
00258
00264 OpalMediaFormatList & operator+=(
00265 const OpalMediaFormat & format
00266 );
00267
00271 OpalMediaFormatList & operator+=(
00272 const OpalMediaFormatList & formats
00273 );
00274
00278 OpalMediaFormatList & operator-=(
00279 const OpalMediaFormat & format
00280 );
00281
00285 OpalMediaFormatList & operator-=(
00286 const OpalMediaFormatList & formats
00287 );
00288
00293 PINDEX FindFormat(
00294 RTP_DataFrame::PayloadTypes rtpPayloadType,
00295 const unsigned clockRate,
00296 const char * rtpEncodingName = NULL
00297 ) const;
00298
00306 PINDEX FindFormat(
00307 const PString & wildcard
00308 ) const;
00309
00312 BOOL HasFormat(
00313 RTP_DataFrame::PayloadTypes rtpPayloadType
00314 ) const { return FindFormat(rtpPayloadType) != P_MAX_INDEX; }
00315
00321 BOOL HasFormat(
00322 const PString & wildcard
00323 ) const { return FindFormat(wildcard) != P_MAX_INDEX; }
00324
00327 void Remove(
00328 const PStringArray & mask
00329 );
00330
00335 void Reorder(
00336 const PStringArray & order
00337 );
00339
00340 private:
00341 virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
00342 virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
00343 virtual PINDEX InsertAt(PINDEX, PObject *) { return P_MAX_INDEX; }
00344 virtual BOOL SetAt(PINDEX, PObject *) { return FALSE; }
00345 };
00346
00347
00349
00352 class OpalMediaOption : public PObject
00353 {
00354 PCLASSINFO(OpalMediaOption, PObject);
00355 public:
00356 enum MergeType {
00357 NoMerge,
00358 MinMerge,
00359 MaxMerge,
00360 EqualMerge,
00361 NotEqualMerge,
00362 AlwaysMerge,
00363
00364
00365 AndMerge = MaxMerge,
00366 OrMerge = MinMerge,
00367 XorMerge = NotEqualMerge,
00368 NotXorMerge = EqualMerge
00369 };
00370
00371 protected:
00372 OpalMediaOption(
00373 const char * name,
00374 bool readOnly,
00375 MergeType merge
00376 );
00377
00378 public:
00379 virtual Comparison Compare(const PObject & obj) const;
00380
00381 bool Merge(
00382 const OpalMediaOption & option
00383 );
00384 virtual Comparison CompareValue(
00385 const OpalMediaOption & option
00386 ) const = 0;
00387 virtual void Assign(
00388 const OpalMediaOption & option
00389 ) = 0;
00390
00391 PString AsString() const;
00392 bool FromString(const PString & value);
00393
00394 const PString & GetName() const { return m_name; }
00395
00396 bool IsReadOnly() const { return m_readOnly; }
00397 void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
00398
00399 MergeType GetMerge() const { return m_merge; }
00400 void SetMerge(MergeType merge) { m_merge = merge; }
00401
00402 protected:
00403 PString m_name;
00404 bool m_readOnly;
00405 MergeType m_merge;
00406 };
00407
00408 #ifndef __USE_STL__
00409 __inline istream & operator>>(istream & strm, bool& b)
00410 {
00411 int i;strm >> i;b = i; return strm;
00412 }
00413 #endif
00414
00415 template <typename T>
00416 class OpalMediaOptionValue : public OpalMediaOption
00417 {
00418 PCLASSINFO(OpalMediaOptionValue, OpalMediaOption);
00419 public:
00420 OpalMediaOptionValue(
00421 const char * name,
00422 bool readOnly,
00423 MergeType merge = MinMerge,
00424 T value = 0,
00425 T minimum = std::numeric_limits<T>::min(),
00426 T maximum = std::numeric_limits<T>::max()
00427 ) : OpalMediaOption(name, readOnly, merge),
00428 m_value(value),
00429 m_minimum(minimum),
00430 m_maximum(maximum)
00431 { }
00432
00433 virtual PObject * Clone() const
00434 {
00435 return new OpalMediaOptionValue(*this);
00436 }
00437
00438 virtual void PrintOn(ostream & strm) const
00439 {
00440 strm << m_value;
00441 }
00442
00443 virtual void ReadFrom(istream & strm)
00444 {
00445 T temp;
00446 strm >> temp;
00447 if (temp >= m_minimum && temp <= m_maximum)
00448 m_value = temp;
00449 else {
00450 #ifdef __USE_STL__
00451 strm.setstate(ios::badbit);
00452 #else
00453 strm.setf(ios::badbit , ios::badbit);
00454 #endif
00455 }
00456 }
00457
00458 virtual Comparison CompareValue(const OpalMediaOption & option) const {
00459 const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00460 if (otherOption == NULL)
00461 return GreaterThan;
00462 if (m_value < otherOption->m_value)
00463 return LessThan;
00464 if (m_value > otherOption->m_value)
00465 return GreaterThan;
00466 return EqualTo;
00467 }
00468
00469 virtual void Assign(
00470 const OpalMediaOption & option
00471 ) {
00472 const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
00473 if (otherOption != NULL)
00474 m_value = otherOption->m_value;
00475 }
00476
00477 T GetValue() const { return m_value; }
00478 void SetValue(T value) { m_value = value; }
00479
00480 protected:
00481 T m_value;
00482 T m_minimum;
00483 T m_maximum;
00484 };
00485
00486
00487 typedef OpalMediaOptionValue<bool> OpalMediaOptionBoolean;
00488 typedef OpalMediaOptionValue<int> OpalMediaOptionInteger;
00489 typedef OpalMediaOptionValue<double> OpalMediaOptionReal;
00490
00491
00492 class OpalMediaOptionEnum : public OpalMediaOption
00493 {
00494 PCLASSINFO(OpalMediaOptionEnum, OpalMediaOption);
00495 public:
00496 OpalMediaOptionEnum(
00497 const char * name,
00498 bool readOnly,
00499 const char * const * enumerations,
00500 PINDEX count,
00501 MergeType merge = EqualMerge,
00502 PINDEX value = 0
00503 );
00504
00505 virtual PObject * Clone() const;
00506 virtual void PrintOn(ostream & strm) const;
00507 virtual void ReadFrom(istream & strm);
00508
00509 virtual Comparison CompareValue(const OpalMediaOption & option) const;
00510 virtual void Assign(const OpalMediaOption & option);
00511
00512 PINDEX GetValue() const { return m_value; }
00513 void SetValue(PINDEX value);
00514
00515 protected:
00516 PStringArray m_enumerations;
00517 PINDEX m_value;
00518 };
00519
00520
00521 class OpalMediaOptionString : public OpalMediaOption
00522 {
00523 PCLASSINFO(OpalMediaOptionString, OpalMediaOption);
00524 public:
00525 OpalMediaOptionString(
00526 const char * name,
00527 bool readOnly
00528 );
00529 OpalMediaOptionString(
00530 const char * name,
00531 bool readOnly,
00532 const PString & value
00533 );
00534
00535 virtual PObject * Clone() const;
00536 virtual void PrintOn(ostream & strm) const;
00537 virtual void ReadFrom(istream & strm);
00538
00539 virtual Comparison CompareValue(const OpalMediaOption & option) const;
00540 virtual void Assign(const OpalMediaOption & option);
00541
00542 const PString & GetValue() const { return m_value; }
00543 void SetValue(const PString & value);
00544
00545 protected:
00546 PString m_value;
00547 };
00548
00549
00551
00559 class OpalMediaFormat : public PCaselessString
00560 {
00561 PCLASSINFO(OpalMediaFormat, PCaselessString);
00562
00563 public:
00566 OpalMediaFormat();
00567
00581 OpalMediaFormat(
00582 const char * fullName,
00583 unsigned defaultSessionID,
00584 RTP_DataFrame::PayloadTypes rtpPayloadType,
00585 const char * encodingName,
00586 BOOL needsJitter,
00587 unsigned bandwidth,
00588 PINDEX frameSize,
00589 unsigned frameTime,
00590 unsigned clockRate
00591 );
00592
00602 OpalMediaFormat(
00603 RTP_DataFrame::PayloadTypes rtpPayloadType,
00604 unsigned clockRate,
00605 const char * rtpEncodingName = NULL
00606 );
00607
00621 OpalMediaFormat(
00622 const char * wildcard
00623 );
00624
00638 OpalMediaFormat(
00639 const PString & wildcard
00640 );
00641
00645 OpalMediaFormat & operator=(
00646 RTP_DataFrame::PayloadTypes rtpPayloadType
00647 );
00648
00652 OpalMediaFormat & operator=(
00653 const char * wildcard
00654 );
00655
00659 OpalMediaFormat & operator=(
00660 const PString & wildcard
00661 );
00662
00673 virtual bool Merge(
00674 const OpalMediaFormat & mediaFormat
00675 );
00676
00682 RTP_DataFrame::PayloadTypes GetPayloadType() const { return rtpPayloadType; }
00683
00686 const char * GetEncodingName() const { return rtpEncodingName; }
00687
00688 enum {
00689 DefaultAudioSessionID = 1,
00690 DefaultVideoSessionID = 2,
00691 DefaultDataSessionID = 3
00692 };
00693
00696 unsigned GetDefaultSessionID() const { return defaultSessionID; }
00697
00701 bool NeedsJitterBuffer() const { return GetOptionBoolean(NeedsJitterOption); }
00702 static const char * const NeedsJitterOption;
00703
00706 unsigned GetBandwidth() const { return GetOptionInteger(MaxBitRateOption); }
00707 static const char * const MaxBitRateOption;
00708
00713 PINDEX GetFrameSize() const { return GetOptionInteger(MaxFrameSizeOption); }
00714 static const char * const MaxFrameSizeOption;
00715
00719 unsigned GetFrameTime() const { return GetOptionInteger(FrameTimeOption); }
00720 static const char * const FrameTimeOption;
00721
00724 unsigned GetTimeUnits() const { return GetClockRate()/1000; }
00725
00726 enum StandardClockRate {
00727 AudioClockRate = 8000,
00728 VideoClockRate = 90000
00729 };
00730
00733 unsigned GetClockRate() const { return GetOptionInteger(ClockRateOption); }
00734 static const char * const ClockRateOption;
00735
00738 PINDEX GetOptionCount() const { return options.GetSize(); }
00739
00743 const OpalMediaOption & GetOption(
00744 PINDEX index
00745 ) { return options[index]; }
00746
00751 bool GetOptionValue(
00752 const PString & name,
00753 PString & value
00754 ) const;
00755
00762 bool SetOptionValue(
00763 const PString & name,
00764 const PString & value
00765 );
00766
00770 bool GetOptionBoolean(
00771 const PString & name,
00772 bool dflt = FALSE
00773 ) const;
00774
00781 bool SetOptionBoolean(
00782 const PString & name,
00783 bool value
00784 );
00785
00789 int GetOptionInteger(
00790 const PString & name,
00791 int dflt = 0
00792 ) const;
00793
00801 bool SetOptionInteger(
00802 const PString & name,
00803 int value
00804 );
00805
00809 double GetOptionReal(
00810 const PString & name,
00811 double dflt = 0
00812 ) const;
00813
00820 bool SetOptionReal(
00821 const PString & name,
00822 double value
00823 );
00824
00829 PINDEX GetOptionEnum(
00830 const PString & name,
00831 PINDEX dflt = 0
00832 ) const;
00833
00840 bool SetOptionEnum(
00841 const PString & name,
00842 PINDEX value
00843 );
00844
00848 PString GetOptionString(
00849 const PString & name,
00850 const PString & dflt = PString::Empty()
00851 ) const;
00852
00859 bool SetOptionString(
00860 const PString & name,
00861 const PString & value
00862 );
00863
00866 static OpalMediaFormatList GetAllRegisteredMediaFormats();
00867 static void GetAllRegisteredMediaFormats(
00868 OpalMediaFormatList & copy
00869 );
00870
00874 static bool SetRegisteredMediaFormat(
00875 const OpalMediaFormat & mediaFormat
00876 );
00877
00878 protected:
00879 bool AddOption(
00880 OpalMediaOption * option
00881 );
00882
00883 OpalMediaOption * FindOption(
00884 const PString & name
00885 ) const;
00886
00887 RTP_DataFrame::PayloadTypes rtpPayloadType;
00888 const char * rtpEncodingName;
00889 unsigned defaultSessionID;
00890 PSortedList<OpalMediaOption> options;
00891
00892 friend class OpalMediaFormatList;
00893 };
00894
00895
00896
00897
00898 #define OPAL_MEDIA_FORMAT(name, fullName, defaultSessionID, rtpPayloadType, encodingName, needsJitter, bandwidth, frameSize, frameTime, timeUnits) \
00899 const class name##_Class : public OpalMediaFormat \
00900 { \
00901 public: \
00902 name##_Class(); \
00903 } name; \
00904 name##_Class::name##_Class() \
00905 : OpalMediaFormat(fullName, defaultSessionID, rtpPayloadType, encodingName, needsJitter, bandwidth, frameSize, frameTime, timeUnits) \
00906
00907
00908 class OpalAudioFormat : public OpalMediaFormat
00909 {
00910 PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
00911 public:
00912 OpalAudioFormat(
00913 const char * fullName,
00914 RTP_DataFrame::PayloadTypes rtpPayloadType,
00915 const char * encodingName,
00916 PINDEX frameSize,
00917 unsigned frameTime,
00918 unsigned rxFrames,
00919 unsigned txFrames,
00920 unsigned maxFrames = 256,
00921 unsigned clockRate = 8000
00922 );
00923
00924 static const char * const RxFramesPerPacketOption;
00925 static const char * const TxFramesPerPacketOption;
00926 };
00927
00928
00929 class OpalVideoFormat : public OpalMediaFormat
00930 {
00931 PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
00932 public:
00933 OpalVideoFormat(
00934 const char * fullName,
00935 RTP_DataFrame::PayloadTypes rtpPayloadType,
00936 const char * encodingName,
00937 unsigned frameWidth,
00938 unsigned frameHeight,
00939 unsigned frameRate,
00940 unsigned bitRate
00941 );
00942
00943 virtual bool Merge(const OpalMediaFormat & mediaFormat);
00944
00945 static const char * const FrameWidthOption;
00946 static const char * const FrameHeightOption;
00947 static const char * const EncodingQualityOption;
00948 static const char * const TargetBitRateOption;
00949 static const char * const DynamicVideoQualityOption;
00950 static const char * const AdaptivePacketDelayOption;
00951 };
00952
00953
00954
00955
00956 #define OPAL_PCM16 "PCM-16"
00957 #define OPAL_L16_MONO_8KHZ "Linear-16-Mono-8kHz"
00958 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
00959 #define OPAL_G711_ULAW_64K "G.711-uLaw-64k"
00960 #define OPAL_G711_ALAW_64K "G.711-ALaw-64k"
00961 #define OPAL_G728 "G.728"
00962 #define OPAL_G729 "G.729"
00963 #define OPAL_G729A "G.729A"
00964 #define OPAL_G729B "G.729B"
00965 #define OPAL_G729AB "G.729A/B"
00966 #define OPAL_G7231 "G.723.1"
00967 #define OPAL_G7231_6k3 OPAL_G7231
00968 #define OPAL_G7231_5k3 "G.723.1(5.3k)"
00969 #define OPAL_G7231A_6k3 "G.723.1A(6.3k)"
00970 #define OPAL_G7231A_5k3 "G.723.1A(5.3k)"
00971 #define OPAL_GSM0610 "GSM-06.10"
00972 #define OPAL_RFC2833 "UserInput/RFC2833"
00973
00974 extern const OpalAudioFormat & GetOpalPCM16();
00975 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
00976 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
00977 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
00978 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
00979 extern const OpalAudioFormat & GetOpalG728();
00980 extern const OpalAudioFormat & GetOpalG729();
00981 extern const OpalAudioFormat & GetOpalG729A();
00982 extern const OpalAudioFormat & GetOpalG729B();
00983 extern const OpalAudioFormat & GetOpalG729AB();
00984 extern const OpalAudioFormat & GetOpalG7231_6k3();
00985 extern const OpalAudioFormat & GetOpalG7231_5k3();
00986 extern const OpalAudioFormat & GetOpalG7231A_6k3();
00987 extern const OpalAudioFormat & GetOpalG7231A_5k3();
00988 extern const OpalAudioFormat & GetOpalGSM0610();
00989 extern const OpalMediaFormat & GetOpalRFC2833();
00990
00991 #define OpalPCM16 GetOpalPCM16()
00992 #define OpalL16_MONO_8KHZ GetOpalL16_MONO_8KHZ()
00993 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
00994 #define OpalG711_ULAW_64K GetOpalG711_ULAW_64K()
00995 #define OpalG711_ALAW_64K GetOpalG711_ALAW_64K()
00996 #define OpalG728 GetOpalG728()
00997 #define OpalG729 GetOpalG729()
00998 #define OpalG729A GetOpalG729A()
00999 #define OpalG729B GetOpalG729B()
01000 #define OpalG729AB GetOpalG729AB()
01001 #define OpalG7231_6k3 GetOpalG7231_6k3()
01002 #define OpalG7231_5k3 GetOpalG7231_5k3()
01003 #define OpalG7231A_6k3 GetOpalG7231A_6k3()
01004 #define OpalG7231A_5k3 GetOpalG7231A_5k3()
01005 #define OpalGSM0610 GetOpalGSM0610()
01006 #define OpalRFC2833 GetOpalRFC2833()
01007
01008 #define OpalL16Mono8kHz OpalL16_MONO_8KHZ
01009 #define OpalL16Mono16kHz OpalL16_MONO_16KHZ
01010 #define OpalG711uLaw OpalG711_ULAW_64K
01011 #define OpalG711ALaw OpalG711_ALAW_64K
01012
01013 #ifdef _MSC_VER
01014 #if _MSC_VER < 1300
01015 #pragma warning(default:4663)
01016 #endif
01017 #endif
01018
01019 #endif // __OPAL_MEDIAFMT_H
01020
01021
01022