[Sumover-dev] [svn commit] r3969 - rat/trunk

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Fri Mar 2 19:18:24 GMT 2007


Author: piers
Date: Fri Mar  2 19:18:26 2007
New Revision: 3969

Modified:
   rat/trunk/Makefile.in
   rat/trunk/auddev_oss.c
   rat/trunk/auddev_win32.c
   rat/trunk/cmd_parser.c
   rat/trunk/configure.in
   rat/trunk/main_engine.c
   rat/trunk/main_ui.c
   rat/trunk/mbus_engine.c
   rat/trunk/pdb.c
   rat/trunk/pdb.h
   rat/trunk/process.c
   rat/trunk/rtp_callback.c
   rat/trunk/rtp_callback.h
   rat/trunk/session.h
   rat/trunk/ui_audiotool.tcl
   rat/trunk/ui_send_rtp.c
   rat/trunk/ui_send_rtp.h

Log:
Updates for to bring the code into line with AG sources
- Site app extension
- Per participant volume sliders
- Added a new card defination to auddev_oss


Modified: rat/trunk/Makefile.in
==============================================================================
--- rat/trunk/Makefile.in	(original)
+++ rat/trunk/Makefile.in	Fri Mar  2 19:18:26 2007
@@ -85,7 +85,7 @@
 
 INSTALL_OBJS = ui_installer.o installer.o binaries.o
 
-all: version.h sdr2.plugin.S02.audio.rtp.-.$(RATVER) $(RATVER).spec $(RATVER) $(RATVER)-ui $(RATVER)-media rat Makefile
+all: version.h sdr2.plugin.S02.audio.rtp.-.$(RATVER) $(RATVER).spec $(RATVER) $(RATVER)-ui $(RATVER)-media $(RATVER)-kill rat Makefile
 
 libuclaudio.a: $(AUDIO_OBJS)
 	$(AR) r $@ $(AUDIO_OBJS)
@@ -99,6 +99,9 @@
 	$(AR) r $@ $(SNDFILE_OBJS)
 	$(RANLIB) $@
 
+$(RATVER)-kill: rat-kill.o
+	$(CC) $(CFLAGS) rat-kill.o $(COMMON_LIB) $(LIBS) -o $(RATVER)-kill
+
 $(RATVER)-media: $(CHANNEL_OBJS) $(TOY_OBJS) $(MEDIA_OBJS) $(MEDIALIBS) $(EXTERNAL_DEP)
 	$(CC) $(CFLAGS) $(CHANNEL_OBJS) $(TOY_OBJS) $(MEDIA_OBJS) $(MEDIALIBS) $(COMMON_LIB) $(AUD_LIB) $(LIBS) $(G728_LIB) -o $(RATVER)-media
 
@@ -164,6 +167,7 @@
 install: all
 	./install-sh -m 555 -c rat             $(bindir)
 	./install-sh -m 555 -c $(RATVER)       $(bindir)
+	./install-sh -m 555 -c $(RATVER)-kill  $(bindir)/rat-kill
 	./install-sh -m 555 -c $(RATVER)-media $(bindir)
 	./install-sh -m 555 -c $(RATVER)-ui    $(bindir)
 	./install-sh -m 444 -c man/man1/rat.1  $(mandir)/man1/rat.1
@@ -202,11 +206,19 @@
 
 tgz: $(RATVER)-$(OSTYPE).tar.gz
 
-rpm: tgz
+rpm: clean tgz 
 	@${ECHO} "Building $(RATVER).rpm -- this almost certainly needs to run as root on RedHat Linux"
-	install -m 644 $(RATVER)-$(OSTYPE).tar.gz /usr/src/redhat/SOURCES/rat-4.1.2.tar.gz
+#	install -m 644 $(RATVER)-$(OSTYPE).tar.gz /usr/src/redhat/SOURCES/rat-4.1.2.tar.gz
+	install -m 644 AccessGrid-rat.spec /usr/src/redhat/SPECS/AccessGrid-rat.spec
+	install -m 644 $(RATVER)-$(OSTYPE).tar.gz /usr/src/redhat/SOURCES/$(RATVER)-$(OSTYPE).tar.gz
 	rpm -bb $(RATVER).spec
 
+agrpm: clean
+	@${ECHO} "Building AG $(RATVER).rpm -- this almost certainly needs to run as root on RedHat Linux"
+	( cd ../.. ; ln -s ag-rat $(RATVER) ; tar cvfh /usr/src/redhat/SOURCES/$(RATVER).tar.gz $(RATVER) ; rm $(RATVER) )
+	install -m 644 AccessGrid-rat.spec /usr/src/redhat/SPECS/AccessGrid-rat.spec
+	rpm -ba AccessGrid-rat.spec
+
 Makefile: Makefile.in VERSION
 	$(error "Run configure again, the following file(s) are newer than Makefile: $?")
 

