Revision: 1437
http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1437&view=rev
Author: jpgrayson
Date: 2008-07-01 08:42:30 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
Move audio startup retry logic from audio_portaudio.c to higher-level
main_proc_thread_func().
- Allows iaxclient to be usable on systems with no audio hardware.
Modified Paths:
--------------
trunk/lib/audio_portaudio.c
trunk/lib/iaxclient_lib.c
Modified: trunk/lib/audio_portaudio.c
===================================================================
--- trunk/lib/audio_portaudio.c 2008-07-01 15:35:07 UTC (rev 1436)
+++ trunk/lib/audio_portaudio.c 2008-07-01 15:42:30 UTC (rev 1437)
@@ -643,8 +643,6 @@
static int pa_start(struct iaxc_audio_driver *d)
{
- static int errcnt = 0;
-
if ( running )
return 0;
@@ -661,29 +659,13 @@
oMixer = NULL;
}
- if ( errcnt > 5 )
- {
- iaxci_usermsg(IAXC_TEXT_TYPE_FATALERROR,
- "iaxclient audio: Can't open Audio Device. "
- "Perhaps you do not have an input or output device?");
- /* OK, we'll give the application the option to abort or
- * not here, but we will throw a fatal error anyway */
- iaxc_millisleep(1000);
- //return -1; // Give Up. Too many errors.
- }
-
/* flush the ringbuffers */
rb_InitializeRingBuffer(&inRing, INRBSZ, inRingBuf);
rb_InitializeRingBuffer(&outRing, OUTRBSZ, outRingBuf);
if ( pa_openstreams(d) )
- {
- errcnt++;
return -1;
- }
- errcnt = 0; // only count consecutive errors.
-
if ( Pa_StartStream(iStream) != paNoError )
return -1;
Modified: trunk/lib/iaxclient_lib.c
===================================================================
--- trunk/lib/iaxclient_lib.c 2008-07-01 15:35:07 UTC (rev 1436)
+++ trunk/lib/iaxclient_lib.c 2008-07-01 15:42:30 UTC (rev 1437)
@@ -407,7 +407,7 @@
return count;
}
-EXPORT int iaxc_first_free_call()
+EXPORT int iaxc_first_free_call(void)
{
int i;
for ( i = 0; i < max_calls; i++ )
@@ -769,10 +769,13 @@
}
}
-#define LOOP_SLEEP 5 // In ms
static THREADFUNCDECL(main_proc_thread_func)
{
+ const int sleep_ms = 5;
+ const int counts_per_second = 1000 / sleep_ms;
static int refresh_registration_count = 0;
+ static int audio_error_count = 0;
+ static int audio_error_state = 0;
THREADFUNCRET(ret);
@@ -784,11 +787,31 @@
get_iaxc_lock();
service_network();
- if ( !test_mode )
- service_audio();
+ if ( !test_mode &&
+ (!audio_error_state ||
+ audio_error_count++ % counts_per_second == 0) )
+ {
+ /* There are cases when service audio fails such
+ * as when there is no audio devices present in
+ * the system. In these cases, only call
+ * service_audio() once per second until it
+ * succeeds.
+ */
+ if ( (audio_error_state = service_audio()) )
+ {
+ iaxci_usermsg(IAXC_NOTICE,
+ "failed to service audio");
+
+ if ( audio_error_count / counts_per_second == 5 )
+ iaxci_usermsg(IAXC_TEXT_TYPE_FATALERROR,
+ "cannot open audio device"
+ " after several tries");
+ }
+ }
+
// Check registration refresh once a second
- if ( refresh_registration_count++ > 1000/LOOP_SLEEP )
+ if ( refresh_registration_count++ > counts_per_second )
{
iaxc_refresh_registrations();
refresh_registration_count = 0;
@@ -796,7 +819,7 @@
put_iaxc_lock();
- iaxc_millisleep(LOOP_SLEEP);
+ iaxc_millisleep(sleep_ms);
}
/* Decrease priority */
@@ -853,7 +876,8 @@
int to_read;
int cmin;
- audio_driver.start(&audio_driver);
+ if ( audio_driver.start(&audio_driver) )
+ return -1;
/* use codec minimum if higher */
cmin = want_send_audio && call->encoder ?
@@ -941,7 +965,7 @@
}
/* handle IAX URL events */
-void handle_url_event( struct iax_event *e, int callNo )
+static void handle_url_event( struct iax_event *e, int callNo )
{
iaxc_event ev;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|