[svn-commits] russell: branch russell/chan_console r49055 - /team/russell/chan_console/chan...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Dec 29 05:58:01 MST 2006


Author: russell
Date: Fri Dec 29 06:58:01 2006
New Revision: 49055

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49055
Log:
Shift a couple things around and add doxygen comments.

Modified:
    team/russell/chan_console/channels/chan_console.c

Modified: team/russell/chan_console/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_console/channels/chan_console.c?view=diff&rev=49055&r1=49054&r2=49055
==============================================================================
--- team/russell/chan_console/channels/chan_console.c (original)
+++ team/russell/chan_console/channels/chan_console.c Fri Dec 29 06:58:01 2006
@@ -55,14 +55,30 @@
 #include "ring10.h"
 #include "answer.h"
 
+/*! 
+ * \brief The sample rate to request from PortAudio 
+ *
+ * \note 8000 is universal in Asterisk right now.  Once it supports 16kHz,
+ * it should probably be made an option, with a default of 16kHz.
+ */
 #define SAMPLE_RATE      8000
+/*! 
+ * \brief The number of samples to read/write per callback 
+ *
+ * 160 samples is the most common frame size in Asterisk, so this makes
+ * incoming frames and writing data out to the callback a 1 to 1 process
+ * for convenience.  However, the code is still written to handle arbitrary
+ * frame sizes.
+ */
 #define NUM_SAMPLES      160
+/*! \brief Mono Input */
 #define INPUT_CHANNELS   1
+/*! \brief Mono Output */
 #define OUTPUT_CHANNELS  1
 
 #define CONFIG_FILE      "console.conf"
 
-/*
+/*!
  * Each sound is made of 'datalen' samples of sound, repeated as needed to
  * generate 'samplen' samples of data, then followed by 'silencelen' samples
  * of silence. The loop is repeated if 'repeat' is set.
@@ -85,24 +101,43 @@
 };
 
 static struct console_pvt {
+	/*! Current channel for this device */
 	struct ast_channel *owner;
+	/*! Current PortAudio stream for this device */
 	PaStream *stream;
+	/*! Name of the device */
 	const char *name;
+	/*! Default MOH class to listen to, if:
+	 *    - No MOH class set on the channel
+	 *    - Peer channel putting this device on hold did not suggest a class */
 	char mohinterpret[MAX_MUSICCLASS];
+	/*! A frame for preparing to queue on to the channel */
 	struct ast_frame fr;
+	/*! Buffer to hold outgoing audio with the standard offset */
 	char read_buf[NUM_SAMPLES * 2 + AST_FRIENDLY_OFFSET];
+	/*! Buffer to hold left over samples from frames */
 	char write_buf[NUM_SAMPLES * 2];
+	/*! The index for the next write into write_buf */
 	unsigned int write_dst;
+	/*! The current index into the sounds array */
 	int cur_sound;
+	/*! On-hook = 0, Off-hook = 1 */
 	unsigned int hookstate:1;
+	/*! Ignore context in the console dial CLI command */
 	unsigned int overridecontext:1;
+	/*! The PortAudio callback is being executed */
 	unsigned int incallback:1;
+	/*! Used by the PortAudio callback if it gets called but has to wait for
+	 *  the write function to get called to provide frames. */
 	ast_cond_t cond;
+	/*! Lock for this struct */
 	ast_mutex_t lock;
+	/*! List of frames to be written out to the device */
 	AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
 } pvt = {
 	.name = "default",
 	.lock = AST_MUTEX_INIT_VALUE,
+	.cur_sound = -1,
 };
 
 /*! Global jitterbuffer configuration - by default, jb is disabled */
@@ -113,9 +148,6 @@
 	.impl = ""
 };
 static struct ast_jb_conf global_jbconf;
-
-static int start_stream(void);
-static int stop_stream(void);
 
 static struct ast_channel *console_request(const char *type, int format, 
 	void *data, int *cause);
@@ -148,6 +180,47 @@
 	.fixup = console_fixup,
 };
 
