From 096f7df1137dd62871cacd371bf023e39d6b30e5 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 3 Jul 2013 17:29:32 +0200 Subject: Reactiveted miles components and some JSC fixes --- CMakeLists.txt | 11 ++-- apps/samples/vrml.zip | Bin 117742 -> 0 bytes src/uscxml/Factory.cpp | 9 +++- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 6 ++- .../JavaScriptCore/dom/JSCSCXMLEvent.cpp | 13 ++--- .../JavaScriptCore/dom/JSCSCXMLEventCustom.cpp | 31 +++++------ src/uscxml/plugins/invoker/CMakeLists.txt | 10 +--- .../plugins/invoker/miles/MilesSessionInvoker.cpp | 16 +++--- src/uscxml/plugins/invoker/miles/SpatialAudio.cpp | 58 +++++++++++---------- src/uscxml/plugins/invoker/miles/SpatialAudio.h | 17 +++--- test/samples/uscxml/demos/3d-file-server.scxml | 7 --- 11 files changed, 91 insertions(+), 87 deletions(-) delete mode 100644 apps/samples/vrml.zip delete mode 100644 test/samples/uscxml/demos/3d-file-server.scxml diff --git a/CMakeLists.txt b/CMakeLists.txt index 814c099..68dc2d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,7 +526,14 @@ if (UNIX) endif() find_package(MILES) -if (MILES_FOUND AND OFF) +if (MILES_FOUND) + # 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}) + include_directories (${MILES_INCLUDE_DIR}) list (APPEND USCXML_OPT_LIBS ${MILES_LIBRARIES}) list (APPEND USCXML_OPT_LIBS ${OPENAL_LIBRARY}) @@ -597,8 +604,6 @@ if (BUILD_AS_PLUGINS) target_link_libraries(uscxml ${USCXML_CORE_LIBS}) else() add_library(uscxml ${USCXML_FILES}) - message("USCXML_OPT_LIBS: ${USCXML_OPT_LIBS}") - message("USCXML_CORE_LIBS: ${USCXML_CORE_LIBS}") target_link_libraries(uscxml ${USCXML_OPT_LIBS} ${USCXML_CORE_LIBS}) endif() diff --git a/apps/samples/vrml.zip b/apps/samples/vrml.zip deleted file mode 100644 index 730236b..0000000 Binary files a/apps/samples/vrml.zip and /dev/null differ 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 self = info.Holder(); - V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(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 self = info.Holder(); - V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(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 MilesSessionInvoker::create(InterpreterImpl* interpreter) { +boost::shared_ptr MilesSessionInvoker::create(InterpreterImpl* interpreter) { boost::shared_ptr invoker = boost::shared_ptr(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; ichunk_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 SpatialAudio::create(InterpreterImpl* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr(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 >& params, float* position) { +void SpatialAudio::getPosFromParams(const std::multimap& params, float* position) { // vector explicitly given try { if (params.find("x") != params.end()) - position[0] = boost::lexical_cast(params["x"].front()); + position[0] = boost::lexical_cast(params.find("x")->second); if (params.find("y") != params.end()) - position[1] = boost::lexical_cast(params["y"].front()); + position[1] = boost::lexical_cast(params.find("y")->second); if (params.find("z") != params.end()) - position[2] = boost::lexical_cast(params["z"].front()); + position[2] = boost::lexical_cast(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 try { // right is an alias for x if (params.find("right") != params.end()) - position[0] = boost::lexical_cast(params["right"].front()); + position[0] = boost::lexical_cast(params.find("right")->second); // height is an alias for y if (params.find("height") != params.end()) - position[1] = boost::lexical_cast(params["height"].front()); + position[1] = boost::lexical_cast(params.find("height")->second); // front is an alias for z if (params.find("front") != params.end()) - position[2] = boost::lexical_cast(params["front"].front()); + position[2] = boost::lexical_cast(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 // 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 } -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(position.substr(0, position.size() - 3)); + if (trimmedPos.size() > 3 && boost::iequals("deg", trimmedPos.substr(trimmedPos.length() - 3, 3))) { + rad = boost::lexical_cast(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(position.substr(0, position.size() - 3)); + } else if (trimmedPos.size() > 3 && boost::iequals("rad", trimmedPos.substr(trimmedPos.length() - 3, 3))) { + rad = boost::lexical_cast(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 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 create(InterpreterImpl* interpreter); virtual std::set getNames() { std::set 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 >& params, float* position); - static float posToRadian(std::string& position); + void getPosFromParams(const std::multimap& params, float* position); + static float posToRadian(const std::string& position); protected: std::string _invokeId; diff --git a/test/samples/uscxml/demos/3d-file-server.scxml b/test/samples/uscxml/demos/3d-file-server.scxml deleted file mode 100644 index 4823127..0000000 --- a/test/samples/uscxml/demos/3d-file-server.scxml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file -- cgit v0.12