Module: sems
Branch: sayer/dsm DELETED
Commit: faed74155b70196d9718d53e450da0294660eaf6
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=faed74155b70196d9718d53e450da0294660eaf6

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Tue Jun 22 23:52:22 2010 +0200

dsm mod_conference: MixIn for mixing in files

---

 apps/dsm/mods/mod_conference/ModConference.cpp     |   73 ++++++++++++++++++++
 apps/dsm/mods/mod_conference/ModConference.h       |   19 +++++
 .../mods/mod_conference/Readme.mod_conference.txt  |   16 ++++
 3 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/apps/dsm/mods/mod_conference/ModConference.cpp 
b/apps/dsm/mods/mod_conference/ModConference.cpp
index ebaacca..d341d1d 100644
--- a/apps/dsm/mods/mod_conference/ModConference.cpp
+++ b/apps/dsm/mods/mod_conference/ModConference.cpp
@@ -30,10 +30,12 @@
 #include "AmPlaylist.h"
 #include "AmConferenceChannel.h"
 #include "AmRtpAudio.h"
+#include "AmAudioMixIn.h"
 
 #include "DSMSession.h"
 #include "ModConference.h"
 
+
 SC_EXPORT(MOD_CLS_NAME);
 
 MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
@@ -46,6 +48,9 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
   DEF_CMD("conference.teejoin", ConfTeeJoinAction);
   DEF_CMD("conference.teeleave", ConfTeeLeaveAction);
 
+  DEF_CMD("conference.setupMixIn", ConfSetupMixInAction);
+  DEF_CMD("conference.playMixIn", ConfPlayMixInAction);
+
 } MOD_ACTIONEXPORT_END;
 
 MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
@@ -326,3 +331,71 @@ EXEC_ACTION_START(ConfTeeLeaveAction) {
 
   sc_sess->CLR_ERRNO;
 } EXEC_ACTION_END;
+
+CONST_ACTION_2P(ConfSetupMixInAction, ',', true);
+EXEC_ACTION_START(ConfSetupMixInAction) {
+  string level = resolveVars(par1, sess, sc_sess, event_params);
+  string seconds = resolveVars(par2, sess, sc_sess, event_params);
+
+  unsigned int s; double l; int flags = 0;
+
+  l = atof(level.c_str());
+  if (seconds.empty()) {
+    s = 0;
+  } else {
+    if (str2i(seconds, s)) {
+      throw DSMException("conference", 
+                        "cause", "could not interpret seconds value");
+    }
+  }
+  if (s == 0) {
+    flags = AUDIO_MIXIN_IMMEDIATE_START | AUDIO_MIXIN_ONCE;
+  }
+
+  AmAudio* output = sess->getOutput();
+  AmAudioMixIn* m = new AmAudioMixIn(output, NULL, s, l, flags);
+  sess->setOutput(m);
+  
+  DSMDisposableT<AmAudioMixIn >* m_obj = 
+    getDSMConfChannel<DSMDisposableT<AmAudioMixIn > >(sc_sess, 
CONF_AKEY_MIXER);
+  if (NULL != m_obj) {
+    DBG("releasing old MixIn (hope script write setInOutPlaylist before)\n");
+    m_obj->reset(m);
+  } else {
+    DBG("creating new mixer container\n");
+    m_obj = new DSMDisposableT<AmAudioMixIn >(m);
+    AmArg c_arg;
+    c_arg.setBorrowedPointer(m_obj);
+    sc_sess->avar[CONF_AKEY_MIXER] = c_arg;
+      
+    // add to garbage collector
+    sc_sess->transferOwnership(m_obj);
+  }
+} EXEC_ACTION_END;
+
+EXEC_ACTION_START(ConfPlayMixInAction) {
+  string filename = resolveVars(arg, sess, sc_sess, event_params);
+
+  DSMDisposableT<AmAudioMixIn >* m_obj = 
+    getDSMConfChannel<DSMDisposableT<AmAudioMixIn > >(sc_sess, 
CONF_AKEY_MIXER);
+  if (NULL == m_obj) {
+    throw DSMException("conference", "cause", "mixer not setup!\n");
+  } 
+
+  AmAudioMixIn* m = m_obj->get();
+
+  DSMDisposableAudioFile* af = new DSMDisposableAudioFile();
+  if(af->open(filename,AmAudioFile::Read)) {
+    ERROR("audio file '%s' could not be opened for reading.\n", 
+         filename.c_str());
+    delete af;
+    
+    throw DSMException("file", "path", filename);
+  }
+
+  sc_sess->transferOwnership(af);
+
+  DBG("starting mixin of file '%s'\n", filename.c_str());
+  m->mixin(af);
+
+} EXEC_ACTION_END;
diff --git a/apps/dsm/mods/mod_conference/ModConference.h 
b/apps/dsm/mods/mod_conference/ModConference.h
index 877b0d8..4f86905 100644
--- a/apps/dsm/mods/mod_conference/ModConference.h
+++ b/apps/dsm/mods/mod_conference/ModConference.h
@@ -38,6 +38,7 @@ DECLARE_MODULE(MOD_CLS_NAME);
 
 #define CONF_AKEY_CHANNEL        "conf.chan" 
 #define CONF_AKEY_DEF_TEECHANNEL "conf.teechan" 
