# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: h323plus/include/channels.h
--- h323plus/include/channels.h Base (1.5)
+++ h323plus/include/channels.h Locally Modified (Based On 1.5)
@@ -758,6 +758,8 @@
      */
     virtual unsigned GetSessionID() const;
 
+        void SetSessionID(unsigned id);
+
     /**Open the channel.
       */
     virtual PBoolean Open();
Index: h323plus/include/h323caps.h
--- h323plus/include/h323caps.h Base (1.21)
+++ h323plus/include/h323caps.h Locally Modified (Based On 1.21)
@@ -2506,6 +2506,10 @@
       const H245_Capability & cap  ///< H245 capability table entry
     ) const;
 
+    H323Capabilities FindCapabilities(
+	const H245_Capability & cap  ///< H245 capability table entry
+    ) const;
+    
     /**Find the capability given the H.245 data type PDU.
 
        Returns:
@@ -2535,6 +2539,18 @@
 	    const H245_GenericCapability & gen		///< Generic cap
 	) const;
 
+      /**Find generic capability.
+	Returns:
+	NULL if no capability meeting the criteria was found
+	*/
+	H323Capabilities FindCapabilities(
+            H323Capability::MainTypes mainType,		///< Main type to find
+            const PASN_Choice & subTypePDU,			///< Sub-type info
+            const H245_GenericCapability & gen		///< Generic cap
+	) const;
+
+        
+        
     /**Find the capability given the sub-type info.
 
        Returns:
@@ -2546,6 +2562,17 @@
       const unsigned * translationTable   ///< Translation table sub-type tags
     ) const;
 
+    /**Find the capabilities given the sub-type info.
+
+	Returns:
+	NULL if no capability meeting the criteria was found
+	*/
+	H323Capabilities FindCapabilities(
+            H323Capability::MainTypes mainType, ///< Main type to find
+            const PASN_Choice & subTypePDU,     ///< Sub-type info
+            const unsigned * translationTable   ///< Translation table sub-type tags
+	) const;  
+    
     /**Find the capability given the type codecs.
 
        Returns:
@@ -2556,6 +2583,18 @@
       unsigned subType = UINT_MAX         ///< Sub-type to find (UINT_MAX=ignore)
     ) const;
 
+    /**Find the capability given the type codecs.
+
+	Returns:
+	NULL if no capability meeting the criteria was found
+	*/
+	H323Capabilities FindCapabilities(
+            H323Capability::MainTypes mainType, ///< Main type to find
+            unsigned subType = UINT_MAX         ///< Sub-type to find (UINT_MAX=ignore)
+	) const;
+
+
+    
     /**Build a H.245 PDU from the information in the capability set.
       */
     void BuildPDU(
Index: h323plus/include/h323con.h
--- h323plus/include/h323con.h Base (1.48)
+++ h323plus/include/h323con.h Locally Modified (Based On 1.48)
@@ -2131,12 +2131,8 @@
       */
     virtual void OpenExtendedVideoSessionDenied();
 
-	/** On Receiving a H.239 Control Request
-	    Return False to reject the request to open channel.
-	*/
-    virtual PBoolean OnH239ControlRequest();
 
-	/** Open an Extended Video Session
+	/** Open an Extended Video Session with logical channel
 	    This will open an Extended Video session.
 	*/
     PBoolean OpenExtendedVideoSession(H323ChannelNumber & num);
@@ -2167,8 +2163,6 @@
       H323VideoCodec & codec ///< codec doing the opening
     );
 
-	virtual PBoolean SendH239GenericResponse(PBoolean response);
-
 #endif // H323_H239
 
 #endif // NO_H323_VIDEO
@@ -2306,6 +2300,8 @@
       */
     unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
 
+     H323ChannelNumber  GeExtendedChannelNum() const { return m_H239ChanId; }
+
     /**Set the available bandwidth in 100's of bits/sec.
        Note if the force parameter is TRUE this function will close down
        active logical channels to meet the new bandwidth requirement.
@@ -3405,6 +3401,25 @@
 	virtual PBoolean OnReceivedGenericMessage(h245MessageType, const PString & );
 	virtual PBoolean OnReceivedGenericMessage(h245MessageType type, const PString & id, const H245_ArrayOf_GenericParameter & content);
 
+#ifdef H323_H239
+
+	enum H239SubMessageIdentifier
+	{
+		h239smiFlowControlReleaseRequest = 1,
+		h239smiFlowControlReleaseResponse,
+		h239smiPresintationTokenRequest,
+		h239smiPresintationTokenResponse,
+		h239smiPresintationTokenRelease,
+		h239smiPresintationTokenIndicateOwner
+	};
+
+	PBoolean OnH239GenericMessageResponse(const H245_ArrayOf_GenericParameter & content);
+	PBoolean OnH239GenericMessageRequest(const H245_ArrayOf_GenericParameter & content);
+	void BuildH239GenericMessageResponse(H323ControlPDU& pdu, H239SubMessageIdentifier submesId);
+	void BuildH239GenericMessageRequest(H323ControlPDU& pdu, H239SubMessageIdentifier submesId);
+	void BuildH239GenericMessageIndication(H323ControlPDU& pdu, H239SubMessageIdentifier submesId);
+
+#endif //H323_H239        
 #ifdef H323_H230
     /** Open Conference Controls
       */
@@ -3609,6 +3624,15 @@
 	PAec * aec;
 #endif
 
+#ifdef H323_H239
+
+	bool		m_allowOutgoingExtVideo;
+	unsigned	m_outgoingExtVideoChanNum;
+	unsigned	m_incomingExtVideoChanNum;
+
+
+#endif // H323_H239
+       
     PBoolean nonCallConnection; 
 
   private:
