OPAL  Version 3.10.4
mediafmt.h
Go to the documentation of this file.
1 /*
2  * mediafmt.h
3  *
4  * Media Format descriptions
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open H323 Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  *
27  * $Revision: 26920 $
28  * $Author: rjongbloed $
29  * $Date: 2012-01-31 23:02:10 -0600 (Tue, 31 Jan 2012) $
30  */
31 
32 #ifndef OPAL_OPAL_MEDIAFMT_H
33 #define OPAL_OPAL_MEDIAFMT_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #ifdef _MSC_VER
40 #if _MSC_VER < 1300
41 #pragma warning(disable:4663)
42 #endif
43 #endif
44 
45 #include <opal/buildopts.h>
46 
47 #include <opal/mediatype.h>
48 #include <rtp/rtp.h>
49 
50 #if OPAL_VIDEO
51 #include <ptlib/videoio.h>
52 #endif
53 
54 #include <limits>
55 
56 #ifdef min
57 #undef min
58 #endif
59 #ifdef max
60 #undef max
61 #endif
62 
63 class OpalMediaFormat;
64 
65 
67 
68 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
69 
72 class OpalMediaFormatList : public OpalMediaFormatBaseList
73 {
74  PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
75  public:
81 
85  const OpalMediaFormat & format
86  );
87 
90  OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
92 
99  const char * wildcard
100  ) { PConstString s(wildcard); return operator+=(s); }
101 
106  const PString & wildcard
107  );
108 
113  const OpalMediaFormat & format
114  );
115 
120  const OpalMediaFormatList & formats
121  );
122 
127  const OpalMediaFormat & format
128  );
129 
134  const OpalMediaFormatList & formats
135  );
136 
142  const_iterator FindFormat(
143  RTP_DataFrame::PayloadTypes rtpPayloadType,
144  const unsigned clockRate,
145  const char * rtpEncodingName = NULL,
146  const char * protocol = NULL,
147  const_iterator start = const_iterator()
148  ) const;
149 
166  const_iterator FindFormat(
167  const PString & wildcard,
168  const_iterator start = const_iterator()
169  ) const;
170 
173  PBoolean HasFormat(
174  RTP_DataFrame::PayloadTypes rtpPayloadType
175  ) const { return FindFormat(rtpPayloadType) != end(); }
176 
182  PBoolean HasFormat(
183  const PString & wildcard
184  ) const { return FindFormat(wildcard) != end(); }
185 
204  void Remove(
205  const PStringArray & mask
206  );
207 
223  void Reorder(
224  const PStringArray & order
225  );
226 
229  bool HasType(
230  const OpalMediaType & type,
231  bool mustBeTransportable = true
232  ) const;
234 
235  private:
236  virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
237  virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
238  virtual PINDEX InsertAt(PINDEX, PObject *) { return P_MAX_INDEX; }
239  virtual PBoolean SetAt(PINDEX, PObject *) { return false; }
240 };
241 
242 
244 
247 class OpalMediaOption : public PObject
248 {
249  PCLASSINFO(OpalMediaOption, PObject);
250  public:
251  // Note the below enum must be identical to PluginCodec_OptionMerge in opalplugin.h
252  enum MergeType {
260  IntersectionMerge, // Set intersection, applies to numeric (bit wise AND) or string (common substrings)
261 
262  // Synonyms
263  AndMerge = MinMerge, // Applies to Boolean option or Enum with two elements
264  OrMerge = MaxMerge // Applies to Boolean option or Enum with two elements
265  };
266 
267  protected:
269  const PString & name
270  );
272  const char * name,
273  bool readOnly,
274  MergeType merge
275  );
276 
277  public:
278  virtual Comparison Compare(const PObject & obj) const;
279 
280  virtual bool Merge(
281  const OpalMediaOption & option
282  );
283 
284  virtual bool ValidateMerge(
285  const OpalMediaOption & option
286  ) const;
287 
288  virtual Comparison CompareValue(
289  const OpalMediaOption & option
290  ) const = 0;
291  virtual void Assign(
292  const OpalMediaOption & option
293  ) = 0;
294 
295  PString AsString() const;
296  bool FromString(const PString & value);
297 
298  const PString & GetName() const { return m_name; }
299 
300  bool IsReadOnly() const { return m_readOnly; }
301  void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
302 
303  MergeType GetMerge() const { return m_merge; }
304  void SetMerge(MergeType merge) { m_merge = merge; }
305 
306 #if OPAL_SIP
307  const PString & GetFMTPName() const { return m_FMTPName; }
308  void SetFMTPName(const char * name) { m_FMTPName = name; }
309 
310  const PString & GetFMTPDefault() const { return m_FMTPDefault; }
311  void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
312 #endif // OPAL_SIP
313 
314 #if OPAL_H323
316  H245GenericInfo() { memset(this, 0, sizeof(*this)); }
317  unsigned ordinal:16;
318  enum Modes {
322  } mode:3;
327  } integerType:3;
328  bool excludeTCS:1;
329  bool excludeOLC:1;
331  };
332 
333  const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
334  void SetH245Generic(const H245GenericInfo & genericInfo) { m_H245Generic = genericInfo; }
335 #endif // OPAL_H323
336 
337  protected:
338  PCaselessString m_name;
341 
342 #if OPAL_SIP
343  PCaselessString m_FMTPName;
344  PString m_FMTPDefault;
345 #endif // OPAL_SIP
346 
347 #if OPAL_H323
349 #endif // OPAL_H323
350 };
351 
352 
353 template <typename T>
355 {
357  public:
359  const char * name,
360  bool readOnly,
362  T value = T()
363  )
364  : OpalMediaOption(name, readOnly, merge)
365  , m_value(value)
366  {
367  }
368 
369  virtual PObject * Clone() const
370  {
371  return new OpalMediaOptionValue(*this);
372  }
373 
374  virtual void PrintOn(ostream & strm) const
375  {
376  strm << m_value;
377  }
378 
379  virtual void ReadFrom(istream & strm)
380  {
381  strm >> m_value;
382  }
383 
384  virtual bool Merge(const OpalMediaOption & option)
385  {
386  if (m_merge != IntersectionMerge)
387  return OpalMediaOption::Merge(option);
388 
389  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
390  if (otherOption == NULL)
391  return false;
392 
393  m_value &= otherOption->m_value;
394  return true;
395  }
396 
397  virtual Comparison CompareValue(const OpalMediaOption & option) const
398  {
399  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
400  if (otherOption == NULL)
401  return GreaterThan;
402  if (m_value < otherOption->m_value)
403  return LessThan;
404  if (m_value > otherOption->m_value)
405  return GreaterThan;
406  return EqualTo;
407  }
408 
409  virtual void Assign(const OpalMediaOption & option)
410  {
411  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
412  if (otherOption != NULL)
413  m_value = otherOption->m_value;
414  }
415 
416  T GetValue() const
417  {
418  return m_value;
419  }
420 
421  void SetValue(T value)
422  {
423  m_value = value;
424  }
425 
426  protected:
428 };
429 
430 
431 template <typename T>
433 {
436  public:
438  const char * name,
439  bool readOnly,
441  T value = 0,
442  T minimum = std::numeric_limits<T>::min(),
443  T maximum = std::numeric_limits<T>::max()
444  )
445  : BaseClass(name, readOnly, merge, value)
446  , m_minimum(minimum)
447  , m_maximum(maximum)
448  {
449  }
450 
451  virtual PObject * Clone() const
452  {
453  return new OpalMediaOptionNumericalValue(*this);
454  }
455 
456  virtual void ReadFrom(istream & strm)
457  {
458  T temp = 0;
459  strm >> temp;
460  if (strm.fail())
461  return;
462  if (temp >= m_minimum && temp <= m_maximum)
463  this->m_value = temp;
464  else
465  strm.setstate(ios::badbit);
466  }
467 
468  void SetValue(T value)
469  {
470  if (value < m_minimum)
471  this->m_value = m_minimum;
472  else if (value > m_maximum)
473  this->m_value = m_maximum;
474  else
475  this->m_value = value;
476  }
477 
478  void SetMinimum(T m)
479  {
480  this->m_minimum = m;
481  }
482 
483  void SetMaximum(T m)
484  {
485  this->m_maximum = m;
486  }
487 
488  protected:
491 };
492 
493 
497 
498 // Wrapper class so we can implement intersection (&= operator) for floating point
500 {
501  double m_value;
502  public:
503  OpalMediaOptionRealValue(double value = 0) : m_value(value) { }
504  operator double() const { return m_value; }
505  void operator&=(double other) { if (m_value > other) m_value = other; }
506  friend ostream & operator<<(ostream & strm, const OpalMediaOptionRealValue & value) { return strm << value.m_value; }
507  friend istream & operator>>(istream & strm, OpalMediaOptionRealValue & value) { return strm >> value.m_value; }
508 };
509 
511 
512 
514 {
516  public:
518  const char * name,
519  bool readOnly
520  );
522  const char * name,
523  bool readOnly,
524  const char * const * enumerations,
525  PINDEX count,
526  MergeType merge = EqualMerge,
527  PINDEX value = 0
528  );
529 
530  virtual PObject * Clone() const;
531  virtual void PrintOn(ostream & strm) const;
532  virtual void ReadFrom(istream & strm);
533 
534  virtual Comparison CompareValue(const OpalMediaOption & option) const;
535  virtual void Assign(const OpalMediaOption & option);
536 
537  PINDEX GetValue() const { return m_value; }
538  void SetValue(PINDEX value);
539 
540  const PStringArray & GetEnumerations() const { return m_enumerations; }
541  void SetEnumerations(const PStringArray & e)
542  {
543  m_enumerations = e;
544  }
545 
546  protected:
547  PStringArray m_enumerations;
548  PINDEX m_value;
549 };
550 
551 
553 {
555  public:
557  const char * name,
558  bool readOnly
559  );
561  const char * name,
562  bool readOnly,
563  const PString & value
564  );
565 
566  virtual PObject * Clone() const;
567  virtual void PrintOn(ostream & strm) const;
568  virtual void ReadFrom(istream & strm);
569 
570  virtual bool Merge(const OpalMediaOption & option);
571  virtual Comparison CompareValue(const OpalMediaOption & option) const;
572  virtual void Assign(const OpalMediaOption & option);
573 
574  const PString & GetValue() const { return m_value; }
575  void SetValue(const PString & value);
576 
577  protected:
578  PString m_value;
579 };
580 
581 
583 {
585  public:
587  const char * name,
588  bool readOnly,
589  bool base64 = false
590  );
592  const char * name,
593  bool readOnly,
594  bool base64,
595  const PBYTEArray & value
596  );
598  const char * name,
599  bool readOnly,
600  bool base64,
601  const BYTE * data,
602  PINDEX length
603  );
604 
605  virtual PObject * Clone() const;
606  virtual void PrintOn(ostream & strm) const;
607  virtual void ReadFrom(istream & strm);
608 
609  virtual Comparison CompareValue(const OpalMediaOption & option) const;
610  virtual void Assign(const OpalMediaOption & option);
611 
612  const PBYTEArray & GetValue() const { return m_value; }
613  void SetValue(const PBYTEArray & value);
614  void SetValue(const BYTE * data, PINDEX length);
615 
616  void SetBase64(bool b)
617  {
618  m_base64 = b;
619  }
620 
621  protected:
622  PBYTEArray m_value;
623  bool m_base64;
624 };
625 
626 
628 
629 class OpalMediaFormatInternal : public PObject
630 {
631  PCLASSINFO(OpalMediaFormatInternal, PObject);
632  public:
634  const char * fullName,
635  const OpalMediaType & mediaType,
636  RTP_DataFrame::PayloadTypes rtpPayloadType,
637  const char * encodingName,
638  PBoolean needsJitter,
639  unsigned bandwidth,
640  PINDEX frameSize,
641  unsigned frameTime,
642  unsigned clockRate,
643  time_t timeStamp
644  );
645 
646  const PCaselessString & GetName() const { return formatName; }
647 
648  virtual PObject * Clone() const;
649  virtual void PrintOn(ostream & strm) const;
650 
651  virtual bool IsValid() const;
652  virtual bool IsTransportable() const;
653 
654  virtual PStringToString GetOptions() const;
655  virtual bool GetOptionValue(const PString & name, PString & value) const;
656  virtual bool SetOptionValue(const PString & name, const PString & value);
657  virtual bool GetOptionBoolean(const PString & name, bool dflt) const;
658  virtual bool SetOptionBoolean(const PString & name, bool value);
659  virtual int GetOptionInteger(const PString & name, int dflt) const;
660  virtual bool SetOptionInteger(const PString & name, int value);
661  virtual double GetOptionReal(const PString & name, double dflt) const;
662  virtual bool SetOptionReal(const PString & name, double value);
663  virtual PINDEX GetOptionEnum(const PString & name, PINDEX dflt) const;
664  virtual bool SetOptionEnum(const PString & name, PINDEX value);
665  virtual PString GetOptionString(const PString & name, const PString & dflt) const;
666  virtual bool SetOptionString(const PString & name, const PString & value);
667  virtual bool GetOptionOctets(const PString & name, PBYTEArray & octets) const;
668  virtual bool SetOptionOctets(const PString & name, const PBYTEArray & octets);
669  virtual bool SetOptionOctets(const PString & name, const BYTE * data, PINDEX length);
670  virtual bool AddOption(OpalMediaOption * option, PBoolean overwrite = false);
671  virtual OpalMediaOption * FindOption(const PString & name) const;
672 
673  virtual bool ToNormalisedOptions();
674  virtual bool ToCustomisedOptions();
675  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
676 
677  virtual bool ValidateMerge(const OpalMediaFormatInternal & mediaFormat) const;
678 
679  virtual bool IsValidForProtocol(const PString & protocol) const;
680 
681  protected:
682  PCaselessString formatName;
687  PSortedList<OpalMediaOption> options;
691 
692  friend bool operator==(const char * other, const OpalMediaFormat & fmt);
693  friend bool operator!=(const char * other, const OpalMediaFormat & fmt);
694  friend bool operator==(const PString & other, const OpalMediaFormat & fmt);
695  friend bool operator!=(const PString & other, const OpalMediaFormat & fmt);
696 
697  friend class OpalMediaFormat;
698  friend class OpalMediaFormatList;
700 };
701 
702 
704 
710 class OpalMediaFormat : public PContainer
711 {
712  PCLASSINFO(OpalMediaFormat, PContainer)
713  public:
714  OpalMediaFormat(const OpalMediaFormat & c);
715  virtual ~OpalMediaFormat();
716  OpalMediaFormat & operator=(const OpalMediaFormat & c) { AssignContents(c); return *this; }
717  virtual PBoolean MakeUnique();
718  protected:
719  virtual void DestroyContents();
720  virtual void AssignContents(const PContainer & c);
721 
722  public:
726  OpalMediaFormatInternal * info = NULL
727  );
728 
743  const char * fullName,
744  const OpalMediaType & mediaType,
745  RTP_DataFrame::PayloadTypes rtpPayloadType,
746  const char * encodingName,
747  PBoolean needsJitter,
748  unsigned bandwidth,
749  PINDEX frameSize,
750  unsigned frameTime,
751  unsigned clockRate,
752  time_t timeStamp = 0
753  );
754 
765  RTP_DataFrame::PayloadTypes rtpPayloadType,
766  unsigned clockRate,
767  const char * rtpEncodingName = NULL,
768  const char * protocol = NULL
769  );
770 
785  const char * wildcard
786  );
787 
802  const PString & wildcard
803  );
804 
809  RTP_DataFrame::PayloadTypes rtpPayloadType
810  );
811 
816  const char * wildcard
817  );
818 
823  const PString & wildcard
824  );
825 
828  virtual PObject * Clone() const;
829 
832  virtual Comparison Compare(const PObject & obj) const;
833 
838  virtual void PrintOn(ostream & strm) const;
839 
842  virtual void ReadFrom(istream & strm);
843 
848  bool ToNormalisedOptions();
849 
853  bool ToCustomisedOptions();
854 
857  bool Update(
858  const OpalMediaFormat & mediaFormat
859  );
860 
871  bool Merge(
872  const OpalMediaFormat & mediaFormat
873  );
876  bool ValidateMerge(
877  const OpalMediaFormat & mediaFormat
878  ) const;
879 
882  PString GetName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
883 
888  PBoolean IsValid() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValid(); }
889 
893  PBoolean IsTransportable() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsTransportable(); }
894 
901  void SetPayloadType(RTP_DataFrame::PayloadTypes type) { PWaitAndSignal m(m_mutex); MakeUnique(); if (m_info != NULL) m_info->rtpPayloadType = type; }
902 
905  const char * GetEncodingName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->rtpEncodingName.GetPointer(); }
906 
909  OpalMediaType GetMediaType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? OpalMediaType() : m_info->mediaType; }
910 
914  bool NeedsJitterBuffer() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(NeedsJitterOption(), false); }
915  static const PString & NeedsJitterOption();
916 
919  unsigned GetBandwidth() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxBitRateOption(), 0); }
920  static const PString & MaxBitRateOption();
921  static const PString & TargetBitRateOption();
922 
927  PINDEX GetFrameSize() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(MaxFrameSizeOption(), 0); }
928  static const PString & MaxFrameSizeOption();
929 
933  unsigned GetFrameTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(FrameTimeOption(), 0); }
934  static const PString & FrameTimeOption();
935 
938  unsigned GetTimeUnits() const { return GetClockRate()/1000; }
939 
941  AudioClockRate = 8000,
942  VideoClockRate = 90000
943  };
944 
947  unsigned GetClockRate() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->GetOptionInteger(ClockRateOption(), 1000); }
948  static const PString & ClockRateOption();
949 
952  static const PString & ProtocolOption();
953 
960  static const PString & MaxTxPacketSizeOption();
961 
965  PStringToString GetOptions() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? PStringToString() : m_info->GetOptions(); }
966 
969  PINDEX GetOptionCount() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->options.GetSize(); }
970 
975  PINDEX index
976  ) const { PWaitAndSignal m(m_mutex); return m_info->options[index]; }
977 
983  const PString & name,
984  PString & value
985  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionValue(name, value); }
986 
994  const PString & name,
995  const PString & value
996  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionValue(name, value); }
997 
1002  const PString & name,
1003  bool dflt = false
1004  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(name, dflt); }
1005 
1013  const PString & name,
1014  bool value
1015  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionBoolean(name, value); }
1016 
1021  const PString & name,
1022  int dflt = 0
1023  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionInteger(name, dflt); }
1024 
1033  const PString & name,
1034  int value
1035  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionInteger(name, value); }
1036 
1041  const PString & name,
1042  double dflt = 0
1043  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionReal(name, dflt); }
1044 
1052  const PString & name,
1053  double value
1054  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionReal(name, value); }
1055 
1061  const PString & name,
1062  PINDEX dflt = 0
1063  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionEnum(name, dflt); }
1064 
1072  const PString & name,
1073  PINDEX value
1074  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionEnum(name, value); }
1075 
1080  const PString & name,
1081  const PString & dflt = PString::Empty()
1082  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionString(name, dflt); }
1083 
1091  const PString & name,
1092  const PString & value
1093  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionString(name, value); }
1094 
1099  const PString & name,
1100  PBYTEArray & octets
1101  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionOctets(name, octets); }
1102 
1110  const PString & name,
1111  const PBYTEArray & octets
1112  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, octets); }
1114  const PString & name,
1115  const BYTE * data,
1116  PINDEX length
1117  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, data, length); }
1118 
1122  static void GetAllRegisteredMediaFormats(
1123  OpalMediaFormatList & copy
1124  );
1125 
1129  static bool SetRegisteredMediaFormat(
1130  const OpalMediaFormat & mediaFormat
1131  );
1132 
1136  static bool RemoveRegisteredMediaFormat(
1137  const OpalMediaFormat & mediaFormat
1138  );
1139 
1144  OpalMediaOption * option,
1145  PBoolean overwrite = false
1146  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->AddOption(option, overwrite); }
1147 
1151  bool HasOption(const PString & name) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->FindOption(name) != NULL; }
1152 
1157  const PString & name
1158  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? NULL : m_info->FindOption(name); }
1159 
1163  template <class T> T * FindOptionAs(
1164  const PString & name
1165  ) const { return dynamic_cast<T *>(FindOption(name)); }
1166 
1172  bool IsValidForProtocol(const PString & protocol) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValidForProtocol(protocol); }
1173 
1174  time_t GetCodecVersionTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->codecVersionTime; }
1175 
1176  ostream & PrintOptions(ostream & strm) const
1177  {
1178  PWaitAndSignal m(m_mutex);
1179  if (m_info != NULL)
1180  strm << setw(-1) << *m_info;
1181  return strm;
1182  }
1183 
1184 #if OPAL_VIDEO
1185 
1187  void AdjustVideoArgs(
1188  PVideoDevice::OpenArgs & args
1189  ) const;
1190 #endif
1191 
1192  // Backward compatibility
1193  virtual PBoolean IsEmpty() const { PWaitAndSignal m(m_mutex); return m_info == NULL || !m_info->IsValid(); }
1194  operator PString() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
1195  operator const char *() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
1196  bool operator==(const char * other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
1197  bool operator!=(const char * other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
1198  bool operator==(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
1199  bool operator!=(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
1200  bool operator==(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) == EqualTo; }
1201  bool operator!=(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) != EqualTo; }
1202  friend bool operator==(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
1203  friend bool operator!=(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
1204  friend bool operator==(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
1205  friend bool operator!=(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
1206 
1207 #if OPAL_H323
1208  static const PString & MediaPacketizationOption();
1209  static const PString & MediaPacketizationsOption();
1210 #endif
1211 
1212  private:
1213  PBoolean SetSize(PINDEX) { return true; }
1214 
1215  protected:
1216  void Construct(OpalMediaFormatInternal * info);
1217 
1219  PMutex m_mutex;
1220 
1222  friend class OpalMediaFormatList;
1223 };
1224 
1225 
1227 {
1228  public:
1230  const char * fullName,
1231  RTP_DataFrame::PayloadTypes rtpPayloadType,
1232  const char * encodingName,
1233  PINDEX frameSize,
1234  unsigned frameTime,
1235  unsigned rxFrames,
1236  unsigned txFrames,
1237  unsigned maxFrames,
1238  unsigned clockRate,
1239  time_t timeStamp
1240  );
1241  virtual PObject * Clone() const;
1242  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
1243 };
1244 
1246 {
1247  PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
1248  public:
1250  OpalMediaFormatInternal * info = NULL
1251  ) : OpalMediaFormat(info) { }
1253  const char * fullName,
1254  RTP_DataFrame::PayloadTypes rtpPayloadType,
1255  const char * encodingName,
1256  PINDEX frameSize,
1257  unsigned frameTime,
1258  unsigned rxFrames,
1259  unsigned txFrames,
1260  unsigned maxFrames = 256,
1261  unsigned clockRate = 8000,
1262  time_t timeStamp = 0
1263  );
1264 
1265  static const PString & RxFramesPerPacketOption();
1266  static const PString & TxFramesPerPacketOption();
1267  static const PString & MaxFramesPerPacketOption();
1268  static const PString & ChannelsOption();
1269 };
1270 
1271 #if OPAL_VIDEO
1273 {
1274  public:
1276  const char * fullName,
1277  RTP_DataFrame::PayloadTypes rtpPayloadType,
1278  const char * encodingName,
1279  unsigned maxFrameWidth,
1280  unsigned maxFrameHeight,
1281  unsigned maxFrameRate,
1282  unsigned maxBitRate,
1283  time_t timeStamp
1284  );
1285  virtual PObject * Clone() const;
1286  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
1287 };
1288 
1289 
1291 {
1292  PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
1293  public:
1295  OpalMediaFormatInternal * info = NULL
1296  ) : OpalMediaFormat(info) { }
1298  const char * fullName,
1299  RTP_DataFrame::PayloadTypes rtpPayloadType,
1300  const char * encodingName,
1301  unsigned maxFrameWidth,
1302  unsigned maxFrameHeight,
1303  unsigned maxFrameRate,
1304  unsigned maxBitRate,
1305  time_t timeStamp = 0
1306  );
1307 
1308  static const PString & FrameWidthOption();
1309  static const PString & FrameHeightOption();
1310  static const PString & MinRxFrameWidthOption();
1311  static const PString & MinRxFrameHeightOption();
1312  static const PString & MaxRxFrameWidthOption();
1313  static const PString & MaxRxFrameHeightOption();
1314  static const PString & TemporalSpatialTradeOffOption();
1315  static const PString & TxKeyFramePeriodOption();
1316  static const PString & RateControlEnableOption();
1317  static const PString & RateControllerOption();
1318  static const PString & RateControllerBitRateScalerOption();
1319 
1337  };
1338  enum { ContentRoleMask = 15 };
1339  __inline static unsigned ContentRoleBit(ContentRole contentRole) { return contentRole != eNoRole ? (1<<(contentRole-1)) : 0; }
1340  static const PString & ContentRoleOption();
1341  static const PString & ContentRoleMaskOption();
1342 };
1343 #endif
1344 
1345 // List of known media formats
1346 
1347 #define OPAL_PCM16 "PCM-16"
1348 #define OPAL_PCM16S "PCM-16S"
1349 #define OPAL_PCM16_16KHZ "PCM-16-16kHz"
1350 #define OPAL_PCM16S_16KHZ "PCM-16S-16kHz"
1351 #define OPAL_PCM16_32KHZ "PCM-16-32kHz"
1352 #define OPAL_PCM16S_32KHZ "PCM-16S-32kHz"
1353 #define OPAL_PCM16_48KHZ "PCM-16-48kHz"
1354 #define OPAL_PCM16S_48KHZ "PCM-16S-48kHz"
1355 #define OPAL_L16_MONO_8KHZ "Linear-16-Mono-8kHz"
1356 #define OPAL_L16_STEREO_8KHZ "Linear-16-Stereo-8kHz"
1357 #define OPAL_L16_MONO_16KHZ "Linear-16-Mono-16kHz"
1358 #define OPAL_L16_STEREO_16KHZ "Linear-16-Stereo-16kHz"
1359 #define OPAL_L16_MONO_32KHZ "Linear-16-Mono-32kHz"
1360 #define OPAL_L16_STEREO_32KHZ "Linear-16-Stereo-32kHz"
1361 #define OPAL_L16_MONO_48KHZ "Linear-16-Mono-48kHz"
1362 #define OPAL_L16_STEREO_48KHZ "Linear-16-Stereo-48kHz"
1363 #define OPAL_G711_ULAW_64K "G.711-uLaw-64k"
1364 #define OPAL_G711_ALAW_64K "G.711-ALaw-64k"
1365 #define OPAL_G722 "G.722"
1366 #define OPAL_G7221 "G.722.1"
1367 #define OPAL_G7222 "G.722.2"
1368 #define OPAL_G726_40K "G.726-40K"
1369 #define OPAL_G726_32K "G.726-32K"
1370 #define OPAL_G726_24K "G.726-24K"
1371 #define OPAL_G726_16K "G.726-16K"
1372 #define OPAL_G728 "G.728"
1373 #define OPAL_G729 "G.729"
1374 #define OPAL_G729A "G.729A"
1375 #define OPAL_G729B "G.729B"
1376 #define OPAL_G729AB "G.729A/B"
1377 #define OPAL_G7231 "G.723.1"
1378 #define OPAL_G7231_6k3 OPAL_G7231
1379 #define OPAL_G7231_5k3 "G.723.1(5.3k)"
1380 #define OPAL_G7231A_6k3 "G.723.1A(6.3k)"
1381 #define OPAL_G7231A_5k3 "G.723.1A(5.3k)"
1382 #define OPAL_GSM0610 "GSM-06.10"
1383 #define OPAL_GSMAMR "GSM-AMR"
1384 #define OPAL_iLBC "iLBC"
1385 #define OPAL_H261 "H.261"
1386 #define OPAL_H263 "H.263"
1387 #define OPAL_H264 "H.264"
1388 #define OPAL_H264_MODE0 "H.264-0"
1389 #define OPAL_H264_MODE1 "H.264-1"
1390 #define OPAL_MPEG4 "MPEG4"
1391 #define OPAL_RFC2833 "UserInput/RFC2833"
1392 #define OPAL_CISCONSE "NamedSignalEvent"
1393 #define OPAL_T38 "T.38"
1394 
1395 extern const OpalAudioFormat & GetOpalPCM16();
1396 extern const OpalAudioFormat & GetOpalPCM16S();
1397 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
1398 extern const OpalAudioFormat & GetOpalPCM16S_16KHZ();
1399 extern const OpalAudioFormat & GetOpalPCM16_32KHZ();
1400 extern const OpalAudioFormat & GetOpalPCM16S_32KHZ();
1401 extern const OpalAudioFormat & GetOpalPCM16_48KHZ();
1402 extern const OpalAudioFormat & GetOpalPCM16S_48KHZ();
1403 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
1404 extern const OpalAudioFormat & GetOpalL16_STEREO_8KHZ();
1405 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
1406 extern const OpalAudioFormat & GetOpalL16_STEREO_16KHZ();
1407 extern const OpalAudioFormat & GetOpalL16_MONO_32KHZ();
1408 extern const OpalAudioFormat & GetOpalL16_STEREO_32KHZ();
1409 extern const OpalAudioFormat & GetOpalL16_MONO_48KHZ();
1410 extern const OpalAudioFormat & GetOpalL16_STEREO_48KHZ();
1411 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
1412 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
1413 extern const OpalAudioFormat & GetOpalG722();
1414 extern const OpalAudioFormat & GetOpalG7221();
1415 extern const OpalAudioFormat & GetOpalG7222();
1416 extern const OpalAudioFormat & GetOpalG726_40K();
1417 extern const OpalAudioFormat & GetOpalG726_32K();
1418 extern const OpalAudioFormat & GetOpalG726_24K();
1419 extern const OpalAudioFormat & GetOpalG726_16K();
1420 extern const OpalAudioFormat & GetOpalG728();
1421 extern const OpalAudioFormat & GetOpalG729();
1422 extern const OpalAudioFormat & GetOpalG729A();
1423 extern const OpalAudioFormat & GetOpalG729B();
1424 extern const OpalAudioFormat & GetOpalG729AB();
1425 extern const OpalAudioFormat & GetOpalG7231_6k3();
1426 extern const OpalAudioFormat & GetOpalG7231_5k3();
1427 extern const OpalAudioFormat & GetOpalG7231A_6k3();
1428 extern const OpalAudioFormat & GetOpalG7231A_5k3();
1429 extern const OpalAudioFormat & GetOpalGSM0610();
1430 extern const OpalAudioFormat & GetOpalGSMAMR();
1431 extern const OpalAudioFormat & GetOpaliLBC();
1432 
1433 extern const OpalMediaFormat & GetOpalRFC2833();
1434 
1435 #if OPAL_T38_CAPABILITY
1436 extern const OpalMediaFormat & GetOpalCiscoNSE();
1437 extern const OpalMediaFormat & GetOpalT38();
1438 #endif
1439 
1440 
1441 #define OpalPCM16 GetOpalPCM16()
1442 #define OpalPCM16S GetOpalPCM16S()
1443 #define OpalPCM16_16KHZ GetOpalPCM16_16KHZ()
1444 #define OpalPCM16S_16KHZ GetOpalPCM16S_16KHZ()
1445 #define OpalPCM16_32KHZ GetOpalPCM16_32KHZ()
1446 #define OpalPCM16S_32KHZ GetOpalPCM16S_32KHZ()
1447 #define OpalPCM16_48KHZ GetOpalPCM16_48KHZ()
1448 #define OpalPCM16S_48KHZ GetOpalPCM16S_48KHZ()
1449 #define OpalL16_MONO_8KHZ GetOpalL16_MONO_8KHZ()
1450 #define OpalL16_STEREO_8KHZ GetOpalL16_STEREO_8KHZ()
1451 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
1452 #define OpalL16_STEREO_16KHZ GetOpalL16_STEREO_16KHZ()
1453 #define OpalL16_MONO_32KHZ GetOpalL16_MONO_32KHZ()
1454 #define OpalL16_STEREO_32KHZ GetOpalL16_STEREO_32KHZ()
1455 #define OpalL16_MONO_48KHZ GetOpalL16_MONO_48KHZ()
1456 #define OpalL16_STEREO_48KHZ GetOpalL16_STEREO_48KHZ()
1457 #define OpalG711_ULAW_64K GetOpalG711_ULAW_64K()
1458 #define OpalG711_ALAW_64K GetOpalG711_ALAW_64K()
1459 #define OpalG722 GetOpalG722()
1460 #define OpalG7221 GetOpalG7221()
1461 #define OpalG7222 GetOpalG7222()
1462 #define OpalG726_40K GetOpalG726_40K()
1463 #define OpalG726_32K GetOpalG726_32K()
1464 #define OpalG726_24K GetOpalG726_24K()
1465 #define OpalG726_16K GetOpalG726_16K()
1466 #define OpalG728 GetOpalG728()
1467 #define OpalG729 GetOpalG729()
1468 #define OpalG729A GetOpalG729A()
1469 #define OpalG729B GetOpalG729B()
1470 #define OpalG729AB GetOpalG729AB()
1471 #define OpalG7231_6k3 GetOpalG7231_6k3()
1472 #define OpalG7231_5k3 GetOpalG7231_5k3()
1473 #define OpalG7231A_6k3 GetOpalG7231A_6k3()
1474 #define OpalG7231A_5k3 GetOpalG7231A_5k3()
1475 #define OpalGSM0610 GetOpalGSM0610()
1476 #define OpalGSMAMR GetOpalGSMAMR()
1477 #define OpaliLBC GetOpaliLBC()
1478 #define OpalRFC2833 GetOpalRFC2833()
1479 #define OpalCiscoNSE GetOpalCiscoNSE()
1480 #define OpalT38 GetOpalT38()
1481 
1482 #define OpalL16Mono8kHz OpalL16_MONO_8KHZ
1483 #define OpalL16Mono16kHz OpalL16_MONO_16KHZ
1484 #define OpalG711uLaw OpalG711_ULAW_64K
1485 #define OpalG711ALaw OpalG711_ALAW_64K
1486 
1487 #define OPAL_T140 "T.140"
1488 #define OpalT140 GetOpalT140()
1489 extern const OpalMediaFormat & GetOpalT140();
1490 
1491 #if OPAL_HAS_MSRP
1492 #define OPAL_MSRP "MSRP"
1493 #define OpalMSRP GetOpalMSRP()
1494 extern const OpalMediaFormat & GetOpalMSRP();
1495 #endif
1496 
1497 #if OPAL_HAS_SIPIM
1498 #define OPAL_SIPIM "SIP-IM"
1499 #define OpalSIPIM GetOpalSIPIM()
1500 extern const OpalMediaFormat & GetOpalSIPIM();
1501 #endif
1502 
1503 #ifdef _MSC_VER
1504 #if _MSC_VER < 1300
1505 #pragma warning(default:4663)
1506 #endif
1507 #endif
1508 
1509 #endif // OPAL_OPAL_MEDIAFMT_H
1510 
1511 
1512 // End of File ///////////////////////////////////////////////////////////////