diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index e728c343b..48bf3e36e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -19,6 +19,9 @@ if(WIN32) message(STATUS "enc-amf submodule not found! Please fetch submodules. enc-amf plugin disabled.") endif() endif() + if (MSVC) + add_subdirectory(win-ivcam) + endif() elseif(APPLE) add_subdirectory(coreaudio-encoder) add_subdirectory(mac-avcapture) diff --git a/plugins/win-ivcam/CMakeLists.txt b/plugins/win-ivcam/CMakeLists.txt new file mode 100644 index 000000000..6b6e05adb --- /dev/null +++ b/plugins/win-ivcam/CMakeLists.txt @@ -0,0 +1,62 @@ +project(win-ivcam) + +if(DISABLE_IVCAM) + message(STATUS "Realsense camera plugin disabled") + return() +endif() + +find_package(RSSDK QUIET) +if(NOT RSSDK_FOUND AND ENABLE_IVCAM) + message(FATAL_ERROR "RSSDK not found, but the realsense camera plugin is set as enabled") +elseif(NOT RSSDK_FOUND) + message(STATUS "RSSDK not found, Realsense camera plugin disabled") + return() +endif() + +include(IDLFileHelper) + +set(win-ivcam_seg_library_IDLS + seg_service/seg_service.idl + ) + +add_idl_files(win-ivcam_seg_library_GENERATED_FILES + ${win-ivcam_seg_library_IDLS}) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ) + +set(win-ivcam_seg_library_HEADERS + seg_library/Dependencies.h + seg_library/SegImage.h + seg_library/SegServer.h + seg_library/SegServerImpl.h + seg_library/SegService.h + ) +set(win-ivcam_seg_library_SOURCES + seg_library/SerServer.cpp + seg_library/SegServerImpl.cpp + seg_library/SegImage.cpp + ${win-ivcam_seg_library_GENERATED_FILES} + ) + +set(win-ivcam_SOURCES + realsense.cpp + ) + +source_group("seg_library\\Source Files" FILES ${win-ivcam_seg_library_SOURCES}) +source_group("seg_library\\Header Files" FILES ${win-ivcam_seg_library_HEADERS}) + +add_library(win-ivcam MODULE + ${win-ivcam_seg_library_HEADERS} + ${win-ivcam_seg_library_SOURCES} + ${win-ivcam_SOURCES} + ) +target_link_libraries(win-ivcam + libobs) + +install_obs_plugin_with_data(win-ivcam data) + +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + add_subdirectory(seg_service) +endif() diff --git a/plugins/win-ivcam/realsense.cpp b/plugins/win-ivcam/realsense.cpp new file mode 100644 index 000000000..6ac4ffc05 --- /dev/null +++ b/plugins/win-ivcam/realsense.cpp @@ -0,0 +1,184 @@ +/* +Copyright(c) 2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met : + +- Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and / +or other materials provided with the distribution. +- Neither the name of Intel Corporation nor the names of its contributors may +be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "seg_library/SegService.h" + +using namespace std; + +#include +#include +#include + +#define do_log(level, format, ...) \ + blog(level, "[win-ivcam (%s): '%s'] " format, \ + __FUNCTION__, obs_source_get_name(source), \ + ##__VA_ARGS__) + +#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__) +#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__) +#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__) + +void TerminateProcessByName(wchar_t *procName) +{ + PROCESSENTRY32 entry; + entry.dwSize = sizeof(entry); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL); + BOOL hRes = Process32First(snapshot, &entry); + + while (hRes) { + if (wcscmp(entry.szExeFile, procName) == 0) { + HANDLE process = OpenProcess(PROCESS_TERMINATE, 0, + (DWORD)entry.th32ProcessID); + + if (process != NULL) { + TerminateProcess(process, 0); + CloseHandle(process); + } + } + hRes = Process32Next(snapshot, &entry); + } + CloseHandle(snapshot); +} + +struct IVCamSource { + SegServer* pSegServer; + obs_source_t *source; + thread camThread; + atomic stopThread = false; + + void IVCamSource::PushSegmentedFrameData(SegImage *segmented_image) + { + /*uint8_t* pix = (uint8_t*)segmented_image->GetData(); + if (pix != NULL) { + int pixels = segmented_image->Width() * + segmented_image->Height(); + + for (int i = 0; i < pixels; i++) { + if (pix[3]<100) { + pix[0] /= 3; pix[1] /= 2; pix[2] /= 3; + } + pix += 4; + } + }*/ + + obs_source_frame frame = {}; + frame.data[0] = (uint8_t*)segmented_image->GetData(); + frame.linesize[0] = segmented_image->Pitch(); + frame.format = VIDEO_FORMAT_BGRA; + frame.width = segmented_image->Width(); + frame.height = segmented_image->Height(); + frame.timestamp = os_gettime_ns(); + obs_source_output_video(source, &frame); + } + + void IVCamSource::CamThread() + { + pSegServer = SegServer::CreateServer(); + SegServer::ServiceStatus status = pSegServer->Init(); + + if (status != SegServer::ServiceStatus::SERVICE_NO_ERROR) { + warn("SegServer initialization error (%d)\n", status); + return; + } + + while (!stopThread) { + SegImage* image = nullptr; + SegServer::ServiceStatus error = + pSegServer->GetFrame(&image); + if (error != SegServer::ServiceStatus::SERVICE_NO_ERROR + || image->Width() == 0 + || image->Height() == 0) { + //warn("AcquireFrame failed (%d)\n", error); + continue; + } + + PushSegmentedFrameData(image); + + delete image; + } + + pSegServer->Stop(); + delete pSegServer; + } + + inline IVCamSource::IVCamSource(obs_source_t* source_) : + source(source_) + { + stopThread = false; + camThread = std::thread(&IVCamSource::CamThread, this); + } + + static void* IVCamSource::CreateIVCamSource(obs_data_t*, + obs_source_t *source) + { + //kill whatever is running just in case + TerminateProcessByName(L"seg_service.exe"); + return new IVCamSource(source); + } + + inline IVCamSource::~IVCamSource() + { + //done using it, kill the seg_service + stopThread = true; + if (camThread.joinable()) camThread.join(); + TerminateProcessByName(L"seg_service.exe"); + } +}; + +static const char *GetIVCamName(void*) +{ + return "Intel(R) RealSense(TM) 3D Camera GreenScreen"; +} + +static void DestroyIVCamSource(void *data) +{ + delete reinterpret_cast(data); +} + +OBS_DECLARE_MODULE() + +bool obs_module_load(void) +{ + obs_source_info info = {}; + info.id = "win-ivcam"; + info.type = OBS_SOURCE_TYPE_INPUT; + info.output_flags = OBS_SOURCE_ASYNC_VIDEO; + info.get_name = GetIVCamName; + info.create = IVCamSource::CreateIVCamSource; + info.destroy = DestroyIVCamSource; + obs_register_source(&info); + return true; +} diff --git a/plugins/win-ivcam/seg_library/Dependencies.h b/plugins/win-ivcam/seg_library/Dependencies.h new file mode 100644 index 000000000..02a1ce706 --- /dev/null +++ b/plugins/win-ivcam/seg_library/Dependencies.h @@ -0,0 +1,40 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DEPENDENCIES_H_ +#define DEPENDENCIES_H_ + +// WinAPI section +#include + +// CRT section +#include +#include +#include +#include + +#endif // DEPENDENCIES_H_ \ No newline at end of file diff --git a/plugins/win-ivcam/seg_library/SegImage.cpp b/plugins/win-ivcam/seg_library/SegImage.cpp new file mode 100644 index 000000000..e6ae0f021 --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegImage.cpp @@ -0,0 +1,102 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "SegImage.h" + +SegImage::SegImage() + : m_width(0), m_height(0), m_pitch(0), m_data(nullptr), m_number(0), m_timestamp(0L) {} + +SegImage::SegImage(int width, int height, int pitch, void* data, long long timestamp, int number) + : m_width(width), m_height(height), m_pitch(pitch), m_data(new char[height*pitch]), m_timestamp(timestamp), m_number(number) +{ + memcpy_s(m_data, height*pitch, data, height*pitch); +} + +SegImage::SegImage(SegImage const& src) + : m_width(src.m_width), m_height(src.m_height), m_pitch(src.m_pitch), m_data(new char[src.m_height*src.m_pitch]), + m_timestamp(src.m_timestamp), m_number(src.m_number) +{ + memcpy_s(m_data, m_pitch*m_height, src.m_data, src.m_height*src.m_pitch); +} + +SegImage::~SegImage() +{ + delete[] m_data; +} + +SegImage& SegImage::operator=(const SegImage & src) +{ + if (this != &src) + { + m_width = src.m_width; + m_height = src.m_height; + m_pitch = src.m_pitch; + if (m_data) + { + delete[] m_data; + } + m_data = new char[m_height*m_pitch]; + m_timestamp = src.m_timestamp; + m_number = src.m_number; + memcpy_s(m_data, m_pitch*m_height, src.m_data, m_height*m_pitch); + } + return *this; +} + +int SegImage::Width() +{ + return m_width; +} + +int SegImage::Height() +{ + return m_height; +} + +int SegImage::Pitch() +{ + return m_pitch; +} + +long long SegImage::TimeStamp() +{ + return m_timestamp; +} + +int SegImage::Number() +{ + return m_number; +} + +SegPixel SegImage::Get(int i, int j) +{ + SegPixel result; + result.blue = (((char*)m_data) + j*m_pitch + i * 4)[0]; + result.green = (((char*)m_data) + j*m_pitch + i * 4)[1]; + result.red = (((char*)m_data) + j*m_pitch + i * 4)[2]; + return result; +} diff --git a/plugins/win-ivcam/seg_library/SegImage.h b/plugins/win-ivcam/seg_library/SegImage.h new file mode 100644 index 000000000..554bae3cd --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegImage.h @@ -0,0 +1,66 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SEG_IMAGE_H_ +#define SEG_IMAGE_H_ + +#include "Dependencies.h" + +struct SegPixel +{ + unsigned char red; + unsigned char green; + unsigned char blue; +}; + +class SegImage +{ +private: + int m_width; + int m_height; + int m_pitch; + long long m_timestamp; + int m_number; + void* m_data; +public: + SegImage(); + SegImage(SegImage const& src); + SegImage(int width, int height, int pitch, void* data, long long timestamp, int number); + ~SegImage(); + + SegImage& operator=(const SegImage & src); + + int Width(); + int Height(); + int Pitch(); + long long TimeStamp(); + int Number(); + SegPixel Get(int i, int j); + void* GetData() { return m_data; }; +}; + +#endif // SEG_IMAGE_H_ diff --git a/plugins/win-ivcam/seg_library/SegServer.h b/plugins/win-ivcam/seg_library/SegServer.h new file mode 100644 index 000000000..2d792abc4 --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegServer.h @@ -0,0 +1,71 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SEG_SERVER_H_ +#define SEG_SERVER_H_ + +#include "Dependencies.h" +#include "SegImage.h" + +#define USE_DEFAULT_PROPERTY_VALUE -1 + +class SegServer +{ +public: + enum ServiceStatus + { + COM_LIB_INIT_ERROR = -1, + SERVICE_INIT_ERROR = -2, + SERVICE_REINIT_ERROR = -3, + SERVICE_FUNC_ERROR = -4, + SHARED_MEMORY_ERROR = -5, + ALLOCATION_FAILURE = -6, + SERVICE_NO_ERROR = 0, + SERVICE_NOT_READY = 1 + }; + + static SegServer* CreateServer(); + static SegServer* GetServerInstance(); + + virtual ServiceStatus Init() = 0; + virtual ServiceStatus Stop() = 0; + + virtual ServiceStatus GetFrame(SegImage** image) = 0; + + virtual void SetFps(int fps) = 0; + virtual int GetFps() = 0; + /** + @brief Set the IVCAM motion range trade off option, ranged from 0 (short range, better motion) to 100 (far range, long exposure). Custom property value used only with 60 fps profile + @param[in] value The motion range trade option. USE_DEFAULT_PROPERTY_VALUE to return default value + */ + virtual void SetIVCAMMotionRangeTradeOff(int value) = 0; + virtual int GetIVCAMMotionRangeTradeOff() = 0; + + virtual ~SegServer() {}; +}; + +#endif // SEG_SERVER_H_ diff --git a/plugins/win-ivcam/seg_library/SegServerImpl.cpp b/plugins/win-ivcam/seg_library/SegServerImpl.cpp new file mode 100644 index 000000000..7f74d519a --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegServerImpl.cpp @@ -0,0 +1,202 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "SegServerImpl.h" + +SegServerImpl* SegServerImpl::instance = nullptr; + +SegServerImpl::SegServerImpl() +{ + m_comInit = false; + m_serviceConnected = false; + m_sharedBuffer = NULL; +} + +SegServerImpl::SegServerImpl(SegServerImpl const& src) {}; +SegServerImpl::~SegServerImpl() +{ + if (m_server) + { + m_server->Release(); + m_server = nullptr; + } + instance = nullptr; +}; +SegServerImpl& SegServerImpl::operator=(const SegServerImpl & src) { return *this; }; + +SegServer* SegServerImpl::CreateServer() +{ + if (instance == nullptr) + { + instance = new SegServerImpl(); + return instance; + } + else + { + return nullptr; + } +} + +SegServer* SegServerImpl::GetServerInstance() +{ + return instance; +} + +SegServerImpl::ServiceStatus SegServerImpl::Init() +{ + if (m_comInit && m_serviceConnected) + return SERVICE_REINIT_ERROR; + GUID guid = { 0 }; + m_bufferName = new wchar_t[40](); + CoCreateGuid(&guid); + StringFromGUID2(guid, m_bufferName, 40); + if (!m_comInit) + { + HRESULT comInit = CoInitializeEx(0, COINIT_MULTITHREADED); + if (FAILED(comInit)) + { + comInit = CoInitialize(0); + if (FAILED(comInit)) + { + return COM_LIB_INIT_ERROR; + } + } + m_comInit = true; + } + + if (!m_serviceConnected) + { + HRESULT instanceCreate = CoCreateInstance(CLSID_SegProc, NULL, CLSCTX_LOCAL_SERVER, IID_ISegProc, (void**)&m_server); + if (FAILED(instanceCreate)) { + return SERVICE_INIT_ERROR; + } + + HRESULT serverInit = m_server->Init(m_bufferName); + if (FAILED(serverInit)) { + return SERVICE_INIT_ERROR; + } + m_serviceConnected = true; + } + return SERVICE_NO_ERROR; +} + +SegServerImpl::ServiceStatus SegServerImpl::Stop() +{ + HRESULT errCode = m_server->Stop(); + if (FAILED(errCode)) { + return SERVICE_FUNC_ERROR; + } + return SERVICE_NO_ERROR; +} + +void SegServerImpl::SetFps(int fps) +{ + m_server->SetFps(fps); +} + +int SegServerImpl::GetFps() +{ + int outFps = -1; + m_server->GetFps(&outFps); + return outFps; +} + +void SegServerImpl::SetIVCAMMotionRangeTradeOff(int value) +{ + m_server->SetIVCAMMotionRangeTradeOff(value); +} + +int SegServerImpl::GetIVCAMMotionRangeTradeOff() +{ + int outPropertyValue = -1; + m_server->GetIVCAMMotionRangeTradeOff(&outPropertyValue); + return outPropertyValue; +} + +SegServerImpl::ServiceStatus SegServerImpl::GetFrame(SegImage** image) +{ + ServiceStatus res = SERVICE_NO_ERROR; + int frameId = -1; + int bufferRealloc = -1; + int frameSize = -1; + if (FAILED(m_server->LockBuffer(&frameId, &frameSize, &bufferRealloc))) + { + return SHARED_MEMORY_ERROR; + } + if (bufferRealloc) + { + HANDLE hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, m_bufferName); + + if (hMapFile == NULL) + { + m_server->UnlockBuffer(); + return SHARED_MEMORY_ERROR; + } + + m_sharedBuffer = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, frameSize * 2); + + if (m_sharedBuffer == NULL) + { + CloseHandle(hMapFile); + m_server->UnlockBuffer(); + return SHARED_MEMORY_ERROR; + } + CloseHandle(hMapFile); + } + + if(m_sharedBuffer && frameId != -1 && frameSize != -1) + { + size_t offset = (size_t)frameId * frameSize; + //int width = ((int*)(m_sharedBuffer + offset))[0]; + //int height = ((int*)(m_sharedBuffer + offset))[1]; + //int pitch = ((int*)(m_sharedBuffer + offset))[2]; + FrameHeader* fhPtr = (FrameHeader*)(m_sharedBuffer + offset); + int width = fhPtr->width; + int height = fhPtr->height; + int pitch = fhPtr->pitch; + long long timestamp = fhPtr->timestamp; + int frameNumber = fhPtr->frameNumber; + void* data = (void*)(m_sharedBuffer + offset + sizeof(FrameHeader)); + SegImage* result = nullptr; + try + { + result = new SegImage(width, height, pitch, data, timestamp, frameNumber); + } + catch (std::bad_alloc &/*e*/) + { + res = ALLOCATION_FAILURE; + result = NULL; + } + *image = result; + } + else + { + res = SERVICE_NOT_READY; + } + m_server->UnlockBuffer(); + return res; +} diff --git a/plugins/win-ivcam/seg_library/SegServerImpl.h b/plugins/win-ivcam/seg_library/SegServerImpl.h new file mode 100644 index 000000000..bad7e6b8d --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegServerImpl.h @@ -0,0 +1,77 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SEG_SERVER_IMPL_H_ +#define SEG_SERVER_IMPL_H_ + +#include "Dependencies.h" +#include "SegImage.h" +#include "SegServer.h" + +#include "seg_service.h" + +typedef struct +{ + int width; + int height; + int pitch; + long long timestamp; + int frameNumber; +} FrameHeader; + +class SegServerImpl : public SegServer +{ +private: + static SegServerImpl* instance; + ISegProc* m_server; + + bool m_comInit; + bool m_serviceConnected; + + LPWSTR m_bufferName; + LPCTSTR m_sharedBuffer; + + SegServerImpl(); + SegServerImpl(SegServerImpl const& src); + SegServerImpl& operator=(const SegServerImpl & src); + +public: + virtual ~SegServerImpl(); + static SegServer* CreateServer(); + static SegServer* GetServerInstance(); + + ServiceStatus Init(); + ServiceStatus Stop(); + void SetFps(int fps) override; + int GetFps() override; + void SetIVCAMMotionRangeTradeOff(int value) override; + int GetIVCAMMotionRangeTradeOff() override; + + ServiceStatus GetFrame(SegImage** image); +}; + +#endif // SEG_SERVER_IMPL_H_ diff --git a/plugins/win-ivcam/seg_library/SegService.h b/plugins/win-ivcam/seg_library/SegService.h new file mode 100644 index 000000000..d374bb100 --- /dev/null +++ b/plugins/win-ivcam/seg_library/SegService.h @@ -0,0 +1,34 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SEG_SERVICE_H_ +#define SEG_SERVICE_H_ + +#include "SegImage.h" +#include "SegServer.h" + +#endif // SEG_SERVICE_H_ diff --git a/plugins/win-ivcam/seg_library/SerServer.cpp b/plugins/win-ivcam/seg_library/SerServer.cpp new file mode 100644 index 000000000..a7bc5cfbc --- /dev/null +++ b/plugins/win-ivcam/seg_library/SerServer.cpp @@ -0,0 +1,39 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "SegServer.h" +#include "SegServerImpl.h" + +SegServer* SegServer::CreateServer() +{ + return SegServerImpl::CreateServer(); +} + +SegServer* SegServer::GetServerInstance() +{ + return SegServerImpl::GetServerInstance(); +} diff --git a/plugins/win-ivcam/seg_service/CMakeLists.txt b/plugins/win-ivcam/seg_service/CMakeLists.txt new file mode 100644 index 000000000..0573efc8b --- /dev/null +++ b/plugins/win-ivcam/seg_service/CMakeLists.txt @@ -0,0 +1,43 @@ +project(seg_service) + +include(IDLFileHelper) + +set(seg_service_IDLS + seg_service.idl + ) + +add_idl_files_with_tlb(seg_service_GENERATED_FILES + ${seg_service_IDLS}) + +include_directories( + ${RSSDK_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ) + +set(seg_service_HEADERS + resource.h + SegProc.h + stdafx.h + targetver.h + xdlldata.h + ) + +set(seg_service_SOURCES + SegProc.rgs + seg_service.rgs + seg_service.cpp + SegProc.cpp + stdafx.cpp + xdlldata.c + seg_service.rc + ${seg_service_GENERATED_FILES} + ) + +add_executable(seg_service WIN32 + ${seg_service_SOURCES} + ${seg_service_HEADERS}) + +target_link_libraries(seg_service + ) + +install_obs_datatarget(seg_service "obs-plugins/win-ivcam") diff --git a/plugins/win-ivcam/seg_service/SegProc.cpp b/plugins/win-ivcam/seg_service/SegProc.cpp new file mode 100644 index 000000000..808a330a5 --- /dev/null +++ b/plugins/win-ivcam/seg_service/SegProc.cpp @@ -0,0 +1,35 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// SegProc.cpp : Implementation of CSegProc + +#include "stdafx.h" +#include "SegProc.h" + + +// CSegProc + diff --git a/plugins/win-ivcam/seg_service/SegProc.h b/plugins/win-ivcam/seg_service/SegProc.h new file mode 100644 index 000000000..346caea92 --- /dev/null +++ b/plugins/win-ivcam/seg_service/SegProc.h @@ -0,0 +1,508 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// SegProc.h : Declaration of the CSegProc + +#pragma once +#include "resource.h" // main symbols +#include "seg_service.h" + +#include "pxcsession.h" +#include "pxcsensemanager.h" +#include "pxc3dseg.h" + +#include + +#include +#include +#include + +#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA) +#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms." +#endif + +using namespace ATL; + + +/* Number of milliseconds service waits for worker thread to start */ +#define START_TIMEOUT 2000 +#define USE_DEFAULT_PROPERTY_VALUE -1 + +// CSegProc + +typedef struct _frameHeader +{ + int width; + int height; + int pitch; + long long timestamp; + int frameNumber; +} FrameHeader; + +class ATL_NO_VTABLE CSegProc : + public CComObjectRootEx, + public CComCoClass, + public IDispatchImpl, + public PXCSenseManager::Handler +{ +private: + enum { + DEPTH_PROPERTY_NORMAL_MODE = 0x03, + DEPTH_PROPERTY_HDR_MODE = 0x200 + }; + // Service state section + HANDLE m_loopThreadHandle; + bool m_procRun; + HANDLE m_hStartedEvt; + + // Shared memory section + std::wstring m_bufferName; + HANDLE m_sharedBufferHandle; + LPCTSTR m_sharedBuffer; + bool m_bufferRealloc; + + // Frames section + int m_currentFrame; + int m_frameToRead; + size_t m_frameSize; + const static size_t headerSize = sizeof(FrameHeader); + CRITICAL_SECTION m_frameAccess[2]; + + // RSSDK section + PXCSenseManager* m_senseManager; + PXC3DSeg* m_segModule; + int m_fps; + int m_motionRangeTradeOff; + + bool m_processing; + bool m_isPause; + std::condition_variable m_cvPause; + std::mutex m_pauseMtx; + + pxcStatus PXCAPI OnModuleSetProfile(pxcUID /*mid*/, PXCBase* /*module*/) override + { + PXCCaptureManager* captureMgr = m_senseManager->QueryCaptureManager(); + if (!captureMgr || m_fps != 60) + return PXC_STATUS_NO_ERROR; + PXCCapture::Device* device = captureMgr->QueryDevice(); + PXCCapture::Device::PropertyInfo propInfo = device->QueryIVCAMMotionRangeTradeOffInfo(); + + int value = m_motionRangeTradeOff; + if (m_motionRangeTradeOff == USE_DEFAULT_PROPERTY_VALUE) + value = (int)propInfo.defaultValue; + + device->SetIVCAMMotionRangeTradeOff(value); + return PXC_STATUS_NO_ERROR; + } + + pxcStatus senseMgrInit() + { + pxcStatus status = PXC_STATUS_NO_ERROR; + status = m_senseManager->Enable3DSeg(nullptr); + if (status != PXC_STATUS_NO_ERROR) + return status; + m_segModule = m_senseManager->Query3DSeg(); + if (!m_segModule) + return PXC_STATUS_DATA_UNAVAILABLE; + + + + for (int i = 0; ; i++) { + pxcStatus status = PXC_STATUS_NO_ERROR; + PXCVideoModule::DataDesc currentProfile = {}; + status = m_segModule->QueryInstance()->QueryCaptureProfile(i, ¤tProfile); + if (status != PXC_STATUS_NO_ERROR) + return status; + if ((currentProfile.streams.depth.propertySet != DEPTH_PROPERTY_NORMAL_MODE) + || (currentProfile.streams.depth.options & PXCCapture::Device::STREAM_OPTION_DEPTH_CONFIDENCE)) { + continue; + } + + m_senseManager->QueryCaptureManager()->FilterByStreamProfiles(nullptr); + m_senseManager->QueryCaptureManager()->FilterByStreamProfiles(nullptr); + + m_senseManager->QueryCaptureManager()->FilterByStreamProfiles(PXCCapture::StreamType::STREAM_TYPE_COLOR, 0, 0, m_fps); + m_senseManager->QueryCaptureManager()->FilterByStreamProfiles(PXCCapture::StreamType::STREAM_TYPE_DEPTH, 0, 0, m_fps); + + status = m_senseManager->EnableStreams(¤tProfile); + if (status != PXC_STATUS_NO_ERROR) + return status; + status = m_senseManager->Init(this); + if (status == PXC_STATUS_NO_ERROR) { + m_isPause = false; + break; + } + else { + continue; + } + } + + return status; + } + + HRESULT reinit() + { + m_isPause = true; + //wait_for_end_processing + while (m_processing) + std::this_thread::yield(); + + std::unique_lock lck(m_pauseMtx); + m_senseManager->Close(); + + pxcStatus status = senseMgrInit(); + m_isPause = false; + m_cvPause.notify_one(); + return S_OK; + } + + /* ----------------------------------------------------------------- + * Modification by Jim + * + * To avoid linker issues with the RSSDK .lib files, load via + * LoadLibrary + * ----------------------------------------------------------------- */ + typedef int (WINAPI *PXCSessionCreateProc)(PXCSession **output); + + static HMODULE GetLib() + { + HMODULE lib = nullptr; + HKEY key = nullptr; + wchar_t path[1024]; + + LONG res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Intel\\RSSDK\\Dispatch", 0, KEY_QUERY_VALUE, &key); + if (res != ERROR_SUCCESS) { + res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Intel\\RSSDK\\v10\\Dispatch", 0, KEY_QUERY_VALUE, &key); + } + + if (res != ERROR_SUCCESS) + return nullptr; + + DWORD size = 1024; + res = RegQueryValueExW(key, L"Core", nullptr, nullptr, (LPBYTE)path, &size); + if (res == ERROR_SUCCESS) { + lib = LoadLibrary(path); + } + + RegCloseKey(key); + return lib; + } + + static PXCSenseManager* CreateSessionInstance() + { + static bool initialized = false; + static HMODULE lib = nullptr; + static PXCSessionCreateProc create = nullptr; + + if (!initialized) { + lib = GetLib(); + create = (PXCSessionCreateProc)GetProcAddress(lib, "PXCSession_Create"); + initialized = true; + } + + if (!lib || !create) + return nullptr; + + PXCSession *session = nullptr; + int test = create(&session); + if (test != 0 || !session) + return nullptr; + + PXCSenseManager *sm = session->CreateSenseManager(); + session->Release(); + return sm; + } + + /* ----------------------------------------------------------------- + * End Modification + * ----------------------------------------------------------------- */ + +public: + CSegProc() + : m_isPause(true) + , m_fps(0) + , m_processing(false) + , m_motionRangeTradeOff(USE_DEFAULT_PROPERTY_VALUE) + { + } + + DECLARE_REGISTRY_RESOURCEID(IDR_SEGPROC) + + DECLARE_NOT_AGGREGATABLE(CSegProc) + + BEGIN_COM_MAP(CSegProc) + COM_INTERFACE_ENTRY(ISegProc) + COM_INTERFACE_ENTRY(IDispatch) + END_COM_MAP() + + DECLARE_PROTECT_FINAL_CONSTRUCT() + + HRESULT FinalConstruct() + { + return S_OK; + } + + void FinalRelease() + { + } + + HRESULT STDMETHODCALLTYPE Init(LPCWSTR bufferName) + { + m_frameSize = 16; + m_frameToRead = -1; + + m_bufferName = bufferName; + + m_sharedBufferHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 2 * m_frameSize, m_bufferName.c_str()); + if (m_sharedBufferHandle == NULL) + return E_FAIL; + m_sharedBuffer = (LPTSTR)MapViewOfFile(m_sharedBufferHandle, FILE_MAP_ALL_ACCESS, 0, 0, 32); + if (m_sharedBuffer == NULL) + { + CloseHandle(m_sharedBufferHandle); + return E_FAIL; + } + m_procRun = false; + + /* ----------------------------------------------------------------- + * Modification by Jim + * + * To avoid linker issues with the RSSDK .lib files, load via + * LoadLibrary. + * ----------------------------------------------------------------- */ + m_senseManager = CreateSessionInstance(); + /* ----------------------------------------------------------------- + * End Modification + * ----------------------------------------------------------------- */ + if (!m_senseManager) + return E_FAIL; + + pxcStatus status = senseMgrInit(); + if (status < PXC_STATUS_NO_ERROR) + return E_FAIL; + + m_hStartedEvt = CreateEvent(NULL, FALSE, FALSE, TEXT("StartEvent")); + if (m_hStartedEvt == NULL) + { + return E_FAIL; + } + + if (m_procRun) + return E_FAIL; + m_loopThreadHandle = CreateThread(NULL, 0, &CSegProc::LoopStub, this, 0, NULL); + if (m_loopThreadHandle == NULL) + { + return E_OUTOFMEMORY; + } + /* Waiting thread for start */ + DWORD dwWaitResult = WaitForSingleObject(m_hStartedEvt, INFINITE); + switch (dwWaitResult) + { + case WAIT_OBJECT_0: + return S_OK; + } + return E_FAIL; + } + + static DWORD WINAPI LoopStub(LPVOID lpParam) + { + if (!lpParam) return -1; + return ((CSegProc*)lpParam)->Loop(NULL); + } + + DWORD WINAPI Loop(LPVOID /*lpParam*/) + { + static const int headerSize = sizeof(FrameHeader); + InitializeCriticalSection(&m_frameAccess[0]); + InitializeCriticalSection(&m_frameAccess[1]); + // Loop through frames + m_procRun = true; + SetEvent(m_hStartedEvt); + m_currentFrame = 0; + int frameCounter = 0; + while (m_procRun) + { + m_processing = false; + + if (m_isPause) + { + std::unique_lock lck(m_pauseMtx); + while (m_isPause) + m_cvPause.wait(lck); + } + + m_processing = true; + if (m_senseManager->AcquireFrame(true) != PXC_STATUS_NO_ERROR) + { + continue; + } + + EnterCriticalSection(&m_frameAccess[m_currentFrame]); + { + PXCImage* segImage = m_segModule->AcquireSegmentedImage(); + if (segImage) + { + PXCImage::ImageData segData; + ZeroMemory(&segData, sizeof(segData)); + pxcStatus sts = segImage->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PixelFormat::PIXEL_FORMAT_RGB32, &segData); + if (sts >= PXC_STATUS_NO_ERROR) + { + int newFrameSize = segData.pitches[0] * segImage->QueryInfo().height + headerSize; + if (newFrameSize != (int)m_frameSize) + { + EnterCriticalSection(&m_frameAccess[1 - m_currentFrame]); + ResizeBuffer(newFrameSize * 2); + m_frameSize = newFrameSize; + m_bufferRealloc = true; + LeaveCriticalSection(&m_frameAccess[1 - m_currentFrame]); + } + int offset = m_frameSize*m_currentFrame; + //((int*)m_sharedBuffer)[offset+0] = segImage->QueryInfo().width; + //((int*)m_sharedBuffer)[offset+1] = segImage->QueryInfo().height; + //((int*)m_sharedBuffer)[offset+2] = segData.pitches[0]; + char *ptr = ((char*)m_sharedBuffer) + offset; + PXCImage::ImageInfo info = segImage->QueryInfo(); + FrameHeader *fhPtr = (FrameHeader*)ptr; + fhPtr->width = info.width; + fhPtr->height = info.height; + fhPtr->pitch = segData.pitches[0]; + fhPtr->timestamp = segImage->QueryTimeStamp(); + fhPtr->frameNumber = frameCounter; + memcpy_s((void*)((char*)m_sharedBuffer + offset + headerSize), m_frameSize - headerSize, segData.planes[0], m_frameSize - headerSize); + segImage->ReleaseAccess(&segData); + } + segImage->Release(); + } + } + m_currentFrame = 1 - m_currentFrame; + LeaveCriticalSection(&m_frameAccess[m_currentFrame]); + + m_senseManager->ReleaseFrame(); + frameCounter++; + } + + DeleteCriticalSection(&m_frameAccess[0]); + DeleteCriticalSection(&m_frameAccess[1]); + + return 0; + } + + // Bad function for the reason of outside syncronization + HRESULT ResizeBuffer(size_t newSize) + { + UnmapViewOfFile(m_sharedBuffer); + CloseHandle(m_sharedBufferHandle); + m_sharedBufferHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, newSize, m_bufferName.c_str()); + + if (!m_sharedBufferHandle) + return E_ACCESSDENIED; + m_sharedBuffer = (LPTSTR)MapViewOfFile(m_sharedBufferHandle, FILE_MAP_ALL_ACCESS, 0, 0, newSize); + + if (!m_sharedBuffer) + { + CloseHandle(m_sharedBufferHandle); + return E_OUTOFMEMORY; + } + ZeroMemory((void*)m_sharedBuffer, newSize); + return S_OK; + } + + HRESULT STDMETHODCALLTYPE LockBuffer(int* frameId, int* frameSize, int* bufferRealloc) + { + if (!m_procRun || m_frameToRead != -1) + return E_FAIL; + m_frameToRead = 1 - m_currentFrame; + EnterCriticalSection(&m_frameAccess[m_frameToRead]); + *frameId = m_frameToRead; + if (m_bufferRealloc) + { + *bufferRealloc = (int)m_bufferRealloc; + m_bufferRealloc = false; + } + else + *bufferRealloc = false; + *frameSize = m_frameSize; + return S_OK; + } + + HRESULT STDMETHODCALLTYPE UnlockBuffer() + { + if (!m_procRun || m_frameToRead == -1) + { + return E_FAIL; + } + LeaveCriticalSection(&m_frameAccess[m_frameToRead]); + m_frameToRead = -1; + return S_OK; + } + + HRESULT STDMETHODCALLTYPE Stop() + { + if (!m_procRun) + { + return E_FAIL; + } + m_procRun = false; + WaitForSingleObject(m_loopThreadHandle, INFINITE); + m_senseManager->Close(); + return S_OK; + } + + HRESULT STDMETHODCALLTYPE SetFps(int fps) + { + if (m_fps == fps) + return S_OK; + m_fps = fps; + if (m_procRun) + return reinit(); + return S_OK; + } + + HRESULT STDMETHODCALLTYPE GetFps(int* fps) + { + *fps = m_fps; + return S_OK; + } + + HRESULT STDMETHODCALLTYPE SetIVCAMMotionRangeTradeOff(int value) + { + if (m_motionRangeTradeOff == value) + return S_OK; + m_motionRangeTradeOff = value; + if (m_procRun) + return reinit(); + return S_OK; + } + + HRESULT STDMETHODCALLTYPE GetIVCAMMotionRangeTradeOff(int* value) + { + *value = m_motionRangeTradeOff; + return S_OK; + } +}; + +OBJECT_ENTRY_AUTO(__uuidof(SegProc), CSegProc) diff --git a/plugins/win-ivcam/seg_service/SegProc.rgs b/plugins/win-ivcam/seg_service/SegProc.rgs new file mode 100644 index 000000000..6c8b66fdf --- /dev/null +++ b/plugins/win-ivcam/seg_service/SegProc.rgs @@ -0,0 +1,16 @@ +HKCR +{ + NoRemove CLSID + { + ForceRemove {66917998-CA70-42A6-B8AE-A3A5126123C7} = s 'SegProc Class' + { + ForceRemove Programmable + LocalServer32 = s '%MODULE%' + { + val ServerExecutable = s '%MODULE_RAW%' + } + TypeLib = s '{64BC16FD-9E3C-4904-B9BA-A360310BCFEC}' + Version = s '1.0' + } + } +} diff --git a/plugins/win-ivcam/seg_service/resource.h b/plugins/win-ivcam/seg_service/resource.h new file mode 100644 index 000000000..e4ea7970d --- /dev/null +++ b/plugins/win-ivcam/seg_service/resource.h @@ -0,0 +1,45 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by seg_service.rc +// +#define IDS_PROJNAME 100 +#define IDR_SEG_SERVICE 101 +#define IDR_SEGPROC 106 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 201 +#define _APS_NEXT_COMMAND_VALUE 32768 +#define _APS_NEXT_CONTROL_VALUE 201 +#define _APS_NEXT_SYMED_VALUE 107 +#endif +#endif diff --git a/plugins/win-ivcam/seg_service/seg_service.cpp b/plugins/win-ivcam/seg_service/seg_service.cpp new file mode 100644 index 000000000..a0f9a1eb9 --- /dev/null +++ b/plugins/win-ivcam/seg_service/seg_service.cpp @@ -0,0 +1,56 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// seg_service.cpp : Implementation of WinMain + + +#include "stdafx.h" +#include "resource.h" +#include "seg_service.h" +#include "xdlldata.h" + +using namespace ATL; + + +class Cseg_serviceModule : public ATL::CAtlExeModuleT< Cseg_serviceModule > +{ +public : + DECLARE_LIBID(LIBID_seg_serviceLib) + DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SEG_SERVICE, "{B5EB3281-4ED1-4777-8ACD-99162EB15E81}") + }; + +Cseg_serviceModule _AtlModule; + + + +// +extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, + LPTSTR /*lpCmdLine*/, int nShowCmd) +{ + return _AtlModule.WinMain(nShowCmd); +} + diff --git a/plugins/win-ivcam/seg_service/seg_service.idl b/plugins/win-ivcam/seg_service/seg_service.idl new file mode 100644 index 000000000..7ff0b5b95 --- /dev/null +++ b/plugins/win-ivcam/seg_service/seg_service.idl @@ -0,0 +1,69 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// seg_service.idl : IDL source for seg_service +// + +// This file will be processed by the MIDL tool to +// produce the type library (seg_service.tlb) and marshalling code. + +import "oaidl.idl"; +import "ocidl.idl"; + +[ + object, + uuid(ADD60B51-95C7-4232-84B0-3CCBBEA7147C), + dual, + nonextensible, + pointer_default(unique) +] +interface ISegProc : IDispatch{ + HRESULT Init(LPCWSTR bufferName); + HRESULT Stop(); + HRESULT LockBuffer(int* frame, int* bufferRealloc, int* frameSize); + HRESULT SetFps(int fps); + HRESULT GetFps(int* fps); + HRESULT SetIVCAMMotionRangeTradeOff(int value); + HRESULT GetIVCAMMotionRangeTradeOff(int* value); + HRESULT UnlockBuffer(); +}; +[ + uuid(64BC16FD-9E3C-4904-B9BA-A360310BCFEC), + version(1.0), +] +library seg_serviceLib +{ + importlib("stdole2.tlb"); + [ + uuid(66917998-CA70-42A6-B8AE-A3A5126123C7) + ] + coclass SegProc + { + [default] interface ISegProc; + }; +}; + diff --git a/plugins/win-ivcam/seg_service/seg_service.rc b/plugins/win-ivcam/seg_service/seg_service.rc new file mode 100644 index 000000000..157522c74 Binary files /dev/null and b/plugins/win-ivcam/seg_service/seg_service.rc differ diff --git a/plugins/win-ivcam/seg_service/seg_service.rgs b/plugins/win-ivcam/seg_service/seg_service.rgs new file mode 100644 index 000000000..e7d37400e --- /dev/null +++ b/plugins/win-ivcam/seg_service/seg_service.rgs @@ -0,0 +1,3 @@ +HKCR +{ +} diff --git a/plugins/win-ivcam/seg_service/stdafx.cpp b/plugins/win-ivcam/seg_service/stdafx.cpp new file mode 100644 index 000000000..296442819 --- /dev/null +++ b/plugins/win-ivcam/seg_service/stdafx.cpp @@ -0,0 +1,32 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// stdafx.cpp : source file that includes just the standard includes +// seg_service.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/plugins/win-ivcam/seg_service/stdafx.h b/plugins/win-ivcam/seg_service/stdafx.h new file mode 100644 index 000000000..48d7dbfb7 --- /dev/null +++ b/plugins/win-ivcam/seg_service/stdafx.h @@ -0,0 +1,52 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +#ifndef STRICT +#define STRICT +#endif + +#include "targetver.h" + +#define _ATL_APARTMENT_THREADED + +#define _ATL_NO_AUTOMATIC_NAMESPACE + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit + + +#define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW + +#include "resource.h" +#include +#include +#include diff --git a/plugins/win-ivcam/seg_service/targetver.h b/plugins/win-ivcam/seg_service/targetver.h new file mode 100644 index 000000000..dc445f096 --- /dev/null +++ b/plugins/win-ivcam/seg_service/targetver.h @@ -0,0 +1,35 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/plugins/win-ivcam/seg_service/xdlldata.c b/plugins/win-ivcam/seg_service/xdlldata.c new file mode 100644 index 000000000..b1ed0761b --- /dev/null +++ b/plugins/win-ivcam/seg_service/xdlldata.c @@ -0,0 +1,44 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +// wrapper for dlldata.c + +#ifdef _MERGE_PROXYSTUB // merge proxy stub DLL + +#define REGISTER_PROXY_DLL //DllRegisterServer, etc. + +#define _WIN32_WINNT 0x0500 //for WinNT 4.0 or Win95 with DCOM +#define USE_STUBLESS_PROXY //defined only with MIDL switch /Oicf + +#pragma comment(lib, "rpcns4.lib") +#pragma comment(lib, "rpcrt4.lib") + +#define ENTRY_PREFIX Prx + +#include "dlldata.c" +#include "seg_service_p.c" + +#endif //_MERGE_PROXYSTUB diff --git a/plugins/win-ivcam/seg_service/xdlldata.h b/plugins/win-ivcam/seg_service/xdlldata.h new file mode 100644 index 000000000..56b117ea8 --- /dev/null +++ b/plugins/win-ivcam/seg_service/xdlldata.h @@ -0,0 +1,42 @@ +/* +Copyright (c) 2015-2016, Intel Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#ifdef _MERGE_PROXYSTUB + +extern "C" +{ +BOOL WINAPI PrxDllMain(HINSTANCE hInstance, DWORD dwReason, + LPVOID lpReserved); +STDAPI PrxDllCanUnloadNow(void); +STDAPI PrxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv); +STDAPI PrxDllRegisterServer(void); +STDAPI PrxDllUnregisterServer(void); +} + +#endif