@@ -3676,7 +3700,7 @@
 #endif
 
 #ifdef H323_H239
-	PBoolean DecodeH239GenericResponse(const H245_ArrayOf_GenericParameter & params);
+	//PBoolean DecodeH239GenericResponse(const H245_ArrayOf_GenericParameter & params);
     H323ChannelNumber m_H239ChanId;
 #endif
 };
Index: h323plus/include/h323ep.h
--- h323plus/include/h323ep.h Base (1.30)
+++ h323plus/include/h323ep.h Locally Modified (Based On 1.30)
@@ -651,8 +651,7 @@
     /** Open Extended Video Session
 	  */
 	PBoolean OpenExtendedVideoSession(
-		const PString & token,   ///< Connection Token
-		H323ChannelNumber & num  ///< Opened Channel number
+		const PString & token   ///< Connection Token
 	);
 
     PBoolean CloseExtendedVideoSession(
@@ -863,6 +862,10 @@
 	 */
 	virtual void OnUnRegisterRequest(); 
 
+        /**Called when Unregistered by Gatekeeper 
+	*/
+	virtual void OnUnRegisterConfirm(); 
+
 	/**Called when TTL registration fails 
 	 */
 	virtual void OnRegisterTTLFail();
Index: h323plus/include/h323neg.h
--- h323plus/include/h323neg.h Base (1.2)
+++ h323plus/include/h323neg.h Locally Modified (Based On 1.2)
@@ -373,6 +373,7 @@
     virtual PBoolean HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
 
     H323ChannelNumber GetNextChannelNumber();
+    H323ChannelNumber GetLastChannelNumber()const;
     PINDEX GetSize() const { return channels.GetSize(); }
     H323Channel * GetChannelAt(PINDEX i);
     H323Channel * FindChannel(unsigned channelNumber, PBoolean fromRemote);
Index: h323plus/include/h323pdu.h
--- h323plus/include/h323pdu.h Base (1.5)
+++ h323plus/include/h323pdu.h Locally Modified (Based On 1.5)
@@ -604,6 +604,9 @@
       unsigned channelNumber,
       unsigned cause
     );
+    H245_IndicationMessage & BuildLogicalChannelActive(
+      unsigned channelNumber
+    );
     H245_OpenLogicalChannelConfirm & BuildOpenLogicalChannelConfirm(
       unsigned channelNumber
     );
Index: h323plus/include/openh323buildopts.h
--- h323plus/include/openh323buildopts.h Base (1.5)
+++ h323plus/include/openh323buildopts.h Locally Modified (Based On 1.5)
@@ -1,3 +1,4 @@
+/* include/openh323buildopts.h.  Generated from openh323buildopts.h.in by configure.  */
 /*
  * openh323buildopts.h
  *
@@ -23,10 +24,16 @@
  *
  * Contributor(s): ______________________________________.
  *
- * $Log: openh323buildopts.h,v $
- * Revision 1.5  2010/01/04 05:54:47  shorne
- * Added SetCallingSubAddressIE and SetCalledSubAddressIE support
+ * $Log: openh323buildopts.h.in,v $
+ * Revision 1.18  2010/05/03 00:45:50  shorne
+ * Temporarily lock the ptlib version to 2.8.x until the commits are made to ptlib
  *
+ * Revision 1.17  2010/05/02 22:41:41  shorne
+ * Added ptlib 2.9 check
+ *
+ * Revision 1.16  2010/03/17 07:29:40  willamowius
+ * disable all H.460 features when H.460 is disabled
+ *
  * Revision 1.15  2009/12/08 13:02:26  shorne
  * Adjust H323_H46024B compiler directive
  *
@@ -196,9 +203,12 @@
 #if PTLIB_MAJOR == 2 && PTLIB_MINOR == 6  
 		#define PTLIB_VER 260
 #endif
-#if PTLIB_MAJOR == 2 && PTLIB_MINOR >= 7  
-		#define PTLIB_VER 270
+#if PTLIB_MAJOR == 2 && PTLIB_MINOR == 8  
+     #define PTLIB_VER 280
 #endif
+#if PTLIB_MAJOR == 2 && PTLIB_MINOR >= 9  
+     #define PTLIB_VER 280 //290
+#endif
 
 /////////////////////////////////////////////////
 //
@@ -221,7 +231,7 @@
 
 #ifdef H323_AUDIO_CODECS
 
-#undef H323_EMBEDDED_GSM
+/* #undef H323_EMBEDDED_GSM */
 
 #endif // H323_AUDIO_CODECS
 
@@ -230,7 +240,7 @@
 // Various item support
 //
 
-#define H323_AEC  1
+/* #undef H323_AEC */
 #define H323_T38 1
 #define H323_T120 1
 #define H323_H224 1
@@ -240,11 +250,13 @@
 #define H323_H249 1
 #define H323_H341 1
 #ifdef P_LDAP
-#define H323_H350 1
+/* #undef H323_H350 */
 #endif
 #define H323_H450 1
+
 #define H323_H460 1
-#define H323_H4609 1
+#ifdef H323_H460
+/* #undef H323_H4609 */
 #if (PTLIB_VER > 260) 
 	#define H323_H46018 1
 	#define H323_H46023 1
@@ -259,16 +271,17 @@
 	#endif
 #endif
 #define H323_H460P 1
+#endif
+
 #define H323_H501 1
 #if (PTLIB_VER > 260) 
-	#define H323_GNUGK 1
+/* 	#undef H323_GNUGK */
 #endif
 #define H323_FILE 1
 
-#undef H323_SIGNAL_AGGREGATE
-#undef H323_RTP_AGGREGATE
+/* #undef H323_SIGNAL_AGGREGATE */
+/* #undef H323_RTP_AGGREGATE */
 
 #endif
 
 // End Of File ///////////////////////////////////////////////////////////////
