void CMyPhoneEndPoint::OnLogicalChannel(const H323Channel & channel, unsigned txStrID, unsigned rxStrID)
{
	const H323Capability & capability = channel.GetCapability();
	PString name = capability.GetFormatName();
	PString frames;

	if (capability.GetMainType() == H323Capability::e_Video)
	{
		unsigned numFrames = channel.GetDirection() == H323Channel::IsTransmitter
			? capability.GetTxFramesInPacket()
			: capability.GetRxFramesInPacket();
		frames.sprintf(" (%u frames)", numFrames);
	}
//	else if (capability.GetMainType() == H323Capability::e_Video)
//	{
//		frames.sprintf(" (%ux%u pixels)", videoWidth, videoHeight);
//	}
	
	switch (channel.GetDirection())
	{
    case H323Channel::IsTransmitter :
		m_dialog->OutputStatus(txStrID, (const char *)name, (const char *)frames);
		break;
		
    case H323Channel::IsReceiver :
		m_dialog->OutputStatus(rxStrID, (const char *)name, (const char *)frames);
		break;
		
    default :
		break;
	}
}
/** This callback function is invoked once upon creation of each
  * channel for an H323 session 
  */
BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
{    
	/* Increase the count of channels we have open */
	channelsOpen++;

	if (h323debug) {
		cout << "\t-- Started logical channel: ";
		cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" "));
		cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
		cout <<  "\t\t-- channelsOpen = " << channelsOpen << endl;
	}
	return connectionState != ShuttingDownConnection;
}
BOOL CMyPhoneEndPoint::OnStartLogicalChannel(H323Connection &, H323Channel & channel)
{
	if( isIncomingCall
          && m_fAutoMute
          && (channel.GetCapability().GetMainType()==H323Capability::e_Audio)
          && (channel.GetDirection()==H323Channel::IsTransmitter)
        )
        {
          channel.SetPause(TRUE);
	  m_dialog->m_micMute.SetCheck(BST_CHECKED);
          m_dialog->m_micMute.SetIcon(::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_MICMUTEICON)));
        }

	OnLogicalChannel(channel, IDS_STARTCHANNELTX, IDS_STARTCHANNELRX);
	return TRUE;
}
Exemple #4
0
/** This callback function is invoked once upon creation of each
  * channel for an H323 session 
  */
BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
{    
	PIPSocket::Address remoteIpAddress;
	WORD remotePort;
	
	if (h323debug) {
		cout << "	 -- Started logical channel: ";	
		cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" ")); 
		cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
	}

	/* adjust the count of channels we have open */
	channelsOpen++;

	if (h323debug) {
		cout <<  "		-- channelsOpen = " << channelsOpen << endl;
	}

	if (!Lock()) {
                ast_log(LOG_ERROR,"chan_h323: OnStartLogicalChannel: Could not obtain connection lock");
                return FALSE;
        }
        /* Connect RTP for incoming calls */
        if (!AST_Outgoing) {
                H323_ExternalRTPChannel & external = (H323_ExternalRTPChannel &)channel;
                external.GetRemoteAddress(remoteIpAddress, remotePort);
                if (h323debug) {
                       cout << "\t\tRTP channel id " << sessionId << " parameters:" << endl;
                       cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
                       cout << "\t\t-- remotePort: " << remotePort << endl;
                       cout << "\t\t-- ExternalIpAddress: " <<  externalIpAddress << endl;
                       cout << "\t\t-- ExternalPort: " << externalPort << endl;
                }
                /* Notify Asterisk of remote RTP information */
                on_start_logical_channel(GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
                      			 (const char *)GetCallToken());
                AST_RTP_Connected = TRUE;
	}
	Unlock();
	return TRUE;	
}
BOOL CMyPhoneEndPoint::OpenVideoChannel(H323Connection & connection,
					BOOL isEncoding,
					H323VideoCodec & codec)
{

 PVideoChannel   * channel = new PVideoChannel;
 PVideoDevice * displayDevice = NULL;
	
 if (isEncoding) 
 {
  // Transmitter part
  if(!autoStartTransmitVideo) return FALSE;
		
  codec.SetTxQualityLevel(config.GetInteger(VideoQualityConfigKey,15));
  codec.SetBackgroundFill(2);

  int videoOutMaxBitRate = config.GetInteger(VideoOutMaxbandWidthKey, 320);
  videoOutMaxBitRate = 1024 * PMAX(16, PMIN(10240, videoOutMaxBitRate));

  H323Channel * lchannel = codec.GetLogicalChannel();
  const H323Capability & capability = lchannel->GetCapability();
  PString cname = capability.GetFormatName();
  PINDEX suffixPos = cname.Find("H.263");
  if(suffixPos == P_MAX_INDEX) suffixPos = cname.Find("H.261");

  int videoSize = config.GetInteger(VideoOutSizeConfigKey, 2);
  int width=352, height=288;

  suffixPos = P_MAX_INDEX;
  switch(videoSize)
  {
   case 0: //QCIF
    width = 176; height = 144; break;
   case 1: //QVGA
    if(suffixPos == P_MAX_INDEX) { width = 320; height = 240; break; }
   case 2: //CIF
    width = 352; height = 288; break;
   case 3: //VGA
    if(suffixPos == P_MAX_INDEX) { width = 640; height = 480; break; }
   case 5: //SVGA
    if(suffixPos == P_MAX_INDEX) { width = 800; height = 600; break; }
   case 6: //XVGA
    if(suffixPos == P_MAX_INDEX) { width = 1024; height = 768; break; }
   case 4: //4CIF
    width = 704; height = 576; break;
   case 7: //HD 720
    if(suffixPos == P_MAX_INDEX) { width = 1280; height = 720; break; }
   case 8: //SXGA
    if(suffixPos == P_MAX_INDEX) { width = 1280; height = 1024; break; }
   case 9: //16CIF
    width = 1408; height = 1152; break;
   case 10: //UXGA
    if(suffixPos == P_MAX_INDEX) { width = 1600; height = 1200; break; }
   case 11: //HD 1080
    if(suffixPos == P_MAX_INDEX) { width = 1920; height = 1080; break; }
   default:
    break;
  }

  PTRACE(1, "Video device videoSize=" << videoSize << " width=" << width << " height=" << height);

  codec.SetVideoSize(width, height);
  width = codec.GetWidth(); 
  height = codec.GetHeight();

  PTRACE(1, "Accepted video device width=" << width << " height=" << height);
  
  int curMBR = codec.GetMaxBitRate();
  if(curMBR > videoOutMaxBitRate) codec.SetMaxBitRate(videoOutMaxBitRate);

  int videoFramesPS = config.GetInteger(VideoFPSKey, 10);
  codec.SetGeneralCodecOption("Frame Rate",videoFramesPS);

  //Create grabber.
  bool NoDevice = false;
  PString deviceName = config.GetString(VideoDeviceConfigKey, deviceName);
  if (deviceName.IsEmpty()) 
  {
   PStringArray devices = PVideoInputDevice::GetDriversDeviceNames(VideoInputDriver);
   if (!devices.IsEmpty()) deviceName = devices[0];
   else NoDevice = true;
  }
		
  PVideoInputDevice * grabber = NULL;
  if (deviceName.Find("fake") == 0) NoDevice = true;
//  else if (deviceName.Find("screen") == 0) grabber = PVideoInputDevice::CreateDevice("ScreenVideo");
  else grabber = PVideoInputDevice::CreateDeviceByName(deviceName,VideoInputDriver);
		
  if (NoDevice || !grabber->Open(deviceName, FALSE) ||
      !grabber->SetFrameSize(width, height) || 
      !grabber->SetColourFormatConverter("YUV420P") || 
			!grabber->SetVFlipState(localFlip))
  {
   if(!NoDevice)
   {
    char sSrc[64];
    m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_ERRVDEVSTR), S_SYSTEM, 
 			      (const char *) deviceName, 
				itoa(config.GetInteger(VideoSourceConfigKey,0), sSrc, 10));
    PTRACE(1, "Failed to open or configure the video device \"" << deviceName << '"');
   }

   if(grabber) delete grabber;
   grabber = PVideoInputDevice::CreateDevice("FakeVideo");
			grabber->SetColourFormat("YUV420P");
			grabber->SetVideoFormat(PVideoDevice::PAL);
			grabber->SetFrameSize(width, height);
			grabber->SetVFlipState(localFlip);
			grabber->SetChannel(4);
  }

  if(videoFramesPS >0 && videoFramesPS<30) 
   grabber->SetFrameRate(videoFramesPS);

  grabber->Start();

  channel->AttachVideoReader(grabber);
/*
  if (localVideo)
		{
			BOOL curVFlip = config.GetBoolean(VideoOutVFlipConfigKey, FALSE);
			BOOL curHFlip = config.GetBoolean(VideoOutHFlipConfigKey, FALSE);
			displayDevice = new CVideoOutputDevice(m_dialog, 
				connection.GetLocalPartyName(), curVFlip, curHFlip, TRUE, FALSE);
		}
  else 
*/
   displayDevice = PVideoOutputDevice::CreateDevice("NULLOutput");
 }
 else
 {
  // Receiver part
  if(!autoStartReceiveVideo) return FALSE;
  BOOL curVFlip = config.GetBoolean(VideoInVFlipConfigKey, FALSE);
  BOOL curHFlip = config.GetBoolean(VideoInHFlipConfigKey, FALSE);

  displayDevice = new CVideoOutputDevice( 
		m_vdlg, (LPCTSTR)m_dialog->FindContactName(connection), curVFlip,
		curHFlip, FALSE, localVideo);
 }
	
 if(displayDevice)
 {
  int width = codec.GetWidth();
  int height = codec.GetHeight();
//  if( m_dialog->autohideVideoPan && !m_dialog->showVideoPan)
//   m_dialog->ShowVideoPanels(TRUE);  // show Video panel if it's hiden
  displayDevice->SetColourFormat("RGB32");
  displayDevice->SetColourFormatConverter("YUV420P");
  displayDevice->SetFrameSize(width, height);
  //Give the video window refreshing class to the channel.
  channel->AttachVideoPlayer((PVideoOutputDevice *)displayDevice);
 }

 return codec.AttachChannel(channel,TRUE);
}