OPAL  Version 3.12.5
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: 30182 $
28  * $Author: rjongbloed $
29  * $Date: 2013-07-28 22:20:46 -0500 (Sun, 28 Jul 2013) $
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 #include <opal/buildopts.h>
40 
41 #include <opal/mediatype.h>
42 #include <rtp/rtp.h>
43 #include <ptlib/bitwise_enum.h>
44 
45 #if OPAL_VIDEO
46 #include <ptlib/videoio.h>
47 #endif
48 
49 #include <limits>
50 
51 
53 class OpalMediaFormat;
54 class H225_BandWidth;
55 
56 
58 
64  public:
65  enum Direction {
66  Rx = 1,
67  Tx,
70  };
71  friend std::ostream & operator<<(std::ostream & strm, OpalBandwidth::Direction dir);
72 
73  typedef unsigned int_type;
74 
75  __inline OpalBandwidth(int_type bps = 0) : m_bps(bps) { }
76  __inline OpalBandwidth & operator=(int_type bps) { m_bps = bps; return *this; }
77  __inline operator int_type() const { return m_bps; }
78 
79  __inline OpalBandwidth operator+ (const OpalBandwidth & bw) const { return OpalBandwidth(m_bps + bw.m_bps); }
80  __inline OpalBandwidth operator- (const OpalBandwidth & bw) const { return OpalBandwidth(m_bps - bw.m_bps); }
81  __inline OpalBandwidth & operator+=(const OpalBandwidth & bw) { m_bps += bw.m_bps; return *this; }
82  __inline OpalBandwidth & operator-=(const OpalBandwidth & bw) { m_bps += bw.m_bps; return *this; }
83  __inline OpalBandwidth & operator&=(const OpalBandwidth & bw) { if (m_bps > bw.m_bps) m_bps = bw.m_bps; return *this; }
84 
85  friend std::ostream & operator<<(std::ostream & strm, const OpalBandwidth & bw);
86  friend std::istream & operator>>(std::istream & strm, OpalBandwidth & bw);
87 
88 #if OPAL_H323
89  OpalBandwidth(const H225_BandWidth & bw);
90  OpalBandwidth & operator=(const H225_BandWidth & bw);
91  void SetH225(H225_BandWidth & bw) const;
92  unsigned AsH225() const { return (m_bps+99)/100; }
93 #endif
94  unsigned kbps() const { return (m_bps+999)/1000; }
95 
96  static OpalBandwidth Max() { return OpalBandwidth(UINT_MAX); }
97 
98  protected:
100 };
101 
102 
104 
105 PLIST(OpalMediaFormatBaseList, OpalMediaFormat);
106 
109 class OpalMediaFormatList : public OpalMediaFormatBaseList
110 {
111  PCLASSINFO(OpalMediaFormatList, OpalMediaFormatBaseList);
112  public:
118 
122  const OpalMediaFormat & format
123  );
124 
127  OpalMediaFormatList(const OpalMediaFormatList & l) : OpalMediaFormatBaseList(l) { }
129 
136  const char * wildcard
137  ) { PConstString w(wildcard); return operator+=(w); }
138 
143  const PString & wildcard
144  );
145 
150  const OpalMediaFormat & format
151  );
152 
157  const OpalMediaFormatList & formats
158  );
159 
164  const OpalMediaFormat & format
165  );
166 
171  const OpalMediaFormatList & formats
172  );
173 
190  const_iterator FindFormat(
191  RTP_DataFrame::PayloadTypes rtpPayloadType,
192  const unsigned clockRate = 0,
193  const char * rtpEncodingName = NULL,
194  const char * protocol = NULL,
195  const_iterator start = const_iterator()
196  ) const;
197 
214  const_iterator FindFormat(
215  const PString & wildcard,
216  const_iterator start = const_iterator()
217  ) const;
218 
221  PBoolean HasFormat(
222  RTP_DataFrame::PayloadTypes rtpPayloadType
223  ) const { return FindFormat(rtpPayloadType) != end(); }
224 
230  PBoolean HasFormat(
231  const PString & wildcard
232  ) const { return FindFormat(wildcard) != end(); }
233 
236  bool HasType(
237  const OpalMediaType & type,
238  bool mustBeTransportable = true
239  ) const;
240 
244 
260  void Reorder(
261  const PStringArray & order
262  );
263 
282  void Remove(
283  const PStringArray & mask
284  );
285 
288  void RemoveNonTransportable();
290 
291  private:
292  virtual PINDEX Append(PObject *) { return P_MAX_INDEX; }
293  virtual PINDEX Insert(const PObject &, PObject *) { return P_MAX_INDEX; }
294 };
295 
296 
298 
301 class OpalMediaOption : public PObject
302 {
303  PCLASSINFO(OpalMediaOption, PObject);
304  public:
305  // Note the below enum must be identical to PluginCodec_OptionMerge in opalplugin.h
306  enum MergeType {
314  IntersectionMerge, // Set intersection, applies to numeric (bit wise AND) or string (common substrings)
315 
316  // Synonyms
317  AndMerge = MinMerge, // Applies to Boolean option or Enum with two elements
318  OrMerge = MaxMerge // Applies to Boolean option or Enum with two elements
319  };
320 
321  protected:
323  const PString & name
324  );
326  const char * name,
327  bool readOnly,
328  MergeType merge
329  );
330 
331  public:
332  virtual Comparison Compare(const PObject & obj) const;
333 
334  virtual bool Merge(
335  const OpalMediaOption & option
336  );
337 
338  virtual bool ValidateMerge(
339  const OpalMediaOption & option
340  ) const;
341 
342  virtual Comparison CompareValue(
343  const OpalMediaOption & option
344  ) const = 0;
345  virtual void Assign(
346  const OpalMediaOption & option
347  ) = 0;
348 
349  PString AsString() const;
350  bool FromString(const PString & value);
351 
352  const PString & GetName() const { return m_name; }
353 
354  bool IsReadOnly() const { return m_readOnly; }
355  void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
356 
357  MergeType GetMerge() const { return m_merge; }
358  void SetMerge(MergeType merge) { m_merge = merge; }
359 
360 #if OPAL_SIP
361  const PString & GetFMTPName() const { return m_FMTPName; }
362  void SetFMTPName(const char * name) { m_FMTPName = name; }
363 
364  const PString & GetFMTPDefault() const { return m_FMTPDefault; }
365  void SetFMTPDefault(const char * value) { m_FMTPDefault = value; }
366 
367  void SetFMTP(const char * name, const char * dflt)
368  {
369  m_FMTPName = name;
370  m_FMTPDefault = dflt;
371  }
372 #define OPAL_SET_MEDIA_OPTION_FMTP(opt, name, dflt) (opt)->SetFMTP(name, dflt)
373 #else
374 #define OPAL_SET_MEDIA_OPTION_FMTP(opt, name, dflt)
375 #endif // OPAL_SIP
376 
377 #if OPAL_H323
379  H245GenericInfo();
381  unsigned mask,
382  const char * dflt = NULL
383  );
384 
385  unsigned ordinal;
386 
387  enum Modes {
391  } mode;
392 
397  } integerType;
398 
402  int position; // Position in sequence for parameter
403  PString defaultValue; // Do not include parameter if this value
404  };
405 
406  const H245GenericInfo & GetH245Generic() const { return m_H245Generic; }
407  void SetH245Generic(const H245GenericInfo & genericInfo) { m_H245Generic = genericInfo; }
408 #define OPAL_SET_MEDIA_OPTION_H245(opt, ...) (opt)->SetH245Generic(OpalMediaOption::H245GenericInfo(__VA_ARGS__))
409 #else
410 #define OPAL_SET_MEDIA_OPTION_H245(opt, ...)
411 #endif // OPAL_H323
412 
413  protected:
414  PCaselessString m_name;
417 
418 #if OPAL_SIP
419  PCaselessString m_FMTPName;
420  PString m_FMTPDefault;
421 #endif // OPAL_SIP
422 
423 #if OPAL_H323
425 #endif // OPAL_H323
426 };
427 
428 
429 template <typename T>
431 {
433  public:
435  const char * name,
436  bool readOnly,
438  T value = T()
439  )
440  : OpalMediaOption(name, readOnly, merge)
441  , m_value(value)
442  {
443  }
444 
445  virtual PObject * Clone() const
446  {
447  return new OpalMediaOptionValue(*this);
448  }
449 
450  virtual void PrintOn(ostream & strm) const
451  {
452  strm << m_value;
453  }
454 
455  virtual void ReadFrom(istream & strm)
456  {
457  strm >> m_value;
458  }
459 
460  virtual bool Merge(const OpalMediaOption & option)
461  {
462  if (m_merge != IntersectionMerge)
463  return OpalMediaOption::Merge(option);
464 
465  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
466  if (otherOption == NULL)
467  return false;
468 
469  m_value &= otherOption->m_value;
470  return true;
471  }
472 
473  virtual Comparison CompareValue(const OpalMediaOption & option) const
474  {
475  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
476  if (otherOption == NULL)
477  return GreaterThan;
478  if (m_value < otherOption->m_value)
479  return LessThan;
480  if (m_value > otherOption->m_value)
481  return GreaterThan;
482  return EqualTo;
483  }
484 
485  virtual void Assign(const OpalMediaOption & option)
486  {
487  const OpalMediaOptionValue * otherOption = PDownCast(const OpalMediaOptionValue, &option);
488  if (otherOption != NULL)
489  m_value = otherOption->m_value;
490  }
491 
492  T GetValue() const
493  {
494  return m_value;
495  }
496 
497  void SetValue(T value)
498  {
499  m_value = value;
500  }
501 
502  protected:
504 };
505 
506 
507 template <typename T>
509 {
512  public:
514  const char * name,
515  bool readOnly,
517  T value = 0,
518  T minimum = std::numeric_limits<T>::min(),
519  T maximum = std::numeric_limits<T>::max()
520  )
521  : BaseClass(name, readOnly, merge, value)
522  , m_minimum(minimum)
523  , m_maximum(maximum)
524  {
525  }
526 
527  virtual PObject * Clone() const
528  {
529  return new OpalMediaOptionNumericalValue(*this);
530  }
531 
532  virtual void ReadFrom(istream & strm)
533  {
534  T temp = 0;
535  strm >> temp;
536  if (strm.fail())
537  return;
538  if (temp >= m_minimum && temp <= m_maximum)
539  this->m_value = temp;
540  else
541  strm.setstate(ios::badbit);
542  }
543 
544  void SetValue(T value)
545  {
546  if (value < m_minimum)
547  this->m_value = m_minimum;
548  else if (value > m_maximum)
549  this->m_value = m_maximum;
550  else
551  this->m_value = value;
552  }
553 
554  void SetMinimum(T m)
555  {
556  this->m_minimum = m;
557  }
558 
559  void SetMaximum(T m)
560  {
561  this->m_maximum = m;
562  }
563 
564  protected:
567 };
568 
569 
573 
574 // Wrapper class so we can implement intersection (&= operator) for floating point
576 {
577  double m_value;
578  public:
579  OpalMediaOptionRealValue(double value = 0) : m_value(value) { }
580  operator double() const { return m_value; }
581  void operator&=(double other) { if (m_value > other) m_value = other; }
582  friend ostream & operator<<(ostream & strm, const OpalMediaOptionRealValue & value) { return strm << value.m_value; }
583  friend istream & operator>>(istream & strm, OpalMediaOptionRealValue & value) { return strm >> value.m_value; }
584 };
585 
587 
588 
590 {
592  public:
594  const char * name,
595  bool readOnly
596  );
598  const char * name,
599  bool readOnly,
600  const char * const * enumerations,
601  PINDEX count,
602  MergeType merge = EqualMerge,
603  PINDEX value = 0
604  );
605 
606  virtual PObject * Clone() const;
607  virtual void PrintOn(ostream & strm) const;
608  virtual void ReadFrom(istream & strm);
609 
610  virtual Comparison CompareValue(const OpalMediaOption & option) const;
611  virtual void Assign(const OpalMediaOption & option);
612 
613  PINDEX GetValue() const { return m_value; }
614  void SetValue(PINDEX value);
615 
616  const PStringArray & GetEnumerations() const { return m_enumerations; }
617  void SetEnumerations(const PStringArray & e)
618  {
619  m_enumerations = e;
620  }
621 
622  protected:
623  PStringArray m_enumerations;
624  PINDEX m_value;
625 };
626 
627 
629 {
631  public:
633  const char * name,
634  bool readOnly
635  );
637  const char * name,
638  bool readOnly,
639  const PString & value
640  );
641 
642  virtual PObject * Clone() const;
643  virtual void PrintOn(ostream & strm) const;
644  virtual void ReadFrom(istream & strm);
645 
646  virtual bool Merge(const OpalMediaOption & option);
647  virtual Comparison CompareValue(const OpalMediaOption & option) const;
648  virtual void Assign(const OpalMediaOption & option);
649 
650  const PString & GetValue() const { return m_value; }
651  void SetValue(const PString & value);
652 
653  protected:
654  PString m_value;
655 };
656 
657 
659 {
661  public:
663  const char * name,
664  bool readOnly,
665  bool base64 = false
666  );
668  const char * name,
669  bool readOnly,
670  bool base64,
671  const PBYTEArray & value
672  );
674  const char * name,
675  bool readOnly,
676  bool base64,
677  const BYTE * data,
678  PINDEX length
679  );
680 
681  virtual PObject * Clone() const;
682  virtual void PrintOn(ostream & strm) const;
683  virtual void ReadFrom(istream & strm);
684 
685  virtual Comparison CompareValue(const OpalMediaOption & option) const;
686  virtual void Assign(const OpalMediaOption & option);
687 
688  const PBYTEArray & GetValue() const { return m_value; }
689  void SetValue(const PBYTEArray & value);
690  void SetValue(const BYTE * data, PINDEX length);
691 
692  void SetBase64(bool b)
693  {
694  m_base64 = b;
695  }
696 
697  protected:
698  PBYTEArray m_value;
699  bool m_base64;
700 };
701 
702 
704 
705 class OpalMediaFormatInternal : public PObject
706 {
707  PCLASSINFO(OpalMediaFormatInternal, PObject);
708  public:
710  const char * fullName,
711  const OpalMediaType & mediaType,
712  RTP_DataFrame::PayloadTypes rtpPayloadType,
713  const char * encodingName,
714  bool needsJitter,
715  OpalBandwidth bandwidth,
716  PINDEX frameSize,
717  unsigned frameTime,
718  unsigned clockRate,
719  time_t timeStamp
720  );
721 
722  const PCaselessString & GetName() const { return formatName; }
723 
724  virtual PObject * Clone() const;
725  virtual void PrintOn(ostream & strm) const;
726 
727  virtual bool IsValid() const;
728  virtual bool IsTransportable() const;
729 
730  virtual PStringToString GetOptions() const;
731  virtual bool GetOptionValue(const PString & name, PString & value) const;
732  virtual bool SetOptionValue(const PString & name, const PString & value);
733  virtual bool GetOptionBoolean(const PString & name, bool dflt) const;
734  virtual bool SetOptionBoolean(const PString & name, bool value);
735  virtual int GetOptionInteger(const PString & name, int dflt) const;
736  virtual bool SetOptionInteger(const PString & name, int value);
737  virtual double GetOptionReal(const PString & name, double dflt) const;
738  virtual bool SetOptionReal(const PString & name, double value);
739  virtual PINDEX GetOptionEnum(const PString & name, PINDEX dflt) const;
740  virtual bool SetOptionEnum(const PString & name, PINDEX value);
741  virtual PString GetOptionString(const PString & name, const PString & dflt) const;
742  virtual bool SetOptionString(const PString & name, const PString & value);
743  virtual bool GetOptionOctets(const PString & name, PBYTEArray & octets) const;
744  virtual bool SetOptionOctets(const PString & name, const PBYTEArray & octets);
745  virtual bool SetOptionOctets(const PString & name, const BYTE * data, PINDEX length);
746  virtual bool AddOption(OpalMediaOption * option, PBoolean overwrite = false);
747  virtual OpalMediaOption * FindOption(const PString & name) const;
748 
749  virtual bool ToNormalisedOptions();
750  virtual bool ToCustomisedOptions();
751  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
752 
753  virtual bool ValidateMerge(const OpalMediaFormatInternal & mediaFormat) const;
754 
755  virtual bool IsValidForProtocol(const PString & protocol) const;
756 
757  protected:
758  bool AdjustByOptionMaps(
759  PTRACE_PARAM(const char * operation,)
760  bool (*adjuster)(PluginCodec_OptionMap & original, PluginCodec_OptionMap & changed)
761  );
762 
763  PCaselessString formatName;
768  PSortedList<OpalMediaOption> options;
772 
773  friend bool operator==(const char * other, const OpalMediaFormat & fmt);
774  friend bool operator!=(const char * other, const OpalMediaFormat & fmt);
775  friend bool operator==(const PString & other, const OpalMediaFormat & fmt);
776  friend bool operator!=(const PString & other, const OpalMediaFormat & fmt);
777 
778  friend class OpalMediaFormat;
779  friend class OpalMediaFormatList;
781 };
782 
783 
785 
791 class OpalMediaFormat : public PContainer
792 {
793  PCLASSINFO(OpalMediaFormat, PContainer)
794  public:
795  OpalMediaFormat(const OpalMediaFormat & c);
796  virtual ~OpalMediaFormat();
797  OpalMediaFormat & operator=(const OpalMediaFormat & c) { AssignContents(c); return *this; }
798  virtual PBoolean MakeUnique();
799  protected:
800  virtual void DestroyContents();
801  virtual void AssignContents(const PContainer & c);
802 
803  public:
807  OpalMediaFormatInternal * info = NULL
808  );
809 
824  const char * fullName,
825  const OpalMediaType & mediaType,
826  RTP_DataFrame::PayloadTypes rtpPayloadType,
827  const char * encodingName,
828  PBoolean needsJitter,
829  OpalBandwidth bandwidth,
830  PINDEX frameSize,
831  unsigned frameTime,
832  unsigned clockRate,
833  time_t timeStamp = 0
834  );
835 
846  RTP_DataFrame::PayloadTypes rtpPayloadType,
847  unsigned clockRate,
848  const char * rtpEncodingName = NULL,
849  const char * protocol = NULL
850  );
851 
866  const char * wildcard
867  );
868 
883  const PString & wildcard
884  );
885 
890  RTP_DataFrame::PayloadTypes rtpPayloadType
891  );
892 
897  const char * wildcard
898  );
899 
904  const PString & wildcard
905  );
906 
909  virtual PObject * Clone() const;
910 
913  virtual Comparison Compare(const PObject & obj) const;
914 
919  virtual void PrintOn(ostream & strm) const;
920 
923  virtual void ReadFrom(istream & strm);
924 
929  bool ToNormalisedOptions();
930 
934  bool ToCustomisedOptions();
935 
938  bool Update(
939  const OpalMediaFormat & mediaFormat
940  );
941 
952  bool Merge(
953  const OpalMediaFormat & mediaFormat
954  );
957  bool ValidateMerge(
958  const OpalMediaFormat & mediaFormat
959  ) const;
960 
963  PString GetName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
964 
969  PBoolean IsValid() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValid(); }
970 
974  PBoolean IsTransportable() const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsTransportable(); }
975 
982  void SetPayloadType(RTP_DataFrame::PayloadTypes type) { PWaitAndSignal m(m_mutex); MakeUnique(); if (m_info != NULL) m_info->rtpPayloadType = type; }
983 
986  const char * GetEncodingName() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : (const char *)m_info->rtpEncodingName; }
987 
990  OpalMediaType GetMediaType() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? OpalMediaType() : m_info->mediaType; }
991 
996  static const PString & NeedsJitterOption();
997 
1001  static const PString & MaxBitRateOption();
1002 
1006  static const PString & TargetBitRateOption();
1007 
1012  PINDEX GetFrameSize() const { return GetOptionInteger(MaxFrameSizeOption()); }
1013  static const PString & MaxFrameSizeOption();
1014 
1018  unsigned GetFrameTime() const { return GetOptionInteger(FrameTimeOption()); }
1019  static const PString & FrameTimeOption();
1020 
1023  unsigned GetTimeUnits() const { return GetClockRate()/1000; }
1024 
1028  };
1029 
1033  static const PString & ClockRateOption();
1034 
1037  static const PString & ProtocolOption();
1038 
1045  static const PString & MaxTxPacketSizeOption();
1046 
1050  PStringToString GetOptions() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? PStringToString() : m_info->GetOptions(); }
1051 
1054  PINDEX GetOptionCount() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->options.GetSize(); }
1055 
1060  PINDEX index
1061  ) const { PWaitAndSignal m(m_mutex); return m_info->options[index]; }
1062 
1068  const PString & name,
1069  PString & value
1070  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionValue(name, value); }
1071 
1079  const PString & name,
1080  const PString & value
1081  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionValue(name, value); }
1082 
1087  const PString & name,
1088  bool dflt = false
1089  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionBoolean(name, dflt); }
1090 
1098  const PString & name,
1099  bool value
1100  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionBoolean(name, value); }
1101 
1106  const PString & name,
1107  int dflt = 0
1108  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionInteger(name, dflt); }
1109 
1118  const PString & name,
1119  int value
1120  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionInteger(name, value); }
1121 
1126  const PString & name,
1127  double dflt = 0
1128  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionReal(name, dflt); }
1129 
1137  const PString & name,
1138  double value
1139  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionReal(name, value); }
1140 
1148  template <typename Enum>
1150  const PString & name,
1151  Enum dflt = (Enum)0
1152  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : (Enum)m_info->GetOptionEnum(name, dflt); }
1153 
1163  template <typename Enum>
1165  const PString & name,
1166  Enum value
1167  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionEnum(name, value); }
1168 
1173  const PString & name,
1174  const PString & dflt = PString::Empty()
1175  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? dflt : m_info->GetOptionString(name, dflt); }
1176 
1184  const PString & name,
1185  const PString & value
1186  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionString(name, value); }
1187 
1192  const PString & name,
1193  PBYTEArray & octets
1194  ) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->GetOptionOctets(name, octets); }
1195 
1203  const PString & name,
1204  const PBYTEArray & octets
1205  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, octets); }
1207  const PString & name,
1208  const BYTE * data,
1209  PINDEX length
1210  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->SetOptionOctets(name, data, length); }
1211 
1215  static void GetAllRegisteredMediaFormats(
1216  OpalMediaFormatList & copy
1217  );
1218 
1222  static bool SetRegisteredMediaFormat(
1223  const OpalMediaFormat & mediaFormat
1224  );
1225 
1229  static bool RemoveRegisteredMediaFormat(
1230  const OpalMediaFormat & mediaFormat
1231  );
1232 
1237  OpalMediaOption * option,
1238  PBoolean overwrite = false
1239  ) { PWaitAndSignal m(m_mutex); MakeUnique(); return m_info != NULL && m_info->AddOption(option, overwrite); }
1240 
1244  bool HasOption(const PString & name) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->FindOption(name) != NULL; }
1245 
1250  const PString & name
1251  ) const { PWaitAndSignal m(m_mutex); return m_info == NULL ? NULL : m_info->FindOption(name); }
1252 
1256  template <class T> T * FindOptionAs(
1257  const PString & name
1258  ) const { return dynamic_cast<T *>(FindOption(name)); }
1259 
1265  bool IsValidForProtocol(const PString & protocol) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->IsValidForProtocol(protocol); }
1266 
1267  time_t GetCodecVersionTime() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? 0 : m_info->codecVersionTime; }
1268 
1269  ostream & PrintOptions(ostream & strm) const
1270  {
1271  PWaitAndSignal m(m_mutex);
1272  if (m_info != NULL)
1273  strm << setw(-1) << *m_info;
1274  return strm;
1275  }
1276 
1277 #if OPAL_VIDEO
1278 
1280  void AdjustVideoArgs(
1281  PVideoDevice::OpenArgs & args
1282  ) const;
1283 #endif
1284 
1285  // Backward compatibility
1286  virtual PBoolean IsEmpty() const { PWaitAndSignal m(m_mutex); return m_info == NULL || !m_info->IsValid(); }
1287  operator PString() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
1288  operator const char *() const { PWaitAndSignal m(m_mutex); return m_info == NULL ? "" : m_info->formatName; }
1289  bool operator==(const char * other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
1290  bool operator!=(const char * other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
1291  bool operator==(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info != NULL && m_info->formatName == other; }
1292  bool operator!=(const PString & other) const { PWaitAndSignal m(m_mutex); return m_info == NULL || m_info->formatName != other; }
1293  bool operator==(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) == EqualTo; }
1294  bool operator!=(const OpalMediaFormat & other) const { PWaitAndSignal m(m_mutex); return Compare(other) != EqualTo; }
1295  friend bool operator==(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
1296  friend bool operator!=(const char * other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
1297  friend bool operator==(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info != NULL && fmt.m_info->formatName == other; }
1298  friend bool operator!=(const PString & other, const OpalMediaFormat & fmt) { return fmt.m_info == NULL || fmt.m_info->formatName != other; }
1299 
1300 #if OPAL_H323
1301  static const PString & MediaPacketizationOption();
1302  static const PString & MediaPacketizationsOption();
1303  PStringArray GetMediaPacketizations() const;
1304  PStringSet GetMediaPacketizationSet() const { return PStringSet(GetMediaPacketizations()); }
1305  void SetMediaPacketizations(const PStringSet & packetizations);
1306 #endif
1307 
1308  private:
1309  PBoolean SetSize(PINDEX) { return true; }
1310 
1311  protected:
1312  void Construct(OpalMediaFormatInternal * info);
1313 
1315  PMutex m_mutex;
1316 
1318  friend class OpalMediaFormatList;
1319 };
1320 
1321 
1323 {
1324  public:
1326  const char * fullName,
1327  RTP_DataFrame::PayloadTypes rtpPayloadType,
1328  const char * encodingName,
1329  PINDEX frameSize,
1330  unsigned frameTime,
1331  unsigned rxFrames,
1332  unsigned txFrames,
1333  unsigned maxFrames,
1334  unsigned clockRate,
1335  time_t timeStamp = 0
1336  );
1337  virtual PObject * Clone() const;
1338  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
1339 };
1340 
1342 {
1343  PCLASSINFO(OpalAudioFormat, OpalMediaFormat);
1344  public:
1346  OpalMediaFormatInternal * info = NULL
1347  ) : OpalMediaFormat(info) { }
1349  const char * fullName,
1350  RTP_DataFrame::PayloadTypes rtpPayloadType,
1351  const char * encodingName,
1352  PINDEX frameSize,
1353  unsigned frameTime,
1354  unsigned rxFrames,
1355  unsigned txFrames,
1356  unsigned maxFrames = 256,
1357  unsigned clockRate = 8000,
1358  time_t timeStamp = 0
1359  );
1360 
1361  static const PString & RxFramesPerPacketOption();
1362  static const PString & TxFramesPerPacketOption();
1363  static const PString & MaxFramesPerPacketOption();
1364  static const PString & ChannelsOption();
1365 };
1366 
1367 #if OPAL_VIDEO
1369 {
1370  public:
1372  const char * fullName,
1373  RTP_DataFrame::PayloadTypes rtpPayloadType,
1374  const char * encodingName,
1375  unsigned maxFrameWidth,
1376  unsigned maxFrameHeight,
1377  unsigned maxFrameRate,
1378  unsigned maxBitRate,
1379  time_t timeStamp = 0
1380  );
1381  virtual PObject * Clone() const;
1382  virtual bool Merge(const OpalMediaFormatInternal & mediaFormat);
1383 };
1384 
1385 
1387 {
1388  PCLASSINFO(OpalVideoFormat, OpalMediaFormat);
1389  public:
1391  OpalMediaFormatInternal * info = NULL
1392  ) : OpalMediaFormat(info) { }
1394  const char * fullName,
1395  RTP_DataFrame::PayloadTypes rtpPayloadType,
1396  const char * encodingName,
1397  unsigned maxFrameWidth,
1398  unsigned maxFrameHeight,
1399  unsigned maxFrameRate,
1400  unsigned maxBitRate,
1401  time_t timeStamp = 0
1402  );
1403 
1404  static const PString & FrameWidthOption();
1405  static const PString & FrameHeightOption();
1406  static const PString & MinRxFrameWidthOption();
1407  static const PString & MinRxFrameHeightOption();
1408  static const PString & MaxRxFrameWidthOption();
1409  static const PString & MaxRxFrameHeightOption();
1410  static const PString & TemporalSpatialTradeOffOption();
1411  static const PString & TxKeyFramePeriodOption();
1412  static const PString & RateControlPeriodOption(); // Period over which the rate controller maintains the target bit rate.
1413  static const PString & RateControllerOption(); // String for controller algorithm. Empty is none.
1414 
1425  P_DECLARE_STREAMABLE_ENUM(ContentRole,
1426  eNoRole,
1427  ePresentation,
1428  eMainRole,
1429  eSpeaker,
1430  eSignLanguage
1431  );
1432 
1433  enum { ContentRoleMask = 15 };
1434  __inline static unsigned ContentRoleBit(ContentRole contentRole) { return contentRole != eNoRole ? (1<<(contentRole-1)) : 0; }
1435  static const PString & ContentRoleOption();
1436  static const PString & ContentRoleMaskOption();
1437 
1440  RTCPFeedback,
1441  5,
1442  (
1443  e_NoRTCPFb,
1444  e_PLI,
1445  e_FIR,
1446  e_TMMBR,
1447  e_TSTR,
1448  e_VBCM
1449  ),
1450  "", "pli", "fir", "tmmbr", "tstr", "vcbm"
1451  );
1453  static const PString & RTCPFeedbackOption();
1454 };
1455 #endif
1456 
1457 
1458 #include <codec/known.h>
1459 
1460 
1461 extern const OpalAudioFormat & GetOpalPCM16();
1462 extern const OpalAudioFormat & GetOpalPCM16S();
1463 extern const OpalAudioFormat & GetOpalPCM16_16KHZ();
1464 extern const OpalAudioFormat & GetOpalPCM16S_16KHZ();
1465 extern const OpalAudioFormat & GetOpalPCM16_32KHZ();
1466 extern const OpalAudioFormat & GetOpalPCM16S_32KHZ();
1467 extern const OpalAudioFormat & GetOpalPCM16_48KHZ();
1468 extern const OpalAudioFormat & GetOpalPCM16S_48KHZ();
1469 extern const OpalAudioFormat & GetOpalL16_MONO_8KHZ();
1470 extern const OpalAudioFormat & GetOpalL16_STEREO_8KHZ();
1471 extern const OpalAudioFormat & GetOpalL16_MONO_16KHZ();
1472 extern const OpalAudioFormat & GetOpalL16_STEREO_16KHZ();
1473 extern const OpalAudioFormat & GetOpalL16_MONO_32KHZ();
1474 extern const OpalAudioFormat & GetOpalL16_STEREO_32KHZ();
1475 extern const OpalAudioFormat & GetOpalL16_MONO_48KHZ();
1476 extern const OpalAudioFormat & GetOpalL16_STEREO_48KHZ();
1477 extern const OpalAudioFormat & GetOpalG711_ULAW_64K();
1478 extern const OpalAudioFormat & GetOpalG711_ALAW_64K();
1479 extern const OpalAudioFormat & GetOpalG722();
1480 extern const OpalAudioFormat & GetOpalG7221_24K();
1481 extern const OpalAudioFormat & GetOpalG7221_32K();
1482 extern const OpalAudioFormat & GetOpalG7221_48K();
1483 extern const OpalAudioFormat & GetOpalG7222();
1484 extern const OpalAudioFormat & GetOpalG726_40K();
1485 extern const OpalAudioFormat & GetOpalG726_32K();
1486 extern const OpalAudioFormat & GetOpalG726_24K();
1487 extern const OpalAudioFormat & GetOpalG726_16K();
1488 extern const OpalAudioFormat & GetOpalG728();
1489 extern const OpalAudioFormat & GetOpalG729();
1490 extern const OpalAudioFormat & GetOpalG729A();
1491 extern const OpalAudioFormat & GetOpalG729B();
1492 extern const OpalAudioFormat & GetOpalG729AB();
1493 extern const OpalAudioFormat & GetOpalG7231_6k3();
1494 extern const OpalAudioFormat & GetOpalG7231_5k3();
1495 extern const OpalAudioFormat & GetOpalG7231A_6k3();
1496 extern const OpalAudioFormat & GetOpalG7231A_5k3();
1497 extern const OpalAudioFormat & GetOpalGSM0610();
1498 extern const OpalAudioFormat & GetOpalGSMAMR();
1499 extern const OpalAudioFormat & GetOpaliLBC();
1500 
1501 #if OPAL_VIDEO
1502 extern const OpalVideoFormat & GetOpalH261();
1503 extern const OpalVideoFormat & GetOpalH263();
1504 extern const OpalVideoFormat & GetOpalH263plus();
1505 extern const OpalVideoFormat & GetOpalH264_MODE0();
1506 extern const OpalVideoFormat & GetOpalH264_MODE1();
1507 extern const OpalVideoFormat & GetOpalMPEG4();
1508 #endif // OPAL_VIDEO
1509 
1510 extern const OpalMediaFormat & GetOpalRFC2833();
1511 
1512 #if OPAL_T38_CAPABILITY
1513 extern const OpalMediaFormat & GetOpalCiscoNSE();
1514 extern const OpalMediaFormat & GetOpalT38();
1515 #endif
1516 
1517 
1518 #define OpalPCM16 GetOpalPCM16()
1519 #define OpalPCM16S GetOpalPCM16S()
1520 #define OpalPCM16_16KHZ GetOpalPCM16_16KHZ()
1521 #define OpalPCM16S_16KHZ GetOpalPCM16S_16KHZ()
1522 #define OpalPCM16_32KHZ GetOpalPCM16_32KHZ()
1523 #define OpalPCM16S_32KHZ GetOpalPCM16S_32KHZ()
1524 #define OpalPCM16_48KHZ GetOpalPCM16_48KHZ()
1525 #define OpalPCM16S_48KHZ GetOpalPCM16S_48KHZ()
1526 #define OpalL16_MONO_8KHZ GetOpalL16_MONO_8KHZ()
1527 #define OpalL16_STEREO_8KHZ GetOpalL16_STEREO_8KHZ()
1528 #define OpalL16_MONO_16KHZ GetOpalL16_MONO_16KHZ()
1529 #define OpalL16_STEREO_16KHZ GetOpalL16_STEREO_16KHZ()
1530 #define OpalL16_MONO_32KHZ GetOpalL16_MONO_32KHZ()
1531 #define OpalL16_STEREO_32KHZ GetOpalL16_STEREO_32KHZ()
1532 #define OpalL16_MONO_48KHZ GetOpalL16_MONO_48KHZ()
1533 #define OpalL16_STEREO_48KHZ GetOpalL16_STEREO_48KHZ()
1534 #define OpalG711_ULAW_64K GetOpalG711_ULAW_64K()
1535 #define OpalG711_ALAW_64K GetOpalG711_ALAW_64K()
1536 #define OpalG722 GetOpalG722()
1537 #define OpalG7221 OpalG7221_32K
1538 #define OpalG7221_24K GetOpalG7221_24K()
1539 #define OpalG7221_32K GetOpalG7221_32K()
1540 #define OpalG7221_48K GetOpalG7221_48K()
1541 #define OpalG7222 GetOpalG7222()
1542 #define OpalG726_40K GetOpalG726_40K()
1543 #define OpalG726_32K GetOpalG726_32K()
1544 #define OpalG726_24K GetOpalG726_24K()
1545 #define OpalG726_16K GetOpalG726_16K()
1546 #define OpalG728 GetOpalG728()
1547 #define OpalG729 GetOpalG729()
1548 #define OpalG729A GetOpalG729A()
1549 #define OpalG729B GetOpalG729B()
1550 #define OpalG729AB GetOpalG729AB()
1551 #define OpalG7231_6k3 GetOpalG7231_6k3()
1552 #define OpalG7231_5k3 GetOpalG7231_5k3()
1553 #define OpalG7231A_6k3 GetOpalG7231A_6k3()
1554 #define OpalG7231A_5k3 GetOpalG7231A_5k3()
1555 #define OpalGSM0610 GetOpalGSM0610()
1556 #define OpalGSMAMR GetOpalGSMAMR()
1557 #define OpaliLBC GetOpaliLBC()
1558 #define OpalRFC2833 GetOpalRFC2833()
1559 #define OpalCiscoNSE GetOpalCiscoNSE()
1560 #define OpalT38 GetOpalT38()
1561 
1562 #if OPAL_VIDEO
1563 #define OpalH261 GetOpalH261()
1564 #define OpalH263 GetOpalH263()
1565 #define OpalH263plus GetOpalH263plus()
1566 #define OpalH264 GetOpalH264_MODE1()
1567 #define OpalH264_MODE0 GetOpalH264_MODE0()
1568 #define OpalH264_MODE1 GetOpalH264_MODE1()
1569 #define OpalMPEG4 GetOpalMPEG4()
1570 #endif
1571 
1572 #define OpalL16Mono8kHz OpalL16_MONO_8KHZ
1573 #define OpalL16Mono16kHz OpalL16_MONO_16KHZ
1574 #define OpalG711uLaw OpalG711_ULAW_64K
1575 #define OpalG711ALaw OpalG711_ALAW_64K
1576 
1577 
1578 #endif // OPAL_OPAL_MEDIAFMT_H
1579 
1580 
1581 // End of File ///////////////////////////////////////////////////////////////