-
Index: h323plus/include/rtp.h
--- h323plus/include/rtp.h Base (1.11)
+++ h323plus/include/rtp.h Locally Modified (Based On 1.11)
@@ -693,6 +693,10 @@
       */
     unsigned GetSessionID() const { return sessionID; }
 
+     /**Set the ID for the RTP session.
+      */
+    void SetSessionID(unsigned id);
+
     /**Get the canonical name for the RTP session.
       */
     PString GetCanonicalName() const;
Index: h323plus/src/channels.cxx
--- h323plus/src/channels.cxx Base (1.14)
+++ h323plus/src/channels.cxx Locally Modified (Based On 1.14)
@@ -1191,6 +1191,10 @@
   return rtpSession.GetSessionID();
 }
 
+void H323_RTPChannel::SetSessionID(unsigned id)
+{
+	rtpSession.SetSessionID(id);
+}
 
 PBoolean H323_RTPChannel::Open()
 {
Index: h323plus/src/gkclient.cxx
--- h323plus/src/gkclient.cxx Base (1.15)
+++ h323plus/src/gkclient.cxx Locally Modified (Based On 1.15)
@@ -1317,7 +1317,7 @@
 
   registrationFailReason = UnregisteredLocally;
   timeToLive = 0; // zero disables lightweight RRQ
-
+  endpoint.OnUnRegisterConfirm();
   return TRUE;
 }
 
Index: h323plus/src/h323.cxx
--- h323plus/src/h323.cxx Base (1.62)
+++ h323plus/src/h323.cxx Locally Modified (Based On 1.62)
@@ -809,6 +809,21 @@
 #endif
 #endif  // H323_H460
 
+#ifdef H323_H239
+
+enum H239GenericParameters
+{
+	h239gpReserved			= 0,	// Type of val - unsigned min
+	h239gpBitRate			= 41,	// Type of val - unsigned min
+	h239gpChannelId			= 42,	// Type of val - unsigned min
+	h239gpSymmetryBreaking	= 43,	// Type of val - unsigned min
+	h239gpTerminalLabel		= 44,	// Type of val - unsigned min
+	h239gpAcknowledge		= 126,	// Type of val - boolean
+	h239gpReject			= 127	// Type of val - boolean
+};
+
+#endif //H323_H239
+        
 H323Connection::H323Connection(H323EndPoint & ep,
                                unsigned ref,
                                unsigned options)
@@ -2070,6 +2085,14 @@
   SetRemotePartyInfo(pdu);
   SetRemoteApplication(alert.m_destinationInfo);
 
+   if (h225version<=2) {
+     PTRACE(4, "H4502\tRemote Endpoint does not support H.225 version>2");
+     // old polycom doesn't like the H.264 cap a nd H.239. The device will not answare the call
+   //  localCapabilities.Remove("H.264");
+    //  localCapabilities.Remove("H.239 Control");
+      //localCapabilities.Remove("H.239 Capabilities");
+}
+  
 #ifndef DISABLE_CALLAUTH
   if (!ReceiveAuthenticatorPDU<H225_Alerting_UUIE>(this,alert, 
                          H225_H323_UU_PDU_h323_message_body::e_alerting)){
@@ -4745,6 +4768,11 @@
 
 #ifdef H323_VIDEO
 #ifdef H323_H239
+  if (sessionID == 0)
+  {
+	  sessionID = OpalMediaFormat::DefaultExtVideoSessionID;
+	  const_cast<PASN_Integer&>(param->m_sessionID) = sessionID;
+  }
   if (!startingFast &&
 	  open.HasOptionalField(H245_OpenLogicalChannel::e_genericInformation)) {  // check for extended Video OLC
 
@@ -5647,7 +5675,7 @@
 	}
 	return true;
 }
-
+#endif // H323_H46024A
 bool GetUnsignedGenericMessage(unsigned id, const H245_ArrayOf_GenericParameter & params, unsigned & val)
 {
    for (PINDEX i=0; i < params.GetSize(); i++)
@@ -5753,6 +5781,21 @@
 	return param;
 }
 
+H245_GenericParameter & BuildGenericLogical(H245_GenericParameter & param, unsigned id)
+{
+	H245_ParameterIdentifier & paramId = param.m_parameterIdentifier;
+	paramId.SetTag(H245_ParameterIdentifier::e_standard);
+	PASN_Integer & idx = paramId;
+	idx = id;
+
+	H245_ParameterValue & val = param.m_parameterValue;
+	val.SetTag(H245_ParameterValue::e_logical);
+
+	return param;
+}
+
+#ifdef H323_H46024A
+
 void BuildH46024AIndication(H323ControlPDU & pdu, const PString & oid, bool sender)
 {
 	  H245_GenericMessage & cap = pdu.Build(H245_IndicationMessage::e_genericIndication);
@@ -5806,114 +5849,14 @@
 
 }
 #endif  // H323_H46024B
-
 #ifdef H323_H239
