Exemplo n.º 1
0
static BOOL CALLBACK DlgProcOptsCodec(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch ( msg ) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );

		CheckDlgButton(hwndDlg, IDC_CHK_ULAW_P, options.codecs_preferred & IAXC_FORMAT_ULAW ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_ALAW_P, options.codecs_preferred & IAXC_FORMAT_ALAW ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_GSM_P, options.codecs_preferred & IAXC_FORMAT_GSM ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_SPEEX_P, options.codecs_preferred & IAXC_FORMAT_SPEEX ? TRUE : FALSE);

		CheckDlgButton(hwndDlg, IDC_CHK_ULAW, options.codecs_allowed & IAXC_FORMAT_ULAW ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_ALAW, options.codecs_allowed & IAXC_FORMAT_ALAW ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_GSM, options.codecs_allowed & IAXC_FORMAT_GSM ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_SPEEX, options.codecs_allowed & IAXC_FORMAT_SPEEX ? TRUE : FALSE);

#ifdef CODEC_ILBC
		CheckDlgButton(hwndDlg, IDC_CHK_ILBC_P, options.codecs_preferred & IAXC_FORMAT_ILBC ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_ILBC, options.codecs_allowed & IAXC_FORMAT_ILBC ? TRUE : FALSE);
#else
		{
			HWND hw = GetDlgItem(hwndDlg, IDC_CHK_ILBC);
			EnableWindow(hw, FALSE);
			hw = GetDlgItem(hwndDlg, IDC_CHK_ILBC_P);
			EnableWindow(hw, FALSE);
		}
#endif
		return FALSE;
	case WM_COMMAND:
		if ( HIWORD( wParam ) == BN_CLICKED) {
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);		
		}
		break;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
				{
					options.codecs_preferred = options.codecs_allowed = 0;

					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ULAW_P)) options.codecs_preferred |= IAXC_FORMAT_ULAW;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ALAW_P)) options.codecs_preferred |= IAXC_FORMAT_ALAW;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_GSM_P)) options.codecs_preferred |= IAXC_FORMAT_GSM;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_SPEEX_P)) options.codecs_preferred |= IAXC_FORMAT_SPEEX;

					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ULAW)) options.codecs_allowed |= IAXC_FORMAT_ULAW;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ALAW)) options.codecs_allowed |= IAXC_FORMAT_ALAW;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_GSM)) options.codecs_allowed |= IAXC_FORMAT_GSM;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_SPEEX)) options.codecs_allowed |= IAXC_FORMAT_SPEEX;

#ifdef CODEC_ILBC
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ILBC_P)) options.codecs_preferred |= IAXC_FORMAT_ILBC;
					if(IsDlgButtonChecked(hwndDlg, IDC_CHK_ILBC)) options.codecs_allowed |= IAXC_FORMAT_ILBC;