+static int console_callback(const void *input, void *output,
+	unsigned long frame_count, const PaStreamCallbackTimeInfo *time_info,
+	PaStreamCallbackFlags flags, void *userData);
+
+static int start_stream(void)
+{
+	PaError res;
+
+	res = Pa_OpenDefaultStream(&pvt.stream, INPUT_CHANNELS, OUTPUT_CHANNELS, 
+		paInt16, SAMPLE_RATE, NUM_SAMPLES, console_callback, NULL);
+	if (res != paNoError) {
+		ast_log(LOG_WARNING, "Failed to open default audio device - (%d) %s\n",
+			res, Pa_GetErrorText(res));
+		return -1;
+	}
+
+	res = Pa_StartStream(pvt.stream);
+	if (res != paNoError) {
+		ast_log(LOG_WARNING, "Failed to start stream - (%d) %s\n",
+			res, Pa_GetErrorText(res));
+		return -1;
+	}
+
+	return 0;
+}
+
+/*!
+ * \note Called with pvt struct locked
+ */
+static int stop_stream(void)
+{
+	ast_mutex_lock(&pvt.lock);
+	Pa_AbortStream(pvt.stream);
+	Pa_CloseStream(pvt.stream);
+	pvt.stream = NULL;
+	ast_cond_signal(&pvt.cond);
+	ast_mutex_unlock(&pvt.lock);
+
+	return 0;
+}
+
 /*!
  * \note Called with the pvt struct locked
  */
@@ -186,8 +259,6 @@
 {
 	int oldformat = format;
 	struct ast_channel *chan = NULL;
-
-	ast_log(LOG_NOTICE, "console_request...\n");
 
 	format &= AST_FORMAT_SLINEAR;
 	if (!format) {
@@ -234,6 +305,7 @@
 	ast_verbose(" --- <(\"<) --- Hangup on Console --- (>\")> ---\n");
 
 	pvt.hookstate = 0;
+	pvt.cur_sound = -1;
 	c->tech_pvt = NULL;
 	pvt.owner = NULL;
 
@@ -259,6 +331,7 @@
 
 	ast_mutex_lock(&pvt.lock);
 	ast_setstate(c, AST_STATE_UP);
+	pvt.cur_sound = -1;
 	res = start_stream();
 	ast_mutex_unlock(&pvt.lock);
 
@@ -521,6 +594,7 @@
 		return CLI_FAILURE;
 	}
 	pvt.hookstate = 0;
+	pvt.cur_sound = -1;
 	if (pvt.owner)
 		ast_queue_hangup(pvt.owner);
 
@@ -572,42 +646,12 @@
 	NEW_CLI(cli_list_devices, "List available devices"),
 };
 
-static int start_stream(void)
-{
-	PaError res;
-
-	res = Pa_OpenDefaultStream(&pvt.stream, INPUT_CHANNELS, OUTPUT_CHANNELS, 
-		paInt16, SAMPLE_RATE, NUM_SAMPLES, console_callback, NULL);
-	if (res != paNoError) {
-		ast_log(LOG_WARNING, "Failed to open default audio device - (%d) %s\n",
-			res, Pa_GetErrorText(res));
-		return -1;
-	}
-
-	res = Pa_StartStream(pvt.stream);
-	if (res != paNoError) {
-		ast_log(LOG_WARNING, "Failed to start stream - (%d) %s\n",
-			res, Pa_GetErrorText(res));
-		return -1;
-	}
-
-	return 0;
-}
-
 /*!
- * \note Called with pvt struct locked
- */
-static int stop_stream(void)
-{
-	ast_mutex_lock(&pvt.lock);
-	Pa_AbortStream(pvt.stream);
-	Pa_CloseStream(pvt.stream);
-	ast_cond_signal(&pvt.cond);
-	ast_mutex_unlock(&pvt.lock);
-
-	return 0;
-}
-
+ * \brief Load the configuration
+ * \param reload if this was called due to a reload
+ * \retval 0 succcess
+ * \retval -1 failure
+ */
 static int load_config(int reload)
 {
 	struct ast_config *cfg;



More information about the svn-commits mailing list