-void BuildH239GenericRequest(H323ControlPDU & pdu)
-{
-    H245_GenericMessage & cap = pdu.Build(H245_RequestMessage::e_genericRequest);
-    H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
-      id.SetTag(H245_CapabilityIdentifier::e_standard);
-      PASN_ObjectId & gid = id;
-	  gid.SetValue(OpalPluginCodec_Identifer_H239_Generic);
-
-    cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
-      PASN_Integer & num = cap.m_subMessageIdentifier;
-      num = 3;
-
-    cap.IncludeOptionalField(H245_GenericMessage::e_messageContent);
-    H245_ArrayOf_GenericParameter & msg = cap.m_messageContent;
-
-    H245_GenericParameter ask;
-    H245_ParameterIdentifier & an = ask.m_parameterIdentifier;
-        an.SetTag(H245_ParameterIdentifier::e_standard);
-	PASN_Integer & n = an;
-	n =44;
-    H245_ParameterValue & aw = ask.m_parameterValue;
-	aw.SetTag(H245_ParameterValue::e_unsignedMin);
-        PASN_Integer & k = aw;
-        k =0;
-	msg.SetSize(1);
-	msg[0] = ask;
-
-    H245_GenericParameter ask1;
-    H245_ParameterIdentifier & an1 = ask1.m_parameterIdentifier;
-        an1.SetTag(H245_ParameterIdentifier::e_standard);
-        PASN_Integer & k1 = an1;
-        k1 =42;
-    H245_ParameterValue & aw1 = ask1.m_parameterValue;
-	aw1.SetTag(H245_ParameterValue::e_unsignedMin);
-        PASN_Integer & k2 = aw1;
-        k2 = OpalMediaFormat::DefaultExtVideoSessionID;
-	msg.SetSize(2);
-	msg[1] = ask1;
-}
-
-void BuildH239GenericResponse(H323ControlPDU & pdu, bool accept)
-{
-    H245_GenericMessage & cap = pdu.Build(H245_ResponseMessage::e_genericResponse);
-    H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
-      id.SetTag(H245_CapabilityIdentifier::e_standard);
-      PASN_ObjectId & gid = id;
-	  gid.SetValue(OpalPluginCodec_Identifer_H239_Generic);
-
-    cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
-      PASN_Integer & num = cap.m_subMessageIdentifier;
-      num = 4;
-
-    cap.IncludeOptionalField(H245_GenericMessage::e_messageContent);
-    H245_ArrayOf_GenericParameter & msg = cap.m_messageContent;
-      // callIdentifer
-    H245_GenericParameter call;
-    
-    if (!accept) {
-       H245_ParameterIdentifier & idx = call.m_parameterIdentifier;
-	 idx.SetTag(H245_ParameterIdentifier::e_standard);
-	 PASN_Integer & m = idx;
-         m =127;
-    	 msg.SetSize(1);
-         msg[0] = call;
-       return;
-    } 
-  
-    H245_ParameterIdentifier & idx = call.m_parameterIdentifier;
-	 idx.SetTag(H245_ParameterIdentifier::e_standard);
-	 PASN_Integer & m = idx;
-         m =126;
-    	 msg.SetSize(1);
-         msg[0] = call;
-
-    H245_GenericParameter answer;
-    H245_ParameterIdentifier & an = answer.m_parameterIdentifier;
-        an.SetTag(H245_ParameterIdentifier::e_standard);
-	PASN_Integer & n = an;
-	n =44;
-    H245_ParameterValue & aw = answer.m_parameterValue;
-	aw.SetTag(H245_ParameterValue::e_unsignedMin);
-        PASN_Integer & k = aw;
-        k =0;
-	msg.SetSize(2);
-	msg[1] = answer;
-
-    H245_GenericParameter answer1;
-    H245_ParameterIdentifier & an1 = answer1.m_parameterIdentifier;
-        an1.SetTag(H245_ParameterIdentifier::e_standard);
-        PASN_Integer & k1 = an1;
-        k1 =42;
-    H245_ParameterValue & aw1 = answer1.m_parameterValue;
-	aw1.SetTag(H245_ParameterValue::e_unsignedMin);
-        PASN_Integer & k2 = aw1;
-        k2 = OpalMediaFormat::DefaultExtVideoSessionID;
-	msg.SetSize(3);
-	msg[2] = answer1;
-}
-
 void BuildH239GenericCommand(H323ControlPDU & pdu)
 {
     H245_GenericMessage & cap = pdu.Build(H245_ResponseMessage::e_genericResponse);
     H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
       id.SetTag(H245_CapabilityIdentifier::e_standard);
       PASN_ObjectId & gid = id;
-	  gid.SetValue(OpalPluginCodec_Identifer_H239_Generic);
+	  gid.SetValue(OpalPluginCodec_Identifer_H239_GenericMessage);
 
     cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
       PASN_Integer & num = cap.m_subMessageIdentifier;
@@ -5946,33 +5889,8 @@
 	msg.SetSize(2);
 	msg[1] = answer1;
 }
+#endif //H323_H239
 
-
-PBoolean H323Connection::DecodeH239GenericResponse(const H245_ArrayOf_GenericParameter & params)
-{
-   bool recvdDecision = false;
-   for (PINDEX i=0; i < params.GetSize(); i++) {
-      const H245_GenericParameter & param = params[i];
-      const H245_ParameterIdentifier & idm = param.m_parameterIdentifier; 
-        if (idm.GetTag() == H245_ParameterIdentifier::e_standard) {
-             const PASN_Integer & idx = idm;
-             if (idx == 126) {        // Successful request
-                 OpenExtendedVideoSession(m_H239ChanId);
-                 recvdDecision = true;
-                 break;
-             } else if (idx == 127) { // Unsuccessful request
-                 OpenExtendedVideoSessionDenied();
-                 recvdDecision = true;
-                 break;
-             }
-         }
-   }
-   return recvdDecision;
-}
-
-#endif
-
-
 #ifdef H323_H46024A
 PBoolean H323Connection::SendH46024AMessage(bool sender)
 {
@@ -6044,27 +5962,149 @@
 #endif
 
 #ifdef H323_H239
-    if (id == OpalPluginCodec_Identifer_H239_Generic && type == h245response)
-		 return DecodeH239GenericResponse(content); 
+      if (id == OpalPluginCodec_Identifer_H239_GenericMessage)
+	{
+		switch (type)
+		{
+		case h245request:
+			return OnH239GenericMessageRequest(content);
+		case h245response:
+			OnH239GenericMessageResponse(content);
+			return true;
+		case h245command:  //TODO  handle command message
+		case h245indication:
+			break;
+		}
 
-    if (id == OpalPluginCodec_Identifer_H239_Generic && type == h245request)
-        return OnH239ControlRequest();
-
-    if (id == OpalPluginCodec_Identifer_H239_Generic && type == h245command)
-       return true; //TODO  handle command message
+	}
 #endif
+
 	return false;
 }
 
 #ifdef H323_H239