#endif

					DBWriteContactSettingDword(0, MODULE, "CodecsPreferred", options.codecs_preferred);
					DBWriteContactSettingDword(0, MODULE, "CodecsAllowed", options.codecs_allowed);

					iaxc_set_formats(options.codecs_preferred, options.codecs_allowed);
				}
				return TRUE;
		}
		break;
	}

	return 0;
}
Exemplo n.º 2
0
int
main (int argc, char *argv[])
{
  int numbytes;
  static char buf[MAXBUFLEN];
  //int c;
  //int ret = 0;

	prog = strdup( base_name(argv[0]) );
  
	/* program header */
	std::cout << prog << " - a communication radio based on VoIP with IAX/Asterisk" << std::endl;
	std::cout << "Original (c) 2007-2011 by H. Wirtz <*****@*****.**>" << std::endl;
    std::cout << "OSX and Windows ports 2012 by Yves Sablonier and Geoff R. McLane, respectively." << std::endl;
	std::cout << "Version " << FGCOM_VERSION << " build " << SVN_REV << " date " << __DATE__ << ", at " << __TIME__ << std::endl;
	std::cout << "Using iaxclient library Version " << iaxc_version (tmp) << std::endl;
	std::cout << std::endl;

  /* init values */
  voipserver = DEFAULT_VOIP_SERVER;
  fgserver = DEFAULT_FG_SERVER;
  port = DEFAULT_FG_PORT;
  username = DEFAULT_USER;
  password = DEFAULT_PASSWORD;
  codec_option = DEFAULT_CODEC;
  mode = 0;			/* 0 = ATC mode, 1 = FG mode */
  positions_file = (char *) DEFAULT_POSITIONS_FILE;
  frequency_file = (char *) SPECIAL_FREQUENCIES_FILE;

#ifndef _WIN32
  /* catch signals */
  signal (SIGINT, quit);
  signal (SIGQUIT, quit);
  signal (SIGTERM, quit);
#endif

  /* setup iax */
#ifdef HAVE_IAX12
  if (iaxc_initialize (DEFAULT_MAX_CALLS))
#else
  if (iaxc_initialize (DEFAULT_IAX_AUDIO, DEFAULT_MAX_CALLS))
#endif
    fatal_error ("cannot initialize iaxclient!\nHINT: Have you checked the mic and speakers?");

  initialized = 1;

  // option parser
  fgcomInitOptions (fgcomOptionArray, argc, argv);

  // codec
  if (codec_option)
    {
      switch (codec_option)
	{
	case 'u':
	  codec = IAXC_FORMAT_ULAW;
	  break;
	case 'a':
	  codec = IAXC_FORMAT_ALAW;
	  break;
	case 'g':
	  codec = IAXC_FORMAT_GSM;
	  break;
	case '7':
	  codec = IAXC_FORMAT_G726;
	  break;
	case 's':
	  codec = IAXC_FORMAT_SPEEX;
	  break;
	}
    }

  // airport
  if (airport_option)
    {
      strtoupper (airport_option, airport, sizeof (airport));
    }

  // input level
  if (level_in > 1.0)
    {
      level_in = 1.0;
    }
  if (level_in < 0.0)
    {
      level_in = 0.0;
    }

  // output level
  if (level_out > 1.0)
    {
      level_out = 1.0;
    }
  if (level_out < 0.0)
    {
      level_out = 0.0;
    }

  // microphone boost
  if (mic_boost)
    {
      iaxc_mic_boost_set (1);
    }

  if (list_audio)
    {
      std::cout << "Input audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_INPUT) << std::endl;

      std::cout << "Output audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_OUTPUT) << std::endl;

      iaxc_shutdown ();
      exit (1);
    }


  if (audio_in)
    {
      set_device (audio_in, 0);
    }

  if (audio_out)
    {
      set_device (audio_out, 1);
    }

//#ifdef DEBUG
  /* Print any remaining command line arguments (not options). */
  //if (optind < argc) {
  //      printf ("non-option ARGV-elements: ");
  //      while (optind < argc)
  //              printf ("%s ", argv[optind++]);
  //      putchar ('\n');
  //}
//#endif

  /* checking consistency of arguments */
  if (frequency > 0.0 && frequency < 1000.0)
    {
      if (strlen (airport) == 0 || strlen (airport) > 4)
	{
	  strcpy (airport, "ZZZZ");
	}
      /* airport and frequency are given => ATC mode */
      mode = 0;
    }
  else
    {
      /* no airport => FG mode */
      mode = 1;
    }

	/* Read special frequencies file (if exists).
	 * If no file $(INSTALL_DIR)/special_frequencies.txt exists, then default frequencies
	 * are used and are hard coded.
	 */

    if (fix_input_files()) { /* adjust default input per OS */
        fatal_error ("cannot adjust default input files per OS!\nHINT: Maybe recompile with larger buffer.");
    }

	if((special_frequencies = read_special_frequencies(frequency_file)) == 0) {
        std::cout << "Failed to load file [" << frequency_file << "]!\nUsing internal defaults." << std::endl;
        special_frequencies = special_frq;
    } else {
        std::cout << "Loaded file [" << frequency_file << "]." << std::endl;
    }

	/* read airport frequencies and positions */
	airportlist = read_airports (positions_file);   /* never returns if fail! */

  /* preconfigure iax */
  std::cout << "Initializing IAX client as " << username << ":" <<
    "xxxxxxxxxxx@" << voipserver << std::endl;

  iaxc_set_callerid (const_cast < char *>(username),
		     const_cast < char *>("0125252525122750"));
  iaxc_set_formats (codec,
		    IAXC_FORMAT_ULAW | IAXC_FORMAT_GSM | IAXC_FORMAT_SPEEX);
  iaxc_set_event_callback (iaxc_callback);

  iaxc_start_processing_thread ();

  if (username && password && voipserver)
    {
      reg_id =
	iaxc_register (const_cast < char *>(username),
		       const_cast < char *>(password),
		       const_cast < char *>(voipserver));
#ifdef DEBUG
      std::cout << "DEBUG: Registered as '" << username << "' at '" << voipserver <<
	"'." << std::endl;
#endif
    }
  else
    {
      std::cout << "Failed iaxc_register!\nHINT: Check user name, pwd and ip of server." << std::endl;
      exitcode = 130;
      quit (0);
    }

  iaxc_millisleep (DEFAULT_MILLISLEEP);

  /* main loop */
#ifdef DEBUG
  std::cout << "Entering main loop in mode " << mode_map[mode] << "." <<
    std::endl;
#endif

  if (mode == 1)
    {
      /* only in FG mode */
      netInit ();
      netSocket fgsocket;
      fgsocket.open (false);
      fgsocket.bind (fgserver, port);

      /* mute mic, speaker on */
      iaxc_input_level_set (0);
      iaxc_output_level_set (level_out);

      ulClock clock;
      clock.update ();
      double next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
      /* get data from flightgear */
      while (1)
	{
	  clock.update ();
	  double wait = next_update - clock.getAbsTime ();
	  if (wait > 0.001)
	    {
	      netSocket *readsockets[2] = { &fgsocket, 0 };
	      if (fgsocket.select (readsockets, readsockets + 1,
				   (int) (wait * 1000)) == 1)
		{
		  netAddress their_addr;
		  if ((numbytes =
		       fgsocket.recvfrom (buf, MAXBUFLEN - 1, 0,
					  &their_addr)) == -1)
		    {
		      perror ("recvfrom");
		      exit (1);
		    }
		  buf[numbytes] = '\0';
#ifdef DEBUG
		  std::
		    cout << "DEBUG: got packet from " << their_addr.getHost () << ":"
		    << their_addr.getPort () << std::endl;
		  std::cout << "packet is " << numbytes << " bytes long" <<
		    std::endl;
		  std::
		    cout << "packet contains \"" << buf << "\"" << std::endl;
#endif
		  process_packet (buf);
		}
	    }
	  else
	    {
	      alarm_handler (0);
	      clock.update ();
	      next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
	    }
	}
    }
  else
    {
      /* only in ATC mode */
      struct pos p;

      /* mic on, speaker on */
      iaxc_input_level_set (level_in);
      iaxc_output_level_set (level_out);

      /* get geo positions of the airport */
      p = posbyicao (airportlist, airport);

      icao2number (airport, frequency, tmp);
#ifdef DEBUG
      printf ("DEBUG: dialing %s %3.3f MHz: %s\n", airport, frequency, tmp);
#endif
      do_iaxc_call (username, password, voipserver, tmp);
      /* iaxc_select_call (0); */

      while (1)
	{
	  /* sleep endless */
	  ulSleep (3600);
	}
    }

  /* should never be reached */
  exitcode = 999;
  quit (0);
}