├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── ACKNOWLEDGEMENTS.txt ├── AUTHORS.txt ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── apps ├── CMakeLists.txt ├── DesktopStreamer │ ├── CMakeLists.txt │ ├── DesktopWindowsModel.h │ ├── DesktopWindowsModel.mm │ ├── MainWindow.cpp │ ├── MainWindow.h │ ├── MainWindow.ui │ ├── Stream.cpp │ ├── Stream.h │ ├── cursor.png │ ├── defaults.cpp │ ├── defaults.h │ ├── defaults.json.in │ ├── desktopstreamer.desktop │ ├── desktopstreamer.icns │ ├── desktopstreamer.ico │ ├── desktopstreamer.png │ ├── main.cpp │ ├── nameUtils.cpp │ ├── nameUtils.h │ ├── nameUtils.mm │ └── resources.qrc ├── QmlStreamer │ ├── CMakeLists.txt │ ├── gui.qml │ ├── main.cpp │ └── resources.qrc └── SimpleStreamer │ ├── CMakeLists.txt │ └── main.cpp ├── deflect ├── AppNapSuspender.h ├── AppNapSuspender.mm ├── CMakeLists.txt ├── Event.cpp ├── Event.h ├── ImageJpegCompressor.cpp ├── ImageJpegCompressor.h ├── ImageSegmenter.cpp ├── ImageSegmenter.h ├── ImageWrapper.cpp ├── ImageWrapper.h ├── MTQueue.h ├── MessageHeader.cpp ├── MessageHeader.h ├── MetaTypeRegistration.cpp ├── NetworkProtocol.h ├── Observer.cpp ├── Observer.h ├── Segment.h ├── SegmentParameters.h ├── SizeHints.h ├── Socket.cpp ├── Socket.h ├── Stream.cpp ├── Stream.h ├── StreamPrivate.cpp ├── StreamPrivate.h ├── StreamSendWorker.cpp ├── StreamSendWorker.h ├── TaskBuilder.cpp ├── TaskBuilder.h ├── moodycamel │ ├── blockingconcurrentqueue.h │ └── concurrentqueue.h ├── qt │ ├── CMakeLists.txt │ ├── EventReceiver.cpp │ ├── EventReceiver.h │ ├── OffscreenQuickView.cpp │ ├── OffscreenQuickView.h │ ├── QmlGestures.h │ ├── QmlStreamer.cpp │ ├── QmlStreamer.h │ ├── QmlStreamerImpl.cpp │ ├── QmlStreamerImpl.h │ ├── QuickRenderer.cpp │ ├── QuickRenderer.h │ ├── TouchInjector.cpp │ ├── TouchInjector.h │ └── types.h ├── server │ ├── CMakeLists.txt │ ├── EventReceiver.h │ ├── Frame.cpp │ ├── Frame.h │ ├── FrameDispatcher.cpp │ ├── FrameDispatcher.h │ ├── ImageJpegDecompressor.cpp │ ├── ImageJpegDecompressor.h │ ├── ReceiveBuffer.cpp │ ├── ReceiveBuffer.h │ ├── Server.cpp │ ├── Server.h │ ├── ServerWorker.cpp │ ├── ServerWorker.h │ ├── SourceBuffer.cpp │ ├── SourceBuffer.h │ ├── Tile.h │ ├── TileDecoder.cpp │ ├── TileDecoder.h │ └── types.h └── types.h ├── doc ├── CMakeLists.txt ├── Changelog.md ├── ChromaSubsampling.md ├── StereoStreaming.md ├── overview.png ├── overview.svg ├── stereo.png └── stereo.svg └── tests ├── CMakeLists.txt ├── cpp ├── CMakeLists.txt ├── FrameDispatcherTests.cpp ├── FrameTests.cpp ├── ImageSegmenterTests.cpp ├── ImageWrapperTests.cpp ├── NetworkSerializationTests.cpp ├── ReceiveBufferTests.cpp ├── ServerTests.cpp ├── SocketTests.cpp ├── StreamTests.cpp ├── TileDecoderTests.cpp └── perf │ ├── benchmarkStreamer.cpp │ └── streamTests.cpp └── mock ├── CMakeLists.txt ├── DeflectServer.cpp ├── DeflectServer.h ├── FrameUtils.h ├── MinimalDeflectServer.cpp ├── MinimalDeflectServer.h ├── MinimalGlobalQtApp.h ├── MockServer.cpp ├── MockServer.h ├── Timer.h └── boost_test_thread_safe.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | AccessModifierOffset: -4 3 | AlignConsecutiveAssignments: false 4 | AlignConsecutiveDeclarations: false 5 | AlignEscapedNewlinesLeft: true 6 | AlignOperands: true 7 | AlignTrailingComments: true 8 | AllowAllParametersOfDeclarationOnNextLine: true 9 | AllowShortFunctionsOnASingleLine: Inline 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AlwaysBreakBeforeMultilineStrings: true 13 | AlwaysBreakTemplateDeclarations: true 14 | BinPackParameters: true 15 | BreakBeforeBinaryOperators: false 16 | BreakBeforeBraces: Allman # brace on new line 17 | BreakBeforeTernaryOperators: true 18 | BreakConstructorInitializersBeforeComma: true 19 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 20 | ConstructorInitializerIndentWidth: 4 21 | ContinuationIndentWidth: 4 22 | Cpp11BracedListStyle: true 23 | DerivePointerBinding: true 24 | ExperimentalAutoDetectBinPacking: false 25 | IndentCaseLabels: false 26 | IndentFunctionDeclarationAfterType: true 27 | IndentWidth: 4 28 | KeepEmptyLinesAtTheStartOfBlocks: false 29 | Language: Cpp 30 | MaxEmptyLinesToKeep: 1 31 | NamespaceIndentation: None 32 | PenaltyBreakBeforeFirstCallParameter: 100 33 | PenaltyBreakComment: 60 34 | PenaltyBreakFirstLessLess: 120 35 | PenaltyBreakString: 1000 36 | PenaltyExcessCharacter: 1000000 37 | PenaltyReturnTypeOnItsOwnLine: 200 38 | PointerBindsToType: true 39 | SortIncludes: true 40 | SpaceAfterControlStatementKeyword: true 41 | SpaceBeforeAssignmentOperators: true 42 | SpaceBeforeParens: ControlStatements 43 | SpaceInEmptyParentheses: false 44 | SpacesBeforeTrailingComments: 1 45 | SpacesInAngles: false # '< ' style 46 | SpacesInCStyleCastParentheses: false 47 | SpacesInParentheses: false # '(' style 48 | Standard: Cpp11 49 | TabWidth: 4 50 | UseTab: Never 51 | ... 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Makefile 3 | CMakeLists.txt.user* 4 | build/ 5 | ___* 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CMake/common"] 2 | path = CMake/common 3 | url = https://github.com/Eyescale/CMake 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | notifications: 2 | email: 3 | on_success: never 4 | language: cpp 5 | matrix: 6 | include: 7 | - os: linux 8 | dist: trusty 9 | sudo: required 10 | env: BUILD_TYPE=Debug 11 | - os: linux 12 | dist: trusty 13 | sudo: required 14 | env: BUILD_TYPE=Release 15 | - os: osx 16 | env: BUILD_TYPE=Debug 17 | - os: osx 18 | env: BUILD_TYPE=Release 19 | sudo: false 20 | env: 21 | global: 22 | - NINJA_STATUS="[%p %u/%t@%o %r]" 23 | - PROJECT_NAME=${PWD##*/} 24 | - CMAKE_PREFIX_PATH=/usr/local/opt/qt5:$CMAKE_PREFIX_PATH 25 | - LIBJPEGTURBO_ROOT=/usr/local/opt/jpeg-turbo 26 | addons: 27 | apt: 28 | packages: 29 | - cppcheck 30 | - clang-format-3.8 31 | - doxygen 32 | - ninja-build 33 | - libboost-all-dev 34 | - freeglut3-dev 35 | - libxi-dev 36 | - libxmu-dev 37 | - libjpeg-turbo8-dev 38 | - libturbojpeg 39 | - qtbase5-dev 40 | - qtdeclarative5-dev 41 | - libqt5opengl5-dev 42 | before_install: 43 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 44 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew outdated cmake || brew upgrade cmake; fi 45 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install cppcheck doxygen ninja clang-format jpeg-turbo qt5; fi 46 | script: 47 | - mkdir $BUILD_TYPE 48 | - cd $BUILD_TYPE 49 | - cmake -GNinja -DCLONE_SUBPROJECTS=ON -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. 50 | - ninja all && ninja $PROJECT_NAME-tests && ninja smoketests 51 | - find . -name '*.[hc]' -o -name '*.[hci]pp' -o -name '*.frag' -o -name '*.vert' -o -name '*.ispc' -o -name '*.ih' | grep -v 'CMake/common' | xargs clang-format -style=file -fallback-style=none -i 52 | - git diff 53 | - git diff-index --quiet HEAD -- 54 | -------------------------------------------------------------------------------- /ACKNOWLEDGEMENTS.txt: -------------------------------------------------------------------------------- 1 | =========================================================================== 2 | moodycamel::ConcurrentQueue (https://github.com/cameron314/concurrentqueue) 3 | =========================================================================== 4 | 5 | Simplified BSD License: 6 | 7 | Copyright (c) 2013-2016, Cameron Desrochers. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | - Redistributions of source code must retain the above copyright notice, this list of 14 | conditions and the following disclaimer. 15 | - Redistributions in binary form must reproduce the above copyright notice, this list of 16 | conditions and the following disclaimer in the documentation and/or other materials 17 | provided with the distribution. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 24 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 26 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Raphael Dumusc 2 | Stefan Eilemann 3 | Juan Bautista Hernando Vieites 4 | Daniel Nachbaur 5 | Pawel Jozef Podhajski 6 | Jafet Villafranca Diaz 7 | 8 | Ben Simons (contributor) 9 | Ahmet Bilgili (contributor) 10 | Cyrille Favreau (contributor) 11 | Jonas Karlsson (contributor) 12 | Pablo Toharia (contributor) 13 | Patric Schmitz (contributor) 14 | Judit Planas Carbonell (contributor) 15 | Nadir Roman Guerrero (contributor) 16 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2018, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | # Daniel Nachbaur 5 | 6 | cmake_minimum_required(VERSION 3.1 FATAL_ERROR) 7 | project(Deflect VERSION 1.0.2) 8 | set(Deflect_VERSION_ABI 7) 9 | 10 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/common) 11 | if(NOT EXISTS ${CMAKE_SOURCE_DIR}/CMake/common/Common.cmake) 12 | message(FATAL_ERROR "CMake/common missing, run: git submodule update --init") 13 | endif() 14 | 15 | set(DEFLECT_DESCRIPTION "A fast C++ library for streaming pixels and events") 16 | set(DEFLECT_MAINTAINER "Blue Brain Project ") 17 | set(DEFLECT_VENDOR "Blue Brain Project") 18 | set(DEFLECT_LICENSE LGPL) 19 | set(DEFLECT_DEB_DEPENDS freeglut3-dev libxi-dev libxmu-dev 20 | libjpeg-turbo8-dev libturbojpeg 21 | libboost-program-options-dev libboost-test-dev 22 | qtbase5-dev qtdeclarative5-dev 23 | ) 24 | include(LSBInfo) 25 | if(LSB_DISTRIBUTOR_ID STREQUAL "Ubuntu" AND LSB_RELEASE VERSION_GREATER 16.04) 26 | list(APPEND DEFLECT_DEB_DEPENDS libturbojpeg0-dev) 27 | endif() 28 | set(DEFLECT_PORT_DEPENDS boost freeglut qt5) 29 | set(DEFLECT_BREW_DEPENDS boost freeglut jpeg-turbo qt5) 30 | 31 | include(Common) 32 | 33 | common_find_package(Boost COMPONENTS program_options unit_test_framework) 34 | common_find_package(GLUT) 35 | common_find_package(LibJpegTurbo 1.4) 36 | if(NOT LibJpegTurbo_FOUND) 37 | common_find_package(LibJpegTurbo 1.2 REQUIRED) 38 | list(APPEND COMMON_FIND_PACKAGE_DEFINES DEFLECT_USE_LEGACY_LIBJPEGTURBO) 39 | endif() 40 | common_find_package(OpenGL) 41 | common_find_package(OpenMP) 42 | common_find_package(Qt5Concurrent REQUIRED SYSTEM) 43 | common_find_package(Qt5Core REQUIRED) 44 | if(APPLE) 45 | common_find_package(Qt5MacExtras) 46 | endif() 47 | common_find_package(Qt5Network REQUIRED) 48 | common_find_package(Qt5Qml) 49 | common_find_package(Qt5Quick) 50 | common_find_package(Qt5OpenGL) 51 | common_find_package(Qt5Widgets REQUIRED) 52 | common_find_package_post() 53 | 54 | if(NOT Qt5Quick_VERSION VERSION_LESS 5.5) 55 | option(DEFLECT_QMLSTREAMER_MULTITHREADED "Use multithreaded-rendering in QMLStreamer" ON) 56 | endif() 57 | 58 | set(LCOV_EXCLUDE "deflect/moodycamel/*") 59 | 60 | add_subdirectory(deflect) 61 | add_subdirectory(apps) 62 | if(Boost_FOUND) 63 | add_subdirectory(tests) 64 | endif() 65 | add_subdirectory(doc) 66 | 67 | # Export public package dependencies, used in CommonPackageConfig 68 | if(TARGET DeflectQt) 69 | set(DEFLECT_DEPENDENT_LIBRARIES Qt5Quick) 70 | endif() 71 | 72 | # Name the package "desktopstreamer" instead of "deflect" 73 | set(CPACK_PACKAGE_NAME "desktopstreamer") 74 | set(DEFLECT_PACKAGE_DEB_DEPENDS qtbase5-dev libturbojpeg) 75 | include(CommonCPack) # also includes CommonPackageConfig 76 | 77 | set(COMMON_PROJECT_DOMAIN ch.epfl.bluebrain) 78 | set(DOXYGEN_MAINPAGE_MD README.md) 79 | set(DOXYGEN_EXTRA_INPUT ${PROJECT_SOURCE_DIR}/README.md) 80 | include(DoxygenRule) # must be after all targets 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deflect 2 | 3 | Welcome to Deflect, a C++ library for streaming pixels to other Deflect-based 4 | applications, for example [Tide](https://github.com/BlueBrain/Tide). 5 | Deflect offers a stable API marked with version 1.0 (for the client part). 6 | 7 | ## Overview 8 | 9 | ![Deflect features overview](doc/overview.png) 10 | 11 | ## Features 12 | 13 | Deflect provides the following functionality: 14 | 15 | * Stream pixels to a remote Server from one or multiple sources 16 | * Stream stereo images from a distributed 3D application 17 | * Receive input events from the Server and send data to it 18 | * Transmitted events include keyboard, mouse and multi-point touch gestures 19 | * Compressed or uncompressed streaming 20 | * Fast multi-threaded JPEG (de)compression using libjpeg-turbo 21 | 22 | DeflectQt (optional) provides the following additional functionality: 23 | 24 | * Create QML applications which render offscreen and stream and receive events 25 | via Deflect 26 | 27 | The following applications are provided which make use of the streaming API: 28 | 29 | * DesktopStreamer: A small utility that lets you stream your desktop. 30 | * SimpleStreamer: A simple example to demonstrate streaming of an OpenGL 31 | application. 32 | * QmlStreamer (optional): An offscreen application to stream any given qml file. 33 | 34 | ## Building from source 35 | 36 | ~~~ 37 | git clone --recursive https://github.com/BlueBrain/Deflect.git 38 | mkdir Deflect/build 39 | cd Deflect/build 40 | cmake -GNinja .. 41 | ninja 42 | ~~~ 43 | 44 | ## ChangeLog 45 | 46 | To keep track of the changes between releases check the @ref Changelog. 47 | 48 | ## About 49 | 50 | Deflect is a cross-platform library, designed to run on any modern operating 51 | system, including all Unix variants. Deflect uses CMake to create a 52 | platform-specific build environment. The following platforms and build 53 | environments are tested: 54 | 55 | * Linux: Ubuntu 16.04 and RHEL 6 (Makefile, Ninja; x64) 56 | * Mac OS X: 10.7 - 10.10 (Makefile, Ninja; x86_64) 57 | 58 | The [latest API documentation](http://bluebrain.github.io/Deflect-1.0/index.html) 59 | can be found on [bluebrain.github.io](http://bluebrain.github.io). 60 | 61 | ## Funding & Acknowledgment 62 | 63 | The development of this software was supported by funding to the Blue Brain Project, 64 | a research center of the École polytechnique fédérale de Lausanne (EPFL), from the 65 | Swiss government’s ETH Board of the Swiss Federal Institutes of Technology. 66 | 67 | This project has received funding from the European Union’s FP7-ICT programme 68 | under Grant Agreement No. 604102 (Human Brain Project RUP). 69 | 70 | This project has received funding from the European Union's Horizon 2020 Framework 71 | Programme for Research and Innovation under the Specific Grant Agreement No. 720270 72 | (Human Brain Project SGA1). 73 | 74 | This project is based upon work supported by the King Abdullah University of Science 75 | and Technology (KAUST) Office of Sponsored Research (OSR) under Award No. OSR-2017-CRG6-3438. 76 | 77 | ## License 78 | 79 | Deflect is licensed under the LGPL, unless noted otherwise, e.g., for external dependencies. 80 | See file LICENSE.txt for the full license. External dependencies are either LGPL or BSD-licensed. 81 | See file ACKNOWLEDGEMENTS.txt and AUTHORS.txt for further details. 82 | 83 | Copyright (C) 2013-2023 Blue Brain Project/EPFL and King Abdullah University of Science and 84 | Technology. 85 | 86 | This library is free software; you can redistribute it and/or modify it under the terms of the 87 | GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. 88 | 89 | This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 90 | even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 91 | Lesser General Public License for more details. 92 | 93 | You should have received a copy of the GNU Lesser General Public License along with this library; 94 | if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 95 | MA 02110-1301 USA 96 | 97 | -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2015, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | # Daniel Nachbaur 5 | 6 | add_subdirectory(DesktopStreamer) 7 | 8 | if(TARGET DeflectQt) 9 | add_subdirectory(QmlStreamer) 10 | endif() 11 | 12 | if(GLUT_FOUND) 13 | add_subdirectory(SimpleStreamer) 14 | endif() 15 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2018, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | 5 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) # for autogenerated ui_* file 6 | 7 | set(DESKTOPSTREAMER_HEADERS 8 | defaults.h 9 | MainWindow.h 10 | nameUtils.h 11 | Stream.h 12 | ) 13 | 14 | set(DESKTOPSTREAMER_SOURCES 15 | defaults.cpp 16 | main.cpp 17 | MainWindow.cpp 18 | MainWindow.ui 19 | resources.qrc 20 | Stream.cpp 21 | ) 22 | 23 | set(DESKTOPSTREAMER_LINK_LIBRARIES 24 | Deflect 25 | Qt5::Core 26 | Qt5::Network 27 | Qt5::Widgets 28 | ) 29 | 30 | set(DEFLECT_DESKTOPSTREAMER_HOSTS 31 | "\ 32 | {\"DisplayWall Ground floor\", \"bbpav02.bbp.epfl.ch\"}, \ 33 | {\"DisplayWall 3rd floor\", \"bbpav04.bbp.epfl.ch\"}, \ 34 | {\"OpenDeck 4th floor\", \"cave1.bbp.epfl.ch\"}, \ 35 | {\"DisplayWall 5th floor\", \"bbpav05.bbp.epfl.ch\"}, \ 36 | {\"DisplayWall 6th floor\", \"bbpav06.bbp.epfl.ch\"}" 37 | CACHE STRING "List of default hosts for the DesktopStreamer application" 38 | ) 39 | set_source_files_properties(defaults.cpp PROPERTIES COMPILE_DEFINITIONS 40 | _DEFAULT_HOSTS=${DEFLECT_DESKTOPSTREAMER_HOSTS} 41 | ) 42 | 43 | set(DESKTOPSTREAMER_APP_NAME desktopstreamer) 44 | 45 | if(APPLE) 46 | set(DESKTOPSTREAMER_APP_NAME DesktopStreamer) 47 | string(TIMESTAMP _CURRENT_YEAR "%Y") 48 | set(DESKTOPSTREAMER_COPYRIGHT "EPFL/Blue Brain Project ${_CURRENT_YEAR}") 49 | 50 | list(APPEND DESKTOPSTREAMER_SOURCES nameUtils.mm) 51 | list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework Foundation") 52 | 53 | if(TARGET Qt5::MacExtras) 54 | list(APPEND DESKTOPSTREAMER_HEADERS DesktopWindowsModel.h) 55 | list(APPEND DESKTOPSTREAMER_SOURCES DesktopWindowsModel.mm) 56 | list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES 57 | Qt5::MacExtras "-framework AppKit" 58 | ) 59 | endif() 60 | if(OSX_VERSION VERSION_LESS 10.9) 61 | list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework ApplicationServices") 62 | else() 63 | list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework CoreGraphics") 64 | endif() 65 | 66 | # Configure 'defaults.json' and copy it in the app bundle's 'Resources' folder 67 | string(REGEX REPLACE "\"," "\":" _JSON_HOSTS ${DEFLECT_DESKTOPSTREAMER_HOSTS}) 68 | set(_defaults_file ${CMAKE_CURRENT_BINARY_DIR}/defaults.json) 69 | configure_file(defaults.json.in ${_defaults_file}) 70 | list(APPEND DESKTOPSTREAMER_SOURCES ${_defaults_file}) 71 | set_source_files_properties(${_defaults_file} PROPERTIES 72 | MACOSX_PACKAGE_LOCATION Resources) 73 | else() 74 | list(APPEND DESKTOPSTREAMER_SOURCES nameUtils.cpp) 75 | endif() 76 | 77 | if(MSVC) 78 | list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES Ws2_32) 79 | endif() 80 | 81 | common_application(${DESKTOPSTREAMER_APP_NAME} GUI NOHELP) 82 | 83 | if(APPLE) 84 | # create a zip for Puppet deployment 85 | install(CODE "execute_process(COMMAND zip -r 86 | ${DESKTOPSTREAMER_APP_NAME}-${PROJECT_VERSION}.zip ${DESKTOPSTREAMER_APP_NAME}.app 87 | WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)" COMPONENT apps) 88 | endif() 89 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/DesktopWindowsModel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, EPFL/Blue Brain Project 2 | * Daniel.Nachbaur@epfl.ch 3 | * 4 | * This file is part of Deflect 5 | * 6 | * This library is free software; you can redistribute it and/or modify it under 7 | * the terms of the GNU Lesser General Public License version 3.0 as published 8 | * by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 | * details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #ifndef DESKTOPSTREAMER_DESKTOPWINDOWSMODEL_H 21 | #define DESKTOPSTREAMER_DESKTOPWINDOWSMODEL_H 22 | 23 | #include 24 | #include 25 | 26 | /** 27 | * Item Model which contains all open applications on OSX and updates 28 | * accordingly to new and closed applications. 29 | */ 30 | class DesktopWindowsModel : public QAbstractListModel 31 | { 32 | public: 33 | DesktopWindowsModel(); 34 | 35 | int rowCount(const QModelIndex&) const final; 36 | 37 | /** @return application name for Qt::DisplayRole, window preview pixmap for 38 | * Qt::DecorationRole, original size pixmap for ROLE_PIXMAP, window 39 | * rectangle for ROLE_RECT 40 | */ 41 | QVariant data(const QModelIndex& index, int role) const final; 42 | 43 | enum DataRole 44 | { 45 | ROLE_PIXMAP = Qt::UserRole, 46 | ROLE_RECT, 47 | ROLE_PID 48 | }; 49 | 50 | /** @internal */ 51 | void addApplication(void* app); 52 | 53 | /** @internal */ 54 | void removeApplication(void* app); 55 | 56 | /** 57 | * Check if the application corresponding to the specified PID is currently 58 | * active 59 | * 60 | * @param pid the application process id 61 | * @return true if the application with the PID specified is currently 62 | * active. A pid of 0 means the full desktop, always active 63 | */ 64 | static bool isActive(int pid); 65 | 66 | /** 67 | * Activate the application corresponding to the specified PID. This will 68 | * send the application to the front 69 | * 70 | * @param pid the application process id 71 | */ 72 | static void activate(int pid); 73 | 74 | private: 75 | class Impl; 76 | std::unique_ptr _impl; 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/Stream.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2016-2016, EPFL/Blue Brain Project */ 3 | /* Stefan.Eilemann@epfl.ch */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of The Ecole Polytechnique Federal de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DESKTOPSTREAMER_STREAM_H 41 | #define DESKTOPSTREAMER_STREAM_H 42 | 43 | #include // member 44 | #include // member 45 | #include // member 46 | #include // base class 47 | 48 | class MainWindow; 49 | 50 | class stream_failure : public std::runtime_error 51 | { 52 | using runtime_error::runtime_error; 53 | }; 54 | 55 | class Stream : public deflect::Stream 56 | { 57 | public: 58 | /** Construct a new stream for the given desktop window. */ 59 | Stream(const MainWindow& parent, const QPersistentModelIndex window, 60 | const std::string& id, const std::string& host, int pid = 0); 61 | ~Stream(); 62 | 63 | /** 64 | * Send an update to the server. 65 | * @param compress the image in jpeg 66 | * @param quality the quality setting for compression [1; 100]. 67 | * @param subsamp the chrominance subsampling mode. 68 | * @throw stream_failure on error. 69 | */ 70 | void update(bool compress, int quality, deflect::ChromaSubsampling subsamp); 71 | 72 | /** 73 | * Process all pending events. 74 | * 75 | * @param interact enable interaction from the server 76 | * @return true on success, false if the stream should be closed. 77 | */ 78 | bool processEvents(bool interact); 79 | 80 | const QPersistentModelIndex& getIndex() const; 81 | 82 | private: 83 | Stream(const Stream&) = delete; 84 | Stream(Stream&&) = delete; 85 | 86 | class Impl; 87 | std::unique_ptr _impl; 88 | }; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/cursor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/apps/DesktopStreamer/cursor.png -------------------------------------------------------------------------------- /apps/DesktopStreamer/defaults.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "defaults.h" 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | 51 | namespace defaults 52 | { 53 | std::vector> getHosts() 54 | { 55 | #ifdef __APPLE__ 56 | const auto appPath = QApplication::applicationDirPath(); 57 | QFile file{appPath + "/../Resources/defaults.json"}; 58 | if (!file.exists() || !file.open(QIODevice::ReadOnly)) 59 | { 60 | std::cerr << "could not open file 'defaults.json'" << std::endl; 61 | return {}; 62 | } 63 | QJsonParseError error; 64 | const auto doc = QJsonDocument::fromJson(file.readAll(), &error); 65 | if (doc.isNull()) 66 | { 67 | std::cerr << "defaults.json parsing error: " 68 | << error.errorString().toStdString() << std::endl; 69 | return {}; 70 | } 71 | std::vector> hosts; 72 | for (const auto& value : doc.object()["hosts"].toArray()) 73 | { 74 | const auto entry = value.toObject(); 75 | if (entry.size() != 1) 76 | continue; 77 | const auto name = entry.begin().key(); 78 | const auto addr = entry.begin().value().toString(); 79 | if (!name.isEmpty() && !addr.isEmpty()) 80 | hosts.emplace_back(name, addr); 81 | } 82 | return hosts; 83 | #else 84 | return {_DEFAULT_HOSTS}; // CMake DEFLECT_DESKTOPSTREAMER_HOSTS 85 | #endif 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/defaults.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFAULTS_H 41 | #define DEFAULTS_H 42 | 43 | #include 44 | #include 45 | 46 | namespace defaults 47 | { 48 | /** @return the list of default hosts as [name, address] pairs. */ 49 | std::vector> getHosts(); 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/defaults.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "hosts": [ 3 | ${_JSON_HOSTS} 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/desktopstreamer.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=DesktopStreamer 3 | Comment=Stream your desktop 4 | Keywords=streaming;deflect; 5 | Exec=desktopstreamer 6 | Icon=desktopstreamer 7 | Type=Application 8 | Categories=Utility; 9 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/desktopstreamer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/apps/DesktopStreamer/desktopstreamer.icns -------------------------------------------------------------------------------- /apps/DesktopStreamer/desktopstreamer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/apps/DesktopStreamer/desktopstreamer.ico -------------------------------------------------------------------------------- /apps/DesktopStreamer/desktopstreamer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/apps/DesktopStreamer/desktopstreamer.png -------------------------------------------------------------------------------- /apps/DesktopStreamer/main.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2011-2012, The University of Texas at Austin. */ 3 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 4 | /* Raphael Dumusc */ 5 | /* All rights reserved. */ 6 | /* */ 7 | /* Redistribution and use in source and binary forms, with or */ 8 | /* without modification, are permitted provided that the following */ 9 | /* conditions are met: */ 10 | /* */ 11 | /* 1. Redistributions of source code must retain the above */ 12 | /* copyright notice, this list of conditions and the following */ 13 | /* disclaimer. */ 14 | /* */ 15 | /* 2. Redistributions in binary form must reproduce the above */ 16 | /* copyright notice, this list of conditions and the following */ 17 | /* disclaimer in the documentation and/or other materials */ 18 | /* provided with the distribution. */ 19 | /* */ 20 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 21 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 22 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 23 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 24 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 25 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 26 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 27 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 28 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 29 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 30 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 31 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 32 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 33 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 34 | /* */ 35 | /* The views and conclusions contained in the software and */ 36 | /* documentation are those of the authors and should not be */ 37 | /* interpreted as representing official policies, either expressed */ 38 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 39 | /*********************************************************************/ 40 | 41 | #include "MainWindow.h" 42 | 43 | #include 44 | 45 | #include 46 | 47 | int main(int argc, char* argv[]) 48 | { 49 | QApplication app(argc, argv); 50 | 51 | QApplication::setApplicationVersion( 52 | QString::fromStdString(deflect::Version::getString())); 53 | 54 | QCommandLineParser parser; 55 | parser.setApplicationDescription("Stream your desktop to a remote host"); 56 | QCommandLineOption streamEnabledOption(QStringList() << "e" 57 | << "enable", 58 | "Enable streaming on startup."); 59 | parser.addOption(streamEnabledOption); 60 | QCommandLineOption advancedOption(QStringList() << "a" 61 | << "advanced", 62 | "Show advanced settings."); 63 | parser.addOption(advancedOption); 64 | parser.addPositionalArgument("host", "Default host to stream to."); 65 | parser.addHelpOption(); 66 | parser.addVersionOption(); 67 | parser.process(app); 68 | 69 | const auto posArgs = parser.positionalArguments(); 70 | const auto host = posArgs.isEmpty() ? QString() : posArgs.at(0); 71 | const auto enable = parser.isSet(streamEnabledOption); 72 | const auto advanced = parser.isSet(advancedOption); 73 | 74 | Q_INIT_RESOURCE(resources); 75 | 76 | MainWindow mainWindow{{host, enable, advanced}}; 77 | mainWindow.show(); 78 | 79 | // enter Qt event loop 80 | return app.exec(); 81 | } 82 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/nameUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, EPFL/Blue Brain Project 2 | * Raphael Dumusc 3 | * 4 | * This file is part of Deflect 5 | * 6 | * This library is free software; you can redistribute it and/or modify it under 7 | * the terms of the GNU Lesser General Public License version 3.0 as published 8 | * by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 | * details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #include "nameUtils.h" 21 | 22 | #ifndef _WIN32 23 | #include 24 | #endif 25 | 26 | namespace nameutils 27 | { 28 | QString getFullUsername() 29 | { 30 | #ifdef _WIN32 31 | return qgetenv("USERNAME"); 32 | #else 33 | auto username = qgetenv("USER"); 34 | if (username.isEmpty()) 35 | username = qgetenv("USERNAME"); 36 | if (username.isEmpty()) 37 | return {}; 38 | 39 | if (auto userinfo = getpwnam(username.constData())) 40 | { 41 | const auto fullname = QString{userinfo->pw_gecos}; 42 | if (!fullname.isEmpty()) 43 | return fullname; 44 | } 45 | return username; 46 | #endif 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/nameUtils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, EPFL/Blue Brain Project 2 | * Raphael Dumusc 3 | * 4 | * This file is part of Deflect 5 | * 6 | * This library is free software; you can redistribute it and/or modify it under 7 | * the terms of the GNU Lesser General Public License version 3.0 as published 8 | * by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 | * details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #ifndef DESKTOPSTREAMER_NAMEUTILS_H 21 | #define DESKTOPSTREAMER_NAMEUTILS_H 22 | 23 | #include 24 | 25 | /** 26 | * Cross-platform utilities to retrieve the name of the user. 27 | */ 28 | namespace nameutils 29 | { 30 | /** 31 | * Retrieve the full name of the user (e.g. "John Doe"). 32 | * @return full name if available, else the basic username or an empty string. 33 | */ 34 | QString getFullUsername(); 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/nameUtils.mm: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, EPFL/Blue Brain Project 2 | * Raphael Dumusc 3 | * 4 | * This file is part of Deflect 5 | * 6 | * This library is free software; you can redistribute it and/or modify it under 7 | * the terms of the GNU Lesser General Public License version 3.0 as published 8 | * by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 | * details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #include "nameUtils.h" 21 | 22 | #import 23 | 24 | namespace nameutils 25 | { 26 | 27 | QString getFullUsername() 28 | { 29 | const auto fullname = QString{ [NSFullUserName() UTF8String] }; 30 | if( !fullname.isEmpty( )) 31 | return fullname; 32 | 33 | return qgetenv( "USER" ); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /apps/DesktopStreamer/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | cursor.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /apps/QmlStreamer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2015, EPFL/Blue Brain Project 3 | # Daniel Nachbaur 4 | 5 | set(QMLSTREAMER_SOURCES main.cpp resources.qrc) 6 | set(QMLSTREAMER_LINK_LIBRARIES DeflectQt) 7 | common_application(qmlstreamer NOHELP) 8 | -------------------------------------------------------------------------------- /apps/QmlStreamer/gui.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | import QtQuick.Window 2.2 3 | 4 | Item 5 | { 6 | objectName: "QmlStreamer example" 7 | 8 | onWindowChanged: { 9 | // tell the window/streamer our size constrains 10 | window.width = 300 11 | window.height = 300 12 | window.minimumWidth = 300 13 | window.minimumHeight = 300 14 | window.maximumWidth = 500 15 | window.maximumHeight = 500 16 | } 17 | 18 | width: 300 19 | height: 300 20 | Column 21 | { 22 | spacing: 2 23 | 24 | Rectangle { color: "red"; width: 50; height: 50 } 25 | Rectangle { id: greenRect; color: "green"; width: 20; height: 50 } 26 | Rectangle { color: "blue"; width: 50; height: 20 } 27 | 28 | move: Transition { 29 | NumberAnimation { properties: "x,y"; duration: 1000 } 30 | } 31 | 32 | focus: true 33 | } 34 | 35 | MouseArea 36 | { 37 | anchors.fill: parent 38 | onClicked: greenRect.visible = !greenRect.visible 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /apps/QmlStreamer/main.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, EPFL/Blue Brain Project 2 | * Daniel.Nachbaur@epfl.ch 3 | * 4 | * This file is part of Deflect 5 | * 6 | * This library is free software; you can redistribute it and/or modify it under 7 | * the terms of the GNU Lesser General Public License version 3.0 as published 8 | * by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 | * details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | int main(int argc, char** argv) 27 | { 28 | QGuiApplication app(argc, argv); 29 | QGuiApplication::setApplicationVersion( 30 | QString::fromStdString(deflect::Version::getString())); 31 | app.setQuitOnLastWindowClosed(true); 32 | 33 | QCommandLineParser parser; 34 | parser.setApplicationDescription( 35 | "Stream an offscreen QML scene to a remote" 36 | " host"); 37 | parser.addHelpOption(); 38 | parser.addVersionOption(); 39 | 40 | QCommandLineOption qmlFileOption("qml", "QML file to load", "qml-file", 41 | "qrc:/qml/gui.qml"); 42 | parser.addOption(qmlFileOption); 43 | 44 | QCommandLineOption streamHostOption("host", 45 | "Stream target host " 46 | "(default: localhost)", 47 | "host", "localhost"); 48 | parser.addOption(streamHostOption); 49 | 50 | // note: the 'name' command line option is already taken by QCoreApplication 51 | QCommandLineOption streamNameOption("streamname", 52 | "Stream name (default: " 53 | "Qml's root objectName " 54 | "property or 'QmlStreamer')", 55 | "name"); 56 | parser.addOption(streamNameOption); 57 | 58 | parser.process(app); 59 | 60 | const QString qmlFile = parser.value(qmlFileOption); 61 | const QString streamHost = parser.value(streamHostOption); 62 | const QString streamName = parser.value(streamNameOption); 63 | 64 | try 65 | { 66 | std::unique_ptr streamer( 67 | new deflect::qt::QmlStreamer(qmlFile, streamHost.toStdString(), 68 | streamName.toStdString())); 69 | app.connect(streamer.get(), &deflect::qt::QmlStreamer::streamClosed, 70 | &app, &QCoreApplication::quit); 71 | return app.exec(); 72 | } 73 | catch (const std::runtime_error& exception) 74 | { 75 | qWarning() << "QmlStreamer startup failed:" << exception.what(); 76 | return EXIT_FAILURE; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /apps/QmlStreamer/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | gui.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /apps/SimpleStreamer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2015, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | 5 | set(SIMPLESTREAMER_SOURCES main.cpp) 6 | set(SIMPLESTREAMER_LINK_LIBRARIES Deflect ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES}) 7 | 8 | common_application(simplestreamer) 9 | -------------------------------------------------------------------------------- /deflect/AppNapSuspender.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2014-2015, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of The Ecole Polytechnique Federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_APPNAPSUSPENDER_H 41 | #define DEFLECT_APPNAPSUSPENDER_H 42 | 43 | namespace deflect 44 | { 45 | /** 46 | * Suspend AppNap on OSX >= 10.9. 47 | */ 48 | class AppNapSuspender 49 | { 50 | public: 51 | /** Constructor. */ 52 | AppNapSuspender(); 53 | 54 | /** Destruct the object, resuming AppNap if it was suspended. */ 55 | ~AppNapSuspender(); 56 | 57 | /** Suspend AppNap. */ 58 | void suspend(); 59 | 60 | /** Resume AppNap */ 61 | void resume(); 62 | 63 | private: 64 | class Impl; 65 | Impl* _impl; 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /deflect/AppNapSuspender.mm: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2014-2015, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ 20 | /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ 21 | /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 22 | /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 23 | /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ 24 | /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ 25 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 26 | /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ 27 | /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ 28 | /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 29 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 30 | /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ 31 | /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ 32 | /* POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of The University of Texas at Austin. */ 38 | /*********************************************************************/ 39 | 40 | #include "AppNapSuspender.h" 41 | 42 | #include 43 | 44 | // We check at runtime if beginActivityWithOptions and endActivity 45 | // are available so that we can also compile using OSX SDK < 10.9 46 | #pragma clang diagnostic ignored "-Wobjc-method-access" 47 | 48 | #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED 49 | #if __MAC_OS_X_VERSION_MAX_ALLOWED < 1090 50 | // NSActivityUserInitiated is undefined when compiling with OSX SDK < 10.9 51 | #define NSActivityUserInitiated (0x00FFFFFFULL | (1ULL << 20)) 52 | #endif 53 | #endif 54 | 55 | namespace deflect 56 | { 57 | 58 | class AppNapSuspender::Impl 59 | { 60 | public: 61 | Impl() 62 | : activityId( nil ) 63 | {} 64 | 65 | id activityId; 66 | }; 67 | 68 | AppNapSuspender::AppNapSuspender() : 69 | _impl( new Impl ) 70 | { 71 | } 72 | 73 | AppNapSuspender::~AppNapSuspender() 74 | { 75 | resume(); 76 | delete _impl; 77 | } 78 | 79 | void AppNapSuspender::suspend() 80 | { 81 | if( _impl->activityId ) 82 | return; 83 | 84 | if( [[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)] ) 85 | { 86 | _impl->activityId = [[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiated reason:@"Good reason"]; 87 | [_impl->activityId retain]; 88 | } 89 | } 90 | 91 | void AppNapSuspender::resume() 92 | { 93 | if( !_impl->activityId ) 94 | return; 95 | 96 | if( [[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)] ) 97 | { 98 | [[NSProcessInfo processInfo] endActivity:_impl->activityId]; 99 | [_impl->activityId release]; 100 | _impl->activityId = nil; 101 | } 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /deflect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2018, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | # Daniel Nachbaur 5 | 6 | set(DEFLECT_PUBLIC_HEADERS 7 | Event.h 8 | ImageWrapper.h 9 | Observer.h 10 | SizeHints.h 11 | Stream.h 12 | types.h 13 | ) 14 | 15 | set(DEFLECT_HEADERS 16 | moodycamel/blockingconcurrentqueue.h 17 | moodycamel/concurrentqueue.h 18 | ImageSegmenter.h 19 | MessageHeader.h 20 | MTQueue.h 21 | NetworkProtocol.h 22 | Segment.h 23 | SegmentParameters.h 24 | Socket.h 25 | StreamPrivate.h 26 | TaskBuilder.h 27 | ) 28 | 29 | set(DEFLECT_SOURCES 30 | Event.cpp 31 | ImageSegmenter.cpp 32 | ImageWrapper.cpp 33 | MessageHeader.cpp 34 | MetaTypeRegistration.cpp 35 | Observer.cpp 36 | Socket.cpp 37 | Stream.cpp 38 | StreamPrivate.cpp 39 | StreamSendWorker.cpp 40 | TaskBuilder.cpp 41 | ) 42 | 43 | set(DEFLECT_LINK_LIBRARIES PRIVATE Qt5::Concurrent Qt5::Core Qt5::Network) 44 | 45 | if(APPLE) 46 | list(APPEND DEFLECT_PUBLIC_HEADERS AppNapSuspender.h) 47 | list(APPEND DEFLECT_SOURCES AppNapSuspender.mm) 48 | list(APPEND DEFLECT_LINK_LIBRARIES PRIVATE "-framework Foundation") 49 | endif() 50 | 51 | if(DEFLECT_USE_LIBJPEGTURBO) 52 | list(APPEND DEFLECT_HEADERS 53 | ImageJpegCompressor.h 54 | ) 55 | list(APPEND DEFLECT_SOURCES 56 | ImageJpegCompressor.cpp 57 | ) 58 | list(APPEND DEFLECT_LINK_LIBRARIES PRIVATE ${LibJpegTurbo_LIBRARIES}) 59 | endif() 60 | 61 | common_library(Deflect) 62 | 63 | add_subdirectory(server) 64 | 65 | if(Qt5Qml_FOUND AND Qt5Quick_FOUND AND Qt5OpenGL_FOUND AND 66 | NOT Qt5Quick_VERSION VERSION_LESS 5.4) 67 | add_subdirectory(qt) 68 | endif() 69 | -------------------------------------------------------------------------------- /deflect/Event.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "Event.h" 41 | 42 | #include 43 | 44 | namespace deflect 45 | { 46 | const uint32_t Event::serializedSize = 3 * sizeof(quint32) + 47 | 4 * sizeof(double) + 3 * sizeof(bool) + 48 | UNICODE_TEXT_SIZE; 49 | 50 | QDataStream& operator<<(QDataStream& out, const deflect::Event& event) 51 | { 52 | out << (qint32)event.type; 53 | 54 | out << event.mouseX << event.mouseY; 55 | out << event.dx << event.dy; 56 | 57 | out << event.mouseLeft << event.mouseRight << event.mouseMiddle; 58 | 59 | out << (qint32)event.key << (qint32)event.modifiers; 60 | 61 | for (size_t i = 0; i < UNICODE_TEXT_SIZE; ++i) 62 | out << (quint8)event.text[i]; 63 | 64 | return out; 65 | } 66 | 67 | QDataStream& operator>>(QDataStream& in, deflect::Event& event) 68 | { 69 | qint32 type; 70 | in >> type; 71 | event.type = (Event::EventType)type; 72 | 73 | in >> event.mouseX >> event.mouseY; 74 | in >> event.dx >> event.dy; 75 | 76 | in >> event.mouseLeft >> event.mouseRight >> event.mouseMiddle; 77 | 78 | qint32 key, modifiers; 79 | in >> key >> modifiers; 80 | event.key = (int)key; 81 | event.modifiers = (int)modifiers; 82 | 83 | quint8 character; 84 | for (size_t i = 0; i < UNICODE_TEXT_SIZE; ++i) 85 | { 86 | in >> character; 87 | event.text[i] = (char)character; 88 | } 89 | 90 | return in; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /deflect/ImageJpegCompressor.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_IMAGEJPEGCOMPRESSOR_H 41 | #define DEFLECT_IMAGEJPEGCOMPRESSOR_H 42 | 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #include 50 | 51 | namespace deflect 52 | { 53 | /** 54 | * Perform JPEG compression for a region of an image. 55 | */ 56 | class ImageJpegCompressor 57 | { 58 | public: 59 | DEFLECT_API ImageJpegCompressor(); 60 | DEFLECT_API ~ImageJpegCompressor(); 61 | 62 | /** 63 | * Compute the JPEG imageData for a segment 64 | * 65 | * @param sourceImage The source image containing uncompressed image data. 66 | * @param imageRegion The region of the image to be compressed. Must not 67 | * exceed image dimensions. 68 | * @return compressed image 69 | * @throw std::invalid_argument if sourceImage.data is nullptr 70 | * @throw std::runtime_error if JPEG compression failed 71 | */ 72 | DEFLECT_API QByteArray computeJpeg(const ImageWrapper& sourceImage, 73 | const QRect& imageRegion); 74 | 75 | private: 76 | tjhandle _tjHandle; 77 | std::vector _tjJpegBuf; 78 | }; 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /deflect/ImageWrapper.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "ImageWrapper.h" 41 | 42 | #include 43 | 44 | #define DEFAULT_COMPRESSION_QUALITY 75 45 | 46 | namespace deflect 47 | { 48 | ImageWrapper::ImageWrapper(const void* data_, const unsigned int width_, 49 | const unsigned int height_, 50 | const PixelFormat format_, const unsigned int x_, 51 | const unsigned int y_) 52 | : data(data_) 53 | , width(width_) 54 | , height(height_) 55 | , pixelFormat(format_) 56 | , x(x_) 57 | , y(y_) 58 | , compressionPolicy(COMPRESSION_AUTO) 59 | , compressionQuality(DEFAULT_COMPRESSION_QUALITY) 60 | , subsampling(ChromaSubsampling::YUV444) 61 | { 62 | } 63 | 64 | unsigned int ImageWrapper::getBytesPerPixel() const 65 | { 66 | // enum PixelFormat { RGB, RGBA, ARGB, BGR, BGRA, ABGR }; 67 | static const unsigned int bytesPerPixel[] = {3, 4, 4, 3, 4, 4}; 68 | 69 | return bytesPerPixel[pixelFormat]; 70 | } 71 | 72 | size_t ImageWrapper::getBufferSize() const 73 | { 74 | return width * height * getBytesPerPixel(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /deflect/MTQueue.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2015, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_MTQUEUE_H 41 | #define DEFLECT_MTQUEUE_H 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | namespace deflect 48 | { 49 | /** Thread-safe multiple producer, multiple consumer queue. */ 50 | template 51 | class MTQueue 52 | { 53 | public: 54 | /** @param maxSize maximum size of the queue after which enqueue() blocks */ 55 | MTQueue(const size_t maxSize = std::numeric_limits::max()) 56 | : _maxSize(maxSize) 57 | { 58 | } 59 | 60 | /** 61 | * Push a new value to the end of the queue. Blocks if maxSize is reached. 62 | */ 63 | void enqueue(const T& value) 64 | { 65 | std::unique_lock lock(_mutex); 66 | while (_queue.size() >= _maxSize) 67 | _full.wait(lock); 68 | _queue.push(value); 69 | _empty.notify_one(); 70 | } 71 | 72 | /** Pop a value from the front of the queue. Blocks if queue is empty. */ 73 | T dequeue() 74 | { 75 | std::unique_lock lock(_mutex); 76 | while (_queue.empty()) 77 | _empty.wait(lock); 78 | T value = _queue.front(); 79 | _queue.pop(); 80 | _full.notify_one(); 81 | return value; 82 | } 83 | 84 | /** Clears the queue. */ 85 | void clear() 86 | { 87 | std::lock_guard lock(_mutex); 88 | _queue = {}; 89 | _full.notify_one(); 90 | } 91 | 92 | /** @return the current size of the queue. */ 93 | size_t size() const 94 | { 95 | std::lock_guard lock(_mutex); 96 | return _queue.size(); 97 | } 98 | 99 | /** @return true if the queue is empty. */ 100 | bool empty() const 101 | { 102 | std::lock_guard lock(_mutex); 103 | return _queue.empty(); 104 | } 105 | 106 | private: 107 | size_t _maxSize; 108 | std::queue _queue; 109 | mutable std::mutex _mutex; 110 | std::condition_variable _empty; 111 | std::condition_variable _full; 112 | }; 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /deflect/MessageHeader.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "MessageHeader.h" 41 | 42 | #include 43 | 44 | namespace deflect 45 | { 46 | const size_t MessageHeader::serializedSize = 47 | sizeof(quint32) + sizeof(qint32) + MESSAGE_HEADER_URI_LENGTH; 48 | 49 | MessageHeader::MessageHeader() 50 | : type(MESSAGE_TYPE_NONE) 51 | , size(0) 52 | { 53 | memset(uri, '\0', MESSAGE_HEADER_URI_LENGTH); 54 | } 55 | 56 | MessageHeader::MessageHeader(const MessageType type_, const uint32_t size_, 57 | const std::string& streamUri) 58 | : type(type_) 59 | , size(size_) 60 | { 61 | memset(uri, '\0', MESSAGE_HEADER_URI_LENGTH); 62 | 63 | // add the truncated URI to the header 64 | const size_t len = streamUri.copy(uri, MESSAGE_HEADER_URI_LENGTH - 1); 65 | uri[len] = '\0'; 66 | } 67 | } // namespace deflect 68 | 69 | QDataStream& operator<<(QDataStream& out, const deflect::MessageHeader& header) 70 | { 71 | out << (qint32)header.type << (quint32)header.size; 72 | out.writeRawData(header.uri, MESSAGE_HEADER_URI_LENGTH); 73 | 74 | return out; 75 | } 76 | 77 | QDataStream& operator>>(QDataStream& in, deflect::MessageHeader& header) 78 | { 79 | qint32 type; 80 | quint32 size; 81 | 82 | in >> type; 83 | header.type = (deflect::MessageType)type; 84 | in >> size; 85 | header.size = size; 86 | in.readRawData(header.uri, MESSAGE_HEADER_URI_LENGTH); 87 | return in; 88 | } 89 | -------------------------------------------------------------------------------- /deflect/MessageHeader.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael.Dumusc@epfl.ch */ 4 | /* Daniel.Nachbaur@epfl.ch */ 5 | /* Redistribution and use in source and binary forms, with or */ 6 | /* without modification, are permitted provided that the following */ 7 | /* conditions are met: */ 8 | /* */ 9 | /* 1. Redistributions of source code must retain the above */ 10 | /* copyright notice, this list of conditions and the following */ 11 | /* disclaimer. */ 12 | /* */ 13 | /* 2. Redistributions in binary form must reproduce the above */ 14 | /* copyright notice, this list of conditions and the following */ 15 | /* disclaimer in the documentation and/or other materials */ 16 | /* provided with the distribution. */ 17 | /* */ 18 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 19 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 20 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 21 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 22 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 23 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 24 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 25 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 26 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 27 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 28 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 29 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 30 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 31 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 32 | /* */ 33 | /* The views and conclusions contained in the software and */ 34 | /* documentation are those of the authors and should not be */ 35 | /* interpreted as representing official policies, either expressed */ 36 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 37 | /*********************************************************************/ 38 | 39 | #ifndef DEFLECT_MESSAGE_HEADER_H 40 | #define DEFLECT_MESSAGE_HEADER_H 41 | 42 | #include 43 | 44 | #ifdef _WIN32 45 | typedef unsigned __int32 uint32_t; 46 | #else 47 | #include 48 | #endif 49 | 50 | #include 51 | 52 | class QDataStream; 53 | 54 | namespace deflect 55 | { 56 | /** The message types. */ 57 | enum MessageType 58 | { 59 | MESSAGE_TYPE_NONE = 0, 60 | MESSAGE_TYPE_PIXELSTREAM_OPEN = 3, 61 | MESSAGE_TYPE_PIXELSTREAM_FINISH_FRAME = 4, 62 | MESSAGE_TYPE_PIXELSTREAM = 5, 63 | MESSAGE_TYPE_BIND_EVENTS = 6, 64 | MESSAGE_TYPE_BIND_EVENTS_EX = 7, 65 | MESSAGE_TYPE_BIND_EVENTS_REPLY = 8, 66 | MESSAGE_TYPE_EVENT = 9, 67 | MESSAGE_TYPE_QUIT = 12, 68 | MESSAGE_TYPE_SIZE_HINTS = 13, 69 | MESSAGE_TYPE_DATA = 14, 70 | MESSAGE_TYPE_IMAGE_VIEW = 15, 71 | MESSAGE_TYPE_OBSERVER_OPEN = 16, 72 | MESSAGE_TYPE_IMAGE_ROW_ORDER = 17, 73 | MESSAGE_TYPE_IMAGE_CHANNEL = 18 74 | }; 75 | 76 | #define MESSAGE_HEADER_URI_LENGTH 64 77 | 78 | /** Fixed-size message header. */ 79 | struct MessageHeader 80 | { 81 | /** Message type. */ 82 | MessageType type; 83 | 84 | /** Size of the message payload. */ 85 | uint32_t size; 86 | 87 | /** 88 | * Optional URI related to message. 89 | * @note Needs to be of fixed size so that sizeof(MessageHeader) is constant 90 | */ 91 | char uri[MESSAGE_HEADER_URI_LENGTH]; 92 | 93 | /** Construct a default message header */ 94 | DEFLECT_API MessageHeader(); 95 | 96 | /** Construct a message header with a uri */ 97 | DEFLECT_API MessageHeader(const MessageType type, const uint32_t size, 98 | const std::string& streamUri = ""); 99 | 100 | /** The size of the QDataStream serialized output. */ 101 | static const size_t serializedSize; 102 | }; 103 | } 104 | 105 | /** 106 | * Serialization for network, where sizeof(MessageHeader) can differ between 107 | * compilers. 108 | */ 109 | DEFLECT_API QDataStream& operator<<(QDataStream& out, 110 | const deflect::MessageHeader& header); 111 | DEFLECT_API QDataStream& operator>>(QDataStream& in, 112 | deflect::MessageHeader& header); 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /deflect/MetaTypeRegistration.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2014-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* Daniel.Nachbaur@epfl.ch */ 5 | /* All rights reserved. */ 6 | /* */ 7 | /* Redistribution and use in source and binary forms, with or */ 8 | /* without modification, are permitted provided that the following */ 9 | /* conditions are met: */ 10 | /* */ 11 | /* 1. Redistributions of source code must retain the above */ 12 | /* copyright notice, this list of conditions and the following */ 13 | /* disclaimer. */ 14 | /* */ 15 | /* 2. Redistributions in binary form must reproduce the above */ 16 | /* copyright notice, this list of conditions and the following */ 17 | /* disclaimer in the documentation and/or other materials */ 18 | /* provided with the distribution. */ 19 | /* */ 20 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 21 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 22 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 23 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 24 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 25 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 26 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 27 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 28 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 29 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 30 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 31 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 32 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 33 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 34 | /* */ 35 | /* The views and conclusions contained in the software and */ 36 | /* documentation are those of the authors and should not be */ 37 | /* interpreted as representing official policies, either expressed */ 38 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 39 | /*********************************************************************/ 40 | 41 | #include "Event.h" 42 | #include "Segment.h" 43 | #include "SizeHints.h" 44 | #include "server/Tile.h" 45 | #include "server/types.h" 46 | #include "types.h" 47 | 48 | #include 49 | 50 | namespace deflect 51 | { 52 | /** 53 | * Register types for use in Qt signals/slots 54 | */ 55 | struct MetaTypeRegistration 56 | { 57 | MetaTypeRegistration() 58 | { 59 | qRegisterMetaType("size_t"); 60 | qRegisterMetaType("deflect::Segment"); 61 | qRegisterMetaType("deflect::SizeHints"); 62 | qRegisterMetaType("deflect::Event"); 63 | qRegisterMetaType("deflect::View"); 64 | qRegisterMetaType( 65 | "deflect::server::BoolPromisePtr"); 66 | qRegisterMetaType( 67 | "deflect::server::FramePtr"); 68 | qRegisterMetaType("deflect::server::Tile"); 69 | } 70 | }; 71 | 72 | // Static instance to register types during library static initialisation phase 73 | static MetaTypeRegistration staticInstance; 74 | } 75 | -------------------------------------------------------------------------------- /deflect/NetworkProtocol.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2011-2012, The University of Texas at Austin. */ 3 | /* All rights reserved. */ 4 | /* */ 5 | /* Redistribution and use in source and binary forms, with or */ 6 | /* without modification, are permitted provided that the following */ 7 | /* conditions are met: */ 8 | /* */ 9 | /* 1. Redistributions of source code must retain the above */ 10 | /* copyright notice, this list of conditions and the following */ 11 | /* disclaimer. */ 12 | /* */ 13 | /* 2. Redistributions in binary form must reproduce the above */ 14 | /* copyright notice, this list of conditions and the following */ 15 | /* disclaimer in the documentation and/or other materials */ 16 | /* provided with the distribution. */ 17 | /* */ 18 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 19 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 20 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 21 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 22 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 23 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 24 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 25 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 26 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 27 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 28 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 29 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 30 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 31 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 32 | /* */ 33 | /* The views and conclusions contained in the software and */ 34 | /* documentation are those of the authors and should not be */ 35 | /* interpreted as representing official policies, either expressed */ 36 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 37 | /*********************************************************************/ 38 | 39 | #ifndef DEFLECT_NETWORK_PROTOCOL_H 40 | #define DEFLECT_NETWORK_PROTOCOL_H 41 | 42 | #define NETWORK_PROTOCOL_VERSION 8 43 | #define DEFAULT_PORT_NUMBER 1701 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /deflect/Segment.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SEGMENT_H 41 | #define DEFLECT_SEGMENT_H 42 | 43 | #include 44 | 45 | #include 46 | 47 | namespace deflect 48 | { 49 | /** 50 | * Image data and parameters for a segment of a larger image. 51 | */ 52 | struct Segment 53 | { 54 | SegmentParameters parameters; 55 | QByteArray imageData; 56 | 57 | /** Extra parameters sent separately for network protocol compatiblity. */ 58 | 59 | View view = View::mono; //!< Eye pass for the segment 60 | RowOrder rowOrder = RowOrder::top_down; //!< Row order of imageData 61 | uint8_t channel = 0; //!< Channel index for the segment 62 | }; 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /deflect/SegmentParameters.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SEGMENTPARAMETERS_H 41 | #define DEFLECT_SEGMENTPARAMETERS_H 42 | 43 | #ifdef _WIN32 44 | typedef unsigned __int32 uint32_t; 45 | #else 46 | #include 47 | #endif 48 | 49 | #include 50 | 51 | namespace deflect 52 | { 53 | /** 54 | * Parameters for a Segment of an image. 55 | * @version 1.0 56 | */ 57 | struct SegmentParameters 58 | { 59 | /** @name Coordinates */ 60 | //@{ 61 | uint32_t x = 0u; /**< The x position in pixels. */ 62 | uint32_t y = 0u; /**< The y position in pixels. */ 63 | //@} 64 | 65 | /** @name Dimensions */ 66 | //@{ 67 | uint32_t width = 0u; /**< The width in pixels. */ 68 | uint32_t height = 0u; /**< The height in pixels. */ 69 | //@} 70 | 71 | /** Format in which the segment data is stored. */ 72 | Format format = Format::jpeg; 73 | 74 | /** 75 | * WARNING: 76 | * Extending this struct breaks compatibility with current 77 | * NETWORK_PROTOCOL_VERSION == 8. This is due to the use of 78 | * sizeof(SegmentParameters) in (de)serialization code. 79 | */ 80 | }; 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /deflect/SizeHints.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2015, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur@epfl.ch */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SIZEHINTS_H 41 | #define DEFLECT_SIZEHINTS_H 42 | 43 | namespace deflect 44 | { 45 | /** 46 | * A struct that contains hints about minimum, maximum and preferred sizes of a 47 | * streamer which can be interpreted by the stream server accordingly. 48 | * 49 | * @version 1.0 50 | */ 51 | struct SizeHints 52 | { 53 | /** value for an unspecified size value; streamer did not report any hint */ 54 | static const unsigned int UNSPECIFIED_SIZE = 0; 55 | 56 | /** @name Minimum size */ 57 | //@{ 58 | unsigned int minWidth = UNSPECIFIED_SIZE; 59 | unsigned int minHeight = UNSPECIFIED_SIZE; 60 | //@} 61 | 62 | /** @name Maximum size */ 63 | //@{ 64 | unsigned int maxWidth = UNSPECIFIED_SIZE; 65 | unsigned int maxHeight = UNSPECIFIED_SIZE; 66 | //@} 67 | 68 | /** @name Preferred size */ 69 | //@{ 70 | unsigned int preferredWidth = UNSPECIFIED_SIZE; 71 | unsigned int preferredHeight = UNSPECIFIED_SIZE; 72 | //@} 73 | }; 74 | 75 | /** @return true if rhs and this are equal for all sizes. */ 76 | inline bool operator==(const SizeHints& lhs, const SizeHints& rhs) noexcept 77 | { 78 | return lhs.minWidth == rhs.minWidth && lhs.minHeight == rhs.minHeight && 79 | lhs.maxWidth == rhs.maxWidth && lhs.maxHeight == rhs.maxHeight && 80 | lhs.preferredWidth == rhs.preferredWidth && 81 | lhs.preferredHeight == rhs.preferredHeight; 82 | } 83 | 84 | /** @return true if rhs and this not equal for any size. */ 85 | inline bool operator!=(const SizeHints& lhs, const SizeHints& rhs) noexcept 86 | { 87 | return !(lhs == rhs); 88 | } 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /deflect/Stream.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* Stefan.Eilemann@epfl.ch */ 5 | /* Daniel.Nachbaur@epfl.ch */ 6 | /* All rights reserved. */ 7 | /* */ 8 | /* Redistribution and use in source and binary forms, with or */ 9 | /* without modification, are permitted provided that the following */ 10 | /* conditions are met: */ 11 | /* */ 12 | /* 1. Redistributions of source code must retain the above */ 13 | /* copyright notice, this list of conditions and the following */ 14 | /* disclaimer. */ 15 | /* */ 16 | /* 2. Redistributions in binary form must reproduce the above */ 17 | /* copyright notice, this list of conditions and the following */ 18 | /* disclaimer in the documentation and/or other materials */ 19 | /* provided with the distribution. */ 20 | /* */ 21 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 22 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 23 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 24 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 25 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 26 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 27 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 28 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 29 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 30 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 31 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 32 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 33 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 34 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 35 | /* */ 36 | /* The views and conclusions contained in the software and */ 37 | /* documentation are those of the authors and should not be */ 38 | /* interpreted as representing official policies, either expressed */ 39 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 40 | /*********************************************************************/ 41 | 42 | #include "Stream.h" 43 | #include "StreamPrivate.h" 44 | 45 | namespace deflect 46 | { 47 | Stream::Stream() 48 | : Observer(new StreamPrivate("", "", 0, false)) 49 | { 50 | } 51 | 52 | Stream::Stream(const unsigned short port) 53 | : Observer(new StreamPrivate("", "", port, false)) 54 | { 55 | } 56 | 57 | Stream::Stream(const std::string& id, const std::string& host, 58 | const unsigned short port) 59 | : Observer(new StreamPrivate(id, host, port, false)) 60 | { 61 | } 62 | 63 | Stream::~Stream() 64 | { 65 | } 66 | 67 | Stream::Future Stream::send(const ImageWrapper& image) 68 | { 69 | return _impl->sendImage(image, false); 70 | } 71 | 72 | Stream::Future Stream::finishFrame() 73 | { 74 | return _impl->sendFinishFrame(); 75 | } 76 | 77 | Stream::Future Stream::sendAndFinish(const ImageWrapper& image) 78 | { 79 | return _impl->sendImage(image, true); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /deflect/TaskBuilder.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_TASKBUILDER_H 41 | #define DEFLECT_TASKBUILDER_H 42 | 43 | #include "StreamSendWorker.h" 44 | #include "types.h" 45 | 46 | namespace deflect 47 | { 48 | /** 49 | * Create tasks to be executed asynchrounously by the StreamSendWorker. 50 | */ 51 | class TaskBuilder 52 | { 53 | public: 54 | TaskBuilder(StreamSendWorker* worker, StreamPrivate* stream); 55 | 56 | Task openStream(); 57 | Task openObserver(); 58 | Task bindEvents(bool exclusive); 59 | Task close(); 60 | 61 | Task send(const SizeHints& hints); 62 | Task send(const QByteArray& data); 63 | Task send(Segment&& segment); 64 | std::vector sendUsingMTCompression(const ImageWrapper& image, 65 | ImageSegmenter& imageSegmenter, 66 | bool finish); 67 | std::vector finishFrame(); 68 | 69 | private: 70 | StreamSendWorker* _worker = nullptr; 71 | StreamPrivate* _stream = nullptr; 72 | 73 | Task send(const ImageWrapper& image, ImageSegmenter& imageSegmenter); 74 | }; 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /deflect/qt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2015-2018, EPFL/Blue Brain Project 3 | # Daniel Nachbaur 4 | # Raphael Dumusc 5 | 6 | set(DEFLECTQT_PUBLIC_HEADERS 7 | OffscreenQuickView.h 8 | QmlStreamer.h 9 | QuickRenderer.h 10 | TouchInjector.h 11 | types.h 12 | ) 13 | 14 | set(DEFLECTQT_HEADERS 15 | EventReceiver.h 16 | QmlGestures.h 17 | QmlStreamerImpl.h 18 | ) 19 | 20 | set(DEFLECTQT_SOURCES 21 | EventReceiver.cpp 22 | OffscreenQuickView.cpp 23 | QmlStreamer.cpp 24 | QmlStreamerImpl.cpp 25 | QuickRenderer.cpp 26 | TouchInjector.cpp 27 | ) 28 | 29 | set(DEFLECTQT_LINK_LIBRARIES 30 | PUBLIC Deflect Qt5::Quick PRIVATE Qt5::Qml 31 | ) 32 | 33 | set(DEFLECTQT_INCLUDE_NAME deflect/qt) 34 | set(DEFLECTQT_OMIT_VERSION_HEADERS ON) 35 | 36 | common_library(DeflectQt) 37 | 38 | if(DEFLECT_QMLSTREAMER_MULTITHREADED) 39 | target_compile_definitions(DeflectQt PRIVATE DEFLECTQT_MULTITHREADED) 40 | endif() 41 | -------------------------------------------------------------------------------- /deflect/qt/EventReceiver.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2015-2016, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur */ 4 | /* Raphael Dumusc */ 5 | /* All rights reserved. */ 6 | /* */ 7 | /* Redistribution and use in source and binary forms, with or */ 8 | /* without modification, are permitted provided that the following */ 9 | /* conditions are met: */ 10 | /* */ 11 | /* 1. Redistributions of source code must retain the above */ 12 | /* copyright notice, this list of conditions and the following */ 13 | /* disclaimer. */ 14 | /* */ 15 | /* 2. Redistributions in binary form must reproduce the above */ 16 | /* copyright notice, this list of conditions and the following */ 17 | /* disclaimer in the documentation and/or other materials */ 18 | /* provided with the distribution. */ 19 | /* */ 20 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 21 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 22 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 23 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 24 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 25 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 26 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 27 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 28 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 29 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 30 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 31 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 32 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 33 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 34 | /* */ 35 | /* The views and conclusions contained in the software and */ 36 | /* documentation are those of the authors and should not be */ 37 | /* interpreted as representing official policies, either expressed */ 38 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 39 | /*********************************************************************/ 40 | 41 | #ifndef DELFECT_QT_EVENTRECEIVER_H 42 | #define DELFECT_QT_EVENTRECEIVER_H 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | 52 | namespace deflect 53 | { 54 | namespace qt 55 | { 56 | class EventReceiver : public QObject 57 | { 58 | Q_OBJECT 59 | 60 | public: 61 | EventReceiver(Stream& stream); 62 | ~EventReceiver(); 63 | 64 | signals: 65 | void pressed(QPointF position); 66 | void released(QPointF position); 67 | void moved(QPointF position); 68 | 69 | void resized(QSize newSize); 70 | void closed(); 71 | 72 | void keyPress(int key, int modifiers, QString text); 73 | void keyRelease(int key, int modifiers, QString text); 74 | 75 | void swipeLeft(); 76 | void swipeRight(); 77 | void swipeUp(); 78 | void swipeDown(); 79 | 80 | void touchPointAdded(int id, QPointF position); 81 | void touchPointUpdated(int id, QPointF position); 82 | void touchPointRemoved(int id, QPointF position); 83 | 84 | private: 85 | Stream& _stream; 86 | std::unique_ptr _notifier; 87 | std::unique_ptr _timer; 88 | 89 | void _onEvent(int socket); 90 | void _stop(); 91 | }; 92 | } 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /deflect/qt/QmlGestures.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2016, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DELFECT_QT_QMLGESTURES_H 41 | #define DELFECT_QT_QMLGESTURES_H 42 | 43 | #include 44 | 45 | namespace deflect 46 | { 47 | namespace qt 48 | { 49 | /** 50 | * Expose gesture events as a Qml context property object. 51 | */ 52 | class QmlGestures : public QObject 53 | { 54 | Q_OBJECT 55 | 56 | signals: 57 | void swipeLeft(); 58 | void swipeRight(); 59 | void swipeUp(); 60 | void swipeDown(); 61 | }; 62 | } 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /deflect/qt/QmlStreamer.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2015, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "QmlStreamer.h" 41 | #include "QmlStreamerImpl.h" 42 | 43 | #include "../Stream.h" 44 | 45 | namespace deflect 46 | { 47 | namespace qt 48 | { 49 | QmlStreamer::QmlStreamer(const QString& qmlFile, const std::string& streamHost, 50 | const std::string& streamId) 51 | : _impl(new Impl(qmlFile, streamHost, streamId)) 52 | { 53 | connect(_impl.get(), &Impl::streamClosed, this, &QmlStreamer::streamClosed); 54 | } 55 | 56 | QmlStreamer::~QmlStreamer() {} 57 | 58 | void QmlStreamer::useAsyncSend(const bool async) 59 | { 60 | _impl->useAsyncSend(async); 61 | } 62 | 63 | QQuickItem* QmlStreamer::getRootItem() 64 | { 65 | return _impl->getRootItem(); 66 | } 67 | 68 | QQmlEngine* QmlStreamer::getQmlEngine() 69 | { 70 | return _impl->getQmlEngine(); 71 | } 72 | 73 | bool QmlStreamer::sendData(const QByteArray data) 74 | { 75 | return _impl->getStream()->sendData(data.constData(), data.size()); 76 | } 77 | 78 | void QmlStreamer::setRenderInterval(uint interval) 79 | { 80 | _impl->setRenderInterval(interval); 81 | } 82 | 83 | } // namespace qt 84 | } // namespace deflect 85 | -------------------------------------------------------------------------------- /deflect/qt/types.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_QT_TYPES_H 41 | #define DEFLECT_QT_TYPES_H 42 | 43 | #include 44 | 45 | namespace deflect 46 | { 47 | namespace qt 48 | { 49 | class QuickRenderer; 50 | class QmlStreamer; 51 | class TouchInjector; 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /deflect/server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2018, EPFL/Blue Brain Project 3 | # Raphael Dumusc 4 | 5 | set(DEFLECTSERVER_PUBLIC_HEADERS 6 | EventReceiver.h 7 | Frame.h 8 | Server.h 9 | Tile.h 10 | types.h 11 | ) 12 | set(DEFLECTSERVER_HEADERS 13 | FrameDispatcher.h 14 | ServerWorker.h 15 | ReceiveBuffer.h 16 | SourceBuffer.h 17 | ) 18 | set(DEFLECTSERVER_SOURCES 19 | Frame.cpp 20 | FrameDispatcher.cpp 21 | Server.cpp 22 | ServerWorker.cpp 23 | ReceiveBuffer.cpp 24 | SourceBuffer.cpp 25 | ) 26 | 27 | set(DEFLECTSERVER_LINK_LIBRARIES 28 | PUBLIC Deflect Qt5::Core PRIVATE Qt5::Network 29 | ) 30 | 31 | if(DEFLECT_USE_LIBJPEGTURBO) 32 | list(APPEND DEFLECTSERVER_PUBLIC_HEADERS 33 | TileDecoder.h 34 | ) 35 | list(APPEND DEFLECTSERVER_HEADERS 36 | ImageJpegDecompressor.h 37 | ) 38 | list(APPEND DEFLECTSERVER_SOURCES 39 | ImageJpegDecompressor.cpp 40 | TileDecoder.cpp 41 | ) 42 | list(APPEND DEFLECTSERVER_LINK_LIBRARIES PRIVATE ${LibJpegTurbo_LIBRARIES}) 43 | endif() 44 | 45 | set(DEFLECTSERVER_INCLUDE_NAME deflect/server) 46 | set(DEFLECTSERVER_OMIT_VERSION_HEADERS ON) 47 | # avoid conflict between server.h and Server.h on case-insensitive file systems 48 | set(DEFLECTSERVER_OMIT_LIBRARY_HEADER ON) 49 | 50 | common_library(DeflectServer) 51 | -------------------------------------------------------------------------------- /deflect/server/EventReceiver.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_EVENTRECEIVER_H 41 | #define DEFLECT_SERVER_EVENTRECEIVER_H 42 | 43 | #include 44 | #include 45 | 46 | #include 47 | 48 | namespace deflect 49 | { 50 | namespace server 51 | { 52 | /** 53 | * Interface for classes to register as receivers for events. 54 | */ 55 | class DEFLECT_API EventReceiver : public QObject 56 | { 57 | Q_OBJECT 58 | 59 | public: 60 | virtual ~EventReceiver() = default; 61 | 62 | public slots: 63 | virtual void processEvent(deflect::Event event) = 0; 64 | }; 65 | } 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /deflect/server/Frame.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2015-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "Frame.h" 41 | 42 | namespace deflect 43 | { 44 | namespace server 45 | { 46 | QSize Frame::computeDimensions(const uint8_t channel) const 47 | { 48 | QSize size(0, 0); 49 | 50 | for (const auto& tile : tiles) 51 | { 52 | if (tile.channel != channel) 53 | continue; 54 | 55 | size.setWidth(std::max(size.width(), (int)(tile.width + tile.x))); 56 | size.setHeight(std::max(size.height(), (int)(tile.height + tile.y))); 57 | } 58 | 59 | return size; 60 | } 61 | 62 | RowOrder Frame::determineRowOrder() const 63 | { 64 | if (tiles.empty()) 65 | throw std::runtime_error("frame has no tiles"); 66 | 67 | const auto frameRowOrder = tiles[0].rowOrder; 68 | 69 | for (const auto& tile : tiles) 70 | { 71 | if (tile.rowOrder != frameRowOrder) 72 | throw std::runtime_error("frame has incoherent row orders"); 73 | } 74 | 75 | return frameRowOrder; 76 | } 77 | 78 | std::map Frame::computeChannelDimensions() const 79 | { 80 | std::map sizes; 81 | for (const auto& tile : tiles) 82 | { 83 | auto& size = sizes[tile.channel]; 84 | size.setWidth(std::max(size.width(), (int)(tile.width + tile.x))); 85 | size.setHeight(std::max(size.height(), (int)(tile.height + tile.y))); 86 | } 87 | return sizes; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /deflect/server/Frame.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2014-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_FRAME_H 41 | #define DEFLECT_SERVER_FRAME_H 42 | 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #include 50 | 51 | namespace deflect 52 | { 53 | namespace server 54 | { 55 | /** 56 | * A frame for a PixelStream. 57 | */ 58 | struct Frame 59 | { 60 | /** The full set of tiles for this frame. */ 61 | Tiles tiles; 62 | 63 | /** The PixelStream uri to which this frame is associated. */ 64 | QString uri; 65 | 66 | /** @return the total dimensions of the given channel of this frame. */ 67 | DEFLECT_API QSize computeDimensions(const uint8_t channel = 0) const; 68 | 69 | /** @return the total dimensions of all channels of this frame. */ 70 | DEFLECT_API std::map computeChannelDimensions() const; 71 | 72 | /** 73 | * @return the row order of all frame tiles. 74 | * @throws std::runtime_error if not all tiles have the same RowOrder. 75 | */ 76 | DEFLECT_API RowOrder determineRowOrder() const; 77 | }; 78 | } 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /deflect/server/ImageJpegDecompressor.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_IMAGEJPEGDECOMPRESSOR_H 41 | #define DEFLECT_SERVER_IMAGEJPEGDECOMPRESSOR_H 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | #include 48 | 49 | #include 50 | 51 | namespace deflect 52 | { 53 | namespace server 54 | { 55 | /** 56 | * JPEG header information. 57 | */ 58 | struct JpegHeader 59 | { 60 | int width = 0; 61 | int height = 0; 62 | ChromaSubsampling subsampling; 63 | }; 64 | 65 | /** 66 | * Decompress Jpeg compressed data. 67 | */ 68 | class ImageJpegDecompressor 69 | { 70 | public: 71 | DEFLECT_API ImageJpegDecompressor(); 72 | DEFLECT_API ~ImageJpegDecompressor(); 73 | 74 | /** 75 | * Decompress the header of a Jpeg image. 76 | * 77 | * @param jpegData The compressed Jpeg data 78 | * @return The decompressed Jpeg header 79 | * @throw std::runtime_error if a decompression error occured 80 | */ 81 | DEFLECT_API JpegHeader decompressHeader(const QByteArray& jpegData); 82 | 83 | /** 84 | * Decompress a Jpeg image. 85 | * 86 | * @param jpegData The compressed Jpeg data 87 | * @return The decompressed image data in (GL_)RGBA format 88 | * @throw std::runtime_error if a decompression error occured 89 | */ 90 | DEFLECT_API QByteArray decompress(const QByteArray& jpegData); 91 | 92 | #ifndef DEFLECT_USE_LEGACY_LIBJPEGTURBO 93 | 94 | using YUVData = std::pair; 95 | 96 | /** 97 | * Decompress a Jpeg image to YUV, skipping the YUV -> RGBA conversion step. 98 | * 99 | * @param jpegData The compressed Jpeg data 100 | * @return The decompressed image data in YUV format 101 | * @throw std::runtime_error if a decompression error occured 102 | */ 103 | DEFLECT_API YUVData decompressToYUV(const QByteArray& jpegData); 104 | 105 | #endif 106 | 107 | private: 108 | /** libjpeg-turbo handle for decompression */ 109 | tjhandle _tjHandle; 110 | }; 111 | } 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /deflect/server/ReceiveBuffer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_RECEIVEBUFFER_H 41 | #define DEFLECT_SERVER_RECEIVEBUFFER_H 42 | 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | namespace deflect 50 | { 51 | namespace server 52 | { 53 | /** 54 | * Buffer Tiles from (multiple) sources. 55 | * 56 | * The buffer aggregates tiles coming from different sources and delivers 57 | * complete frames. 58 | */ 59 | class ReceiveBuffer 60 | { 61 | public: 62 | /** 63 | * Add a source of tiles. 64 | * @param sourceIndex Unique source identifier 65 | * @throw std::runtime_error if finishFrameForSource() has already been 66 | * called for all existing sources (reject late joiners). 67 | */ 68 | DEFLECT_API void addSource(size_t sourceIndex); 69 | 70 | /** 71 | * Remove a source of tiles. 72 | * @param sourceIndex Unique source identifier 73 | */ 74 | DEFLECT_API void removeSource(size_t sourceIndex); 75 | 76 | /** Get the number of sources for this Stream */ 77 | DEFLECT_API size_t getSourceCount() const; 78 | 79 | /** 80 | * Insert a tile for the current frame and source. 81 | * @param tile The tile to insert 82 | * @param sourceIndex Unique source identifier 83 | */ 84 | DEFLECT_API void insert(const Tile& tile, size_t sourceIndex); 85 | 86 | /** 87 | * Call when the source has finished sending tiles for the current frame. 88 | * @param sourceIndex Unique source identifier 89 | * @throw std::runtime_error if the buffer exceeds its maximum size 90 | */ 91 | DEFLECT_API void finishFrameForSource(size_t sourceIndex); 92 | 93 | /** Does the Buffer have a new complete frame (from all sources) */ 94 | DEFLECT_API bool hasCompleteFrame() const; 95 | 96 | /** 97 | * Get the finished frame. 98 | * @return A collection of tiles that form a frame 99 | */ 100 | DEFLECT_API Tiles popFrame(); 101 | 102 | /** Allow this buffer to be used by the next 103 | * FrameDispatcher::sendLatestFrame */ 104 | DEFLECT_API void setAllowedToSend(bool enable); 105 | 106 | /** @return true if this buffer can be sent by FrameDispatcher */ 107 | DEFLECT_API bool isAllowedToSend() const; 108 | 109 | private: 110 | FrameIndex _lastFrameComplete = 0; 111 | std::map _sourceBuffers; 112 | bool _allowedToSend = false; 113 | }; 114 | } 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /deflect/server/SourceBuffer.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "SourceBuffer.h" 41 | 42 | #include 43 | 44 | namespace deflect 45 | { 46 | namespace server 47 | { 48 | SourceBuffer::SourceBuffer() 49 | { 50 | _tiles.push(Tiles()); 51 | } 52 | 53 | const Tiles& SourceBuffer::getTiles() const 54 | { 55 | return _tiles.front(); 56 | } 57 | 58 | FrameIndex SourceBuffer::getBackFrameIndex() const 59 | { 60 | return _backFrameIndex; 61 | } 62 | 63 | bool SourceBuffer::isBackFrameEmpty() const 64 | { 65 | return _tiles.back().empty(); 66 | } 67 | 68 | void SourceBuffer::pop() 69 | { 70 | _tiles.pop(); 71 | } 72 | 73 | void SourceBuffer::push() 74 | { 75 | _tiles.push(Tiles()); 76 | ++_backFrameIndex; 77 | } 78 | 79 | void SourceBuffer::insert(const Tile& tile) 80 | { 81 | _tiles.back().push_back(tile); 82 | } 83 | 84 | size_t SourceBuffer::getQueueSize() const 85 | { 86 | return _tiles.size(); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /deflect/server/SourceBuffer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_SOURCEBUFFER_H 41 | #define DEFLECT_SERVER_SOURCEBUFFER_H 42 | 43 | #include 44 | 45 | #include 46 | #include 47 | 48 | namespace deflect 49 | { 50 | namespace server 51 | { 52 | using FrameIndex = unsigned int; 53 | 54 | /** 55 | * Buffer for a single source of tiles. 56 | */ 57 | class SourceBuffer 58 | { 59 | public: 60 | /** Construct an empty buffer. */ 61 | SourceBuffer(); 62 | 63 | /** @return the tiles at the front of the queue. */ 64 | const Tiles& getTiles() const; 65 | 66 | /** @return the frame index of the back of the buffer. */ 67 | FrameIndex getBackFrameIndex() const; 68 | 69 | /** @return true if the back frame has no tiles. */ 70 | bool isBackFrameEmpty() const; 71 | 72 | /** Insert a tile into the back frame. */ 73 | void insert(const Tile& tile); 74 | 75 | /** Push a new frame to the back. */ 76 | void push(); 77 | 78 | /** Pop the front frame. */ 79 | void pop(); 80 | 81 | /** @return the size of the queue. */ 82 | size_t getQueueSize() const; 83 | 84 | private: 85 | /** The collections of tiles for each mono/left/right view. */ 86 | std::queue _tiles; 87 | 88 | /** The current indices of the mono/left/right frame for this source. */ 89 | FrameIndex _backFrameIndex = 0u; 90 | }; 91 | } 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /deflect/server/Tile.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_TILE_H 41 | #define DEFLECT_SERVER_TILE_H 42 | 43 | #include 44 | 45 | #include 46 | 47 | namespace deflect 48 | { 49 | namespace server 50 | { 51 | /** 52 | * A Tile is a sub-region of an image in a Frame. 53 | */ 54 | struct Tile 55 | { 56 | /** @name Coordinates */ 57 | //@{ 58 | uint32_t x = 0u; /**< The x position in pixels. */ 59 | uint32_t y = 0u; /**< The y position in pixels. */ 60 | //@} 61 | 62 | /** @name Dimensions */ 63 | //@{ 64 | uint32_t width = 0u; /**< The width in pixels. */ 65 | uint32_t height = 0u; /**< The height in pixels. */ 66 | //@} 67 | 68 | /** Image data. */ 69 | QByteArray imageData; 70 | 71 | /** @name Image data parameters */ 72 | //@{ 73 | Format format = Format::jpeg; //!< Format in which the data is stored 74 | RowOrder rowOrder = RowOrder::top_down; //!< Row order of imageData 75 | //@} 76 | 77 | /** @name Metadata */ 78 | //@{ 79 | View view = View::mono; //!< Eye pass for the Tile 80 | uint8_t channel = 0; //!< Channel for the Tile 81 | //@} 82 | }; 83 | } 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /deflect/server/types.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_SERVER_TYPES_H 41 | #define DEFLECT_SERVER_TYPES_H 42 | 43 | #include 44 | 45 | namespace deflect 46 | { 47 | namespace server 48 | { 49 | class EventReceiver; 50 | class FrameDispatcher; 51 | class TileDecoder; 52 | class Server; 53 | 54 | struct Frame; 55 | struct Tile; 56 | 57 | using Tiles = std::vector; 58 | using BoolPromisePtr = std::shared_ptr>; 59 | using FramePtr = std::shared_ptr; 60 | } 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2021 Daniel Nachbaur 3 | 4 | install(FILES Changelog.md ../LICENSE.txt 5 | DESTINATION ${COMMON_DOC_DIR} COMPONENT doc) 6 | -------------------------------------------------------------------------------- /doc/ChromaSubsampling.md: -------------------------------------------------------------------------------- 1 | YUV & Chroma Subsampling 2 | ============ 3 | 4 | This document provides general information about the YUV decoding and 5 | chrominance subsampling support introduced in Deflect 0.13. 6 | 7 | ## Introduction 8 | 9 | The JPEG algorithm must convert RGB input images to YUV prior to performing the 10 | actual compression. The inverse transform is applied when decoding. 11 | 12 | The rendering process can be made faster by skipping the YUV -> RGB step and 13 | displaying the YUV images directly through an OpenGL shader. 14 | 15 | ## Chroma Subsampling 16 | 17 | In addition to JPEG compression, the image size can be reduced by subsampling 18 | the chrominance channels in the YUV color space. This technique is widely used 19 | for movie encoding (most codecs use YUV420 by default). It has limited impact 20 | on visual quality when applied to "natural" images, although it can be more 21 | detrimental to artifical images such as computer interfaces. 22 | 23 | Supported chrominance subsampling modes in Deflect are: 24 | 25 | * YUV444 - No sub-sampling (default, image size: 100%) 26 | * YUV422 - 50% vertical sub-sampling (image size: 75%) 27 | * YUV420 - 50% vertical + horizontal sub-sampling (image size: 50%) 28 | 29 | ## Results 30 | 31 | Chroma subsampling test results obtained with a 3840x1200[px] desktop stream. 32 | 33 | | JPEG Quality | YUV444 vs YUV420 | JPEG size reduction (%) | 34 | | ------------- | ---------------- | -----------------------:| 35 | | 20 | 320 / 250 KB | 22 % | 36 | | 50 | 450 / 370 KB | 18 % | 37 | | 75 | 590 / 490 KB | 17 % | 38 | | 90 | 850 / 700 KB | 17 % | 39 | | 100 | 2000 / 1500 KB | 25 % | 40 | 41 | We observe modest gains of network bandwidth using YUV420 subsampling (17% at 42 | quality 75), but further performance is gained on the server side during 43 | the transfer of the decompressed YUV image to GPU memory (50% less data). 44 | -------------------------------------------------------------------------------- /doc/StereoStreaming.md: -------------------------------------------------------------------------------- 1 | Stereo Streaming 2 | ============ 3 | 4 | This document describes the stereo streaming support introduced in Deflect 0.13. 5 | 6 | ## Requirements 7 | 8 | * Simple extension of the monoscopic Stream API 9 | * No network protocol changes that break current Deflect clients or servers 10 | * Support both screen space decompostion (sort-first) and left-right stereo 11 | decomposition modes for distributed rendering. 12 | 13 | ![Stereo streaming overview](stereo.png) 14 | 15 | ## API 16 | 17 | New view enum in deflect/types.h: 18 | 19 | enum class View : std::int8_t { mono, left_eye, right_eye }; 20 | 21 | The ImageWrapper takes an additional View parameter. 22 | 23 | API changes to the Stream class: 24 | * asyncSend is renamed to sendAndFinish, asyncSend forwards and is deprecated 25 | * send and finish are now asynchronous and return a future instead of bool 26 | 27 | The send operation sends one tile of one eye pass to the server. The finishFrame 28 | operation completes the whole frame for all eye passes, that is, send is 29 | analogous to an OpenGL draw pass (GL_BACK, GL_BACK_LEFT, GL_BACK_RIGHT), and 30 | finishFrame is analogous to a swap buffer call, with the extension that all 31 | client's finish is synchronized by the server. 32 | 33 | On the server side, no changes to the Server API (except some cleanups). Each 34 | Segment dispatched now with a Frame contains the View information. A frame is 35 | considered complete when all connected clients have send a finish. 36 | 37 | 38 | ## Protocol 39 | 40 | The Stream send an additional View information message before each image 41 | payload. This message is silently ignored by older Servers. 42 | 43 | ## Examples 44 | 45 | Example of a stereo 3D client application using synchronous operations: 46 | 47 | deflect::Stream stream( ... ); 48 | 49 | /** ...synchronize start with other render clients (network barrier)... */ 50 | 51 | renderLoop() 52 | { 53 | /** ...render left image... */ 54 | 55 | deflect::ImageWrapper leftImage( data, width, height, deflect::RGBA ); 56 | leftImage.view = deflect::View::left_eye; 57 | deflectStream->send( leftImage ).wait(); 58 | 59 | /** ...render right image... */ 60 | 61 | deflect::ImageWrapper rightImage( data, width, height, deflect::RGBA ); 62 | rightImage.view = deflect::View::right_eye; 63 | deflectStream->send( rightImage ).wait(); 64 | 65 | deflectStream->finishFrame().wait(); 66 | 67 | /** ...synchronize with other render clients (network barrier)... */ 68 | } 69 | 70 | Example of a stereo 3D client application using the asynchronous operations: 71 | 72 | deflect::Stream stream( ... ); 73 | 74 | /** ...synchronize start with other render clients (network barrier)... */ 75 | std::vector< std::future< bool >> futures; 76 | renderLoop() 77 | { 78 | for( auto& future : futures ) 79 | if( !future.get( )) 80 | return; 81 | futures.clear(); 82 | 83 | /** ...render left image... */ 84 | 85 | deflect::ImageWrapper leftImage( leftData, width, height, deflect::RGBA ); 86 | leftImage.view = deflect::View::left_eye; 87 | futures.emplace_back( deflectStream->send( leftImage )); 88 | 89 | /** ...render right image... */ 90 | 91 | deflect::ImageWrapper rightImage( rightData, width, height, deflect::RGBA ); 92 | rightImage.view = deflect::View::right_eye; 93 | futures.emplace_back( deflectStream->send( rightImage )); 94 | 95 | futures.emplace_back( deflectStream->finishFrame( )); 96 | 97 | /** ...synchronize with other render clients (network barrier)... */ 98 | } 99 | 100 | For a complete code example, please refer to the SimpleStreamer application. 101 | 102 | ## Issues 103 | 104 | ### 1: Should clients be notified if they attempt to stream stereo content to a server which can only handle monoscopic content? 105 | 106 | _Resolution: Not yet:_ 107 | For legacy implementation reasons, it is not possible to 108 | send information from the Server to the Stream about the capabilities of the 109 | server (such as stereo support) without rejecting all clients based on Deflect 110 | < 0.12.1. A transition period is required before implementing this feature. 111 | -------------------------------------------------------------------------------- /doc/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/doc/overview.png -------------------------------------------------------------------------------- /doc/stereo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueBrain/Deflect/9b74863ce4b48f71aebbe91925b9cbc2c80df1e4/doc/stereo.png -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2015, EPFL/Blue Brain Project 3 | # Daniel Nachbaur 4 | # Raphael Dumusc 5 | 6 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/mock) 7 | 8 | add_subdirectory(mock) 9 | add_subdirectory(cpp) 10 | -------------------------------------------------------------------------------- /tests/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2018, EPFL/Blue Brain Project 3 | # Daniel Nachbaur 4 | # Raphael Dumusc 5 | # 6 | # Change this number when adding tests to force a CMake run: 0 7 | 8 | set(TEST_LIBRARIES DeflectServer DeflectMock ${Boost_LIBRARIES} Qt5::Widgets) 9 | add_definitions(-DBOOST_PROGRAM_OPTIONS_DYN_LINK) 10 | if(NOT DEFLECT_USE_LIBJPEGTURBO) 11 | set(EXCLUDE_FROM_TESTS TileDecoderTests.cpp) 12 | endif() 13 | include(CommonCTest) 14 | -------------------------------------------------------------------------------- /tests/cpp/FrameTests.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #define BOOST_TEST_MODULE FrameTests 41 | 42 | #include 43 | namespace ut = boost::unit_test; 44 | 45 | #include "FrameUtils.h" 46 | 47 | BOOST_AUTO_TEST_CASE(compute_frame_dimensions) 48 | { 49 | auto frame = makeTestFrame(640, 480, 64); 50 | BOOST_CHECK_EQUAL(frame.computeDimensions(), QSize(640, 480)); 51 | 52 | frame = makeTestFrame(1920, 1200, 64); 53 | BOOST_CHECK_EQUAL(frame.computeDimensions(), QSize(1920, 1200)); 54 | 55 | frame = makeTestFrame(1920, 1080, 32); 56 | BOOST_CHECK_EQUAL(frame.computeDimensions(), QSize(1920, 1080)); 57 | 58 | frame = makeTestFrame(2158, 1786, 56); 59 | BOOST_CHECK_EQUAL(frame.computeDimensions(), QSize(2158, 1786)); 60 | } 61 | 62 | BOOST_AUTO_TEST_CASE(determine_frame_row_order) 63 | { 64 | auto frame = makeTestFrame(640, 480, 64); 65 | BOOST_CHECK(frame.determineRowOrder() == deflect::RowOrder::top_down); 66 | 67 | frame.tiles[0].rowOrder = deflect::RowOrder::bottom_up; 68 | BOOST_CHECK_THROW(frame.determineRowOrder(), std::runtime_error); 69 | 70 | for (auto& tile : frame.tiles) 71 | tile.rowOrder = deflect::RowOrder::bottom_up; 72 | BOOST_CHECK(frame.determineRowOrder() == deflect::RowOrder::bottom_up); 73 | 74 | frame.tiles[0].rowOrder = deflect::RowOrder::top_down; 75 | BOOST_CHECK_THROW(frame.determineRowOrder(), std::runtime_error); 76 | } 77 | -------------------------------------------------------------------------------- /tests/cpp/ImageWrapperTests.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #define BOOST_TEST_MODULE ImageWrapper 41 | #include 42 | namespace ut = boost::unit_test; 43 | 44 | #include 45 | 46 | BOOST_AUTO_TEST_CASE(testImageBufferSize) 47 | { 48 | char* data = nullptr; 49 | 50 | { 51 | deflect::ImageWrapper imageWrapper(data, 7, 5, deflect::ARGB); 52 | BOOST_CHECK_EQUAL(imageWrapper.getBufferSize(), 7 * 5 * 4); 53 | } 54 | { 55 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::ARGB); 56 | BOOST_CHECK_EQUAL(imageWrapper.getBufferSize(), 256 * 512 * 4); 57 | } 58 | { 59 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::RGB); 60 | BOOST_CHECK_EQUAL(imageWrapper.getBufferSize(), 256 * 512 * 3); 61 | } 62 | } 63 | 64 | BOOST_AUTO_TEST_CASE(testImageBytesPerPixel) 65 | { 66 | char* data = nullptr; 67 | 68 | { 69 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::RGB); 70 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 3); 71 | } 72 | { 73 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::RGBA); 74 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 4); 75 | } 76 | { 77 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::ARGB); 78 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 4); 79 | } 80 | { 81 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::BGR); 82 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 3); 83 | } 84 | { 85 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::BGRA); 86 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 4); 87 | } 88 | { 89 | deflect::ImageWrapper imageWrapper(data, 256, 512, deflect::ABGR); 90 | BOOST_CHECK_EQUAL(imageWrapper.getBytesPerPixel(), 4); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/cpp/NetworkSerializationTests.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #define BOOST_TEST_MODULE NetworkSerializationTests 41 | #include 42 | namespace ut = boost::unit_test; 43 | 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | 50 | BOOST_AUTO_TEST_CASE(testMessageHeaderSerialization) 51 | { 52 | QByteArray storage; 53 | 54 | deflect::MessageHeader header(deflect::MESSAGE_TYPE_PIXELSTREAM, 512, 55 | std::string("MyUri")); 56 | QDataStream dataStreamOut(&storage, QIODevice::Append); 57 | dataStreamOut << header; 58 | 59 | deflect::MessageHeader messageHeaderDeserialized; 60 | QDataStream dataStreamIn(storage); 61 | dataStreamIn >> messageHeaderDeserialized; 62 | 63 | BOOST_CHECK_EQUAL(messageHeaderDeserialized.type, header.type); 64 | BOOST_CHECK_EQUAL(messageHeaderDeserialized.size, header.size); 65 | BOOST_CHECK_EQUAL(std::string(messageHeaderDeserialized.uri), 66 | std::string(header.uri)); 67 | } 68 | 69 | BOOST_AUTO_TEST_CASE(testEventSerialization) 70 | { 71 | QByteArray storage; 72 | 73 | deflect::Event event; 74 | event.type = deflect::Event::EVT_PRESS; 75 | event.mouseX = 0.78; 76 | event.mouseY = 0.456; 77 | 78 | event.dx = 0.6; 79 | event.dy = 0.2; 80 | 81 | event.mouseLeft = true; 82 | event.mouseRight = true; 83 | event.mouseMiddle = true; 84 | 85 | event.key = 'Y'; 86 | event.modifiers = Qt::ControlModifier; 87 | 88 | QDataStream dataStreamOut(&storage, QIODevice::Append); 89 | dataStreamOut << event; 90 | 91 | deflect::Event eventDeserialized; 92 | QDataStream dataStreamIn(storage); 93 | dataStreamIn >> eventDeserialized; 94 | 95 | BOOST_CHECK_EQUAL(eventDeserialized.type, event.type); 96 | BOOST_CHECK_EQUAL(eventDeserialized.mouseX, event.mouseX); 97 | BOOST_CHECK_EQUAL(eventDeserialized.mouseY, event.mouseY); 98 | BOOST_CHECK_EQUAL(eventDeserialized.dx, event.dx); 99 | BOOST_CHECK_EQUAL(eventDeserialized.dy, event.dy); 100 | BOOST_CHECK_EQUAL(eventDeserialized.mouseLeft, event.mouseLeft); 101 | BOOST_CHECK_EQUAL(eventDeserialized.mouseRight, event.mouseRight); 102 | BOOST_CHECK_EQUAL(eventDeserialized.mouseMiddle, event.mouseMiddle); 103 | BOOST_CHECK_EQUAL(eventDeserialized.key, event.key); 104 | BOOST_CHECK_EQUAL(eventDeserialized.modifiers, event.modifiers); 105 | } 106 | -------------------------------------------------------------------------------- /tests/cpp/SocketTests.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #define BOOST_TEST_MODULE Socket 41 | #include 42 | namespace ut = boost::unit_test; 43 | 44 | #include "MinimalDeflectServer.h" 45 | #include "MinimalGlobalQtApp.h" 46 | 47 | #include 48 | 49 | BOOST_GLOBAL_FIXTURE(MinimalGlobalQtApp); 50 | 51 | void testSocketConnect(const int32_t versionOffset) 52 | { 53 | MinimalDeflectServer server(versionOffset); 54 | 55 | try 56 | { 57 | deflect::Socket socket("localhost", server.serverPort()); 58 | BOOST_CHECK(socket.isConnected()); 59 | BOOST_CHECK_EQUAL(socket.getPort(), server.serverPort()); 60 | } 61 | catch (const std::runtime_error&) 62 | { 63 | BOOST_CHECK(versionOffset < 0); 64 | } 65 | } 66 | 67 | BOOST_AUTO_TEST_CASE( 68 | testSocketConnectionValidWhenReturnedCorrectNetworkProtocolVersion) 69 | { 70 | testSocketConnect(0); 71 | } 72 | 73 | BOOST_AUTO_TEST_CASE( 74 | testSocketConnectionInvalidWhenReturnedLowerNetworkProtocolVersion) 75 | { 76 | testSocketConnect(-1); 77 | } 78 | 79 | BOOST_AUTO_TEST_CASE( 80 | testSocketConnectionInvalidWhenReturnedHigherNetworkProtocolVersion) 81 | { 82 | testSocketConnect(1); 83 | } 84 | -------------------------------------------------------------------------------- /tests/mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2013-2018, EPFL/Blue Brain Project 3 | # Daniel Nachbaur 4 | # Raphael Dumusc 5 | # 6 | # Generates a mock library used by the cpp unit tests. 7 | 8 | set(DEFLECTMOCK_HEADERS 9 | boost_test_thread_safe.h 10 | DeflectServer.h 11 | FrameUtils.h 12 | MinimalGlobalQtApp.h 13 | MinimalDeflectServer.h 14 | MockServer.h 15 | Timer.h 16 | ) 17 | 18 | set(DEFLECTMOCK_SOURCES 19 | DeflectServer.cpp 20 | MinimalDeflectServer.cpp 21 | MockServer.cpp 22 | ) 23 | 24 | set(DEFLECTMOCK_LINK_LIBRARIES Deflect DeflectServer Qt5::Core Qt5::Network 25 | ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 26 | 27 | set(DEFLECTMOCK_INCLUDE_NAME deflect/mock) 28 | set(DEFLECTMOCK_OMIT_LIBRARY_HEADER ON) 29 | set(DEFLECTMOCK_OMIT_VERSION_HEADERS ON) 30 | set(DEFLECTMOCK_OMIT_CHECK_TARGETS ON) 31 | set(DEFLECTMOCK_OMIT_INSTALL ON) 32 | common_library(DeflectMock) 33 | -------------------------------------------------------------------------------- /tests/mock/DeflectServer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur@epfl.ch */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_DEFLECTSERVER_H 41 | #define DEFLECT_DEFLECTSERVER_H 42 | 43 | #ifdef _WIN32 44 | typedef __int32 int32_t; 45 | #endif 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | #include 52 | #include 53 | 54 | class DeflectServer 55 | { 56 | public: 57 | explicit DeflectServer(); 58 | ~DeflectServer(); 59 | 60 | quint16 serverPort() const { return _server->getPort(); } 61 | void requestFrame(QString uri); 62 | void waitForMessage(); 63 | 64 | size_t getReceivedFrames() const { return _receivedFrames; } 65 | size_t getOpenedStreams() const { return _openedStreams; } 66 | using SizeHintsCallback = 67 | std::function; 68 | void setSizeHintsCallback(const SizeHintsCallback& callback) 69 | { 70 | _sizeHintsCallback = callback; 71 | } 72 | 73 | using RegisterToEventsCallback = 74 | std::function; 76 | void setRegisterToEventsCallback(const RegisterToEventsCallback& callback) 77 | { 78 | _registerToEventsCallback = callback; 79 | } 80 | 81 | using DataReceivedCallback = std::function; 82 | void setDataReceivedCallback(const DataReceivedCallback& callback) 83 | { 84 | _dataReceivedCallback = callback; 85 | } 86 | 87 | using FrameReceivedCallback = 88 | std::function; 89 | void setFrameReceivedCallback(const FrameReceivedCallback& callback) 90 | { 91 | _frameReceivedCallback = callback; 92 | } 93 | 94 | void processEvent(const deflect::Event& event); 95 | 96 | private: 97 | QThread _thread; 98 | // destroyed by Object::deleteLater 99 | deflect::server::Server* _server = nullptr; 100 | 101 | bool _receivedState{false}; 102 | QWaitCondition _received; 103 | QMutex _mutex; 104 | 105 | size_t _openedStreams{0}; 106 | size_t _receivedFrames{0}; 107 | 108 | SizeHintsCallback _sizeHintsCallback; 109 | RegisterToEventsCallback _registerToEventsCallback; 110 | DataReceivedCallback _dataReceivedCallback; 111 | FrameReceivedCallback _frameReceivedCallback; 112 | 113 | deflect::server::EventReceiver* _eventReceiver{nullptr}; 114 | }; 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /tests/mock/FrameUtils.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017-2018, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include 41 | 42 | #include // std::ceil 43 | 44 | inline deflect::server::Frame makeTestFrame(int width, int height, int tileSize) 45 | { 46 | const int numTilesX = std::ceil((float)width / (float)tileSize); 47 | const int numTilesY = std::ceil((float)height / (float)tileSize); 48 | 49 | const int lastTileWidth = 50 | (width % tileSize) > 0 ? (width % tileSize) : tileSize; 51 | const int lastTileHeight = 52 | (height % tileSize) > 0 ? (height % tileSize) : tileSize; 53 | 54 | deflect::server::Frame frame; 55 | for (int y = 0; y < numTilesY; ++y) 56 | { 57 | for (int x = 0; x < numTilesX; ++x) 58 | { 59 | deflect::server::Tile tile; 60 | tile.x = x * tileSize; 61 | tile.y = y * tileSize; 62 | tile.width = tileSize; 63 | tile.height = tileSize; 64 | if (x == numTilesX - 1) 65 | tile.width = lastTileWidth; 66 | if (y == numTilesY - 1) 67 | tile.height = lastTileHeight; 68 | frame.tiles.push_back(tile); 69 | } 70 | } 71 | return frame; 72 | } 73 | 74 | inline void compare(const deflect::server::Frame& frame1, 75 | const deflect::server::Frame& frame2) 76 | { 77 | BOOST_REQUIRE_EQUAL(frame1.tiles.size(), frame2.tiles.size()); 78 | 79 | for (size_t i = 0; i < frame1.tiles.size(); ++i) 80 | { 81 | const auto& t1 = frame1.tiles[i]; 82 | const auto& t2 = frame2.tiles[i]; 83 | BOOST_CHECK(t1.view == t2.view); 84 | BOOST_CHECK(t1.rowOrder == t2.rowOrder); 85 | BOOST_CHECK_EQUAL(t1.x, t2.x); 86 | BOOST_CHECK_EQUAL(t1.y, t2.y); 87 | BOOST_CHECK_EQUAL(t1.width, t2.width); 88 | BOOST_CHECK_EQUAL(t1.height, t2.height); 89 | } 90 | } 91 | 92 | inline std::ostream& operator<<(std::ostream& str, const QSize& s) 93 | { 94 | str << s.width() << 'x' << s.height(); 95 | return str; 96 | } 97 | -------------------------------------------------------------------------------- /tests/mock/MinimalDeflectServer.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur@epfl.ch */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "MinimalDeflectServer.h" 41 | 42 | #include 43 | 44 | MinimalDeflectServer::MinimalDeflectServer(const int32_t versionOffset) 45 | { 46 | _server = new MockServer(NETWORK_PROTOCOL_VERSION + versionOffset); 47 | _server->moveToThread(&_thread); 48 | _server->connect(&_thread, &QThread::finished, _server, 49 | &QObject::deleteLater); 50 | _thread.start(); 51 | } 52 | 53 | MinimalDeflectServer::~MinimalDeflectServer() 54 | { 55 | _thread.quit(); 56 | _thread.wait(); 57 | } 58 | -------------------------------------------------------------------------------- /tests/mock/MinimalDeflectServer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Daniel.Nachbaur@epfl.ch */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_MINIMAL_DEFLECTSERVER_H 41 | #define DEFLECT_MINIMAL_DEFLECTSERVER_H 42 | 43 | #include "MockServer.h" 44 | 45 | #include 46 | 47 | class MinimalDeflectServer 48 | { 49 | public: 50 | explicit MinimalDeflectServer(int32_t versionOffset = 0); 51 | ~MinimalDeflectServer(); 52 | 53 | quint16 serverPort() const { return _server->serverPort(); } 54 | private: 55 | QThread _thread; 56 | MockServer* _server; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tests/mock/MinimalGlobalQtApp.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_MINIMALGLOBALQTAPP_H 41 | #define DEFLECT_MINIMALGLOBALQTAPP_H 42 | 43 | #include 44 | #include 45 | 46 | // We need a global fixture because a bug in QApplication prevents 47 | // deleting then recreating a QApplication in the same process. 48 | // https://bugreports.qt-project.org/browse/QTBUG-7104 49 | struct MinimalGlobalQtApp : public boost::noncopyable 50 | { 51 | MinimalGlobalQtApp() 52 | { 53 | // need QApplication to instantiate WebkitPixelStreamer 54 | ut::master_test_suite_t& testSuite = ut::framework::master_test_suite(); 55 | app = new QCoreApplication(testSuite.argc, testSuite.argv); 56 | } 57 | virtual ~MinimalGlobalQtApp() { delete app; } 58 | QCoreApplication* app = nullptr; 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /tests/mock/MockServer.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #include "MockServer.h" 41 | 42 | #include 43 | 44 | MockServer::MockServer(const int32_t protocolVersion) 45 | : _protocolVersion{protocolVersion} 46 | { 47 | if (!listen()) 48 | qDebug("MockServer could not start listening!!"); 49 | 50 | // Handshake -> send network protocol version 51 | connect(this, &QTcpServer::newConnection, [this]() { 52 | auto tcpSocket = nextPendingConnection(); 53 | tcpSocket->write((char*)&_protocolVersion, sizeof(int32_t)); 54 | tcpSocket->flush(); 55 | }); 56 | } 57 | -------------------------------------------------------------------------------- /tests/mock/MockServer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef DEFLECT_MOCKSERVER_H 41 | #define DEFLECT_MOCKSERVER_H 42 | 43 | #ifdef _WIN32 44 | typedef __int32 int32_t; 45 | #endif 46 | 47 | #include 48 | 49 | #include 50 | 51 | class MockServer : public QTcpServer 52 | { 53 | Q_OBJECT 54 | 55 | public: 56 | DEFLECT_API explicit MockServer(int32_t protocolVersion); 57 | 58 | private: 59 | const int32_t _protocolVersion; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /tests/mock/Timer.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2016, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef TIMER_H 41 | #define TIMER_H 42 | 43 | #include 44 | 45 | class Timer 46 | { 47 | public: 48 | using clock = std::chrono::high_resolution_clock; 49 | 50 | void start() { _startTime = clock::now(); } 51 | void restart() { start(); } 52 | float elapsed() 53 | { 54 | return std::chrono::duration{clock::now() - _startTime}.count(); 55 | } 56 | 57 | private: 58 | clock::time_point _startTime; 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /tests/mock/boost_test_thread_safe.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************/ 2 | /* Copyright (c) 2017, EPFL/Blue Brain Project */ 3 | /* Raphael Dumusc */ 4 | /* All rights reserved. */ 5 | /* */ 6 | /* Redistribution and use in source and binary forms, with or */ 7 | /* without modification, are permitted provided that the following */ 8 | /* conditions are met: */ 9 | /* */ 10 | /* 1. Redistributions of source code must retain the above */ 11 | /* copyright notice, this list of conditions and the following */ 12 | /* disclaimer. */ 13 | /* */ 14 | /* 2. Redistributions in binary form must reproduce the above */ 15 | /* copyright notice, this list of conditions and the following */ 16 | /* disclaimer in the documentation and/or other materials */ 17 | /* provided with the distribution. */ 18 | /* */ 19 | /* THIS SOFTWARE IS PROVIDED BY THE ECOLE POLYTECHNIQUE */ 20 | /* FEDERALE DE LAUSANNE ''AS IS'' AND ANY EXPRESS OR IMPLIED */ 21 | /* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 22 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 23 | /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ECOLE */ 24 | /* POLYTECHNIQUE FEDERALE DE LAUSANNE OR CONTRIBUTORS BE */ 25 | /* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ 26 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 27 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 28 | /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ 29 | /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ 30 | /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE */ 31 | /* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 32 | /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 33 | /* */ 34 | /* The views and conclusions contained in the software and */ 35 | /* documentation are those of the authors and should not be */ 36 | /* interpreted as representing official policies, either expressed */ 37 | /* or implied, of Ecole polytechnique federale de Lausanne. */ 38 | /*********************************************************************/ 39 | 40 | #ifndef BOOST_TEST_THREAD_SAFE_H 41 | #define BOOST_TEST_THREAD_SAFE_H 42 | 43 | #include 44 | #include 45 | 46 | #define SAFE_TEST(T) \ 47 | do \ 48 | { \ 49 | static std::mutex _boostTestMutex; \ 50 | std::lock_guard _boostTestLock(_boostTestMutex); \ 51 | T; \ 52 | } while (0); 53 | 54 | #define SAFE_BOOST_REQUIRE(P) SAFE_TEST(BOOST_REQUIRE((P))) 55 | #define SAFE_BOOST_REQUIRE_EQUAL(L, R) SAFE_TEST(BOOST_REQUIRE_EQUAL((L), (R))) 56 | #define SAFE_BOOST_CHECK(P) SAFE_TEST(BOOST_CHECK((P))) 57 | #define SAFE_BOOST_CHECK_EQUAL(L, R) SAFE_TEST(BOOST_CHECK_EQUAL((L), (R))) 58 | #define SAFE_BOOST_CHECK_THROW(L, R) SAFE_TEST(BOOST_CHECK_THROW((L), R)) 59 | 60 | #endif 61 | --------------------------------------------------------------------------------