diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-03 15:29:32 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-03 15:29:32 (GMT) |
commit | 096f7df1137dd62871cacd371bf023e39d6b30e5 (patch) | |
tree | e1fa0dc079698d700e6323dcc7769169142a236e /src/uscxml | |
parent | 8941cc07d4df9c112744e58a9108fcf5575fa9d6 (diff) | |
download | uscxml-096f7df1137dd62871cacd371bf023e39d6b30e5.zip uscxml-096f7df1137dd62871cacd371bf023e39d6b30e5.tar.gz uscxml-096f7df1137dd62871cacd371bf023e39d6b30e5.tar.bz2 |
Reactiveted miles components and some JSC fixes
Diffstat (limited to 'src/uscxml')
8 files changed, 83 insertions, 77 deletions
diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index a13a887..b3ad09e 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -38,6 +38,7 @@ # ifdef MILES_FOUND # include "uscxml/plugins/invoker/miles/MilesSessionInvoker.h" +# include "uscxml/plugins/invoker/miles/SpatialAudio.h" # endif # ifdef FFMPEG_FOUND @@ -129,8 +130,12 @@ Factory::Factory() { #ifdef MILES_FOUND { -// MilesSessionInvoker* invoker = new MilesSessionInvoker(); -// registerInvoker(invoker); + MilesSessionInvoker* invoker = new MilesSessionInvoker(); + registerInvoker(invoker); + } + { + SpatialAudio* invoker = new SpatialAudio(); + registerInvoker(invoker); } #endif diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 174c33d..c78cdad 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -84,7 +84,7 @@ void JSCDataModel::setEvent(const Event& event) { JSObjectRef eventObj = JSObjectMake(_ctx, Arabica::DOM::JSCSCXMLEvent::getTmpl(), privData); JSObjectRef globalObject = JSContextGetGlobalObject(_ctx); - + JSValueRef exception = NULL; if (event.dom) { @@ -146,7 +146,9 @@ void JSCDataModel::setEvent(const Event& event) { } } - JSObjectSetProperty(_ctx, globalObject, JSStringCreateWithUTF8CString("_event"), eventObj, kJSPropertyAttributeDontDelete, NULL); + JSObjectSetProperty(_ctx, globalObject, JSStringCreateWithUTF8CString("_event"), eventObj, kJSPropertyAttributeDontDelete, &exception); + if (exception) + handleException(exception); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp index ba95603..9b6f34f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp @@ -7,18 +7,19 @@ namespace DOM { JSClassRef JSCSCXMLEvent::Tmpl; JSStaticValue JSCSCXMLEvent::staticValues[] = { - { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "origin", originAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "origintype", origintypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "raw", rawAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "invokeid", invokeidAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "dom", domAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "origintype", origintypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + + { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "sendid", sendidCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "invokeid", invokeidAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "INTERNAL", INTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "EXTERNAL", EXTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "PLATFORM", PLATFORMConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "INTERNAL", INTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, + { "EXTERNAL", EXTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, + { "PLATFORM", PLATFORMConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, { 0, 0, 0, 0 } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp index f36e544..de81244 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp @@ -4,36 +4,37 @@ namespace Arabica { namespace DOM { JSValueRef JSCSCXMLEvent::typeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { -#if 0 - v8::Local<v8::Object> self = info.Holder(); - V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); + struct JSCSCXMLEventPrivate* privData = (struct JSCSCXMLEventPrivate*)JSObjectGetPrivate(thisObj); + JSStringRef stringRef; switch (privData->nativeObj->type) { case uscxml::Event::INTERNAL: - return v8::String::New("internal"); + stringRef = JSStringCreateWithUTF8CString("internal"); break; case uscxml::Event::EXTERNAL: - return v8::String::New("external"); + stringRef = JSStringCreateWithUTF8CString("external"); break; case uscxml::Event::PLATFORM: - return v8::String::New("platform"); + stringRef = JSStringCreateWithUTF8CString("platform"); break; default: + stringRef = JSStringCreateWithUTF8CString("undefined"); break; } - return v8::String::New("unknown"); -#endif + + return JSValueMakeString(ctx, stringRef); } JSValueRef JSCSCXMLEvent::sendidCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { -#if 0 - v8::Local<v8::Object> self = info.Holder(); - V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); + struct JSCSCXMLEventPrivate* privData = (struct JSCSCXMLEventPrivate*)JSObjectGetPrivate(thisObj); + JSStringRef stringRef; - if (privData->nativeObj->sendid.length() == 0 || privData->nativeObj->hideSendId) - return v8::Undefined(); - return v8::String::New(privData->nativeObj->sendid.c_str()); -#endif + if (privData->nativeObj->sendid.length() == 0 || privData->nativeObj->hideSendId) { + return JSValueMakeUndefined(ctx); + } else { + stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->sendid.c_str()); + return JSValueMakeString(ctx, stringRef); + } } } diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index 4e74a8c..f0d124f 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -226,14 +226,7 @@ endif() # MILES modality components -if (MILES_FOUND AND OFF) - # openal is only needed for miles - find_package(OpenAL REQUIRED) -# find_package(JPEG REQUIRED) - list (APPEND MILES_LIBRARIES "iconv") - list (APPEND MILES_LIBRARIES ${JPEG_LIBRARIES}) - list (APPEND USCXML_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) - +if (MILES_FOUND) file(GLOB_RECURSE MILES_INVOKER miles/*.cpp miles/*.h) @@ -254,6 +247,7 @@ if (MILES_FOUND AND OFF) endif() endif() + # VoiceXML modality components if (UMUNDO_FOUND) diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp index 1c7d8a5..8d19019 100644 --- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp +++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp @@ -25,7 +25,7 @@ MilesSessionInvoker::MilesSessionInvoker() { MilesSessionInvoker::~MilesSessionInvoker() { }; -boost::shared_ptr<IOProcessorImpl> MilesSessionInvoker::create(InterpreterImpl* interpreter) { +boost::shared_ptr<InvokerImpl> MilesSessionInvoker::create(InterpreterImpl* interpreter) { boost::shared_ptr<MilesSessionInvoker> invoker = boost::shared_ptr<MilesSessionInvoker>(new MilesSessionInvoker()); invoker->_interpreter = interpreter; return invoker; @@ -123,14 +123,14 @@ void MilesSessionInvoker::send(const SendRequest& req) { /* Set up audio grabber */ - int n = miles_audio_device_get_supported_devices(&supported_audio_devices); + int n = miles_audio_device_get_supported_devices(MILES_AUDIO_DEVICE_OPENAL, &supported_audio_devices); if(n<=0) { /* No audio device available */ exit(-1); } /* Use first device that supports capture */ for(int i=0; i<n; i++) { - audio_dev = miles_audio_device_open(supported_audio_devices[i].id, MILES_AUDIO_FORMAT_PCM, 16000, 2, 1, 640, 1); + audio_dev = miles_audio_device_open(MILES_AUDIO_DEVICE_OPENAL, supported_audio_devices[i].id, MILES_AUDIO_FORMAT_PCM, 16000, 2, 1, 640, 1); if(audio_dev) break; } @@ -139,7 +139,7 @@ void MilesSessionInvoker::send(const SendRequest& req) { /* Find first audio device that supports playback */ for(int i=0; i<n; i++) { - audio_dev_playback = miles_audio_device_open(supported_audio_devices[i].id, MILES_AUDIO_FORMAT_PCM, 16000, 2, 1, 640, 0); + audio_dev_playback = miles_audio_device_open(MILES_AUDIO_DEVICE_OPENAL, supported_audio_devices[i].id, MILES_AUDIO_FORMAT_PCM, 16000, 2, 1, 640, 0); if(audio_dev_playback) { audio_dev_playback_id = supported_audio_devices[i].id; break; @@ -231,14 +231,14 @@ void MilesSessionInvoker::playback_audio(u_int32_t ssrc, char *buf, int sample_r if(audio_dev_playback == NULL || audio_dev_playback->chunk_size != size || audio_dev_playback->sample_rate != sample_rate || audio_dev_playback->format != audio_format || audio_dev_playback->bytes_per_sample != bps) { if(audio_dev_playback) - miles_audio_device_close(audio_dev_playback, 0); - audio_dev_playback = miles_audio_device_open(audio_dev_playback_id, audio_format, sample_rate, bps, 1, size, 0); + miles_audio_device_close(MILES_AUDIO_DEVICE_OPENAL, audio_dev_playback, 0); + audio_dev_playback = miles_audio_device_open(MILES_AUDIO_DEVICE_OPENAL, audio_dev_playback_id, audio_format, sample_rate, bps, 1, size, 0); if(audio_dev_playback == NULL) return; } /* play audio */ - n = miles_audio_device_write(audio_dev_playback, buf, size); + n = miles_audio_device_write(MILES_AUDIO_DEVICE_OPENAL, audio_dev_playback, buf, size); } /** @@ -391,7 +391,7 @@ int MilesSessionInvoker::audio_transmitter(struct miles_audio_device *dev, struc /* Send RTCP packets, if due */ miles_rtp_send_rtcp(out_rtcp_audio_stream); - n = miles_audio_device_read(dev, audio_read_buf, codec_ctx->chunk_size); + n = miles_audio_device_read(MILES_AUDIO_DEVICE_OPENAL, dev, audio_read_buf, codec_ctx->chunk_size); if(n <= 0) return 0; if(dev->format != codec_ctx->input_format) { diff --git a/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp b/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp index acc5c4b..3826ebb 100644 --- a/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp +++ b/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp @@ -28,14 +28,16 @@ SpatialAudio::SpatialAudio() { _pos[0] = _pos[1] = _pos[2] = 0.0; _listener = new float[3]; _listener[0] = _listener[1] = _listener[2] = 0.0; + miles_init(); + } SpatialAudio::~SpatialAudio() { }; -Invoker* SpatialAudio::create(Interpreter* interpreter) { - SpatialAudio* invoker = new SpatialAudio(); +boost::shared_ptr<InvokerImpl> SpatialAudio::create(InterpreterImpl* interpreter) { + boost::shared_ptr<SpatialAudio> invoker = boost::shared_ptr<SpatialAudio>(new SpatialAudio()); invoker->_interpreter = interpreter; return invoker; } @@ -46,13 +48,13 @@ Data SpatialAudio::getDataModelVariables() { return data; } -void SpatialAudio::send(SendRequest& req) { +void SpatialAudio::send(const SendRequest& req) { if (!_audioDevOpen) { - _audioDev = miles_audio_device_open(_audioDevIndex, 0, 22050, 2, 1, 0); + _audioDev = miles_audio_device_open(MILES_AUDIO_IO_OPENAL, _audioDevIndex, 0, 22050, 2, 1, 1024, false); if (_audioDev != NULL) { _audioDevOpen = true; float rolloffFactor = 0.2; - miles_audio_device_control(_audioDev, MILES_AUDIO_DEVICE_CTRL_SET_ROLLOFF_FACTOR, &rolloffFactor); + miles_audio_device_control(MILES_AUDIO_IO_OPENAL, _audioDev, MILES_AUDIO_DEVICE_CTRL_SET_ROLLOFF_FACTOR, &rolloffFactor); } } @@ -66,14 +68,14 @@ void SpatialAudio::send(SendRequest& req) { // } // std::cout << std::endl; - miles_audio_device_control(_audioDev, MILES_AUDIO_DEVICE_CTRL_SET_POSITION, _pos); + miles_audio_device_control(MILES_AUDIO_IO_OPENAL, _audioDev, MILES_AUDIO_DEVICE_CTRL_SET_POSITION, _pos); char* buffer = (char*)malloc(_audioDev->chunk_size); // skip wav header _dataStream.seekg(44); while(_dataStream.readsome(buffer, _audioDev->chunk_size) != 0) { - miles_audio_device_write(_audioDev, buffer, _audioDev->chunk_size); + miles_audio_device_write(MILES_AUDIO_IO_OPENAL, _audioDev, buffer, _audioDev->chunk_size); } free(buffer); } @@ -87,7 +89,7 @@ void SpatialAudio::send(SendRequest& req) { } std::cout << std::endl; - miles_audio_device_control(_audioDev, MILES_AUDIO_DEVICE_CTRL_SET_LISTENER_POS, _listener); + miles_audio_device_control(MILES_AUDIO_IO_OPENAL, _audioDev, MILES_AUDIO_DEVICE_CTRL_SET_LISTENER_POS, _listener); } } @@ -102,17 +104,16 @@ void SpatialAudio::sendToParent(SendRequest& req) { assert(false); } -void SpatialAudio::invoke(InvokeRequest& req) { +void SpatialAudio::invoke(const InvokeRequest& req) { _invokeId = req.invokeid; if (req.src.length() > 0) { - Arabica::io::URI url(req.src); - if (!_interpreter->makeAbsolute(url)) { + URL scriptUrl(req.src); + if (!scriptUrl.toAbsolute(_interpreter->getBaseURI())) { LOG(ERROR) << "Source attribute for audio invoker has relative URI " << req.src << " with no base URI set for interpreter"; return; } - URL scriptUrl(url.as_string()); _dataStream << scriptUrl; } @@ -121,7 +122,7 @@ void SpatialAudio::invoke(InvokeRequest& req) { struct miles_audio_device_description *devices; int ndevs; - ndevs = miles_audio_device_get_supported_devices(&devices); + ndevs = miles_audio_device_get_supported_devices(MILES_AUDIO_IO_OPENAL, &devices); for (int i = 0; i < ndevs; i++) { if ((devices[i].capabilities & MILES_AUDIO_DEVICE_CAPABILITY_SPATIAL) && @@ -132,15 +133,15 @@ void SpatialAudio::invoke(InvokeRequest& req) { } } -void SpatialAudio::getPosFromParams(std::map<std::string, std::list<std::string> >& params, float* position) { +void SpatialAudio::getPosFromParams(const std::multimap<std::string, std::string>& params, float* position) { // vector explicitly given try { if (params.find("x") != params.end()) - position[0] = boost::lexical_cast<float>(params["x"].front()); + position[0] = boost::lexical_cast<float>(params.find("x")->second); if (params.find("y") != params.end()) - position[1] = boost::lexical_cast<float>(params["y"].front()); + position[1] = boost::lexical_cast<float>(params.find("y")->second); if (params.find("z") != params.end()) - position[2] = boost::lexical_cast<float>(params["z"].front()); + position[2] = boost::lexical_cast<float>(params.find("z")->second); } catch (boost::bad_lexical_cast& e) { LOG(ERROR) << "Cannot interpret x, y or z as float value in params: " << e.what(); } @@ -148,13 +149,13 @@ void SpatialAudio::getPosFromParams(std::map<std::string, std::list<std::string> try { // right is an alias for x if (params.find("right") != params.end()) - position[0] = boost::lexical_cast<float>(params["right"].front()); + position[0] = boost::lexical_cast<float>(params.find("right")->second); // height is an alias for y if (params.find("height") != params.end()) - position[1] = boost::lexical_cast<float>(params["height"].front()); + position[1] = boost::lexical_cast<float>(params.find("height")->second); // front is an alias for z if (params.find("front") != params.end()) - position[2] = boost::lexical_cast<float>(params["front"].front()); + position[2] = boost::lexical_cast<float>(params.find("front")->second); } catch (boost::bad_lexical_cast& e) { LOG(ERROR) << "Cannot interpret right, height or front as float value in params: " << e.what(); } @@ -162,7 +163,7 @@ void SpatialAudio::getPosFromParams(std::map<std::string, std::list<std::string> // do we have a position on a circle? try { if (params.find("circle") != params.end()) { - float rad = posToRadian(params["circle"].front()); + float rad = posToRadian(params.find("circle")->second); position[0] = cosf(rad); position[2] = -1 * sinf(rad); // z axis increases to front } @@ -173,23 +174,24 @@ void SpatialAudio::getPosFromParams(std::map<std::string, std::list<std::string> } -float SpatialAudio::posToRadian(std::string& position) { - boost::trim(position); +float SpatialAudio::posToRadian(const std::string& pos) { + + std::string trimmedPos = boost::trim_copy(pos); float rad = 0; - if (position.size() > 3 && boost::iequals("deg", position.substr(position.length() - 3, 3))) { - rad = boost::lexical_cast<float>(position.substr(0, position.size() - 3)); + if (trimmedPos.size() > 3 && boost::iequals("deg", trimmedPos.substr(trimmedPos.length() - 3, 3))) { + rad = boost::lexical_cast<float>(trimmedPos.substr(0, trimmedPos.size() - 3)); rad = fmodf(rad, 360); // into range [0-360] rad /= 180; // into range [0-2] rad *= M_PI; // into range [0-2PI] rad -= M_PI_2; // 0 to top; rad *= -1; // make clockwise rad += 2 * M_PI; // make positive - } else if (position.size() > 3 && boost::iequals("rad", position.substr(position.length() - 3, 3))) { - rad = boost::lexical_cast<float>(position.substr(0, position.size() - 3)); + } else if (trimmedPos.size() > 3 && boost::iequals("rad", trimmedPos.substr(trimmedPos.length() - 3, 3))) { + rad = boost::lexical_cast<float>(trimmedPos.substr(0, trimmedPos.size() - 3)); rad = fmodf(rad, M_PI * 2); // into range [0-2*PI] } else { - LOG(ERROR) << "Cannot make sense of position value " << position << ": does not end in 'deg', 'rad'"; + LOG(ERROR) << "Cannot make sense of position value " << trimmedPos << ": does not end in 'deg', 'rad'"; } return rad; } diff --git a/src/uscxml/plugins/invoker/miles/SpatialAudio.h b/src/uscxml/plugins/invoker/miles/SpatialAudio.h index bb0886f..082d796 100644 --- a/src/uscxml/plugins/invoker/miles/SpatialAudio.h +++ b/src/uscxml/plugins/invoker/miles/SpatialAudio.h @@ -5,9 +5,10 @@ #include <uscxml/Interpreter.h> extern "C" { -# include "miles/audio.h" -# include "miles/audio_codec.h" -# include "miles/audio_device.h" +#include "miles/audio_device.h" +#include "miles/audio_codec.h" +#include "miles/audio_io.h" +#include "miles/miles.h" } namespace uscxml { @@ -16,7 +17,7 @@ class SpatialAudio : public InvokerImpl { public: SpatialAudio(); virtual ~SpatialAudio(); - virtual Invoker* create(Interpreter* interpreter); + virtual boost::shared_ptr<InvokerImpl> create(InterpreterImpl* interpreter); virtual std::set<std::string> getNames() { std::set<std::string> names; @@ -28,13 +29,13 @@ public: } virtual Data getDataModelVariables(); - virtual void send(SendRequest& req); + virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); - virtual void invoke(InvokeRequest& req); + virtual void invoke(const InvokeRequest& req); virtual void sendToParent(SendRequest& req); - void getPosFromParams(std::map<std::string, std::list<std::string> >& params, float* position); - static float posToRadian(std::string& position); + void getPosFromParams(const std::multimap<std::string, std::string>& params, float* position); + static float posToRadian(const std::string& position); protected: std::string _invokeId; |