[asterisk-commits] jpeeler: branch jpeeler/bug13173 r154876 - /team/jpeeler/bug13173/apps/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 5 15:14:56 CST 2008


Author: jpeeler
Date: Wed Nov  5 15:14:56 2008
New Revision: 154876

URL: http://svn.digium.com/view/asterisk?view=rev&rev=154876
Log:
Fix multiple issues suggested by Russell via reviewboard. Adds ability (via sleep, need to find a better way) for new conference participant to not hear their own join announcement matching the previous behavior.

Modified:
    team/jpeeler/bug13173/apps/app_meetme.c

Modified: team/jpeeler/bug13173/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/bug13173/apps/app_meetme.c?view=diff&rev=154876&r1=154875&r2=154876
==============================================================================
--- team/jpeeler/bug13173/apps/app_meetme.c (original)
+++ team/jpeeler/bug13173/apps/app_meetme.c Wed Nov  5 15:14:56 2008
@@ -322,9 +322,10 @@
 };
 
 struct announce_listitem {
-	AST_LIST_ENTRY(announce_listitem) list;
+	AST_LIST_ENTRY(announce_listitem) entry;
 	char namerecloc[PATH_MAX];				/*!< Name Recorded file Location */
 	char language[MAX_LANGUAGE];
+	char channame[AST_CHANNEL_NAME];
 	struct ast_channel *confchan;
 	int confusers;
 	enum announcetypes announcetype;
@@ -350,6 +351,7 @@
 	ast_mutex_t recordthreadlock;		/*!< control threads trying to start recordthread */
 	pthread_t announcethread;
 	ast_mutex_t announcethreadlock;
+	int announcethread_stop:1;
 	pthread_attr_t attr;                    /*!< thread attribute */
 	const char *recordingfilename;          /*!< Filename to record the Conference into */
 	const char *recordingformat;            /*!< Format to record the Conference in */
@@ -782,6 +784,7 @@
 	ast_mutex_init(&cnf->recordthreadlock);
 	cnf->announcethread = AST_PTHREADT_NULL;
 	ast_mutex_init(&cnf->announcethreadlock);
+	AST_LIST_HEAD_INIT(&cnf->announcelist);
 	ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
 	ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
 	ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
@@ -1276,12 +1279,17 @@
 			ast_translator_free_path(conf->transpath[x]);
 	}
 	if (conf->announcethread != AST_PTHREADT_NULL) {
+		AST_LIST_LOCK(&conf->announcelist);
+		conf->announcethread_stop = 1;
 		ast_softhangup(conf->chan, AST_SOFTHANGUP_EXPLICIT);
-		pthread_cancel(conf->announcethread);
+		ast_cond_signal(&conf->announcelist_addition);
+		AST_LIST_UNLOCK(&conf->announcelist);
+		//pthread_cancel(conf->announcethread);
 		pthread_join(conf->announcethread, NULL);
-		while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, list))) {
-			free(item);
-		}
+		while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
+			ast_free(item);
+		}
+		AST_LIST_HEAD_DESTROY(&conf->announcelist);
 	}
 	if (conf->origframe)
 		ast_frfree(conf->origframe);
@@ -1401,16 +1409,45 @@
 	return res;
 }
 
-static void get_announce_filename(char *filename, enum announcetypes type)
+static const char *get_announce_filename(enum announcetypes type)
 {
 	switch (type) {
 	case CONF_HASLEFT:
-		ast_copy_string(filename, "conf-hasleft", 40);
-	break;
+		return "conf-hasleft";
+		break;
 	case CONF_HASJOIN:
-		ast_copy_string(filename, "conf-hasjoin", 40);
-	break;
-	}
+		return "conf-hasjoin";
+		break;
+	default:
+		return "";
+	}
+}
+
+/* jpeeler: I think using this function warrants use of ast_obj2 */
+static int announcement_played(struct ast_conference *conf, struct ast_channel *chan)
+{
+	struct announce_listitem *item;
+	AST_LIST_LOCK(&conf->announcelist);
+	if (AST_LIST_EMPTY(&conf->announcelist)) {
+		AST_LIST_UNLOCK(&conf->announcelist);
+	ast_log(LOG_NOTICE, "jpeeler: list was empty\n");
+		return 0;
+	}
+
+	item = AST_LIST_FIRST(&conf->announcelist);
+	while (item) {
+	ast_log(LOG_NOTICE, "jpeeler: checking for match in %s\n", item->channame);
+		if (!strcmp(item->channame, chan->name)) {
+			AST_LIST_UNLOCK(&conf->announcelist);
+	ast_log(LOG_NOTICE, "jpeeler: announcement not played yet\n");
+			return 1;
+		}
+		item = AST_LIST_NEXT(item, entry);
+	}
+
+	ast_log(LOG_NOTICE, "jpeeler: announcement not found\n");
+	AST_LIST_UNLOCK(&conf->announcelist);
+	return 0;
 }
 
 static void *announce_thread(void *data)
