1 /*
2  * h323caps.h
3  *
4  * H.323 protocol handler
5  *
6  * Open H323 Library
7  *
8  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions of this code were written with the assisance of funding from
25  * Vovida Networks, Inc. http://www.vovida.com.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 27461 $
30  * $Author: rjongbloed $
31  * $Date: 2012-04-17 13:11:41 -0500 (Tue, 17 Apr 2012) $
32  */
33 
34 #ifndef OPAL_H323_H323CAPS_H
35 #define OPAL_H323_H323CAPS_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <opal/buildopts.h>
42 
43 #if OPAL_H323
44 
45 #include <opal/mediafmt.h>
46 #include <h323/channels.h>
47 
48 
49 /* The following classes have forward references to avoid including the VERY
50    large header files for H225 and H245. If an application requires access
51    to the protocol classes they can include them, but for simple usage their
52    inclusion can be avoided.
53  */
54 class PASN_Choice;
55 class H245_Capability;
56 class H245_DataType;
57 class H245_ModeElement;
58 class H245_AudioCapability;
59 class H245_AudioMode;
60 class H245_VideoCapability;
61 class H245_VideoMode;
62 class H245_DataApplicationCapability;
63 class H245_DataMode;
64 class H245_DataProtocolCapability;
65 class H245_H2250LogicalChannelParameters;
66 class H245_TerminalCapabilitySet;
67 class H245_NonStandardParameter;
68 class H323Connection;
69 class H323Capabilities;
70 class H245_CapabilityIdentifier;
71 class H245_GenericCapability;
72 class H245_GenericParameter;
73 
74 ///////////////////////////////////////////////////////////////////////////////
75 
76 /**This class describes the interface to a capability of the endpoint, usually
77    a codec, used to transfer data via the logical channels opened and managed
78    by the H323 control channel.
79 
80    Note that this is not an instance of the codec itself. Merely the
81    description of that codec. There is typically only one instance of this
82    class contained in the capability tables of the endpoint. There may be
83    several instances of the actualy codec managing the conversion of an
84    individual stream of data.
85 
86    An application may create a descendent off this class and override
87    functions as required for describing a codec that it implements.
88  */
89 class H323Capability : public PObject
90 {
91   PCLASSINFO(H323Capability, PObject);
92 
93   public:
94   /**@name Construction */
95   //@{
96     /**Create a new capability specification.
97      */
98     H323Capability();
99   //@}
100 
101   /**@name Overrides from class PObject */
102   //@{
103     /**Compare two capability instances. This compares the main and sub-types
104        of the capability.
105      */
106     Comparison Compare(const PObject & obj) const;
107 
108     /**Print out the object to the stream, virtual version of << operator.
109      */
110     void PrintOn(ostream & strm) const;
111   //@}
112 
113   /**@name Identification functions */
114   //@{
115     enum MainTypes {
116       /// Audio codec capability
117       e_Audio,
118       /// Video codec capability
119       e_Video,
120       /// Arbitrary data capability
121       e_Data,
122       /// User Input capability
123       e_UserInput,
124       /// Generic Control
125       e_GenericControl,
126       /// Count of main types
127       e_NumMainTypes
128     };
129 
130     /**Get the main type of the capability.
131 
132        This function is overridden by one of the three main sub-classes off
133        which real capabilities would be descendend.
134      */
135     virtual MainTypes GetMainType() const = 0;
136 
137     /**Get the sub-type of the capability. This is a code dependent on the
138        main type of the capability.
139      */
140     virtual unsigned  GetSubType()  const = 0;
141 
142     /**Get the name of the media data format this class represents.
143      */
144     virtual PString GetFormatName() const = 0;
145   //@}
146 
147   /**@name Operations */
148   //@{
149     /**Create an H323Capability descendant given a string name.
150        This uses the registration system to create the capability.
151       */
152     static H323Capability * Create(
153       const PString & name     ///<  Name of capability
154     );
155 
156     enum {
157       DefaultAudioSessionID = 1,
158       DefaultVideoSessionID = 2,
159       DefaultDataSessionID  = 3,
160       DefaultH224SessionID  = 4
161     };
162 
163     /**Get the default RTP session.
164        This function gets the default RTP session ID for the capability
165        type. For example audio capabilities return the value
166        H323Capability::DefaultAudioSessionID etc.
167 
168        The default behaviour returns zero, indicating it is not an RTP
169        based capability.
170       */
171     virtual unsigned GetDefaultSessionID() const;
172 
173     /**Set the maximum size (in frames) of data that will be transmitted in a
174        single PDU.
175 
176        This will also be the desired number that will be sent by most codec
177        implemetations.
178 
179        The default behaviour does nothing.
180      */
181     virtual void SetTxFramesInPacket(
182       unsigned frames   ///<  Number of frames per packet
183     );
184 
185     /**Get the maximum size (in frames) of data that will be transmitted in a single PDU.
186 
187        The default behaviour returns the value 1.
188      */
189     virtual unsigned GetTxFramesInPacket() const;
190 
191     /**Get the maximum size (in frames) of data that can be received in a single PDU.
192 
193        The default behaviour returns the value 1.
194      */
195     virtual unsigned GetRxFramesInPacket() const;
196 
197     /**Create the channel instance, allocating resources as required.
198        This creates a logical channel object appropriate for the parameters
199        provided. Not if param is NULL, sessionID must be provided, otherwise
200        this is taken from the fields in param.
201      */
202     virtual H323Channel * CreateChannel(
203       H323Connection & connection,    ///<  Owner connection for channel
204       H323Channel::Directions dir,    ///<  Direction of channel
205       unsigned sessionID,             ///<  Session ID for RTP channel
206       const H245_H2250LogicalChannelParameters * param
207                                       ///<  Parameters for channel
208     ) const = 0;
209   //@}
210 
211   /**@name Protocol manipulation */
212   //@{
213     enum CommandType {
214       e_TCS,
215       e_OLC,
216       e_ReqMode
217     };
218 
219     /**This function is called whenever and outgoing TerminalCapabilitySet
220        PDU is being constructed for the control channel. It allows the
221        capability to set the PDU fields from information in members specific
222        to the class.
223 
224        The default behaviour is pure.
225      */
226     virtual PBoolean OnSendingPDU(
227       H245_Capability & pdu  ///<  PDU to set information on
228     ) const = 0;
229 
230     /**This function is called whenever and outgoing OpenLogicalChannel
231        PDU is being constructed for the control channel. It allows the
232        capability to set the PDU fields from information in members specific
233        to the class.
234 
235        The default behaviour is pure.
236      */
237     virtual PBoolean OnSendingPDU(
238       H245_DataType & pdu  ///<  PDU to set information on
239     ) const;
240 
241     /**This function is called whenever and outgoing RequestMode
242        PDU is being constructed for the control channel. It allows the
243        capability to set the PDU fields from information in members specific
244        to the class.
245 
246        The default behaviour is pure.
247      */
248     virtual PBoolean OnSendingPDU(
249       H245_ModeElement & pdu  ///<  PDU to set information on
250     ) const = 0;
251 
252     /**This function is called whenever and incoming TerminalCapabilitySet
253        PDU is received on the control channel, and a new H323Capability
254        descendent was created. This completes reading fields from the PDU
255        into the classes members.
256 
257        If the function returns false then the received PDU codec description
258        is not supported, so will be ignored.
259 
260          The default behaviour sets the capabilityDirection member variable
261          from the PDU and then returns true. Note that this means it is very
262          important to call the ancestor function when overriding.
263      */
264     virtual PBoolean OnReceivedPDU(
265       const H245_Capability & pdu ///<  PDU to get information from
266     );
267 
268     /**This function is called whenever and incoming OpenLogicalChannel
269        PDU has been used to construct the control channel. It allows the
270        capability to set from the PDU fields, information in members specific
271        to the class.
272 
273        The default behaviour is pure.
274      */
275     virtual PBoolean OnReceivedPDU(
276       const H245_DataType & pdu,  ///<  PDU to get information from
277       PBoolean receiver               ///<  Is receiver OLC
278     );
279 
280     /**Compare the PDU part of the capability.
281       */
282     virtual PBoolean IsMatch(
283       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
284       const PString & mediaPacketization  ///< Media packetization used
285     ) const;
286 
287     /**Validate that the capability is usable given the connection.
288        This checks agains the negotiated protocol version number and remote
289        application to determine if this capability should be used in TCS or
290        OLC pdus.
291 
292        The default behaviour returns true.
293       */
294     virtual PBoolean IsUsable(
295       const H323Connection & connection
296     ) const;
297   //@}
298 
299   /**@name Member variable access */
300   //@{
301     enum CapabilityDirection {
302       e_Unknown,
303       e_Receive,
304       e_Transmit,
305       e_ReceiveAndTransmit,
306       e_NoDirection,
307       NumCapabilityDirections
308     };
309 
310     /**Get the direction for this capability.
311       */
GetCapabilityDirection()312     CapabilityDirection GetCapabilityDirection() const { return capabilityDirection; }
313 
314     /**Set the direction for this capability.
315       */
SetCapabilityDirection(CapabilityDirection dir)316     void SetCapabilityDirection(
317       CapabilityDirection dir   ///<  New direction code
318     ) { capabilityDirection = dir; }
319 
320     /// Get unique capability number.
GetCapabilityNumber()321     unsigned GetCapabilityNumber() const { return assignedCapabilityNumber; }
322 
323     /// Set unique capability number.
SetCapabilityNumber(unsigned num)324     void SetCapabilityNumber(unsigned num) { assignedCapabilityNumber = num; }
325 
326     /**Get media format of the media data this class represents.
327       */
328     OpalMediaFormat GetMediaFormat() const;
329 
330     /** Set media format option for the media data this class represents.
331       */
332     bool UpdateMediaFormat(
333       const OpalMediaFormat & format
334     );
335 
336     /// Get the payload type for the capaibility
GetPayloadType()337     RTP_DataFrame::PayloadTypes GetPayloadType() const { return GetMediaFormat().GetPayloadType(); }
338 
339     /// Set the payload type for the capaibility
SetPayloadType(RTP_DataFrame::PayloadTypes pt)340     void SetPayloadType(RTP_DataFrame::PayloadTypes pt) { GetWritableMediaFormat().SetPayloadType(pt); }
341 
342     /// Attach a QoS specification to this channel
AttachQoS(RTP_QOS *)343     virtual void AttachQoS(RTP_QOS *) { }
344   //@}
345 
346 #if PTRACING
347     friend ostream & operator<<(ostream & o , MainTypes t);
348     friend ostream & operator<<(ostream & o , CapabilityDirection d);
349 #endif
350 
351   protected:
352     OpalMediaFormat & GetWritableMediaFormat() const;
353 
354     unsigned            assignedCapabilityNumber;  /// Unique ID assigned to capability
355     CapabilityDirection capabilityDirection;
356 
357   private:
358     mutable OpalMediaFormat m_mediaFormat;
359     P_REMOVE_VIRTUAL(PBoolean, IsMatch(const PASN_Choice &) const, false);
360 
361   friend class H323Capabilities;
362 };
363 
364 
365 
366 /**This class describes the interface to a non-standard codec used to
367    transfer data via the logical channels opened and managed by the H323
368    control channel.
369 
370    It is expected that an application makes a descendent off
371    H323NonStandardAudioCapability or H323NonStandardVideoCapability which
372    multiply inherit from this class.
373  */
374 class H323NonStandardCapabilityInfo
375 {
376   public:
377     typedef PObject::Comparison (*CompareFuncType)(struct PluginCodec_H323NonStandardCodecData *);
378 
379     /**Create a new set of information about a non-standard codec.
380       */
381     H323NonStandardCapabilityInfo(
382       CompareFuncType compareFunc,
383       const BYTE * dataBlock,         ///< Non-Standard data for codec type
384       PINDEX dataSize                 ///< Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
385     );
386 
387     /**Create a new set of information about a non-standard codec.
388       */
389     H323NonStandardCapabilityInfo(
390       const BYTE * dataBlock,         ///<  Non-Standard data for codec type
391       PINDEX dataSize,                ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
392       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
393       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
394     );
395 
396     /**Create a new set of information about a non-standard codec.
397       */
398     H323NonStandardCapabilityInfo(
399       const PString & oid,
400       const BYTE * dataBlock,         ///<  Non-Standard data for codec type
401       PINDEX dataSize,                ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
402       PINDEX comparisonOffset = 0,
403       PINDEX comparisonLength = P_MAX_INDEX
404     );
405 
406     /**Create a new set of information about a non-standard codec.
407       */
408     H323NonStandardCapabilityInfo(
409       BYTE country,                  ///<  t35 information
410       BYTE extension,                ///<  t35 information
411       WORD maufacturer,              ///<  t35 information
412       const BYTE * dataBlock,         ///<  Non-Standard data for codec type
413       PINDEX dataSize,                ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
414       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
415       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
416     );
417 
418     /**Destroy the capability information
419      */
420     virtual ~H323NonStandardCapabilityInfo();
421 
422     /**This function gets the non-standard data field.
423 
424        The default behaviour sets data to fixedData.
425       */
426     virtual PBoolean OnSendingPDU(
427       PBYTEArray & data  ///<  Data field in PDU to send
428     ) const;
429 
430     /**This function validates and uses the non-standard data field.
431 
432        The default behaviour returns true if data is equal to fixedData.
433       */
434     virtual PBoolean OnReceivedPDU(
435       const PBYTEArray & data  ///<  Data field in PDU received
436     );
437 
438     PBoolean IsMatch(const H245_NonStandardParameter & param) const;
439 
440     PObject::Comparison CompareParam(
441       const H245_NonStandardParameter & param
442     ) const;
443 
444   protected:
445     PBoolean OnSendingNonStandardPDU(
446       PASN_Choice & pdu,
447       unsigned nonStandardTag
448     ) const;
449     PBoolean OnReceivedNonStandardPDU(
450       const PASN_Choice & pdu,
451       unsigned nonStandardTag
452     );
453 
454     PObject::Comparison CompareInfo(
455       const H323NonStandardCapabilityInfo & obj
456     ) const;
457     PObject::Comparison CompareData(
458       const PBYTEArray & data  ///<  Data field in PDU received
459     ) const;
460 
461     PString    oid;
462     BYTE       t35CountryCode;
463     BYTE       t35Extension;
464     WORD       manufacturerCode;
465     PBYTEArray nonStandardData;
466     PINDEX     comparisonOffset;
467     PINDEX     comparisonLength;
468     CompareFuncType compareFunc;
469 };
470 
471 /**This class describes the interface to a generic codec used to
472    transfer data via the logical channels opened and managed by the H323
473    control channel.
474 
475    It is expected that an application makes a descendent off
476    H323GenericAudioCapability or H323GenericVideoCapability which
477    multiply inherit from this class.
478  */
479 
480 class H323GenericCapabilityInfo
481 {
482   public:
483     H323GenericCapabilityInfo(
484       const PString & id,     ///< generic codec identifier
485       unsigned maxBitRate = 0   ///< maxBitRate parameter for the GenericCapability
486     );
487 
~H323GenericCapabilityInfo()488     virtual ~H323GenericCapabilityInfo() { }
489 
490   protected:
491     virtual PBoolean OnSendingGenericPDU(
492       H245_GenericCapability & pdu,
493       const OpalMediaFormat & mediaFormat,
494       H323Capability::CommandType type
495     ) const;
496     virtual PBoolean OnReceivedGenericPDU(
497       OpalMediaFormat & mediaFormat,
498       const H245_GenericCapability & pdu,
499       H323Capability::CommandType type
500     );
501 
502     PBoolean IsMatch(
503       const H245_GenericCapability & param  ///< Non standard field in PDU received
504     ) const;
505     PObject::Comparison CompareInfo(
506       const H323GenericCapabilityInfo & obj
507     ) const;
508 
509 
510     PString  m_identifier;
511     unsigned maxBitRate;
512 };
513 
514 /**This class describes the interface to a codec that has channels based on
515    the RTP protocol.
516 
517    An application may create a descendent off this class and override
518    functions as required for descibing the codec.
519  */
520 class H323RealTimeCapability : public H323Capability
521 {
522   PCLASSINFO(H323RealTimeCapability, H323Capability);
523 
524   public:
525   /**@name Operations */
526   //@{
527     /**Create the channel instance, allocating resources as required.
528      */
529     virtual H323Channel * CreateChannel(
530       H323Connection & connection,    ///<  Owner connection for channel
531       H323Channel::Directions dir,    ///<  Direction of channel
532       unsigned sessionID,             ///<  Session ID for RTP channel
533       const H245_H2250LogicalChannelParameters * param
534                                       ///<  Parameters for channel
535     ) const;
536 
537     H323RealTimeCapability();
538     H323RealTimeCapability(const H323RealTimeCapability &rtc);
539     virtual ~H323RealTimeCapability();
540     void AttachQoS(RTP_QOS * _rtpqos);
541 
542   protected:
543     RTP_QOS * rtpqos;
544   //@}
545 };
546 
547 
548 /**This class describes the interface to an audio codec used to transfer data
549    via the logical channels opened and managed by the H323 control channel.
550 
551    An application may create a descendent off this class and override
552    functions as required for descibing the codec.
553  */
554 class H323AudioCapability : public H323RealTimeCapability
555 {
556   PCLASSINFO(H323AudioCapability, H323RealTimeCapability);
557 
558   public:
559   /**@name Construction */
560   //@{
561     /**Create an audio based capability.
562       */
563     H323AudioCapability();
564   //@}
565 
566   /**@name Identification functions */
567   //@{
568     /**Get the main type of the capability.
569        Always returns e_Audio.
570      */
571     virtual MainTypes GetMainType() const;
572   //@}
573 
574   /**@name Operations */
575   //@{
576     /**Get the default RTP session.
577        This function gets the default RTP session ID for the capability
578        type. For example audio capabilities return the value
579        RTP_Session::DefaultAudioSessionID etc.
580 
581        The default behaviour returns zero, indicating it is not an RTP
582        based capability.
583       */
584     virtual unsigned GetDefaultSessionID() const;
585 
586     /**Set the maximum size (in frames) of data that will be transmitted in a
587        single PDU.
588 
589        This will also be the desired number that will be sent by most codec
590        implemetations.
591 
592        The default behaviour sets the txFramesInPacket variable.
593      */
594     virtual void SetTxFramesInPacket(
595       unsigned frames   ///<  Number of frames per packet
596     );
597 
598     /**Get the maximum size (in frames) of data that will be transmitted in a
599        single PDU.
600 
601        The default behaviour sends the txFramesInPacket variable.
602      */
603     virtual unsigned GetTxFramesInPacket() const;
604 
605     /**Get the maximum size (in frames) of data that can be received in a
606        single PDU.
607 
608        The default behaviour sends the rxFramesInPacket variable.
609      */
610     virtual unsigned GetRxFramesInPacket() const;
611   //@}
612 
613   /**@name Protocol manipulation */
614   //@{
615     /**This function is called whenever and outgoing TerminalCapabilitySet
616        PDU is being constructed for the control channel. It allows the
617        capability to set the PDU fields from information in members specific
618        to the class.
619 
620        The default behaviour calls the OnSendingPDU() function with a more
621        specific PDU type.
622      */
623     virtual PBoolean OnSendingPDU(
624       H245_Capability & pdu  ///<  PDU to set information on
625     ) const;
626 
627     /**This function is called whenever and outgoing OpenLogicalChannel
628        PDU is being constructed for the control channel. It allows the
629        capability to set the PDU fields from information in members specific
630        to the class.
631 
632        The default behaviour calls the OnSendingPDU() function with a more
633        specific PDU type.
634      */
635     virtual PBoolean OnSendingPDU(
636       H245_DataType & pdu  ///<  PDU to set information on
637     ) const;
638 
639     /**This function is called whenever and outgoing RequestMode
640        PDU is being constructed for the control channel. It allows the
641        capability to set the PDU fields from information in members specific
642        to the class.
643 
644        The default behaviour calls the OnSendingPDU() function with a more
645        specific PDU type.
646      */
647     virtual PBoolean OnSendingPDU(
648       H245_ModeElement & pdu  ///<  PDU to set information on
649     ) const;
650 
651     /**This function is called whenever and outgoing TerminalCapabilitySet
652        or OpenLogicalChannel PDU is being constructed for the control channel.
653        It allows the capability to set the PDU fields from information in
654        members specific to the class.
655 
656        The default behaviour assumes the pdu is an integer number of frames
657        per packet.
658      */
659     virtual PBoolean OnSendingPDU(
660       H245_AudioCapability & pdu,  ///<  PDU to set information on
661       unsigned packetSize          ///<  Packet size to use in capability
662     ) const;
663     virtual PBoolean OnSendingPDU(
664       H245_AudioCapability & pdu,  ///<  PDU to set information on
665       unsigned packetSize,         ///<  Packet size to use in capability
666       CommandType type             ///<  Type of PDU to send in
667     ) const;
668 
669     /**This function is called whenever and outgoing RequestMode
670        PDU is being constructed for the control channel. It allows the
671        capability to set the PDU fields from information in members specific
672        to the class.
673 
674        The default behaviour sets the PDUs tag according to the GetSubType()
675        function (translated to different enum).
676      */
677     virtual PBoolean OnSendingPDU(
678       H245_AudioMode & pdu  ///<  PDU to set information on
679     ) const;
680 
681     /**This function is called whenever and incoming TerminalCapabilitySet
682        PDU is received on the control channel, and a new H323Capability
683        descendent was created. This completes reading fields from the PDU
684        into the classes members.
685 
686        If the function returns false then the received PDU codec description
687        is not supported, so will be ignored.
688 
689        The default behaviour calls the OnReceivedPDU() that takes a
690        H245_AudioCapability and clamps the txFramesInPacket.
691      */
692     virtual PBoolean OnReceivedPDU(
693       const H245_Capability & pdu  ///<  PDU to get information from
694     );
695 
696     /**This function is called whenever and incoming OpenLogicalChannel
697        PDU has been used to construct the control channel. It allows the
698        capability to set from the PDU fields, information in members specific
699        to the class.
700 
701        The default behaviour calls the OnReceivedPDU() that takes a
702        H245_AudioCapability and clamps the txFramesInPacket or
703        rxFramesInPacket.
704      */
705     virtual PBoolean OnReceivedPDU(
706       const H245_DataType & pdu,  ///<  PDU to get information from
707       PBoolean receiver               ///<  Is receiver OLC
708     );
709 
710     /**This function is called whenever and incoming TerminalCapabilitySet
711        or OpenLogicalChannel PDU has been used to construct the control
712        channel. It allows the capability to set from the PDU fields,
713        information in members specific to the class.
714 
715        The default behaviour assumes the pdu is an integer number of frames
716        per packet.
717      */
718     virtual PBoolean OnReceivedPDU(
719       const H245_AudioCapability & pdu,  ///<  PDU to get information from
720       unsigned & packetSize              ///<  Packet size to use in capability
721     );
722     virtual PBoolean OnReceivedPDU(
723       const H245_AudioCapability & pdu,  ///< PDU to get information from
724       unsigned & packetSize,             ///< Packet size to use in capability
725       CommandType type                   ///<  Type of PDU to send in
726     );
727   //@}
728 };
729 
730 
731 /**This class describes the interface to a non-standard audio codec used to
732    transfer data via the logical channels opened and managed by the H323
733    control channel.
734 
735    An application may create a descendent off this class and override
736    functions as required for descibing the codec.
737  */
738 class H323NonStandardAudioCapability : public H323AudioCapability,
739                                        public H323NonStandardCapabilityInfo
740 {
741   PCLASSINFO(H323NonStandardAudioCapability, H323AudioCapability);
742 
743   public:
744   /**@name Construction */
745   //@{
746     H323NonStandardAudioCapability(
747       H323NonStandardCapabilityInfo::CompareFuncType compareFunc,
748       const BYTE * dataBlock,         ///< Non-Standard data for codec type
749       PINDEX dataSize                 ///< Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
750     );
751     /**Create a new set of information about a non-standard codec.
752       */
753     H323NonStandardAudioCapability(
754       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
755       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
756       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
757       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
758      );
759 
760     /**Create a new set of information about a non-standard codec.
761       */
762     H323NonStandardAudioCapability(
763       const PString & oid,            ///<  OID for indentification of codec
764       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
765       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
766       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
767       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
768     );
769 
770     /**Create a new set of information about a non-standard codec.
771       */
772     H323NonStandardAudioCapability(
773       BYTE country,                   ///<  t35 information
774       BYTE extension,                 ///<  t35 information
775       WORD maufacturer,               ///<  t35 information
776       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
777       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
778       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
779       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
780     );
781   //@}
782 
783   /**@name Overrides from class PObject */
784   //@{
785     /**Compare two capability instances. This compares the main and sub-types
786        of the capability.
787      */
788     Comparison Compare(const PObject & obj) const;
789   //@}
790 
791   /**@name Identification functions */
792   //@{
793     /**Get the sub-type of the capability. This is a code dependent on the
794        main type of the capability.
795 
796        This returns H245_AudioCapability::e_nonStandard.
797      */
798     virtual unsigned GetSubType() const;
799   //@}
800 
801   /**@name Protocol manipulation */
802   //@{
803     /**This function is called whenever and outgoing TerminalCapabilitySet
804        or OpenLogicalChannel PDU is being constructed for the control channel.
805        It allows the capability to set the PDU fields from information in
806        members specific to the class.
807 
808        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
809        to handle the PDU.
810      */
811     virtual PBoolean OnSendingPDU(
812       H245_AudioCapability & pdu,  ///<  PDU to set information on
813       unsigned packetSize          ///<  Packet size to use in capability
814     ) const;
815 
816     /**This function is called whenever and outgoing RequestMode
817        PDU is being constructed for the control channel. It allows the
818        capability to set the PDU fields from information in members specific
819        to the class.
820 
821        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
822        to handle the PDU.
823      */
824     virtual PBoolean OnSendingPDU(
825       H245_AudioMode & pdu  ///<  PDU to set information on
826     ) const;
827 
828     /**This function is called whenever and incoming TerminalCapabilitySet
829        or OpenLogicalChannel PDU has been used to construct the control
830        channel. It allows the capability to set from the PDU fields,
831        information in members specific to the class.
832 
833        The default behaviour calls H323NonStandardCapabilityinfo::OnReceivedPDU()
834        to handle the provided PDU.
835      */
836     virtual PBoolean OnReceivedPDU(
837       const H245_AudioCapability & pdu,  ///<  PDU to get information from
838       unsigned & packetSize              ///<  Packet size to use in capability
839     );
840 
841     /**Compare the nonStandardData part of the capability, if applicable.
842       */
843     virtual PBoolean IsMatch(
844       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
845       const PString & mediaPacketization  ///< Media packetization used
846     ) const;
847   //@}
848 };
849 
850 /**This class describes the interface to a generic audio codec used to
851    transfer data via the logical channels opened and managed by the H323
852    control channel.
853 
854    An application may create a descendent off this class and override
855    functions as required for descibing the codec.
856  */
857 class H323GenericAudioCapability : public H323AudioCapability,
858                                    public H323GenericCapabilityInfo
859 {
860   PCLASSINFO(H323NonStandardAudioCapability, H323AudioCapability);
861 
862   public:
863   /**@name Construction */
864   //@{
865     /**Create a new set of information about a non-standard codec.
866       */
867     H323GenericAudioCapability(
868       const PString & capabilityId,    ///< generic codec identifier
869       PINDEX maxBitRate = 0               ///< maxBitRate parameter for the GenericCapability
870     );
871   //@}
872 
873   /**@name Overrides from class PObject */
874   //@{
875     /**Compare two capability instances. This compares the main and sub-types
876        of the capability.
877      */
878     Comparison Compare(const PObject & obj) const;
879   //@}
880 
881   /**@name Identification functions */
882   //@{
883     /**Get the sub-type of the capability. This is a code dependent on the
884        main type of the capability.
885 
886        This returns H245_AudioCapability::e_genericCapability.
887      */
888     virtual unsigned GetSubType() const;
889   //@}
890 
891   /**@name Protocol manipulation */
892   //@{
893     /**This function is called whenever and outgoing TerminalCapabilitySet
894        or OpenLogicalChannel PDU is being constructed for the control channel.
895        It allows the capability to set the PDU fields from information in
896        members specific to the class.
897 
898        The default behaviour calls H323GenericCapabilityinfo::OnSendingPDU()
899        to handle the PDU.
900      */
901     virtual PBoolean OnSendingPDU(
902       H245_AudioCapability & pdu,  ///<  PDU to set information on
903       unsigned packetSize,         ///<  Packet size to use in capability
904       CommandType type             ///<  Type of PDU to send in
905     ) const;
906 
907     /**This function is called whenever and outgoing RequestMode
908        PDU is being constructed for the control channel. It allows the
909        capability to set the PDU fields from information in members specific
910        to the class.
911 
912        The default behaviour sets the PDUs tag according to the GetSubType()
913        function (translated to different enum).
914      */
915     virtual PBoolean OnSendingPDU(
916       H245_AudioMode & pdu  ///<  PDU to set information on
917     ) const;
918 
919     /**This function is called whenever and incoming TerminalCapabilitySet
920        or OpenLogicalChannel PDU has been used to construct the control
921        channel. It allows the capability to set from the PDU fields,
922        information in members specific to the class.
923 
924        The default behaviour calls H323GenericCapabilityinfo::OnReceivedPDU()
925        to handle the provided PDU.
926      */
927     virtual PBoolean OnReceivedPDU(
928       const H245_AudioCapability & pdu,  ///< PDU to get information from
929       unsigned & packetSize,             ///< Packet size to use in capability
930       CommandType type                   ///<  Type of PDU to send in
931     );
932 
933     /**Compare the generic part of the capability, if applicable.
934      */
935     virtual PBoolean IsMatch(
936       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
937       const PString & mediaPacketization  ///< Media packetization used
938     ) const;
939   //@}
940 };
941 
942 
943 #if OPAL_VIDEO
944 
945 /**This class describes the interface to a video codec used to transfer data
946    via the logical channels opened and managed by the H323 control channel.
947 
948    An application may create a descendent off this class and override
949    functions as required for descibing a codec.
950  */
951 class H323VideoCapability : public H323RealTimeCapability
952 {
953   PCLASSINFO(H323VideoCapability, H323RealTimeCapability);
954 
955   public:
956   /**@name Identification functions */
957   //@{
958     /**Get the main type of the capability.
959        Always returns e_Video.
960      */
961     virtual MainTypes GetMainType() const;
962   //@}
963 
964   /**@name Operations */
965   //@{
966     /**Get the default RTP session.
967        This function gets the default RTP session ID for the capability
968        type. For example audio capabilities return the value
969        RTP_Session::DefaultAudioSessionID etc.
970 
971        The default behaviour returns zero, indicating it is not an RTP
972        based capability.
973       */
974     virtual unsigned GetDefaultSessionID() const;
975   //@}
976 
977   /**@name Protocol manipulation */
978   //@{
979     /**This function is called whenever and outgoing TerminalCapabilitySet
980        PDU is being constructed for the control channel. It allows the
981        capability to set the PDU fields from information in members specific
982        to the class.
983 
984        The default behaviour calls the OnSendingPDU() function with a more
985        specific PDU type.
986      */
987     virtual PBoolean OnSendingPDU(
988       H245_Capability & pdu  ///<  PDU to set information on
989     ) const;
990 
991     /**This function is called whenever and outgoing OpenLogicalChannel
992        PDU is being constructed for the control channel. It allows the
993        capability to set the PDU fields from information in members specific
994        to the class.
995 
996        The default behaviour calls the OnSendingPDU() function with a more
997        specific PDU type.
998      */
999     virtual PBoolean OnSendingPDU(
1000       H245_DataType & pdu  ///<  PDU to set information on
1001     ) const;
1002 
1003     /**This function is called whenever and outgoing RequestMode
1004        PDU is being constructed for the control channel. It allows the
1005        capability to set the PDU fields from information in members specific
1006        to the class.
1007 
1008        The default behaviour calls the OnSendingPDU() function with a more
1009        specific PDU type.
1010      */
1011     virtual PBoolean OnSendingPDU(
1012       H245_ModeElement & pdu  ///<  PDU to set information on
1013     ) const;
1014 
1015     /**This function is called whenever and outgoing TerminalCapabilitySet
1016        or OpenLogicalChannel PDU is being constructed for the control channel.
1017        It allows the capability to set the PDU fields from information in
1018        members specific to the class.
1019 
1020        The default behaviour is pure.
1021      */
1022     virtual PBoolean OnSendingPDU(
1023       H245_VideoCapability & pdu  ///<  PDU to set information on
1024     ) const;
1025     virtual PBoolean OnSendingPDU(
1026       H245_VideoCapability & pdu,  ///<  PDU to set information on
1027       CommandType type             ///<  Type of PDU to send in
1028     ) const;
1029 
1030     /**This function is called whenever and outgoing RequestMode
1031        PDU is being constructed for the control channel. It allows the
1032        capability to set the PDU fields from information in members specific
1033        to the class.
1034 
1035        The default behaviour sets the PDUs tag according to the GetSubType()
1036        function (translated to different enum).
1037      */
1038     virtual PBoolean OnSendingPDU(
1039       H245_VideoMode & pdu  ///<  PDU to set information on
1040     ) const = 0;
1041 
1042     /**This function is called whenever and incoming TerminalCapabilitySet
1043        PDU is received on the control channel, and a new H323Capability
1044        descendent was created. This completes reading fields from the PDU
1045        into the classes members.
1046 
1047        If the function returns false then the received PDU codec description
1048        is not supported, so will be ignored. The default behaviour simply
1049        returns true.
1050      */
1051     virtual PBoolean OnReceivedPDU(
1052       const H245_Capability & pdu  ///<  PDU to get information from
1053     );
1054 
1055     /**This function is called whenever and incoming OpenLogicalChannel
1056        PDU has been used to construct the control channel. It allows the
1057        capability to set from the PDU fields, information in members specific
1058        to the class.
1059 
1060        The default behaviour is pure.
1061      */
1062     virtual PBoolean OnReceivedPDU(
1063       const H245_DataType & pdu,  ///<  PDU to get information from
1064       PBoolean receiver               ///<  Is receiver OLC
1065     );
1066 
1067     /**This function is called whenever and incoming TerminalCapabilitySet
1068        or OpenLogicalChannel PDU has been used to construct the control
1069        channel. It allows the capability to set from the PDU fields,
1070        information in members specific to the class.
1071 
1072        The default behaviour is pure.
1073      */
1074     virtual PBoolean OnReceivedPDU(
1075       const H245_VideoCapability & pdu  ///<  PDU to set information on
1076     );
1077     virtual PBoolean OnReceivedPDU(
1078       const H245_VideoCapability & pdu,  ///< PDU to get information from
1079       CommandType type                   ///<  Type of PDU to send in
1080     );
1081   //@}
1082 };
1083 
1084 
1085 /**This class describes the interface to a non-standard video codec used to
1086    transfer data via the logical channels opened and managed by the H323
1087    control channel.
1088 
1089    An application may create a descendent off this class and override
1090    functions as required for descibing the codec.
1091  */
1092 class H323NonStandardVideoCapability : public H323VideoCapability,
1093                                        public H323NonStandardCapabilityInfo
1094 {
1095   PCLASSINFO(H323NonStandardVideoCapability, H323VideoCapability);
1096 
1097   public:
1098   /**@name Construction */
1099   //@{
1100     H323NonStandardVideoCapability(
1101       H323NonStandardCapabilityInfo::CompareFuncType compareFunc,
1102       const BYTE * dataBlock,         ///< Non-Standard data for codec type
1103       PINDEX dataSize                 ///< Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1104     );
1105     /**Create a new set of information about a non-standard codec.
1106       */
1107     H323NonStandardVideoCapability(
1108       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1109       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1110       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1111       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1112     );
1113 
1114     /**Create a new set of information about a non-standard codec.
1115       */
1116     H323NonStandardVideoCapability(
1117       const PString & oid,            ///<  OID for indentification of codec
1118       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1119       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1120       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1121       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1122     );
1123 
1124     /**Create a new set of information about a non-standard codec.
1125       */
1126     H323NonStandardVideoCapability(
1127       BYTE country,                   ///<  t35 information
1128       BYTE extension,                 ///<  t35 information
1129       WORD maufacturer,               ///<  t35 information
1130       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1131       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1132       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1133       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1134     );
1135   //@}
1136 
1137   /**@name Overrides from class PObject */
1138   //@{
1139     /**Compare two capability instances. This compares the main and sub-types
1140        of the capability.
1141      */
1142     Comparison Compare(const PObject & obj) const;
1143   //@}
1144 
1145   /**@name Identification functions */
1146   //@{
1147     /**Get the sub-type of the capability. This is a code dependent on the
1148        main type of the capability.
1149 
1150        This returns one of the four possible combinations of mode and speed
1151        using the enum values of the protocol ASN H245_AudioCapability class.
1152      */
1153     virtual unsigned GetSubType() const;
1154   //@}
1155 
1156   /**@name Protocol manipulation */
1157   //@{
1158     /**This function is called whenever and outgoing TerminalCapabilitySet
1159        or OpenLogicalChannel PDU is being constructed for the control channel.
1160        It allows the capability to set the PDU fields from information in
1161        members specific to the class.
1162 
1163        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
1164        to handle the PDU.
1165      */
1166     virtual PBoolean OnSendingPDU(
1167       H245_VideoCapability & pdu  ///<  PDU to set information on
1168     ) const;
1169 
1170     /**This function is called whenever and outgoing RequestMode
1171        PDU is being constructed for the control channel. It allows the
1172        capability to set the PDU fields from information in members specific
1173        to the class.
1174 
1175        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
1176        to handle the PDU.
1177      */
1178     virtual PBoolean OnSendingPDU(
1179       H245_VideoMode & pdu  ///<  PDU to set information on
1180     ) const;
1181 
1182     /**This function is called whenever and incoming TerminalCapabilitySet
1183        or OpenLogicalChannel PDU has been used to construct the control
1184        channel. It allows the capability to set from the PDU fields,
1185        information in members specific to the class.
1186 
1187        The default behaviour calls H323NonStandardCapabilityinfo::OnReceivedPDU()
1188        to handle the provided PDU.
1189      */
1190     virtual PBoolean OnReceivedPDU(
1191       const H245_VideoCapability & pdu  ///<  PDU to set information on
1192     );
1193 
1194     /**Compare the nonStandardData part of the capability, if applicable.
1195       */
1196     virtual PBoolean IsMatch(
1197       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
1198       const PString & mediaPacketization  ///< Media packetization used
1199     ) const;
1200   //@}
1201 };
1202 
1203 /**This class describes the interface to a generic video codec used to
1204    transfer data via the logical channels opened and managed by the H323
1205    control channel.
1206 
1207    An application may create a descendent off this class and override
1208    functions as required for descibing the codec.
1209  */
1210 class H323GenericVideoCapability : public H323VideoCapability,
1211                                    public H323GenericCapabilityInfo
1212 {
1213   PCLASSINFO(H323GenericVideoCapability, H323VideoCapability);
1214 
1215   public:
1216   /**@name Construction */
1217   //@{
1218     /**Create a new set of information about a non-standard codec.
1219       */
1220     H323GenericVideoCapability(
1221       const PString & capabilityId,    ///< generic codec identifier (OID)
1222       PINDEX maxBitRate = 0           ///< maxBitRate parameter for the GenericCapability
1223     );
1224   //@}
1225 
1226   /**@name Overrides from class PObject */
1227   //@{
1228     /**Compare two capability instances. This compares the main and sub-types
1229        of the capability.
1230      */
1231     Comparison Compare(const PObject & obj) const;
1232   //@}
1233 
1234   /**@name Identification functions */
1235   //@{
1236     /**Get the sub-type of the capability. This is a code dependent on the
1237        main type of the capability.
1238 
1239        This returns H245_VideoCapability::e_genericCapability.
1240      */
1241     virtual unsigned GetSubType() const;
1242   //@}
1243 
1244   /**@name Protocol manipulation */
1245   //@{
1246     /**This function is called whenever and outgoing TerminalCapabilitySet
1247        or OpenLogicalChannel PDU is being constructed for the control channel.
1248        It allows the capability to set the PDU fields from information in
1249        members specific to the class.
1250 
1251        The default behaviour calls H323GenericCapabilityinfo::OnSendingPDU()
1252        to handle the PDU.
1253      */
1254     virtual PBoolean OnSendingPDU(
1255       H245_VideoCapability & pdu,  ///<  PDU to set information on
1256       CommandType type             ///<  Type of PDU to send in
1257     ) const;
1258 
1259     /**This function is called whenever and outgoing RequestMode
1260        PDU is being constructed for the control channel. It allows the
1261        capability to set the PDU fields from information in members specific
1262        to the class.
1263 
1264        The default behaviour sets the PDUs tag according to the GetSubType()
1265        function (translated to different enum).
1266      */
1267     virtual PBoolean OnSendingPDU(
1268       H245_VideoMode & pdu  ///<  PDU to set information on
1269     ) const;
1270 
1271     /**This function is called whenever and incoming TerminalCapabilitySet
1272        or OpenLogicalChannel PDU has been used to construct the control
1273        channel. It allows the capability to set from the PDU fields,
1274        information in members specific to the class.
1275 
1276        The default behaviour calls H323GenericCapabilityinfo::OnReceivedPDU()
1277        to handle the provided PDU.
1278      */
1279     virtual PBoolean OnReceivedPDU(
1280       const H245_VideoCapability & pdu,  ///< PDU to get information from
1281       CommandType type                   ///<  Type of PDU to send in
1282     );
1283 
1284     /**Compare the generic part of the capability, if applicable.
1285      */
1286     virtual PBoolean IsMatch(
1287       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
1288       const PString & mediaPacketization  ///< Media packetization used
1289     ) const;
1290   //@}
1291 };
1292 
1293 
1294 #if OPAL_H239
1295 
1296 /**This class descibes an extended ideo capability, as used in H.239.
1297   */
1298 class H323ExtendedVideoCapability : public H323GenericVideoCapability
1299 {
1300   PCLASSINFO(H323ExtendedVideoCapability, H323GenericVideoCapability);
1301 
1302   public:
1303   /**@name Construction */
1304   //@{
1305     /**Create a new Extended Video capability.
1306       */
1307     H323ExtendedVideoCapability(
1308       const PString & identifier   ///< generic codec identifier (OID)
1309     );
1310   //@}
1311 
1312   /**@name Identification functions */
1313   //@{
1314     /**Get the sub-type of the capability. This is a code dependent on the
1315        main type of the capability.
1316 
1317        This returns H245_VideoCapability::e_extendedVideoCapability.
1318      */
1319     virtual unsigned GetSubType() const;
1320   //@}
1321 
1322   /**@name Protocol manipulation */
1323   //@{
1324     /**This function is called whenever and outgoing TerminalCapabilitySet
1325        or OpenLogicalChannel PDU is being constructed for the control channel.
1326        It allows the capability to set the PDU fields from information in
1327        members specific to the class.
1328 
1329        The default behaviour calls H323GenericCapabilityinfo::OnSendingPDU()
1330        to handle the PDU.
1331      */
1332     virtual PBoolean OnSendingPDU(
1333       H245_VideoCapability & pdu,  ///<  PDU to set information on
1334       CommandType type             ///<  Type of PDU to send in
1335     ) const;
1336 
1337     /**This function is called whenever and outgoing RequestMode
1338        PDU is being constructed for the control channel. It allows the
1339        capability to set the PDU fields from information in members specific
1340        to the class.
1341 
1342        The default behaviour sets the PDUs tag according to the GetSubType()
1343        function (translated to different enum).
1344      */
1345     virtual PBoolean OnSendingPDU(
1346       H245_VideoMode & pdu  ///<  PDU to set information on
1347     ) const;
1348 
1349     /**This function is called whenever and incoming TerminalCapabilitySet
1350        or OpenLogicalChannel PDU has been used to construct the control
1351        channel. It allows the capability to set from the PDU fields,
1352        information in members specific to the class.
1353 
1354        The default behaviour calls H323GenericCapabilityinfo::OnReceivedPDU()
1355        to handle the provided PDU.
1356      */
1357     virtual PBoolean OnReceivedPDU(
1358       const H245_VideoCapability & pdu,  ///< PDU to get information from
1359       CommandType type                   ///<  Type of PDU to send in
1360     );
1361 
1362     /**Compare the generic part of the capability, if applicable.
1363      */
1364     virtual PBoolean IsMatch(
1365       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
1366       const PString & mediaPacketization  ///< Media packetization used
1367     ) const;
1368   //@}
1369 
1370   protected:
1371     OpalMediaFormatList m_videoFormats;
1372 };
1373 
1374 
1375 ///////////////////////////////////////////////////////////////////////////////
1376 
1377 /**This class describes a generic control capability, as used in H.239
1378  */
1379 class H323GenericControlCapability : public H323Capability,
1380                                      public H323GenericCapabilityInfo
1381 {
1382   PCLASSINFO(H323GenericControlCapability, H323Capability);
1383 
1384   public:
1385   /**@name Construction */
1386   //@{
1387     /**Create a new data capability.
1388       */
1389     H323GenericControlCapability(
1390       const PString & identifier  ///< Indentifer (OID) for generic control
1391     );
1392   //@}
1393 
1394   /**@name Identification functions */
1395   //@{
1396     /**Get the main type of the capability.
1397        Always returns e_Data.
1398      */
1399     virtual MainTypes GetMainType() const;
1400 
1401     /**Get the sub-type of the capability. This is a code dependent on the
1402        main type of the capability.
1403 
1404        This returns H245_VideoCapability::e_extendedVideoCapability.
1405      */
1406     virtual unsigned GetSubType() const;
1407   //@}
1408 
1409   /**@name Protocol manipulation */
1410   //@{
1411     /**This function is called whenever and outgoing TerminalCapabilitySet
1412        PDU is being constructed for the control channel. It allows the
1413        capability to set the PDU fields from information in members specific
1414        to the class.
1415 
1416        The default behaviour calls the OnSendingPDU() function with a more
1417        specific PDU type.
1418      */
1419     virtual PBoolean OnSendingPDU(
1420       H245_Capability & pdu  ///<  PDU to set information on
1421     ) const;
1422 
1423     /**This function is called whenever and outgoing RequestMode
1424        PDU is being constructed for the control channel. It allows the
1425        capability to set the PDU fields from information in members specific
1426        to the class.
1427 
1428        The default behaviour is pure.
1429      */
1430     virtual PBoolean OnSendingPDU(
1431       H245_ModeElement & pdu  ///<  PDU to set information on
1432     ) const;
1433 
1434     /**This function is called whenever and incoming TerminalCapabilitySet
1435        PDU is received on the control channel, and a new H323Capability
1436        descendent was created. This completes reading fields from the PDU
1437        into the classes members.
1438 
1439        If the function returns false then the received PDU codec description
1440        is not supported, so will be ignored. The default behaviour simply
1441        returns true.
1442      */
1443     virtual PBoolean OnReceivedPDU(
1444       const H245_Capability & pdu  ///<  PDU to get information from
1445     );
1446 
1447     /**Compare the generic part of the capability, if applicable.
1448      */
1449     virtual PBoolean IsMatch(
1450       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
1451       const PString & mediaPacketization  ///< Media packetization used
1452     ) const;
1453   //@}
1454 
1455   /**@name Operations */
1456   //@{
1457     /**Create the channel instance, allocating resources as required.
1458        This creates a logical channel object appropriate for the parameters
1459        provided. Not if param is NULL, sessionID must be provided, otherwise
1460        this is taken from the fields in param.
1461      */
1462     virtual H323Channel * CreateChannel(
1463       H323Connection & connection,    ///<  Owner connection for channel
1464       H323Channel::Directions dir,    ///<  Direction of channel
1465       unsigned sessionID,             ///<  Session ID for RTP channel
1466       const H245_H2250LogicalChannelParameters * param
1467                                       ///<  Parameters for channel
1468     ) const;
1469   //@}
1470 };
1471 
1472 
1473 ///////////////////////////////////////////////////////////////////////////////
1474 
1475 class H323H239VideoCapability : public H323ExtendedVideoCapability
1476 {
1477   PCLASSINFO(H323H239VideoCapability, H323ExtendedVideoCapability);
1478 
1479   public:
1480   /**@name Construction */
1481   //@{
1482     /**Create a new Extended Video capability.
1483       */
1484     H323H239VideoCapability(
1485       const OpalMediaFormat & videoFormat
1486     );
1487   //@}
1488 
1489   /**@name Overrides from class PObject */
1490   //@{
1491     /**Compare two capability instances. This compares the main and sub-types
1492        of the capability.
1493      */
1494     Comparison Compare(const PObject & obj) const;
1495 
1496     /**Create a copy of the object.
1497       */
1498     virtual PObject * Clone() const;
1499 
1500     /**Print name of capability.
1501       */
1502     void PrintOn(ostream & strm) const;
1503   //@}
1504 
1505   /**@name Identification functions */
1506   //@{
1507     /**Get the name of the media data format this class represents.
1508      */
1509     virtual PString GetFormatName() const;
1510   //@}
1511 
1512   /**@name Identification functions */
1513   //@{
1514     /**This function is called whenever and outgoing TerminalCapabilitySet
1515        or OpenLogicalChannel PDU is being constructed for the control channel.
1516        It allows the capability to set the PDU fields from information in
1517        members specific to the class.
1518 
1519        The default behaviour calls H323GenericCapabilityinfo::OnSendingPDU()
1520        to handle the PDU.
1521      */
1522     virtual PBoolean OnSendingPDU(
1523       H245_VideoCapability & pdu,  ///<  PDU to set information on
1524       CommandType type             ///<  Type of PDU to send in
1525     ) const;
1526 
1527     /**This function is called whenever and incoming TerminalCapabilitySet
1528        or OpenLogicalChannel PDU has been used to construct the control
1529        channel. It allows the capability to set from the PDU fields,
1530        information in members specific to the class.
1531 
1532        The default behaviour calls H323GenericCapabilityinfo::OnReceivedPDU()
1533        to handle the provided PDU.
1534      */
1535     virtual PBoolean OnReceivedPDU(
1536       const H245_VideoCapability & pdu,  ///< PDU to get information from
1537       CommandType type                   ///<  Type of PDU to send in
1538     );
1539   //@}
1540 };
1541 
1542 
1543 ///////////////////////////////////////////////////////////////////////////////
1544 
1545 class H323H239ControlCapability : public H323GenericControlCapability
1546 {
1547   PCLASSINFO(H323H239ControlCapability, H323GenericControlCapability);
1548 
1549   public:
1550   /**@name Construction */
1551   //@{
1552     /**Create a new Extended Video capability.
1553       */
1554     H323H239ControlCapability();
1555   //@}
1556 
1557   /**@name Overrides from class PObject */
1558   //@{
1559     /**Create a copy of the object.
1560       */
1561     virtual PObject * Clone() const;
1562   //@}
1563 
1564   /**@name Identification functions */
1565   //@{
1566     /**Get the name of the media data format this class represents.
1567      */
1568     virtual PString GetFormatName() const;
1569   //@}
1570 };
1571 
1572 
1573 #endif  // OPAL_H239
1574 
1575 #endif  // OPAL_VIDEO
1576 
1577 
1578 /**This class describes the interface to a data channel used to transfer data
1579    via the logical channels opened and managed by the H323 control channel.
1580 
1581    An application may create a descendent off this class and override
1582    functions as required for descibing a codec.
1583  */
1584 class H323DataCapability : public H323Capability
1585 {
1586   PCLASSINFO(H323DataCapability, H323Capability);
1587 
1588   public:
1589   /**@name Construction */
1590   //@{
1591     /**Create a new data capability.
1592       */
1593     H323DataCapability(
1594       unsigned maxBitRate = 0  ///<  Maximum bit rate for data in 100's b/s
1595     );
1596   //@}
1597 
1598   /**@name Identification functions */
1599   //@{
1600     /**Get the main type of the capability.
1601        Always returns e_Data.
1602      */
1603     virtual MainTypes GetMainType() const;
1604   //@}
1605 
1606   /**@name Operations */
1607   //@{
1608     /**Get the default RTP session.
1609        This function gets the default RTP session ID for the capability
1610        type. For example audio capabilities return the value
1611        RTP_Session::DefaultAudioSessionID etc.
1612 
1613        The default behaviour returns 3, indicating a data session.
1614       */
1615     virtual unsigned GetDefaultSessionID() const;
1616   //@}
1617 
1618   /**@name Protocol manipulation */
1619   //@{
1620     /**This function is called whenever and outgoing TerminalCapabilitySet
1621        PDU is being constructed for the control channel. It allows the
1622        capability to set the PDU fields from information in members specific
1623        to the class.
1624 
1625        The default behaviour calls the OnSendingPDU() function with a more
1626        specific PDU type.
1627      */
1628     virtual PBoolean OnSendingPDU(
1629       H245_Capability & pdu  ///<  PDU to set information on
1630     ) const;
1631 
1632     /**This function is called whenever and outgoing OpenLogicalChannel
1633        PDU is being constructed for the control channel. It allows the
1634        capability to set the PDU fields from information in members specific
1635        to the class.
1636 
1637        The default behaviour calls the OnSendingPDU() function with a more
1638        specific PDU type.
1639      */
1640     virtual PBoolean OnSendingPDU(
1641       H245_DataType & pdu  ///<  PDU to set information on
1642     ) const;
1643 
1644     /**This function is called whenever and outgoing RequestMode
1645        PDU is being constructed for the control channel. It allows the
1646        capability to set the PDU fields from information in members specific
1647        to the class.
1648 
1649        The default behaviour calls the OnSendingPDU() function with a more
1650        specific PDU type.
1651      */
1652     virtual PBoolean OnSendingPDU(
1653       H245_ModeElement & pdu  ///<  PDU to set information on
1654     ) const;
1655 
1656     /**This function is called whenever and outgoing TerminalCapabilitySet
1657        or OpenLogicalChannel PDU is being constructed for the control channel.
1658        It allows the capability to set the PDU fields from information in
1659        members specific to the class.
1660 
1661        The default behaviour is pure.
1662      */
1663     virtual PBoolean OnSendingPDU(
1664       H245_DataApplicationCapability & pdu  ///<  PDU to set information on
1665     ) const;
1666     virtual PBoolean OnSendingPDU(
1667       H245_DataApplicationCapability & pdu, ///<  PDU to set information on
1668       CommandType type                      ///<  Type of PDU to send in
1669     ) const;
1670 
1671     /**This function is called whenever and outgoing RequestMode
1672        PDU is being constructed for the control channel. It allows the
1673        capability to set the PDU fields from information in members specific
1674        to the class.
1675 
1676        The default behaviour sets the PDUs tag according to the GetSubType()
1677        function (translated to different enum).
1678      */
1679     virtual PBoolean OnSendingPDU(
1680       H245_DataMode & pdu  ///<  PDU to set information on
1681     ) const = 0;
1682 
1683     /**This function is called whenever and incoming TerminalCapabilitySet
1684        PDU is received on the control channel, and a new H323Capability
1685        descendent was created. This completes reading fields from the PDU
1686        into the classes members.
1687 
1688        If the function returns false then the received PDU codec description
1689        is not supported, so will be ignored. The default behaviour simply
1690        returns true.
1691      */
1692     virtual PBoolean OnReceivedPDU(
1693       const H245_Capability & pdu  ///<  PDU to get information from
1694     );
1695 
1696     /**This function is called whenever and incoming OpenLogicalChannel
1697        PDU has been used to construct the control channel. It allows the
1698        capability to set from the PDU fields, information in members specific
1699        to the class.
1700 
1701        The default behaviour is pure.
1702      */
1703     virtual PBoolean OnReceivedPDU(
1704       const H245_DataType & pdu,  ///<  PDU to get information from
1705       PBoolean receiver               ///<  Is receiver OLC
1706     );
1707 
1708     /**This function is called whenever and incoming TerminalCapabilitySet
1709        or OpenLogicalChannel PDU has been used to construct the control
1710        channel. It allows the capability to set from the PDU fields,
1711        information in members specific to the class.
1712 
1713        The default behaviour is pure.
1714      */
1715     virtual PBoolean OnReceivedPDU(
1716       const H245_DataApplicationCapability & pdu  ///<  PDU to set information on
1717     );
1718     virtual PBoolean OnReceivedPDU(
1719       const H245_DataApplicationCapability & pdu, ///<  PDU to set information on
1720       CommandType type                            ///<  Type of PDU to send in
1721     );
1722   //@}
1723 
1724   protected:
1725     unsigned maxBitRate;
1726 };
1727 
1728 
1729 /**This class describes the interface to a non-standard data codec used to
1730    transfer data via the logical channels opened and managed by the H323
1731    control channel.
1732 
1733    An application may create a descendent off this class and override
1734    functions as required for descibing the codec.
1735  */
1736 class H323NonStandardDataCapability : public H323DataCapability,
1737                                       public H323NonStandardCapabilityInfo
1738 {
1739   PCLASSINFO(H323NonStandardDataCapability, H323DataCapability);
1740 
1741   public:
1742   /**@name Construction */
1743   //@{
1744     /**Create a new set of information about a non-standard codec.
1745       */
1746     H323NonStandardDataCapability(
1747       unsigned maxBitRate,            ///<  Maximum bit rate for data in 100's b/s
1748       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1749       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1750       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1751       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1752     );
1753 
1754     /**Create a new set of information about a non-standard codec.
1755       */
1756     H323NonStandardDataCapability(
1757       unsigned maxBitRate,            ///<  Maximum bit rate for data in 100's b/s
1758       const PString & oid,            ///<  OID for indentification of codec
1759       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1760       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1761       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1762       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1763     );
1764 
1765     /**Create a new set of information about a non-standard codec.
1766       */
1767     H323NonStandardDataCapability(
1768       unsigned maxBitRate,            ///<  Maximum bit rate for data in 100's b/s
1769       BYTE country,                   ///<  t35 information
1770       BYTE extension,                 ///<  t35 information
1771       WORD maufacturer,               ///<  t35 information
1772       const BYTE * dataBlock = NULL,  ///<  Non-Standard data for codec type
1773       PINDEX dataSize = 0,            ///<  Size of dataBlock. If 0 and dataBlock != NULL use strlen(dataBlock)
1774       PINDEX comparisonOffset = 0,    ///<  Offset into dataBlock to compare
1775       PINDEX comparisonLength = P_MAX_INDEX  ///<  Length of bytes to compare
1776     );
1777   //@}
1778 
1779   /**@name Overrides from class PObject */
1780   //@{
1781     /**Compare two capability instances. This compares the main and sub-types
1782        of the capability.
1783      */
1784     Comparison Compare(const PObject & obj) const;
1785   //@}
1786 
1787   /**@name Identification functions */
1788   //@{
1789     /**Get the sub-type of the capability. This is a code dependent on the
1790        main type of the capability.
1791 
1792        This returns one of the four possible combinations of mode and speed
1793        using the enum values of the protocol ASN H245_AudioCapability class.
1794      */
1795     virtual unsigned GetSubType() const;
1796   //@}
1797 
1798   /**@name Protocol manipulation */
1799   //@{
1800     /**This function is called whenever and outgoing TerminalCapabilitySet
1801        or OpenLogicalChannel PDU is being constructed for the control channel.
1802        It allows the capability to set the PDU fields from information in
1803        members specific to the class.
1804 
1805        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
1806        to handle the PDU.
1807      */
1808     virtual PBoolean OnSendingPDU(
1809       H245_DataApplicationCapability & pdu  ///<  PDU to set information on
1810     ) const;
1811 
1812     /**This function is called whenever and outgoing RequestMode
1813        PDU is being constructed for the control channel. It allows the
1814        capability to set the PDU fields from information in members specific
1815        to the class.
1816 
1817        The default behaviour calls H323NonStandardCapabilityinfo::OnSendingPDU()
1818        to handle the PDU.
1819      */
1820     virtual PBoolean OnSendingPDU(
1821       H245_DataMode & pdu  ///<  PDU to set information on
1822     ) const;
1823 
1824     /**This function is called whenever and incoming TerminalCapabilitySet
1825        or OpenLogicalChannel PDU has been used to construct the control
1826        channel. It allows the capability to set from the PDU fields,
1827        information in members specific to the class.
1828 
1829        The default behaviour calls H323NonStandardCapabilityinfo::OnReceivedPDU()
1830        to handle the provided PDU.
1831      */
1832     virtual PBoolean OnReceivedPDU(
1833       const H245_DataApplicationCapability & pdu  ///<  PDU to set information on
1834     );
1835 
1836     /**Compare the nonStandardData part of the capability, if applicable.
1837       */
1838     virtual PBoolean IsMatch(
1839       const PASN_Choice & subTypePDU,     ///<  sub-type PDU of H323Capability
1840       const PString & mediaPacketization  ///< Media packetization used
1841     ) const;
1842   //@}
1843 };
1844 
1845 
1846 ///////////////////////////////////////////////////////////////////////////////
1847 // Known audio codecs
1848 
1849 /**This class describes the G.711 codec capability.
1850  */
1851 class H323_G711Capability : public H323AudioCapability
1852 {
1853   PCLASSINFO(H323_G711Capability, H323AudioCapability)
1854 
1855   public:
1856     /// Specific G.711 encoding algorithm.
1857     enum Mode {
1858       /// European standard
1859       ALaw,
1860       /// American standard
1861       muLaw
1862     };
1863     /// Specific G.711 encoding bit rates.
1864     enum Speed {
1865       /// European standard
1866       At64k,
1867       /// American standard
1868       At56k
1869     };
1870 
1871   /**@name Construction */
1872   //@{
1873     /**Create a new G.711 capability.
1874      */
1875     H323_G711Capability(
1876       Mode mode = muLaw,    ///<  Type of encoding.
1877       Speed speed = At64k   ///<  Encoding bit rate.
1878     );
1879   //@}
1880 
1881   /**@name Overrides from class PObject */
1882   //@{
1883     /**Create a copy of the object.
1884       */
1885     virtual PObject * Clone() const;
1886   //@}
1887 
1888   /**@name Identification functions */
1889   //@{
1890     /**Get the sub-type of the capability. This is a code dependent on the
1891        main type of the capability.
1892 
1893        This returns one of the four possible combinations of mode and speed
1894        using the enum values of the protocol ASN H245_AudioCapability class.
1895      */
1896     virtual unsigned GetSubType() const;
1897 
1898     /**Get the name of the media data format this class represents.
1899      */
1900     virtual PString GetFormatName() const;
1901   //@}
1902 
1903   protected:
1904     Mode     mode;
1905     Speed    speed;
1906 };
1907 
1908 ///////////////////////////////////////////////////////////////////////////////
1909 
1910 /**This class describes the UserInput psuedo-channel.
1911  */
1912 class H323_UserInputCapability : public H323Capability
1913 {
1914   PCLASSINFO(H323_UserInputCapability, H323Capability);
1915 
1916   public:
1917   /**@name Construction */
1918   //@{
1919     enum SubTypes {
1920       BasicString,
1921       IA5String,
1922       GeneralString,
1923       SignalToneH245,
1924       HookFlashH245,
1925       SignalToneRFC2833,
1926       NumSubTypes
1927     };
1928     static const char * GetSubTypeName(SubTypes subType);
1929     friend ostream & operator<<(ostream & strm, SubTypes subType) { return strm << GetSubTypeName(subType); }
1930 
1931     /**Create the capability for User Input.
1932        The subType parameter is a value from the enum
1933        H245_UserInputCapability::Choices.
1934       */
1935     H323_UserInputCapability(
1936       SubTypes subType
1937     );
1938   //@}
1939 
1940   /**@name Overrides from class PObject */
1941   //@{
1942     /**Create a copy of the object.
1943       */
1944     virtual PObject * Clone() const;
1945   //@}
1946 
1947   /**@name Identification functions */
1948   //@{
1949     /**Get the main type of the capability.
1950 
1951        This function is overridden by one of the three main sub-classes off
1952        which real capabilities would be descendend.
1953      */
1954     virtual MainTypes GetMainType() const;
1955 
1956     /**Get the sub-type of the capability. This is a code dependent on the
1957        main type of the capability.
1958      */
1959     virtual unsigned  GetSubType()  const;
1960 
1961     /**Get the name of the media data format this class represents.
1962      */
1963     virtual PString GetFormatName() const;
1964   //@}
1965 
1966   /**@name Operations */
1967   //@{
1968     /**Create the channel instance, allocating resources as required.
1969        This creates a logical channel object appropriate for the parameters
1970        provided. Not if param is NULL, sessionID must be provided, otherwise
1971        this is taken from the fields in param.
1972      */
1973     virtual H323Channel * CreateChannel(
1974       H323Connection & connection,    ///<  Owner connection for channel
1975       H323Channel::Directions dir,    ///<  Direction of channel
1976       unsigned sessionID,             ///<  Session ID for RTP channel
1977       const H245_H2250LogicalChannelParameters * param
1978                                       ///<  Parameters for channel
1979     ) const;
1980   //@}
1981 
1982   /**@name Protocol manipulation */
1983   //@{
1984     /**This function is called whenever and outgoing TerminalCapabilitySet
1985        PDU is being constructed for the control channel. It allows the
1986        capability to set the PDU fields from information in members specific
1987        to the class.
1988 
1989        The default behaviour is pure.
1990      */
1991     virtual PBoolean OnSendingPDU(
1992       H245_Capability & pdu  ///<  PDU to set information on
1993     ) const;
1994 
1995     /**This function is called whenever and outgoing OpenLogicalChannel
1996        PDU is being constructed for the control channel. It allows the
1997        capability to set the PDU fields from information in members specific
1998        to the class.
1999 
2000        The default behaviour is pure.
2001      */
2002     virtual PBoolean OnSendingPDU(
2003       H245_DataType & pdu  ///<  PDU to set information on
2004     ) const;
2005 
2006     /**This function is called whenever and outgoing RequestMode
2007        PDU is being constructed for the control channel. It allows the
2008        capability to set the PDU fields from information in members specific
2009        to the class.
2010 
2011        The default behaviour calls the OnSendingPDU() function with a more
2012        specific PDU type.
2013      */
2014     virtual PBoolean OnSendingPDU(
2015       H245_ModeElement & pdu  ///<  PDU to set information on
2016     ) const;
2017 
2018     /**This function is called whenever and incoming TerminalCapabilitySet
2019        PDU is received on the control channel, and a new H323Capability
2020        descendent was created. This completes reading fields from the PDU
2021        into the classes members.
2022 
2023        If the function returns false then the received PDU codec description
2024        is not supported, so will be ignored. The default behaviour simply
2025        returns true.
2026      */
2027     virtual PBoolean OnReceivedPDU(
2028       const H245_Capability & pdu  ///<  PDU to get information from
2029     );
2030 
2031     /**This function is called whenever and incoming OpenLogicalChannel
2032        PDU has been used to construct the control channel. It allows the
2033        capability to set from the PDU fields, information in members specific
2034        to the class.
2035 
2036        The default behaviour is pure.
2037      */
2038     virtual PBoolean OnReceivedPDU(
2039       const H245_DataType & pdu,  ///<  PDU to get information from
2040       PBoolean receiver               ///<  Is receiver OLC
2041     );
2042 
2043     /**Validate that the capability is usable given the connection.
2044        This checks agains the negotiated protocol version number and remote
2045        application to determine if this capability should be used in TCS or
2046        OLC pdus.
2047 
2048        The default behaviour will check for early versions and return false
2049        for RFC2833 mode.
2050       */
2051     virtual PBoolean IsUsable(
2052       const H323Connection & connection
2053     ) const;
2054   //@}
2055 
2056     static void AddAllCapabilities(
2057       H323Capabilities & capabilities,  ///<  Table to add capabilities to
2058       PINDEX descriptorNum,             ///<  The member of the capabilityDescriptor to add
2059       PINDEX simultaneous,              ///<  The member of the SimultaneousCapabilitySet to add
2060       bool includeRFC2833 = true
2061     );
2062 
2063   protected:
2064     SubTypes subType;
2065 };
2066 
2067 
2068 
2069 ///////////////////////////////////////////////////////////////////////////////
2070 
2071 PARRAY(H323CapabilitiesList, H323Capability);
2072 
2073 PARRAY(H323CapabilitiesListArray, H323CapabilitiesList);
2074 
2075 class H323SimultaneousCapabilities : public H323CapabilitiesListArray
2076 {
2077   PCLASSINFO(H323SimultaneousCapabilities, H323CapabilitiesListArray);
2078   public:
2079     PBoolean SetSize(PINDEX newSize);
2080 };
2081 
2082 
2083 PARRAY(H323CapabilitiesSetArray, H323SimultaneousCapabilities);
2084 
2085 
2086 class H323CapabilitiesSet : public H323CapabilitiesSetArray
2087 {
2088   PCLASSINFO(H323CapabilitiesSet, H323CapabilitiesSetArray);
2089   public:
2090     /// Set the new size of the table, internal use only.
2091     PBoolean SetSize(PINDEX newSize);
2092 };
2093 
2094 
2095 /**This class contains all of the capabilities and their combinations.
2096   */
2097 class H323Capabilities : public PObject
2098 {
2099     PCLASSINFO(H323Capabilities, PObject);
2100   public:
2101   /**@name Construction */
2102   //@{
2103     /**Construct an empty capability set.
2104       */
2105     H323Capabilities();
2106 
2107     /**Construct a capability set from the H.245 PDU provided.
2108       */
2109     H323Capabilities(
2110       const H323Connection & connection,      ///<  Connection for capabilities
2111       const H245_TerminalCapabilitySet & pdu  ///<  PDU to convert to a capability set.
2112     );
2113 
2114     /**Construct a copy of a capability set.
2115        Note this will completely duplicate the set by making clones of every
2116        capability in the original set.
2117       */
2118     H323Capabilities(
2119       const H323Capabilities & original ///<  Original capabilities to duplicate
2120     );
2121 
2122     /**Assign a copy of a capability set.
2123        Note this will completely duplicate the set by making clones of every
2124        capability in the original set.
2125       */
2126     H323Capabilities & operator=(
2127       const H323Capabilities & original ///<  Original capabilities to duplicate
2128     );
2129   //@}
2130 
2131   /**@name Overrides from class PObject */
2132   //@{
2133     /**Print out the object to the stream, virtual version of << operator.
2134      */
2135     void PrintOn(
2136       ostream & strm    ///<  Stream to print out to.
2137     ) const;
2138   //@}
2139 
2140   /**@name Operations */
2141   //@{
2142     /**Get the number of capabilities in the set.
2143       */
GetSize()2144     PINDEX GetSize() const { return table.GetSize(); }
2145 
2146     /**Get the capability at the specified index.
2147       */
2148     H323Capability & operator[](PINDEX i) const { return table[i]; }
2149 
2150     /**Set the capability descriptor lists. This is three tier set of
2151        codecs. The top most level is a list of particular capabilities. Each
2152        of these consists of a list of alternatives that can operate
2153        simultaneously. The lowest level is a list of codecs that cannot
2154        operate together. See H323 section 6.2.8.1 and H245 section 7.2 for
2155        details.
2156 
2157        If descriptorNum is P_MAX_INDEX, the the next available index in the
2158        array of descriptors is used. Similarly if simultaneous is P_MAX_INDEX
2159        the the next available SimultaneousCapabilitySet is used. The return
2160        value is the index used for the new entry. Note if both are P_MAX_INDEX
2161        then the return value is the descriptor index as the simultaneous index
2162        must be zero.
2163 
2164        Note that the capability specified here is automatically added to the
2165        capability table using the AddCapability() function. A specific
2166        instance of a capability is only ever added once, so multiple
2167        SetCapability() calls with the same H323Capability pointer will only
2168        add that capability once.
2169      */
2170     PINDEX SetCapability(
2171       PINDEX descriptorNum, ///<  The member of the capabilityDescriptor to add
2172       PINDEX simultaneous,  ///<  The member of the SimultaneousCapabilitySet to add
2173       H323Capability * cap  ///<  New capability specification
2174     );
2175 
2176     /**Add matching capability to media format.
2177       */
2178     PINDEX AddMediaFormat(
2179       PINDEX descriptorNum,    ///<  The member of the capabilityDescriptor to add
2180       PINDEX simultaneous,     ///<  The member of the SimultaneousCapabilitySet to add
2181       const OpalMediaFormat & mediaFormat ///<  Media format to add.
2182     );
2183 
2184     /**Add all matching capabilities to descriptor lists.
2185        All capabilities that match the specified name are added as in the other
2186        form of the SetCapability() function.
2187       */
2188     PINDEX AddAllCapabilities(
2189       PINDEX descriptorNum,    ///<  The member of the capabilityDescriptor to add
2190       PINDEX simultaneous,     ///<  The member of the SimultaneousCapabilitySet to add
2191       const PString & name,    ///<  New capabilities name, if using "known" one.
2192       PBoolean exact = false       ///<  Capability name must be exact match
2193     );
2194 
2195     // this function is retained for backwards compatibility
2196     PINDEX AddAllCapabilities(
2197       const H323EndPoint &,    ///<  The endpoint adding the capabilities.
2198       PINDEX descriptorNum,    ///<  The member of the capabilityDescriptor to add
2199       PINDEX simultaneous,     ///<  The member of the SimultaneousCapabilitySet to add
2200       const PString & name,    ///<  New capabilities name, if using "known" one.
2201       PBoolean exact = false       ///<  Capability name must be exact match
2202     )
2203     { return AddAllCapabilities(descriptorNum, simultaneous, name, exact); }
2204 
2205     /**Add a codec to the capabilities table. This will assure that the
2206        assignedCapabilityNumber field in the capability is unique for all
2207        capabilities installed on this set.
2208 
2209        If the specific instance of the capability is already in the table, it
2210        is not added again. Ther can be multiple instances of the same
2211        capability class however.
2212      */
2213     void Add(
2214       H323Capability * capability   ///<  New capability specification
2215     );
2216 
2217     /**Copy a codec to the capabilities table. This will make a clone of the
2218        capability and assure that the assignedCapabilityNumber field in the
2219        capability is unique for all capabilities installed on this set.
2220 
2221        Returns the copy that is put in the table.
2222      */
2223     H323Capability * Copy(
2224       const H323Capability & capability   ///<  New capability specification
2225     );
2226 
2227     /**Remove a capability from the table. Note that the the parameter must be
2228        the actual instance of the capability in the table. The instance is
2229        deleted when removed from the table.
2230       */
2231     void Remove(
2232       H323Capability * capability   ///<  Existing capability specification
2233     );
2234 
2235     /**Remove all capabilities matching the string. This uses FindCapability()
2236        to locate the first capability whose format name does a partial match
2237        for the argument.
2238       */
2239     void Remove(
2240       const PString & formatName   ///<  Format name to search for.
2241     );
2242 
2243     /**Remove all capabilities matching any of the strings provided. This
2244        simply calls Remove() for each string in the list.
2245       */
2246     void Remove(
2247       const PStringArray & formatNames  ///<  Array of format names to remove
2248     );
2249 
2250     /**Remove all of the capabilities.
2251       */
2252     void RemoveAll();
2253 
2254     /**Find the capability given the capability number. This number is
2255        guarenteed to be unique for a give capability table. Note that is may
2256        not be the same as the index into the table.
2257 
2258        Returns:
2259        NULL if no capability meeting the criteria was found
2260       */
2261     H323Capability * FindCapability(
2262       unsigned capabilityNumber
2263     ) const;
2264 
2265     /**Find the capability given the capability format name string. This does
2266        a partial match for the supplied argument. If the argument matches a
2267        substring of the actual capabilities name, then it is returned. For
2268        example "GSM" or "0610" will match "GSM 0610". Note case is not
2269        significant.
2270 
2271        The user should be carefull of using short strings such as "G"!
2272 
2273        The direction parameter can further refine the search for specific
2274        receive or transmit capabilities. The default value of e_Unknown will
2275        wildcard that field.
2276 
2277        Returns:
2278        NULL if no capability meeting the criteria was found
2279       */
2280     H323Capability * FindCapability(
2281       const PString & formatName, ///<  Wildcard format name to search for
2282       H323Capability::CapabilityDirection direction = H323Capability::e_Unknown,
2283             ///<  Optional direction to include into search criteria
2284       PBoolean exact = false       ///<  Capability name must be exact match
2285     ) const;
2286 
2287     /**Find the first capability in the table of the specified direction.
2288 
2289        Returns:
2290        NULL if no capability meeting the criteria was found
2291       */
2292     H323Capability * FindCapability(
2293       H323Capability::CapabilityDirection direction ///<  Direction to search for
2294     ) const;
2295 
2296     /**Find the capability given the capability. This does a value compare of
2297        the two capabilities. Usually this means the mainType and subType are
2298        the same.
2299 
2300        Returns:
2301        NULL if no capability meeting the criteria was found
2302       */
2303     H323Capability * FindCapability(
2304       const H323Capability & capability ///<  Capability to search for
2305     ) const;
2306 
2307     /**Find the capability given the H.245 capability PDU.
2308 
2309        Returns:
2310        NULL if no capability meeting the criteria was found
2311       */
2312     H323Capability * FindCapability(
2313       const H245_Capability & cap  ///<  H245 capability table entry
2314     ) const;
2315 
2316     /**Find the capability given the H.245 data type PDU.
2317 
2318        Returns:
2319        NULL if no capability meeting the criteria was found
2320       */
2321     H323Capability * FindCapability(
2322       const H245_DataType & dataType,  ///<  H245 data type of codec
2323       const PString & mediaPacketization = PString::Empty()  ///< Media packetization, if present
2324     ) const;
2325 
2326     /**Find the capability given the H.245 data type PDU.
2327 
2328        Returns:
2329        NULL if no capability meeting the criteria was found
2330       */
2331     H323Capability * FindCapability(
2332       const H245_ModeElement & modeElement,  ///<  H245 data type of codec
2333       const PString & mediaPacketization = PString::Empty()  ///< Media packetization, if present
2334     ) const;
2335 
2336     /**Find the capability given the type codecs.
2337 
2338        Returns:
2339        NULL if no capability meeting the criteria was found
2340       */
2341     H323Capability * FindCapability(
2342       H323Capability::MainTypes mainType, ///<  Main type to find
2343       unsigned subType = UINT_MAX         ///<  Sub-type to find (UINT_MAX=ignore)
2344     ) const;
2345 
2346     /**Build a H.245 PDU from the information in the capability set.
2347       */
2348     void BuildPDU(
2349       const H323Connection & connection,  ///<  Connection building PDU for
2350       H245_TerminalCapabilitySet & pdu    ///<  PDU to build
2351     ) const;
2352 
2353     /**Merge the capabilities into this set.
2354       */
2355     PBoolean Merge(
2356       const H323Capabilities & newCaps
2357     );
2358 
2359     /**Change the order of capabilities in the table to the order specified.
2360        Note that this does not change the unique capability numbers assigned
2361        when the capability is first added to the set.
2362 
2363        The string matching rules are as for the FindCapability() function.
2364       */
2365     void Reorder(
2366       const PStringArray & preferenceOrder  ///<  New order
2367     );
2368 
2369     /**Test if the capability is allowed.
2370       */
2371     PBoolean IsAllowed(
2372       const H323Capability & capability
2373     );
2374 
2375     /**Test if the capability is allowed.
2376       */
2377     PBoolean IsAllowed(
2378       unsigned capabilityNumber
2379     );
2380 
2381     /**Test if the capabilities are an allowed combination.
2382       */
2383     PBoolean IsAllowed(
2384       const H323Capability & capability1,
2385       const H323Capability & capability2
2386     );
2387 
2388     /**Test if the capabilities are an allowed combination.
2389       */
2390     PBoolean IsAllowed(
2391       unsigned capabilityNumber1,
2392       unsigned capabilityNumber2
2393     );
2394 
2395     /**Get the list of capabilities as a list of media formats.
2396       */
2397     OpalMediaFormatList GetMediaFormats() const;
2398 
GetMediaPacketizations()2399     const PStringSet & GetMediaPacketizations() const { return m_mediaPacketizations; }
2400   //@}
2401 
2402   protected:
2403     H323CapabilitiesList table;
2404     H323CapabilitiesSet  set;
2405     PStringSet           m_mediaPacketizations;
2406 };
2407 
2408 
2409 ///////////////////////////////////////////////////////////////////////////////
2410 
2411 /* New capability registration macros based on abstract factories
2412  */
2413 typedef PFactory<H323Capability, std::string> H323CapabilityFactory;
2414 
2415 #define H323_REGISTER_CAPABILITY(cls, capName)   static H323CapabilityFactory::Worker<cls> cls##Factory(capName, true); \
2416 
2417 
2418 #endif // OPAL_H323
2419 
2420 #endif // OPAL_H323_H323CAPS_H
2421 
2422 
2423 /////////////////////////////////////////////////////////////////////////////
2424