diff --git a/apps/announcement/Announcement.cpp b/apps/announcement/Announcement.cpp index 810f94a0..e7cd7c0b 100644 --- a/apps/announcement/Announcement.cpp +++ b/apps/announcement/Announcement.cpp @@ -29,6 +29,8 @@ #include "AmConfig.h" #include "AmUtils.h" +#include "AmAudioMixIn.h" + #include "sems.h" #include "log.h" @@ -119,8 +121,15 @@ void AnnouncementDialog::startSession(){ if(wav_file.open(filename,AmAudioFile::Read)) throw string("AnnouncementDialog::onSessionStart: Cannot open file\n"); - - setOutput(&wav_file); + + DBG("*************************asdasdasdasd*********\n"); + AmAudioFile* f = new AmAudioFile(); + if (f->open("/tmp/beep.wav", AmAudioFile::Read)) { + throw string("AnnouncementDialog::onSessionStart: Cannot open file\n"); + } + + AmAudioMixIn* s = new AmAudioMixIn(&wav_file, f, 4, 0.0); + setOutput(s); } void AnnouncementDialog::onBye(const AmSipRequest& req) diff --git a/apps/examples/mixin_announce/Makefile b/apps/examples/mixin_announce/Makefile new file mode 100644 index 00000000..53bfa557 --- /dev/null +++ b/apps/examples/mixin_announce/Makefile @@ -0,0 +1,14 @@ + +NAME=mix_announce +VERSION=0.0.1 + +PYTHON_VERSION=2.4 + +LIBDIR= + +COREPATH=../../../core +IVRPATH=../../ivr + +# general python app Makefile +include $(IVRPATH)/Makefile.ivr_application + diff --git a/apps/examples/mixin_announce/etc/mixin_announce.conf b/apps/examples/mixin_announce/etc/mixin_announce.conf new file mode 100644 index 00000000..5494785a --- /dev/null +++ b/apps/examples/mixin_announce/etc/mixin_announce.conf @@ -0,0 +1,2 @@ +announcement=../apps/voicemail/wav/default_en.wav +beep=../apps/voicemail/wav/beep.wav diff --git a/apps/examples/mixin_announce/py_comp b/apps/examples/mixin_announce/py_comp new file mode 100644 index 00000000..911ce58f --- /dev/null +++ b/apps/examples/mixin_announce/py_comp @@ -0,0 +1,2 @@ +import compileall +compileall.main() diff --git a/apps/ivr/Ivr.cpp b/apps/ivr/Ivr.cpp index f9e44d01..d4468195 100644 --- a/apps/ivr/Ivr.cpp +++ b/apps/ivr/Ivr.cpp @@ -24,6 +24,7 @@ #include "IvrSipRequest.h" #include "IvrSipReply.h" #include "IvrAudio.h" +#include "IvrAudioMixIn.h" #include "IvrUAC.h" #include "Ivr.h" @@ -240,6 +241,9 @@ void IvrFactory::import_ivr_builtins() // IvrAudioFile import_object(ivr_module,"IvrAudioFile",&IvrAudioFileType); + // IvrAudioMixIn + import_object(ivr_module,"IvrAudioMixIn",&IvrAudioMixInType); + // IvrUAC import_object(ivr_module,"IvrUAC",&IvrUACType); diff --git a/apps/ivr/IvrAudioMixIn.cpp b/apps/ivr/IvrAudioMixIn.cpp new file mode 100644 index 00000000..79f988ea --- /dev/null +++ b/apps/ivr/IvrAudioMixIn.cpp @@ -0,0 +1,131 @@ +#include "IvrAudioMixIn.h" +#include "IvrAudio.h" + +#include "log.h" + +static PyObject* IvrAudioMixIn_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + DBG("---------- IvrAudioMixIn_alloc -----------\n"); + IvrAudioMixIn *self; + + self = (IvrAudioMixIn *)type->tp_alloc(type, 0); + + if (self != NULL) { + self->mix = NULL; + } + + return (PyObject *)self; +} + +static void IvrAudioMixIn_dealloc(IvrAudioMixIn* self) +{ + DBG("---------- IvrAudioMixIn_dealloc -----------\n"); + if (self->mix) { + delete self->mix; + self->mix = NULL; + } + + self->ob_type->tp_free((PyObject*)self); +} + + +static PyObject* IvrAudioMixIn_init(IvrAudioMixIn* self, PyObject* args) +{ + AmAudioFile* a = NULL; + AmAudioFile* b = NULL; + int s; + double l; + + PyObject *o_a, *o_b; + + if(!PyArg_ParseTuple(args,"OOid", &o_a, &o_b, &s, &l)) + return NULL; + + if (o_a == Py_None) { + PyErr_SetString(PyExc_TypeError,"Argument 1 is None (need IvrAudioFile)"); + return NULL; + } + + if (o_b == Py_None) { + PyErr_SetString(PyExc_TypeError,"Argument 2 is None (need IvrAudioFile)"); + return NULL; + } + + if(!PyObject_TypeCheck(o_a,&IvrAudioFileType)){ + PyErr_SetString(PyExc_TypeError,"Argument 1 is no IvrAudioFile"); + return NULL; + } + a = ((IvrAudioFile*)o_a)->af; + + + if(!PyObject_TypeCheck(o_b,&IvrAudioFileType)){ + PyErr_SetString(PyExc_TypeError,"Argument 2 is no IvrAudioFile"); + return NULL; + } + b = ((IvrAudioFile*)o_b)->af; + + if (NULL !=self->mix) { + delete self->mix; + } + + self->mix = new AmAudioMixIn(a, b, s, l); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef IvrAudioMixIn_methods[] = { + {"init", (PyCFunction)IvrAudioMixIn_init, METH_VARARGS, + "open the mixin with two audio files, interval and level" + }, + {NULL} /* Sentinel */ +}; + + + +static PyGetSetDef IvrAudioMixIn_getseters[] = { + {NULL} /* Sentinel */ +}; + +PyTypeObject IvrAudioMixInType = { + + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "ivr.IvrAudioMixIn", /*tp_name*/ + sizeof(IvrAudioMixIn), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)IvrAudioMixIn_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "An audio file", /*tp_doc*/ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + IvrAudioMixIn_methods, /* tp_methods */ + 0, /* tp_members */ + IvrAudioMixIn_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + IvrAudioMixIn_new, /* tp_new */ +}; diff --git a/apps/ivr/IvrAudioMixIn.h b/apps/ivr/IvrAudioMixIn.h new file mode 100644 index 00000000..4bd349c9 --- /dev/null +++ b/apps/ivr/IvrAudioMixIn.h @@ -0,0 +1,20 @@ +#ifndef IvrAudioMixIn_h +#define IvrAudioMixIn_h + +// Python stuff +#include +#include + +#include "AmAudioMixIn.h" + +// Data definition +typedef struct { + + PyObject_HEAD + AmAudioMixIn* mix; + +} IvrAudioMixIn; + +extern PyTypeObject IvrAudioMixInType; + +#endif diff --git a/apps/ivr/IvrDialogBase.cpp b/apps/ivr/IvrDialogBase.cpp index f628ef8b..13047691 100644 --- a/apps/ivr/IvrDialogBase.cpp +++ b/apps/ivr/IvrDialogBase.cpp @@ -1,5 +1,7 @@ #include "IvrDialogBase.h" #include "IvrAudio.h" +#include "IvrAudioMixIn.h" +# #include "Ivr.h" #include "IvrSipDialog.h" @@ -183,21 +185,27 @@ static PyObject* IvrDialogBase_enqueue(IvrDialogBase* self, PyObject* args) assert(self->p_dlg); PyObject *o_play, *o_rec; - AmAudioFile *a_play=NULL, *a_rec=NULL; + AmAudio *a_play=NULL; + AmAudioFile *a_rec=NULL; if(!PyArg_ParseTuple(args,"OO",&o_play,&o_rec)) return NULL; if (o_play != Py_None){ - if(!PyObject_TypeCheck(o_play,&IvrAudioFileType)){ - + if(PyObject_TypeCheck(o_play,&IvrAudioFileType)){ + ((IvrAudioFile*)o_play)->af->rewind(); + a_play = ((IvrAudioFile*)o_play)->af; + + } if(PyObject_TypeCheck(o_play,&IvrAudioMixInType)){ + + a_play = ((IvrAudioMixIn*)o_play)->mix; + + } else { PyErr_SetString(PyExc_TypeError,"Argument 1 is no IvrAudioFile"); return NULL; } - a_play = ((IvrAudioFile*)o_play)->af; - a_play->rewind(); } if (o_rec != Py_None){