@@ -1420,31 +1457,42 @@
 	int res;
 	char filename[40] = ""; /* jpeeler: don't know what amount should put here */
 
-	for (;;) {
+	while (!conf->announcethread_stop) {
 		AST_LIST_LOCK(&conf->announcelist);
+		if (conf->announcethread_stop) {
+			AST_LIST_UNLOCK(&conf->announcelist);
+			return NULL;
+		}
 		if (AST_LIST_EMPTY(&conf->announcelist))
 			ast_cond_wait(&conf->announcelist_addition, &conf->announcelist.lock);
 		next = AST_LIST_FIRST(&conf->announcelist);
 		AST_LIST_UNLOCK(&conf->announcelist);
+		if (conf->announcethread_stop)
+			return NULL;
 
 		while ((current = next)) {
-			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); 
+			ast_log(LOG_DEBUG, "About to play %s on behalf of %s\n", current->namerecloc, current->channame);
 			if (ast_fileexists(current->namerecloc, NULL, NULL)) {
 				if ((current->confchan) && (current->confusers > 1) && !ast_check_hangup(current->confchan)) {
 					if (!ast_streamfile(current->confchan, current->namerecloc, current->language))
 						res = ast_waitstream(current->confchan, "");
 					if (!res) {
-						get_announce_filename(filename, current->announcetype);
+						ast_copy_string(filename, get_announce_filename(current->announcetype), sizeof(filename));
 						if (!ast_streamfile(current->confchan, filename, current->language))
 							ast_waitstream(current->confchan, "");
 					}
 				}
 				ast_filedelete(current->namerecloc, NULL);
 			}
-			next = AST_LIST_NEXT(current, list);
-			AST_LIST_REMOVE_HEAD(&conf->announcelist, list);
+			next = AST_LIST_NEXT(current, entry);
+			AST_LIST_LOCK(&conf->announcelist);
+			if (conf->announcethread_stop) {
+				AST_LIST_UNLOCK(&conf->announcelist);
+				return NULL;
+			}
+			AST_LIST_REMOVE_HEAD(&conf->announcelist, entry);
 			free(current);
-			pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+			AST_LIST_UNLOCK(&conf->announcelist);
 		}
 	}
 
@@ -1548,7 +1596,7 @@
 		//pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
 		//ast_pthread_create_background(&conf->announcethread, &conf->attr, announce_thread, conf);
 		//pthread_attr_destroy(&conf->attr);
-		ast_pthread_create(&conf->announcethread, NULL, announce_thread, conf);
+		ast_pthread_create_background(&conf->announcethread, NULL, announce_thread, conf);
 	}
 	ast_mutex_unlock(&conf->announcethreadlock);
 
@@ -1762,11 +1810,12 @@
 		struct announce_listitem *item = ast_calloc(1, sizeof(*item));
 		ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
 		ast_copy_string(item->language, chan->language, sizeof(item->language));
+		ast_copy_string(item->channame, chan->name, sizeof(item->channame));
 		item->confchan = conf->chan;
 		item->confusers = conf->users;
 		item->announcetype = CONF_HASJOIN;
 		AST_LIST_LOCK(&conf->announcelist);
-		AST_LIST_INSERT_TAIL(&conf->announcelist, item, list);
+		AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
 		ast_cond_signal(&conf->announcelist_addition);
 		AST_LIST_UNLOCK(&conf->announcelist);
 	}
@@ -1780,7 +1829,10 @@
 	else 
 		ztc.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
 
-	//while (!ast_check_hangup(chan) && !ast_check_hangup(conf->chan) && 
+	while (!ast_check_hangup(chan) && !ast_check_hangup(conf->chan) && announcement_played(conf, chan)) {
+		ast_log(LOG_NOTICE, "jpeeler: waiting for announcement to finish for %s...\n", chan->name);
+		ast_safe_sleep(chan, 1000);
+	}
 	if (ioctl(fd, DAHDI_SETCONF, &ztc)) {
 		ast_log(LOG_WARNING, "Error setting conference\n");
 		close(fd);
@@ -2362,11 +2414,12 @@
 		struct announce_listitem *item = ast_calloc(1, sizeof(*item));
 		ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
 		ast_copy_string(item->language, chan->language, sizeof(item->language));
+		ast_copy_string(item->channame, chan->name, sizeof(item->channame));
 		item->confchan = conf->chan;
 		item->confusers = conf->users;
 		item->announcetype = CONF_HASLEFT;
 		AST_LIST_LOCK(&conf->announcelist);
-		AST_LIST_INSERT_TAIL(&conf->announcelist, item, list);
+		AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
 		ast_cond_signal(&conf->announcelist_addition);
 		AST_LIST_UNLOCK(&conf->announcelist);
 	}




More information about the asterisk-commits mailing list