diff --git a/apps/examples/dtmftester/DtmfTester.cpp b/apps/examples/dtmftester/DtmfTester.cpp new file mode 100644 index 00000000..15270c99 --- /dev/null +++ b/apps/examples/dtmftester/DtmfTester.cpp @@ -0,0 +1,206 @@ +/* + * $Id: DtmfTester.cpp 410 2007-07-29 15:14:14Z sayer $ + * + * Copyright (C) 2002-2003 Fhg Fokus + * + * This file is part of sems, a free SIP media server. + * + * sems 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. + * + * For a license to use the sems software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * info@iptel.org + * + * sems 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 + */ + +#include "DtmfTester.h" +#include "AmConfig.h" +#include "AmUtils.h" +#include "AmPlugIn.h" + +#include "sems.h" +#include "log.h" + +#define MOD_NAME "dtmftester" + +EXPORT_SESSION_FACTORY(DtmfTesterFactory,MOD_NAME); + +string DtmfTesterFactory::AnnouncePath; +string DtmfTesterFactory::AnnounceFile; + +DtmfTesterFactory::DtmfTesterFactory(const string& _app_name) + : AmSessionFactory(_app_name) +{ +} + +int DtmfTesterFactory::onLoad() +{ + AmConfigReader cfg; + if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) + return -1; + + // get application specific global parameters + configureModule(cfg); + + AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); + if( !AnnouncePath.empty() + && AnnouncePath[AnnouncePath.length()-1] != '/' ) + AnnouncePath += "/"; + + AnnounceFile = cfg.getParameter("default_announce",ANNOUNCE_FILE); + + string announce_file = AnnouncePath + AnnounceFile; + if(!file_exists(announce_file)){ + ERROR("default file for announcement module does not exist ('%s').\n", + announce_file.c_str()); + return -1; + } + + return 0; +} + +string DtmfTesterFactory::getAnnounceFile(const AmSipRequest& req) { + string announce_path = AnnouncePath; + string announce_file = announce_path + req.domain + + "/" + req.user + ".wav"; + + DBG("trying '%s'\n",announce_file.c_str()); + if(file_exists(announce_file)) + goto end; + + announce_file = announce_path + req.user + ".wav"; + DBG("trying '%s'\n",announce_file.c_str()); + if(file_exists(announce_file)) + goto end; + + announce_file = AnnouncePath + AnnounceFile; + + end: + return announce_file; +} + +AmSession* DtmfTesterFactory::onInvite(const AmSipRequest& req) +{ + return new DtmfTesterDialog(getAnnounceFile(req), NULL); +} + +AmSession* DtmfTesterFactory::onInvite(const AmSipRequest& req, + AmArg& session_params) +{ + UACAuthCred* cred = NULL; + if (session_params.getType() == AmArg::AObject) { + ArgObject* cred_obj = session_params.asObject(); + if (cred_obj) + cred = dynamic_cast(cred_obj); + } + + AmSession* s = new DtmfTesterDialog(getAnnounceFile(req), cred); + + if (NULL == cred) { + WARN("discarding unknown session parameters.\n"); + } else { + AmSessionEventHandlerFactory* uac_auth_f = + AmPlugIn::instance()->getFactory4Seh("uac_auth"); + if (uac_auth_f != NULL) { + DBG("UAC Auth enabled for new announcement session.\n"); + AmSessionEventHandler* h = uac_auth_f->getHandler(s); + if (h != NULL ) + s->addHandler(h); + } else { + ERROR("uac_auth interface not accessible. " + "Load uac_auth for authenticated dialout.\n"); + } + } + + return s; +} + +DtmfTesterDialog::DtmfTesterDialog(const string& filename, + UACAuthCred* credentials) + : filename(filename), cred(credentials), play_list(this) +{ + // try out this inband detector + setInbandDetector(Dtmf::SpanDSP); +} + +DtmfTesterDialog::~DtmfTesterDialog() +{ + for (vector::iterator it=del_files.begin(); + it != del_files.end(); it++) + delete *it; + +} + +void DtmfTesterDialog::onSessionStart(const AmSipRequest& req) +{ + DBG("DtmfTesterDialog::onSessionStart\n"); + startSession(); +} + +void DtmfTesterDialog::onSessionStart(const AmSipReply& rep) +{ + DBG("DtmfTesterDialog::onSessionStart (SEMS originator mode)\n"); + startSession(); +} + +void DtmfTesterDialog::startSession(){ + + if(wav_file.open(filename,AmAudioFile::Read)) + throw string("DtmfTesterDialog::onSessionStart: Cannot open file\n"); + + string rec_fname = "/tmp/dtmftest_"+getLocalTag()+".wav"; + if(rec_file.open(rec_fname,AmAudioFile::Write)) + throw string("DtmfTesterDialog::onSessionStart: Cannot open rec_file\n"); + + play_list.addToPlaylist(new AmPlaylistItem(&wav_file, NULL)); + setInOut(&rec_file, &play_list); +} + +void DtmfTesterDialog::onBye(const AmSipRequest& req) +{ + DBG("onBye: stopSession\n"); + setStopped(); +} + + +void DtmfTesterDialog::process(AmEvent* event) +{ + + AmAudioEvent* audio_event = dynamic_cast(event); + if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){ + dlg.bye(); + setStopped(); + return; + } + + AmSession::process(event); +} + +inline UACAuthCred* DtmfTesterDialog::getCredentials() { + return cred.get(); +} + +void DtmfTesterDialog::onDtmf(int event, int duration) { + AmAudioFile* f = new AmAudioFile(); + if(f->open(DtmfTesterFactory::AnnouncePath+"/"+int2str(event)+".wav", + AmAudioFile::Read)) { + ERROR("Cannot open file %s\n", + (DtmfTesterFactory::AnnouncePath+"/"+int2str(event)+".wav").c_str()); + } + + del_files.push_back(f); + play_list.addToPlaylist(new AmPlaylistItem(f, NULL)); +} + diff --git a/apps/examples/dtmftester/DtmfTester.h b/apps/examples/dtmftester/DtmfTester.h new file mode 100644 index 00000000..86254211 --- /dev/null +++ b/apps/examples/dtmftester/DtmfTester.h @@ -0,0 +1,93 @@ +/* + * $Id: DtmfTester.h 457 2007-09-24 17:37:04Z sayer $ + * + * Copyright (C) 2002-2003 Fhg Fokus + * + * This file is part of sems, a free SIP media server. + * + * sems 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. + * + * For a license to use the sems software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * info@iptel.org + * + * sems 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 + */ + +#ifndef _ANNOUNCEMENT_H_ +#define _ANNOUNCEMENT_H_ + +#include "AmSession.h" +#include "AmConfigReader.h" +#include "AmPlaylist.h" + +#include "ampi/UACAuthAPI.h" + +#include +using std::string; + +#include + +/** \brief Factory for announcement sessions */ +class DtmfTesterFactory: public AmSessionFactory +{ + inline string getAnnounceFile(const AmSipRequest& req); +public: + static string AnnouncePath; + static string AnnounceFile; + + DtmfTesterFactory(const string& _app_name); + + int onLoad(); + AmSession* onInvite(const AmSipRequest& req); + AmSession* onInvite(const AmSipRequest& req, + AmArg& session_params); + +}; + +/**\brief announcement session logic implementation */ +class DtmfTesterDialog : public AmSession, + public CredentialHolder +{ + AmAudioFile wav_file; + AmAudioFile rec_file; + string filename; + + AmPlaylist play_list; + + std::auto_ptr cred; + + vector del_files; + +public: + DtmfTesterDialog(const string& filename, + UACAuthCred* credentials = NULL); + ~DtmfTesterDialog(); + + void onSessionStart(const AmSipRequest& req); + void onSessionStart(const AmSipReply& rep); + void startSession(); + void onBye(const AmSipRequest& req); + void onDtmf(int event, int duration_msec); + + void process(AmEvent* event); + + UACAuthCred* getCredentials(); +}; + +#endif +// Local Variables: +// mode:C++ +// End: + diff --git a/apps/examples/dtmftester/Makefile b/apps/examples/dtmftester/Makefile new file mode 100644 index 00000000..052bd6c1 --- /dev/null +++ b/apps/examples/dtmftester/Makefile @@ -0,0 +1,9 @@ +plug_in_name = dtmftester + +module_ldflags = +module_cflags = + +extra_install = $(plug_in_name)_audio + +COREPATH ?=../../../core +include $(COREPATH)/plug-in/Makefile.app_module diff --git a/apps/examples/dtmftester/Readme.dtmftester b/apps/examples/dtmftester/Readme.dtmftester new file mode 100644 index 00000000..dc607c5a --- /dev/null +++ b/apps/examples/dtmftester/Readme.dtmftester @@ -0,0 +1,8 @@ +dtmf detection tester + +this app records the file to /tmp/dtmftest_.wav, and +plays all detected digits in a playlist. + +this comes in handy to tune/check the dtmf detection. + + \ No newline at end of file diff --git a/apps/examples/dtmftester/etc/dtmf_tester.conf b/apps/examples/dtmftester/etc/dtmf_tester.conf new file mode 100644 index 00000000..e0bfec5a --- /dev/null +++ b/apps/examples/dtmftester/etc/dtmf_tester.conf @@ -0,0 +1,2 @@ +announce_path=../apps/examples/dtmftester/wav/ +default_announce=prompt.wav diff --git a/apps/examples/dtmftester/wav/0.wav b/apps/examples/dtmftester/wav/0.wav new file mode 100644 index 00000000..d0a85f70 Binary files /dev/null and b/apps/examples/dtmftester/wav/0.wav differ diff --git a/apps/examples/dtmftester/wav/1.wav b/apps/examples/dtmftester/wav/1.wav new file mode 100644 index 00000000..7e70a73a Binary files /dev/null and b/apps/examples/dtmftester/wav/1.wav differ diff --git a/apps/examples/dtmftester/wav/10.wav b/apps/examples/dtmftester/wav/10.wav new file mode 100644 index 00000000..67ef45b5 Binary files /dev/null and b/apps/examples/dtmftester/wav/10.wav differ diff --git a/apps/examples/dtmftester/wav/11.wav b/apps/examples/dtmftester/wav/11.wav new file mode 100644 index 00000000..ae835ed5 Binary files /dev/null and b/apps/examples/dtmftester/wav/11.wav differ diff --git a/apps/examples/dtmftester/wav/12.wav b/apps/examples/dtmftester/wav/12.wav new file mode 100644 index 00000000..10806591 Binary files /dev/null and b/apps/examples/dtmftester/wav/12.wav differ diff --git a/apps/examples/dtmftester/wav/13.wav b/apps/examples/dtmftester/wav/13.wav new file mode 100644 index 00000000..09e3c23a Binary files /dev/null and b/apps/examples/dtmftester/wav/13.wav differ diff --git a/apps/examples/dtmftester/wav/14.wav b/apps/examples/dtmftester/wav/14.wav new file mode 100644 index 00000000..7c6b289d Binary files /dev/null and b/apps/examples/dtmftester/wav/14.wav differ diff --git a/apps/examples/dtmftester/wav/15.wav b/apps/examples/dtmftester/wav/15.wav new file mode 100644 index 00000000..09574c41 Binary files /dev/null and b/apps/examples/dtmftester/wav/15.wav differ diff --git a/apps/examples/dtmftester/wav/2.wav b/apps/examples/dtmftester/wav/2.wav new file mode 100644 index 00000000..5747e5df Binary files /dev/null and b/apps/examples/dtmftester/wav/2.wav differ diff --git a/apps/examples/dtmftester/wav/3.wav b/apps/examples/dtmftester/wav/3.wav new file mode 100644 index 00000000..52cbe1e4 Binary files /dev/null and b/apps/examples/dtmftester/wav/3.wav differ diff --git a/apps/examples/dtmftester/wav/4.wav b/apps/examples/dtmftester/wav/4.wav new file mode 100644 index 00000000..63a2e3a0 Binary files /dev/null and b/apps/examples/dtmftester/wav/4.wav differ diff --git a/apps/examples/dtmftester/wav/5.wav b/apps/examples/dtmftester/wav/5.wav new file mode 100644 index 00000000..0d48a9ac Binary files /dev/null and b/apps/examples/dtmftester/wav/5.wav differ diff --git a/apps/examples/dtmftester/wav/6.wav b/apps/examples/dtmftester/wav/6.wav new file mode 100644 index 00000000..6fd80061 Binary files /dev/null and b/apps/examples/dtmftester/wav/6.wav differ diff --git a/apps/examples/dtmftester/wav/7.wav b/apps/examples/dtmftester/wav/7.wav new file mode 100644 index 00000000..af134d74 Binary files /dev/null and b/apps/examples/dtmftester/wav/7.wav differ diff --git a/apps/examples/dtmftester/wav/8.wav b/apps/examples/dtmftester/wav/8.wav new file mode 100644 index 00000000..12d18834 Binary files /dev/null and b/apps/examples/dtmftester/wav/8.wav differ diff --git a/apps/examples/dtmftester/wav/9.wav b/apps/examples/dtmftester/wav/9.wav new file mode 100644 index 00000000..c0ac86aa Binary files /dev/null and b/apps/examples/dtmftester/wav/9.wav differ diff --git a/apps/examples/dtmftester/wav/prompt.wav b/apps/examples/dtmftester/wav/prompt.wav new file mode 100644 index 00000000..8d83afd4 Binary files /dev/null and b/apps/examples/dtmftester/wav/prompt.wav differ