/*****************************************************************************
 *                                                                           *
 * iaxrecord (warvox 1.0.1) patch. Enable the use of test mode of iaxclient  *
 * library (needed 2.2.x), you will not need an audio device anymore.        *
 *                                                                           *
 * Copyright (c) 2010 @ Mediaservice.net Srl. All rights reserved            *
 * Wrote by Maurizio Agazzini <inode[at]mediaservice.net>                    *
 *                                                                           *
 * This program is free software; you can redistribute it and/or             *
 * modify it under the terms of the GNU General Public License               *
 * as published by the Free Software Foundation; either version 2            *
 * of the License, or (at your option) any later version.                    *
 *                                                                           *
 * This program is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 * GNU General Public License for more details.                              *
 *                                                                           *
 * You should have received a copy of the GNU General Public License         *
 * along with this program; if not, write to the Free Software               *
 * Foundation, Inc., 59 Temple Place                                         *
 * Suite 330, Boston, MA  02111-1307, USA.                                   *
 *                                                                           *
 *****************************************************************************/

--- iaxrecord.orig	2010-01-04 17:59:25.000000000 +0100
+++ iaxrecord.c	2010-01-04 18:06:15.000000000 +0100
@@ -13,6 +13,8 @@
  * the GNU General Public License
  */
 
+#define TEST_MODE 1
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -38,6 +40,11 @@
 char *iax_out;
 int reg_id;
 
+#ifdef TEST_MODE
+int call_end = 0;
+unsigned char empty_buf[200];
+#endif
+
 void signal_handler(int signum) {
 	if ( signum == SIGTERM || signum == SIGINT ) {
 		done = 1;
@@ -198,6 +205,11 @@
 	/* install signal handler to catch CRTL-Cs */
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
+
+	/* enable test mode */
+#ifdef TEST_MODE
+	iaxc_set_test_mode(1);
+#endif
 	
 	/* forcible disable pulse audio if the audio flag is not set (-A) */
 	if(! audio) setenv("PULSE_SERVER", "0.0.0.0", 1);
@@ -245,6 +257,13 @@
 			if(call_state & IAXC_CALL_STATE_BUSY) break;
 			if(iaxc_first_free_call() == call_id) break;
 			iaxc_millisleep(250);
+			
+#ifdef TEST_MODE
+			/* we need do send something to receive data... I don't know why... */
+			if( !call_end && call_state & IAXC_CALL_STATE_COMPLETE )
+				iaxc_push_audio(&empty_buf[0], 200, 200);
+#endif
+
 		}
 	} else {
 		fail = 1;
