early media receiving example

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@506 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 18 years ago
parent 061dcad669
commit 1c92fcb303

@ -0,0 +1,122 @@
#include "EarlyRecord.h"
#include "log.h"
#include "AmConfigReader.h"
#include "AmUtils.h"
#include "AmPlugIn.h"
#define MOD_NAME "early_record"
EXPORT_SESSION_FACTORY(EarlyRecordFactory,MOD_NAME);
string EarlyRecordFactory::RecordDir;
EarlyRecordFactory::EarlyRecordFactory(const string& _app_name)
: AmSessionFactory(_app_name)
{
}
int EarlyRecordFactory::onLoad()
{
return 0;
}
AmSession* EarlyRecordFactory::onInvite(const AmSipRequest& req)
{
return new EarlyRecordDialog(NULL);
}
// auth with di_dial
AmSession* EarlyRecordFactory::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<UACAuthCred*>(cred_obj);
}
AmSession* s = new EarlyRecordDialog(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;
}
EarlyRecordDialog::EarlyRecordDialog(UACAuthCred* credentials)
: cred(credentials)
{
// this sets the session to run onEarlySessionStart
accept_early_session = true;
}
EarlyRecordDialog::~EarlyRecordDialog()
{
}
void EarlyRecordDialog::onEarlySessionStart(const AmSipReply& req) {
DBG("Early Session Start\n");
msg_filename = "/tmp/" + getLocalTag() + ".wav";
if(a_msg.open(msg_filename,AmAudioFile::Write,false))
throw string("EarlyRecordDialog: couldn't open ") +
msg_filename + string(" for writing");
setInput(&a_msg);
setMute(true);
}
void EarlyRecordDialog::onSessionStart(const AmSipReply& req)
{
setInOut(NULL, NULL);
a_msg.close();
// replay the recorded early media
msg_filename = "/tmp/" + getLocalTag() + ".wav";
if(a_msg.open(msg_filename,AmAudioFile::Read,false))
throw string("EarlyRecordDialog: couldn't open ") +
msg_filename + string(" for writing");
setOutput(&a_msg);
}
void EarlyRecordDialog::onBye(const AmSipRequest& req)
{
DBG("onBye: stopSession\n");
setStopped();
}
void EarlyRecordDialog::process(AmEvent* event)
{
AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event);
if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){
dlg.bye();
setStopped();
return;
}
AmSession::process(event);
}
inline UACAuthCred* EarlyRecordDialog::getCredentials() {
return cred.get();
}

@ -0,0 +1,47 @@
#ifndef _EARLY_RECORD_H_
#define _EARLY_RECORD_H_
#include "AmSession.h"
#include "AmAudio.h"
#include "ampi/UACAuthAPI.h"
#include <string>
using std::string;
class EarlyRecordFactory: public AmSessionFactory
{
public:
static string RecordDir;
EarlyRecordFactory(const string& _app_name);
int onLoad();
AmSession* onInvite(const AmSipRequest& req);
AmSession* onInvite(const AmSipRequest& req,
AmArg& session_params);
};
class EarlyRecordDialog
: public AmSession,
public CredentialHolder // who invented that stupid name? ;)
{
string msg_filename;
AmAudioFile a_msg;
std::auto_ptr<UACAuthCred> cred;
protected:
void process(AmEvent* event);
public:
EarlyRecordDialog(UACAuthCred* credentials);
~EarlyRecordDialog();
void onEarlySessionStart(const AmSipReply& req);
void onSessionStart(const AmSipReply& req);
void onBye(const AmSipRequest& req);
inline UACAuthCred* getCredentials();
};
#endif

@ -0,0 +1,7 @@
plug_in_name = early_record
module_ldflags =
module_cflags =
COREPATH ?=../../../core
include $(COREPATH)/plug-in/Makefile.app_module

@ -0,0 +1,6 @@
EarlyRecord
This example demonstrates how to use the early media
receiving mode. It records received early media of an
authenticated call in a file in /tmp folder, and when
the callee picks up, it plays the recorded file.
Loading…
Cancel
Save