Modified: rat/trunk/auddev_oss.c
==============================================================================
--- rat/trunk/auddev_oss.c	(original)
+++ rat/trunk/auddev_oss.c	Fri Mar  2 19:18:26 2007
@@ -97,6 +97,8 @@
 	"OSS: AudioPCI 97 (CRY13/0x43525913)",
 	"OSS: AudioPCI 97 (CS4297A)",
 	"OSS: Realtek ALC650E",
+	"OSS: Analog Devices AD1981B",
+	"OSS: Asahi Kasei AK4531",
 	0
 };
 
@@ -891,6 +893,7 @@
                 len -= done;
                 p   += done;
         }
+	debug_msg("OSS wrote %d bytes\n",write_bytes);
         return write_bytes;
 }
 

Modified: rat/trunk/auddev_win32.c
==============================================================================
--- rat/trunk/auddev_win32.c	(original)
+++ rat/trunk/auddev_win32.c	Fri Mar  2 19:18:26 2007
@@ -1449,6 +1449,7 @@
 {
         UNUSED(ad);
 
+	debug_msg("set audio_loopback gain to %d\n", gain);
         nLoopGain = gain;
 }
 

Modified: rat/trunk/cmd_parser.c
==============================================================================
--- rat/trunk/cmd_parser.c	(original)
+++ rat/trunk/cmd_parser.c	Fri Mar  2 19:18:26 2007
@@ -58,6 +58,17 @@
 }
 
 static int
+cmd_logdebug(struct mbus *m, char *addr, int argc, char *argv[])
+{
+        assert(argc == 1);
+	printf("cmdparser logdebug\n");
+        mbus_qmsgf(m, addr, TRUE, "tool.rat.logdebug", "1 %s", mbus_encode_str(argv[0]));
+        UNUSED(argc);
+        UNUSED(argv);
+        return TRUE;
+}
+
+static int 
 cmd_layers(struct mbus *m, char *addr, int argc, char *argv[])
 {
         int layers;
@@ -273,8 +284,28 @@
         return TRUE;
 }
 
+static int
+cmd_app_site(struct mbus *m, char *addr, int argc, char *argv[]) {
+        char *app_value, *local_user;
+	assert(argc == 1);
+	UNUSED(argc);
+        local_user = mbus_encode_str("localuser");
+        app_value = mbus_encode_str(argv[0]);
+        mbus_qmsgf(m,
+		   addr,
+		   TRUE,
+		   "rtp.source.app.site",
+		   "%s %s",
+		   local_user,
+		   app_value);
+        xfree(local_user);
+        xfree(app_value);
+        return TRUE;
+}
+  
 static args_handler late_args[] = {
 	{ "-logstats",       cmd_logstats,     0 },
+	{ "-logdebug",       cmd_logdebug,     1 },
         { "-l",              cmd_layers,       1 },
         { "-allowloopback",  cmd_allowloop,    0 },
         { "-allow_loopback", cmd_allowloop,    0 },
@@ -286,6 +317,7 @@
         { "-L",              cmd_sdes_loc,     1 },
         { "-N",              cmd_sdes_name,    1 },
         { "-P",              cmd_sdes_phone,   1 },
+        { "-S",              cmd_app_site,     1 },
         { "-agc",            cmd_agc,          1 },
         { "-silence",        cmd_silence,      1 },
         { "-repair",         cmd_repair,       1 },

Modified: rat/trunk/configure.in
==============================================================================
--- rat/trunk/configure.in	(original)
+++ rat/trunk/configure.in	Fri Mar  2 19:18:26 2007
@@ -187,7 +187,7 @@
 		],AC_MSG_RESULT(missing))
 	])
 	# Do we have ALSA?