+#define CONF_AKEY_MIXER          "conf.mixer" 
 
 /** holds a conference channel  */
 class DSMConfChannel 
@@ -68,6 +69,20 @@ class DSMTeeConfChannel
   AmAudio* setupAudio(AmAudio* out);
 };
 
+template<class T> class DSMDisposableT
+: public DSMDisposable,
+  public ArgObject {
+  std::auto_ptr<T> pobj;
+
+ public:
+ DSMDisposableT(T* _pobj) : pobj(_pobj) { }
+  ~DSMDisposableT() { }
+  void release() { pobj.reset(NULL); }
+  void reset(T* _pobj) { pobj.reset(_pobj); }
+
+  T* get() { return pobj.get(); }
+};
+
 DEF_ACTION_2P(ConfJoinAction);
 DEF_ACTION_1P(ConfLeaveAction);
 DEF_ACTION_2P(ConfRejoinAction); 
@@ -76,4 +91,8 @@ DEF_ACTION_1P(ConfSetPlayoutTypeAction);
 
 DEF_ACTION_2P(ConfTeeJoinAction);
 DEF_ACTION_1P(ConfTeeLeaveAction);
+
+DEF_ACTION_2P(ConfSetupMixInAction);
+DEF_ACTION_1P(ConfPlayMixInAction);
+
 #endif
diff --git a/apps/dsm/mods/mod_conference/Readme.mod_conference.txt 
b/apps/dsm/mods/mod_conference/Readme.mod_conference.txt
index cf3f7c0..7a40601 100644
--- a/apps/dsm/mods/mod_conference/Readme.mod_conference.txt
+++ b/apps/dsm/mods/mod_conference/Readme.mod_conference.txt
@@ -29,3 +29,19 @@ conference.teejoin(string roomname [, string avar_id])
 conference.teeleave([string avar_id])
    - leave tee conference (release conf channel)
    - resets playlist as input and output
+
+conference.setupMixIn(float level, unsigned int seconds)
+   - set up MixIn for mixing in files into output later
+    notes: 
+      o only do that when playlist is input/output 
+          (possibly do setInOutPlaylist first)
+      o in sessionStart event, set $connect_session=0, otherwise
+        playlist will be set as output again, and MixIn does not 
+        play, e.g.
+          set($connect_session=0);
+          setInOutPlaylist();
+          conference.setupMixIn(0.5);
+
+     o if you use setupMixIn multiple times, use setInOutPlaylist first!!!!!
+       otherwise it could crash if old MixIn is still in the output / 
+       the audio queue

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to