-PBoolean H323Connection::SendH239GenericResponse(PBoolean response)
+
+bool H323Connection::OnH239GenericMessageRequest(const H245_ArrayOf_GenericParameter & content)
 {
+	PTRACE(4,"H239\tReceived Generic Request.");
+	for (int i = 0; i < content.GetSize(); ++i)
+	{
+		H245_GenericParameter& param = content[i];
+		switch ((PASN_Integer)param.m_parameterIdentifier)
+		{
+		case h239gpBitRate:
+			break;
+		case h239gpChannelId:					
+			m_incomingExtVideoChanNum = (PASN_Integer)param.m_parameterValue;
+			break;
+		case h239gpSymmetryBreaking:
+		case h239gpTerminalLabel:
+		default:
+			break;
+		}
+	}
+
     H323ControlPDU pdu;
-    BuildH239GenericResponse(pdu,response);
+	BuildH239GenericMessageResponse(pdu, h239smiPresintationTokenResponse); 
     return WriteControlPDU(pdu);
 }
-#endif
 
+PBoolean H323Connection::OnH239GenericMessageResponse(const H245_ArrayOf_GenericParameter & content)
+{
+	PTRACE(4,"H239\tReceived Generic Response.");
+
+	for (int i = 0; i < content.GetSize(); ++i)
+	{
+		H245_GenericParameter& param = content[i];
+		switch ((PASN_Integer)param.m_parameterIdentifier)
+		{
+		case h239gpChannelId:					
+			m_outgoingExtVideoChanNum = (PASN_Integer)param.m_parameterValue;
+			break;
+		case h239gpAcknowledge:						
+			m_allowOutgoingExtVideo = true;
+                        OpenExtendedVideoSession(m_H239ChanId);
+			break;
+		case h239gpReject:
+			m_allowOutgoingExtVideo = false;
+                        OpenExtendedVideoSessionDenied();
+			break;
+		case h239gpBitRate:
+		case h239gpSymmetryBreaking:
+		case h239gpTerminalLabel:
+		default:
+			break;
+		}
+	}
+     return m_allowOutgoingExtVideo;
+}
+
+void H323Connection::BuildH239GenericMessageIndication(H323ControlPDU& pdu, H239SubMessageIdentifier submesId)
+{       
+        PTRACE(4,"H239\tSending Generic Message Indication.");
+        
+	H245_GenericMessage & cap = pdu.Build(H245_IndicationMessage::e_genericIndication);
+
+	H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
+	id.SetTag(H245_CapabilityIdentifier::e_standard);
+	PASN_ObjectId & gid = id;
+        gid.SetValue(OpalPluginCodec_Identifer_H239_GenericMessage);
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
+	PASN_Integer & subMesID = cap.m_subMessageIdentifier;
+	subMesID = submesId;
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_messageContent);
+	H245_ArrayOf_GenericParameter & msg = cap.m_messageContent;
+	msg.SetSize(2);
+	BuildGenericInteger(msg[0], h239gpTerminalLabel, 0);
+	BuildGenericInteger(msg[1], h239gpChannelId, logicalChannels->GetLastChannelNumber() + 1);
+}
+
+void H323Connection::BuildH239GenericMessageResponse(H323ControlPDU& pdu, H239SubMessageIdentifier submesId)
+{
+	H245_GenericMessage & cap = pdu.Build(H245_ResponseMessage::e_genericResponse);
+
+	H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
+	id.SetTag(H245_CapabilityIdentifier::e_standard);
+	PASN_ObjectId & gid = id;
+	gid.SetValue(OpalPluginCodec_Identifer_H239_GenericMessage);
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
+	PASN_Integer & subMesID = cap.m_subMessageIdentifier;
+	subMesID = submesId;
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_messageContent);
+	H245_ArrayOf_GenericParameter & msg = cap.m_messageContent;
+	msg.SetSize(3);
+	BuildGenericLogical(msg[0], h239gpAcknowledge);
+	BuildGenericInteger(msg[1], h239gpTerminalLabel, 0);
+	BuildGenericInteger(msg[2], h239gpChannelId, m_incomingExtVideoChanNum);
+}
+
+void H323Connection::BuildH239GenericMessageRequest(H323ControlPDU& pdu, H239SubMessageIdentifier submesId)
+{
+	H245_GenericMessage & cap = pdu.Build(H245_RequestMessage::e_genericRequest);
+
+	H245_CapabilityIdentifier & id = cap.m_messageIdentifier;
+	id.SetTag(H245_CapabilityIdentifier::e_standard);
+	PASN_ObjectId & gid = id;
+	gid.SetValue(OpalPluginCodec_Identifer_H239_GenericMessage);
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_subMessageIdentifier);
+	PASN_Integer & subMesID = cap.m_subMessageIdentifier;
+	subMesID = submesId;
+
+	cap.IncludeOptionalField(H245_GenericMessage::e_messageContent);
+        H245_ArrayOf_GenericParameter & msg = cap.m_messageContent;
+	msg.SetSize(3);
+	BuildGenericInteger(msg[0], h239gpTerminalLabel, 0);
+	BuildGenericInteger(msg[1], h239gpChannelId, logicalChannels->GetLastChannelNumber() + 1);
+	BuildGenericInteger(msg[2], h239gpSymmetryBreaking, 4);
+}
+
+#endif // H323_H239
+
 PBoolean H323Connection::OnReceiveOLCGenericInformation(unsigned sessionID,
 	                    const H245_ArrayOf_GenericInformation & alternate) const
 {
@@ -7250,10 +7290,6 @@
 
 #ifdef H323_VIDEO
 #ifdef H323_H239
-PBoolean H323Connection::OnH239ControlRequest()
-{
-    return SendH239GenericResponse(true);
-}
 
 PBoolean H323Connection::OpenH239Channel()
 {
@@ -7268,7 +7304,7 @@
    }
 
    H323ControlPDU pdu;
-   BuildH239GenericRequest(pdu);
+   BuildH239GenericMessageRequest(pdu, h239smiPresintationTokenRequest);
    WriteControlPDU(pdu);
    return true;
 }