-	AC_CHECK_HEADER(sys/asoundlib.h,[
+	AC_CHECK_HEADER(alsa/asoundlib.h,[
 		AUD_OBJ="$AUD_OBJ auddev_alsa.o"
 		AUD_LIB="$AUD_LIB -lasound"
 		AC_DEFINE(HAVE_ALSA_AUDIO)

Modified: rat/trunk/main_engine.c
==============================================================================
--- rat/trunk/main_engine.c	(original)
+++ rat/trunk/main_engine.c	Fri Mar  2 19:18:26 2007
@@ -1,14 +1,14 @@
 /*
  * FILE:    main-engine.c
  * PROGRAM: RAT
- * AUTHOR:  Colin Perkins
+ * AUTHOR:  Colin Perkins 
  *
  * Copyright (c) 1995-2001 University College London
  * All rights reserved.
  */
-
+ 
 #ifndef HIDE_SOURCE_STRINGS
-static const char cvsid[] =
+static const char cvsid[] = 
 	"$Id$";
 #endif /* HIDE_SOURCE_STRINGS */
 
@@ -53,7 +53,7 @@
 #include "util.h"
 
 char		*c_addr, *token[2], *token_e[2]; /* Could be in the session struct */
-int         	 should_exit = FALSE;
+int         	 should_exit = FALSE; 
 int		 mbus_shutdown_error = FALSE;
 int		 num_sessions = 1;
 
@@ -72,7 +72,7 @@
 
 static void parse_args(int argc, char *argv[])
 {
-	int 	i, tc;
+	int 		i, tc;
 
 	if ((argc != 5)  && (argc != 8)) {
 		printf("Usage: rat-%s-media [-T] -ctrl <addr> -token <token> [-token <token>]\n", RAT_VERSION);
@@ -109,7 +109,7 @@
         ppid = strtoul(&c_addr[i], NULL, 10);
 }
 
-static void
+static void 
 mbus_error_handler(int seqnum, int reason)
 {
 	debug_msg("mbus message failed (seqnum:%d - %s)\n", seqnum, mbus_errlist[reason>=MBUS_ERR_MAX?MBUS_ERR_MAX:reason]);
@@ -118,7 +118,7 @@
                 sprintf(msg, "MBUS message failed (%d:%s)\n", seqnum, mbus_errlist[reason>=MBUS_ERR_MAX?MBUS_ERR_MAX:reason]);
                 fatal_error("RAT v" RAT_VERSION, msg);
                 abort();
-        }
+        } 
 	mbus_shutdown_error = TRUE;
         UNUSED(seqnum);
         UNUSED(reason);
@@ -144,7 +144,7 @@
 		for (j = 0; j < num_sessions; j++) {
 			timeout.tv_sec  = 0;
 			timeout.tv_usec = 10000;
-			mbus_send(sp[j]->mbus_engine);
+			mbus_send(sp[j]->mbus_engine); 
 			mbus_recv(sp[j]->mbus_engine, (void *) sp[j], &timeout);
 			mbus_heartbeat(sp[j]->mbus_engine, 1);
 			mbus_retransmit(sp[j]->mbus_engine);
@@ -187,7 +187,7 @@
 			timeout.tv_sec  = 0;
 			timeout.tv_usec = 20000;
 			mbus_qmsgf(sp[i]->mbus_engine, c_addr, FALSE, "mbus.waiting", "%s", token_e[i]);
-			mbus_send(sp[i]->mbus_engine);
+			mbus_send(sp[i]->mbus_engine); 
 			mbus_recv(sp[i]->mbus_engine, (void *) sp[i], &timeout);
 			mbus_heartbeat(sp[i]->mbus_engine, 1);
 			mbus_retransmit(sp[i]->mbus_engine);
@@ -212,7 +212,7 @@
 #ifdef WIN32
 	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
 #else
-	signal(SIGINT, signal_handler);
+	signal(SIGINT, signal_handler); 
         debug_set_core_dir(argv[0]);
 #endif
 
@@ -254,19 +254,19 @@
 
         /* Moved session[0] setup to rx_rtp_addr so one may change addr
            binding dynamically */
-        /* Load saved settings, and create the participant database... */
-        /* FIXME: probably needs updating for the transcoder so we can */
-        /*        have different saved settings for each domain.       */
-        /* FIXME: this gets the wrong device name for the transcoder.  */
-        for (i = 0; i < num_sessions; i++) {
-                if (pdb_create(&sp[i]->pdb) == FALSE) {
-                        debug_msg("Failed to create participant database\n");
-                        abort();
-                }
-                pdb_item_create(sp[i]->pdb, (uint16_t)ts_get_freq(sp[i]->cur_ts), rtp_my_ssrc(sp[i]->rtp_session[0]));
-                settings_load_late(sp[i]);
-                session_validate(sp[i]);
-        }
+	/* Load saved settings, and create the participant database... */
+	/* FIXME: probably needs updating for the transcoder so we can */
+	/*        have different saved settings for each domain.       */
+	/* FIXME: this gets the wrong device name for the transcoder.  */
+	for (i = 0; i < num_sessions; i++) {
+		if (pdb_create(&sp[i]->pdb) == FALSE) {
+			debug_msg("Failed to create participant database\n");
+			abort();
+		}
+		pdb_item_create(sp[i]->pdb, (uint16_t)ts_get_freq(sp[i]->cur_ts), rtp_my_ssrc(sp[i]->rtp_session[0])); 
+		settings_load_late(sp[i]);
+		session_validate(sp[i]);
+	}
 
 	xmemchk();
 	xdoneinit();
@@ -295,7 +295,7 @@
 			for (j = 0; j < sp[i]->rtp_session_count; j++) {
 				rtp_time = tx_get_rtp_time(sp[i]);
 				while(rtp_recv(sp[i]->rtp_session[j], &timeout, rtp_time));
-				rtp_send_ctrl(sp[i]->rtp_session[j], rtp_time, NULL);
+				rtp_send_ctrl(sp[i]->rtp_session[j], rtp_time, rtcp_app_site_callback);
 				rtp_update(sp[i]->rtp_session[j]);
 			}
 
@@ -305,7 +305,7 @@
 			mbus_recv(sp[i]->mbus_engine, (void *) sp[i], &timeout);
 			mbus_heartbeat(sp[i]->mbus_engine, 1);
 			mbus_retransmit(sp[i]->mbus_engine);
-			mbus_send(sp[i]->mbus_engine);
+			mbus_send(sp[i]->mbus_engine); 
 
 			/* Process and mix active sources */
 			if (sp[i]->playing_audio) {
@@ -430,7 +430,7 @@
 					}
 				}
 			}
-
+			
 			/* Choke CPU usage */
 			if (!audio_is_ready(sp[i]->audio_device)) {
 				audio_wait_for(sp[i]->audio_device, 50);
@@ -467,7 +467,7 @@
 		audio_device_release(sp[i], sp[i]->audio_device);
 		audio_free_interfaces();
 	}
-
+	
 	/* FIXME: This should be integrated into the previous loop, so instead of */
 	/*        sending mbus.bye() ourselves, we just call mbus_exit(...) which */
 	/*        sends a bye and shuts everything down cleanly for us.           */
@@ -475,7 +475,7 @@
 	if (mbus_addr_valid(sp[0]->mbus_engine, c_addr)) {
 		do {
 			struct timeval	 timeout;
-			mbus_send(sp[0]->mbus_engine);
+			mbus_send(sp[0]->mbus_engine); 
 			/* At this stage we no longer care about acks for messages */
 			/* mbus_retransmit(sp[0]->mbus_engine); */
 			timeout.tv_sec  = 0;
@@ -494,7 +494,7 @@
 		xfree(token[i]);
 		xfree(token_e[i]);
 	}
-
+        
 	converters_free();
 	xfree(c_addr);
 	xmemdmp();

Modified: rat/trunk/main_ui.c
==============================================================================
--- rat/trunk/main_ui.c	(original)
+++ rat/trunk/main_ui.c	Fri Mar  2 19:18:26 2007
@@ -94,9 +94,15 @@
 	struct timeval	 timeout;
 
 #ifdef WIN32
+	HANDLE waitHandles[2];
+
         HANDLE     hWakeUpEvent;
+	HANDLE	hParentProcess;
+	DWORD waitRet;
+
         TkWinXInit(hAppInstance);
         hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, "Local\\RAT UI WakeUp Event");
+
 #endif
 
         debug_set_core_dir(argv[0]);
@@ -105,6 +111,11 @@
 	parse_args(argc, argv);
 	tcl_init1(argc, argv);
 
+#ifdef WIN32
+	hParentProcess = OpenProcess(SYNCHRONIZE, FALSE, ppid);
+	debug_msg("OpenPRocess returns %d\n", hParentProcess);
+#endif
+
 	sprintf(m_addr, "(media:audio module:ui app:rat id:%lu)", (unsigned long) ppid);
 	m = mbus_init(mbus_ui_rx, mbus_error_handler, m_addr);
         if (m == NULL) {
@@ -161,7 +172,17 @@
 		/* Throttle CPU usage */
 #ifdef WIN32
                 /* Just timeout waiting for event that never happens */
-                WaitForSingleObject(hWakeUpEvent, 30);
+                /* WaitForSingleObject(hWakeUpEvent, 30); */
+
+		waitHandles[0] = hWakeUpEvent;
+		waitHandles[1] = hParentProcess;
+		waitRet = WaitForMultipleObjects(2, waitHandles, FALSE, 30);
+		
+		if ((waitRet - WAIT_OBJECT_0) == 1)
+		{
+			debug_msg("Parent process died\n");
+			should_exit = TRUE;
+		}
 #else
 		timeout.tv_sec  = 0;
 		timeout.tv_usec = 30000;

Modified: rat/trunk/mbus_engine.c
==============================================================================
--- rat/trunk/mbus_engine.c	(original)
+++ rat/trunk/mbus_engine.c	Fri Mar  2 19:18:26 2007
@@ -52,6 +52,8 @@
 extern int 	 should_exit;
 extern FILE 	*stats_file;
 
+extern void rtp_callback_open_logfile(char *file);
+
 /* Mbus command reception function type */
 typedef void (*mbus_rx_proc)(char *srce, char *args, session_t *sp);
 
@@ -630,6 +632,32 @@
 	mbus_parse_done(mp);
 }
 
+static void rx_tool_rat_logdebug(char *srce, char *args, session_t *sp)
+{
+    int enabled;
+    char *file;
+	struct mbus_parser	*mp;
+
+	UNUSED(srce);
+	UNUSED(sp);
+	
+		printf("Logdebug '%s'\n", args);
+
+	mp = mbus_parse_init(args);
+	if (mbus_parse_int(mp, &enabled) &&
+	    mbus_parse_str(mp, &file))
+	    {
+		mbus_decode_str(file);
+		printf("enabled=%d file=%s\n", enabled, file);
+		if (enabled) {
+		    rtp_callback_open_logfile(file);
+		}
+	} else {
+		debug_msg("mbus: usage \"tool.rat.logstats <boolean>\"\n");
+	}
+	mbus_parse_done(mp);
+}
+
 static void rx_tool_rat_tone_start(char *srce, char *args, session_t *sp)
 {
 	int freq, amp;
@@ -901,6 +929,7 @@
 	/* We respond by dumping all our RTP related state to the querier.     */
 	uint32_t	 ssrc, my_ssrc;
 	struct s_source	*s;
+    pdb_entry_t *e;
 
 	UNUSED(args);
 	debug_msg("mbus: rx_rtp_query\n");
@@ -917,6 +946,13 @@
 		ui_send_rtp_tool(sp, srce, ssrc);
 		ui_send_rtp_note(sp, srce, ssrc);
 		ui_send_rtp_mute(sp, srce, ssrc);
+
+		if (pdb_item_get(sp->pdb, ssrc, &e) == TRUE) {
+		  if (e->siteid != NULL) {
+		    ui_send_rtp_app_site(sp, srce, ssrc, e->siteid);
+		  }
+		}
+
 		if (ssrc != my_ssrc) {
 			if ((s = source_get_by_ssrc(sp->active_sources, ssrc)) != NULL) {
 				ui_send_rtp_active(sp, srce, ssrc);
@@ -1098,6 +1134,45 @@
 	rx_rtp_source_sdes(srce, args, sp, RTCP_SDES_NOTE);
 }
 
+static void rx_rtp_source_app_site(char *srce, char *args, session_t *sp)
+{
+        char               *arg, *ss;
+        uint32_t           ssrc;
+        struct mbus_parser *mp;
+        UNUSED(srce);
+
+        mp = mbus_parse_init(args);
+        if (mbus_parse_str(mp, &ss) &&
+            mbus_parse_str(mp, &arg)) {
+                uint32_t my_ssrc = rtp_my_ssrc(sp->rtp_session[0]);
+                ss = mbus_decode_str(ss);
+                if (isalpha((int)ss[0])) {
+                        /*
+                         * Allow alpha so people can do my_src, me,
+                         * local_user, whatever.  Let the mbus police
+                         * pick something sane.
+                         */
+                        ssrc = my_ssrc;
+                } else {
+                        ssrc = strtoul(ss, 0, 16);
+                }
+                if (ssrc == my_ssrc) {
+                        char *value;
+
+                        value = mbus_decode_str(arg);
+
+                        if (sp->rtp_session_app_site != NULL) {
+                                xfree(sp->rtp_session_app_site);
+                        }
+                        sp->rtp_session_app_site = xstrdup(value);
+                } else {
+                        debug_msg("mbus: rtp_source_app_site ssrc %s (%08lx) != %08lx\n", ss, strtoul(ss, 0, 16), rtp_my_ssrc(sp->rtp_session[0]));
+                }
+        } else {
+                debug_msg("mbus: usage \"rtp_source_app_site <ssrc> <siteid>\"\n");
+        }
+        mbus_parse_done(mp);
+}
 
 static void rx_rtp_source_gain(char *srce, char *args, session_t *sp)
 {
@@ -1639,6 +1714,7 @@
 
 static const mbus_cmd_tuple engine_cmds[] = {
 	{ "tool.rat.logstats",                     rx_tool_rat_logstats },
+	{ "tool.rat.logdebug",                     rx_tool_rat_logdebug },
 	{ "tool.rat.tone.start",                   rx_tool_rat_tone_start },
 	{ "tool.rat.tone.stop",                    rx_tool_rat_tone_stop },
 	{ "tool.rat.voxlet.play",                  rx_tool_rat_voxlet_play },
@@ -1695,6 +1771,7 @@
 	{ "rtp.source.note",                       rx_rtp_source_note },
 	{ "rtp.source.mute",                       rx_rtp_source_mute },
 	{ "rtp.source.gain",                       rx_rtp_source_gain },
+        { "rtp.source.app.site",                   rx_rtp_source_app_site },
 	{ "mbus.quit",                             rx_mbus_quit },
 	{ "mbus.bye",                              rx_mbus_bye },
 	{ "mbus.waiting",                          rx_mbus_waiting },
@@ -1716,6 +1793,7 @@
 	}
 	debug_msg("Unknown mbus command: %s (%s)\n", cmnd, args);
 #ifndef NDEBUG
+	fprintf(stderr, "Unknown mbus command: %s (%s)\n", cmnd, args);
 	abort();
 #endif
 }

Modified: rat/trunk/pdb.c
==============================================================================
--- rat/trunk/pdb.c	(original)
+++ rat/trunk/pdb.c	Fri Mar  2 19:18:26 2007
@@ -129,6 +129,7 @@
         }
 
         /* Initialize elements of item here as necesary **********************/
+
 	item->magic             = 0xc001babe;
         item->ssrc              = id;
         item->render_3D_data    = NULL;
@@ -152,7 +153,6 @@
         item->last_arr          = zero_ts;
         item->last_rtt          = 0.0;
         item->avg_rtt           = 0.0;
-
         /* Packet stats initialization                                       */
         item->received          = 0;
         item->duplicates        = 0;
@@ -161,6 +161,8 @@
         item->spike_toged       = 0;
         item->spike_events      = 0;
 
+	item->siteid          = NULL;
+
 	pdb_item_validate(item);
         /*********************************************************************/
 

Modified: rat/trunk/pdb.h
==============================================================================
--- rat/trunk/pdb.h	(original)
+++ rat/trunk/pdb.h	Fri Mar  2 19:18:26 2007
@@ -66,6 +66,9 @@
         uint32_t        misordered;
         uint32_t        jit_toged;                   /* Packets discarded because late ("Thrown on ground") */
 
+  /* SiteID from RTCP APP packet. */
+        char           *siteid;
+
 	uint32_t	magic;	/* For debugging */
 } pdb_entry_t;
 

Modified: rat/trunk/process.c
==============================================================================
--- rat/trunk/process.c	(original)
+++ rat/trunk/process.c	Fri Mar  2 19:18:26 2007
@@ -47,9 +47,9 @@
         proc_info = (LPPROCESS_INFORMATION) xmalloc(sizeof(PROCESS_INFORMATION));
 
 	if (num_tokens == 1) {
-		sprintf(args, "%s -ctrl \"%s\" -token %s", proc_name, ctrl_addr, token[0]);
+		_snprintf(args, sizeof(args), "%s -ctrl \"%s\" -token %s", proc_name, ctrl_addr, token[0]);
 	} else {
-		sprintf(args, "%s -T -ctrl \"%s\" -token %s -token %s", proc_name, ctrl_addr, token[0], token[1]);
+		_snprintf(args, sizeof(args), "%s -T -ctrl \"%s\" -token %s -token %s", proc_name, ctrl_addr, token[0], token[1]);
 	}
 
         if (!CreateProcess(NULL, args, NULL, NULL, TRUE, 0, NULL, NULL, startup_info, proc_info)) {

Modified: rat/trunk/rtp_callback.c
==============================================================================
--- rat/trunk/rtp_callback.c	(original)
+++ rat/trunk/rtp_callback.c	Fri Mar  2 19:18:26 2007
@@ -31,6 +31,8 @@
 #include "rtp_callback.h"
 #include "rtp_dump.h"
 
+int rtp_get_ssrc_count(struct rtp *r);
+
 /* We need to be able to resolve the rtp session to a rat session in */
 /* order to get persistent participant information, etc.  We use a   */
 /* double linked list with sentinel for this.  We normally don't     */
@@ -48,6 +50,28 @@
 static rtp_assoc_t rtp_as;
 static int rtp_as_inited;
 
+static FILE *log_fp = 0;
+
+void rtp_callback_open_logfile(char *file);
+
+void rtp_callback_open_logfile(char *file)
+{
+    log_fp = fopen(file, "a");
+    if (!log_fp)
+    {
+	perror("log_fp open failed");
+    }
+    else
+    {
+        struct timeval  tv;
+        gettimeofday(&tv, 0);
+
+	printf("Opened logfile %s\n", file);
+	fprintf(log_fp, "%d.%06d 0 start\n", (int) tv.tv_sec, (int) tv.tv_usec);
+    }
+}
+
+
 void
 rtp_callback_init(struct rtp *rtps, struct s_session *rats)
 {
@@ -87,6 +111,13 @@
 {
         rtp_assoc_t *cur, *sentinel;
 
+
+	if (log_fp != 0)
+	{
+	    fclose(log_fp);
+	    log_fp = 0;
+	}
+
         sentinel = &rtp_as;
         cur = sentinel->next;
         while(cur != sentinel) {
@@ -282,6 +313,17 @@
                 /* for us to deal with.                                      */
                 break;
         case RTCP_SDES_CNAME:
+	    if (log_fp != 0)
+	    {
+		struct timeval  tv;
+		gettimeofday(&tv, 0);
+
+		fprintf(log_fp, "%d.%06d %d cname %x %s\n", (int) tv.tv_sec, (int) tv.tv_usec,
+			(int) rtp_get_ssrc_count(sp->rtp_session[0]),
+			(int) ssrc,
+			rtp_get_sdes(sp->rtp_session[0], ssrc, RTCP_SDES_CNAME));
+		fflush(log_fp);
+	    }
                 ui_send_rtp_cname(sp, sp->mbus_ui_addr, ssrc);
                 break;
         case RTCP_SDES_NAME:
@@ -311,8 +353,41 @@
 }
 
 static void
+process_app(session_t *sp, uint32_t ssrc, rtcp_app *app)
+{
+  if (strncmp(app->name, "site", 4) == 0) {
+    int site_id_len = 4*(app->length - 2);
+    pdb_entry_t *e;
+
+    if (pdb_item_get(sp->pdb, ssrc, &e) == FALSE) {
+      debug_msg("process_app: unknown source (0x%08x).\n", ssrc);
+      return;
+    } else {
+      if (e->siteid == NULL) {
+	e->siteid = xmalloc(site_id_len + 1);
+	strncpy(e->siteid, app->data, site_id_len);
+	e->siteid[site_id_len] = '\0';
+      }
+	
+      ui_send_rtp_app_site(sp, sp->mbus_ui_addr, ssrc, e->siteid);
+    }
+  }
+}
+
+static void
 process_create(session_t *sp, uint32_t ssrc)
 {
+	    if (log_fp != 0)
+	    {
+		struct timeval  tv;
+		gettimeofday(&tv, 0);
+
+		fprintf(log_fp, "%d.%06d %d create %x \n", (int) tv.tv_sec, (int) tv.tv_usec,
+			(int) rtp_get_ssrc_count(sp->rtp_session[0]),
+			(int) ssrc);
+		fflush(log_fp);
+	    }
+    
 	if (pdb_item_create(sp->pdb, (uint16_t)ts_get_freq(sp->cur_ts), ssrc) == FALSE) {
 		debug_msg("Unable to create source 0x%08lx\n", ssrc);
 	}
@@ -321,6 +396,25 @@
 static void
 process_delete(session_t *sp, rtp_event *e)
 {
+	    if (log_fp != 0)
+	    {
+		struct timeval  tv, *dead;
+		int d_sec = -1, d_usec = -1;
+
+		gettimeofday(&tv, 0);
+
+		dead = (struct timeval *) e->data;
+		if (dead != 0)
+		{
+		    d_sec = (int) dead->tv_sec;
+		    d_usec = (int) dead->tv_usec;
+		}
+		fprintf(log_fp, "%d.%06d %d delete %x %d.%06d\n", (int) tv.tv_sec, (int) tv.tv_usec,
+			rtp_get_ssrc_count(sp->rtp_session[0]),
+			e->ssrc,
+			d_sec, d_usec);
+		fflush(log_fp);
+	    }
         if (e->ssrc != rtp_my_ssrc(sp->rtp_session[0]) && sp->mbus_engine != NULL) {
                 struct s_source *s;
                 pdb_entry_t     *pdbe;
@@ -383,6 +477,8 @@
 		break;
         case RX_APP:
                 debug_msg("Received and ignored application specific report from %08x\n", e->ssrc);
+	        process_app(sp, e->ssrc, (rtcp_app*)e->data);
+		xfree(e->data);
                 break;
 	case RX_BYE:
 	case SOURCE_DELETED:
@@ -405,3 +501,63 @@
 	}
 }
 
+rtcp_app* rtcp_app_site_callback(struct rtp *session, 
+				 uint32_t rtp_ts, 
+				 int max_size)
+{
+        struct s_session *sp;
+	int len;
+	int datalen;
+	int slen;
+
+	sp = get_session(session);
+	if (sp == NULL) {
+	        /* Shouldn't happen */
+   	        return NULL;
+        }
+
+	if (sp->rtp_session_app_site == NULL) {
+	        /* Site identifier not set */
+	        return NULL;
+	}
+
+	if (sp->rtcp_app_packet_ts == rtp_ts) {
+	        /* Already sent an APP for this timestamp */
+	        return NULL;
+	}
+
+	slen = strlen(sp->rtp_session_app_site);
+	datalen = slen;
+	if (slen % 4 > 0) {
+	        datalen += 4 - (slen % 4);
+        }
+        len = datalen + sizeof(rtcp_app) - 1;
+	if (len > max_size) {
+	        /* Can't fit the site id in the current RTCP compound packet */
+	        return NULL;
+	}
+
+        if (sp->rtcp_app_packet != NULL) {
+	  xfree(sp->rtcp_app_packet);
+        }
+
+	sp->rtcp_app_packet = xmalloc(len);
+
+	sp->rtcp_app_packet->version = RTP_VERSION;
+	sp->rtcp_app_packet->p = 0;
+	sp->rtcp_app_packet->subtype = 0;
+	sp->rtcp_app_packet->pt = 204;
+
+	/* Host -> Network order is handled by common lib */
+	sp->rtcp_app_packet->length = 2 + datalen/4;
+	sp->rtcp_app_packet->ssrc = rtp_my_ssrc(session);
+
+	strncpy(sp->rtcp_app_packet->name, "site", 4);
+	memset(sp->rtcp_app_packet->data, 0, datalen);
+	strncpy(sp->rtcp_app_packet->data, sp->rtp_session_app_site, slen);
+
+	sp->rtcp_app_packet_ts = rtp_ts;
+	return sp->rtcp_app_packet;
+}
+
+

Modified: rat/trunk/rtp_callback.h
==============================================================================
--- rat/trunk/rtp_callback.h	(original)
+++ rat/trunk/rtp_callback.h	Fri Mar  2 19:18:26 2007
@@ -18,4 +18,9 @@
 void rtp_callback_proc (struct rtp *s, rtp_event *e);
 void rtp_callback_exit (struct rtp *s);
 
+
+rtcp_app* rtcp_app_site_callback(struct rtp *session,
+				 uint32_t rtp_ts,
+				 int max_size);
+
 #endif /* __RTP_CALLBACK_H__ */

Modified: rat/trunk/session.h
==============================================================================
--- rat/trunk/session.h	(original)
+++ rat/trunk/session.h	Fri Mar  2 19:18:26 2007
@@ -18,6 +18,8 @@
 #include "converter_types.h"
 #include "repair_types.h"
 
+#include "rtp.h"
+
 /* This will have to be raised in the future */
 #define MAX_LAYERS      2
 
@@ -62,6 +64,9 @@
 	int             	 ttl;
         struct rtp     		*rtp_session[MAX_LAYERS];
         int             	 rtp_session_count;
+        char                    *rtp_session_app_site;
+        rtcp_app                *rtcp_app_packet;
+        uint32_t                 rtcp_app_packet_ts;
 	uint8_t          	 layers; 			/* number of layers == rtp_session_count */
         int             	 filter_loopback;
         timestamp_t              cur_ts; 			/* current device time */

Modified: rat/trunk/ui_audiotool.tcl
==============================================================================
--- rat/trunk/ui_audiotool.tcl	(original)
+++ rat/trunk/ui_audiotool.tcl	Fri Mar  2 19:18:26 2007
@@ -321,6 +321,7 @@
 		rtp.source.mute			{eval mbus_recv_rtp.source.mute $args}
 		rtp.source.gain			{eval mbus_recv_rtp.source.gain $args}
 		rtp.source.rtt			{eval mbus_recv_rtp.source.rtt $args}
+		rtp.source.app.site     {eval mbus_recv_rtp.source.app.site $args}
 		security.encryption.key 	{eval mbus_recv_security.encryption.key $args}
 		default				{bgerror "Unknown mbus command $cmnd"}
 	}
@@ -1092,6 +1093,9 @@
 	}
 }
 
+proc mbus_recv_rtp.source.app.site {ssrc val} {
+}
+
 proc mbus_recv_audio.file.play.ready {name} {
     global play_file
     set    play_file(name) $name
@@ -1239,6 +1243,8 @@
 		$cw create text [expr $f + 2] $h -anchor w -text $NAME($ssrc) -fill black -tag t
 		$cw create polygon $l $h $h $l $h $f -outline black -fill grey -tag m
 		$cw create polygon $f $h $h $l $h $f -outline black -fill grey -tag h
+	        scale ${cw}.gain_scale_$ssrc -showvalue 0 -orient h -from -3 -to +3 -resolution 0.25 -command "ssrc_set_gain $ssrc"
+	        $cw create window [expr $iwd + 1] $h -anchor e -window $cw.gain_scale_$ssrc 
 
 		bind $cw <Button-1>         "toggle_stats \"$ssrc\""
 		bind $cw <Button-2>         "toggle_mute $cw \"$ssrc\""
@@ -1641,7 +1647,6 @@
 pack .st -side bottom -fill x -padx 2 -pady 0
 pack .st.file .st.recp .st.help -side left -anchor e -padx 2 -pady 2
 
-
 pack .st.quit .st.about .st.opts -side right -anchor w -padx 2 -pady 2
 
 pack .r -side top -fill x -padx 2

Modified: rat/trunk/ui_send_rtp.c
==============================================================================
--- rat/trunk/ui_send_rtp.c	(original)
+++ rat/trunk/ui_send_rtp.c	Fri Mar  2 19:18:26 2007
@@ -188,3 +188,11 @@
         xfree(title);
 }
 
+void ui_send_rtp_app_site(session_t *sp, char *addr, uint32_t ssrc, char *siteid)
+{
+        char *enc_siteid;
+	if (!sp->ui_on) return;
+	enc_siteid = mbus_encode_str(siteid);
+	mbus_qmsgf(sp->mbus_engine, addr, TRUE, "rtp.source.app.site", "\"%08lx\" %s", ssrc, enc_siteid);
+	xfree(enc_siteid);
+}

Modified: rat/trunk/ui_send_rtp.h
==============================================================================
--- rat/trunk/ui_send_rtp.h	(original)
+++ rat/trunk/ui_send_rtp.h	Fri Mar  2 19:18:26 2007
@@ -27,4 +27,4 @@
 void ui_send_rtp_ssrc       (session_t *sp, char *addr);
 void ui_send_rtp_addr       (session_t *sp, char *addr);
 void ui_send_rtp_title      (session_t *sp, char *addr);
-
+void ui_send_rtp_app_site   (session_t *sp, char *addr, uint32_t ssrc, char *siteid);



More information about the Sumover-dev mailing list