├── .MODULE_NAME_pdraw ├── .MODULE_LICENSE_BSD ├── AUTHORS ├── qpdraw ├── qpdraw.pro ├── atom.mk ├── src │ ├── qpdraw_priv.hpp │ ├── qpdraw_widget_priv.hpp │ ├── qpdraw.cpp │ └── qpdraw_demuxer_priv.hpp └── include │ └── pdraw │ └── qpdraw.hpp ├── .clang-format ├── libpdraw-vsink ├── atom.mk └── include │ └── pdraw-vsink │ └── pdraw_vsink.h ├── apps └── pdraw_desktop │ ├── atom.mk │ └── pdraw_desktop_view.cpp ├── libpdraw ├── pdraw.in ├── src │ ├── pdraw_alsa_audio.hpp │ ├── pdraw_settings.hpp │ ├── pdraw_channel_audio.hpp │ ├── pdraw_gl_common.hpp │ ├── pdraw_channel_raw_video.hpp │ ├── pdraw_channel_coded_video.hpp │ ├── pdraw_channel_audio.cpp │ ├── pdraw_channel_raw_video.cpp │ ├── pdraw_decoder_audio.hpp │ ├── pdraw_video_pres_stats.cpp │ ├── pdraw_alsa_audio.cpp │ ├── pdraw_channel_coded_video.cpp │ ├── pdraw_decoder_video.hpp │ ├── pdraw_settings.cpp │ ├── pdraw_video_pres_stats.hpp │ ├── pdraw_renderer_audio.hpp │ ├── pdraw_renderer_audio_alsa.hpp │ ├── pdraw_demuxer_stream_net.hpp │ ├── pdraw_external_audio_source.hpp │ ├── pdraw_source.hpp │ ├── pdraw_channel.hpp │ ├── pdraw_scaler_video.hpp │ ├── pdraw_external_audio_sink.hpp │ ├── pdraw_demuxer_stream_mux.hpp │ ├── pdraw_renderer_video.hpp │ ├── pdraw_external_raw_video_source.hpp │ ├── pdraw_encoder_audio.hpp │ ├── pdraw_external_coded_video_source.hpp │ ├── pdraw_muxer_stream_rtmp.hpp │ ├── pdraw_external_raw_video_sink.hpp │ ├── pdraw_encoder_video.hpp │ ├── pdraw_alsa_source.hpp │ ├── pdraw_sink.hpp │ └── pdraw_renderer_audio.cpp └── atom.mk ├── COPYING ├── libpdraw-gles2hud ├── atom.mk └── src │ ├── pdraw_gles2hud_icons.cpp │ └── pdraw_gles2hud_text.cpp └── libpdraw-backend ├── atom.mk └── include └── pdraw └── pdraw_backend.hpp /.MODULE_NAME_pdraw: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.MODULE_LICENSE_BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Parrot Drones SAS 2 | Copyright (c) 2016 Aurelien Barre 3 | 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Aurelien Barre 2 | Original author 3 | Parrot Drones SAS 4 | Maintainer 5 | -------------------------------------------------------------------------------- /qpdraw/qpdraw.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | 3 | TARGET = qpdraw 4 | 5 | SOURCES += \ 6 | src/qpdraw.cpp \ 7 | src/qpdraw_demuxer.cpp \ 8 | src/qpdraw_widget.cpp 9 | 10 | HEADERS += \ 11 | include/pdraw/qpdraw.hpp \ 12 | include/pdraw/qpdraw_demuxer.hpp \ 13 | include/pdraw/qpdraw_widget.hpp \ 14 | src/qpdraw_priv.hpp \ 15 | src/qpdraw_demuxer_priv.hpp \ 16 | src/qpdraw_widget_priv.hpp 17 | 18 | exists($${OUT_PWD}/alchemy.pri) { 19 | include($${OUT_PWD}/alchemy.pri) 20 | } else: exists($${PWD}/alchemy.pri) { 21 | include($${PWD}/alchemy.pri) 22 | } 23 | -------------------------------------------------------------------------------- /qpdraw/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | ifeq ("$(TARGET_OS)","linux") 5 | ifneq ("$(TARGET_OS_FLAVOUR)","android") 6 | 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_MODULE := qpdraw 10 | LOCAL_CATEGORY_PATH := libs 11 | LOCAL_DESCRIPTION := PDrAW Qt library 12 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 13 | LOCAL_CXXFLAGS := -std=c++11 14 | 15 | LOCAL_SRC_FILES := \ 16 | $(call all-cpp-files-under,src) 17 | 18 | LOCAL_LIBRARIES := \ 19 | libfutils \ 20 | libpdraw-backend \ 21 | libulog 22 | 23 | LOCAL_DEPENDS_MODULES := qt5-base 24 | LOCAL_EXPORT_LDLIBS := -lqpdraw 25 | 26 | include $(BUILD_QMAKE) 27 | 28 | endif 29 | endif 30 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | AccessModifierOffset: -8 4 | AlignAfterOpenBracket: true 5 | AlignEscapedNewlinesLeft: false 6 | AlignOperands: true 7 | AlignTrailingComments: false 8 | AllowAllParametersOfDeclarationOnNextLine: false 9 | AllowShortFunctionsOnASingleLine: Empty 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AlwaysBreakBeforeMultilineStrings: true 13 | BinPackArguments: false 14 | BinPackParameters: false 15 | BreakBeforeBinaryOperators: None 16 | BreakBeforeBraces: WebKit 17 | BreakConstructorInitializers: AfterColon 18 | BreakStringLiterals: false 19 | ContinuationIndentWidth: 8 20 | ConstructorInitializerIndentWidth: 16 21 | IndentCaseLabels: false 22 | IndentPPDirectives: AfterHash 23 | IndentWidth: 8 24 | Language: Cpp 25 | MaxEmptyLinesToKeep: 2 26 | SortIncludes: true 27 | SpaceAfterCStyleCast: false 28 | UseTab: ForContinuationAndIndentation 29 | -------------------------------------------------------------------------------- /libpdraw-vsink/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE := libpdraw-vsink 7 | LOCAL_CATEGORY_PATH := libs 8 | LOCAL_DESCRIPTION := PDrAW video sink wrapper library 9 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 10 | LOCAL_CFLAGS := -DPDRAW_VSINK_API_EXPORTS -fvisibility=hidden -std=gnu99 -D_GNU_SOURCE 11 | LOCAL_SRC_FILES := \ 12 | src/pdraw_vsink.c 13 | LOCAL_LIBRARIES := \ 14 | libfutils \ 15 | libmedia-buffers \ 16 | libmedia-buffers-memory \ 17 | libmedia-buffers-memory-generic \ 18 | libpdraw \ 19 | libpomp \ 20 | libulog 21 | 22 | include $(BUILD_LIBRARY) 23 | 24 | 25 | include $(CLEAR_VARS) 26 | 27 | LOCAL_MODULE := pdraw-vsink-test 28 | LOCAL_DESCRIPTION := PDrAW video sink wrapper library test program 29 | LOCAL_CATEGORY_PATH := multimedia 30 | LOCAL_SRC_FILES := tests/pdraw_vsink_test.c 31 | LOCAL_LIBRARIES := \ 32 | libmedia-buffers \ 33 | libpdraw-vsink \ 34 | libulog \ 35 | libvideo-defs \ 36 | libvideo-metadata 37 | 38 | include $(BUILD_EXECUTABLE) 39 | -------------------------------------------------------------------------------- /apps/pdraw_desktop/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE := pdraw 7 | LOCAL_DESCRIPTION := PDrAW desktop player application 8 | LOCAL_CATEGORY_PATH := multimedia 9 | LOCAL_CFLAGS := -D_USE_MATH_DEFINES -D_GNU_SOURCE 10 | LOCAL_SRC_FILES := \ 11 | pdraw_desktop.c \ 12 | pdraw_desktop_ext_tex.c \ 13 | pdraw_desktop_ui.c \ 14 | pdraw_desktop_view.cpp 15 | LOCAL_LIBRARIES := \ 16 | eigen \ 17 | libfutils \ 18 | libmedia-buffers \ 19 | libpdraw \ 20 | libpdraw-backend \ 21 | libpdraw-gles2hud \ 22 | libpomp \ 23 | libulog \ 24 | libvideo-defs \ 25 | libvideo-metadata \ 26 | sdl2 27 | 28 | LOCAL_CONDITIONAL_LIBRARIES := \ 29 | OPTIONAL:libpdraw-overlayer 30 | 31 | ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","linux-native") 32 | LOCAL_LIBRARIES += \ 33 | opengl 34 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","darwin-native") 35 | LOCAL_LDLIBS += \ 36 | -framework OpenGL 37 | else ifeq ("$(TARGET_OS)","windows") 38 | LOCAL_CFLAGS += -D_WIN32_WINNT=0x0600 -DEPOXY_SHARED 39 | LOCAL_LDLIBS += -lws2_32 -lepoxy 40 | endif 41 | 42 | include $(BUILD_EXECUTABLE) 43 | -------------------------------------------------------------------------------- /libpdraw/pdraw.in: -------------------------------------------------------------------------------- 1 | config PDRAW_VIPC_BACKEND_DMABUF 2 | bool "Include vipc-dmabuf backend support" 3 | default n 4 | help 5 | Enable or disable support for vipc-dmabuf backend 6 | 7 | config PDRAW_VIPC_BACKEND_HISI 8 | bool "Include vipc-hisi backend support" 9 | default n 10 | help 11 | Enable or disable support for vipc-hisi backend 12 | 13 | config PDRAW_VIPC_BACKEND_SHM 14 | bool "Include vipc-shm backend support" 15 | default n 16 | help 17 | Enable or disable support for vipc-shm backend 18 | 19 | config PDRAW_VIPC_BACKEND_NETWORK_HISI 20 | bool "Include vipc-network-hisi backend support" 21 | default n 22 | help 23 | Enable or disable support for vipc-network-hisi backend 24 | 25 | config PDRAW_VIPC_BACKEND_NETWORK_CBUF 26 | bool "Include vipc-network-cbuf backend support" 27 | default n 28 | help 29 | Enable or disable support for vipc-network-cbuf backend 30 | 31 | config PDRAW_USE_GL 32 | bool "Use OpenGL" 33 | default n 34 | help 35 | Enable or disable OpenGL support 36 | 37 | config PDRAW_USE_ALSA 38 | bool "Use ALSA" 39 | default n 40 | help 41 | Enable or disable ALSA support 42 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Parrot Drones SAS 2 | Copyright (c) 2016 Aurelien Barre 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the copyright holders nor the names of its 12 | contributors may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /libpdraw-gles2hud/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | LOCAL_MODULE := libpdraw-gles2hud 6 | LOCAL_CATEGORY_PATH := libs 7 | LOCAL_DESCRIPTION := PDrAW OpenGL ES 2.0 HUD rendering library 8 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 9 | # Public API headers - top level headers first 10 | # This header list is currently used to generate a python binding 11 | LOCAL_EXPORT_CUSTOM_VARIABLES := LIBPDRAW_GLES2HUD_HEADERS=$\ 12 | $(LOCAL_PATH)/include/pdraw/pdraw_gles2hud.h; 13 | LOCAL_CFLAGS := \ 14 | -DPDRAW_GLES2HUD_API_EXPORTS \ 15 | -fvisibility=hidden \ 16 | -std=gnu99 \ 17 | -D_USE_MATH_DEFINES 18 | LOCAL_CXXFLAGS := -std=c++11 19 | LOCAL_SRC_FILES := \ 20 | src/pdraw_gles2hud.cpp \ 21 | src/pdraw_gles2hud_icons.cpp \ 22 | src/pdraw_gles2hud_icons_data.cpp \ 23 | src/pdraw_gles2hud_instruments.cpp \ 24 | src/pdraw_gles2hud_shaders.cpp \ 25 | src/pdraw_gles2hud_shapes.cpp \ 26 | src/pdraw_gles2hud_text.cpp \ 27 | src/pdraw_gles2hud_text_profont36.cpp 28 | LOCAL_LIBRARIES := \ 29 | eigen \ 30 | libpdraw \ 31 | libulog \ 32 | libvideo-metadata 33 | 34 | ifeq ($(TARGET_CPU),$(filter %$(TARGET_CPU),s905d3 s905x3)) 35 | LOCAL_LDLIBS += -lGLESv2 36 | LOCAL_LIBRARIES += \ 37 | am-gpu 38 | else ifeq ($(TARGET_CPU),qrb5165) 39 | LOCAL_LIBRARIES += \ 40 | glesv2 41 | else ifeq ($(TARGET_CPU),qcs405) 42 | LOCAL_LIBRARIES += \ 43 | glesv2 \ 44 | egl 45 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","linux-native") 46 | LOCAL_LIBRARIES += \ 47 | opengl 48 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","linux-android") 49 | LOCAL_LDLIBS += -lGLESv2 50 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","darwin-native") 51 | LOCAL_LDLIBS += \ 52 | -framework OpenGL 53 | else ifeq ($(TARGET_OS_FLAVOUR),$(filter %$(TARGET_OS_FLAVOUR),iphoneos iphonesimulator)) 54 | LOCAL_LDLIBS += \ 55 | -framework OpenGLES 56 | else ifeq ("$(TARGET_OS)","windows") 57 | LOCAL_CFLAGS += -D_WIN32_WINNT=0x0600 -DEPOXY_SHARED 58 | LOCAL_LDLIBS += -lepoxy 59 | endif 60 | 61 | include $(BUILD_LIBRARY) 62 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_alsa_audio.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * ALSA audio 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_ALSA_AUDIO_HPP_ 32 | #define _PDRAW_ALSA_AUDIO_HPP_ 33 | 34 | #ifdef PDRAW_USE_ALSA 35 | 36 | # include 37 | 38 | # include "pdraw_utils.hpp" 39 | 40 | # define ALSA_AUDIO_DEFAULT_SAMPLE_COUNT 1024 41 | 42 | namespace Pdraw { 43 | 44 | 45 | class AlsaAudio { 46 | public: 47 | static snd_pcm_format_t 48 | adefFormatToAlsa(const struct adef_format *format); 49 | 50 | static const struct adef_format * 51 | alsaFormatToAdef(snd_pcm_format_t format); 52 | }; 53 | 54 | } /* namespace Pdraw */ 55 | 56 | #endif /* PDRAW_USE_ALSA */ 57 | 58 | #endif /* !_PDRAW_ALSA_AUDIO_HPP_ */ 59 | -------------------------------------------------------------------------------- /apps/pdraw_desktop/pdraw_desktop_view.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Desktop player application 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "pdraw_desktop.h" 34 | 35 | 36 | void pdraw_desktop_view_create_matrices(struct pdraw_desktop *self, 37 | unsigned int width, 38 | unsigned int height, 39 | float *view_mat, 40 | float *proj_mat, 41 | float near, 42 | float far) 43 | { 44 | float w = 1.f; 45 | float h = (float)width / (float)height; 46 | float a = (far + near) / (far - near); 47 | float b = -((2 * far * near) / (far - near)); 48 | 49 | Eigen::Matrix4f p_mat; 50 | p_mat << w, 0, 0, 0, 0, h, 0, 0, 0, 0, a, b, 0, 0, 1, 0; 51 | 52 | Eigen::Matrix4f v_mat = Eigen::Matrix4f::Identity(); 53 | 54 | unsigned int i, j; 55 | for (i = 0; i < 4; i++) { 56 | for (j = 0; j < 4; j++) 57 | view_mat[j * 4 + i] = v_mat(i, j); 58 | } 59 | for (i = 0; i < 4; i++) { 60 | for (j = 0; j < 4; j++) 61 | proj_mat[j * 4 + i] = p_mat(i, j); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /qpdraw/src/qpdraw_priv.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Qt PDrAW object 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _QPDRAW_PRIV_HPP_ 32 | #define _QPDRAW_PRIV_HPP_ 33 | 34 | #include 35 | #include 36 | 37 | using namespace Pdraw; 38 | using namespace PdrawBackend; 39 | 40 | namespace QPdraw { 41 | namespace Internal { 42 | 43 | 44 | class QPdrawPriv : public IPdraw::Listener { 45 | 46 | public: 47 | explicit QPdrawPriv(QPdraw *parent); 48 | ~QPdrawPriv(); 49 | 50 | int start(void); 51 | 52 | int stop(void); 53 | 54 | intptr_t getInternal(void); 55 | 56 | struct pomp_loop *getLoop(void); 57 | 58 | private: 59 | void stopResponse(IPdraw *pdraw, int status) override; 60 | 61 | void onMediaAdded(IPdraw *pdraw, 62 | const struct pdraw_media_info *info, 63 | void *elementUserData) override; 64 | 65 | void onMediaRemoved(IPdraw *pdraw, 66 | const struct pdraw_media_info *info, 67 | void *elementUserData) override; 68 | 69 | void onSocketCreated(IPdraw *pdraw, int fd) override; 70 | 71 | QPdraw *mParent; 72 | IPdrawBackend *mPdraw; 73 | }; 74 | 75 | } /* namespace Internal */ 76 | } /* namespace QPdraw */ 77 | 78 | #endif /* !_QPDRAW_PRIV_HPP_ */ 79 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_settings.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * User settings 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_SETTINGS_HPP_ 32 | #define _PDRAW_SETTINGS_HPP_ 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | 45 | #define SETTINGS_DISPLAY_XDPI (200.0f) 46 | #define SETTINGS_DISPLAY_YDPI (200.0f) 47 | #define SETTINGS_DISPLAY_DEVICE_MARGIN (0.0f) 48 | 49 | 50 | class Settings { 51 | public: 52 | Settings(void); 53 | 54 | ~Settings(void); 55 | 56 | void lock(void); 57 | 58 | void unlock(void); 59 | 60 | void getFriendlyName(std::string *friendlyName); 61 | 62 | void setFriendlyName(const std::string &friendlyName); 63 | 64 | void getSerialNumber(std::string *serialNumber); 65 | 66 | void setSerialNumber(const std::string &serialNumber); 67 | 68 | void getSoftwareVersion(std::string *softwareVersion); 69 | 70 | void setSoftwareVersion(const std::string &softwareVersion); 71 | 72 | private: 73 | pthread_mutex_t mMutex; 74 | std::string mFriendlyName; 75 | std::string mSerialNumber; 76 | std::string mSoftwareVersion; 77 | }; 78 | 79 | } /* namespace Pdraw */ 80 | 81 | #endif /* !_PDRAW_SETTINGS_HPP_ */ 82 | -------------------------------------------------------------------------------- /libpdraw-backend/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE := libpdraw-backend 7 | LOCAL_CATEGORY_PATH := libs 8 | LOCAL_DESCRIPTION := PDrAW back-end library 9 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 10 | LOCAL_CFLAGS := -DPDRAW_BACKEND_API_EXPORTS -fvisibility=hidden -std=gnu99 11 | LOCAL_SRC_FILES := \ 12 | src/pdraw_backend_impl.cpp \ 13 | src/pdraw_backend_wrapper.cpp 14 | LOCAL_LIBRARIES := \ 15 | libfutils \ 16 | libpdraw \ 17 | libpomp \ 18 | libulog 19 | 20 | include $(BUILD_LIBRARY) 21 | 22 | 23 | include $(CLEAR_VARS) 24 | 25 | LOCAL_MODULE := pdraw-backend-test 26 | LOCAL_CATEGORY_PATH := multimedia 27 | LOCAL_DESCRIPTION := PDrAW back-end library test program 28 | LOCAL_SRC_FILES := \ 29 | tests/pdraw_backend_test.c 30 | LOCAL_LIBRARIES := \ 31 | libpdraw \ 32 | libpdraw-backend \ 33 | libulog 34 | 35 | include $(BUILD_EXECUTABLE) 36 | 37 | 38 | include $(CLEAR_VARS) 39 | 40 | LOCAL_MODULE := pdraw-vipcsourcesink-test 41 | LOCAL_CATEGORY_PATH := multimedia 42 | LOCAL_DESCRIPTION := PDrAW video IPC source to sink test program 43 | LOCAL_SRC_FILES := \ 44 | tests/pdraw_vipcsourcesink_test.c 45 | LOCAL_LIBRARIES := \ 46 | libmedia-buffers \ 47 | libmedia-buffers-memory \ 48 | libmedia-buffers-memory-generic \ 49 | libpdraw \ 50 | libpdraw-backend \ 51 | libulog \ 52 | libvideo-defs \ 53 | libvideo-raw 54 | 55 | include $(BUILD_EXECUTABLE) 56 | 57 | 58 | include $(CLEAR_VARS) 59 | 60 | LOCAL_MODULE := pdraw-rawsourcesink-test 61 | LOCAL_CATEGORY_PATH := multimedia 62 | LOCAL_DESCRIPTION := PDrAW raw video source to sink test program 63 | LOCAL_SRC_FILES := \ 64 | tests/pdraw_rawsourcesink_test.c 65 | LOCAL_LIBRARIES := \ 66 | libmedia-buffers \ 67 | libmedia-buffers-memory \ 68 | libmedia-buffers-memory-generic \ 69 | libpdraw \ 70 | libpdraw-backend \ 71 | libulog \ 72 | libvideo-defs \ 73 | libvideo-raw 74 | 75 | include $(BUILD_EXECUTABLE) 76 | 77 | 78 | include $(CLEAR_VARS) 79 | 80 | LOCAL_MODULE := pdraw-codedsourcesink-test 81 | LOCAL_CATEGORY_PATH := multimedia 82 | LOCAL_DESCRIPTION := PDrAW coded video source to sink test program 83 | LOCAL_SRC_FILES := \ 84 | tests/pdraw_codedsourcesink_test.c 85 | LOCAL_LIBRARIES := \ 86 | libh264 \ 87 | libh265 \ 88 | libmedia-buffers \ 89 | libmedia-buffers-memory \ 90 | libmedia-buffers-memory-generic \ 91 | libpdraw \ 92 | libpdraw-backend \ 93 | libulog \ 94 | libvideo-defs 95 | 96 | ifeq ("$(TARGET_OS)","windows") 97 | LOCAL_LDLIBS += -lws2_32 98 | endif 99 | 100 | include $(BUILD_EXECUTABLE) 101 | 102 | 103 | include $(CLEAR_VARS) 104 | 105 | LOCAL_MODULE := pdraw-audiosourcesink-test 106 | LOCAL_CATEGORY_PATH := multimedia 107 | LOCAL_DESCRIPTION := PDrAW audio source to sink test program 108 | LOCAL_SRC_FILES := \ 109 | tests/pdraw_audiosourcesink_test.c 110 | LOCAL_LIBRARIES := \ 111 | libaudio-defs \ 112 | libaudio-raw \ 113 | libmedia-buffers \ 114 | libmedia-buffers-memory \ 115 | libmedia-buffers-memory-generic \ 116 | libpdraw \ 117 | libpdraw-backend \ 118 | libulog 119 | 120 | include $(BUILD_EXECUTABLE) 121 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_audio.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for audio 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_CHANNEL_AUDIO_HPP_ 32 | #define _PDRAW_CHANNEL_AUDIO_HPP_ 33 | 34 | #include "pdraw_channel.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | class AudioChannel : public Channel { 45 | public: 46 | class AudioSinkListener { 47 | public: 48 | virtual ~AudioSinkListener(void) {} 49 | 50 | virtual void 51 | onAudioChannelQueue(AudioChannel *channel, 52 | struct mbuf_audio_frame *frame) = 0; 53 | }; 54 | 55 | AudioChannel(Sink *owner, 56 | SinkListener *sinkListener, 57 | AudioSinkListener *audioSinkListener, 58 | struct pomp_loop *loop); 59 | 60 | ~AudioChannel(void) {} 61 | 62 | int queue(mbuf_audio_frame *frame); 63 | 64 | int getAudioMediaFormatCaps(const struct adef_format **caps); 65 | 66 | void setAudioMediaFormatCaps(Sink *owner, 67 | const struct adef_format *caps, 68 | int count); 69 | 70 | struct mbuf_audio_frame_queue *getQueue(Sink *owner); 71 | 72 | void setQueue(Sink *owner, struct mbuf_audio_frame_queue *queue); 73 | 74 | private: 75 | AudioSinkListener *mAudioSinkListener; 76 | const struct adef_format *mAudioMediaFormatCaps; 77 | int mAudioMediaFormatCapsCount; 78 | struct mbuf_audio_frame_queue *mQueue; 79 | }; 80 | 81 | } /* namespace Pdraw */ 82 | 83 | #endif /* !_PDRAW_CHANNEL_AUDIO_HPP_ */ 84 | -------------------------------------------------------------------------------- /libpdraw-gles2hud/src/pdraw_gles2hud_icons.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * OpenGL ES 2.0 HUD rendering library 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "pdraw_gles2hud_priv.h" 32 | 33 | 34 | void pdraw_gles2hud_draw_icon(struct pdraw_gles2hud *self, 35 | int index, 36 | float x, 37 | float y, 38 | float size, 39 | float scalew, 40 | float scaleh, 41 | const float color[4]) 42 | { 43 | float vertices[8]; 44 | float texcoords[8]; 45 | 46 | vertices[0] = x - size * scalew / 2.; 47 | vertices[1] = y - size * scaleh / 2.; 48 | vertices[2] = x + size * scalew / 2.; 49 | vertices[3] = y - size * scaleh / 2.; 50 | vertices[4] = x - size * scalew / 2.; 51 | vertices[5] = y + size * scaleh / 2.; 52 | vertices[6] = x + size * scalew / 2.; 53 | vertices[7] = y + size * scaleh / 2.; 54 | 55 | GLCHK(glVertexAttribPointer( 56 | self->tex_position_handle, 2, GL_FLOAT, false, 0, vertices)); 57 | 58 | int ix = index % 3; 59 | int iy = index / 3; 60 | 61 | texcoords[0] = ((float)ix + 0.) / 3.; 62 | texcoords[1] = ((float)iy + 0.99) / 3.; 63 | texcoords[2] = ((float)ix + 0.99) / 3.; 64 | texcoords[3] = ((float)iy + 0.99) / 3.; 65 | texcoords[4] = ((float)ix + 0.) / 3.; 66 | texcoords[5] = ((float)iy + 0.) / 3.; 67 | texcoords[6] = ((float)ix + 0.99) / 3.; 68 | texcoords[7] = ((float)iy + 0.) / 3.; 69 | 70 | GLCHK(glVertexAttribPointer( 71 | self->tex_texcoord_handle, 2, GL_FLOAT, false, 0, texcoords)); 72 | 73 | GLCHK(glUniform4fv(self->tex_color_handle, 1, color)); 74 | 75 | GLCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); 76 | } 77 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_gl_common.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * OpenGL common header 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_GL_COMMON_HPP_ 32 | #define _PDRAW_GL_COMMON_HPP_ 33 | 34 | #ifdef PDRAW_USE_GL 35 | 36 | # if defined(__APPLE__) 37 | # include 38 | # if TARGET_OS_IPHONE 39 | # include 40 | # include 41 | # else 42 | # define GL_GLEXT_PROTOTYPES 43 | # include 44 | # include 45 | # include 46 | # endif 47 | # elif defined(_WIN32) 48 | # include 49 | # else 50 | # include 51 | # endif 52 | 53 | /* Uncomment to enable extra GL error checking */ 54 | // # define CHECK_GL_ERRORS 55 | # if defined(CHECK_GL_ERRORS) 56 | # warning CHECK_GL_ERRORS is enabled 57 | # include 58 | # define GLCHK(X) \ 59 | do { \ 60 | GLenum err = GL_NO_ERROR; \ 61 | X; \ 62 | while ((err = glGetError())) { \ 63 | ULOGE("GL error 0x%x in " #X \ 64 | " file %s line %d", \ 65 | err, \ 66 | __FILE__, \ 67 | __LINE__); \ 68 | assert(err == GL_NO_ERROR); \ 69 | } \ 70 | } while (0) 71 | # else 72 | # define GLCHK(X) X 73 | # endif /* CHECK_GL_ERRORS */ 74 | 75 | #endif /* PDRAW_USE_GL */ 76 | 77 | #endif /* !_PDRAW_GL_COMMON_HPP_ */ 78 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_raw_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for raw video 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_CHANNEL_RAW_VIDEO_HPP_ 32 | #define _PDRAW_CHANNEL_RAW_VIDEO_HPP_ 33 | 34 | #include "pdraw_channel.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | class RawVideoChannel : public Channel { 45 | public: 46 | class RawVideoSinkListener { 47 | public: 48 | virtual ~RawVideoSinkListener(void) {} 49 | 50 | virtual void 51 | onRawVideoChannelQueue(RawVideoChannel *channel, 52 | struct mbuf_raw_video_frame *frame) = 0; 53 | }; 54 | 55 | RawVideoChannel(Sink *owner, 56 | SinkListener *sinkListener, 57 | RawVideoSinkListener *rawVideoSinkListener, 58 | struct pomp_loop *loop); 59 | 60 | ~RawVideoChannel(void) {} 61 | 62 | int queue(mbuf_raw_video_frame *frame); 63 | 64 | int 65 | getRawVideoMediaFormatCaps(const struct vdef_raw_format **caps) const; 66 | 67 | void setRawVideoMediaFormatCaps(const Sink *owner, 68 | const struct vdef_raw_format *caps, 69 | int count); 70 | 71 | struct mbuf_raw_video_frame_queue *getQueue(const Sink *owner) const; 72 | 73 | void setQueue(const Sink *owner, 74 | struct mbuf_raw_video_frame_queue *queue); 75 | 76 | private: 77 | RawVideoSinkListener *mRawVideoSinkListener; 78 | const struct vdef_raw_format *mRawVideoMediaFormatCaps; 79 | int mRawVideoMediaFormatCapsCount; 80 | struct mbuf_raw_video_frame_queue *mQueue; 81 | }; 82 | 83 | } /* namespace Pdraw */ 84 | 85 | #endif /* !_PDRAW_CHANNEL_RAW_VIDEO_HPP_ */ 86 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_coded_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for coded video 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_CHANNEL_CODED_VIDEO_HPP_ 32 | #define _PDRAW_CHANNEL_CODED_VIDEO_HPP_ 33 | 34 | #include "pdraw_channel.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | class CodedVideoChannel : public Channel { 45 | public: 46 | class CodedVideoSinkListener { 47 | public: 48 | virtual ~CodedVideoSinkListener(void) {} 49 | 50 | virtual void 51 | onCodedVideoChannelQueue(CodedVideoChannel *channel, 52 | mbuf_coded_video_frame *frame) = 0; 53 | }; 54 | 55 | CodedVideoChannel(Sink *owner, 56 | SinkListener *sinkListener, 57 | CodedVideoSinkListener *codedVideoSinkListener, 58 | struct pomp_loop *loop); 59 | 60 | ~CodedVideoChannel(void) {} 61 | 62 | int queue(mbuf_coded_video_frame *frame); 63 | 64 | int getCodedVideoMediaFormatCaps( 65 | const struct vdef_coded_format **caps) const; 66 | 67 | void setCodedVideoMediaFormatCaps(const Sink *owner, 68 | const struct vdef_coded_format *caps, 69 | int count); 70 | 71 | bool onlySupportsByteStream() const; 72 | 73 | struct mbuf_coded_video_frame_queue *getQueue(const Sink *owner) const; 74 | 75 | void setQueue(const Sink *owner, 76 | struct mbuf_coded_video_frame_queue *queue); 77 | 78 | private: 79 | CodedVideoSinkListener *mCodedVideoSinkListener; 80 | const struct vdef_coded_format *mCodedVideoMediaFormatCaps; 81 | int mCodedVideoMediaFormatCapsCount; 82 | struct mbuf_coded_video_frame_queue *mQueue; 83 | }; 84 | 85 | } /* namespace Pdraw */ 86 | 87 | #endif /* !_PDRAW_CHANNEL_CODED_VIDEO_HPP_ */ 88 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_audio.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for audio 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_channel_audio 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include "pdraw_channel_audio.hpp" 36 | #include "pdraw_media.hpp" 37 | 38 | #include 39 | 40 | namespace Pdraw { 41 | 42 | 43 | AudioChannel::AudioChannel(Sink *owner, 44 | SinkListener *sinkListener, 45 | AudioSinkListener *audioSinkListener, 46 | struct pomp_loop *loop) : 47 | Channel(owner, sinkListener, loop), 48 | mAudioSinkListener(audioSinkListener), 49 | mAudioMediaFormatCaps(nullptr), mAudioMediaFormatCapsCount(0), 50 | mQueue(nullptr) 51 | { 52 | } 53 | 54 | 55 | int AudioChannel::getAudioMediaFormatCaps(const struct adef_format **caps) 56 | { 57 | if (caps == nullptr) 58 | return -EINVAL; 59 | *caps = mAudioMediaFormatCaps; 60 | return mAudioMediaFormatCapsCount; 61 | } 62 | 63 | 64 | void AudioChannel::setAudioMediaFormatCaps(Sink *owner, 65 | const struct adef_format *caps, 66 | int count) 67 | { 68 | if (owner != mOwner) { 69 | ULOGE("AudioChannel::setAudioMediaFormatCaps: " 70 | "wrong owner"); 71 | return; 72 | } 73 | mAudioMediaFormatCaps = caps; 74 | mAudioMediaFormatCapsCount = count; 75 | } 76 | 77 | 78 | struct mbuf_audio_frame_queue *AudioChannel::getQueue(Sink *owner) 79 | { 80 | if (owner != mOwner) { 81 | ULOGE("AudioChannel::getQueue: wrong owner"); 82 | return nullptr; 83 | } 84 | return mQueue; 85 | } 86 | 87 | 88 | void AudioChannel::setQueue(Sink *owner, struct mbuf_audio_frame_queue *queue) 89 | { 90 | if (owner != mOwner) { 91 | ULOGE("AudioChannel::setQueue: wrong owner"); 92 | return; 93 | } 94 | mQueue = queue; 95 | } 96 | 97 | 98 | int AudioChannel::queue(mbuf_audio_frame *frame) 99 | { 100 | if (frame == nullptr) 101 | return -EINVAL; 102 | if (mAudioSinkListener == nullptr) { 103 | ULOGE("invalid sink listener"); 104 | return -EPROTO; 105 | } 106 | 107 | mAudioSinkListener->onAudioChannelQueue(this, frame); 108 | return 0; 109 | } 110 | 111 | } /* namespace Pdraw */ 112 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_raw_video.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for raw video 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_channel_raw_video 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include "pdraw_channel_raw_video.hpp" 36 | #include "pdraw_media.hpp" 37 | 38 | #include 39 | 40 | namespace Pdraw { 41 | 42 | 43 | RawVideoChannel::RawVideoChannel(Sink *owner, 44 | SinkListener *sinkListener, 45 | RawVideoSinkListener *rawVideoSinkListener, 46 | struct pomp_loop *loop) : 47 | Channel(owner, sinkListener, loop), 48 | mRawVideoSinkListener(rawVideoSinkListener), 49 | mRawVideoMediaFormatCaps(nullptr), 50 | mRawVideoMediaFormatCapsCount(0), mQueue(nullptr) 51 | { 52 | } 53 | 54 | 55 | int RawVideoChannel::getRawVideoMediaFormatCaps( 56 | const struct vdef_raw_format **caps) const 57 | { 58 | if (caps == nullptr) 59 | return -EINVAL; 60 | *caps = mRawVideoMediaFormatCaps; 61 | return mRawVideoMediaFormatCapsCount; 62 | } 63 | 64 | 65 | void RawVideoChannel::setRawVideoMediaFormatCaps( 66 | const Sink *owner, 67 | const struct vdef_raw_format *caps, 68 | int count) 69 | { 70 | if (owner != mOwner) { 71 | ULOGE("RawVideoChannel::setRawVideoMediaFormatCaps: " 72 | "wrong owner"); 73 | return; 74 | } 75 | mRawVideoMediaFormatCaps = caps; 76 | mRawVideoMediaFormatCapsCount = count; 77 | } 78 | 79 | 80 | struct mbuf_raw_video_frame_queue * 81 | RawVideoChannel::getQueue(const Sink *owner) const 82 | { 83 | if (owner != mOwner) { 84 | ULOGE("RawVideoChannel::getQueue: wrong owner"); 85 | return nullptr; 86 | } 87 | return mQueue; 88 | } 89 | 90 | 91 | void RawVideoChannel::setQueue(const Sink *owner, 92 | struct mbuf_raw_video_frame_queue *queue) 93 | { 94 | if (owner != mOwner) { 95 | ULOGE("RawVideoChannel::setQueue: wrong owner"); 96 | return; 97 | } 98 | mQueue = queue; 99 | } 100 | 101 | 102 | int RawVideoChannel::queue(mbuf_raw_video_frame *frame) 103 | { 104 | if (frame == nullptr) 105 | return -EINVAL; 106 | if (mRawVideoSinkListener == nullptr) { 107 | ULOGE("invalid sink listener"); 108 | return -EPROTO; 109 | } 110 | 111 | mRawVideoSinkListener->onRawVideoChannelQueue(this, frame); 112 | return 0; 113 | } 114 | 115 | } /* namespace Pdraw */ 116 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_decoder_audio.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Audio decoder element 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_DECODER_AUDIO_HPP_ 32 | #define _PDRAW_DECODER_AUDIO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class AudioDecoder : public FilterElement { 44 | public: 45 | AudioDecoder(Session *session, 46 | Element::Listener *elementListener, 47 | Source::Listener *sourceListener); 48 | 49 | ~AudioDecoder(void); 50 | 51 | int start(void) override; 52 | 53 | int stop(void) override; 54 | 55 | void completeFlush(void); 56 | 57 | void completeStop(void); 58 | 59 | private: 60 | int createOutputMedia(const struct adef_frame *frameInfo, 61 | const AudioMedia::Frame &frame); 62 | 63 | int flush(bool discard = true); 64 | 65 | inline int drain(void) 66 | { 67 | return flush(false); 68 | } 69 | 70 | int tryStop(void); 71 | 72 | void onAudioChannelQueue(AudioChannel *channel, 73 | struct mbuf_audio_frame *buf) override; 74 | 75 | void onChannelFlush(Channel *channel) override; 76 | 77 | void onChannelFlushed(Channel *channel) override; 78 | 79 | void onChannelDrain(Channel *channel) override; 80 | 81 | void onChannelDrained(Channel *channel) override; 82 | 83 | void onChannelTeardown(Channel *channel) override; 84 | 85 | void onChannelUnlink(Channel *channel) override; 86 | 87 | static void frameOutputCb(struct adec_decoder *dec, 88 | int status, 89 | struct mbuf_audio_frame *out_frame, 90 | void *userdata); 91 | 92 | static void flushCb(struct adec_decoder *dec, void *userdata); 93 | 94 | static void stopCb(struct adec_decoder *dec, void *userdata); 95 | 96 | static void idleCompleteFlush(void *userdata); 97 | 98 | AudioMedia *mInputMedia; 99 | AudioMedia *mOutputMedia; 100 | struct mbuf_pool *mInputBufferPool; 101 | struct mbuf_audio_frame_queue *mInputBufferQueue; 102 | struct adec_decoder *mAdec; 103 | bool mInputChannelFlushPending; 104 | bool mOutputChannelDrainRequired; 105 | bool mAdecFlushPending; 106 | bool mAdecStopPending; 107 | static const struct adec_cbs mDecoderCbs; 108 | }; 109 | 110 | } /* namespace Pdraw */ 111 | 112 | #endif /* !_PDRAW_DECODER_AUDIO_HPP_ */ 113 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_video_pres_stats.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video presentation statistics 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_video_pres_stats 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include 36 | 37 | #include "pdraw_video_pres_stats.hpp" 38 | 39 | namespace Pdraw { 40 | 41 | 42 | VideoPresStats::VideoPresStats(void) : 43 | timestamp(0), presentationFrameCount(0), 44 | presentationTimestampDeltaIntegral(0), 45 | presentationTimestampDeltaIntegralSq(0), 46 | presentationTimingErrorIntegral(0), 47 | presentationTimingErrorIntegralSq(0), 48 | presentationEstimatedLatencyIntegral(0), 49 | presentationEstimatedLatencyIntegralSq(0), 50 | playerLatencyIntegral(0), playerLatencyIntegralSq(0), 51 | estimatedLatencyPrecisionIntegral(0) 52 | { 53 | } 54 | 55 | 56 | int VideoPresStats::writeMsg(struct pomp_msg *msg, uint32_t msgid) 57 | { 58 | ULOG_ERRNO_RETURN_ERR_IF(msg == nullptr, EINVAL); 59 | 60 | return pomp_msg_write(msg, 61 | msgid, 62 | "%" PRIu64 "%" PRIu32 "%" PRIu64 "%" PRIu64 63 | "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 64 | "%" PRIu64 "%" PRIu64 "%" PRIu64, 65 | timestamp, 66 | presentationFrameCount, 67 | presentationTimestampDeltaIntegral, 68 | presentationTimestampDeltaIntegralSq, 69 | presentationTimingErrorIntegral, 70 | presentationTimingErrorIntegralSq, 71 | presentationEstimatedLatencyIntegral, 72 | presentationEstimatedLatencyIntegralSq, 73 | playerLatencyIntegral, 74 | playerLatencyIntegralSq, 75 | estimatedLatencyPrecisionIntegral); 76 | } 77 | 78 | 79 | int VideoPresStats::readMsg(const struct pomp_msg *msg) 80 | { 81 | ULOG_ERRNO_RETURN_ERR_IF(msg == nullptr, EINVAL); 82 | 83 | return pomp_msg_read(msg, 84 | "%" PRIu64 "%" PRIu32 "%" PRIu64 "%" PRIu64 85 | "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 86 | "%" PRIu64 "%" PRIu64 "%" PRIu64, 87 | ×tamp, 88 | &presentationFrameCount, 89 | &presentationTimestampDeltaIntegral, 90 | &presentationTimestampDeltaIntegralSq, 91 | &presentationTimingErrorIntegral, 92 | &presentationTimingErrorIntegralSq, 93 | &presentationEstimatedLatencyIntegral, 94 | &presentationEstimatedLatencyIntegralSq, 95 | &playerLatencyIntegral, 96 | &playerLatencyIntegralSq, 97 | &estimatedLatencyPrecisionIntegral); 98 | } 99 | 100 | } /* namespace Pdraw */ 101 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_alsa_audio.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * ALSA audio 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #define ULOG_TAG pdraw_alsaaudio 33 | #include 34 | ULOG_DECLARE_TAG(ULOG_TAG); 35 | 36 | #include "pdraw_alsa_audio.hpp" 37 | 38 | #ifdef PDRAW_USE_ALSA 39 | 40 | # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) 41 | 42 | 43 | namespace Pdraw { 44 | 45 | 46 | static const struct { 47 | enum _snd_pcm_format sndFormat; 48 | const struct adef_format *adefFormat; 49 | } audio_format_map[] = { 50 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_8000hz_stereo}, 51 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_8000hz_mono}, 52 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_11025hz_mono}, 53 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_11025hz_stereo}, 54 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_12000hz_mono}, 55 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_12000hz_stereo}, 56 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_16000hz_mono}, 57 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_16000hz_stereo}, 58 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_22050hz_mono}, 59 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_22050hz_stereo}, 60 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_24000hz_mono}, 61 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_24000hz_stereo}, 62 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_32000hz_mono}, 63 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_32000hz_stereo}, 64 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_44100hz_mono}, 65 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_44100hz_stereo}, 66 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_48000hz_mono}, 67 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_48000hz_stereo}, 68 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_64000hz_mono}, 69 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_64000hz_stereo}, 70 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_88200hz_mono}, 71 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_88200hz_stereo}, 72 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_96000hz_mono}, 73 | {SND_PCM_FORMAT_S16_LE, &adef_pcm_16b_96000hz_stereo}, 74 | }; 75 | 76 | 77 | snd_pcm_format_t AlsaAudio::adefFormatToAlsa(const struct adef_format *format) 78 | { 79 | for (unsigned int i = 0; i < ARRAY_SIZE(audio_format_map); i++) { 80 | if (adef_format_cmp(audio_format_map[i].adefFormat, format)) 81 | return audio_format_map[i].sndFormat; 82 | } 83 | 84 | return SND_PCM_FORMAT_UNKNOWN; 85 | } 86 | 87 | 88 | const struct adef_format *AlsaAudio::alsaFormatToAdef(snd_pcm_format_t format) 89 | { 90 | for (unsigned int i = 0; i < ARRAY_SIZE(audio_format_map); i++) { 91 | if (audio_format_map[i].sndFormat == format) 92 | return audio_format_map[i].adefFormat; 93 | } 94 | 95 | return nullptr; 96 | } 97 | 98 | } /* namespace Pdraw */ 99 | 100 | #endif /* PDRAW_USE_ALSA */ 101 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel_coded_video.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel for coded video 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_channel_coded_video 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include "pdraw_channel_coded_video.hpp" 36 | #include "pdraw_media.hpp" 37 | 38 | #include 39 | 40 | namespace Pdraw { 41 | 42 | 43 | CodedVideoChannel::CodedVideoChannel( 44 | Sink *owner, 45 | SinkListener *sinkListener, 46 | CodedVideoSinkListener *codedVideoSinkListener, 47 | struct pomp_loop *loop) : 48 | Channel(owner, sinkListener, loop), 49 | mCodedVideoSinkListener(codedVideoSinkListener), 50 | mCodedVideoMediaFormatCaps(nullptr), 51 | mCodedVideoMediaFormatCapsCount(0), mQueue(nullptr) 52 | { 53 | } 54 | 55 | 56 | int CodedVideoChannel::getCodedVideoMediaFormatCaps( 57 | const struct vdef_coded_format **caps) const 58 | { 59 | if (caps == nullptr) 60 | return -EINVAL; 61 | *caps = mCodedVideoMediaFormatCaps; 62 | return mCodedVideoMediaFormatCapsCount; 63 | } 64 | 65 | 66 | void CodedVideoChannel::setCodedVideoMediaFormatCaps( 67 | const Sink *owner, 68 | const struct vdef_coded_format *caps, 69 | int count) 70 | { 71 | if (owner != mOwner) { 72 | ULOGE("CodedVideoChannel::setRawVideoMediaFormatCaps: " 73 | "wrong owner"); 74 | return; 75 | } 76 | mCodedVideoMediaFormatCaps = caps; 77 | mCodedVideoMediaFormatCapsCount = count; 78 | } 79 | 80 | 81 | bool CodedVideoChannel::onlySupportsByteStream() const 82 | { 83 | for (int i = 0; i < mCodedVideoMediaFormatCapsCount; i++) { 84 | if (mCodedVideoMediaFormatCaps[i].data_format != 85 | VDEF_CODED_DATA_FORMAT_BYTE_STREAM) 86 | return false; 87 | } 88 | return true; 89 | } 90 | 91 | 92 | struct mbuf_coded_video_frame_queue * 93 | CodedVideoChannel::getQueue(const Sink *owner) const 94 | { 95 | if (owner != mOwner) { 96 | ULOGE("CodedVideoChannel::getQueue: wrong owner"); 97 | return nullptr; 98 | } 99 | return mQueue; 100 | } 101 | 102 | 103 | void CodedVideoChannel::setQueue(const Sink *owner, 104 | struct mbuf_coded_video_frame_queue *queue) 105 | { 106 | if (owner != mOwner) { 107 | ULOGE("CodedVideoChannel::setQueue: wrong owner"); 108 | return; 109 | } 110 | mQueue = queue; 111 | } 112 | 113 | 114 | int CodedVideoChannel::queue(mbuf_coded_video_frame *frame) 115 | { 116 | if (frame == nullptr) 117 | return -EINVAL; 118 | if (mCodedVideoSinkListener == nullptr) { 119 | ULOGE("invalid sink listener"); 120 | return -EPROTO; 121 | } 122 | 123 | mCodedVideoSinkListener->onCodedVideoChannelQueue(this, frame); 124 | return 0; 125 | } 126 | 127 | } /* namespace Pdraw */ 128 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_decoder_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video decoder element 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_DECODER_VIDEO_HPP_ 32 | #define _PDRAW_DECODER_VIDEO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class VideoDecoder : public FilterElement { 44 | public: 45 | VideoDecoder(Session *session, 46 | Element::Listener *elementListener, 47 | Source::Listener *sourceListener); 48 | 49 | ~VideoDecoder(void); 50 | 51 | int start(void) override; 52 | 53 | int stop(void) override; 54 | 55 | void completeFlush(void); 56 | 57 | void completeStop(void); 58 | 59 | void resync(void); 60 | 61 | private: 62 | int createOutputMedia(const struct vdef_raw_frame *frameInfo, 63 | const RawVideoMedia::Frame &frame); 64 | 65 | int flush(bool discard = true); 66 | 67 | inline int drain(void) 68 | { 69 | return flush(false); 70 | } 71 | 72 | void completeResync(void); 73 | 74 | int tryStop(void); 75 | 76 | void 77 | onCodedVideoChannelQueue(CodedVideoChannel *channel, 78 | struct mbuf_coded_video_frame *buf) override; 79 | 80 | void onChannelFlush(Channel *channel) override; 81 | 82 | void onChannelDrain(Channel *channel) override; 83 | 84 | void onChannelFlushed(Channel *channel) override; 85 | 86 | void onChannelDrained(Channel *channel) override; 87 | 88 | void onChannelTeardown(Channel *channel) override; 89 | 90 | void onChannelUnlink(Channel *channel) override; 91 | 92 | void onChannelSessionMetaUpdate(Channel *channel) override; 93 | 94 | static void frameOutputCb(struct vdec_decoder *dec, 95 | int status, 96 | struct mbuf_raw_video_frame *out_frame, 97 | void *userdata); 98 | 99 | static void flushCb(struct vdec_decoder *dec, void *userdata); 100 | 101 | static void stopCb(struct vdec_decoder *dec, void *userdata); 102 | 103 | static void idleCompleteFlush(void *userdata); 104 | 105 | static ssize_t preparePsBuffer(const uint8_t *ps, 106 | size_t psSize, 107 | enum vdef_coded_data_format fmt, 108 | uint8_t **ret); 109 | 110 | CodedVideoMedia *mInputMedia; 111 | RawVideoMedia *mOutputMedia; 112 | struct mbuf_pool *mInputBufferPool; 113 | struct mbuf_coded_video_frame_queue *mInputBufferQueue; 114 | struct vdec_decoder *mVdec; 115 | bool mInputChannelFlushPending; 116 | bool mOutputChannelDrainRequired; 117 | bool mResyncPending; 118 | bool mVdecFlushPending; 119 | bool mVdecStopPending; 120 | static const struct vdec_cbs mDecoderCbs; 121 | }; 122 | 123 | } /* namespace Pdraw */ 124 | 125 | #endif /* !_PDRAW_DECODER_VIDEO_HPP_ */ 126 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_settings.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * User settings 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_settings 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include "pdraw_settings.hpp" 36 | 37 | namespace Pdraw { 38 | 39 | 40 | Settings::Settings(void) 41 | { 42 | int res; 43 | pthread_mutexattr_t attr; 44 | bool attr_created = false; 45 | 46 | res = pthread_mutexattr_init(&attr); 47 | if (res != 0) { 48 | ULOG_ERRNO("pthread_mutexattr_init", res); 49 | goto error; 50 | } 51 | attr_created = true; 52 | 53 | res = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 54 | if (res != 0) { 55 | ULOG_ERRNO("pthread_mutexattr_settype", res); 56 | goto error; 57 | } 58 | 59 | res = pthread_mutex_init(&mMutex, &attr); 60 | if (res != 0) { 61 | ULOG_ERRNO("pthread_mutex_init", res); 62 | goto error; 63 | } 64 | 65 | pthread_mutexattr_destroy(&attr); 66 | return; 67 | 68 | error: 69 | if (attr_created) 70 | pthread_mutexattr_destroy(&attr); 71 | } 72 | 73 | 74 | Settings::~Settings(void) 75 | { 76 | pthread_mutex_destroy(&mMutex); 77 | } 78 | 79 | 80 | void Settings::lock(void) 81 | { 82 | pthread_mutex_lock(&mMutex); 83 | } 84 | 85 | 86 | void Settings::unlock(void) 87 | { 88 | pthread_mutex_unlock(&mMutex); 89 | } 90 | 91 | 92 | void Settings::getFriendlyName(std::string *friendlyName) 93 | { 94 | if (friendlyName == nullptr) 95 | return; 96 | 97 | pthread_mutex_lock(&mMutex); 98 | *friendlyName = mFriendlyName; 99 | pthread_mutex_unlock(&mMutex); 100 | } 101 | 102 | 103 | void Settings::setFriendlyName(const std::string &friendlyName) 104 | { 105 | pthread_mutex_lock(&mMutex); 106 | mFriendlyName = friendlyName; 107 | pthread_mutex_unlock(&mMutex); 108 | } 109 | 110 | 111 | void Settings::getSerialNumber(std::string *serialNumber) 112 | { 113 | if (serialNumber == nullptr) 114 | return; 115 | 116 | pthread_mutex_lock(&mMutex); 117 | *serialNumber = mSerialNumber; 118 | pthread_mutex_unlock(&mMutex); 119 | } 120 | 121 | 122 | void Settings::setSerialNumber(const std::string &serialNumber) 123 | { 124 | pthread_mutex_lock(&mMutex); 125 | mSerialNumber = serialNumber; 126 | pthread_mutex_unlock(&mMutex); 127 | } 128 | 129 | 130 | void Settings::getSoftwareVersion(std::string *softwareVersion) 131 | { 132 | if (softwareVersion == nullptr) 133 | return; 134 | 135 | pthread_mutex_lock(&mMutex); 136 | *softwareVersion = mSoftwareVersion; 137 | pthread_mutex_unlock(&mMutex); 138 | } 139 | 140 | 141 | void Settings::setSoftwareVersion(const std::string &softwareVersion) 142 | { 143 | pthread_mutex_lock(&mMutex); 144 | mSoftwareVersion = softwareVersion; 145 | pthread_mutex_unlock(&mMutex); 146 | } 147 | 148 | } /* namespace Pdraw */ 149 | -------------------------------------------------------------------------------- /qpdraw/src/qpdraw_widget_priv.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Qt PDrAW widget 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _QPDRAW_WIDGET_PRIV_HPP_ 32 | #define _QPDRAW_WIDGET_PRIV_HPP_ 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | using namespace Pdraw; 40 | 41 | namespace QPdraw { 42 | namespace Internal { 43 | 44 | 45 | class QPdrawWidgetPriv : public QObject, 46 | public IPdraw::IVideoRenderer::Listener { 47 | Q_OBJECT 48 | 49 | public: 50 | explicit QPdrawWidgetPriv(QPdrawWidget *parent); 51 | ~QPdrawWidgetPriv(); 52 | 53 | void start(QPdraw *pdraw, 54 | unsigned int mediaId, 55 | const struct pdraw_rect *renderPos, 56 | const struct pdraw_video_renderer_params *params); 57 | void stop(); 58 | void setFramerate(float framerate); 59 | bool resizeGL(const struct pdraw_rect *renderPos); 60 | bool paintGL(); 61 | 62 | private: 63 | void 64 | onVideoRendererMediaAdded(IPdraw *pdraw, 65 | IPdraw::IVideoRenderer *renderer, 66 | const struct pdraw_media_info *info) override; 67 | 68 | void onVideoRendererMediaRemoved(IPdraw *pdraw, 69 | IPdraw::IVideoRenderer *renderer, 70 | const struct pdraw_media_info *info, 71 | bool restart) override; 72 | 73 | void onVideoRenderReady(IPdraw *pdraw, 74 | IPdraw::IVideoRenderer *renderer) override; 75 | 76 | int loadVideoTexture(IPdraw *pdraw, 77 | IPdraw::IVideoRenderer *renderer, 78 | unsigned int textureWidth, 79 | unsigned int textureHeight, 80 | const struct pdraw_media_info *mediaInfo, 81 | struct mbuf_raw_video_frame *frame, 82 | const void *frameUserdata, 83 | size_t frameUserdataLen) override; 84 | 85 | int renderVideoOverlay( 86 | IPdraw *pdraw, 87 | IPdraw::IVideoRenderer *renderer, 88 | const struct pdraw_rect *renderPos, 89 | const struct pdraw_rect *contentPos, 90 | const float *viewMat, 91 | const float *projMat, 92 | const struct pdraw_media_info *mediaInfo, 93 | struct vmeta_frame *frameMeta, 94 | const struct pdraw_video_frame_extra *frameExtra) override; 95 | 96 | private slots: 97 | /* Update slot, connected to the rendering timer timeout signal, 98 | * used to trigger the widget update in the Qt GUI thread. */ 99 | void update(); 100 | 101 | private: 102 | QPdrawWidget *mParent; 103 | QPdraw *mPdraw; 104 | IPdraw::IVideoRenderer *mRenderer; 105 | /* Rendering timer */ 106 | QTimer *mTimer; 107 | /* Rendering framerate (sec) */ 108 | float mFramerate; 109 | /* Timestamp of the previous rendering (usec) */ 110 | uint64_t mPrevRenderTs; 111 | /* Expected timestamp of the next rendering (usec) */ 112 | uint64_t mNextRenderExpectedTs; 113 | }; 114 | 115 | } /* namespace Internal */ 116 | } /* namespace QPdraw */ 117 | 118 | #endif /* !_QPDRAW_WIDGET_PRIV_HPP_ */ 119 | -------------------------------------------------------------------------------- /qpdraw/src/qpdraw.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Qt PDrAW object 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "qpdraw_priv.hpp" 32 | 33 | #define ULOG_TAG qpdraw 34 | #include 35 | ULOG_DECLARE_TAG(ULOG_TAG); 36 | 37 | 38 | namespace QPdraw { 39 | namespace Internal { 40 | 41 | 42 | QPdrawPriv::QPdrawPriv(QPdraw *parent) : mParent(parent), mPdraw(nullptr) 43 | { 44 | int res; 45 | 46 | res = createPdrawBackend(this, &mPdraw); 47 | if (res < 0) { 48 | ULOG_ERRNO("createPdrawBackend", -res); 49 | goto error; 50 | } 51 | 52 | return; 53 | 54 | error: 55 | if (mPdraw != nullptr) { 56 | delete mPdraw; 57 | mPdraw = nullptr; 58 | } 59 | } 60 | 61 | 62 | QPdrawPriv::~QPdrawPriv() 63 | { 64 | if (mPdraw != nullptr) { 65 | delete mPdraw; 66 | mPdraw = nullptr; 67 | } 68 | } 69 | 70 | 71 | int QPdrawPriv::start(void) 72 | { 73 | return mPdraw->start(); 74 | } 75 | 76 | 77 | int QPdrawPriv::stop(void) 78 | { 79 | return mPdraw->stop(); 80 | } 81 | 82 | 83 | intptr_t QPdrawPriv::getInternal(void) 84 | { 85 | return reinterpret_cast(mPdraw); 86 | } 87 | 88 | 89 | struct pomp_loop *QPdrawPriv::getLoop(void) 90 | { 91 | return mPdraw->getLoop(); 92 | } 93 | 94 | 95 | void QPdrawPriv::stopResponse(IPdraw *pdraw, int status) 96 | { 97 | Q_UNUSED(pdraw); 98 | 99 | emit mParent->stopResponse(status); 100 | } 101 | 102 | 103 | void QPdrawPriv::onMediaAdded(IPdraw *pdraw, 104 | const struct pdraw_media_info *info, 105 | void *elementUserData) 106 | { 107 | Q_UNUSED(pdraw); 108 | 109 | struct pdraw_media_info info_copy = *info; 110 | emit mParent->onMediaAdded(info_copy, elementUserData); 111 | } 112 | 113 | 114 | void QPdrawPriv::onMediaRemoved(IPdraw *pdraw, 115 | const struct pdraw_media_info *info, 116 | void *elementUserData) 117 | { 118 | Q_UNUSED(pdraw); 119 | 120 | struct pdraw_media_info info_copy = *info; 121 | emit mParent->onMediaRemoved(info_copy, elementUserData); 122 | } 123 | 124 | 125 | void QPdrawPriv::onSocketCreated(IPdraw *pdraw, int fd) 126 | { 127 | Q_UNUSED(pdraw); 128 | 129 | emit mParent->onSocketCreated(fd); 130 | } 131 | 132 | } /* namespace Internal */ 133 | 134 | 135 | QPdraw::QPdraw(QObject *parent) : QObject(parent) 136 | { 137 | qRegisterMetaType("pdraw_media_info"); 138 | 139 | mPriv = new Internal::QPdrawPriv(this); 140 | } 141 | 142 | 143 | QPdraw::~QPdraw() 144 | { 145 | delete mPriv; 146 | } 147 | 148 | 149 | int QPdraw::start(void) 150 | { 151 | return mPriv->start(); 152 | } 153 | 154 | 155 | int QPdraw::stop(void) 156 | { 157 | return mPriv->stop(); 158 | } 159 | 160 | 161 | intptr_t QPdraw::getInternal(void) 162 | { 163 | return mPriv->getInternal(); 164 | } 165 | 166 | 167 | struct pomp_loop *QPdraw::getLoop(void) 168 | { 169 | return mPriv->getLoop(); 170 | } 171 | 172 | } /* namespace QPdraw */ 173 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_video_pres_stats.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video presentation statistics 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_VIDEO_PRES_STATS_HPP_ 32 | #define _PDRAW_VIDEO_PRES_STATS_HPP_ 33 | 34 | #include 35 | 36 | #include 37 | 38 | 39 | namespace Pdraw { 40 | 41 | /** 42 | * Video presentation statistics 43 | */ 44 | class VideoPresStats { 45 | public: 46 | VideoPresStats(void); 47 | 48 | ~VideoPresStats(void) {} 49 | 50 | /* Write video presentation statistics to a pomp_msg */ 51 | int writeMsg(struct pomp_msg *msg, uint32_t msgid); 52 | 53 | /* Read video presentation statistics from a pomp_msg */ 54 | int readMsg(const struct pomp_msg *msg); 55 | 56 | /* Timestamp associated with the video statistics (us, monotonic); 57 | * This must be set on the receiver side to a monotonic timestamp on 58 | * the sender's clock (e.g. a frame capture timestamp) */ 59 | uint64_t timestamp; 60 | 61 | /* Presentation frame counter i.e. frames that reach presentation; this 62 | * value can be used with the integral time values below to compute 63 | * average values over a time period */ 64 | uint32_t presentationFrameCount; 65 | 66 | /* Presentation frame timestamp delta integral value; timestamp delta is 67 | * the time difference between two consecutive presentation frames 68 | * acquisition timestamps */ 69 | uint64_t presentationTimestampDeltaIntegral; 70 | 71 | /* Presentation frame timestamp delta squared integral value */ 72 | uint64_t presentationTimestampDeltaIntegralSq; 73 | 74 | /* Frame presentation timing error integral value; the timing error 75 | * is the absolute difference between acquisition timestamp delta 76 | * and presentation timestamp delta for two consecutive presentation 77 | * frames */ 78 | uint64_t presentationTimingErrorIntegral; 79 | 80 | /* Frame presentation timing error squared integral value */ 81 | uint64_t presentationTimingErrorIntegralSq; 82 | 83 | /* Frame estimated latency integral value; the estimated latency is the 84 | * difference between a frame presentation timestamp and acquisition 85 | * timestamp using an estimation of the clock difference between the 86 | * sender and the receiver */ 87 | uint64_t presentationEstimatedLatencyIntegral; 88 | 89 | /* Frame estimated latency squared integral value */ 90 | uint64_t presentationEstimatedLatencyIntegralSq; 91 | 92 | /* Player-side frame latency integral value; the player latency is the 93 | * difference between a frame presentation timestamp and the output 94 | * timestamp of the frame from the reeciver */ 95 | uint64_t playerLatencyIntegral; 96 | 97 | /* Player-side frame latency squared integral value */ 98 | uint64_t playerLatencyIntegralSq; 99 | 100 | /* Estimated latency precision integral value; this is the precision of 101 | * the estimation of the clock difference between the sender and the 102 | * receiver */ 103 | uint64_t estimatedLatencyPrecisionIntegral; 104 | }; 105 | 106 | } /* namespace Pdraw */ 107 | 108 | #endif /* !_PDRAW_VIDEO_PRES_STATS_HPP_ */ 109 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_renderer_audio.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Audio renderer interface 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_RENDERER_AUDIO_HPP_ 32 | #define _PDRAW_RENDERER_AUDIO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | namespace Pdraw { 39 | 40 | class AudioRendererWrapper; 41 | 42 | 43 | class AudioRenderer : public SinkElement { 44 | public: 45 | virtual ~AudioRenderer(void); 46 | 47 | virtual int setMediaId(unsigned int mediaId) = 0; 48 | 49 | virtual unsigned int getMediaId(void) const = 0; 50 | 51 | virtual int 52 | setParams(const struct pdraw_audio_renderer_params *params) = 0; 53 | 54 | virtual int getParams(struct pdraw_audio_renderer_params *params) = 0; 55 | 56 | static AudioRenderer * 57 | create(Session *session, 58 | Element::Listener *listener, 59 | AudioRendererWrapper *wrapper, 60 | IPdraw::IAudioRenderer::Listener *rndListener, 61 | unsigned int mediaId, 62 | const struct pdraw_audio_renderer_params *params); 63 | 64 | protected: 65 | AudioRenderer(Session *session, 66 | Element::Listener *listener, 67 | AudioRendererWrapper *wrapper, 68 | IPdraw::IAudioRenderer::Listener *rndListener, 69 | uint32_t mediaTypeCaps, 70 | const struct adef_format *audioMediaFormatCaps, 71 | int audioMediaFormatCapsCount, 72 | unsigned int mediaId, 73 | const struct pdraw_audio_renderer_params *params); 74 | 75 | void removeRendererListener(void); 76 | 77 | void asyncCompleteStop(void); 78 | 79 | virtual void completeStop(void) = 0; 80 | 81 | IPdraw::IAudioRenderer *mRenderer; 82 | IPdraw::IAudioRenderer::Listener *mRendererListener; 83 | pthread_mutex_t mListenerMutex; 84 | 85 | private: 86 | static void idleCompleteStop(void *userdata); 87 | }; 88 | 89 | 90 | class AudioRendererWrapper : public IPdraw::IAudioRenderer, 91 | public ElementWrapper { 92 | public: 93 | AudioRendererWrapper(Session *session, 94 | unsigned int mediaId, 95 | const struct pdraw_audio_renderer_params *params, 96 | IPdraw::IAudioRenderer::Listener *listener); 97 | 98 | ~AudioRendererWrapper(void); 99 | 100 | int setMediaId(unsigned int mediaId) override; 101 | 102 | unsigned int getMediaId(void) override; 103 | 104 | int 105 | setParams(const struct pdraw_audio_renderer_params *params) override; 106 | 107 | int getParams(struct pdraw_audio_renderer_params *params) override; 108 | 109 | void clearElement(void) override 110 | { 111 | ElementWrapper::clearElement(); 112 | mRenderer = nullptr; 113 | } 114 | 115 | Sink *getSink() 116 | { 117 | return mRenderer; 118 | } 119 | 120 | AudioRenderer *getAudioRenderer() 121 | { 122 | return mRenderer; 123 | } 124 | 125 | private: 126 | bool isElementStopped(void) const override 127 | { 128 | return (ElementWrapper::isElementStopped() || 129 | mRenderer == nullptr); 130 | } 131 | 132 | AudioRenderer *mRenderer; 133 | }; 134 | 135 | } /* namespace Pdraw */ 136 | 137 | #endif /* !_PDRAW_RENDERER_AUDIO_HPP_ */ 138 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_renderer_audio_alsa.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * ALSA audio renderer 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_RENDERER_AUDIO_ALSA_HPP_ 32 | #define _PDRAW_RENDERER_AUDIO_ALSA_HPP_ 33 | 34 | #include "pdraw_session.hpp" 35 | 36 | #ifdef PDRAW_USE_ALSA 37 | 38 | # include 39 | # include 40 | 41 | # include 42 | 43 | # include "pdraw_alsa_audio.hpp" 44 | # include "pdraw_renderer_audio.hpp" 45 | 46 | 47 | namespace Pdraw { 48 | 49 | class AlsaAudioRenderer : public AudioRenderer { 50 | public: 51 | AlsaAudioRenderer(Session *session, 52 | Element::Listener *listener, 53 | AudioRendererWrapper *wrapper, 54 | IPdraw::IAudioRenderer::Listener *rndListener, 55 | uint32_t mediaTypeCaps, 56 | unsigned int mediaId, 57 | const struct pdraw_audio_renderer_params *params); 58 | 59 | ~AlsaAudioRenderer(void); 60 | 61 | int start(void) override; 62 | 63 | int stop(void) override; 64 | 65 | int setMediaId(unsigned int mediaId) override; 66 | 67 | unsigned int getMediaId(void) const override; 68 | 69 | int 70 | setParams(const struct pdraw_audio_renderer_params *params) override; 71 | 72 | int getParams(struct pdraw_audio_renderer_params *params) override; 73 | 74 | int addInputMedia(Media *media) override; 75 | 76 | int removeInputMedia(Media *media) override; 77 | 78 | int removeInputMedias(void) override; 79 | 80 | void completeStop(void) override; 81 | 82 | private: 83 | int startAlsa(void); 84 | 85 | int stopAlsa(void); 86 | 87 | void onChannelFlush(Channel *channel) override; 88 | 89 | void onChannelDrain(Channel *channel) override; 90 | 91 | void onChannelSos(Channel *channel) override; 92 | 93 | void onChannelEos(Channel *channel) override; 94 | 95 | static void idleStart(void *renderer); 96 | 97 | static void idleDrain(void *renderer); 98 | 99 | int render(void); 100 | 101 | static void renderCb(pomp_evt *event, void *userdata); 102 | 103 | static void watchdogTimerCb(struct pomp_timer *timer, void *userdata); 104 | 105 | static bool queueFilter(struct mbuf_audio_frame *frame, void *userdata); 106 | 107 | struct mbuf_audio_frame_queue *getLastAddedMediaQueue(void); 108 | 109 | int removeQueueFdFromPomp(struct mbuf_audio_frame_queue *queue); 110 | 111 | static void idleRenewMedia(void *userdata); 112 | 113 | unsigned int mMediaId; 114 | unsigned int mCurrentMediaId; 115 | bool mRunning; 116 | AudioMedia *mLastAddedMedia; 117 | struct pdraw_media_info mMediaInfo; 118 | bool mAlsaReady; 119 | struct pdraw_audio_renderer_params mParams; 120 | std::string mAddress; 121 | snd_pcm_t *mHandle; 122 | snd_pcm_hw_params_t *mHwParams; 123 | snd_pcm_sw_params_t *mSwParams; 124 | size_t mFrameSize; 125 | size_t mSampleCount; 126 | 127 | /* Watchdog timer: triggered if no new frame is received for a given 128 | * amount of time */ 129 | struct pomp_timer *mWatchdogTimer; 130 | std::atomic_bool mWatchdogTriggered; 131 | std::atomic_bool mEos; 132 | }; 133 | 134 | } /* namespace Pdraw */ 135 | 136 | #endif /* PDRAW_USE_ALSA */ 137 | 138 | #endif /* !_PDRAW_RENDERER_AUDIO_ALSA_HPP_ */ 139 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_demuxer_stream_net.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Streaming demuxer - net implementation 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_DEMUXER_STREAM_NET_HPP_ 32 | #define _PDRAW_DEMUXER_STREAM_NET_HPP_ 33 | 34 | #include "pdraw_demuxer_stream.hpp" 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class StreamDemuxerNet : public StreamDemuxer { 44 | public: 45 | StreamDemuxerNet(Session *session, 46 | Element::Listener *elementListener, 47 | Source::Listener *sourceListener, 48 | DemuxerWrapper *wrapper, 49 | IPdraw::IDemuxer::Listener *demuxerListener, 50 | const std::string &url, 51 | const struct pdraw_demuxer_params *params); 52 | 53 | StreamDemuxerNet(Session *session, 54 | Element::Listener *elementListener, 55 | Source::Listener *sourceListener, 56 | DemuxerWrapper *wrapper, 57 | IPdraw::IDemuxer::Listener *demuxerListener, 58 | const std::string &localAddr, 59 | uint16_t localStreamPort, 60 | uint16_t localControlPort, 61 | const std::string &remoteAddr, 62 | uint16_t remoteStreamPort, 63 | uint16_t remoteControlPort, 64 | const struct pdraw_demuxer_params *params); 65 | 66 | ~StreamDemuxerNet(void); 67 | 68 | uint16_t getSingleStreamLocalStreamPort(void); 69 | 70 | uint16_t getSingleStreamLocalControlPort(void); 71 | 72 | protected: 73 | VideoMedia *createVideoMedia(void); 74 | 75 | private: 76 | class VideoMediaNet : StreamDemuxer::VideoMedia { 77 | public: 78 | VideoMediaNet(StreamDemuxerNet *demuxer); 79 | 80 | ~VideoMediaNet(void); 81 | 82 | int startRtpAvp(void) override; 83 | 84 | int stopRtpAvp(void) override; 85 | 86 | int sendCtrl(struct vstrm_receiver *stream, 87 | struct tpkt_packet *pkt) override; 88 | 89 | int prepareSetup(void) override; 90 | 91 | enum rtsp_lower_transport 92 | getLowerTransport(void) const override; 93 | 94 | uint16_t getLocalStreamPort(void) const override; 95 | 96 | uint16_t getLocalControlPort(void) const override; 97 | 98 | uint16_t getRemoteStreamPort(void) const override; 99 | 100 | uint16_t getRemoteControlPort(void) const override; 101 | 102 | void setLocalStreamPort(uint16_t port) override; 103 | 104 | void setLocalControlPort(uint16_t port) override; 105 | 106 | void setRemoteStreamPort(uint16_t port) override; 107 | 108 | void setRemoteControlPort(uint16_t port) override; 109 | 110 | private: 111 | int createSockets(void); 112 | 113 | struct tpkt_packet *newRxPkt(void); 114 | 115 | static void dataCb(int fd, uint32_t events, void *userdata); 116 | 117 | static void ctrlCb(int fd, uint32_t events, void *userdata); 118 | 119 | StreamDemuxerNet *mDemuxerNet; 120 | struct tskt_socket *mStreamSock; 121 | struct tskt_socket *mControlSock; 122 | struct tpkt_packet *mRxPkt; 123 | size_t mRxBufLen; 124 | }; 125 | 126 | uint16_t mSingleLocalStreamPort; 127 | uint16_t mSingleLocalControlPort; 128 | uint16_t mSingleRemoteStreamPort; 129 | uint16_t mSingleRemoteControlPort; 130 | }; 131 | 132 | } /* namespace Pdraw */ 133 | 134 | #endif /* !_PDRAW_DEMUXER_STREAM_NET_HPP_ */ 135 | -------------------------------------------------------------------------------- /libpdraw/atom.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE := libpdraw 7 | LOCAL_DESCRIPTION := Parrot Drones Audio and Video Vector library 8 | LOCAL_CATEGORY_PATH := libs 9 | 10 | LOCAL_CONFIG_FILES := pdraw.in 11 | $(call load-config) 12 | 13 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 14 | # Public API headers - top level headers first 15 | # This header list is currently used to generate a python binding 16 | LOCAL_EXPORT_CUSTOM_VARIABLES := LIBPDRAW_HEADERS=$\ 17 | $(LOCAL_PATH)/include/pdraw/pdraw.h:$\ 18 | $(LOCAL_PATH)/include/pdraw/pdraw_defs.h; 19 | LOCAL_EXPORT_CXXFLAGS := -std=c++11 20 | LOCAL_CFLAGS := -DPDRAW_API_EXPORTS -fvisibility=hidden -D_USE_MATH_DEFINES -D_GNU_SOURCE 21 | 22 | LOCAL_SRC_FILES := \ 23 | src/pdraw_alsa_audio.cpp \ 24 | src/pdraw_alsa_source.cpp \ 25 | src/pdraw_channel.cpp \ 26 | src/pdraw_channel_audio.cpp \ 27 | src/pdraw_channel_coded_video.cpp \ 28 | src/pdraw_channel_raw_video.cpp \ 29 | src/pdraw_decoder_audio.cpp \ 30 | src/pdraw_decoder_video.cpp \ 31 | src/pdraw_demuxer_record_audio_media.cpp \ 32 | src/pdraw_demuxer_record_coded_video_media.cpp \ 33 | src/pdraw_demuxer_record_raw_video_media.cpp \ 34 | src/pdraw_demuxer_record.cpp \ 35 | src/pdraw_demuxer_stream_mux.cpp \ 36 | src/pdraw_demuxer_stream_net.cpp \ 37 | src/pdraw_demuxer_stream.cpp \ 38 | src/pdraw_demuxer.cpp \ 39 | src/pdraw_element.cpp \ 40 | src/pdraw_encoder_audio.cpp \ 41 | src/pdraw_encoder_video.cpp \ 42 | src/pdraw_external_audio_sink.cpp \ 43 | src/pdraw_external_audio_source.cpp \ 44 | src/pdraw_external_coded_video_sink.cpp \ 45 | src/pdraw_external_coded_video_source.cpp \ 46 | src/pdraw_external_raw_video_sink.cpp \ 47 | src/pdraw_external_raw_video_source.cpp \ 48 | src/pdraw_gl_video.cpp \ 49 | src/pdraw_media.cpp \ 50 | src/pdraw_muxer_record.cpp \ 51 | src/pdraw_muxer_stream_rtmp.cpp \ 52 | src/pdraw_muxer.cpp \ 53 | src/pdraw_renderer_audio_alsa.cpp \ 54 | src/pdraw_renderer_audio.cpp \ 55 | src/pdraw_renderer_video.cpp \ 56 | src/pdraw_renderer_video_gl.cpp \ 57 | src/pdraw_scaler_video.cpp \ 58 | src/pdraw_session.cpp \ 59 | src/pdraw_settings.cpp \ 60 | src/pdraw_sink.cpp \ 61 | src/pdraw_source.cpp \ 62 | src/pdraw_utils.cpp \ 63 | src/pdraw_video_pres_stats.cpp \ 64 | src/pdraw_vipc_source.cpp \ 65 | src/pdraw_wrapper.cpp 66 | 67 | LOCAL_LIBRARIES := \ 68 | eigen \ 69 | libaac \ 70 | libaudio-decode \ 71 | libaudio-defs \ 72 | libaudio-encode \ 73 | libaudio-encode-core \ 74 | libfutils \ 75 | libh264 \ 76 | libh265 \ 77 | libmedia-buffers \ 78 | libmedia-buffers-memory \ 79 | libmedia-buffers-memory-generic \ 80 | libmp4 \ 81 | libpomp \ 82 | librtp \ 83 | librtsp \ 84 | libsdp \ 85 | libtransport-packet \ 86 | libtransport-socket \ 87 | libulog \ 88 | libvideo-decode \ 89 | libvideo-defs \ 90 | libvideo-encode \ 91 | libvideo-encode-core \ 92 | libvideo-metadata \ 93 | libvideo-scale \ 94 | libvideo-scale-core \ 95 | libvideo-streaming 96 | 97 | LOCAL_CONDITIONAL_LIBRARIES := \ 98 | OPTIONAL:json \ 99 | OPTIONAL:libmux \ 100 | OPTIONAL:librtmp \ 101 | OPTIONAL:libvideo-ipc \ 102 | OPTIONAL:libvideo-ipc-client-config 103 | 104 | LOCAL_CONDITIONAL_LIBRARIES += \ 105 | CONFIG_PDRAW_VIPC_BACKEND_DMABUF:libvideo-ipc-dmabuf-be \ 106 | CONFIG_PDRAW_VIPC_BACKEND_DMABUF:libmedia-buffers-memory-ion \ 107 | CONFIG_PDRAW_VIPC_BACKEND_HISI:libvideo-ipc-hisibe \ 108 | CONFIG_PDRAW_VIPC_BACKEND_HISI:libmedia-buffers-memory-hisi \ 109 | CONFIG_PDRAW_VIPC_BACKEND_NETWORK_CBUF:libvideo-ipc-network-cbuf-be \ 110 | CONFIG_PDRAW_VIPC_BACKEND_NETWORK_HISI:libvideo-ipc-network-hisi-be \ 111 | CONFIG_PDRAW_VIPC_BACKEND_SHM:libvideo-ipc-shmbe \ 112 | CONFIG_PDRAW_USE_ALSA:alsa-lib 113 | 114 | ifeq ("$(TARGET_OS)","windows") 115 | LOCAL_CFLAGS += -D_WIN32_WINNT=0x0600 116 | LOCAL_LDLIBS += -lws2_32 117 | endif 118 | 119 | ifdef CONFIG_PDRAW_USE_GL 120 | ifeq ($(TARGET_CPU),$(filter %$(TARGET_CPU),s905d3 s905x3)) 121 | LOCAL_LDLIBS += -lGLESv2 122 | LOCAL_CONDITIONAL_LIBRARIES += \ 123 | CONFIG_PDRAW_USE_GL:am-gpu 124 | else ifeq ($(TARGET_CPU),qcs405) 125 | LOCAL_CFLAGS += -DUSE_GLES2 126 | LOCAL_LIBRARIES += \ 127 | glesv2 \ 128 | egl 129 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","linux-native") 130 | LOCAL_CONDITIONAL_LIBRARIES += \ 131 | CONFIG_PDRAW_USE_GL:opengl 132 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","linux-android") 133 | LOCAL_LDLIBS += -lEGL -lGLESv2 -landroid 134 | else ifeq ("$(TARGET_OS)-$(TARGET_OS_FLAVOUR)","darwin-native") 135 | LOCAL_LDLIBS += -framework OpenGL 136 | else ifeq ($(TARGET_OS_FLAVOUR),$(filter %$(TARGET_OS_FLAVOUR),iphoneos iphonesimulator)) 137 | LOCAL_LDLIBS += -framework OpenGLES 138 | else ifeq ("$(TARGET_OS)","windows") 139 | LOCAL_CFLAGS += -DEPOXY_SHARED 140 | LOCAL_LDLIBS += -lepoxy 141 | endif 142 | endif 143 | 144 | include $(BUILD_LIBRARY) 145 | -------------------------------------------------------------------------------- /libpdraw-backend/include/pdraw/pdraw_backend.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * PDrAW back-end library 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_BACKEND_HPP_ 32 | #define _PDRAW_BACKEND_HPP_ 33 | 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | /* To be used for all public API */ 42 | #ifdef PDRAW_BACKEND_API_EXPORTS 43 | # ifdef _WIN32 44 | # define PDRAW_BACKEND_API __declspec(dllexport) 45 | # else /* !_WIN32 */ 46 | # define PDRAW_BACKEND_API __attribute__((visibility("default"))) 47 | # endif /* !_WIN32 */ 48 | #else /* !PDRAW_BACKEND_API_EXPORTS */ 49 | # define PDRAW_BACKEND_API 50 | #endif /* !PDRAW_BACKEND_API_EXPORTS */ 51 | 52 | using namespace Pdraw; 53 | 54 | namespace PdrawBackend { 55 | 56 | 57 | /* PDrAW back-end object interface; 58 | * see the createPdrawBackend() function for creating a PDrAW back-end instance 59 | */ 60 | class IPdrawBackend : public IPdraw { 61 | public: 62 | /** 63 | * Destroy a PDrAW back-end instance. 64 | * This function frees all resources associated with a PDrAW back-end 65 | * instance. The stop() function must be called and one must wait for 66 | * the stopResponse() listener function to be called prior to destroying 67 | * the PDrAW back-end instance. 68 | */ 69 | virtual ~IPdrawBackend(void) {} 70 | 71 | /** 72 | * Start a PDrAW back-end instance. 73 | * This function must be called after the PDrAW back-end object creation 74 | * prior to calling any other function. 75 | * @return 0 on success, negative errno value in case of error 76 | */ 77 | virtual int start(void) = 0; 78 | 79 | /** 80 | * Stop a PDrAW back-end instance. 81 | * This function must be called prior to destroying the PDrAW back-end 82 | * instance. 83 | * @return 0 on success, negative errno value in case of error 84 | */ 85 | virtual int stop(void) = 0; 86 | 87 | /** 88 | * Get the PDrAW back-end internal event loop. 89 | * This function returns a pointer to the event loop used internally. 90 | * @return a pointer on the internal loop on success, 91 | * nullptr in case of error 92 | */ 93 | virtual struct pomp_loop *getLoop(void) = 0; 94 | }; 95 | 96 | 97 | /** 98 | * Create a PDrAW back-end instance. 99 | * All API functions can be called from any thread, with the exception of 100 | * rendering functions which must still be called from the rendering thread. 101 | * All listener functions with the exception of video renderer listener 102 | * functions are called from the internal pomp_loop thread; synchronization 103 | * is up to the application. A valid listener must be provided. The instance 104 | * handle is returned through the retObj parameter. 105 | * When no longer needed, the instance must be deleted to free the resources. 106 | * The stop() function must be called and one must wait for the stopResponse() 107 | * listener function to be called prior to destroying the instance. 108 | * @param listener: listener functions implementation 109 | * @param retObj: PDrAW back-end instance handle (output) 110 | * @return 0 on success, negative errno value in case of error 111 | */ 112 | PDRAW_BACKEND_API int createPdrawBackend(IPdraw::Listener *listener, 113 | IPdrawBackend **retObj); 114 | 115 | 116 | } /* namespace PdrawBackend */ 117 | 118 | #endif /* !_PDRAW_BACKEND_HPP_ */ 119 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_external_audio_source.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Application external audio source 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_EXTERNAL_AUDIO_SOURCE_HPP_ 32 | #define _PDRAW_EXTERNAL_AUDIO_SOURCE_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class AudioSourceWrapper; 44 | 45 | 46 | class ExternalAudioSource : public SourceElement { 47 | public: 48 | ExternalAudioSource(Session *session, 49 | Element::Listener *elementListener, 50 | Source::Listener *sourceListener, 51 | IPdraw::IAudioSource::Listener *listener, 52 | AudioSourceWrapper *wrapper, 53 | const struct pdraw_audio_source_params *params); 54 | 55 | ~ExternalAudioSource(void); 56 | 57 | int start(void) override; 58 | 59 | int stop(void) override; 60 | 61 | int flush(bool discard = true); 62 | 63 | inline int drain(void) 64 | { 65 | return flush(false); 66 | } 67 | 68 | struct mbuf_audio_frame_queue *getQueue(void) const 69 | { 70 | return mFrameQueue; 71 | } 72 | 73 | IPdraw::IAudioSource *getAudioSource(void) const 74 | { 75 | return mAudioSource; 76 | } 77 | 78 | private: 79 | int process(void); 80 | 81 | int processFrame(struct mbuf_audio_frame *frame); 82 | 83 | void completeFlush(void); 84 | 85 | int tryStop(void); 86 | 87 | void completeStop(void); 88 | 89 | void onChannelFlushed(Channel *channel) override; 90 | 91 | void onChannelDrained(Channel *channel) override; 92 | 93 | void onChannelUnlink(Channel *channel) override; 94 | 95 | int removeQueueEvtFromLoop(struct mbuf_audio_frame_queue *queue, 96 | struct pomp_loop *loop); 97 | 98 | static void queueEventCb(struct pomp_evt *evt, void *userdata); 99 | 100 | static bool inputFilter(struct mbuf_audio_frame *frame, void *userdata); 101 | 102 | static void idleCompleteFlush(void *userdata); 103 | 104 | /* Audio source listener calls from idle functions */ 105 | static void callOnMediaAdded(void *userdata); 106 | 107 | static void callAudioSourceFlushed(void *userdata); 108 | 109 | IPdraw::IAudioSource *mAudioSource; 110 | IPdraw::IAudioSource::Listener *mAudioSourceListener; 111 | struct pdraw_audio_source_params mParams; 112 | struct mbuf_audio_frame_queue *mFrameQueue; 113 | AudioMedia *mOutputMedia; 114 | uint64_t mLastTimestamp; 115 | }; 116 | 117 | 118 | class AudioSourceWrapper : public IPdraw::IAudioSource, public ElementWrapper { 119 | public: 120 | AudioSourceWrapper(Session *session, 121 | const struct pdraw_audio_source_params *params, 122 | IPdraw::IAudioSource::Listener *listener); 123 | 124 | ~AudioSourceWrapper(void); 125 | 126 | struct mbuf_audio_frame_queue *getQueue(void) override; 127 | 128 | int flush(void) override; 129 | 130 | int drain(void) override; 131 | 132 | void clearElement(void) override 133 | { 134 | ElementWrapper::clearElement(); 135 | mSource = nullptr; 136 | } 137 | 138 | Source *getSource() const 139 | { 140 | return mSource; 141 | } 142 | 143 | ExternalAudioSource *getAudioSource() const 144 | { 145 | return mSource; 146 | } 147 | 148 | private: 149 | bool isElementStopped(void) const override 150 | { 151 | return (ElementWrapper::isElementStopped() || 152 | mSource == nullptr); 153 | } 154 | 155 | ExternalAudioSource *mSource; 156 | }; 157 | 158 | } /* namespace Pdraw */ 159 | 160 | #endif /* !_PDRAW_EXTERNAL_AUDIO_SOURCE_HPP_ */ 161 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_source.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline media source for elements 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_SOURCE_HPP_ 32 | #define _PDRAW_SOURCE_HPP_ 33 | 34 | #include "pdraw_channel.hpp" 35 | #include "pdraw_media.hpp" 36 | 37 | #include 38 | 39 | namespace Pdraw { 40 | 41 | class Source : public Channel::SourceListener { 42 | public: 43 | class Listener { 44 | public: 45 | virtual ~Listener(void) {} 46 | 47 | virtual void onOutputMediaAdded(Source *source, 48 | Media *media, 49 | void *elementUserData) = 0; 50 | 51 | virtual void onOutputMediaRemoved(Source *source, 52 | Media *media, 53 | void *elementUserData) = 0; 54 | }; 55 | 56 | virtual ~Source(void); 57 | 58 | void lock(void); 59 | 60 | void unlock(void); 61 | 62 | virtual std::string &getName(void) = 0; 63 | 64 | unsigned int getOutputMediaCount(void); 65 | 66 | Media *getOutputMedia(unsigned int index); 67 | 68 | Media *findOutputMedia(Media *media); 69 | 70 | unsigned int getOutputChannelCount(Media *media); 71 | 72 | Channel *getOutputChannel(Media *media, unsigned int index); 73 | 74 | Channel *findOutputChannel(Media *media, Channel *channel); 75 | 76 | int addOutputChannel(Media *media, Channel *channel); 77 | 78 | int removeOutputChannel(Media *media, Channel *channel); 79 | 80 | protected: 81 | struct OutputPort { 82 | Media *media; 83 | std::vector channels; 84 | struct mbuf_pool *pool; 85 | bool sharedPool; 86 | void *elementUserData; 87 | 88 | inline OutputPort() : 89 | media(nullptr), pool(nullptr), 90 | sharedPool(false), elementUserData(nullptr) 91 | { 92 | } 93 | }; 94 | 95 | Source(unsigned int maxOutputMedias, Listener *listener); 96 | 97 | Media *getOutputMediaFromChannel(Channel *channel); 98 | 99 | OutputPort *getOutputPort(Media *media); 100 | 101 | int addOutputPort(Media *media, void *elementUserData = nullptr); 102 | 103 | int removeOutputPort(Media *media); 104 | 105 | int removeOutputPorts(void); 106 | 107 | int createOutputPortMemoryPool(Media *media, 108 | unsigned int count, 109 | size_t capacity); 110 | 111 | int destroyOutputPortMemoryPool(Media *media); 112 | 113 | int sendDownstreamEvent(Media *media, Channel::DownstreamEvent event); 114 | 115 | virtual void onChannelUpstreamEvent(Channel *channel, 116 | const struct pomp_msg *event); 117 | 118 | virtual void onChannelUnlink(Channel *channel); 119 | 120 | virtual void onChannelFlushed(Channel *channel); 121 | 122 | virtual void onChannelDrained(Channel *channel); 123 | 124 | virtual void onChannelResync(Channel *channel); 125 | 126 | virtual void onChannelVideoPresStats(Channel *channel, 127 | VideoPresStats *stats); 128 | 129 | int getOutputMemory(Media *media, struct mbuf_mem **mem); 130 | 131 | int 132 | getCodedVideoOutputMemory(std::vector &videoMedia, 133 | struct mbuf_mem **mem, 134 | unsigned int *defaultMediaIndex); 135 | 136 | int copyCodedVideoOutputFrame(CodedVideoMedia *srcMedia, 137 | struct mbuf_coded_video_frame *srcFrame, 138 | CodedVideoMedia *dstMedia, 139 | struct mbuf_coded_video_frame **dstFrame); 140 | 141 | pthread_mutex_t mMutex; 142 | unsigned int mMaxOutputMedias; 143 | std::vector mOutputPorts; 144 | Listener *mListener; 145 | 146 | private: 147 | int removeOutputPorts(bool calledFromDtor); 148 | 149 | int destroyOutputPortMemoryPool(OutputPort *port); 150 | }; 151 | 152 | } /* namespace Pdraw */ 153 | 154 | #endif /* !_PDRAW_SOURCE_HPP_ */ 155 | -------------------------------------------------------------------------------- /qpdraw/src/qpdraw_demuxer_priv.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Qt PDrAW demuxer object 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _QPDRAW_DEMUXER_PRIV_HPP_ 32 | #define _QPDRAW_DEMUXER_PRIV_HPP_ 33 | 34 | #include 35 | #include 36 | 37 | using namespace Pdraw; 38 | 39 | namespace QPdraw { 40 | namespace Internal { 41 | 42 | 43 | class QPdrawDemuxerPriv : public IPdraw::IDemuxer::Listener { 44 | 45 | public: 46 | explicit QPdrawDemuxerPriv(QPdrawDemuxer *parent); 47 | ~QPdrawDemuxerPriv(); 48 | 49 | int open(const std::string &url, 50 | const struct pdraw_demuxer_params *params); 51 | 52 | int open(const std::string &localAddr, 53 | uint16_t localStreamPort, 54 | uint16_t localControlPort, 55 | const std::string &remoteAddr, 56 | uint16_t remoteStreamPort, 57 | uint16_t remoteControlPort, 58 | const struct pdraw_demuxer_params *params); 59 | 60 | int open(const std::string &url, 61 | struct mux_ctx *mux, 62 | const struct pdraw_demuxer_params *params); 63 | 64 | int close(void); 65 | 66 | int getMediaList(struct pdraw_demuxer_media **mediaList, 67 | size_t *mediaCount, 68 | uint32_t *selectedMedias); 69 | 70 | int selectMedia(uint32_t selectedMedias); 71 | 72 | uint16_t getSingleStreamLocalStreamPort(void); 73 | 74 | uint16_t getSingleStreamLocalControlPort(void); 75 | 76 | bool isReadyToPlay(void); 77 | 78 | bool isPaused(void); 79 | 80 | int play(float speed = 1.0f); 81 | 82 | int pause(void); 83 | 84 | int previousFrame(void); 85 | 86 | int nextFrame(void); 87 | 88 | int seek(int64_t delta, bool exact = false); 89 | 90 | int seekForward(uint64_t delta, bool exact = false); 91 | 92 | int seekBack(uint64_t delta, bool exact = false); 93 | 94 | int seekTo(uint64_t timestamp, bool exact = false); 95 | 96 | int getChapterList(struct pdraw_chapter **chapterList, 97 | size_t *chapterCount); 98 | 99 | uint64_t getDuration(void); 100 | 101 | uint64_t getCurrentTime(void); 102 | 103 | private: 104 | IPdraw *getPdrawInternal(); 105 | 106 | void demuxerOpenResponse(IPdraw *pdraw, 107 | IPdraw::IDemuxer *demuxer, 108 | int status) override; 109 | 110 | void demuxerCloseResponse(IPdraw *pdraw, 111 | IPdraw::IDemuxer *demuxer, 112 | int status) override; 113 | 114 | void onDemuxerUnrecoverableError(IPdraw *pdraw, 115 | IPdraw::IDemuxer *demuxer) override; 116 | 117 | int demuxerSelectMedia(IPdraw *pdraw, 118 | IPdraw::IDemuxer *demuxer, 119 | const struct pdraw_demuxer_media *medias, 120 | size_t count, 121 | uint32_t selectedMedias) override; 122 | 123 | void demuxerReadyToPlay(IPdraw *pdraw, 124 | IPdraw::IDemuxer *demuxer, 125 | bool ready) override; 126 | 127 | void onDemuxerEndOfRange(IPdraw *pdraw, 128 | IPdraw::IDemuxer *demuxer, 129 | uint64_t timestamp) override; 130 | 131 | void demuxerPlayResponse(IPdraw *pdraw, 132 | IPdraw::IDemuxer *demuxer, 133 | int status, 134 | uint64_t timestamp, 135 | float speed) override; 136 | 137 | void demuxerPauseResponse(IPdraw *pdraw, 138 | IPdraw::IDemuxer *demuxer, 139 | int status, 140 | uint64_t timestamp) override; 141 | 142 | void demuxerSeekResponse(IPdraw *pdraw, 143 | IPdraw::IDemuxer *demuxer, 144 | int status, 145 | uint64_t timestamp, 146 | float speed) override; 147 | 148 | QPdrawDemuxer *mParent; 149 | IPdraw::IDemuxer *mDemuxer; 150 | bool mClosing; 151 | }; 152 | 153 | } /* namespace Internal */ 154 | } /* namespace QPdraw */ 155 | 156 | #endif /* !_QPDRAW_DEMUXER_PRIV_HPP_ */ 157 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_channel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline source to sink channel 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_CHANNEL_HPP_ 32 | #define _PDRAW_CHANNEL_HPP_ 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "pdraw_video_pres_stats.hpp" 40 | 41 | namespace Pdraw { 42 | 43 | class Sink; 44 | 45 | class Channel { 46 | public: 47 | enum DownstreamEvent { 48 | /* flush required */ 49 | FLUSH, 50 | 51 | /* drain required */ 52 | DRAIN, 53 | 54 | /* teardown required */ 55 | TEARDOWN, 56 | 57 | /* start of stream */ 58 | SOS, 59 | 60 | /* end of stream */ 61 | EOS, 62 | 63 | /* reconfiguration in progress */ 64 | RECONFIGURE, 65 | 66 | /* resolution change in progress */ 67 | RESOLUTION_CHANGE, 68 | 69 | /* framerate change in progress */ 70 | FRAMERATE_CHANGE, 71 | 72 | /* reception timeout */ 73 | TIMEOUT, 74 | 75 | /* photo trigger */ 76 | PHOTO_TRIGGER, 77 | 78 | /* session metadata update */ 79 | SESSION_META_UPDATE, 80 | }; 81 | 82 | enum UpstreamEvent { 83 | /* unlink required */ 84 | UNLINK, 85 | 86 | /* flush completed */ 87 | FLUSHED, 88 | 89 | /* drain completed */ 90 | DRAINED, 91 | 92 | /* resynchronization required */ 93 | RESYNC, 94 | 95 | /* video presentation statistics */ 96 | VIDEO_PRES_STATS, 97 | }; 98 | 99 | class SinkListener { 100 | public: 101 | virtual ~SinkListener(void) {} 102 | 103 | virtual void 104 | onChannelDownstreamEvent(Channel *channel, 105 | const struct pomp_msg *event) = 0; 106 | }; 107 | 108 | class SourceListener { 109 | public: 110 | virtual ~SourceListener(void) {} 111 | 112 | virtual void 113 | onChannelUpstreamEvent(Channel *channel, 114 | const struct pomp_msg *event) = 0; 115 | }; 116 | 117 | static const char *getDownstreamEventStr(DownstreamEvent val); 118 | 119 | static const char *getUpstreamEventStr(UpstreamEvent val); 120 | 121 | Channel(Sink *owner, 122 | SinkListener *sinkListener, 123 | struct pomp_loop *loop); 124 | 125 | virtual ~Channel(void) = 0; 126 | 127 | int flush(void); 128 | 129 | bool isFlushPending(void) 130 | { 131 | return mFlushPending; 132 | } 133 | 134 | int flushDone(void); 135 | 136 | int asyncFlushDone(void); 137 | 138 | int drain(void); 139 | 140 | bool isDrainPending(void) 141 | { 142 | return mDrainPending; 143 | } 144 | 145 | int drainDone(void); 146 | 147 | int asyncDrainDone(void); 148 | 149 | int resync(void); 150 | 151 | int unlink(void); 152 | 153 | int teardown(void); 154 | 155 | int sendVideoPresStats(VideoPresStats *stats); 156 | 157 | int sendDownstreamEvent(DownstreamEvent downstreamEvent); 158 | 159 | SourceListener *getSourceListener(void) const 160 | { 161 | return mSourceListener; 162 | } 163 | 164 | void setSourceListener(SourceListener *sourceListener) 165 | { 166 | mSourceListener = sourceListener; 167 | } 168 | 169 | Sink *getOwner(void) const 170 | { 171 | return mOwner; 172 | } 173 | 174 | struct mbuf_pool *getPool(const Sink *owner) const; 175 | 176 | void setPool(const Sink *owner, struct mbuf_pool *pool); 177 | 178 | protected: 179 | Sink *mOwner; 180 | 181 | private: 182 | static void idleFlushDone(void *userdata); 183 | 184 | static void idleDrainDone(void *userdata); 185 | 186 | SinkListener *mSinkListener; 187 | SourceListener *mSourceListener; 188 | struct mbuf_pool *mPool; 189 | struct pomp_loop *mLoop; 190 | bool mFlushPending; 191 | bool mDrainPending; 192 | }; 193 | 194 | } /* namespace Pdraw */ 195 | 196 | #endif /* !_PDRAW_CHANNEL_HPP_ */ 197 | -------------------------------------------------------------------------------- /qpdraw/include/pdraw/qpdraw.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Qt PDrAW object 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _QPDRAW_HPP_ 32 | #define _QPDRAW_HPP_ 33 | 34 | #include 35 | 36 | #include 37 | 38 | 39 | Q_DECLARE_METATYPE(pdraw_media_info); 40 | 41 | 42 | namespace QPdraw { 43 | 44 | /* Forward declarations */ 45 | namespace Internal { 46 | class QPdrawPriv; 47 | } 48 | 49 | 50 | class QPdraw : public QObject { 51 | Q_OBJECT 52 | 53 | public: 54 | explicit QPdraw(QObject *parent = nullptr); 55 | 56 | ~QPdraw(); 57 | 58 | /** 59 | * Start a QPdraw instance. 60 | * This function must be called after the object creation prior to 61 | * calling any other function. 62 | * @return 0 on success, negative errno value in case of error 63 | */ 64 | int start(void); 65 | 66 | /** 67 | * Stop a QPdraw instance. 68 | * This function must be called prior to destroying the instance. 69 | * @return 0 on success, negative errno value in case of error 70 | */ 71 | int stop(void); 72 | 73 | /** 74 | * Get the internal PDrAW instance pointer. 75 | * This function returns a pointer to the internal PDrAW instance. 76 | * @return a pointer on the internal PDrAW instance on success, 77 | * null in case of error 78 | */ 79 | intptr_t getInternal(void); 80 | 81 | /** 82 | * Get the internal event loop. 83 | * This function returns a pointer to the event loop used internally. 84 | * @return a pointer on the internal loop on success, 85 | * null in case of error 86 | */ 87 | struct pomp_loop *getLoop(void); 88 | 89 | signals: 90 | /** 91 | * Stop response signal, called when a stop operation is complete or 92 | * has failed. The status parameter is the stop operation status: 0 on 93 | * success, or a negative errno value in case of error. 94 | * @param status: 0 on success, negative errno value in case of error 95 | */ 96 | void stopResponse(int status); 97 | 98 | /** 99 | * Media added signal, called when a media has been added internally in 100 | * the PDrAW pipeline. Medias are for example YUV or H.264 video medias. 101 | * The info structure gives the media identifier that can be used to 102 | * create a video sink on this media. 103 | * Note: a Qt::DirectConnection is required to connect this signal to 104 | * any slot that accesses the session_meta pointer. 105 | * @param info: information on the media 106 | * @param elementUserData: optional user data pointer that was passed 107 | * on the pipeline element creation 108 | */ 109 | void onMediaAdded(struct pdraw_media_info info, void *elementUserData); 110 | 111 | /** 112 | * Media removed signal, called when a media has been removed internally 113 | * from the PDrAW pipeline. Medias are for example YUV or H.264 video 114 | * medias. When a media is removed, any video sink created on this media 115 | * must then be stopped. 116 | * Note: a Qt::DirectConnection is required to connect this signal to 117 | * any slot that accesses the session_meta pointer. 118 | * @param info: information on the media 119 | * @param elementUserData: optional user data pointer that was passed 120 | * on the pipeline element creation 121 | */ 122 | void onMediaRemoved(struct pdraw_media_info info, 123 | void *elementUserData); 124 | 125 | /** 126 | * Socket creation signal, called immediately after a socket creation 127 | * with its file descriptor as parameter. 128 | * @param fd: socket file descriptor 129 | */ 130 | void onSocketCreated(int fd); 131 | 132 | private: 133 | Internal::QPdrawPriv *mPriv; 134 | }; 135 | 136 | } /* namespace QPdraw */ 137 | 138 | #endif /* !_QPDRAW_HPP_ */ 139 | -------------------------------------------------------------------------------- /libpdraw-gles2hud/src/pdraw_gles2hud_text.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * OpenGL ES 2.0 HUD rendering library 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "pdraw_gles2hud_priv.h" 32 | 33 | 34 | void pdraw_gles2hud_get_text_dimensions(struct pdraw_gles2hud *self, 35 | const char *str, 36 | float size, 37 | float scalew, 38 | float scaleh, 39 | float *width, 40 | float *height) 41 | { 42 | float w, h; 43 | 44 | profont_36::file_header *glyph_info = &profont_36::font; 45 | float cx = 0.; 46 | const char *c = str; 47 | while (*c != '\0') { 48 | if (*c == '\n') { 49 | break; 50 | } else { 51 | profont_36::glyph_info &g = 52 | glyph_info->glyphs[(int)(*c)]; 53 | cx += g.norm.advance; 54 | } 55 | c++; 56 | } 57 | w = cx; 58 | h = glyph_info->norm.ascent + glyph_info->norm.descent; 59 | /* + glyph_info->norm.linegap; */ 60 | w *= size * scalew; 61 | h *= size * scaleh; 62 | 63 | if (width) 64 | *width = w; 65 | if (height) 66 | *height = h; 67 | } 68 | 69 | 70 | void pdraw_gles2hud_draw_text(struct pdraw_gles2hud *self, 71 | const char *str, 72 | float x, 73 | float y, 74 | float size, 75 | float scalew, 76 | float scaleh, 77 | enum pdraw_gles2hud_text_align halign, 78 | enum pdraw_gles2hud_text_align valign, 79 | const float color[4]) 80 | { 81 | float w, h; 82 | float vertices[8]; 83 | float texcoords[8]; 84 | profont_36::file_header *glyph_info = &profont_36::font; 85 | 86 | pdraw_gles2hud_get_text_dimensions( 87 | self, str, size, scalew, scaleh, &w, &h); 88 | 89 | switch (halign) { 90 | default: 91 | case PDRAW_GLES2HUD_TEXT_ALIGN_LEFT: 92 | break; 93 | case PDRAW_GLES2HUD_TEXT_ALIGN_CENTER: 94 | x -= w / 2; 95 | break; 96 | case PDRAW_GLES2HUD_TEXT_ALIGN_RIGHT: 97 | x -= w; 98 | break; 99 | } 100 | 101 | switch (valign) { 102 | default: 103 | case PDRAW_GLES2HUD_TEXT_ALIGN_TOP: 104 | y -= h; 105 | break; 106 | case PDRAW_GLES2HUD_TEXT_ALIGN_MIDDLE: 107 | y -= h / 2; 108 | break; 109 | case PDRAW_GLES2HUD_TEXT_ALIGN_BOTTOM: 110 | break; 111 | } 112 | 113 | GLCHK(glUniform4fv(self->tex_color_handle, 1, color)); 114 | 115 | const char *c = str; 116 | float cx = 0.; 117 | while (*c != '\0') { 118 | if (*c == '\n') 119 | break; 120 | 121 | profont_36::glyph_info &g = glyph_info->glyphs[(int)(*c)]; 122 | vertices[0] = x + cx + g.norm.offx * size * scalew; 123 | vertices[1] = y - g.norm.offy * size * scaleh; 124 | vertices[2] = 125 | x + cx + (g.norm.offx + g.norm.width) * size * scalew; 126 | vertices[3] = y - g.norm.offy * size * scaleh; 127 | vertices[4] = x + cx + g.norm.offx * size * scalew; 128 | vertices[5] = y - (g.norm.offy + g.norm.height) * size * scaleh; 129 | vertices[6] = 130 | x + cx + (g.norm.offx + g.norm.width) * size * scalew; 131 | vertices[7] = y - (g.norm.offy + g.norm.height) * size * scaleh; 132 | 133 | texcoords[0] = g.norm.u; 134 | texcoords[1] = g.norm.v + g.norm.height; 135 | texcoords[2] = g.norm.u + g.norm.width; 136 | texcoords[3] = g.norm.v + g.norm.height; 137 | texcoords[4] = g.norm.u; 138 | texcoords[5] = g.norm.v; 139 | texcoords[6] = g.norm.u + g.norm.width; 140 | texcoords[7] = g.norm.v; 141 | 142 | GLCHK(glVertexAttribPointer(self->tex_position_handle, 143 | 2, 144 | GL_FLOAT, 145 | false, 146 | 0, 147 | vertices)); 148 | GLCHK(glVertexAttribPointer(self->tex_texcoord_handle, 149 | 2, 150 | GL_FLOAT, 151 | false, 152 | 0, 153 | texcoords)); 154 | GLCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); 155 | 156 | cx += g.norm.advance * size * scalew; 157 | c++; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_scaler_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video scaler element 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_SCALER_VIDEO_HPP_ 32 | #define _PDRAW_SCALER_VIDEO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | class VideoScalerWrapper; 45 | 46 | 47 | class VideoScaler : public FilterElement { 48 | public: 49 | VideoScaler(Session *session, 50 | Element::Listener *elementListener, 51 | Source::Listener *sourceListener, 52 | IPdraw::IVideoScaler::Listener *listener, 53 | VideoScalerWrapper *wrapper, 54 | const struct vscale_config *params); 55 | 56 | ~VideoScaler(void); 57 | 58 | int start(void) override; 59 | 60 | int stop(void) override; 61 | 62 | void completeFlush(void); 63 | 64 | void completeStop(void); 65 | 66 | IPdraw::IVideoScaler *getVideoScaler(void) const 67 | { 68 | return mScaler; 69 | } 70 | 71 | private: 72 | int createOutputMedia(struct vdef_raw_frame *frameInfo, 73 | RawVideoMedia::Frame &frame); 74 | 75 | int flush(bool discard = true); 76 | 77 | inline int drain(void) 78 | { 79 | return flush(false); 80 | } 81 | 82 | int tryStop(void); 83 | 84 | void 85 | onRawVideoChannelQueue(RawVideoChannel *channel, 86 | struct mbuf_raw_video_frame *frame) override; 87 | 88 | void onChannelFlush(Channel *channel) override; 89 | 90 | void onChannelDrain(Channel *channel) override; 91 | 92 | void onChannelFlushed(Channel *channel) override; 93 | 94 | void onChannelDrained(Channel *channel) override; 95 | 96 | void onChannelTeardown(Channel *channel) override; 97 | 98 | void onChannelUnlink(Channel *channel) override; 99 | 100 | void onChannelSessionMetaUpdate(Channel *channel) override; 101 | 102 | static void frameOutputCb(struct vscale_scaler *scaler, 103 | int status, 104 | struct mbuf_raw_video_frame *out_frame, 105 | void *userdata); 106 | 107 | static void flushCb(struct vscale_scaler *scaler, void *userdata); 108 | 109 | static void stopCb(struct vscale_scaler *scaler, void *userdata); 110 | 111 | static void idleCompleteFlush(void *userdata); 112 | 113 | IPdraw::IVideoScaler *mScaler; 114 | IPdraw::IVideoScaler::Listener *mScalerListener; 115 | RawVideoMedia *mInputMedia; 116 | RawVideoMedia *mOutputMedia; 117 | struct mbuf_pool *mInputBufferPool; 118 | struct mbuf_raw_video_frame_queue *mInputBufferQueue; 119 | struct vscale_config *mScalerConfig; 120 | std::string mScalerName; 121 | struct vscale_scaler *mVscale; 122 | bool mInputChannelFlushPending; 123 | bool mOutputChannelDrainRequired; 124 | bool mVscaleFlushPending; 125 | bool mVscaleStopPending; 126 | static const struct vscale_cbs mScalerCbs; 127 | }; 128 | 129 | 130 | class VideoScalerWrapper : public IPdraw::IVideoScaler, public ElementWrapper { 131 | public: 132 | VideoScalerWrapper(Session *session, 133 | const struct vscale_config *params, 134 | IPdraw::IVideoScaler::Listener *listener); 135 | 136 | ~VideoScalerWrapper(void); 137 | 138 | void clearElement(void) override 139 | { 140 | ElementWrapper::clearElement(); 141 | mScaler = nullptr; 142 | } 143 | 144 | Sink *getScaler() const 145 | { 146 | return mScaler; 147 | } 148 | 149 | VideoScaler *getVideoScaler() const 150 | { 151 | return mScaler; 152 | } 153 | 154 | private: 155 | bool isElementStopped(void) const override 156 | { 157 | return (ElementWrapper::isElementStopped() || 158 | mScaler == nullptr); 159 | } 160 | 161 | VideoScaler *mScaler; 162 | }; 163 | 164 | } /* namespace Pdraw */ 165 | 166 | #endif /* !_PDRAW_SCALER_VIDEO_HPP_ */ 167 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_external_audio_sink.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Application external audio sink 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_EXTERNAL_AUDIO_SINK_HPP_ 32 | #define _PDRAW_EXTERNAL_AUDIO_SINK_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class AudioSinkWrapper; 44 | 45 | 46 | class ExternalAudioSink : public SinkElement { 47 | public: 48 | ExternalAudioSink(Session *session, 49 | Element::Listener *elementListener, 50 | IPdraw::IAudioSink::Listener *listener, 51 | AudioSinkWrapper *wrapper, 52 | unsigned int mediaId); 53 | 54 | ~ExternalAudioSink(void); 55 | 56 | int start(void) override; 57 | 58 | int stop(void) override; 59 | 60 | int setMediaId(unsigned int mediaId); 61 | 62 | unsigned int getMediaId(void) const; 63 | 64 | int flushDone(bool discard = true); 65 | 66 | inline int drainDone(void) 67 | { 68 | return flushDone(false); 69 | } 70 | 71 | struct mbuf_audio_frame_queue *getQueue(void) const 72 | { 73 | return mInputFrameQueue; 74 | } 75 | 76 | IPdraw::IAudioSink *getAudioSink(void) const 77 | { 78 | return mAudioSink; 79 | } 80 | 81 | int addInputMedia(Media *media) override; 82 | 83 | int removeInputMedia(Media *media) override; 84 | 85 | private: 86 | int flush(bool discard = true); 87 | 88 | inline int drain(void) 89 | { 90 | return flush(false); 91 | } 92 | 93 | int channelTeardown(AudioChannel *channel); 94 | 95 | void onAudioChannelQueue(AudioChannel *channel, 96 | struct mbuf_audio_frame *frame) override; 97 | 98 | void onChannelReconfigure(Channel *channel) override; 99 | 100 | void onChannelFlush(Channel *channel) override; 101 | 102 | void onChannelDrain(Channel *channel) override; 103 | 104 | void onChannelTeardown(Channel *channel) override; 105 | 106 | int prepareAudioFrame(AudioChannel *channel, 107 | struct mbuf_audio_frame *frame); 108 | 109 | static void idleFlushDone(void *userdata); 110 | 111 | /* Audio sink listener calls from idle functions */ 112 | static void callAudioSinkFlush(void *userdata); 113 | 114 | static void idleRenewMedia(void *userdata); 115 | 116 | IPdraw::IAudioSink *mAudioSink; 117 | IPdraw::IAudioSink::Listener *mAudioSinkListener; 118 | AudioMedia *mInputMedia; 119 | struct pdraw_media_info mMediaInfo; 120 | unsigned int mMediaId; 121 | unsigned int mTargetMediaId; 122 | struct mbuf_audio_frame_queue *mInputFrameQueue; 123 | bool mInputChannelFlushPending; 124 | bool mTearingDown; 125 | bool mPendingRestart; 126 | }; 127 | 128 | 129 | class AudioSinkWrapper : public IPdraw::IAudioSink, public ElementWrapper { 130 | public: 131 | AudioSinkWrapper(Session *session, 132 | unsigned int mediaId, 133 | IPdraw::IAudioSink::Listener *listener); 134 | 135 | ~AudioSinkWrapper(void); 136 | 137 | int setMediaId(unsigned int mediaId) override; 138 | 139 | unsigned int getMediaId(void) override; 140 | 141 | struct mbuf_audio_frame_queue *getQueue(void) override; 142 | 143 | int queueFlushed(void) override; 144 | 145 | int queueDrained(void) override; 146 | 147 | void clearElement(void) override 148 | { 149 | ElementWrapper::clearElement(); 150 | mSink = nullptr; 151 | } 152 | 153 | Sink *getSink() const 154 | { 155 | return mSink; 156 | } 157 | 158 | ExternalAudioSink *getAudioSink() const 159 | { 160 | return mSink; 161 | } 162 | 163 | private: 164 | bool isElementStopped(void) const override 165 | { 166 | return (ElementWrapper::isElementStopped() || mSink == nullptr); 167 | } 168 | 169 | ExternalAudioSink *mSink; 170 | }; 171 | 172 | } /* namespace Pdraw */ 173 | 174 | #endif /* !_PDRAW_EXTERNAL_AUDIO_SINK_HPP_ */ 175 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_demuxer_stream_mux.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Streaming demuxer - mux implementation 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_DEMUXER_STREAM_MUX_HPP_ 32 | #define _PDRAW_DEMUXER_STREAM_MUX_HPP_ 33 | 34 | #ifdef BUILD_LIBMUX 35 | 36 | # include "pdraw_demuxer_stream.hpp" 37 | 38 | # include 39 | # include 40 | 41 | # include 42 | 43 | # include 44 | # include 45 | 46 | namespace Pdraw { 47 | 48 | class StreamDemuxerMux : public StreamDemuxer { 49 | public: 50 | StreamDemuxerMux(Session *session, 51 | Element::Listener *elementListener, 52 | Source::Listener *sourceListener, 53 | DemuxerWrapper *wrapper, 54 | IPdraw::IDemuxer::Listener *demuxerListener, 55 | const std::string &url, 56 | struct mux_ctx *mux, 57 | const struct pdraw_demuxer_params *params); 58 | 59 | ~StreamDemuxerMux(void); 60 | 61 | protected: 62 | VideoMedia *createVideoMedia(void); 63 | 64 | private: 65 | class VideoMediaMux : StreamDemuxer::VideoMedia { 66 | public: 67 | VideoMediaMux(StreamDemuxerMux *demuxer); 68 | 69 | ~VideoMediaMux(void); 70 | 71 | int startRtpAvp(void); 72 | 73 | int stopRtpAvp(void); 74 | 75 | int sendCtrl(struct vstrm_receiver *stream, 76 | struct tpkt_packet *pkt); 77 | 78 | int prepareSetup(void); 79 | 80 | enum rtsp_lower_transport getLowerTransport(void) const; 81 | 82 | uint16_t getLocalStreamPort(void) const; 83 | 84 | uint16_t getLocalControlPort(void) const; 85 | 86 | uint16_t getRemoteStreamPort(void) const; 87 | 88 | uint16_t getRemoteControlPort(void) const; 89 | 90 | const struct rtsp_header_ext *getHeaderExt(void) const; 91 | 92 | size_t getHeaderExtCount(void) const; 93 | 94 | void setLocalStreamPort(uint16_t port); 95 | 96 | void setLocalControlPort(uint16_t port); 97 | 98 | void setRemoteStreamPort(uint16_t port); 99 | 100 | void setRemoteControlPort(uint16_t port); 101 | 102 | private: 103 | static void legacyDataCb(struct mux_ctx *ctx, 104 | uint32_t chanid, 105 | enum mux_channel_event event, 106 | struct pomp_buffer *buf, 107 | void *userdata); 108 | 109 | static void legacyCtrlCb(struct mux_ctx *ctx, 110 | uint32_t chanid, 111 | enum mux_channel_event event, 112 | struct pomp_buffer *buf, 113 | void *userdata); 114 | 115 | int createSockets(void); 116 | 117 | void closeSockets(void); 118 | 119 | struct tpkt_packet *newRxPkt(void); 120 | 121 | static void dataCb(int fd, uint32_t events, void *userdata); 122 | 123 | static void ctrlCb(int fd, uint32_t events, void *userdata); 124 | 125 | static void callFinishSetup(void *userdata); 126 | 127 | static void proxyOpenCb(struct mux_ip_proxy *proxy, 128 | uint16_t localPort, 129 | void *userdata); 130 | 131 | static void proxyCloseCb(struct mux_ip_proxy *proxy, 132 | void *userdata); 133 | 134 | static void proxyUpdateCb(struct mux_ip_proxy *proxy, 135 | void *userdata); 136 | 137 | static void proxyFailedCb(struct mux_ip_proxy *proxy, 138 | int err, 139 | void *userdata); 140 | 141 | StreamDemuxerMux *mDemuxerMux; 142 | struct tskt_socket *mStreamSock; 143 | struct mux_ip_proxy *mStreamProxy; 144 | bool mStreamProxyOpened; 145 | struct tskt_socket *mControlSock; 146 | struct mux_ip_proxy *mControlProxy; 147 | bool mControlProxyOpened; 148 | struct tpkt_packet *mRxPkt; 149 | size_t mRxBufLen; 150 | static const struct rtsp_header_ext mHeaderExt; 151 | static const size_t mHeaderExtCount; 152 | }; 153 | 154 | bool setMux(struct mux_ctx *mux); 155 | 156 | struct mux_ctx *mMux; 157 | }; 158 | 159 | } /* namespace Pdraw */ 160 | 161 | #endif /* BUILD_LIBMUX */ 162 | 163 | #endif /* !_PDRAW_DEMUXER_STREAM_MUX_HPP_ */ 164 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_renderer_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video renderer interface 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_RENDERER_VIDEO_HPP_ 32 | #define _PDRAW_RENDERER_VIDEO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | namespace Pdraw { 39 | 40 | class VideoRendererWrapper; 41 | 42 | 43 | class VideoRenderer : public SinkElement { 44 | public: 45 | virtual ~VideoRenderer(void); 46 | 47 | virtual int render(struct pdraw_rect *contentPos, 48 | const float *viewMat = nullptr, 49 | const float *projMat = nullptr) = 0; 50 | 51 | virtual int resize(const struct pdraw_rect *renderPos) = 0; 52 | 53 | virtual int setMediaId(unsigned int mediaId) = 0; 54 | 55 | virtual unsigned int getMediaId(void) = 0; 56 | 57 | virtual int setParams(const struct pdraw_video_renderer_params *params, 58 | bool force) = 0; 59 | 60 | virtual int getParams(struct pdraw_video_renderer_params *params) = 0; 61 | 62 | virtual void completeStop(void) = 0; 63 | 64 | static VideoRenderer * 65 | create(Session *session, 66 | Element::Listener *listener, 67 | VideoRendererWrapper *wrapper, 68 | IPdraw::IVideoRenderer::Listener *rndListener, 69 | unsigned int mediaId, 70 | const struct pdraw_rect *renderPos, 71 | const struct pdraw_video_renderer_params *params); 72 | 73 | protected: 74 | VideoRenderer(Session *session, 75 | Element::Listener *listener, 76 | VideoRendererWrapper *wrapper, 77 | IPdraw::IVideoRenderer::Listener *rndListener, 78 | uint32_t mediaTypeCaps, 79 | const struct vdef_raw_format *rawVideoMediaFormatCaps, 80 | int rawVideoMediaFormatCapsCount, 81 | unsigned int mediaId, 82 | const struct pdraw_rect *renderPos, 83 | const struct pdraw_video_renderer_params *params); 84 | 85 | void removeRendererListener(void); 86 | 87 | void asyncCompleteStop(void); 88 | 89 | IPdraw::IVideoRenderer *mRenderer; 90 | IPdraw::IVideoRenderer::Listener *mRendererListener; 91 | pthread_mutex_t mListenerMutex; 92 | 93 | private: 94 | static void idleCompleteStop(void *userdata); 95 | }; 96 | 97 | 98 | class VideoRendererWrapper : public IPdraw::IVideoRenderer, 99 | public ElementWrapper { 100 | public: 101 | /* Called on the rendering thread */ 102 | VideoRendererWrapper(Session *session, 103 | unsigned int mediaId, 104 | const struct pdraw_rect *renderPos, 105 | const struct pdraw_video_renderer_params *params, 106 | IPdraw::IVideoRenderer::Listener *listener); 107 | 108 | /* Called on the rendering thread */ 109 | ~VideoRendererWrapper(void); 110 | 111 | /* Called on the rendering thread */ 112 | int resize(const struct pdraw_rect *renderPos) override; 113 | 114 | /* Called on the rendering thread */ 115 | int setMediaId(unsigned int mediaId) override; 116 | 117 | /* Called on the rendering thread */ 118 | unsigned int getMediaId(void) override; 119 | 120 | /* Called on the rendering thread */ 121 | int 122 | setParams(const struct pdraw_video_renderer_params *params) override; 123 | 124 | /* Called on the rendering thread */ 125 | int getParams(struct pdraw_video_renderer_params *params) override; 126 | 127 | /* Called on the rendering thread */ 128 | int render(struct pdraw_rect *contentPos, 129 | const float *viewMat = nullptr, 130 | const float *projMat = nullptr) override; 131 | 132 | void clearElement(void) override 133 | { 134 | ElementWrapper::clearElement(); 135 | mRenderer = nullptr; 136 | } 137 | 138 | private: 139 | bool isElementStopped(void) const override 140 | { 141 | return (ElementWrapper::isElementStopped() || 142 | mRenderer == nullptr); 143 | } 144 | 145 | VideoRenderer *mRenderer; 146 | }; 147 | 148 | } /* namespace Pdraw */ 149 | 150 | #endif /* !_PDRAW_RENDERER_VIDEO_HPP_ */ 151 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_external_raw_video_source.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Application external raw video source 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_EXTERNAL_RAW_VIDEO_SOURCE_HPP_ 32 | #define _PDRAW_EXTERNAL_RAW_VIDEO_SOURCE_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class RawVideoSourceWrapper; 44 | 45 | 46 | class ExternalRawVideoSource : public SourceElement { 47 | public: 48 | ExternalRawVideoSource(Session *session, 49 | Element::Listener *elementListener, 50 | Source::Listener *sourceListener, 51 | IPdraw::IRawVideoSource::Listener *listener, 52 | RawVideoSourceWrapper *wrapper, 53 | const struct pdraw_video_source_params *params); 54 | 55 | ~ExternalRawVideoSource(void); 56 | 57 | int start(void) override; 58 | 59 | int stop(void) override; 60 | 61 | int flush(bool discard = true); 62 | 63 | inline int drain(void) 64 | { 65 | return flush(false); 66 | } 67 | 68 | int setSessionMetadata(const struct vmeta_session *meta); 69 | 70 | int getSessionMetadata(struct vmeta_session *meta) const; 71 | 72 | struct mbuf_raw_video_frame_queue *getQueue(void) const 73 | { 74 | return mFrameQueue; 75 | } 76 | 77 | IPdraw::IRawVideoSource *getVideoSource(void) const 78 | { 79 | return mVideoSource; 80 | } 81 | 82 | private: 83 | int process(void); 84 | 85 | int processFrame(struct mbuf_raw_video_frame *frame); 86 | 87 | void completeFlush(void); 88 | 89 | int tryStop(void); 90 | 91 | void completeStop(void); 92 | 93 | void onChannelFlushed(Channel *channel) override; 94 | 95 | void onChannelDrained(Channel *channel) override; 96 | 97 | void onChannelUnlink(Channel *channel) override; 98 | 99 | int removeQueueEvtFromLoop(struct mbuf_raw_video_frame_queue *queue, 100 | struct pomp_loop *loop); 101 | 102 | static void queueEventCb(struct pomp_evt *evt, void *userdata); 103 | 104 | static bool inputFilter(struct mbuf_raw_video_frame *frame, 105 | void *userdata); 106 | 107 | static void idleCompleteFlush(void *userdata); 108 | 109 | /* Video source listener calls from idle functions */ 110 | static void callOnMediaAdded(void *userdata); 111 | 112 | static void callVideoSourceFlushed(void *userdata); 113 | 114 | IPdraw::IRawVideoSource *mVideoSource; 115 | IPdraw::IRawVideoSource::Listener *mVideoSourceListener; 116 | struct pdraw_video_source_params mParams; 117 | struct mbuf_raw_video_frame_queue *mFrameQueue; 118 | RawVideoMedia *mOutputMedia; 119 | uint64_t mLastTimestamp; 120 | }; 121 | 122 | 123 | class RawVideoSourceWrapper : public IPdraw::IRawVideoSource, 124 | public ElementWrapper { 125 | public: 126 | RawVideoSourceWrapper(Session *session, 127 | const struct pdraw_video_source_params *params, 128 | IPdraw::IRawVideoSource::Listener *listener); 129 | 130 | ~RawVideoSourceWrapper(void); 131 | 132 | struct mbuf_raw_video_frame_queue *getQueue(void) override; 133 | 134 | int flush(void) override; 135 | 136 | int drain(void) override; 137 | 138 | int setSessionMetadata(const struct vmeta_session *meta) override; 139 | 140 | int getSessionMetadata(struct vmeta_session *meta) override; 141 | 142 | void clearElement(void) override 143 | { 144 | ElementWrapper::clearElement(); 145 | mSource = nullptr; 146 | } 147 | 148 | Source *getSource() const 149 | { 150 | return mSource; 151 | } 152 | 153 | ExternalRawVideoSource *getRawVideoSource() const 154 | { 155 | return mSource; 156 | } 157 | 158 | private: 159 | bool isElementStopped(void) const override 160 | { 161 | return (ElementWrapper::isElementStopped() || 162 | mSource == nullptr); 163 | } 164 | 165 | ExternalRawVideoSource *mSource; 166 | }; 167 | 168 | } /* namespace Pdraw */ 169 | 170 | #endif /* !_PDRAW_EXTERNAL_RAW_VIDEO_SOURCE_HPP_ */ 171 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_encoder_audio.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video encoder element 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_ENCODER_AUDIO_HPP_ 32 | #define _PDRAW_ENCODER_AUDIO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | namespace Pdraw { 45 | 46 | class AudioEncoderWrapper; 47 | 48 | 49 | class AudioEncoder : public FilterElement { 50 | public: 51 | AudioEncoder(Session *session, 52 | Element::Listener *elementListener, 53 | Source::Listener *sourceListener, 54 | IPdraw::IAudioEncoder::Listener *listener, 55 | AudioEncoderWrapper *wrapper, 56 | const struct aenc_config *params); 57 | 58 | ~AudioEncoder(void); 59 | 60 | int start(void) override; 61 | 62 | int stop(void) override; 63 | 64 | void completeFlush(void); 65 | 66 | void completeStop(void); 67 | 68 | IPdraw::IAudioEncoder *getAudioEncoder(void) const 69 | { 70 | return mEncoder; 71 | } 72 | 73 | private: 74 | int createOutputMedia(struct adef_frame *frame_info, 75 | AudioMedia::Frame &frame); 76 | 77 | int flush(bool discard = true); 78 | 79 | inline int drain(void) 80 | { 81 | return flush(false); 82 | } 83 | 84 | int tryStop(void); 85 | 86 | void removeEncoderListener(void); 87 | 88 | void onAudioChannelQueue(AudioChannel *channel, 89 | struct mbuf_audio_frame *frame) override; 90 | 91 | void onChannelFlush(Channel *channel) override; 92 | 93 | void onChannelDrain(Channel *channel) override; 94 | 95 | void onChannelFlushed(Channel *channel) override; 96 | 97 | void onChannelDrained(Channel *channel) override; 98 | 99 | void onChannelTeardown(Channel *channel) override; 100 | 101 | void onChannelUnlink(Channel *channel) override; 102 | 103 | static void frameOutputCb(struct aenc_encoder *enc, 104 | int status, 105 | struct mbuf_audio_frame *out_frame, 106 | void *userdata); 107 | 108 | static void flushCb(struct aenc_encoder *enc, void *userdata); 109 | 110 | static void stopCb(struct aenc_encoder *enc, void *userdata); 111 | 112 | /* Can be called from any thread */ 113 | static void framePreReleaseCb(struct mbuf_audio_frame *frame, 114 | void *userdata); 115 | 116 | static void idleCompleteFlush(void *userdata); 117 | 118 | IPdraw::IAudioEncoder *mEncoder; 119 | IPdraw::IAudioEncoder::Listener *mEncoderListener; 120 | pthread_mutex_t mListenerMutex; 121 | AudioMedia *mInputMedia; 122 | AudioMedia *mOutputMedia; 123 | struct mbuf_pool *mInputBufferPool; 124 | struct mbuf_audio_frame_queue *mInputBufferQueue; 125 | struct aenc_config *mEncoderConfig; 126 | std::string mEncoderName; 127 | std::string mEncoderDevice; 128 | struct aenc_encoder *mAenc; 129 | bool mInputChannelFlushPending; 130 | bool mOutputChannelDrainRequired; 131 | bool mAencFlushPending; 132 | bool mAencStopPending; 133 | static const struct aenc_cbs mEncoderCbs; 134 | }; 135 | 136 | 137 | class AudioEncoderWrapper : public IPdraw::IAudioEncoder, 138 | public ElementWrapper { 139 | public: 140 | AudioEncoderWrapper(Session *session, 141 | const struct aenc_config *params, 142 | IPdraw::IAudioEncoder::Listener *listener); 143 | 144 | ~AudioEncoderWrapper(void); 145 | 146 | void clearElement(void) override 147 | { 148 | ElementWrapper::clearElement(); 149 | mEncoder = nullptr; 150 | } 151 | 152 | Sink *getEncoder() const 153 | { 154 | return mEncoder; 155 | } 156 | 157 | AudioEncoder *getAudioEncoder() const 158 | { 159 | return mEncoder; 160 | } 161 | 162 | private: 163 | bool isElementStopped(void) const override 164 | { 165 | return (ElementWrapper::isElementStopped() || 166 | mEncoder == nullptr); 167 | } 168 | 169 | AudioEncoder *mEncoder; 170 | }; 171 | 172 | } /* namespace Pdraw */ 173 | 174 | #endif /* !_PDRAW_ENCODER_AUDIO_HPP_ */ 175 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_external_coded_video_source.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Application external coded video source 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_EXTERNAL_CODED_VIDEO_SOURCE_HPP_ 32 | #define _PDRAW_EXTERNAL_CODED_VIDEO_SOURCE_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class CodedVideoSourceWrapper; 44 | 45 | 46 | class ExternalCodedVideoSource : public SourceElement { 47 | public: 48 | ExternalCodedVideoSource( 49 | Session *session, 50 | Element::Listener *elementListener, 51 | Source::Listener *sourceListener, 52 | IPdraw::ICodedVideoSource::Listener *listener, 53 | CodedVideoSourceWrapper *wrapper, 54 | const struct pdraw_video_source_params *params); 55 | 56 | ~ExternalCodedVideoSource(void); 57 | 58 | int start(void) override; 59 | 60 | int stop(void) override; 61 | 62 | int flush(bool discard = true); 63 | 64 | inline int drain(void) 65 | { 66 | return flush(false); 67 | } 68 | 69 | int setSessionMetadata(const struct vmeta_session *meta); 70 | 71 | int getSessionMetadata(struct vmeta_session *meta) const; 72 | 73 | struct mbuf_coded_video_frame_queue *getQueue(void) const 74 | { 75 | return mFrameQueue; 76 | } 77 | 78 | IPdraw::ICodedVideoSource *getVideoSource(void) const 79 | { 80 | return mVideoSource; 81 | } 82 | 83 | private: 84 | int process(void); 85 | 86 | int processFrame(struct mbuf_coded_video_frame *frame); 87 | 88 | void completeFlush(void); 89 | 90 | int tryStop(void); 91 | 92 | void completeStop(void); 93 | 94 | void onChannelFlushed(Channel *channel) override; 95 | 96 | void onChannelDrained(Channel *channel) override; 97 | 98 | void onChannelUnlink(Channel *channel) override; 99 | 100 | int removeQueueEvtFromLoop(struct mbuf_coded_video_frame_queue *queue, 101 | struct pomp_loop *loop); 102 | 103 | static void queueEventCb(struct pomp_evt *evt, void *userdata); 104 | 105 | static bool inputFilter(struct mbuf_coded_video_frame *frame, 106 | void *userdata); 107 | 108 | static void idleCompleteFlush(void *userdata); 109 | 110 | /* Video source listener calls from idle functions */ 111 | static void callOnMediaAdded(void *userdata); 112 | 113 | static void callVideoSourceFlushed(void *userdata); 114 | 115 | IPdraw::ICodedVideoSource *mVideoSource; 116 | IPdraw::ICodedVideoSource::Listener *mVideoSourceListener; 117 | struct pdraw_video_source_params mParams; 118 | struct mbuf_coded_video_frame_queue *mFrameQueue; 119 | CodedVideoMedia *mOutputMedia; 120 | uint64_t mLastTimestamp; 121 | }; 122 | 123 | 124 | class CodedVideoSourceWrapper : public IPdraw::ICodedVideoSource, 125 | public ElementWrapper { 126 | public: 127 | CodedVideoSourceWrapper(Session *session, 128 | const struct pdraw_video_source_params *params, 129 | IPdraw::ICodedVideoSource::Listener *listener); 130 | 131 | ~CodedVideoSourceWrapper(void); 132 | 133 | struct mbuf_coded_video_frame_queue *getQueue(void) override; 134 | 135 | int flush(void) override; 136 | 137 | int drain(void) override; 138 | 139 | int setSessionMetadata(const struct vmeta_session *meta) override; 140 | 141 | int getSessionMetadata(struct vmeta_session *meta) override; 142 | 143 | void clearElement(void) override 144 | { 145 | ElementWrapper::clearElement(); 146 | mSource = nullptr; 147 | } 148 | 149 | Source *getSource() const 150 | { 151 | return mSource; 152 | } 153 | 154 | ExternalCodedVideoSource *getCodedVideoSource() const 155 | { 156 | return mSource; 157 | } 158 | 159 | private: 160 | bool isElementStopped(void) const override 161 | { 162 | return (ElementWrapper::isElementStopped() || 163 | mSource == nullptr); 164 | } 165 | 166 | ExternalCodedVideoSource *mSource; 167 | }; 168 | 169 | } /* namespace Pdraw */ 170 | 171 | #endif /* !_PDRAW_EXTERNAL_CODED_VIDEO_SOURCE_HPP_ */ 172 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_muxer_stream_rtmp.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * RTMP stream muxer 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_MUXER_STREAM_RTMP_HPP_ 32 | #define _PDRAW_MUXER_STREAM_RTMP_HPP_ 33 | 34 | #ifdef BUILD_LIBRTMP 35 | 36 | # include "pdraw_muxer.hpp" 37 | 38 | # include 39 | 40 | # include 41 | 42 | namespace Pdraw { 43 | 44 | 45 | class RtmpStreamMuxer : public Muxer { 46 | public: 47 | RtmpStreamMuxer(Session *session, 48 | Element::Listener *elementListener, 49 | IPdraw::IMuxer::Listener *listener, 50 | MuxerWrapper *wrapper, 51 | const std::string &url, 52 | const struct pdraw_muxer_params *params); 53 | 54 | ~RtmpStreamMuxer(void); 55 | 56 | int 57 | addInputMedia(Media *media, 58 | const struct pdraw_muxer_media_params *params) override; 59 | 60 | int addInputMedia(Media *media) override 61 | { 62 | return addInputMedia(media, nullptr); 63 | }; 64 | 65 | int getStats(struct pdraw_muxer_stats *stats) override; 66 | 67 | private: 68 | enum RtmpState { 69 | DISCONNECTED = 0, 70 | CONNECTING, 71 | CONNECTED, 72 | }; 73 | 74 | int internalStart(void) override; 75 | 76 | int internalStop(void) override; 77 | 78 | int configure(void); 79 | 80 | int scheduleReconnection(void); 81 | 82 | int reconnect(void); 83 | 84 | int process(void) override; 85 | 86 | int processMedia(CodedVideoMedia *media); 87 | 88 | int processFrame(CodedVideoMedia *media, 89 | struct mbuf_coded_video_frame *frame); 90 | 91 | void onChannelFlush(Channel *channel) override; 92 | 93 | void onChannelDrain(Channel *channel) override; 94 | 95 | void setRtmpState(RtmpStreamMuxer::RtmpState state); 96 | 97 | static const char *getRtmpStateStr(RtmpStreamMuxer::RtmpState val); 98 | 99 | static enum pdraw_muxer_connection_state 100 | rtmpStateToMuxerConnectionState(RtmpStreamMuxer::RtmpState val); 101 | 102 | static void getReconnectionStrategy( 103 | enum rtmp_client_disconnection_reason disconnectionReason, 104 | bool *doReconnect, 105 | int *reconnectionCount); 106 | 107 | static void fakeAudioTimerCb(struct pomp_timer *timer, void *userdata); 108 | 109 | static void onSocketCreated(int fd, void *userdata); 110 | 111 | static void connectionStateCb( 112 | enum rtmp_client_conn_state state, 113 | enum rtmp_client_disconnection_reason disconnection_reason, 114 | void *userdata); 115 | 116 | static void peerBwChangedCb(uint32_t bandwidth, void *userdata); 117 | 118 | static void 119 | dataUnrefCb(uint8_t *data, void *buffer_userdata, void *userdata); 120 | 121 | static void connectionWatchdogCb(struct pomp_timer *timer, 122 | void *userdata); 123 | 124 | static void reconnectionTimerCb(struct pomp_timer *timer, 125 | void *userdata); 126 | 127 | std::string mUrl; 128 | struct pomp_timer *mDummyAudioTimer; 129 | bool mDummyAudioStarted; 130 | struct rtmp_client *mRtmpClient; 131 | RtmpState mRtmpState; 132 | enum rtmp_client_conn_state mRtmpConnectionState; 133 | enum rtmp_client_disconnection_reason mRtmpDisconnectionReason; 134 | bool mConfigured; 135 | bool mSynchronized; 136 | CodedVideoMedia *mVideoMedia; 137 | double mDuration; 138 | int mWidth; 139 | int mHeight; 140 | double mFramerate; 141 | int mAudioSampleRate; 142 | int mAudioSampleSize; 143 | uint32_t mDummyAudioTimestamp; 144 | struct pdraw_muxer_stats mStats; 145 | std::vector mVideoAvcc; 146 | struct pomp_timer *mConnectionWatchdog; 147 | bool mHasBeenConnected; 148 | int mReconnectionCount; 149 | int mReconnectionMaxCount; 150 | struct pomp_timer *mReconnectionTimer; 151 | 152 | static const struct rtmp_callbacks mRtmpCbs; 153 | static const uint8_t mDummyAudioSpecificConfig[5]; 154 | static const uint8_t mDummyAudioSample[6]; 155 | static const int mDummyAudioSampleRate; 156 | static const int mDummyAudioSampleSize; 157 | }; 158 | 159 | } /* namespace Pdraw */ 160 | 161 | #endif /* BUILD_LIBRTMP */ 162 | 163 | #endif /* !_PDRAW_MUXER_STREAM_RTMP_HPP_ */ 164 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_external_raw_video_sink.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Application external raw video sink 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_EXTERNAL_RAW_VIDEO_SINK_HPP_ 32 | #define _PDRAW_EXTERNAL_RAW_VIDEO_SINK_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | namespace Pdraw { 42 | 43 | class RawVideoSinkWrapper; 44 | 45 | 46 | class ExternalRawVideoSink : public SinkElement { 47 | public: 48 | ExternalRawVideoSink(Session *session, 49 | Element::Listener *elementListener, 50 | IPdraw::IRawVideoSink::Listener *listener, 51 | RawVideoSinkWrapper *wrapper, 52 | unsigned int mediaId, 53 | const struct pdraw_video_sink_params *params); 54 | 55 | ~ExternalRawVideoSink(void); 56 | 57 | int start(void) override; 58 | 59 | int stop(void) override; 60 | 61 | int setMediaId(unsigned int mediaId); 62 | 63 | unsigned int getMediaId(void) const; 64 | 65 | int flushDone(bool discard = true); 66 | 67 | inline int drainDone(void) 68 | { 69 | return flushDone(false); 70 | } 71 | 72 | struct mbuf_raw_video_frame_queue *getQueue(void) const 73 | { 74 | return mInputFrameQueue; 75 | } 76 | 77 | IPdraw::IRawVideoSink *getVideoSink(void) const 78 | { 79 | return mVideoSink; 80 | } 81 | 82 | int addInputMedia(Media *media) override; 83 | 84 | int removeInputMedia(Media *media) override; 85 | 86 | private: 87 | int flush(bool discard = true); 88 | 89 | inline int drain(void) 90 | { 91 | return flush(false); 92 | } 93 | 94 | int channelTeardown(RawVideoChannel *channel); 95 | 96 | void 97 | onRawVideoChannelQueue(RawVideoChannel *channel, 98 | struct mbuf_raw_video_frame *frame) override; 99 | 100 | void onChannelFlush(Channel *channel) override; 101 | 102 | void onChannelDrain(Channel *channel) override; 103 | 104 | void onChannelTeardown(Channel *channel) override; 105 | 106 | void onChannelSessionMetaUpdate(Channel *channel) override; 107 | 108 | void onChannelReconfigure(Channel *channel) override; 109 | 110 | void onChannelResolutionChange(Channel *channel) override; 111 | 112 | void onChannelFramerateChange(Channel *channel) override; 113 | 114 | int prepareRawVideoFrame(RawVideoChannel *channel, 115 | struct mbuf_raw_video_frame *frame); 116 | 117 | static void idleFlushDone(void *userdata); 118 | 119 | /* Video sink listener calls from idle functions */ 120 | static void callVideoSinkFlush(void *userdata); 121 | 122 | static void idleRenewMedia(void *userdata); 123 | 124 | IPdraw::IRawVideoSink *mVideoSink; 125 | IPdraw::IRawVideoSink::Listener *mVideoSinkListener; 126 | struct pdraw_video_sink_params mParams; 127 | RawVideoMedia *mInputMedia; 128 | struct pdraw_media_info mMediaInfo; 129 | struct vmeta_session mMediaInfoSessionMeta; 130 | unsigned int mMediaId; 131 | unsigned int mTargetMediaId; 132 | struct mbuf_raw_video_frame_queue *mInputFrameQueue; 133 | bool mInputChannelFlushPending; 134 | bool mTearingDown; 135 | bool mPendingRestart; 136 | }; 137 | 138 | 139 | class RawVideoSinkWrapper : public IPdraw::IRawVideoSink, 140 | public ElementWrapper { 141 | public: 142 | RawVideoSinkWrapper(Session *session, 143 | unsigned int mediaId, 144 | const struct pdraw_video_sink_params *params, 145 | IPdraw::IRawVideoSink::Listener *listener); 146 | 147 | ~RawVideoSinkWrapper(void); 148 | 149 | int setMediaId(unsigned int mediaId) override; 150 | 151 | unsigned int getMediaId(void) override; 152 | 153 | struct mbuf_raw_video_frame_queue *getQueue(void) override; 154 | 155 | int queueFlushed(void) override; 156 | 157 | int queueDrained(void) override; 158 | 159 | void clearElement(void) override 160 | { 161 | ElementWrapper::clearElement(); 162 | mSink = nullptr; 163 | } 164 | 165 | Sink *getSink() const 166 | { 167 | return mSink; 168 | } 169 | 170 | ExternalRawVideoSink *getRawVideoSink() const 171 | { 172 | return mSink; 173 | } 174 | 175 | private: 176 | bool isElementStopped(void) const override 177 | { 178 | return (ElementWrapper::isElementStopped() || mSink == nullptr); 179 | } 180 | 181 | ExternalRawVideoSink *mSink; 182 | }; 183 | 184 | } /* namespace Pdraw */ 185 | 186 | #endif /* !_PDRAW_EXTERNAL_RAW_VIDEO_SINK_HPP_ */ 187 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_encoder_video.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Video encoder element 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_ENCODER_VIDEO_HPP_ 32 | #define _PDRAW_ENCODER_VIDEO_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace Pdraw { 46 | 47 | class VideoEncoderWrapper; 48 | 49 | 50 | class VideoEncoder : public FilterElement { 51 | public: 52 | VideoEncoder(Session *session, 53 | Element::Listener *elementListener, 54 | Source::Listener *sourceListener, 55 | IPdraw::IVideoEncoder::Listener *listener, 56 | VideoEncoderWrapper *wrapper, 57 | const struct venc_config *params); 58 | 59 | ~VideoEncoder(void); 60 | 61 | int start(void) override; 62 | 63 | int stop(void) override; 64 | 65 | void completeFlush(void); 66 | 67 | void completeStop(void); 68 | 69 | int configure(const struct venc_dyn_config *config); 70 | 71 | int getConfig(struct venc_dyn_config *config); 72 | 73 | IPdraw::IVideoEncoder *getVideoEncoder(void) const 74 | { 75 | return mEncoder; 76 | } 77 | 78 | private: 79 | int createOutputMedia(struct vdef_coded_frame *frame_info, 80 | CodedVideoMedia::Frame &frame); 81 | 82 | int flush(bool discard = true); 83 | 84 | inline int drain(void) 85 | { 86 | return flush(false); 87 | } 88 | 89 | int tryStop(void); 90 | 91 | void removeEncoderListener(void); 92 | 93 | void 94 | onRawVideoChannelQueue(RawVideoChannel *channel, 95 | struct mbuf_raw_video_frame *frame) override; 96 | 97 | void onChannelFlush(Channel *channel) override; 98 | 99 | void onChannelDrain(Channel *channel) override; 100 | 101 | void onChannelFlushed(Channel *channel) override; 102 | 103 | void onChannelDrained(Channel *channel) override; 104 | 105 | void onChannelTeardown(Channel *channel) override; 106 | 107 | void onChannelUnlink(Channel *channel) override; 108 | 109 | void onChannelSessionMetaUpdate(Channel *channel) override; 110 | 111 | static void frameOutputCb(struct venc_encoder *enc, 112 | int status, 113 | struct mbuf_coded_video_frame *out_frame, 114 | void *userdata); 115 | 116 | static void flushCb(struct venc_encoder *enc, void *userdata); 117 | 118 | static void stopCb(struct venc_encoder *enc, void *userdata); 119 | 120 | /* Can be called from any thread */ 121 | static void framePreReleaseCb(struct mbuf_coded_video_frame *frame, 122 | void *userdata); 123 | 124 | static void idleCompleteFlush(void *userdata); 125 | 126 | IPdraw::IVideoEncoder *mEncoder; 127 | IPdraw::IVideoEncoder::Listener *mEncoderListener; 128 | pthread_mutex_t mListenerMutex; 129 | RawVideoMedia *mInputMedia; 130 | CodedVideoMedia *mOutputMedia; 131 | struct mbuf_pool *mInputBufferPool; 132 | struct mbuf_raw_video_frame_queue *mInputBufferQueue; 133 | struct venc_config *mEncoderConfig; 134 | std::string mEncoderName; 135 | std::string mEncoderDevice; 136 | struct venc_encoder *mVenc; 137 | bool mInputChannelFlushPending; 138 | bool mOutputChannelDrainRequired; 139 | bool mVencFlushPending; 140 | bool mVencStopPending; 141 | static const struct venc_cbs mEncoderCbs; 142 | }; 143 | 144 | 145 | class VideoEncoderWrapper : public IPdraw::IVideoEncoder, 146 | public ElementWrapper { 147 | public: 148 | VideoEncoderWrapper(Session *session, 149 | const struct venc_config *params, 150 | IPdraw::IVideoEncoder::Listener *listener); 151 | 152 | ~VideoEncoderWrapper(void); 153 | 154 | int configure(const struct venc_dyn_config *config) override; 155 | 156 | int getConfig(struct venc_dyn_config *config) override; 157 | 158 | void clearElement(void) override 159 | { 160 | ElementWrapper::clearElement(); 161 | mEncoder = nullptr; 162 | } 163 | 164 | Sink *getEncoder() const 165 | { 166 | return mEncoder; 167 | } 168 | 169 | VideoEncoder *getVideoEncoder() const 170 | { 171 | return mEncoder; 172 | } 173 | 174 | private: 175 | bool isElementStopped(void) const override 176 | { 177 | return (ElementWrapper::isElementStopped() || 178 | mEncoder == nullptr); 179 | } 180 | 181 | VideoEncoder *mEncoder; 182 | }; 183 | 184 | } /* namespace Pdraw */ 185 | 186 | #endif /* !_PDRAW_ENCODER_VIDEO_HPP_ */ 187 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_alsa_source.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * ALSA source 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_ALSA_SOURCE_HPP_ 32 | #define _PDRAW_ALSA_SOURCE_HPP_ 33 | 34 | #include "pdraw_element.hpp" 35 | 36 | #include 37 | 38 | #include 39 | 40 | #include "pdraw_alsa_audio.hpp" 41 | #include 42 | 43 | #ifdef PDRAW_USE_ALSA 44 | # include 45 | 46 | # include 47 | #endif 48 | 49 | namespace Pdraw { 50 | 51 | 52 | #ifdef PDRAW_USE_ALSA 53 | 54 | class AlsaSourceWrapper; 55 | 56 | 57 | class AlsaSource : public SourceElement { 58 | public: 59 | AlsaSource(Session *session, 60 | Element::Listener *elementListener, 61 | Source::Listener *sourceListener, 62 | IPdraw::IAlsaSource::Listener *listener, 63 | AlsaSourceWrapper *wrapper, 64 | const struct pdraw_alsa_source_params *params); 65 | 66 | ~AlsaSource(void); 67 | 68 | int start(void) override; 69 | 70 | int stop(void) override; 71 | 72 | bool isReadyToPlay(void); 73 | 74 | bool isPaused(void); 75 | 76 | int play(void); 77 | 78 | int pause(void); 79 | 80 | inline int drain(void) 81 | { 82 | return flush(false); 83 | } 84 | 85 | static int getCapabilities(const std::string &address, 86 | struct pdraw_alsa_source_caps *caps); 87 | 88 | IPdraw::IAlsaSource *getAlsaSource(void) const 89 | { 90 | return mAlsaSource; 91 | } 92 | 93 | private: 94 | int readFrame(void); 95 | 96 | int processFrame(struct mbuf_mem *mem, size_t len); 97 | 98 | int setupMedia(void); 99 | 100 | int createMedia(void); 101 | 102 | int destroyMedia(void); 103 | 104 | int teardownChannels(void); 105 | 106 | int flush(bool discard = true); 107 | 108 | void completeFlush(void); 109 | 110 | int tryStop(void); 111 | 112 | void completeStop(void); 113 | 114 | void playResponse(void); 115 | 116 | void pauseResponse(void); 117 | 118 | void onChannelFlushed(Channel *channel) override; 119 | 120 | void onChannelDrained(Channel *channel) override; 121 | 122 | void onChannelUnlink(Channel *channel) override; 123 | 124 | const char *getSourceName(void) const; 125 | 126 | /* Alsa source listener calls from idle functions */ 127 | static void callOnMediaAdded(void *userdata); 128 | 129 | static void callPlayResponse(void *userdata); 130 | 131 | static void callPauseResponse(void *userdata); 132 | 133 | static void timerCb(struct pomp_timer *timer, void *userdata); 134 | 135 | static void idleCompleteFlush(void *userdata); 136 | 137 | IPdraw::IAlsaSource *mAlsaSource; 138 | IPdraw::IAlsaSource::Listener *mAlsaSourceListener; 139 | struct pdraw_alsa_source_params mParams; 140 | std::string mAddress; 141 | enum pdraw_alsa_source_eos_reason mLastEosReason; 142 | AudioMedia *mOutputMedia; 143 | bool mOutputMediaChanging; 144 | bool mReady; 145 | bool mRunning; 146 | bool mFirstFrame; 147 | bool mPausePending; 148 | unsigned int mFrameIndex; 149 | uint32_t mTimescale; 150 | uint64_t mLastTimestamp; 151 | snd_pcm_t *mHandle; 152 | snd_pcm_hw_params_t *mHwParams; 153 | struct pomp_timer *mTimer; 154 | struct mbuf_pool *mPool; 155 | size_t mFrameSize; 156 | uint64_t mFirstTimestamp; 157 | uint64_t mCurTimestamp; 158 | }; 159 | 160 | #endif /* PDRAW_USE_ALSA */ 161 | 162 | 163 | class AlsaSourceWrapper : public IPdraw::IAlsaSource, public ElementWrapper { 164 | public: 165 | AlsaSourceWrapper(Session *session, 166 | const struct pdraw_alsa_source_params *params, 167 | IPdraw::IAlsaSource::Listener *listener); 168 | 169 | ~AlsaSourceWrapper(void); 170 | 171 | bool isReadyToPlay(void) override; 172 | 173 | bool isPaused(void) override; 174 | 175 | int play(void) override; 176 | 177 | int pause(void) override; 178 | 179 | void clearElement(void) override 180 | { 181 | ElementWrapper::clearElement(); 182 | #ifdef PDRAW_USE_ALSA 183 | mSource = nullptr; 184 | #endif 185 | } 186 | 187 | #ifdef PDRAW_USE_ALSA 188 | Source *getSource() const 189 | { 190 | return mSource; 191 | } 192 | 193 | AlsaSource *getAlsaSource() const 194 | { 195 | return mSource; 196 | } 197 | #endif 198 | 199 | private: 200 | bool isElementStopped(void) const override 201 | { 202 | return (ElementWrapper::isElementStopped() 203 | #ifdef PDRAW_USE_ALSA 204 | || mSource == nullptr 205 | #endif 206 | ); 207 | } 208 | 209 | #ifdef PDRAW_USE_ALSA 210 | AlsaSource *mSource; 211 | #endif 212 | }; 213 | 214 | } /* namespace Pdraw */ 215 | 216 | #endif /* !_PDRAW_ALSA_SOURCE_HPP_ */ 217 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_sink.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Pipeline media sink for elements 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_SINK_HPP_ 32 | #define _PDRAW_SINK_HPP_ 33 | 34 | #include "pdraw_channel.hpp" 35 | #include "pdraw_channel_audio.hpp" 36 | #include "pdraw_channel_coded_video.hpp" 37 | #include "pdraw_channel_raw_video.hpp" 38 | #include "pdraw_media.hpp" 39 | 40 | #include 41 | 42 | namespace Pdraw { 43 | 44 | class Session; 45 | 46 | 47 | class Sink : public Channel::SinkListener, 48 | public CodedVideoChannel::CodedVideoSinkListener, 49 | public RawVideoChannel::RawVideoSinkListener, 50 | public AudioChannel::AudioSinkListener { 51 | public: 52 | virtual ~Sink(void); 53 | 54 | void lock(void); 55 | 56 | void unlock(void); 57 | 58 | virtual std::string &getName(void) = 0; 59 | 60 | int getCodedVideoMediaFormatCaps( 61 | const struct vdef_coded_format **caps) const 62 | { 63 | if (caps == nullptr) 64 | return -EINVAL; 65 | *caps = mCodedVideoMediaFormatCaps; 66 | return mCodedVideoMediaFormatCapsCount; 67 | } 68 | 69 | int 70 | getRawVideoMediaFormatCaps(const struct vdef_raw_format **caps) const 71 | { 72 | if (caps == nullptr) 73 | return -EINVAL; 74 | *caps = mRawVideoMediaFormatCaps; 75 | return mRawVideoMediaFormatCapsCount; 76 | } 77 | 78 | int getAudioMediaFormatCaps(const struct adef_format **caps) 79 | { 80 | if (caps == nullptr) 81 | return -EINVAL; 82 | *caps = mAudioMediaFormatCaps; 83 | return mAudioMediaFormatCapsCount; 84 | } 85 | 86 | unsigned int getInputMediaCount(void); 87 | 88 | Media *getInputMedia(unsigned int index); 89 | 90 | Media *findInputMedia(Media *media); 91 | 92 | virtual int addInputMedia(Media *media); 93 | 94 | virtual int removeInputMedia(Media *media); 95 | 96 | Channel *getInputChannel(Media *media); 97 | 98 | protected: 99 | struct InputPort { 100 | Media *media; 101 | Channel *channel; 102 | }; 103 | 104 | Sink(Session *session, 105 | unsigned int maxInputMedias, 106 | const struct vdef_coded_format *codedVideoMediaFormatCaps, 107 | int codedVideoMediaFormatCapsCount, 108 | const struct vdef_raw_format *rawVideoMediaFormatCaps, 109 | int rawVideoMediaFormatCapsCount, 110 | const struct adef_format *audioMediaFormatCaps, 111 | int audioMediaFormatCapsCount); 112 | 113 | void setCodedVideoMediaFormatCaps(const struct vdef_coded_format *caps, 114 | int count) 115 | { 116 | mCodedVideoMediaFormatCaps = caps; 117 | mCodedVideoMediaFormatCapsCount = count; 118 | } 119 | 120 | void setRawVideoMediaFormatCaps(const struct vdef_raw_format *caps, 121 | int count) 122 | { 123 | mRawVideoMediaFormatCaps = caps; 124 | mRawVideoMediaFormatCapsCount = count; 125 | } 126 | 127 | void setAudioMediaFormatCaps(const struct adef_format *caps, int count) 128 | { 129 | mAudioMediaFormatCaps = caps; 130 | mAudioMediaFormatCapsCount = count; 131 | } 132 | 133 | InputPort *getInputPort(Media *media); 134 | 135 | virtual int removeInputMedias(void); 136 | 137 | virtual void 138 | onCodedVideoChannelQueue(CodedVideoChannel *channel, 139 | struct mbuf_coded_video_frame *frame); 140 | 141 | virtual void onRawVideoChannelQueue(RawVideoChannel *channel, 142 | struct mbuf_raw_video_frame *frame); 143 | 144 | virtual void onAudioChannelQueue(AudioChannel *channel, 145 | struct mbuf_audio_frame *frame); 146 | 147 | virtual void onChannelDownstreamEvent(Channel *channel, 148 | const struct pomp_msg *event); 149 | 150 | virtual void onChannelFlush(Channel *channel) = 0; 151 | 152 | virtual void onChannelDrain(Channel *channel) = 0; 153 | 154 | virtual void onChannelTeardown(Channel *channel); 155 | 156 | virtual void onChannelSos(Channel *channel); 157 | 158 | virtual void onChannelEos(Channel *channel); 159 | 160 | virtual void onChannelReconfigure(Channel *channel); 161 | 162 | virtual void onChannelResolutionChange(Channel *channel); 163 | 164 | virtual void onChannelFramerateChange(Channel *channel); 165 | 166 | virtual void onChannelTimeout(Channel *channel); 167 | 168 | virtual void onChannelPhotoTrigger(Channel *channel); 169 | 170 | virtual void onChannelSessionMetaUpdate(Channel *channel); 171 | 172 | struct pomp_loop *mLoop; 173 | pthread_mutex_t mMutex; 174 | unsigned int mMaxInputMedias; 175 | std::vector mInputPorts; 176 | const struct vdef_coded_format *mCodedVideoMediaFormatCaps; 177 | int mCodedVideoMediaFormatCapsCount; 178 | const struct vdef_raw_format *mRawVideoMediaFormatCaps; 179 | int mRawVideoMediaFormatCapsCount; 180 | const struct adef_format *mAudioMediaFormatCaps; 181 | int mAudioMediaFormatCapsCount; 182 | }; 183 | 184 | } /* namespace Pdraw */ 185 | 186 | #endif /* !_PDRAW_SINK_HPP_ */ 187 | -------------------------------------------------------------------------------- /libpdraw/src/pdraw_renderer_audio.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector library 3 | * Audio renderer interface 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ULOG_TAG pdraw_rndaud 32 | #include 33 | ULOG_DECLARE_TAG(ULOG_TAG); 34 | 35 | #include "pdraw_renderer_audio.hpp" 36 | #if defined(PDRAW_USE_ALSA) 37 | # include "pdraw_renderer_audio_alsa.hpp" 38 | #endif 39 | #include "pdraw_session.hpp" 40 | 41 | #include 42 | 43 | namespace Pdraw { 44 | 45 | AudioRenderer * 46 | AudioRenderer::create(Session *session, 47 | Element::Listener *listener, 48 | AudioRendererWrapper *wrapper, 49 | IPdraw::IAudioRenderer::Listener *rndListener, 50 | unsigned int mediaId, 51 | const struct pdraw_audio_renderer_params *params) 52 | { 53 | #if defined(PDRAW_USE_ALSA) 54 | return new AlsaAudioRenderer(session, 55 | listener, 56 | wrapper, 57 | rndListener, 58 | Media::Type::AUDIO, 59 | mediaId, 60 | params); 61 | #else 62 | ULOGE("no audio renderer implementation found"); 63 | return nullptr; 64 | #endif /* PDRAW_USE_ALSA */ 65 | } 66 | 67 | 68 | AudioRenderer::AudioRenderer(Session *session, 69 | Element::Listener *listener, 70 | AudioRendererWrapper *wrapper, 71 | IPdraw::IAudioRenderer::Listener *rndListener, 72 | uint32_t mediaTypeCaps, 73 | const struct adef_format *audioMediaFormatCaps, 74 | int audioMediaFormatCapsCount, 75 | unsigned int mediaId, 76 | const struct pdraw_audio_renderer_params *params) : 77 | SinkElement(session, 78 | listener, 79 | wrapper, 80 | 1, 81 | nullptr, 82 | 0, 83 | nullptr, 84 | 0, 85 | audioMediaFormatCaps, 86 | audioMediaFormatCapsCount), 87 | mRenderer(wrapper), mRendererListener(rndListener) 88 | { 89 | int res; 90 | pthread_mutexattr_t attr; 91 | 92 | res = pthread_mutexattr_init(&attr); 93 | if (res != 0) { 94 | PDRAW_LOG_ERRNO("pthread_mutexattr_init", res); 95 | return; 96 | } 97 | 98 | res = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 99 | if (res != 0) { 100 | PDRAW_LOG_ERRNO("pthread_mutexattr_settype", res); 101 | goto exit; 102 | } 103 | 104 | res = pthread_mutex_init(&mListenerMutex, &attr); 105 | if (res != 0) { 106 | PDRAW_LOG_ERRNO("pthread_mutex_init", res); 107 | goto exit; 108 | } 109 | 110 | exit: 111 | pthread_mutexattr_destroy(&attr); 112 | return; 113 | } 114 | 115 | 116 | AudioRenderer::~AudioRenderer(void) 117 | { 118 | /* Remove any leftover idle callbacks */ 119 | int err = pomp_loop_idle_remove_by_cookie(mSession->getLoop(), this); 120 | if (err < 0) 121 | PDRAW_LOG_ERRNO("pomp_loop_idle_remove_by_cookie", -err); 122 | 123 | pthread_mutex_destroy(&mListenerMutex); 124 | } 125 | 126 | 127 | void AudioRenderer::removeRendererListener(void) 128 | { 129 | pthread_mutex_lock(&mListenerMutex); 130 | mRendererListener = nullptr; 131 | pthread_mutex_unlock(&mListenerMutex); 132 | } 133 | 134 | 135 | void AudioRenderer::asyncCompleteStop(void) 136 | { 137 | int err = pomp_loop_idle_add_with_cookie( 138 | mSession->getLoop(), idleCompleteStop, this, this); 139 | if (err < 0) 140 | PDRAW_LOG_ERRNO("pomp_loop_idle_add_with_cookie", -err); 141 | } 142 | 143 | 144 | /* Listener call from an idle function */ 145 | void AudioRenderer::idleCompleteStop(void *userdata) 146 | { 147 | AudioRenderer *self = reinterpret_cast(userdata); 148 | PDRAW_LOG_ERRNO_RETURN_IF(self == nullptr, EINVAL); 149 | self->completeStop(); 150 | } 151 | 152 | 153 | AudioRendererWrapper::AudioRendererWrapper( 154 | Session *session, 155 | unsigned int mediaId, 156 | const struct pdraw_audio_renderer_params *params, 157 | IPdraw::IAudioRenderer::Listener *listener) 158 | { 159 | mElement = mRenderer = Pdraw::AudioRenderer::create( 160 | session, session, this, listener, mediaId, params); 161 | } 162 | 163 | 164 | AudioRendererWrapper::~AudioRendererWrapper(void) 165 | { 166 | if (isElementStopped()) 167 | return; 168 | int ret = mRenderer->stop(); 169 | if (ret < 0) 170 | ULOG_ERRNO("AudioRenderer::stop", -ret); 171 | } 172 | 173 | 174 | int AudioRendererWrapper::setMediaId(unsigned int mediaId) 175 | { 176 | if (isElementStopped()) 177 | return -EPROTO; 178 | 179 | return mRenderer->setMediaId(mediaId); 180 | } 181 | 182 | 183 | unsigned int AudioRendererWrapper::getMediaId(void) 184 | { 185 | if (isElementStopped()) 186 | return -EPROTO; 187 | 188 | return mRenderer->getMediaId(); 189 | } 190 | 191 | 192 | int AudioRendererWrapper::setParams( 193 | const struct pdraw_audio_renderer_params *params) 194 | { 195 | if (isElementStopped()) 196 | return -EPROTO; 197 | 198 | return mRenderer->setParams(params); 199 | } 200 | 201 | 202 | int AudioRendererWrapper::getParams(struct pdraw_audio_renderer_params *params) 203 | { 204 | if (isElementStopped()) 205 | return -EPROTO; 206 | 207 | return mRenderer->getParams(params); 208 | } 209 | 210 | } /* namespace Pdraw */ 211 | -------------------------------------------------------------------------------- /libpdraw-vsink/include/pdraw-vsink/pdraw_vsink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Parrot Drones Audio and Video Vector 3 | * Video sink wrapper library 4 | * 5 | * Copyright (c) 2018 Parrot Drones SAS 6 | * Copyright (c) 2016 Aurelien Barre 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _PDRAW_VSINK_H_ 32 | #define _PDRAW_VSINK_H_ 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif /* __cplusplus */ 40 | 41 | /* To be used for all public API */ 42 | #ifdef PDRAW_VSINK_API_EXPORTS 43 | # ifdef _WIN32 44 | # define PDRAW_VSINK_API __declspec(dllexport) 45 | # else /* !_WIN32 */ 46 | # define PDRAW_VSINK_API __attribute__((visibility("default"))) 47 | # endif /* !_WIN32 */ 48 | #else /* !PDRAW_VSINK_API_EXPORTS */ 49 | # define PDRAW_VSINK_API 50 | #endif /* !PDRAW_VSINK_API_EXPORTS */ 51 | 52 | 53 | /* Forward declarations */ 54 | struct pdraw_vsink; 55 | 56 | 57 | /* Callback functions */ 58 | struct pdraw_vsink_cbs { 59 | /* Called when a frame is ready (optional, can be null). 60 | * The frame does not need to be unreferenced in the callback 61 | * implementation, but if the frame needs to be kept to be used later by 62 | * the application it should be referenced and later unreferenced when 63 | * no longer needed by calling mbuf_raw_video_frame_ref() and 64 | * mbuf_raw_video_frame_unref(). 65 | * This function is called from the pdraw_vsink internal thread. 66 | * Note: the caller must ensure thread safety and should keep in mind 67 | * that the pdraw_vsink thread is blocked by this function call. 68 | * @param frame: the mbuf_raw_video_frame structure 69 | * @param frame_info: information about the frame 70 | * @param userdata: user data pointer */ 71 | void (*frame_ready)(struct mbuf_raw_video_frame *frame, 72 | struct pdraw_video_frame *frame_info, 73 | void *userdata); 74 | }; 75 | 76 | 77 | /* Instance parameters */ 78 | struct pdraw_vsink_params { 79 | /* Network URL or local file (mandatory) */ 80 | const char *url; 81 | 82 | /* Camera type to select (optional; set to VMETA_CAMERA_TYPE_UNKNOWN to 83 | * select the default camera) */ 84 | enum vmeta_camera_type camera_type; 85 | 86 | /* Callback functions (optional; if the frame_ready callback is not 87 | * provided, use the pdraw_vsink_get_frame() function to retrieve 88 | * frames) */ 89 | struct pdraw_vsink_cbs cbs; 90 | 91 | /* Callback functions user data pointer */ 92 | void *cbs_userdata; 93 | }; 94 | 95 | 96 | /** 97 | * Create a pdraw_vsink instance and connect to a URL. 98 | * The parameters structure is mandatory but only the url field needs to be 99 | * filled (network URL or local file); other fields are optional and can be 100 | * null. The camera_type value can be set to VMETA_CAMERA_TYPE_UNKNOWN to select 101 | * the default camera. The instance handle is returned through the ret_obj 102 | * parameter. When no longer needed, the instance must be freed using the 103 | * pdraw_vsink_stop() function. 104 | * @param params: instance parameters 105 | * @param media_info: optional pointer to a media info structure (output) 106 | * Note: the ownership of the memory stays with the library 107 | * instance and will be freed in pdraw_vsink_stop(). 108 | * @param ret_obj: pdraw_vsink instance handle (output) 109 | * @return 0 on success, negative errno value in case of error 110 | */ 111 | PDRAW_VSINK_API int pdraw_vsink_start(const struct pdraw_vsink_params *params, 112 | struct pdraw_media_info **media_info, 113 | struct pdraw_vsink **ret_obj); 114 | 115 | 116 | /** 117 | * Stop and destroy a pdraw_vsink instance. 118 | * @param self: pdraw_vsink instance handle 119 | * @return 0 on success, negative errno value in case of error 120 | */ 121 | PDRAW_VSINK_API int pdraw_vsink_stop(struct pdraw_vsink *self); 122 | 123 | 124 | /** 125 | * Get a frame. 126 | * The caller can pass a mbuf_mem object to hold the frame. If not given, this 127 | * call will allocate a memory internally. The returned frame is properly 128 | * referenced, so the caller will need to call mbuf_raw_video_frame_unref() when 129 | * the frame is no longer needed. 130 | * Note: this function cannot be used if a get_frame_cb_t callback function has 131 | * been provided in the initial parameters. 132 | * @param self: pdraw_vsink instance handle 133 | * @param timeout_ms: timeout of wait, 0 to return immediately (non-blocking 134 | * mode) or -1 for infinite wait 135 | * @param frame_memory: memory used by the frame (optional) 136 | * @param frame_info: frame information (output) 137 | * @param ret_frame: frame (output) 138 | * @return 0 in case of success, -ETIMEDOUT if timeout occurred, 139 | * negative errno value in case of error 140 | */ 141 | PDRAW_VSINK_API int 142 | pdraw_vsink_get_frame(struct pdraw_vsink *self, 143 | int timeout_ms, 144 | struct mbuf_mem *frame_memory, 145 | struct pdraw_video_frame *frame_info, 146 | struct mbuf_raw_video_frame **ret_frame); 147 | 148 | 149 | #ifdef __cplusplus 150 | } 151 | #endif /* __cplusplus */ 152 | 153 | #endif /* !_LIBPDRAW_VSINK_H_ */ 154 | --------------------------------------------------------------------------------