@@ -7298,23 +7334,33 @@
 {
   PBoolean applicationOpen = FALSE;
 
-  for (PINDEX i = 0; i < localCapabilities.GetSize(); i++) {
+   for (PINDEX i = 0; i < localCapabilities.GetSize(); i++) 
+	{
     H323Capability & localCapability = localCapabilities[i];
 	if ((localCapability.GetMainType() == H323Capability::e_Video) && 
-		(localCapability.GetSubType() == H245_VideoCapability::e_extendedVideoCapability)) {
-      H323ExtendedVideoCapability * remoteCapability = (H323ExtendedVideoCapability *)remoteCapabilities.FindCapability(localCapability);
-      if (remoteCapability != NULL) {
-        PTRACE(3, "H323\tApplication Available " << *remoteCapability);
+			(localCapability.GetSubType() == H245_VideoCapability::e_extendedVideoCapability)) 
+		{
+			for (PINDEX k = 0; k < remoteCapabilities.GetSize(); ++k)
+			{
+				H323Capability& remoteCap = remoteCapabilities[k];
+				if (remoteCap.GetMainType() == H323Capability::e_Video && 
+					remoteCap.GetSubType() == H245_VideoCapability::e_extendedVideoCapability)
+				{
+					H323ExtendedVideoCapability* remoteExtCap = dynamic_cast<H323ExtendedVideoCapability*>(&remoteCap);
+					if (!remoteExtCap)
+						continue;
          
-		for (PINDEX j = 0; j < remoteCapability->GetSize(); j++) {
-		  if (logicalChannels->Open(remoteCapability[j], OpalMediaFormat::DefaultExtVideoSessionID,num)) {
-		     applicationOpen = TRUE;
-             break;
+					PTRACE(3, "H323\tApplication Available " << *remoteExtCap);
+
+					for (PINDEX j = 0; j < remoteExtCap->GetSize(); j++) 
+					{
+                                            // SessionID must be 0 becouse otherwise Tandberg will reject the OLC.
+						if (logicalChannels->Open(remoteExtCap[j], 0,num))
+							return PTrue;
 		  }
 		}
-        PTRACE(2, "H323\tApplication OpenLogicalChannel failed: "
-               << *remoteCapability);
       }
+			PTRACE(2, "H323\tApplication OpenLogicalChannel failed");
 	  break;
     }
   }
Index: h323plus/src/h323caps.cxx
--- h323plus/src/h323caps.cxx Base (1.31)
+++ h323plus/src/h323caps.cxx Locally Modified (Based On 1.31)
@@ -3101,7 +3101,10 @@
   if (pdu.HasOptionalField(H245_TerminalCapabilitySet::e_capabilityTable)) {
     for (PINDEX i = 0; i < pdu.m_capabilityTable.GetSize(); i++) {
       if (pdu.m_capabilityTable[i].HasOptionalField(H245_CapabilityTableEntry::e_capability)) {
-        H323Capability * capability = allCapabilities.FindCapability(pdu.m_capabilityTable[i].m_capability);
+				H323Capabilities caps = allCapabilities.FindCapabilities(pdu.m_capabilityTable[i].m_capability);
+				for (int k = 0; k < caps.GetSize(); ++k)
+				{
+					H323Capability * capability = &caps[k];
         if (capability != NULL) {
           H323Capability * copy = (H323Capability *)capability->Clone();
           copy->SetCapabilityNumber(pdu.m_capabilityTable[i].m_capabilityTableEntryNumber);
@@ -3113,6 +3116,7 @@
       }
     }
   }
+	}
 
   PINDEX outerSize = pdu.m_capabilityDescriptors.GetSize();
   set.SetSize(outerSize);
@@ -3504,7 +3508,62 @@
   return NULL;
 }
 
+H323Capabilities H323Capabilities::FindCapabilities(const H245_Capability & cap) const
+{
+	PTRACE(4, "H323\tFindCapability: " << cap.GetTagName());
 
+	switch (cap.GetTag()) {
+	case H245_Capability::e_receiveAudioCapability :
+	case H245_Capability::e_transmitAudioCapability :
+	case H245_Capability::e_receiveAndTransmitAudioCapability :
+		{
+			const H245_AudioCapability & audio = cap;
+			return FindCapabilities(H323Capability::e_Audio, audio, NULL);
+		}
+
+	case H245_Capability::e_receiveVideoCapability :
+	case H245_Capability::e_transmitVideoCapability :
+	case H245_Capability::e_receiveAndTransmitVideoCapability :
+		{
+			const H245_VideoCapability & video = cap;
+			return FindCapabilities(H323Capability::e_Video, video, NULL);
+		}
+
+	case H245_Capability::e_receiveDataApplicationCapability :
+	case H245_Capability::e_transmitDataApplicationCapability :
+	case H245_Capability::e_receiveAndTransmitDataApplicationCapability :
+		{
+			const H245_DataApplicationCapability & data = cap;
+			return FindCapabilities(H323Capability::e_Data, data.m_application, NULL);
+		}
+
+	case H245_Capability::e_receiveUserInputCapability :
+	case H245_Capability::e_transmitUserInputCapability :
+	case H245_Capability::e_receiveAndTransmitUserInputCapability :
+		{
+			const H245_UserInputCapability & ui = cap;
+			if (ui.GetTag() == H245_UserInputCapability::e_genericUserInputCapability)
+				return FindCapabilities(H323Capability::e_UserInput, ui, ui);
+			else
+				return FindCapabilities(H323Capability::e_UserInput, ui, NULL);
+		}
+
+	case H245_Capability::e_receiveRTPAudioTelephonyEventCapability :
+		return FindCapabilities(H323Capability::e_UserInput, SignalToneRFC2833_SubType);
+
+	case H245_Capability::e_genericControlCapability :
+		return FindCapabilities(H323Capability::e_GenericControl);
+
+	case H245_Capability::e_conferenceCapability :
+		return FindCapabilities(H323Capability::e_ConferenceControl);
+
+	default :
+		break;
+	}
+
+	return H323Capabilities();
+}
+
 H323Capability * H323Capabilities::FindCapability(const H245_DataType & dataType) const
 {
   PTRACE(4, "H323\tFindCapability: " << dataType.GetTagName());
@@ -3665,6 +3724,35 @@
 }
 
 
+H323Capabilities H323Capabilities::FindCapabilities(H323Capability::MainTypes mainType,
+												  const PASN_Choice & subTypePDU,
+												  const H245_GenericCapability & gen) const
+{
+	H323Capabilities caps;
+ 
+	const H245_CapabilityIdentifier & id = gen.m_capabilityIdentifier;
+	if (id.GetTag() != H245_CapabilityIdentifier::e_standard)
+		return caps;
+
+	const PASN_ObjectId & idx = gen.m_capabilityIdentifier;
+	PString oid = idx.AsString();
+
+	PTRACE(4, "H323\tFindCapability: " << mainType << " Generic " << oid);
+
+	unsigned int subType = subTypePDU.GetTag();
+	for (PINDEX i = 0; i < table.GetSize(); i++) {
+		H323Capability & capability = table[i];
+		if (capability.GetMainType() == mainType &&
+			(subType == UINT_MAX || capability.GetSubType() == subType) &&
+			(capability.GetIdentifier() == oid)) {
+				PTRACE(3, "H323\tFound capability: " << capability);
+				caps.Add((H323Capability*)capability.Clone());
+		}
+	}
+
+	return caps;
+}
+
 H323Capability * H323Capabilities::FindCapability(H323Capability::MainTypes mainType,
                                                   const PASN_Choice & subTypePDU,
                                                   const unsigned * translationTable) const
@@ -3689,7 +3777,32 @@
   return NULL;
 }
 
+H323Capabilities H323Capabilities::FindCapabilities(H323Capability::MainTypes mainType,
+												  const PASN_Choice & subTypePDU,
+												  const unsigned * translationTable) const
+{
+	unsigned int subTypeID = subTypePDU.GetTag();
+	if (subTypePDU.GetTag() != 0) {
+		if (translationTable != NULL)
+			subTypeID = translationTable[subTypeID];
+		return FindCapabilities(mainType, subTypeID);
+	}
 
+	PTRACE(4, "H323\tFindCapability: " << mainType << " nonStandard");
+
+	H323Capabilities caps;
+
+	for (PINDEX i = 0; i < table.GetSize(); i++) {
+		H323Capability & capability = table[i];
+		if (capability.IsMatch(subTypePDU)) {
+			PTRACE(3, "H323\tFound capability: " << capability);
+			caps.Add((H323Capability*)capability.Clone());
+		}
+	}
+
+	return caps;
+}
+
 H323Capability * H323Capabilities::FindCapability(H323Capability::MainTypes mainType,
                                                   unsigned subType) const
 {
@@ -3709,6 +3822,28 @@
   return NULL;
 }
 
+H323Capabilities H323Capabilities::FindCapabilities(H323Capability::MainTypes mainType,
+												  unsigned subType) const
+{
+	if (subType != UINT_MAX) {
+		PTRACE(4, "H323\tFindCapability: " << mainType << " subtype=" << subType);
+	}
+
+	H323Capabilities caps;
+
+	for (PINDEX i = 0; i < table.GetSize(); i++) {
+		H323Capability & capability = table[i];
+		if (capability.GetMainType() == mainType &&
+			(subType == UINT_MAX || capability.GetSubType() == subType)) {
+				PTRACE(3, "H323\tFound capability: " << capability);
+				caps.Add((H323Capability*)capability.Clone());
+		}
+	}
+
+	return caps;
+}
+
+
 PBoolean H323Capabilities::RemoveCapability(H323Capability::MainTypes capabilityType)
 {
 	// List of codecs
@@ -3868,7 +4003,7 @@
   // Add any new capabilities not already in set.
   PINDEX i;
   for (i = 0; i < newCaps.GetSize(); i++) {
-    if (FindCapability(newCaps[i]) == NULL)
+//    if (FindCapability(newCaps[i]) == NULL)
       Copy(newCaps[i]);
   }
 
Index: h323plus/src/h323ep.cxx
--- h323plus/src/h323ep.cxx Base (1.42)
+++ h323plus/src/h323ep.cxx Locally Modified (Based On 1.42)
@@ -1619,13 +1619,13 @@
 
 #ifdef H323_VIDEO
 #ifdef H323_H239
-PBoolean H323EndPoint::OpenExtendedVideoSession(const PString & token,H323ChannelNumber & num)
+PBoolean H323EndPoint::OpenExtendedVideoSession(const PString & token)
 {
   H323Connection * connection = FindConnectionWithLock(token);
  
   PBoolean success = FALSE;
   if (connection != NULL) {
-    success = connection->OpenExtendedVideoSession(num);
+    success = connection->OpenH239Channel();
     connection->Unlock();
   }
 
@@ -1858,6 +1858,10 @@
 {
 }
 
+void H323EndPoint::OnUnRegisterConfirm()
+{
+}
+
 void H323EndPoint::OnRegisterTTLFail()
 {
 }
Index: h323plus/src/h323neg.cxx
--- h323plus/src/h323neg.cxx Base (1.10)
+++ h323plus/src/h323neg.cxx Locally Modified (Based On 1.10)
@@ -866,7 +866,7 @@
 				PASN_Integer & val = paramval;
 				val.SetValue(roleLabel);
 	  PINDEX sz = cape.GetSize();
-	  cape.SetSize(sz+1);
+	  cape.SetSize(sz);// was  cape.SetSize(sz+1);
       cape[sz] = gcap; 
   }
 #endif
@@ -1006,7 +1006,13 @@
 
       if (!channel->OnReceivedAckPDU(pdu))
         return CloseWhileLocked();
-
+       // If extended Video channel, then send Channel Active
+       if (channelNumber== connection.GeExtendedChannelNum()) {
+           H323ControlPDU reply;
+           reply.BuildLogicalChannelActive(channelNumber);
+           if (!connection.WriteControlPDU(reply))
+                 return FALSE;
+       }
       if (channel->GetDirection() == H323Channel::IsBidirectional) {
         H323ControlPDU reply;
         reply.BuildOpenLogicalChannelConfirm(channelNumber);
@@ -1469,6 +1475,12 @@
 }
 
 
+H323ChannelNumber H245NegLogicalChannels::GetLastChannelNumber()const
+{
+	PWaitAndSignal wait(mutex);
+	return lastChannelNumber;
+}
+
 H323Channel * H245NegLogicalChannels::GetChannelAt(PINDEX i)
 {
   mutex.Wait();
Index: h323plus/src/h323pdu.cxx
--- h323plus/src/h323pdu.cxx Base (1.8)
+++ h323plus/src/h323pdu.cxx Locally Modified (Based On 1.8)
@@ -2080,6 +2080,15 @@
   return reject;
 }
 
+H245_IndicationMessage &
+      H323ControlPDU::BuildLogicalChannelActive(unsigned channelNumber)
+{
+   H245_IndicationMessage & lca = Build(H245_IndicationMessage::e_miscellaneousIndication);
+		H245_MiscellaneousIndication & miscIndication = lca;
+		miscIndication.m_logicalChannelNumber = channelNumber;
+		miscIndication.m_type.SetTag(H245_MiscellaneousIndication_type::e_logicalChannelActive);
+  return lca;
+}
 
 H245_OpenLogicalChannelConfirm &
       H323ControlPDU::BuildOpenLogicalChannelConfirm(unsigned channelNumber)
Index: h323plus/src/h323pluginmgr.cxx
--- h323plus/src/h323pluginmgr.cxx Base (1.38)
+++ h323plus/src/h323pluginmgr.cxx Locally Modified (Based On 1.38)
Index: h323plus/src/h323rtp.cxx
--- h323plus/src/h323rtp.cxx Base (1.14)
+++ h323plus/src/h323rtp.cxx Locally Modified (Based On 1.14)
@@ -467,7 +467,10 @@
   }
 
   if (param.m_sessionID != rtp.GetSessionID()) {
-    PTRACE(1, "RTP_UDP\tAck for invalid session: " << param.m_sessionID);
+       //update SessionID of the channel with the new one
+      //fix for Tandberg as it allows open only with SessioID=0, but then in OLC ACK sends Session ID 32 up
+      PTRACE(1, "RTP_UDP\tAck for invalid session: " << param.m_sessionID<< "  Change the LC SessionID: "<< rtp.GetSessionID()<<"  to the new one.");
+      rtp.SetSessionID(param.m_sessionID);
   }
 
   if (!param.HasOptionalField(H245_H2250LogicalChannelAckParameters::e_mediaControlChannel)) {
Index: h323plus/src/h460/h4601.cxx
--- h323plus/src/h460/h4601.cxx Base (1.22)
+++ h323plus/src/h460/h4601.cxx Locally Modified (Based On 1.22)
@@ -1768,7 +1768,7 @@
 	}
 }
 
-void H460_FeatureSet::ReceiveFeature(unsigned id, const H225_FeatureSet & Message)
+void H460_FeatureSet::z(unsigned id, const H225_FeatureSet & Message)
 {
 	ReadFeatureSetPDU(Message,id);
 }
Index: h323plus/src/rtp.cxx
--- h323plus/src/rtp.cxx Base (1.17)
+++ h323plus/src/rtp.cxx Locally Modified (Based On 1.17)
@@ -884,7 +884,12 @@
 #endif
 }
 
+void RTP_Session::SetSessionID(unsigned id)
+{
+    sessionID = id;
+}
 
+
 PString RTP_Session::GetCanonicalName() const
 {
   PWaitAndSignal mutex(reportMutex);
@@ -1565,6 +1570,7 @@
     return NULL;  // Deliberately have not release mutex here! See AddSession.
 
   PTRACE(3, "RTP\tFound existing session " << sessionID);
+  session->SetSessionID(sessionID);
   session->IncrementReference();
 
   mutex.Signal();
