Ejemplo n.º 1
0
PStringArray PVideoOutputDevice_EKIGA::GetDeviceNames() const
{
  PStringArray devlist;
  devlist.AppendString(GetDeviceName());

  return devlist;
}
Ejemplo n.º 2
0
bool Manager::MakeCall(const PString &remoteParty)
{
    cout << "Setting up a call to: " << remoteParty << endl;
    PString token;
    if (TPState::Instance().GetProtocol() != TPState::RTP) {
        if (!SetUpCall("local:*", remoteParty, token)) {
            cerr << "Call setup to " << remoteParty << " failed" << endl;
            return false;
        }
    } else {
        // setting up rtp, split desination into ip and port parts
        PStringArray arr = remoteParty.Tokenise(":");
        if (arr.GetSize() != 2) {
            std::cerr << "invalid address: " << remoteParty << std::endl;
            return false;
        }

        // create rtp session
        RTP_Session::Params p;
        p.id = OpalMediaType::Audio().GetDefinition()->GetDefaultSessionId();
        p.encoding = OpalMediaType::Audio().GetDefinition()->GetRTPEncoding();
        p.userData = new RTPUserData;

        //m_rtpsession->SetUserData(new RTPUserData);
        m_rtpsession = new RTPSession(p);
        m_rtpsession->SelectAudioFormat(RTPSession::PCM16);

        // local and remote addresses
        PIPSocket::Address remote(arr[0]);
        PIPSocket::Address local(TPState::Instance().GetLocalAddress());

        if (!m_rtpsession->SetRemoteSocketInfo(remote, arr[1].AsInteger(), true)) {
            cerr << "could not set remote socket info" << endl;
            return false;
        }

        if (!m_rtpsession->Open(local,
                                TPState::Instance().GetListenPort(),
                                TPState::Instance().GetListenPort(), 2)) {
            cerr << "could not open rtp session" << endl;
            return false;
        }

        m_rtpsession->SetJitterBufferSize(100, 1000);
        std::cout
                << "RTP local address:     " << local << std::endl
                << "RTP local data port:   " << m_rtpsession->GetLocalDataPort() << std::endl
                << "RTP remote address:    " << remote << std::endl
                << "RTP remote data port:  " << m_rtpsession->GetRemoteDataPort() << std::endl;

        std::cout << "RTP stream set up!" << std::endl;
        TPState::Instance().SetState(TPState::ESTABLISHED);
        return true;
    }

    cout << "connection set up to " << remoteParty << endl;
    std::string val = token;
    currentCallToken = val;
    return true;
}
Ejemplo n.º 3
0
bool EndPoint::init()
{
	PTRACE( 1, "Initializing endpoint" );

#ifdef ENTERPRISE
	if( !ldapQueried ) {
		PError << "LDAP was not queried successfuly." << endl;
		return false;
	}

	if( ldapAliases.IsEmpty() ) {
		PError << "Aliases were not fetched from LDAP." << endl;
		return false;
	}

	SetLocalUserName( ldapAliases[0] );
	for (int i = 1; i < ldapAliases.GetSize(); i++)
		AddAliasName( ldapAliases[i]);
	if( ldapAttrs.HasKey("h323IdentitydialedDigits") )
		AddAliasName( ldapAttrs.GetString("h323IdentitydialedDigits") );
#else

	if( args.HasOption('u')) {
		PStringArray aliases = args.GetOptionString('u').Lines();
		SetLocalUserName(aliases[0]);
		for (int i = 1; i < aliases.GetSize(); i++)
			AddAliasName(aliases[i]);
	}
	else {
		QStringList userAliases = ancaConf->readListEntry( USER_ALIASES );
		SetLocalUserName( userAliases[ 0 ].latin1() );
		for ( unsigned i = 1; i < userAliases.size(); i++ )
			AddAliasName( userAliases[ i ].latin1() );
	}
#endif

	bool disableFastStart = !ancaConf->readBoolEntry( FAST_START, FAST_START_DEFAULT );
	bool disableTunneling = !ancaConf->readBoolEntry( H245_TUNNELING, H245_TUNNELING_DEFAULT );
	bool disableH245InSetup = !ancaConf->readBoolEntry( H245_IN_SETUP, H245_IN_SETUP_DEFAULT );
	if( args.HasOption("fast-disable") )
		disableFastStart = true;
	if( args.HasOption("h245tunneldisable") )
		disableTunneling = true;
	if( args.HasOption("disable-h245-in-setup") )
		disableH245InSetup = true;

	DisableFastStart( disableFastStart );
	DisableH245Tunneling( disableTunneling );
	DisableH245inSetup( disableH245InSetup );


	// Codecs
	AudioPlugin *audioPlugin = (AudioPlugin*)pluginFactory->getPlugin(Plugin::Audio);
	if( audioPlugin ) {
		audioPlugin->addCapabilities();
	}

	VideoInPlugin *videoPlugin = (VideoInPlugin*)pluginFactory->getPlugin(Plugin::VideoIn);
	if( videoPlugin ) {
		videoPlugin->addCapabilities();
	}

	AddAllUserInputCapabilities( 0, 1 );

	PTRACE( 1, "Capabilities:\n" << setprecision( 2 ) << capabilities );

	ancaInfo->set( ADDRESS, ( const char * ) (GetLocalUserName() + "@" + PIPSocket::GetHostName()) );

	// Initialise the security info
	if( args.HasOption("password") ) {
		SetGatekeeperPassword( args.GetOptionString("password") );
		PTRACE( 1, "Enabling H.235 security access to gatekeeper." );
	}

	// Do not start H323 Listener
	if( args.HasOption("no-listenport") ) return true;

	// Start H323 Listener
	PIPSocket::Address addr = INADDR_ANY;
	WORD port = ancaConf->readIntEntry( PORT, PORT_DEFAULT );
	if (args.HasOption("listenport"))
		port = (WORD)args.GetOptionString("listenport").AsInteger();

	listener = new H323ListenerTCP( *this, addr, port );
	if ( listener == NULL || !StartListener( listener ) ) {
		PTRACE(1, "Unable to start H323 Listener at port " << port );
		if ( listener != NULL )
			delete listener;
		return false;
	}
	PTRACE( 1, "TCP listener started at port " << port );

	return true;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
void CMyPhoneEndPoint::LoadCapabilities()
{

 BOOL sizeChange = FALSE;

 capabilities.RemoveAll();
	
// Add the codecs we know about
 AddAllCapabilities(0, 0, "*"); 

// Удаляю не поддерживаемые видео кодеки из реестра
 PINDEX videoNum = 0;
 for (;;)
 {
  PString key = psprintf("%u", ++videoNum);
  PString name = config.GetString(VideoCodecsConfigSection, key, "");
  if (name.IsEmpty()) break;

  PINDEX suffixPos = name.Find(OnCodecSuffix);
  if (suffixPos != P_MAX_INDEX) 
   name.Delete(suffixPos, P_MAX_INDEX);
  else 
  {
   suffixPos = name.Find(OffCodecSuffix);
   name.Delete(suffixPos, P_MAX_INDEX);
  }

  int res = 0;
  for (PINDEX i = 0; i < capabilities.GetSize(); i++)
  {
   if (capabilities[i].GetMainType() == H323Capability::e_Video)
   {
    if(capabilities[i].GetFormatName() == name)
     { res = 1; break; }
   }
  }
  if(res == 0) 
  {
   PINDEX j = videoNum; videoNum--;
   for (;;)
   {
    PString key1 = psprintf("%u", ++j);
    PString name1 = config.GetString(VideoCodecsConfigSection, key1, "");
    if (name1.IsEmpty()) break;

    config.SetString(VideoCodecsConfigSection, psprintf("%u", j-2), name1);
   }
   config.DeleteKey(VideoCodecsConfigSection, psprintf("%u", j-1));
  }
 }

// добавляю новые видео кодеки если их нет в конфигурации
 for (PINDEX i = 0; i < capabilities.GetSize(); i++)
 {
  if (capabilities[i].GetMainType() == H323Capability::e_Video)
  {
   PINDEX codecNum=0;
   int res = 0;
   int suffix = 0;
   for (;;)
   {
    PString key = psprintf("%u", ++codecNum);
    PString name = config.GetString(VideoCodecsConfigSection, key, "");
    if (name.IsEmpty()) break;   

    suffix = 0;
    PINDEX suffixPos = name.Find(OnCodecSuffix);
    if (suffixPos != P_MAX_INDEX)
     name.Delete(suffixPos, P_MAX_INDEX);
    else
    {
     suffix = 1;
     suffixPos = name.Find(OffCodecSuffix);
     name.Delete(suffixPos, P_MAX_INDEX);
    }
  
    if(capabilities[i].GetFormatName() == name) { res = 1; break; }
   }
   if(res == 0)
   {
    config.SetString(VideoCodecsConfigSection,
        psprintf("%u", codecNum),
        capabilities[i].GetFormatName() + ((suffix==0)?OnCodecSuffix:OffCodecSuffix));
   }
  }
 }

 PINDEX audioNum = 0;
 for (;;)
 {
  PString key = psprintf("%u", ++audioNum);
  PString name = config.GetString(CodecsConfigSection, key, "");
  if (name.IsEmpty()) break;

  PINDEX suffixPos = name.Find(OnCodecSuffix);
  if (suffixPos != P_MAX_INDEX) 
   name.Delete(suffixPos, P_MAX_INDEX);
  else 
  {
   suffixPos = name.Find(OffCodecSuffix);
   name.Delete(suffixPos, P_MAX_INDEX);
  }

  int res = 0;
  for (PINDEX i = 0; i < capabilities.GetSize(); i++)
  {
   if (capabilities[i].GetMainType() == H323Capability::e_Audio)
   {
    if(capabilities[i].GetFormatName() == name)
     { res = 1; break; }
   }
  }
  if(res == 0) 
  {
   PINDEX j = audioNum; audioNum--;
   for (;;)
   {
    PString key1 = psprintf("%u", ++j);
    PString name1 = config.GetString(CodecsConfigSection, key1, "");
    if (name1.IsEmpty()) break;

    config.SetString(CodecsConfigSection, psprintf("%u", j-2), name1);
   }
   config.DeleteKey(CodecsConfigSection, psprintf("%u", j-1));
  }
 }

 for (PINDEX i = 0; i < capabilities.GetSize(); i++)
 {
  if (capabilities[i].GetMainType() == H323Capability::e_Audio)
  {
   PINDEX codecNum=0;
   int res = 0;
   int suffix = 0;
   for (;;)
   {
    PString key = psprintf("%u", ++codecNum);
    PString name = config.GetString(CodecsConfigSection, key, "");
    if (name.IsEmpty()) break;   

    suffix = 0;
    PINDEX suffixPos = name.Find(OnCodecSuffix);
    if (suffixPos != P_MAX_INDEX)
     name.Delete(suffixPos, P_MAX_INDEX);
    else
    {
     suffix = 1;
     suffixPos = name.Find(OffCodecSuffix);
     name.Delete(suffixPos, P_MAX_INDEX);
    }
  
    if(capabilities[i].GetFormatName() == name) { res = 1; break; }
   }
   if(res == 0)
   {
    config.SetString(CodecsConfigSection,
        psprintf("%u", codecNum),
        capabilities[i].GetFormatName() + ((suffix==0)?OnCodecSuffix:OffCodecSuffix));
   }
  }
 }

// Add all the UserInput capabilities
 AddAllUserInputCapabilities(0, 1);

 int videoSizeRx = config.GetInteger(VideoInSizeConfigKey, 2);
 int videoSizeTx = config.GetInteger(VideoOutSizeConfigKey, 2);

 RemoveCapability(H323Capability::e_ExtendVideo);

 autoStartTransmitVideo = config.GetBoolean(AutoTransmitVideoConfigKey, TRUE);
 autoStartReceiveVideo = config.GetBoolean(AutoReceiveVideoConfigKey, TRUE);
	
 localVideo = config.GetBoolean(VideoLocalConfigKey, FALSE);
 localFlip = config.GetBoolean(VideoFlipLocalConfigKey, FALSE);
	
 int videoInMaxBitRate = config.GetInteger(VideoInMaxbandWidthKey, 320);
 videoInMaxBitRate = 1024 * PMAX(16, PMIN(10240, videoInMaxBitRate));

// changing audio codecs
 PStringArray enabledCodecs;
 PINDEX codecNum = 0;
 for (;;) 
 {
  PString key = psprintf("%u", ++codecNum);
  PString name = config.GetString(CodecsConfigSection, key, "");
  if (name.IsEmpty()) break;
		
  PINDEX suffixPos = name.Find(OffCodecSuffix);
  if (suffixPos != P_MAX_INDEX) 
  {
   capabilities.Remove(name(0, suffixPos-1));
   continue;
  }
		
  suffixPos = name.Find(OnCodecSuffix);
  if (suffixPos != P_MAX_INDEX)	name.Delete(suffixPos, P_MAX_INDEX);
  enabledCodecs.AppendString(name);
 }

 codecNum = 0;
 for (;;) 
 {
  PString key = psprintf("%u", ++codecNum);
  PString name = config.GetString(VideoCodecsConfigSection, key, "");
  if (name.IsEmpty()) break;
 }

 int tvNum = 0;
// if(tvCaps==NULL)  this generates error in free
 tvCaps = (char **)calloc(codecNum+1,sizeof(char *));
// while(tvCaps[tvNum]!=NULL) { free(tvCaps[tvNum]); tvCaps[tvNum]=NULL; tvNum++; }

 tvNum = 0;
 codecNum = 0;
 for (;;) 
 {
  PString key = psprintf("%u", ++codecNum);
  PString name = config.GetString(VideoCodecsConfigSection, key, "");
  if (name.IsEmpty()) break;

// удаление отключенных кодеков		
  PINDEX suffixPos = name.Find(OffCodecSuffix);
  if (suffixPos != P_MAX_INDEX) 
  {
   capabilities.Remove(name(0, suffixPos-1)); continue;
  }
// удаление суффикса on из имени кодека
  suffixPos = name.Find(OnCodecSuffix);
  if (suffixPos != P_MAX_INDEX)	name.Delete(suffixPos, P_MAX_INDEX);

// проверка кодека на соответствие размеру принимаемой картинки
// (меньше можно, больше нельзя) и удаление из списка локальных кодеков
  suffixPos = P_MAX_INDEX;
  switch(videoSizeRx)
  {
   case 0: //QCIF
    suffixPos = name.Find("-CIF");   if(suffixPos != P_MAX_INDEX) break;
   case 1: //QVGA
   case 2: //CIF
    suffixPos = name.Find("-4CIF");  if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-480P");    if(suffixPos != P_MAX_INDEX) break;
   case 3: //VGA
   case 4: //4CIF
    suffixPos = name.Find("-SD");    if(suffixPos != P_MAX_INDEX) break;
   case 5: //SVGA
    suffixPos = name.Find("-720P");    if(suffixPos != P_MAX_INDEX) break;
   case 6: //XVGA
    suffixPos = name.Find("-HD");    if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break;
   case 7: //SXGA
    suffixPos = name.Find("-FHD"); if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-1080P"); if(suffixPos != P_MAX_INDEX) break;
   case 8: //16CIF
   default:
    break;
  }
  if(suffixPos == P_MAX_INDEX) enabledCodecs.AppendString(name);
  else capabilities.Remove(name);

// проверка кодека на соответствие размеру отправляемой картинки
// (меньше можно, больше нельзя) и создание списка допустимых кодеков
  suffixPos = P_MAX_INDEX;
  switch(videoSizeTx)
  {
   case 0: //QCIF
    suffixPos = name.Find("-CIF");   if(suffixPos != P_MAX_INDEX) break;
   case 1: //QVGA
   case 2: //CIF
    suffixPos = name.Find("-4CIF");  if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-480P");    if(suffixPos != P_MAX_INDEX) break;
   case 3: //VGA
   case 4: //4CIF
    suffixPos = name.Find("-SD");    if(suffixPos != P_MAX_INDEX) break;
   case 5: //SVGA
   case 6: //XVGA
    suffixPos = name.Find("-HD");    if(suffixPos != P_MAX_INDEX) break;
   case 7: //HD 720
    suffixPos = name.Find("-720P");    if(suffixPos != P_MAX_INDEX) break;
   case 8: //SXGA
    suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-FHD"); if(suffixPos != P_MAX_INDEX) break;
    suffixPos = name.Find("-1080P"); if(suffixPos != P_MAX_INDEX) break;
   case 9: //16CIF
   default:
    break;
  }
  if(suffixPos == P_MAX_INDEX) // добавляю в список допустимых
  {
   const char *p2pstr=name;
   tvCaps[tvNum]=strdup(p2pstr);
   tvNum++;
  }
 }

// Reorder the codecs we have
 capabilities.Reorder(enabledCodecs);

 for (PINDEX i = 0; i < capabilities.GetSize(); i++) 
 {
  if (capabilities[i].GetMainType() == H323Capability::e_Video)
  {
   capabilities[i].SetMediaFormatOptionInteger(OpalVideoFormat::MaxBitRateOption, videoInMaxBitRate);
   if((capabilities[i].GetFormatName().Find("H.264")!=P_MAX_INDEX) || (capabilities[i].GetFormatName().Find("VP8-")==0))
   {

    H323GenericVideoCapability *h264cap = (H323GenericVideoCapability *) &capabilities[i];
    h264cap->SetMaxBitRate(videoInMaxBitRate/100);
   }
  }
 }

/*	
	PINDEX audioNum = 1;
	PINDEX videoNum = 1;
	for (PINDEX i = 0; i < capabilities.GetSize(); i++) 
	{
		if (capabilities[i].GetMainType() == H323Capability::e_Audio)
		{
			config.SetString(CodecsConfigSection,
				psprintf("%u", audioNum++),
				capabilities[i].GetFormatName() + OnCodecSuffix);
		} 
		else if (capabilities[i].GetMainType() == H323Capability::e_Video)
		{
			config.SetString(VideoCodecsConfigSection,
				psprintf("%u", videoNum++),
				capabilities[i].GetFormatName() + OnCodecSuffix);
		}
	}
*/

	PTRACE(1, "MyPhone\tCapability Table:\n" << setprecision(4) << capabilities);
}
Ejemplo n.º 6
0
BOOL CMyPhoneEndPoint::Initialise(CMyPhoneDlg *dlg, CVideoDlg *vdlg)
{
	m_dialog = dlg;
        m_vdlg = vdlg;
	isIncomingCall = FALSE;

	SetAudioJitterDelay(50, config.GetInteger(JitterConfigKey, GetMaxAudioJitterDelay()));
	SetSoundChannelBufferDepth(config.GetInteger(BufferCountConfigKey, GetSoundChannelBufferDepth()));
	
	// UserInput mode
    // Backward compatibility configuration entry
    unsigned mode = H323Connection::SendUserInputAsString;
	m_fDtmfAsString=true;
    if (config.HasKey(DtmfAsStringConfigKey)) {
		if (!config.GetBoolean(DtmfAsStringConfigKey))
		{
			mode = H323Connection::SendUserInputAsTone;
			m_fDtmfAsString=false;
		}
		config.DeleteKey(DtmfAsStringConfigKey);
	}
	mode = config.GetInteger(UserInputModeConfigKey, mode);
	SetSendUserInputMode((H323Connection::SendUserInputModes)mode);

//        SetSoundChannelPlayDriver("WindowsMutimedia");
//        SetSoundChannelRecordDriver("WindowsMultimedia");
//        SetSoundChannelPlayDriver("DirectSound");
//        SetSoundChannelRecordDriver("DirectSound");
	
        PString soundPlayStr = config.GetString(SoundPlayConfigKey, GetSoundChannelPlayDevice());
        PStringArray soundPlayer = soundPlayStr.Tokenise('\t');
        BOOL fPlayerAvailable;
        if(soundPlayer.GetSize()==1)
        {  
         SetSoundChannelPlayDriver("WindowsMutimedia");
	 fPlayerAvailable = SetSoundChannelPlayDevice(soundPlayer[0]);
         PTRACE(1, "MyPhone\tSetSoundPlayer Driver:WindowsMultimedia, Device:" << soundPlayer[0]);
        }
        else
        {
         SetSoundChannelPlayDriver(soundPlayer[0]);
	 fPlayerAvailable = SetSoundChannelPlayDevice(soundPlayer[1]);
         PTRACE(1, "MyPhone\tSetSoundPlayer Driver:" << soundPlayer[0] << ", Device:" << soundPlayer[1]);
	}

        PString soundRecordStr = config.GetString(SoundRecordConfigKey, GetSoundChannelRecordDevice());
        PStringArray soundRecorder = soundRecordStr.Tokenise('\t');
        BOOL fRecorderAvailable;
        if(soundRecorder.GetSize()==1)
        {  
         SetSoundChannelRecordDriver("WindowsMutimedia");
	 fRecorderAvailable = SetSoundChannelRecordDevice(soundRecorder[0]);
         PTRACE(1, "MyPhone\tSetSoundRecorder Driver:WindowsMultimedia, Device:" << soundRecorder[0]);
        }
        else
        {
         SetSoundChannelRecordDriver(soundRecorder[0]);
	 fRecorderAvailable = SetSoundChannelRecordDevice(soundRecorder[1]);
         PTRACE(1, "MyPhone\tSetSoundRecorder Driver:" << soundRecorder[0] << ", Device:" << soundRecorder[1]);
	}

	m_fAECOn = config.GetBoolean(AECEnableConfigKey, FALSE);
	m_fAGCOn = config.GetInteger(AGCEnableConfigKey, FALSE);
	SetAECAlgo(m_fAECOn);
	agc = m_fAGCOn;
	             
	// set some oter settings from Config
	m_fNoFastStart =  config.GetBoolean(NoFastStartConfigKey, FALSE);
    DisableFastStart(m_fNoFastStart);
	m_fStrictSingleLine =  config.GetBoolean(StrictSingleLineConfigKey, FALSE);
    StrictSingleLine(m_fStrictSingleLine);

	m_fDoH245Tunnelling = !(config.GetBoolean(NoTunnelingConfigKey, FALSE));
    DisableH245Tunneling(!m_fDoH245Tunnelling);
	m_fSilenceOn = config.GetBoolean(SilenceDetectConfigKey, TRUE);
    SetSilenceDetectionMode(m_fSilenceOn
		? H323AudioCodec::AdaptiveSilenceDetection
		: H323AudioCodec::NoSilenceDetection);
    SetLocalUserName(config.GetString(UsernameConfigKey, GetLocalUserName()));
    SetInitialBandwidth((unsigned)(config.GetReal(BandwidthConfigKey, 10000)*20));
    SetRtpIpTypeofService(config.GetInteger(IpTosConfigKey, GetRtpIpTypeofService()));
	
	SetRtpIpPorts(config.GetInteger(RTPPortBaseConfigKey, GetRtpIpPortBase()),
		config.GetInteger(RTPPortMaxConfigKey,  GetRtpIpPortBase()));
	if(config.HasKey(RouterConfigKey))
		m_router = config.GetString(RouterConfigKey, m_router.AsString());
	
	m_fAutoAnswer = config.GetBoolean(AutoAnswerConfigKey, false);
	m_fAutoMute = config.GetBoolean(AutoMuteConfigKey, false);
	
    CString alias, aliases;
	aliases = CString((const char *)config.GetString(AliasConfigKey, _T("")));
	aliases.TrimLeft();
	int iPos=0;
    while ((iPos = aliases.Find(_T("|")))>0)  // loading user aliases
	{
		alias = aliases.Left(iPos);
		aliases.Delete(0,iPos+1);
		AddAliasName((LPCTSTR)alias);
	}
	
	// The order in which capabilities are added to the capability table
	// determines which one is selected by default.
	LoadCapabilities();
	
	PString interfaces = config.GetString(ListenerInterfaceConfigKey, "*");
	if(StartListeners(interfaces.Tokenise(',')))
	{
		m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_MPREADY1STR), S_SYSTEM, (const char *)strProgName);
		return true;
	}
	else
	{
		m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_ERRLSNSTR), S_SYSTEM, (const char *)strProgName, (const char *)interfaces);
		return false;
	}
}
Ejemplo n.º 7
0
ControllerThread::ControllerThread(PSerialChannel *_serial, Resources * _resources, PConfig *_config) : PThread(10000, NoAutoDeleteThread), queue() {
    pserial   = _serial;
    resources = _resources;
    config    = _config;
    analogControls = (config->GetString("Gamepad", "AnalogControl", "")).ToUpper().Tokenise(",", PFalse);

    PTRACE(2, "Constructing instance for controller");
    for(int i = 0; i < 256; i++) {
        actionQueuePool[i] = new PIntArray();
    };
    queue.Open(10000);
    queue.SetReadTimeout(0); // timeout 0 ms
    queue.SetWriteTimeout(0); // timeout 0 ms
    timeout = 100;
    retryLimit = 5;
    fReady = PFalse;
    maximumOffset = config->GetInteger("Events", "maximumOffset", 200);
    maximumDelay = config->GetInteger("Events", "maximumOffset", 10);
    for (PINDEX i = 0; i < 10; i++) {
        calibrationTable[i] = new PIntArray;
    };
    for (PINDEX i = 0; i < analogControls.GetSize(); i++) {
        PStringStream summary; // summary string
        int summaryN = -100000; // last value in calibrationTable
        PString calibrationValuesName("Axis");
        calibrationValuesName += analogControls[i];
        calibrationValuesName += "Motion";
        PStringArray calibrationValues = (config->GetString("Gamepad", calibrationValuesName, "")).ToUpper().Tokenise(";", PFalse);
        if (calibrationValues.GetSize() == 0) {
            // push linear sequence
            for (PINDEX j = 0; j < POTENTIOMETER_SCALE; j++) {
                // from -100.00% to +100.00% we have POTENTIOMETER_SCALE values
                int min = ((float)20000/POTENTIOMETER_SCALE)*j;
                int max = ((float)20000/POTENTIOMETER_SCALE)*(j+1);
                for (PINDEX k = min; k <= max; k++) { // overwrite last value
                    PIntArray *table = calibrationTable[i];
                    table->SetAt(k, j);
                };
            };
        } else {
            bool redo;
            do {
                int previous = 0;
                int current  = 0;
                int next     = 0;
                redo = PFalse;
                for (PINDEX j = 0; j < POTENTIOMETER_SCALE; j++) {
                    previous = current;
                    current  = calibrationValues[j].AsInteger();
                    next     = calibrationValues[j+1].AsInteger();
                    if (previous == 20000 && current == 20000) {
                        break;
                    };
                    if (current > next) {
                        if (next != 0 && next != 10000) {
                            PTRACE(1, "calibration error for axis " << analogControls[i] << " value: " << calibrationValues[j] << " previous:" << previous << " current: " << current << " next: " << next);
                            redo = PTrue;
                            calibrationValues[j] = PString(next);
                            calibrationValues[j+1] = PString(current);
                            break;
                        } else {
                            break;
                        };
                    };
                    // set range
                    for (int k = (current+previous)/2; k<=(next+current/2); k++) {
                        PIntArray *table = calibrationTable[i];
                        table->SetAt(k, j);
                    };
                };
            } while(redo);
            // fix head and tail
            int calibrationMinimum = calibrationTable[i]->GetAt(0)-1 > 0 ? calibrationTable[i]->GetAt(0)-1 : 0;
            calibrationTable[i]->SetAt(0, calibrationMinimum);
            int calibrationMaximum = calibrationTable[i]->GetAt(20000)+1 < POTENTIOMETER_SCALE ? calibrationTable[i]->GetAt(20000)+1 : POTENTIOMETER_SCALE-1;
            calibrationTable[i]->SetAt(20000, calibrationMaximum);

        };
        for(PINDEX j = 0; j<= 20000; j++) {
            if (summaryN < calibrationTable[i]->GetAt(j)) {
                summaryN = calibrationTable[i]->GetAt(j);
                summary << " [" << j << "]:" << calibrationTable[i]->GetAt(j);
            };
        };
        PTRACE(4, "ControllerThread\tcalibration summary for '"<< analogControls[i] << "'" << summary);
    };
    // prepare game table
    for (PINDEX i = 0; i < 10; i++) {
        gameTable[i] = new PIntArray;
    };
    resetGameTable();
    PString zzz("mw2x.z");
    loadGameTableT(zzz);
    // start
    Resume();
}
Ejemplo n.º 8
0
/**
 * Add capability to the capability table of the end point. 
 */
int h323_set_capability(int cap, int dtmfMode)
{
	H323Capabilities oldcaps;
	PStringArray codecs;
	int g711Frames = 30;
	int gsmFrames  = 4;

	if (!h323_end_point_exist()) {
		cout << " ERROR: [h323_set_capablity] No Endpoint, this is bad" << endl;
		return 1;
	}

	/* clean up old capabilities list before changing */
	oldcaps = endPoint->GetCapabilities();
	for (PINDEX i=0; i< oldcaps.GetSize(); i++) {
                 codecs.AppendString(oldcaps[i].GetFormatName());
         }
         endPoint->RemoveCapabilities(codecs);

	mode = dtmfMode;
	if (dtmfMode == H323_DTMF_INBAND) {
	    endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsTone);
	} else {
		endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsInlineRFC2833);
	}
	if (cap & AST_FORMAT_SPEEX) {
		/* Not real sure if Asterisk acutally supports all
		   of the various different bit rates so add them 
		   all and figure it out later*/

		endPoint->SetCapability(0, 0, new SpeexNarrow2AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow3AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow4AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow5AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow6AudioCapability());
	}

	if (cap & AST_FORMAT_G729A) {
		AST_G729ACapability *g729aCap;
		AST_G729Capability *g729Cap;
		endPoint->SetCapability(0, 0, g729aCap = new AST_G729ACapability);
		endPoint->SetCapability(0, 0, g729Cap = new AST_G729Capability);
	}
	
	if (cap & AST_FORMAT_G723_1) {
		H323_G7231Capability *g7231Cap;
		endPoint->SetCapability(0, 0, g7231Cap = new H323_G7231Capability);
	} 

	if (cap & AST_FORMAT_GSM) {
		H323_GSM0610Capability *gsmCap;
	    	endPoint->SetCapability(0, 0, gsmCap = new H323_GSM0610Capability);
	    	gsmCap->SetTxFramesInPacket(gsmFrames);
	} 

	if (cap & AST_FORMAT_ULAW) {
		H323_G711Capability *g711uCap;
	    	endPoint->SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw));
		g711uCap->SetTxFramesInPacket(g711Frames);
	} 

	if (cap & AST_FORMAT_ALAW) {
		H323_G711Capability *g711aCap;
		endPoint->SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw));
		g711aCap->SetTxFramesInPacket(g711Frames);
	} 

	if (h323debug) {
		cout <<  "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl;
	}
	return 0;
}