mirror of
https://github.com/fastogt/fastocloud.git
synced 2025-02-12 09:51:58 +00:00
Release 1.4.4
This commit is contained in:
commit
310132c21d
363 changed files with 32789 additions and 0 deletions
5
.clang-format
Normal file
5
.clang-format
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
BasedOnStyle: Chromium
|
||||
ColumnLimit: 120
|
||||
Standard: Cpp11
|
||||
...
|
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# other
|
||||
*.pyc
|
||||
CMakeLists.txt.user
|
||||
*~
|
||||
|
||||
# fastogt tmp files
|
||||
build/.idea/
|
||||
build/build_*_env/
|
||||
build_cmake/
|
||||
build_cmake_release/
|
||||
clients/.idea
|
||||
.idea
|
50
.gitlab-ci.yml
Normal file
50
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,50 @@
|
|||
image: debian:bullseye-slim
|
||||
|
||||
variables:
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
|
||||
stages:
|
||||
- build
|
||||
- build_package
|
||||
|
||||
before_script:
|
||||
- cd build/env
|
||||
- ./fast_build_fastocloud_env_for_package.sh
|
||||
- cd ../
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
||||
script:
|
||||
- ./build.py release
|
||||
|
||||
tags:
|
||||
- fastogt
|
||||
|
||||
build_package:
|
||||
stage: build_package
|
||||
|
||||
script:
|
||||
- mkdir build_releases/
|
||||
- ./build.py release
|
||||
|
||||
- cd build_linux/build_cmake_release/ && cpack -G DEB
|
||||
- cd ../../
|
||||
- mv build_linux/build_cmake_release/*-x86_64-*.deb build_releases/
|
||||
|
||||
- cd build_linux/build_cmake_release/ && cpack -G RPM
|
||||
- cd ../../
|
||||
- mv build_linux/build_cmake_release/*-x86_64-*.rpm build_releases/
|
||||
|
||||
- cd build_linux/build_cmake_release/ && cpack -G TGZ
|
||||
- cd ../../
|
||||
- mv build_linux/build_cmake_release/*-x86_64-*.tar.gz build_releases/
|
||||
|
||||
artifacts:
|
||||
paths:
|
||||
- $CI_PROJECT_DIR/build/build_releases/*.deb
|
||||
- $CI_PROJECT_DIR/build/build_releases/*.rpm
|
||||
- $CI_PROJECT_DIR/build/build_releases/*.tar.gz
|
||||
|
||||
tags:
|
||||
- fastogt
|
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
[submodule "cmake"]
|
||||
path = cmake
|
||||
url = https://github.com/fastogt/cmake
|
||||
[submodule "build/env"]
|
||||
path = build/env
|
||||
url = https://github.com/fastogt/fastocloud_env.git
|
74
CHANGELOG
Normal file
74
CHANGELOG
Normal file
|
@ -0,0 +1,74 @@
|
|||
1.4.4 / October 16, 2024
|
||||
[Alexandr Topilski]
|
||||
- VSystem, vrole stats
|
||||
|
||||
1.4.3 / February 4, 2023
|
||||
[Alexandr Topilski]
|
||||
- Stabilization
|
||||
|
||||
1.4.2 / October 20, 2022
|
||||
[Alexandr Topilski]
|
||||
- Review http post routes
|
||||
- Reload command
|
||||
- Get hash route
|
||||
|
||||
1.4.1 / April 11, 2022
|
||||
[Alexandr Topilski]
|
||||
- Pads reviews
|
||||
|
||||
1.4.0 / February 23, 2022
|
||||
[Alexandr Topilski]
|
||||
- More common code with PRO
|
||||
|
||||
1.4.0 / February 21, 2022
|
||||
[Alexandr Topilski]
|
||||
- FastoTV types integration
|
||||
- Copyrights
|
||||
|
||||
1.3.2 / June 5, 2021
|
||||
[Alexandr Topilski]
|
||||
- Stabilization
|
||||
|
||||
1.3.1 / March 27, 2021
|
||||
[Alexandr Topilski]
|
||||
- Bug fixes
|
||||
|
||||
1.3.0 / March 27, 2021
|
||||
[Alexandr Topilski]
|
||||
- License key review
|
||||
- CI/CD
|
||||
- Docker
|
||||
|
||||
1.2.5 / March 13, 2021
|
||||
[Alexandr Topilski]
|
||||
- Ini section
|
||||
|
||||
1.2.4 / January 30, 2021
|
||||
[Alexandr Topilski]
|
||||
- PyFastoStream integration
|
||||
|
||||
1.2.3 / January 16, 2021
|
||||
[Alexandr Topilski]
|
||||
- Kill stream command
|
||||
|
||||
1.2.2 / January 2, 2021
|
||||
[Alexandr Topilski]
|
||||
- Bitrates fixes
|
||||
|
||||
1.2.1 / December 18, 2020
|
||||
[Alexandr Topilski]
|
||||
- Stabilization
|
||||
- Back to opensource
|
||||
|
||||
1.1.1 / June 20, 2020
|
||||
[Alexandr Topilski]
|
||||
- DVB source
|
||||
- Stabilization
|
||||
|
||||
1.1.0 / April 21, 2020
|
||||
[Alexandr Topilski]
|
||||
- Otional fields
|
||||
|
||||
1.0.0 / March 20, 2020
|
||||
[Alexandr Topilski]
|
||||
- Init release
|
202
CMakeLists.txt
Normal file
202
CMakeLists.txt
Normal file
|
@ -0,0 +1,202 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)
|
||||
|
||||
SET(BRANDING_PROJECT_NAME "fastocloud" CACHE STRING "Branding for ${BRANDING_PROJECT_NAME}") #default
|
||||
SET(BRANDING_PROJECT_VERSION "1.4.4.17" CACHE STRING "Branding version for ${BRANDING_PROJECT_NAME}") #default
|
||||
SET(BRANDING_PROJECT_BUILD_TYPE_VERSION "release" CACHE STRING "Build version type for ${BRANDING_PROJECT_NAME}") #default alfa,beta,rc,release
|
||||
SET(BRANDING_PROJECT_DOMAIN "www.fastogt.com" CACHE STRING "Branding domain url for ${BRANDING_PROJECT_NAME}") #default
|
||||
SET(BRANDING_PROJECT_COMPANYNAME "FastoGT" CACHE STRING "Company name for ${BRANDING_PROJECT_NAME}") #default
|
||||
SET(BRANDING_PROJECT_SUMMARY "${BRANDING_PROJECT_NAME} real-time encoding/transcoding service."
|
||||
CACHE STRING "Short description of ${BRANDING_PROJECT_NAME}")
|
||||
SET(BRANDING_PROJECT_COPYRIGHT "Copyright (C) 2014-2023 ${BRANDING_PROJECT_COMPANYNAME} All Rights Reserved."
|
||||
CACHE STRING "Copyright notice for ${BRANDING_PROJECT_NAME}") #default
|
||||
SET(BRANDING_PROJECT_CHANGELOG_FILE CHANGELOG
|
||||
CACHE STRING "Branding for changelog file ${BRANDING_PROJECT_NAME}
|
||||
(File name given as relative paths are interpreted with respect to the src source directory)") #default
|
||||
SET(BRANDING_PROJECT_LICENSE_FILE_NAME LICENSE
|
||||
CACHE STRING "Branding for license file ${BRANDING_PROJECT_NAME}
|
||||
(File name given as relative paths are interpreted with respect to the src source directory)") #default
|
||||
|
||||
PROJECT(${BRANDING_PROJECT_NAME} VERSION ${BRANDING_PROJECT_VERSION} LANGUAGES CXX C)
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
SET(CMAKE_CXX_EXTENSIONS OFF)
|
||||
SET(CMAKE_C_STANDARD 99)
|
||||
SET(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
#SET(CMAKE_C_EXTENSIONS OFF)
|
||||
#################### Project Settings ####################
|
||||
SET(PROJECT_NAME_TITLE ${PROJECT_NAME}) #PROJECT_NAME in cache
|
||||
SET(PROJECT_DOMAIN ${BRANDING_PROJECT_DOMAIN})
|
||||
SET(PROJECT_COMPANYNAME ${BRANDING_PROJECT_COMPANYNAME})
|
||||
SET(PROJECT_SUMMARY ${BRANDING_PROJECT_SUMMARY})
|
||||
SET(PROJECT_COPYRIGHT ${BRANDING_PROJECT_COPYRIGHT})
|
||||
SET(PROJECT_CHANGELOG_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${BRANDING_PROJECT_LICENSE_FILE_NAME})
|
||||
SET(PROJECT_LICENSE_FILE_NAME ${BRANDING_PROJECT_LICENSE_FILE_NAME})
|
||||
|
||||
SET(DATE_CMD "date")
|
||||
SET(DATE_ARGS "+%a %b %d %Y")
|
||||
EXECUTE_PROCESS(COMMAND ${DATE_CMD} ${DATE_ARGS} RESULT_VARIABLE CHANGELOG_TIMESTAMP_RESULT OUTPUT_VARIABLE CHANGELOG_TIMESTAMP) #for rpm package
|
||||
IF (NOT "${CHANGELOG_TIMESTAMP}" STREQUAL "")
|
||||
STRING(REPLACE "\n" "" CHANGELOG_TIMESTAMP ${CHANGELOG_TIMESTAMP})
|
||||
ELSE()
|
||||
MESSAGE(WARNING "Failed to get timestamp: ${CHANGELOG_TIMESTAMP_RESULT}")
|
||||
ENDIF(NOT "${CHANGELOG_TIMESTAMP}" STREQUAL "")
|
||||
FILE(WRITE ${PROJECT_CHANGELOG_FILE} "* ${CHANGELOG_TIMESTAMP} ${PROJECT_MAINTAINER_NAME} <${PROJECT_MAINTAINER_MAIL}>\n")
|
||||
FILE(READ ${BRANDING_PROJECT_CHANGELOG_FILE} CHANGELOG_TEXT)
|
||||
FILE(APPEND ${PROJECT_CHANGELOG_FILE} ${CHANGELOG_TEXT})
|
||||
|
||||
SET(PROJECT_BUILD_TYPE_VERSION ${BRANDING_PROJECT_BUILD_TYPE_VERSION})
|
||||
##########################################################
|
||||
STRING(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
|
||||
STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERRCASE)
|
||||
|
||||
SET(PROJECT_VERSION_SHORT ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) #PROJECT_VERSION_* in cache
|
||||
SET(PROJECT_VERSION_INTEGER ${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH}) #PROJECT_VERSION_* in cache
|
||||
|
||||
MESSAGE(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}")
|
||||
|
||||
OPTION(DEVELOPER_ENABLE_TESTS "Enable tests for ${PROJECT_NAME_TITLE} project" OFF)
|
||||
OPTION(DEVELOPER_CHECK_STYLE "Enable check style for ${PROJECT_NAME_TITLE} project" OFF)
|
||||
OPTION(DEVELOPER_GENERATE_DOCS "Generate docs api for ${PROJECT_NAME_TITLE} project" OFF)
|
||||
OPTION(BUILD_SERVER "Build server for ${PROJECT_NAME_TITLE} project" ON)
|
||||
OPTION(BUILD_STREAM "Build stream for ${PROJECT_NAME_TITLE} project" ON)
|
||||
OPTION(CPACK_SUPPORT "Enable package build" OFF)
|
||||
|
||||
##################################DEFAULT VALUES##########################################
|
||||
IF(NOT CMAKE_BUILD_TYPE)
|
||||
SET(CMAKE_BUILD_TYPE DEBUG)
|
||||
ENDIF(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
# If the user did not customize the install prefix,
|
||||
# set it to live under build so we don't inadvertently pollute /usr/local
|
||||
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
|
||||
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
|
||||
IF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
|
||||
MESSAGE(SEND_ERROR "In-source builds are not allowed.")
|
||||
ENDIF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
|
||||
|
||||
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
############################################################################
|
||||
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
INCLUDE(config) ###################
|
||||
DEFINE_DEFAULT_DEFINITIONS(ON, ON, OFF)
|
||||
DEFINE_PROJECT_DEFINITIONS()
|
||||
|
||||
SET(PROJECT_VERSION_HUMAN "${PROJECT_VERSION} Revision: ${PROJECT_VERSION_GIT}")
|
||||
|
||||
IF(OS_WINDOWS)
|
||||
SET(LIB_INSTALL_DESTINATION lib)
|
||||
SET(TARGET_INSTALL_DESTINATION bin)
|
||||
SET(SHARE_INSTALL_DESTINATION share)
|
||||
ELSEIF(OS_MACOSX)
|
||||
SET(LIB_INSTALL_DESTINATION lib)
|
||||
SET(TARGET_INSTALL_DESTINATION bin)
|
||||
SET(SHARE_INSTALL_DESTINATION share)
|
||||
ELSEIF(OS_LINUX)
|
||||
SET(LIB_INSTALL_DESTINATION lib)
|
||||
SET(TARGET_INSTALL_DESTINATION bin)
|
||||
SET(SHARE_INSTALL_DESTINATION share)
|
||||
ELSEIF(OS_FREEBSD)
|
||||
SET(LIB_INSTALL_DESTINATION lib)
|
||||
SET(TARGET_INSTALL_DESTINATION bin)
|
||||
SET(SHARE_INSTALL_DESTINATION share)
|
||||
ELSEIF(OS_ANDROID)
|
||||
SET(LIB_INSTALL_DESTINATION libs/${ANDROID_NDK_ABI_NAME})
|
||||
SET(TARGET_INSTALL_DESTINATION libs/${ANDROID_NDK_ABI_NAME}) #libs/armeabi-v7a
|
||||
SET(SHARE_INSTALL_DESTINATION share)
|
||||
ENDIF(OS_WINDOWS)
|
||||
|
||||
IF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
ADD_DEFINITIONS(-DPROJECT_BUILD_RELEASE)
|
||||
ENDIF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
|
||||
ADD_DEFINITIONS(-DPROJECT_VERSION_HUMAN="${PROJECT_VERSION_HUMAN}")
|
||||
|
||||
SET(STREAMER_SERVICE_NAME ${PROJECT_NAME_LOWERCASE})
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
|
||||
#CPACK
|
||||
IF(CPACK_SUPPORT)
|
||||
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_SUMMARY})
|
||||
SET(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
|
||||
# CPACK_DEBIAN_PACKAGE_DESCRIPTION CPACK_RPM_PACKAGE_SUMMARY
|
||||
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/COPYRIGHT")#CPACK_RPM_PACKAGE_DESCRIPTION
|
||||
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
|
||||
SET(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
|
||||
SET(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md")
|
||||
|
||||
SET(CPACK_PACKAGE_VENDOR "${PROJECT_COMPANYNAME}")#CPACK_RPM_PACKAGE_VENDOR
|
||||
SET(CPACK_PACKAGE_CONTACT "${PROJECT_MAINTAINER_NAME} <${PROJECT_MAINTAINER_MAIL}>")#CPACK_DEBIAN_PACKAGE_MAINTAINER
|
||||
|
||||
SET(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
||||
SET(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
||||
SET(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_SHORT})
|
||||
|
||||
SET(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_PATCH})#CPACK_DEBIAN_PACKAGE_VERSION CPACK_RPM_PACKAGE_VERSION
|
||||
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME_LOWERCASE})#CPACK_DEBIAN_PACKAGE_NAME CPACK_RPM_PACKAGE_NAME
|
||||
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${PLATFORM_ARCH_NAME}-${PROJECT_VERSION_GIT}")#out package name
|
||||
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
|
||||
SET(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME})
|
||||
SET(CPACK_PACKAGE_EXECUTABLES "${PROJECT_NAME_TITLE};${PROJECT_NAME}")
|
||||
MESSAGE(STATUS "CPACK_PACKAGE_FILE_NAME: ${CPACK_PACKAGE_FILE_NAME}")
|
||||
SET(CPACK_MONOLITHIC_INSTALL ON)
|
||||
|
||||
IF(OS_WINDOWS)
|
||||
ELSEIF(OS_MACOSX)
|
||||
ELSEIF(OS_LINUX)
|
||||
SET(CPACK_STRIP_FILES ON)
|
||||
# SET(UBUNTU_LP_BUG 300472)
|
||||
# SET(CPACK_STRIP_FILES "bin/${PROJECT_NAME}")
|
||||
# SET(CPACK_SOURCE_STRIP_FILES "")
|
||||
|
||||
SET(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${PROJECT_NAME_LOWERCASE}")
|
||||
CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME_LOWERCASE}/linux/postinst.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/scripts/postinst" @ONLY IMMEDIATE)
|
||||
FILE(COPY ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/scripts/postinst DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME_LOWERCASE}/linux/prerm.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/scripts/prerm" @ONLY IMMEDIATE)
|
||||
FILE(COPY ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/scripts/prerm DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
|
||||
# RPM
|
||||
# CPACK_RPM_PACKAGE_ARCHITECTURE CPACK_RPM_PACKAGE_LICENSE CPACK_RPM_PACKAGE_DESCRIPTION CPACK_RPM_SPEC_INSTALL_POST
|
||||
# SET(CPACK_PACKAGE_RELEASE 1)
|
||||
SET(CPACK_RPM_PACKAGE_LICENSE "GPL v3")
|
||||
SET(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
|
||||
# SET(CPACK_RPM_PACKAGE_REQUIRES "libc.so.6 >= 2.12, libstdc++.so.6 >= 6.0.13")
|
||||
SET(CPACK_RPM_PACKAGE_RELEASE 1)
|
||||
SET(CPACK_RPM_PACKAGE_GROUP "Development/video")
|
||||
SET(CPACK_RPM_PACKAGE_ARCHITECTURE ${PLATFORM_ARCH_NAME})
|
||||
SET(CPACK_RPM_PACKAGE_VERSION ${PROJECT_VERSION_SHORT})
|
||||
SET(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/postinst")
|
||||
SET(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/prerm")
|
||||
SET(CPACK_RPM_CHANGELOG_FILE ${PROJECT_CHANGELOG_FILE})
|
||||
# DEB
|
||||
IF(PLATFORM_ARCH_NAME STREQUAL x86_64)
|
||||
SET(PLATFORM_ARCH_NAME amd64)
|
||||
ENDIF(PLATFORM_ARCH_NAME STREQUAL x86_64)
|
||||
# SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
# CPACK_DEBIAN_PACKAGE_HOMEPAGE The URL of the web site for this package
|
||||
# SET(CPACK_DEBIAN_PACKAGE_DEBUG ON)
|
||||
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.12), libstdc++6 (>= 4.4.7)")
|
||||
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
||||
SET(CPACK_DEBIAN_PACKAGE_SECTION "video") #input our section
|
||||
SET(CPACK_DEBIAN_PACKAGE_RECOMMENDS "Unknown")
|
||||
SET(CPACK_DEBIAN_PACKAGE_SUGGESTS "Unknown")
|
||||
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${PLATFORM_ARCH_NAME})#i386
|
||||
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/postinst;${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/prerm")
|
||||
ELSEIF(OS_ANDROID)
|
||||
ENDIF(OS_WINDOWS)
|
||||
INCLUDE(CPack)
|
||||
ENDIF(CPACK_SUPPORT)
|
||||
|
||||
IF(DEVELOPER_GENERATE_DOCS)
|
||||
CREATE_DOCS(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
ENDIF(DEVELOPER_GENERATE_DOCS)
|
||||
|
||||
IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit)
|
||||
EXECUTE_PROCESS(COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_pre_commit_hook.sh)
|
||||
ENDIF(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit)
|
12
COPYRIGHT
Normal file
12
COPYRIGHT
Normal file
|
@ -0,0 +1,12 @@
|
|||
Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
9
CPPLINT.cfg
Normal file
9
CPPLINT.cfg
Normal file
|
@ -0,0 +1,9 @@
|
|||
# This is the toplevel CPPLINT.cfg file
|
||||
set noparent
|
||||
|
||||
linelength=120
|
||||
root=src
|
||||
|
||||
filter=-runtime/int
|
||||
filter=-build/include_order
|
||||
filter=-build/c++11
|
39
Dockerfile
Normal file
39
Dockerfile
Normal file
|
@ -0,0 +1,39 @@
|
|||
FROM debian:bullseye-slim
|
||||
|
||||
LABEL maintainer="Alexandr Topilski <support@fastogt.com>"
|
||||
|
||||
ENV USER fastocloud
|
||||
ENV APP_NAME fastocloud
|
||||
ENV PROJECT_DIR /usr/src/$APP_NAME
|
||||
RUN useradd -m -U -d /home/$USER $USER -s /bin/bash
|
||||
|
||||
COPY . $PROJECT_DIR
|
||||
|
||||
RUN set -ex; \
|
||||
BUILD_DEPS='ca-certificates git python3 python3-pip nano dbus'; \
|
||||
PREFIX=/usr/local; \
|
||||
apt-get update; \
|
||||
apt-get install -y $BUILD_DEPS --no-install-recommends; \
|
||||
# rm -rf /var/lib/apt/lists/*; \
|
||||
pip3 install setuptools; \
|
||||
PYFASTOGT_DIR=/usr/src/pyfastogt; \
|
||||
mkdir -p $PYFASTOGT_DIR && git clone https://gitlab.com/fastogt/pyfastogt $PYFASTOGT_DIR && cd $PYFASTOGT_DIR && python3 setup.py install; \
|
||||
cd $PROJECT_DIR/build && ./env/build_env.py --prefix=$PREFIX --docker; \
|
||||
cd $PROJECT_DIR/build && PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig python3 build.py release $PREFIX; \
|
||||
rm -rf $PYFASTOGT_DIR $PROJECT_DIR # && apt-get purge -y --auto-remove $BUILD_DEPS
|
||||
|
||||
COPY docker/$APP_NAME.conf /etc/
|
||||
RUN mkdir /var/run/$APP_NAME
|
||||
RUN chown $USER:$USER /var/run/$APP_NAME
|
||||
RUN chown $USER:$USER /var/lib/dbus/ # for unique machine-id
|
||||
#VOLUME /var/run/$APP_NAME
|
||||
|
||||
COPY docker/docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
USER $USER
|
||||
WORKDIR /home/$USER
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
EXPOSE 6317 8000 7000 6000
|
674
LICENSE
Normal file
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
137
README.md
Normal file
137
README.md
Normal file
|
@ -0,0 +1,137 @@
|
|||
### FastoCloud Media
|
||||
[![Join the chat at https://discord.com/invite/cnUXsws](https://img.shields.io/discord/584773460585086977?label=discord)](https://discord.gg/Fxbfx3d5dV)
|
||||
|
||||
#### [Technical details](https://fastogt.com/static/projects/all_presentations/media_server.pdf)
|
||||
|
||||
**FastoCloud Media** is a reliable server software solution for streaming video content of any type and complexity. It enables users to host live video broadcasts using IP/NDI/Analog cameras, provide on-demand video access, and seamlessly integrate video streaming into various projects such as intercom systems, tv streaming, ott, webinars, recording streams and many other. For managment **FastoCloud** nodes can be used:
|
||||
- [**UI**](https://gitlab.com/fastogt/wsfastocloud)
|
||||
- [**API**](https://fastogt.stoplight.io/docs/fastocloud-api/6dbac8c0c0a0f-fasto-cloud-community-pro-ml-versions)
|
||||
|
||||
Software can start as [**Linux**](https://fastocloud.com/downloads.html) service or in [**Docker**](https://hub.docker.com/repository/docker/fastogt/fastocloud).
|
||||
|
||||
Have 3 types of services:
|
||||
- [**[COM]**](https://gitlab.com/fastogt/fastocloud) Community version
|
||||
- [**[PRO]**](https://fastocloud.com/downloads.html) Professional version
|
||||
- [**[ML]**](https://fastocloud.com/downloads.html) Computer vision/AI/ML version
|
||||
|
||||
[About FastoCloud](https://github.com/fastogt/fastocloud_docs/wiki)
|
||||
===============
|
||||
### Features:
|
||||
* Cross-platform (Linux, MacOSX, FreeBSD, Raspbian/Armbian, Windows)
|
||||
* GPU/CPU Encode/Decode/Post Processing
|
||||
* Intel QuickSync
|
||||
* Nvidia NVENC
|
||||
* AMD
|
||||
* Restreaming
|
||||
* Stream/Server statistics
|
||||
* RTSP/RTMP/HLS/DASH and many other different input/output protocols
|
||||
* Firebase/Google/Azure cloud storages outputs **[PRO]**
|
||||
* WEBRTC input to any output **[PRO]** [Demo](http://fastowebrtc.com)
|
||||
* Any inputs to WEBRTC output **[PRO]**
|
||||
* WebRTC-HTTP ingestion protocol (WHIP) **[PRO]**
|
||||
* WebRTC-HTTP egress protocol (WHEP) **[PRO]**
|
||||
* Probe stream **[PRO]**
|
||||
* [REST API](https://fastogt.stoplight.io/docs/fastocloud-api/6dbac8c0c0a0f-fasto-cloud-community-pro-ml-versions)
|
||||
* Adaptive hls streams
|
||||
* Load balancing **[PRO]**
|
||||
* Embedded urls
|
||||
* HLS pull/push
|
||||
* Audio to text conversions **[ML]**
|
||||
* AD insertion **[PRO]**
|
||||
* Logo overlay
|
||||
* Concat videos **[PRO]**
|
||||
* NDI Input/Output **[PRO]**
|
||||
* Merging videos (Green screen, Webpage etc) **[PRO]**
|
||||
* Video effects
|
||||
* Relays audio/video part of stream
|
||||
* Timeshifts
|
||||
* Catchups
|
||||
* Playlists
|
||||
* Restream/Transcode from online streaming services like YouTube, Twitch, etc
|
||||
* Mosaic
|
||||
* CDN internal nodes **[PRO]**
|
||||
* Physical Inputs (IP Camera, DVB-T/C/S, ATSC, USB, Screen, ISDB-T and DTMB)
|
||||
* Presets
|
||||
* Changing inputs in realtime **[PRO]**
|
||||
* Scanning folders for media content **[PRO]**
|
||||
* Channels on demand
|
||||
* HTTP Live Streaming (HLS) server-side support
|
||||
* Deep learning video analysis **[ML]**
|
||||
* Supported deep learning frameworks: **[ML]**
|
||||
* Tensorflow
|
||||
* NCSDK
|
||||
* Caffe
|
||||
* ML Hardware: **[ML]**
|
||||
* Intel Movidius Neural Compute Stick
|
||||
* NVIDIA Jetson, Tesla T4
|
||||
* ML notifications (Face detection, YOLO, Plate detection, etc) **[ML]**
|
||||
* NVIDIA Maxine/Deepstream **[ML]**
|
||||
* Blacklist IP
|
||||
* Tokens protected urls
|
||||
* DRM **[PRO]**
|
||||
* [Amazon Kinesis Video Streams integration](https://aws.amazon.com/kinesis/video-streams)
|
||||
* [Admin panel](https://gitlab.com/fastogt/wsfastocloud)
|
||||
* [Docker Image](https://hub.docker.com/r/fastogt/fastocloud)
|
||||
|
||||
### Use cases:
|
||||
* Broadcast media content
|
||||
* Video conferences
|
||||
* Monetize Media content, own branded apps
|
||||
* YouTube remove AD
|
||||
* Insert your logo to the stream, watermark
|
||||
* Record/Timeshift video
|
||||
* Play own playlist
|
||||
* Mosaic, view many streams in same time on single window
|
||||
* Video effects in streams or files
|
||||
* Insert AD into stream
|
||||
* Subtitles to text conversions and vise versa
|
||||
* Streams find bot, with quality analysis, test m3u file streams
|
||||
* Record and broadcast video from cameras
|
||||
* Detect objects in real-time video and send email/push notifications
|
||||
* Objects classification, open doors, time tracking, lock/unlock devices
|
||||
* Fire/Smoke detection with notifications
|
||||
* Plate/Human/Face detection
|
||||
* CCTV Monitoring service
|
||||
* Screen recording
|
||||
* Personal branded video apps
|
||||
* Own video streaming platform on web, tablet and TV
|
||||
|
||||
Visit our site: [fastocloud.com](https://fastocloud.com)
|
||||
|
||||
[Admin panel](https://gitlab.com/fastogt/wsfastocloud)
|
||||
==========
|
||||
### Dashboard page:
|
||||
![](https://gitlab.com/fastogt/wsfastocloud/raw/main/docs/images/fastocloud_one_web.png)
|
||||
![](https://gitlab.com/fastogt/wsfastocloud/raw/main/docs/images/fastocloud_one_web_store_live.png)
|
||||
![](https://gitlab.com/fastogt/wsfastocloud/raw/main/docs/images/fastocloud_one_web_store_vod.png)
|
||||
|
||||
[Demo Admin panel](https://ws.fastocloud.com) **Note: Press connect**
|
||||
|
||||
Contribute
|
||||
==========
|
||||
Contributions are always welcome! Just try to follow our coding style: [FastoGT Coding Style](https://github.com/fastogt/fastonosql/wiki/Coding-Style)
|
||||
|
||||
Build
|
||||
========
|
||||
Build documentation: [Build FastoCloud](https://github.com/fastogt/fastocloud_env/wiki/Build-service-from-sources)
|
||||
|
||||
Install
|
||||
========
|
||||
Install documentation: [Install FastoCloud](https://github.com/fastogt/fastocloud_env/wiki/Install-package)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Copyright (C) 2014-2024 [FastoGT](https://fastogt.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 3 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
38
build/build.py
Executable file
38
build/build.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from pyfastogt import build_utils, system_info
|
||||
|
||||
|
||||
class BuildRequest(build_utils.BuildRequest):
|
||||
def __init__(self, platform, arch_name, dir_path, prefix_path):
|
||||
build_utils.BuildRequest.__init__(self, platform, arch_name, dir_path, prefix_path)
|
||||
|
||||
def build(self, build_type):
|
||||
cmake_flags = []
|
||||
self._build_via_cmake_double(cmake_flags, build_type)
|
||||
|
||||
|
||||
def print_usage():
|
||||
print("Usage:\n"
|
||||
"[required] argv[1] build type(release/debug)\n"
|
||||
"[optional] argv[2] prefix\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
argc = len(sys.argv)
|
||||
|
||||
if argc > 1:
|
||||
build_type = sys.argv[1]
|
||||
else:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
prefix = '/usr/local'
|
||||
if argc > 2:
|
||||
prefix = sys.argv[2]
|
||||
|
||||
host_os = system_info.get_os()
|
||||
arch_host_os = system_info.get_arch_name()
|
||||
|
||||
request = BuildRequest(host_os, arch_host_os, 'build_' + host_os, prefix)
|
||||
request.build(build_type)
|
1
build/env
Submodule
1
build/env
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit ce152395c8e6eeaf6e3a09f0529cea8b6057b00c
|
52
build/fast_build.sh
Normal file
52
build/fast_build.sh
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# exports
|
||||
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
|
||||
|
||||
# variables
|
||||
USER=fastocloud
|
||||
|
||||
# update system
|
||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||
if [ -n "$(command -v yum)" ]; then
|
||||
yum update -y
|
||||
yum install -y git python3-setuptools python3-pip
|
||||
elif [ -n "$(command -v apt-get)" ]; then
|
||||
apt-get update
|
||||
apt-get install -y git python3-setuptools python3-pip --no-install-recommends
|
||||
else
|
||||
:
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
:
|
||||
elif [[ "$OSTYPE" == "cygwin" ]]; then
|
||||
:
|
||||
elif [[ "$OSTYPE" == "msys" ]]; then
|
||||
:
|
||||
elif [[ "$OSTYPE" == "win32" ]]; then
|
||||
:
|
||||
elif [[ "$OSTYPE" == "freebsd"* ]]; then
|
||||
:
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
# sync modules
|
||||
git submodule update --init --recursive
|
||||
|
||||
# install pyfastogt
|
||||
git clone https://gitlab.com/fastogt/pyfastogt
|
||||
cd pyfastogt
|
||||
python3 setup.py install
|
||||
cd ../
|
||||
rm -rf pyfastogt
|
||||
|
||||
# build env for service
|
||||
./env/build_env.py
|
||||
|
||||
# build service
|
||||
./build.py release
|
||||
|
||||
# add user
|
||||
useradd -m -U -d /home/$USER $USER -s /bin/bash
|
92
build/nginx/default
Normal file
92
build/nginx/default
Normal file
|
@ -0,0 +1,92 @@
|
|||
##
|
||||
# You should look at the following URL's in order to grasp a solid understanding
|
||||
# of Nginx configuration files in order to fully unleash the power of Nginx.
|
||||
# https://www.nginx.com/resources/wiki/start/
|
||||
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
|
||||
# https://wiki.debian.org/Nginx/DirectoryStructure
|
||||
#
|
||||
# In most cases, administrators will remove this file from sites-enabled/ and
|
||||
# leave it as reference inside of sites-available where it will continue to be
|
||||
# updated by the nginx packaging team.
|
||||
#
|
||||
# This file will automatically load configuration files provided by other
|
||||
# applications, such as Drupal or Wordpress. These applications will be made
|
||||
# available underneath a path with that package name, such as /drupal8.
|
||||
#
|
||||
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
|
||||
##
|
||||
|
||||
# Default server configuration
|
||||
#
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
# SSL configuration
|
||||
#
|
||||
# listen 443 ssl default_server;
|
||||
# listen [::]:443 ssl default_server;
|
||||
#
|
||||
# Note: You should disable gzip for SSL traffic.
|
||||
# See: https://bugs.debian.org/773332
|
||||
#
|
||||
# Read up on ssl_ciphers to ensure a secure configuration.
|
||||
# See: https://bugs.debian.org/765782
|
||||
#
|
||||
# Self signed certs generated by the ssl-cert package
|
||||
# Don't use them in a production server!
|
||||
#
|
||||
# include snippets/snakeoil.conf;
|
||||
|
||||
root /home/fastocloud/streamer;
|
||||
|
||||
# Add index.php to the list if you are using PHP
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
# First attempt to serve request as file, then
|
||||
# as directory, then fall back to displaying a 404.
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# pass PHP scripts to FastCGI server
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# include snippets/fastcgi-php.conf;
|
||||
#
|
||||
# # With php-fpm (or other unix sockets):
|
||||
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
|
||||
# # With php-cgi (or other tcp sockets):
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# Virtual Host configuration for example.com
|
||||
#
|
||||
# You can move that to a different file under sites-available/ and symlink that
|
||||
# to sites-enabled/ to enable it.
|
||||
#
|
||||
#server {
|
||||
# listen 80;
|
||||
# listen [::]:80;
|
||||
#
|
||||
# server_name example.com;
|
||||
#
|
||||
# root /var/www/example.com;
|
||||
# index index.html;
|
||||
#
|
||||
# location / {
|
||||
# try_files $uri $uri/ =404;
|
||||
# }
|
||||
#}
|
||||
|
8
build/nginx_hls_debian.sh
Normal file
8
build/nginx_hls_debian.sh
Normal file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# update system
|
||||
apt-get update
|
||||
apt-get install -y nginx
|
||||
cp env/nginx/fastocloud /etc/nginx/sites-available/fastocloud
|
||||
systemctl restart nginx
|
1
cmake
Submodule
1
cmake
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b13774ddc003e7a5d6a0116b594a9dbe7313851a
|
22
docker/docker-entrypoint.sh
Normal file
22
docker/docker-entrypoint.sh
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
#set -e
|
||||
|
||||
regenerate_dbus_machine_id() {
|
||||
rm -f /var/lib/dbus/machine-id
|
||||
rm -f /etc/machine-id
|
||||
dbus-uuidgen --ensure
|
||||
}
|
||||
|
||||
CONTAINER_ALREADY_STARTED="CONTAINER_ALREADY_STARTED_PLACEHOLDER"
|
||||
if [ ! -e $CONTAINER_ALREADY_STARTED ]; then
|
||||
touch $CONTAINER_ALREADY_STARTED
|
||||
regenerate_dbus_machine_id
|
||||
else
|
||||
echo "machine-id already was regenerated"
|
||||
fi
|
||||
|
||||
if [ "${1#-}" != "$1" ]; then
|
||||
set -- fastocloud "$@"
|
||||
fi
|
||||
|
||||
exec "$@"
|
21
docker/fastocloud.conf
Normal file
21
docker/fastocloud.conf
Normal file
|
@ -0,0 +1,21 @@
|
|||
[settings]
|
||||
log_path=~/fastocloud.log
|
||||
log_level=INFO
|
||||
host=0.0.0.0:6317
|
||||
alias=0.0.0.0
|
||||
|
||||
hls_host=http://0.0.0.0:8000
|
||||
vods_host=http://0.0.0.0:7000
|
||||
cods_host=http://0.0.0.0:6000
|
||||
|
||||
hls_dir=~/streamer/hls
|
||||
vods_dir=~/streamer/vods
|
||||
cods_dir=~/streamer/cods
|
||||
timeshifts_dir=~/streamer/timeshifts
|
||||
feedback_dir=~/streamer/feedback
|
||||
proxy_dir=~/streamer/proxy
|
||||
data_dir=~/streamer/data
|
||||
|
||||
cods_ttl=600
|
||||
pyfastostream_path=/usr/local/bin/pyfastostream
|
||||
files_ttl=604800
|
2304
docs/Doxyfile.in
Normal file
2304
docs/Doxyfile.in
Normal file
File diff suppressed because it is too large
Load diff
5
install/fastocloud/linux/postinst.in
Normal file
5
install/fastocloud/linux/postinst.in
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
ln -sf @CPACK_PACKAGING_INSTALL_PREFIX@/@TARGET_INSTALL_DESTINATION@/@STREAMER_SERVICE_NAME@ @EXECUTABLE_PATH@
|
||||
chmod +x @EXECUTABLE_PATH@
|
||||
|
6
install/fastocloud/linux/prerm.in
Normal file
6
install/fastocloud/linux/prerm.in
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if test -e @EXECUTABLE_PATH@ ; then
|
||||
rm @EXECUTABLE_PATH@
|
||||
fi
|
21
install/fastocloud/service/service.conf.in
Normal file
21
install/fastocloud/service/service.conf.in
Normal file
|
@ -0,0 +1,21 @@
|
|||
[settings]
|
||||
log_path=~/@STREAMER_SERVICE_NAME@.log
|
||||
log_level=INFO
|
||||
host=@STREAMER_SERVICE_HOST@
|
||||
alias=@STREAMER_SERVICE_ALIAS@
|
||||
|
||||
hls_host=@STREAMER_SERVICE_HLS_HOST@
|
||||
vods_host=@STREAMER_SERVICE_VODS_HOST@
|
||||
cods_host=@STREAMER_SERVICE_CODS_HOST@
|
||||
|
||||
hls_dir=@STREAMER_SERVICE_HLS_DIR@
|
||||
vods_dir=@STREAMER_SERVICE_VODS_DIR@
|
||||
cods_dir=@STREAMER_SERVICE_CODS_DIR@
|
||||
timeshifts_dir=@STREAMER_SERVICE_TIMESHIFTS_DIR@
|
||||
feedback_dir=@STREAMER_SERVICE_FEEDBACK_DIR@
|
||||
proxy_dir=@STREAMER_SERVICE_PROXY_DIR@
|
||||
data_dir=@STREAMER_SERVICE_DATA_DIR@
|
||||
|
||||
cods_ttl=@STREAMER_SERVICE_CODS_TTL@
|
||||
pyfastostream_path=@STREAMER_SERVICE_PYFASTOSTREAM_PATH@
|
||||
files_ttl=@STREAMER_SERVICE_FILES_TTL@
|
11
scripts/create_pre_commit_hook.sh
Normal file
11
scripts/create_pre_commit_hook.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
HOOKS="pre-commit"
|
||||
ROOT_DIR=$(git rev-parse --show-toplevel)
|
||||
|
||||
for hook in $HOOKS; do
|
||||
if [ ! -f $ROOT_DIR/.git/hooks/$hook ]; then
|
||||
ln -s $ROOT_DIR/scripts/$hook $ROOT_DIR/.git/hooks/$hook
|
||||
fi
|
||||
done
|
||||
|
15
scripts/pre-commit
Normal file
15
scripts/pre-commit
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
TOTAL_ERRORS=0
|
||||
|
||||
for file in `git diff-index --name-only --diff-filter=d HEAD`; do
|
||||
case "${file#*.}" in
|
||||
cpp|c|h)
|
||||
clang-format -i "${file}"
|
||||
cpplint "${file}"
|
||||
TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
exit $TOTAL_ERRORS
|
189
src/CMakeLists.txt
Normal file
189
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,189 @@
|
|||
OPTION(MACHINE_LEARNING "ML plugins" OFF)
|
||||
OPTION(AMAZON_KINESIS "AWS KVS plugins" OFF)
|
||||
|
||||
MESSAGE(STATUS "MACHINE_LEARNING: ${MACHINE_LEARNING}")
|
||||
MESSAGE(STATUS "AMAZON_KINESIS: ${AMAZON_KINESIS}")
|
||||
|
||||
# projects globals names
|
||||
SET(STREAMER_NAME streamer CACHE STRING "Stream process name")
|
||||
SET(STREAMER_COMMON ${STREAMER_NAME}_common)
|
||||
|
||||
SET(SOURCE_ROOT ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
# for sources only absolute paths
|
||||
SET(BASE_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/base/types.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/utils.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_config.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_config_parse.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/constants.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/platform_macros.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/gst_constants.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/config_fields.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/channel_stats.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_struct.h
|
||||
)
|
||||
|
||||
SET(BASE_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/base/types.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/utils.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_config.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_config_parse.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/constants.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/gst_constants.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/config_fields.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/channel_stats.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/stream_struct.cpp
|
||||
)
|
||||
|
||||
SET(STREAM_COMMANDS_INFO_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_factory.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/stop_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/restart_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/changed_sources_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/statistic_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/details/channel_stats_info.h
|
||||
)
|
||||
SET(STREAM_COMMANDS_INFO_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_factory.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/stop_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/restart_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/changed_sources_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/statistic_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/stream_commands/commands_info/details/channel_stats_info.cpp
|
||||
)
|
||||
|
||||
SET(LINK_GENERATOR_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/base/link_generator/ilink_generator.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/link_generator/pyfastostream.h
|
||||
)
|
||||
SET(LINK_GENERATOR_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/base/link_generator/ilink_generator.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/link_generator/pyfastostream.cpp
|
||||
)
|
||||
|
||||
FIND_PACKAGE(Common REQUIRED)
|
||||
FIND_PACKAGE(FastoTvCPP REQUIRED)
|
||||
FIND_PACKAGE(JSON-C REQUIRED)
|
||||
|
||||
# options
|
||||
IF(MACHINE_LEARNING)
|
||||
FIND_PACKAGE(FastoML REQUIRED)
|
||||
IF (NOT FASTOML_FOUND)
|
||||
MESSAGE(SEND_ERROR "Please install ${PROJECT_COMPANYNAME} gstreamer machine learning framework.")
|
||||
ENDIF(NOT FASTOML_FOUND)
|
||||
ADD_DEFINITIONS(-DMACHINE_LEARNING)
|
||||
|
||||
SET(BASE_HEADERS ${BASE_HEADERS}
|
||||
${CMAKE_SOURCE_DIR}/src/base/machine_learning/deep_learning.h
|
||||
${CMAKE_SOURCE_DIR}/src/base/machine_learning/deep_learning_overlay.h
|
||||
)
|
||||
SET(BASE_SOURCES ${BASE_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/base/machine_learning/deep_learning.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/base/machine_learning/deep_learning_overlay.cpp
|
||||
)
|
||||
ENDIF(MACHINE_LEARNING)
|
||||
|
||||
IF(AMAZON_KINESIS)
|
||||
ADD_DEFINITIONS(-DAMAZON_KINESIS)
|
||||
SET(BASE_HEADERS ${BASE_HEADERS}
|
||||
${CMAKE_SOURCE_DIR}/src/base/amazon_kinesis/amazon_kinesis.h
|
||||
)
|
||||
SET(BASE_SOURCES ${BASE_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/base/amazon_kinesis/amazon_kinesis.cpp
|
||||
)
|
||||
ENDIF(AMAZON_KINESIS)
|
||||
|
||||
IF(OS_WINDOWS)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES)
|
||||
ELSEIF(OS_LINUX)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES)
|
||||
ELSEIF(OS_POSIX)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES)
|
||||
ENDIF(OS_WINDOWS)
|
||||
|
||||
IF(USE_PTHREAD)
|
||||
IF(NOT OS_ANDROID)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} pthread)
|
||||
ENDIF(NOT OS_ANDROID)
|
||||
ENDIF(USE_PTHREAD)
|
||||
|
||||
ADD_SUBDIRECTORY(utils)
|
||||
|
||||
# common iptv lib
|
||||
|
||||
SET(STREAMER_COMMON_SOURCES
|
||||
${STREAM_COMMANDS_INFO_HEADERS} ${STREAM_COMMANDS_INFO_SOURCES}
|
||||
${BASE_HEADERS} ${BASE_SOURCES}
|
||||
${LINK_GENERATOR_HEADERS} ${LINK_GENERATOR_SOURCES}
|
||||
)
|
||||
SET(STREAMER_COMMON_LIBRARIES
|
||||
${STREAMER_COMMON_LIBRARIES}
|
||||
${JSONC_LIBRARIES} utils
|
||||
${COMMON_BASE_LIBRARY}
|
||||
${FASTOTV_CPP_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
)
|
||||
SET(PRIVATE_INCLUDE_DIRECTORIES_COMMON
|
||||
${PRIVATE_INCLUDE_DIRECTORIES_COMMON}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${FASTOTV_CPP_INCLUDE_DIRS}
|
||||
${COMMON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
ADD_LIBRARY(${STREAMER_COMMON} STATIC ${STREAMER_COMMON_SOURCES})
|
||||
TARGET_INCLUDE_DIRECTORIES(${STREAMER_COMMON} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_COMMON})
|
||||
TARGET_LINK_LIBRARIES(${STREAMER_COMMON} ${STREAMER_COMMON_LIBRARIES})
|
||||
|
||||
SET(STREAMER_CORE ${STREAMER_NAME}_core)
|
||||
|
||||
IF(BUILD_SERVER)
|
||||
ADD_SUBDIRECTORY(server)
|
||||
ENDIF(BUILD_SERVER)
|
||||
IF(BUILD_STREAM)
|
||||
ADD_SUBDIRECTORY(stream)
|
||||
ENDIF(BUILD_STREAM)
|
||||
|
||||
INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION . COMPONENT LICENSE RENAME LICENSE OPTIONAL)
|
||||
INSTALL(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION . COMPONENT LICENSE RENAME COPYRIGHT OPTIONAL)
|
||||
INSTALL(FILES ${PROJECT_CHANGELOG_FILE} DESTINATION . COMPONENT LICENSE RENAME CHANGELOG OPTIONAL)
|
||||
|
||||
IF (DEVELOPER_CHECK_STYLE)
|
||||
SET(CHECK_SOURCES ${STREAMER_COMMON_SOURCES})
|
||||
REGISTER_CHECK_STYLE_TARGET(check_style_${STREAMER_COMMON} "${CHECK_SOURCES}")
|
||||
REGISTER_CHECK_INCLUDES_TARGET(${STREAMER_COMMON})
|
||||
ENDIF(DEVELOPER_CHECK_STYLE)
|
||||
|
||||
IF(DEVELOPER_ENABLE_TESTS)
|
||||
FIND_PACKAGE(GTest REQUIRED)
|
||||
|
||||
## Unit tests
|
||||
SET(PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS
|
||||
${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
SET(UNIT_TESTS_LIBS
|
||||
${GTEST_BOTH_LIBRARIES}
|
||||
${STREAMER_COMMON}
|
||||
${PLATFORM_LIBRARIES})
|
||||
SET(UNIT_TESTS unit_tests)
|
||||
ADD_EXECUTABLE(${UNIT_TESTS}
|
||||
${CMAKE_SOURCE_DIR}/tests/unit_test_output_uri.cpp
|
||||
${CMAKE_SOURCE_DIR}/tests/unit_test_input_uri.cpp
|
||||
${CMAKE_SOURCE_DIR}/tests/unit_test_types.cpp
|
||||
)
|
||||
TARGET_INCLUDE_DIRECTORIES(${UNIT_TESTS} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS} ${JSONC_INCLUDE_DIRS})
|
||||
TARGET_LINK_LIBRARIES(${UNIT_TESTS} ${UNIT_TESTS_LIBS})
|
||||
ADD_TEST_TARGET(${UNIT_TESTS})
|
||||
SET_PROPERTY(TARGET ${UNIT_TESTS} PROPERTY FOLDER "Unit tests")
|
||||
ENDIF(DEVELOPER_ENABLE_TESTS)
|
99
src/base/amazon_kinesis/amazon_kinesis.cpp
Normal file
99
src/base/amazon_kinesis/amazon_kinesis.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/amazon_kinesis/amazon_kinesis.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#define AMAZON_KINESIS_STREAM_NAME_FIELD "stream_name"
|
||||
#define AMAZON_KINESIS_SECRET_KEY_FIELD "secret_key"
|
||||
#define AMAZON_KINESIS_ACCESS_KEY_FIELD "access_key"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace amazon_kinesis {
|
||||
|
||||
AmazonKinesis::AmazonKinesis() : AmazonKinesis(std::string(), std::string(), std::string()) {}
|
||||
|
||||
AmazonKinesis::AmazonKinesis(const std::string& stream_name,
|
||||
const std::string& secret_key,
|
||||
const std::string& access_key)
|
||||
: stream_name_(stream_name), secret_key_(secret_key), access_key_(access_key) {}
|
||||
|
||||
bool AmazonKinesis::Equals(const AmazonKinesis& aws) const {
|
||||
return aws.stream_name_ == stream_name_ && aws.secret_key_ == secret_key_ && aws.access_key_ == access_key_;
|
||||
}
|
||||
|
||||
common::Optional<AmazonKinesis> AmazonKinesis::MakeAmazonKinesis(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<AmazonKinesis>();
|
||||
}
|
||||
|
||||
AmazonKinesis res;
|
||||
common::Value* stream_name_field = hash->Find(AMAZON_KINESIS_STREAM_NAME_FIELD);
|
||||
std::string stream_name;
|
||||
if (stream_name_field && stream_name_field->GetAsBasicString(&stream_name)) {
|
||||
res.stream_name_ = stream_name;
|
||||
}
|
||||
|
||||
common::Value* secret_key_field = hash->Find(AMAZON_KINESIS_SECRET_KEY_FIELD);
|
||||
std::string secret_key;
|
||||
if (secret_key_field && secret_key_field->GetAsBasicString(&secret_key)) {
|
||||
res.secret_key_ = secret_key;
|
||||
}
|
||||
|
||||
common::Value* access_key_field = hash->Find(AMAZON_KINESIS_ACCESS_KEY_FIELD);
|
||||
std::string access_key;
|
||||
if (access_key_field && access_key_field->GetAsBasicString(&access_key)) {
|
||||
res.access_key_ = access_key;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error AmazonKinesis::DoDeSerialize(json_object* serialized) {
|
||||
AmazonKinesis res;
|
||||
json_object* jstream_name = nullptr;
|
||||
json_bool jstream_name_exists =
|
||||
json_object_object_get_ex(serialized, AMAZON_KINESIS_STREAM_NAME_FIELD, &jstream_name);
|
||||
if (jstream_name_exists) {
|
||||
res.stream_name_ = json_object_get_string(jstream_name);
|
||||
}
|
||||
|
||||
json_object* jsecret_key = nullptr;
|
||||
json_bool jsecret_key_exists = json_object_object_get_ex(serialized, AMAZON_KINESIS_SECRET_KEY_FIELD, &jsecret_key);
|
||||
if (jsecret_key_exists) {
|
||||
res.secret_key_ = json_object_get_string(jsecret_key);
|
||||
}
|
||||
|
||||
json_object* jaccess_key = nullptr;
|
||||
json_bool jaccess_key_exists = json_object_object_get_ex(serialized, AMAZON_KINESIS_ACCESS_KEY_FIELD, &jaccess_key);
|
||||
if (jaccess_key_exists) {
|
||||
res.access_key_ = json_object_get_string(jaccess_key);
|
||||
}
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error AmazonKinesis::SerializeFields(json_object* out) const {
|
||||
json_object_object_add(out, AMAZON_KINESIS_STREAM_NAME_FIELD, json_object_new_string(stream_name_.c_str()));
|
||||
json_object_object_add(out, AMAZON_KINESIS_SECRET_KEY_FIELD, json_object_new_string(secret_key_.c_str()));
|
||||
json_object_object_add(out, AMAZON_KINESIS_ACCESS_KEY_FIELD, json_object_new_string(access_key_.c_str()));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace amazon_kinesis
|
||||
} // namespace fastocloud
|
45
src/base/amazon_kinesis/amazon_kinesis.h
Normal file
45
src/base/amazon_kinesis/amazon_kinesis.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace amazon_kinesis {
|
||||
|
||||
class AmazonKinesis : public common::serializer::JsonSerializer<AmazonKinesis> {
|
||||
public:
|
||||
AmazonKinesis();
|
||||
AmazonKinesis(const std::string& stream_name, const std::string& secret_key, const std::string& access_key);
|
||||
|
||||
bool Equals(const AmazonKinesis& aws) const;
|
||||
|
||||
static common::Optional<AmazonKinesis> MakeAmazonKinesis(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
std::string stream_name_;
|
||||
std::string secret_key_;
|
||||
std::string access_key_;
|
||||
};
|
||||
|
||||
} // namespace amazon_kinesis
|
||||
} // namespace fastocloud
|
92
src/base/channel_stats.cpp
Normal file
92
src/base/channel_stats.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
|
||||
#include <common/time.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
ChannelStats::ChannelStats() : ChannelStats(0) {}
|
||||
|
||||
ChannelStats::ChannelStats(fastotv::channel_id_t cid)
|
||||
: id_(cid),
|
||||
last_update_time_(0),
|
||||
total_bytes_(0),
|
||||
prev_total_bytes_(0),
|
||||
bytes_per_second_(0),
|
||||
desire_bytes_per_second_() {}
|
||||
|
||||
fastotv::channel_id_t ChannelStats::GetID() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
fastotv::timestamp_t ChannelStats::GetLastUpdateTime() const {
|
||||
return last_update_time_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetLastUpdateTime(fastotv::timestamp_t t) {
|
||||
last_update_time_ = t;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetTotalBytes() const {
|
||||
return total_bytes_;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetPrevTotalBytes() const {
|
||||
return prev_total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetPrevTotalBytes(size_t bytes) {
|
||||
prev_total_bytes_ = bytes;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetDiffTotalBytes() const {
|
||||
return total_bytes_ - prev_total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::UpdateBps(size_t sec) {
|
||||
if (!sec) {
|
||||
return;
|
||||
}
|
||||
|
||||
bytes_per_second_ = GetDiffTotalBytes() / sec;
|
||||
}
|
||||
|
||||
size_t ChannelStats::GetBps() const {
|
||||
return bytes_per_second_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetBps(size_t bps) {
|
||||
bytes_per_second_ = bps;
|
||||
}
|
||||
|
||||
void ChannelStats::UpdateCheckPoint() {
|
||||
prev_total_bytes_ = total_bytes_;
|
||||
}
|
||||
|
||||
void ChannelStats::SetTotalBytes(size_t bytes) {
|
||||
total_bytes_ = bytes;
|
||||
last_update_time_ = common::time::current_utc_mstime();
|
||||
}
|
||||
|
||||
void ChannelStats::SetDesireBytesPerSecond(const common::media::DesireBytesPerSec& bps) {
|
||||
desire_bytes_per_second_ = bps;
|
||||
}
|
||||
|
||||
common::media::DesireBytesPerSec ChannelStats::GetDesireBytesPerSecond() const {
|
||||
return desire_bytes_per_second_;
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
61
src/base/channel_stats.h
Normal file
61
src/base/channel_stats.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/media/bandwidth_estimation.h>
|
||||
|
||||
#include <fastotv/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
class ChannelStats { // only compile time size fields
|
||||
public:
|
||||
ChannelStats();
|
||||
explicit ChannelStats(fastotv::channel_id_t cid);
|
||||
|
||||
fastotv::channel_id_t GetID() const;
|
||||
|
||||
fastotv::timestamp_t GetLastUpdateTime() const;
|
||||
void SetLastUpdateTime(fastotv::timestamp_t t);
|
||||
|
||||
size_t GetTotalBytes() const;
|
||||
void SetTotalBytes(size_t bytes);
|
||||
|
||||
size_t GetPrevTotalBytes() const;
|
||||
void SetPrevTotalBytes(size_t bytes);
|
||||
|
||||
size_t GetDiffTotalBytes() const;
|
||||
|
||||
void UpdateBps(size_t sec);
|
||||
size_t GetBps() const;
|
||||
void SetBps(size_t bps);
|
||||
|
||||
void UpdateCheckPoint();
|
||||
|
||||
void SetDesireBytesPerSecond(const common::media::DesireBytesPerSec& bps);
|
||||
common::media::DesireBytesPerSec GetDesireBytesPerSecond() const;
|
||||
|
||||
private:
|
||||
fastotv::channel_id_t id_;
|
||||
|
||||
fastotv::timestamp_t last_update_time_; // up_time
|
||||
size_t total_bytes_; // received bytes
|
||||
size_t prev_total_bytes_; // checkpoint received bytes
|
||||
size_t bytes_per_second_; // bps
|
||||
|
||||
common::media::DesireBytesPerSec desire_bytes_per_second_;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
15
src/base/config_fields.cpp
Normal file
15
src/base/config_fields.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/config_fields.h"
|
65
src/base/config_fields.h
Normal file
65
src/base/config_fields.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define FEEDBACK_DIR_FIELD "feedback_directory" // required
|
||||
#define DATA_DIR_FIELD "data_directory"
|
||||
#define LOG_LEVEL_FIELD "log_level"
|
||||
#define ID_FIELD "id" // required
|
||||
#define TYPE_FIELD "type" // required
|
||||
#define PYFASTOSTREAM_PATH_FIELD "pyfastostream_path"
|
||||
#define AUTO_EXIT_TIME_FIELD "auto_exit_time"
|
||||
|
||||
#define INPUT_FIELD "input" // required
|
||||
#define OUTPUT_FIELD "output"
|
||||
#define HAVE_VIDEO_FIELD "have_video"
|
||||
#define HAVE_AUDIO_FIELD "have_audio"
|
||||
#define HAVE_SUBTITLE_FIELD "have_subtitle"
|
||||
#define DEINTERLACE_FIELD "deinterlace"
|
||||
#define FRAME_RATE_FIELD "frame_rate"
|
||||
#define AUDIO_CHANNELS_FIELD "audio_channels"
|
||||
#define VOLUME_FIELD "volume"
|
||||
#define VIDEO_PARSER_FIELD "video_parser"
|
||||
#define AUDIO_PARSER_FIELD "audio_parser"
|
||||
#define VIDEO_CODEC_FIELD "video_codec"
|
||||
#define AUDIO_CODEC_FIELD "audio_codec"
|
||||
#define AUDIO_SELECT_FIELD "audio_select"
|
||||
#define TIMESHIFT_DIR_FIELD "timeshift_dir" // requeired in timeshift mode
|
||||
#define TIMESHIFT_CHUNK_LIFE_TIME_FIELD "timeshift_chunk_life_time"
|
||||
#define TIMESHIFT_DELAY_FIELD "timeshift_delay"
|
||||
#define TIMESHIFT_CHUNK_DURATION_FIELD "timeshift_chunk_duration"
|
||||
#define CLEANUP_TS_FIELD "cleanup_ts"
|
||||
#define LOGO_FIELD "logo"
|
||||
#define RSVG_LOGO_FIELD "rsvg_logo"
|
||||
#define LOOP_FIELD "loop"
|
||||
#define RESTART_ATTEMPTS_FIELD "restart_attempts"
|
||||
#define DELAY_TIME_FIELD "delay_time"
|
||||
#define SIZE_FIELD "size"
|
||||
#define VIDEO_BIT_RATE_FIELD "video_bitrate"
|
||||
#define AUDIO_BIT_RATE_FIELD "audio_bitrate"
|
||||
#define ASPECT_RATIO_FIELD "aspect_ratio"
|
||||
#define RELAY_AUDIO_FIELD "relay_audio"
|
||||
#define RELAY_VIDEO_FIELD "relay_video"
|
||||
|
||||
#define DECKLINK_VIDEO_MODE_FIELD "decklink_video_mode"
|
||||
|
||||
#if defined(MACHINE_LEARNING)
|
||||
#define DEEP_LEARNING_FIELD "deep_learning"
|
||||
#define DEEP_LEARNING_OVERLAY_FIELD "deep_learning_overlay"
|
||||
#endif
|
||||
|
||||
#if defined(AMAZON_KINESIS)
|
||||
#define AMAZON_KINESIS_FIELD "amazon_kinesis"
|
||||
#endif
|
15
src/base/constants.cpp
Normal file
15
src/base/constants.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/constants.h"
|
33
src/base/constants.h
Normal file
33
src/base/constants.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#define DEFAULT_VOLUME 1.0
|
||||
#define DEFAULT_DECKLINK_VIDEO_MODE 1
|
||||
|
||||
#define DEFAULT_TIMESHIFT_CHUNK_DURATION 120
|
||||
#define DEFAULT_CHUNK_LIFE_TIME 12 * 3600
|
||||
|
||||
#define DEFAULT_LOOP false
|
||||
|
||||
#define TEST_URL "test"
|
||||
#define DISPLAY_URL "display"
|
||||
#define FAKE_URL "fake"
|
||||
|
||||
#define LOGS_FILE_NAME "logs"
|
||||
|
||||
#define KILL_STREAM_SIGNAL SIGTERM
|
27
src/base/gst_constants.cpp
Normal file
27
src/base/gst_constants.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/gst_constants.h"
|
||||
|
||||
const std::array<const char*, SUPPORTED_VIDEO_PARSERS_COUNT> kSupportedVideoParsers = {
|
||||
{TS_PARSE, H264_PARSE, H265_PARSE}};
|
||||
|
||||
const std::array<const char*, SUPPORTED_AUDIO_PARSERS_COUNT> kSupportedAudioParsers = {
|
||||
{MPEG_AUDIO_PARSE, AAC_PARSE, AC3_PARSE, RAW_AUDIO_PARSE}};
|
||||
|
||||
const std::array<const char*, SUPPORTED_VIDEO_ENCODERS_COUNT> kSupportedVideoEncoders = {
|
||||
{EAVC_ENC, OPEN_H264_ENC, X264_ENC, NV_H264_ENC, NV_H265_ENC, VAAPI_H264_ENC, VAAPI_MPEG2_ENC, MFX_H264_ENC,
|
||||
X265_ENC, MSDK_H264_ENC}};
|
||||
const std::array<const char*, SUPPORTED_AUDIO_ENCODERS_COUNT> kSupportedAudioEncoders = {
|
||||
{LAME_MP3_ENC, FAAC, VOAAC_ENC}};
|
157
src/base/gst_constants.h
Normal file
157
src/base/gst_constants.h
Normal file
|
@ -0,0 +1,157 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#define DECODEBIN "decodebin"
|
||||
#define FAKE_SINK "fakesink"
|
||||
#define TEST_SINK "testsink"
|
||||
#define VIDEO_TEST_SRC "videotestsrc"
|
||||
#define AUDIO_TEST_SRC "audiotestsrc"
|
||||
#define DISPLAY_SRC "ximagesrc"
|
||||
#define VIDEO_SCREEN_SINK "autovideosink"
|
||||
#define AUDIO_SCREEN_SINK "autoaudiosink"
|
||||
#define QUEUE "queue"
|
||||
#define QUEUE2 "queue2"
|
||||
#define H264_PARSE "h264parse"
|
||||
#define H265_PARSE "h265parse"
|
||||
#define MPEG_VIDEO_PARSE "mpegvideoparse"
|
||||
#define AAC_PARSE "aacparse"
|
||||
#define AC3_PARSE "ac3parse"
|
||||
#define MPEG_AUDIO_PARSE "mpegaudioparse"
|
||||
#define RAW_AUDIO_PARSE "rawaudioparse"
|
||||
#define TEE "tee"
|
||||
#define MP4_MUX "mp4mux"
|
||||
#define QT_MUX "qtmux"
|
||||
#define FLV_MUX "flvmux"
|
||||
#define MPEGTS_MUX "mpegtsmux"
|
||||
#define FILE_SINK "filesink"
|
||||
#define RTP_MUX "rtpmux"
|
||||
#define RTP_MPEG2_PAY "rtpmp2tpay"
|
||||
#define RTP_H264_PAY "rtph264pay"
|
||||
#define RTP_H265_PAY "rtph265pay"
|
||||
#define RTP_AAC_PAY "rtpmp4apay"
|
||||
#define RTP_AC3_PAY "rtpac3pay"
|
||||
#define RTP_MPEG2_DEPAY "rtpmp2tdepay"
|
||||
#define RTP_H264_DEPAY "rtph264depay"
|
||||
#define RTP_H265_DEPAY "rtph265depay"
|
||||
#define RTP_AAC_DEPAY "rtpmp4adepay"
|
||||
#define RTP_AC3_DEPAY "rtpac3depay"
|
||||
#define V4L2_SRC "v4l2src"
|
||||
#define SPLIT_MUX_SINK "splitmuxsink"
|
||||
#define ALSA_SRC "alsasrc"
|
||||
#define MULTIFILE_SRC "multifilesrc"
|
||||
#define APP_SRC "appsrc"
|
||||
#define FILE_SRC "filesrc"
|
||||
#define IMAGE_FREEZE "imagefreeze"
|
||||
#define CAPS_FILTER "capsfilter"
|
||||
#define AUDIO_CONVERT "audioconvert"
|
||||
#define RG_VOLUME "rgvolume"
|
||||
#define VOLUME "volume"
|
||||
#define FAAC "faac"
|
||||
#define VOAAC_ENC "voaacenc"
|
||||
#define AUDIO_RESAMPLE "audioresample"
|
||||
#define LAME_MP3_ENC "lamemp3enc"
|
||||
#define VIDEO_CONVERT "videoconvert"
|
||||
#define AV_DEINTERLACE "avdeinterlace"
|
||||
#define DEINTERLACE "deinterlace"
|
||||
#define ASPECT_RATIO "aspectratiocrop"
|
||||
#define UDP_SINK "udpsink"
|
||||
#define TCP_SERVER_SINK "tcpserversink"
|
||||
#define RTMP_SINK "rtmpsink"
|
||||
#define HLS_SINK "hlssink"
|
||||
#define SOUP_HTTP_SRC "souphttpsrc"
|
||||
#define DVB_SRC "dvbsrc"
|
||||
#define VIDEO_SCALE "videoscale"
|
||||
#define VIDEO_RATE "videorate"
|
||||
#define MULTIFILE_SINK "multifilesink"
|
||||
#define KVS_SINK "kvssink"
|
||||
|
||||
#define NV_H264_ENC "nvh264enc"
|
||||
|
||||
#define NV_H265_ENC "nvh265enc"
|
||||
|
||||
#define MSDK_H264_ENC "msdkh264enc"
|
||||
|
||||
#define X264_ENC "x264enc"
|
||||
|
||||
#define X265_ENC "x265enc"
|
||||
#define MPEG2_ENC "mpeg2enc"
|
||||
|
||||
#define EAVC_ENC "eavcenc"
|
||||
|
||||
#define OPEN_H264_ENC "openh264enc"
|
||||
|
||||
#define UDP_SRC "udpsrc"
|
||||
#define RTMP_SRC "rtmpsrc"
|
||||
#define RTSP_SRC "rtspsrc"
|
||||
#define TCP_SERVER_SRC "tcpserversrc"
|
||||
|
||||
#define VAAPI_H264_ENC "vaapih264enc"
|
||||
|
||||
#define VAAPI_MPEG2_ENC "vaapimpeg2enc"
|
||||
#define VAAPI_DECODEBIN "vaapidecodebin"
|
||||
#define VAAPI_POST_PROC "vaapipostproc"
|
||||
|
||||
#define GDK_PIXBUF_OVERLAY "gdkpixbufoverlay"
|
||||
#define RSVG_OVERLAY "rsvgoverlay"
|
||||
#define VIDEO_BOX "videobox"
|
||||
#define VIDEO_MIXER "videomixer"
|
||||
#define AUDIO_MIXER "audiomixer"
|
||||
#define INTERLEAVE "interleave"
|
||||
#define DEINTERLEAVE "deinterleave"
|
||||
#define TEXT_OVERLAY "textoverlay"
|
||||
#define VIDEO_CROP "videocrop"
|
||||
#define SPECTRUM "spectrum"
|
||||
#define LEVEL "level"
|
||||
#define HLS_DEMUX "hlsdemux"
|
||||
#define VIDEO_DECK_SINK "decklinkvideosink"
|
||||
#define AUDIO_DECK_SINK "decklinkaudiosink"
|
||||
#define INTERLACE "interlace"
|
||||
#define AUTO_VIDEO_CONVERT "autovideoconvert"
|
||||
#define TS_PARSE "tsparse"
|
||||
#define AVDEC_H264 "avdec_h264"
|
||||
#define TS_DEMUX "tsdemux"
|
||||
|
||||
#define AVDEC_AC3 "avdec_ac3"
|
||||
#define AVDEC_AC3_FIXED "avdec_ac3_fixed"
|
||||
#define AVDEC_AAC "avdec_aac"
|
||||
#define AVDEC_AAC_FIXED "avdec_aac_fixed"
|
||||
#define SOUP_HTTP_CLIENT_SINK "souphttpclientsink"
|
||||
|
||||
#define MFX_H264_ENC "mfxh264enc"
|
||||
#define MFX_VPP "mfxvpp"
|
||||
#define MFX_H264_DEC "mfxh264dec"
|
||||
|
||||
#define SRT_SRC "srtsrc"
|
||||
#define SRT_SINK "srtsink"
|
||||
|
||||
// deep learning
|
||||
#define TINY_YOLOV2 "tinyyolov2"
|
||||
#define TINY_YOLOV3 "tinyyolov3"
|
||||
#define DETECTION_OVERLAY "detectionoverlay"
|
||||
|
||||
#define SUPPORTED_VIDEO_PARSERS_COUNT 3
|
||||
#define SUPPORTED_AUDIO_PARSERS_COUNT 4
|
||||
|
||||
extern const std::array<const char*, SUPPORTED_VIDEO_PARSERS_COUNT> kSupportedVideoParsers;
|
||||
extern const std::array<const char*, SUPPORTED_AUDIO_PARSERS_COUNT> kSupportedAudioParsers;
|
||||
|
||||
#define SUPPORTED_VIDEO_ENCODERS_COUNT 10
|
||||
#define SUPPORTED_AUDIO_ENCODERS_COUNT 3
|
||||
|
||||
extern const std::array<const char*, SUPPORTED_VIDEO_ENCODERS_COUNT> kSupportedVideoEncoders;
|
||||
extern const std::array<const char*, SUPPORTED_AUDIO_ENCODERS_COUNT> kSupportedAudioEncoders;
|
23
src/base/link_generator/ilink_generator.cpp
Normal file
23
src/base/link_generator/ilink_generator.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/link_generator/ilink_generator.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
ILinkGenerator::~ILinkGenerator() {}
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
29
src/base/link_generator/ilink_generator.h
Normal file
29
src/base/link_generator/ilink_generator.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fastotv/types/input_uri.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
class ILinkGenerator {
|
||||
public:
|
||||
virtual bool Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const WARN_UNUSED_RESULT = 0;
|
||||
virtual ~ILinkGenerator();
|
||||
};
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
126
src/base/link_generator/pyfastostream.cpp
Normal file
126
src/base/link_generator/pyfastostream.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/link_generator/pyfastostream.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#include "base/platform_macros.h"
|
||||
#include "base/utils.h"
|
||||
|
||||
namespace {
|
||||
static const char* kStreams[9] = {"best", "1080p60", "720p60", "720p", "480p", "360p", "240p", "144p", "worst"};
|
||||
|
||||
bool GetTrueUrl(const std::string& path,
|
||||
const common::uri::GURL& url,
|
||||
const fastotv::PyFastoStream& link,
|
||||
common::uri::GURL* generated_url,
|
||||
size_t rec = 0) {
|
||||
if (rec >= SIZEOFMASS(kStreams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!generated_url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cmd_line = path + " --url";
|
||||
const auto http = link.GetHttp();
|
||||
if (http) {
|
||||
cmd_line += " --http-proxy=" + http->spec();
|
||||
}
|
||||
|
||||
const auto https = link.GetHttps();
|
||||
if (https) {
|
||||
cmd_line += " --https-proxy=" + https->spec();
|
||||
}
|
||||
|
||||
std::string raw_url = url.spec();
|
||||
common::Optional<std::string> audio_master;
|
||||
if (url.SchemeIsFile() && url.has_query()) {
|
||||
audio_master = fastocloud::GetAudioMasterUrlFromQuery(url.query());
|
||||
if (audio_master) {
|
||||
raw_url = *audio_master;
|
||||
}
|
||||
}
|
||||
|
||||
cmd_line += common::MemSPrintf(" \'%s\' --quality %s --prefer %d", raw_url, kStreams[rec], link.GetPrefer());
|
||||
FILE* fp = popen(cmd_line.c_str(), "r");
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char true_url[1024] = {0};
|
||||
char* res = fgets(true_url, sizeof(true_url) - 1, fp);
|
||||
int closed = pclose(fp);
|
||||
if (WIFEXITED(closed)) {
|
||||
if (WEXITSTATUS(closed) == EXIT_FAILURE) {
|
||||
return GetTrueUrl(path, url, link, generated_url, ++rec);
|
||||
}
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ln = strlen(true_url) - 1;
|
||||
if (true_url[ln] == '\n') {
|
||||
true_url[ln] = 0;
|
||||
}
|
||||
|
||||
if (audio_master) {
|
||||
*generated_url = common::uri::GURL("file://" + url.path() + "?audio=" + true_url);
|
||||
return true;
|
||||
}
|
||||
|
||||
*generated_url = common::uri::GURL(true_url);
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
PyFastoPyFastoStreamGenerator::PyFastoPyFastoStreamGenerator(
|
||||
const common::file_system::ascii_file_string_path& script_path)
|
||||
: script_path_(script_path) {}
|
||||
|
||||
bool PyFastoPyFastoStreamGenerator::Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const {
|
||||
if (!out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto str = src.GetPyFastoStream();
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!script_path_.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
common::uri::GURL gen;
|
||||
if (!GetTrueUrl(script_path_.GetPath(), src.GetUrl(), *str, &gen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = src;
|
||||
out->SetUrl(gen);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
36
src/base/link_generator/pyfastostream.h
Normal file
36
src/base/link_generator/pyfastostream.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
|
||||
#include "base/link_generator/ilink_generator.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace link_generator {
|
||||
|
||||
class PyFastoPyFastoStreamGenerator : public ILinkGenerator {
|
||||
public:
|
||||
typedef common::Optional<common::uri::GURL> http_proxy_t;
|
||||
explicit PyFastoPyFastoStreamGenerator(const common::file_system::ascii_file_string_path& script_path);
|
||||
|
||||
bool Generate(const fastotv::InputUri& src, fastotv::InputUri* out) const override WARN_UNUSED_RESULT;
|
||||
|
||||
private:
|
||||
const common::file_system::ascii_file_string_path script_path_;
|
||||
};
|
||||
|
||||
} // namespace link_generator
|
||||
} // namespace fastocloud
|
158
src/base/machine_learning/deep_learning.cpp
Normal file
158
src/base/machine_learning/deep_learning.cpp
Normal file
|
@ -0,0 +1,158 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/machine_learning/deep_learning.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#define DEEP_LEARNING_BACKEND_FIELD "backend"
|
||||
#define DEEP_LEARNING_MODEL_PATH_FIELD "model_path"
|
||||
#define DEEP_LEARNING_PROPERTIES_FIELD "properties"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
DeepLearning::DeepLearning() : backend_(fastoml::TENSORFLOW), model_path_(), properties_() {}
|
||||
|
||||
DeepLearning::DeepLearning(fastoml::SupportedBackends backend, const file_path_t& model_path, const properties_t& prop)
|
||||
: backend_(backend), model_path_(model_path), properties_(prop) {}
|
||||
|
||||
DeepLearning::file_path_t DeepLearning::GetModelPath() const {
|
||||
return model_path_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetModelPath(const file_path_t& path) {
|
||||
model_path_ = path;
|
||||
}
|
||||
|
||||
DeepLearning::properties_t DeepLearning::GetProperties() const {
|
||||
return properties_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetProperties(const properties_t& prop) {
|
||||
properties_ = prop;
|
||||
}
|
||||
|
||||
fastoml::SupportedBackends DeepLearning::GetBackend() const {
|
||||
return backend_;
|
||||
}
|
||||
|
||||
void DeepLearning::SetBackend(fastoml::SupportedBackends backend) {
|
||||
backend_ = backend;
|
||||
}
|
||||
|
||||
bool DeepLearning::Equals(const DeepLearning& learn) const {
|
||||
return learn.backend_ == backend_ && learn.model_path_ == model_path_;
|
||||
}
|
||||
|
||||
common::Optional<DeepLearning> DeepLearning::MakeDeepLearning(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
|
||||
DeepLearning res;
|
||||
common::Value* learning_backend_field = hash->Find(DEEP_LEARNING_BACKEND_FIELD);
|
||||
int backend;
|
||||
if (!learning_backend_field || !learning_backend_field->GetAsInteger(&backend)) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
res.SetBackend(static_cast<fastoml::SupportedBackends>(backend));
|
||||
|
||||
std::string model_path_str;
|
||||
common::Value* model_path_field = hash->Find(DEEP_LEARNING_MODEL_PATH_FIELD);
|
||||
if (!model_path_field || !model_path_field->GetAsBasicString(&model_path_str)) {
|
||||
return common::Optional<DeepLearning>();
|
||||
}
|
||||
res.SetModelPath(file_path_t(model_path_str));
|
||||
|
||||
common::Value* properties_field = hash->Find(DEEP_LEARNING_PROPERTIES_FIELD);
|
||||
common::ArrayValue* arr = nullptr;
|
||||
if (properties_field && properties_field->GetAsList(&arr)) {
|
||||
properties_t properties;
|
||||
for (size_t i = 0; i < arr->GetSize(); ++i) {
|
||||
common::Value* prop = nullptr;
|
||||
if (arr->Get(i, &prop)) {
|
||||
common::HashValue* hprop = nullptr;
|
||||
if (prop->GetAsHash(&hprop)) {
|
||||
for (auto it = hprop->begin(); it != hprop->end(); ++it) {
|
||||
std::string value_str;
|
||||
if (it->second->GetAsBasicString(&value_str)) {
|
||||
BackendProperty pr = {it->first.as_string(), value_str};
|
||||
properties.push_back(pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.SetProperties(properties);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error DeepLearning::DoDeSerialize(json_object* serialized) {
|
||||
DeepLearning res;
|
||||
json_object* jbackend = nullptr;
|
||||
json_bool jbackend_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_BACKEND_FIELD, &jbackend);
|
||||
if (!jbackend_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetBackend(static_cast<fastoml::SupportedBackends>(json_object_get_int(jbackend)));
|
||||
|
||||
json_object* jmodel_path = nullptr;
|
||||
json_bool jmodel_path_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_MODEL_PATH_FIELD, &jmodel_path);
|
||||
if (!jmodel_path_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetModelPath(file_path_t(json_object_get_string(jmodel_path)));
|
||||
|
||||
json_object* jproperties = nullptr;
|
||||
json_bool jproperties_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_PROPERTIES_FIELD, &jproperties);
|
||||
if (jproperties_exists) {
|
||||
properties_t properties;
|
||||
size_t len = json_object_array_length(jproperties);
|
||||
// [{"input_layer" : "1234"}, {"output_layer" : "321"}]
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
json_object* jproperty = json_object_array_get_idx(jproperties, i);
|
||||
json_object_object_foreach(jproperty, key, val) { properties.push_back({key, json_object_get_string(val)}); }
|
||||
}
|
||||
res.SetProperties(properties);
|
||||
}
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error DeepLearning::SerializeFields(json_object* out) const {
|
||||
json_object_object_add(out, DEEP_LEARNING_BACKEND_FIELD, json_object_new_int64(backend_));
|
||||
const std::string model_path_str = model_path_.GetPath();
|
||||
json_object_object_add(out, DEEP_LEARNING_MODEL_PATH_FIELD, json_object_new_string(model_path_str.c_str()));
|
||||
|
||||
json_object* jproperties = json_object_new_array();
|
||||
for (size_t i = 0; i < properties_.size(); ++i) {
|
||||
json_object* jproperty = json_object_new_object();
|
||||
json_object_object_add(jproperty, properties_[i].property.c_str(),
|
||||
json_object_new_string(properties_[i].value.c_str()));
|
||||
json_object_array_add(jproperties, jproperty);
|
||||
}
|
||||
json_object_object_add(out, DEEP_LEARNING_PROPERTIES_FIELD, jproperties);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
68
src/base/machine_learning/deep_learning.h
Normal file
68
src/base/machine_learning/deep_learning.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
#include <fastoml/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
struct BackendProperty {
|
||||
std::string property;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class DeepLearning : public common::serializer::JsonSerializer<DeepLearning> {
|
||||
public:
|
||||
typedef common::file_system::ascii_file_string_path file_path_t;
|
||||
typedef std::vector<BackendProperty> properties_t;
|
||||
|
||||
DeepLearning();
|
||||
DeepLearning(fastoml::SupportedBackends backend,
|
||||
const file_path_t& model_path,
|
||||
const properties_t& prop = properties_t());
|
||||
|
||||
bool Equals(const DeepLearning& learn) const;
|
||||
|
||||
properties_t GetProperties() const;
|
||||
void SetProperties(const properties_t& prop);
|
||||
|
||||
fastoml::SupportedBackends GetBackend() const;
|
||||
void SetBackend(fastoml::SupportedBackends backend);
|
||||
|
||||
file_path_t GetModelPath() const;
|
||||
void SetModelPath(const file_path_t& path);
|
||||
|
||||
static common::Optional<DeepLearning> MakeDeepLearning(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
fastoml::SupportedBackends backend_;
|
||||
file_path_t model_path_;
|
||||
properties_t properties_;
|
||||
};
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
78
src/base/machine_learning/deep_learning_overlay.cpp
Normal file
78
src/base/machine_learning/deep_learning_overlay.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* Copyright (C) 2014-2019 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/machine_learning/deep_learning_overlay.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#define DEEP_LEARNING_LABELS_PATH_FIELD "labels_path"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
DeepLearningOverlay::DeepLearningOverlay() : labels_path_() {}
|
||||
|
||||
DeepLearningOverlay::DeepLearningOverlay(const file_path_t& labels_path) : labels_path_(labels_path) {}
|
||||
|
||||
DeepLearningOverlay::file_path_t DeepLearningOverlay::GetLabelsPath() const {
|
||||
return labels_path_;
|
||||
}
|
||||
|
||||
void DeepLearningOverlay::SetLabelsPath(const file_path_t& path) {
|
||||
labels_path_ = path;
|
||||
}
|
||||
|
||||
bool DeepLearningOverlay::Equals(const DeepLearningOverlay& learn) const {
|
||||
return learn.labels_path_ == labels_path_;
|
||||
}
|
||||
|
||||
common::Optional<DeepLearningOverlay> DeepLearningOverlay::MakeDeepLearningOverlay(common::HashValue* hash) {
|
||||
if (!hash) {
|
||||
return common::Optional<DeepLearningOverlay>();
|
||||
}
|
||||
|
||||
DeepLearningOverlay res;
|
||||
common::Value* paths_field = hash->Find(DEEP_LEARNING_LABELS_PATH_FIELD);
|
||||
std::string paths;
|
||||
if (!paths_field || !paths_field->GetAsBasicString(&paths)) {
|
||||
return common::Optional<DeepLearningOverlay>();
|
||||
}
|
||||
res.SetLabelsPath(file_path_t(paths));
|
||||
return res;
|
||||
}
|
||||
|
||||
common::Error DeepLearningOverlay::DoDeSerialize(json_object* serialized) {
|
||||
DeepLearningOverlay res;
|
||||
json_object* jlabels_path = nullptr;
|
||||
json_bool jlabels_path_exists = json_object_object_get_ex(serialized, DEEP_LEARNING_LABELS_PATH_FIELD, &jlabels_path);
|
||||
if (!jlabels_path_exists) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
res.SetLabelsPath(file_path_t(json_object_get_string(jlabels_path)));
|
||||
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error DeepLearningOverlay::SerializeFields(json_object* out) const {
|
||||
const std::string labels_path_str = labels_path_.GetPath();
|
||||
json_object_object_add(out, DEEP_LEARNING_LABELS_PATH_FIELD, json_object_new_string(labels_path_str.c_str()));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
52
src/base/machine_learning/deep_learning_overlay.h
Normal file
52
src/base/machine_learning/deep_learning_overlay.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/serializer/json_serializer.h>
|
||||
#include <common/value.h>
|
||||
|
||||
#include <fastoml/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace machine_learning {
|
||||
|
||||
class DeepLearningOverlay : public common::serializer::JsonSerializer<DeepLearningOverlay> {
|
||||
public:
|
||||
typedef common::file_system::ascii_file_string_path file_path_t;
|
||||
|
||||
DeepLearningOverlay();
|
||||
explicit DeepLearningOverlay(const file_path_t& labels_path);
|
||||
|
||||
bool Equals(const DeepLearningOverlay& learn) const;
|
||||
|
||||
file_path_t GetLabelsPath() const;
|
||||
void SetLabelsPath(const file_path_t& path);
|
||||
|
||||
static common::Optional<DeepLearningOverlay> MakeDeepLearningOverlay(common::HashValue* hash);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
file_path_t labels_path_;
|
||||
};
|
||||
|
||||
} // namespace machine_learning
|
||||
} // namespace fastocloud
|
27
src/base/platform_macros.h
Normal file
27
src/base/platform_macros.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#ifndef WIFEXITED
|
||||
#define WIFEXITED(S) (((S)&0xff) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(S) (((S)&0xff00) >> 8)
|
||||
#endif
|
||||
|
||||
#endif
|
370
src/base/stream_config.cpp
Normal file
370
src/base/stream_config.cpp
Normal file
|
@ -0,0 +1,370 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/config_fields.h"
|
||||
#include "base/utils.h"
|
||||
|
||||
#include <json-c/json_object.h>
|
||||
#include <json-c/json_tokener.h>
|
||||
|
||||
#include <common/convert2string.h>
|
||||
#include <common/file_system/file_system.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace {
|
||||
|
||||
bool ConvertFromString(common::ArrayValue* output_urls, fastocloud::output_t* out) {
|
||||
if (!output_urls || !out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fastocloud::output_t output;
|
||||
for (size_t i = 0; i < output_urls->GetSize(); ++i) {
|
||||
common::Value* url = nullptr;
|
||||
common::HashValue* url_hash = nullptr;
|
||||
if (output_urls->Get(i, &url) && url->GetAsHash(&url_hash)) {
|
||||
const auto murl = fastotv::OutputUri::Make(url_hash);
|
||||
if (murl) {
|
||||
output.push_back(*murl);
|
||||
}
|
||||
}
|
||||
}
|
||||
*out = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertFromString(common::ArrayValue* input_urls, fastocloud::input_t* out) {
|
||||
if (!input_urls || !out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fastocloud::input_t input;
|
||||
for (size_t i = 0; i < input_urls->GetSize(); ++i) {
|
||||
common::Value* url = nullptr;
|
||||
common::HashValue* url_hash = nullptr;
|
||||
if (input_urls->Get(i, &url) && url->GetAsHash(&url_hash)) {
|
||||
const auto murl = fastotv::InputUri::Make(url_hash);
|
||||
if (murl) {
|
||||
input.push_back(*murl);
|
||||
}
|
||||
}
|
||||
}
|
||||
*out = input;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
common::Optional<input_t> ReadInput(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
common::Value* input_field = config->Find(INPUT_FIELD);
|
||||
common::ArrayValue* input_hash = nullptr;
|
||||
if (!input_field || !input_field->GetAsList(&input_hash)) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
input_t linput;
|
||||
if (!ConvertFromString(input_hash, &linput)) {
|
||||
return common::Optional<input_t>();
|
||||
}
|
||||
|
||||
return common::Optional<input_t>(linput);
|
||||
}
|
||||
|
||||
common::Optional<output_t> ReadOutput(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
common::Value* output_field = config->Find(OUTPUT_FIELD);
|
||||
common::ArrayValue* output_hash = nullptr;
|
||||
if (!output_field || !output_field->GetAsList(&output_hash)) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
output_t loutput;
|
||||
if (!ConvertFromString(output_hash, &loutput)) {
|
||||
return common::Optional<output_t>();
|
||||
}
|
||||
|
||||
return common::Optional<output_t>(loutput);
|
||||
}
|
||||
|
||||
common::Optional<fastotv::stream_id_t> GetSid(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<fastotv::stream_id_t>();
|
||||
}
|
||||
|
||||
common::Value* id_field = config->Find(ID_FIELD);
|
||||
fastotv::stream_id_t lsid;
|
||||
if (id_field && id_field->GetAsBasicString(&lsid)) {
|
||||
return common::Optional<fastotv::stream_id_t>(lsid);
|
||||
}
|
||||
|
||||
return common::Optional<fastotv::stream_id_t>();
|
||||
}
|
||||
|
||||
common::Optional<fastotv::StreamTTL> GetTTL(const StreamConfig& config) {
|
||||
if (!config) {
|
||||
return common::Optional<fastotv::StreamTTL>();
|
||||
}
|
||||
|
||||
common::HashValue* ttl_hash = nullptr;
|
||||
common::Value* frame_field = config->Find(AUTO_EXIT_TIME_FIELD);
|
||||
if (frame_field && frame_field->GetAsHash(&ttl_hash)) {
|
||||
return fastotv::StreamTTL::Make(ttl_hash);
|
||||
}
|
||||
|
||||
return common::Optional<fastotv::StreamTTL>();
|
||||
}
|
||||
|
||||
common::ErrnoError MakeStreamInfo(const StreamConfig& config,
|
||||
bool check_folders,
|
||||
StreamInfo* sha,
|
||||
std::string* feedback_dir,
|
||||
std::string* data_dir,
|
||||
common::logging::LOG_LEVEL* logs_level) {
|
||||
if (!sha || !data_dir || !feedback_dir || !logs_level) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
auto sid = GetSid(config);
|
||||
if (!sid) {
|
||||
return common::make_errno_error("Define " ID_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
StreamInfo lsha;
|
||||
lsha.id = *sid;
|
||||
|
||||
int64_t type;
|
||||
common::Value* type_field = config->Find(TYPE_FIELD);
|
||||
if (!type_field || !type_field->GetAsInteger64(&type)) {
|
||||
return common::make_errno_error("Define " TYPE_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.type = static_cast<fastotv::StreamType>(type);
|
||||
|
||||
if (lsha.type == fastotv::PROXY || lsha.type == fastotv::VOD_PROXY) {
|
||||
return common::make_errno_error("Proxy streams not handled for now", EINVAL);
|
||||
}
|
||||
|
||||
std::string lfeedback_dir;
|
||||
common::Value* feedback_field = config->Find(FEEDBACK_DIR_FIELD);
|
||||
if (!feedback_field || !feedback_field->GetAsBasicString(&lfeedback_dir)) {
|
||||
return common::make_errno_error("Define " FEEDBACK_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
std::string ldata_dir;
|
||||
common::Value* data_field = config->Find(DATA_DIR_FIELD);
|
||||
if (!data_field || !data_field->GetAsBasicString(&ldata_dir)) {
|
||||
return common::make_errno_error("Define " DATA_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
int64_t llogs_level;
|
||||
common::Value* log_level_field = config->Find(LOG_LEVEL_FIELD);
|
||||
if (!log_level_field || !log_level_field->GetAsInteger64(&llogs_level)) {
|
||||
llogs_level = common::logging::LOG_LEVEL_DEBUG;
|
||||
}
|
||||
|
||||
common::ErrnoError errn = CreateAndCheckDir(lfeedback_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
errn = CreateAndCheckDir(ldata_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
const auto input = ReadInput(config);
|
||||
if (!input) {
|
||||
return common::make_errno_error("Define " INPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.input = *input;
|
||||
|
||||
if (check_folders) {
|
||||
bool is_timeshift_rec = type == fastotv::TIMESHIFT_RECORDER; // no outputs
|
||||
if (is_timeshift_rec || type == fastotv::CATCHUP) {
|
||||
std::string timeshift_dir;
|
||||
common::Value* timeshift_dir_field = config->Find(TIMESHIFT_DIR_FIELD);
|
||||
if (!timeshift_dir_field || !timeshift_dir_field->GetAsBasicString(×hift_dir)) {
|
||||
return common::make_errno_error("Define " TIMESHIFT_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
errn = CreateAndCheckDir(timeshift_dir);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_timeshift_rec) {
|
||||
const auto output = ReadOutput(config);
|
||||
if (!output) {
|
||||
return common::make_errno_error("Define " OUTPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
for (const auto& out_uri : *output) {
|
||||
auto ouri = out_uri.GetUrl();
|
||||
if (ouri.SchemeIsHTTPOrHTTPS()) {
|
||||
if (out_uri.IsHls()) {
|
||||
const auto http_root = out_uri.GetHttpRoot();
|
||||
if (!http_root) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string http_root_str = http_root->GetPath();
|
||||
common::ErrnoError errn = CreateAndCheckDir(http_root_str);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
} else if (ouri.SchemeIsFile()) {
|
||||
const auto file_path = common::file_system::ascii_file_string_path(ouri.path());
|
||||
if (!file_path.IsValid()) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string file_root_str = file_path.GetDirectory();
|
||||
common::ErrnoError errn = CreateAndCheckDir(file_root_str);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
lsha.output.push_back(out_uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*logs_level = static_cast<common::logging::LOG_LEVEL>(llogs_level);
|
||||
*feedback_dir = lfeedback_dir;
|
||||
*data_dir = ldata_dir;
|
||||
*sha = lsha;
|
||||
return common::ErrnoError();
|
||||
}
|
||||
|
||||
common::ErrnoError CleanStream(const StreamConfig& config) {
|
||||
auto sid = GetSid(config);
|
||||
if (!sid) {
|
||||
return common::make_errno_error("Define " ID_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
StreamInfo lsha;
|
||||
lsha.id = *sid;
|
||||
|
||||
int64_t type;
|
||||
common::Value* type_field = config->Find(TYPE_FIELD);
|
||||
if (!type_field || !type_field->GetAsInteger64(&type)) {
|
||||
return common::make_errno_error("Define " TYPE_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.type = static_cast<fastotv::StreamType>(type);
|
||||
|
||||
if (lsha.type == fastotv::PROXY || lsha.type == fastotv::VOD_PROXY) {
|
||||
return common::make_errno_error("Proxy streams not handled for now", EINVAL);
|
||||
}
|
||||
|
||||
std::string lfeedback_dir;
|
||||
common::Value* feedback_field = config->Find(FEEDBACK_DIR_FIELD);
|
||||
if (!feedback_field || !feedback_field->GetAsBasicString(&lfeedback_dir)) {
|
||||
return common::make_errno_error("Define " FEEDBACK_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
std::string ldata_dir;
|
||||
common::Value* data_field = config->Find(DATA_DIR_FIELD);
|
||||
if (!data_field || !data_field->GetAsBasicString(&ldata_dir)) {
|
||||
return common::make_errno_error("Define " DATA_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
int64_t llogs_level;
|
||||
common::Value* log_level_field = config->Find(LOG_LEVEL_FIELD);
|
||||
if (!log_level_field || !log_level_field->GetAsInteger64(&llogs_level)) {
|
||||
llogs_level = common::logging::LOG_LEVEL_DEBUG;
|
||||
}
|
||||
|
||||
common::ErrnoError errn = common::file_system::remove_directory(lfeedback_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
errn = common::file_system::remove_directory(ldata_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
|
||||
const auto input = ReadInput(config);
|
||||
if (!input) {
|
||||
return common::make_errno_error("Define " INPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
lsha.input = *input;
|
||||
|
||||
bool is_timeshift_rec = type == fastotv::TIMESHIFT_RECORDER; // no outputs
|
||||
if (is_timeshift_rec || type == fastotv::CATCHUP) {
|
||||
std::string timeshift_dir;
|
||||
common::Value* timeshift_dir_field = config->Find(TIMESHIFT_DIR_FIELD);
|
||||
if (!timeshift_dir_field || !timeshift_dir_field->GetAsBasicString(×hift_dir)) {
|
||||
return common::make_errno_error("Define " TIMESHIFT_DIR_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
errn = common::file_system::remove_directory(timeshift_dir, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_timeshift_rec) {
|
||||
const auto output = ReadOutput(config);
|
||||
if (!output) {
|
||||
return common::make_errno_error("Define " OUTPUT_FIELD " variable and make it valid", EAGAIN);
|
||||
}
|
||||
|
||||
for (const auto& out_uri : *output) {
|
||||
auto ouri = out_uri.GetUrl();
|
||||
if (ouri.SchemeIsHTTPOrHTTPS()) {
|
||||
if (out_uri.IsHls()) {
|
||||
const auto http_root = out_uri.GetHttpRoot();
|
||||
if (!http_root) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string http_root_str = http_root->GetPath();
|
||||
common::ErrnoError errn = common::file_system::remove_directory(http_root_str, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
} else if (ouri.SchemeIsFile()) {
|
||||
const auto file_path = common::file_system::ascii_file_string_path(ouri.path());
|
||||
if (!file_path.IsValid()) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
const std::string file_root_str = file_path.GetDirectory();
|
||||
common::ErrnoError errn = common::file_system::remove_directory(file_root_str, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
lsha.output.push_back(out_uri);
|
||||
}
|
||||
}
|
||||
|
||||
return common::ErrnoError();
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
42
src/base/stream_config.h
Normal file
42
src/base/stream_config.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
#include <fastotv/types/stream_ttl.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef std::shared_ptr<common::HashValue> StreamConfig;
|
||||
|
||||
common::Optional<fastotv::stream_id_t> GetSid(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<fastotv::StreamTTL> GetTTL(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<input_t> ReadInput(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
common::Optional<output_t> ReadOutput(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError MakeStreamInfo(const StreamConfig& config,
|
||||
bool check_folders,
|
||||
StreamInfo* sha,
|
||||
std::string* feedback_dir,
|
||||
std::string* data_dir,
|
||||
common::logging::LOG_LEVEL* logs_level) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError CleanStream(const StreamConfig& config) WARN_UNUSED_RESULT;
|
||||
|
||||
} // namespace fastocloud
|
188
src/base/stream_config_parse.cpp
Normal file
188
src/base/stream_config_parse.cpp
Normal file
|
@ -0,0 +1,188 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_config_parse.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <json-c/json_tokener.h>
|
||||
#include <json-c/linkhash.h>
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
|
||||
namespace {
|
||||
common::Value* MakeValueFromJson(json_object* obj) {
|
||||
json_type obj_type = json_object_get_type(obj);
|
||||
if (obj_type == json_type_null) {
|
||||
return common::Value::CreateNullValue();
|
||||
} else if (obj_type == json_type_boolean) {
|
||||
return common::Value::CreateBooleanValue(json_object_get_boolean(obj));
|
||||
} else if (obj_type == json_type_double) {
|
||||
return common::Value::CreateDoubleValue(json_object_get_double(obj));
|
||||
} else if (obj_type == json_type_int) {
|
||||
int64_t jint = json_object_get_int64(obj);
|
||||
return common::Value::CreateInteger64Value(jint);
|
||||
} else if (obj_type == json_type_string) {
|
||||
return common::Value::CreateStringValueFromBasicString(json_object_get_string(obj));
|
||||
} else if (obj_type == json_type_object) {
|
||||
common::HashValue* result = common::Value::CreateHashValue();
|
||||
json_object_object_foreach(obj, key, val) {
|
||||
json_type val_type = json_object_get_type(val);
|
||||
common::Value* value = nullptr;
|
||||
switch (val_type) {
|
||||
case json_type_null:
|
||||
value = common::Value::CreateNullValue();
|
||||
break;
|
||||
case json_type_boolean:
|
||||
value = common::Value::CreateBooleanValue(json_object_get_boolean(val));
|
||||
break;
|
||||
case json_type_double:
|
||||
value = common::Value::CreateDoubleValue(json_object_get_double(val));
|
||||
break;
|
||||
case json_type_int:
|
||||
value = common::Value::CreateInteger64Value(json_object_get_int64(val));
|
||||
break;
|
||||
case json_type_string:
|
||||
value = common::Value::CreateStringValueFromBasicString(json_object_get_string(val));
|
||||
break;
|
||||
case json_type_object:
|
||||
value = MakeValueFromJson(val);
|
||||
break;
|
||||
case json_type_array:
|
||||
common::ArrayValue* arr = common::Value::CreateArrayValue();
|
||||
for (size_t i = 0; i < json_object_array_length(val); i++) {
|
||||
json_object* item = json_object_array_get_idx(val, i);
|
||||
arr->Append(MakeValueFromJson(item));
|
||||
}
|
||||
value = arr;
|
||||
break;
|
||||
}
|
||||
|
||||
result->Insert(key, value);
|
||||
}
|
||||
return result;
|
||||
} else if (obj_type == json_type_array) {
|
||||
common::ArrayValue* arr = common::Value::CreateArrayValue();
|
||||
for (size_t i = 0; i < json_object_array_length(obj); i++) {
|
||||
json_object* item = json_object_array_get_idx(obj, i);
|
||||
arr->Append(MakeValueFromJson(item));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
DNOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
json_object* MakeJson(const common::Value* value) {
|
||||
const common::Value::Type type = value->GetType();
|
||||
if (type == common::Value::TYPE_NULL) {
|
||||
return nullptr;
|
||||
} else if (type == common::Value::TYPE_BOOLEAN) {
|
||||
bool rbool;
|
||||
if (value->GetAsBoolean(&rbool)) {
|
||||
return json_object_new_boolean(rbool);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_DOUBLE) {
|
||||
double rdouble;
|
||||
if (value->GetAsDouble(&rdouble)) {
|
||||
return json_object_new_double(rdouble);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_INTEGER64) {
|
||||
int64_t rint;
|
||||
if (value->GetAsInteger64(&rint)) {
|
||||
return json_object_new_int64(rint);
|
||||
}
|
||||
} else if (type == common::Value::TYPE_STRING) {
|
||||
common::Value::string_t rstring;
|
||||
if (value->GetAsString(&rstring)) {
|
||||
const std::string r = rstring.as_string();
|
||||
return json_object_new_string(r.c_str());
|
||||
}
|
||||
} else if (type == common::Value::TYPE_HASH) {
|
||||
json_object* result = json_object_new_object();
|
||||
const common::HashValue* hash = nullptr;
|
||||
if (value->GetAsHash(&hash)) {
|
||||
for (auto it = hash->begin(); it != hash->end(); ++it) {
|
||||
const common::Value::string_t key = it->first;
|
||||
const std::string key_str = key.as_string();
|
||||
const common::Value* value = it->second;
|
||||
ignore_result(common::serializer::json_set_object(result, key_str.c_str(), MakeJson(value)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else if (type == common::Value::TYPE_ARRAY) {
|
||||
json_object* arr = json_object_new_array();
|
||||
const common::ArrayValue* arr_value = nullptr;
|
||||
if (value->GetAsList(&arr_value)) {
|
||||
for (size_t i = 0; i < arr_value->GetSize(); ++i) {
|
||||
const common::Value* val = nullptr;
|
||||
if (arr_value->Get(i, &val)) {
|
||||
json_object* obj = MakeJson(val);
|
||||
json_object_array_add(arr, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
DNOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(const std::string& json) {
|
||||
if (json.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
json_object* obj = json_tokener_parse(json.c_str());
|
||||
if (!obj) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<common::HashValue> res = MakeConfigFromJson(obj);
|
||||
json_object_put(obj);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(json_object* obj) {
|
||||
json_type obj_type = json_object_get_type(obj);
|
||||
if (obj_type == json_type_object) {
|
||||
return std::unique_ptr<common::HashValue>(static_cast<common::HashValue*>(MakeValueFromJson(obj)));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MakeJsonFromConfig(std::shared_ptr<common::HashValue> config, std::string* json) {
|
||||
if (!config || !json) {
|
||||
return false;
|
||||
}
|
||||
|
||||
json_object* jobj = MakeJson(config.get());
|
||||
if (!jobj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*json = json_object_get_string(jobj);
|
||||
json_object_put(jobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
32
src/base/stream_config_parse.h
Normal file
32
src/base/stream_config_parse.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <common/value.h>
|
||||
|
||||
#include <json-c/json_types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(const std::string& json);
|
||||
std::unique_ptr<common::HashValue> MakeConfigFromJson(json_object* obj);
|
||||
|
||||
bool MakeJsonFromConfig(std::shared_ptr<common::HashValue> config, std::string* json);
|
||||
|
||||
} // namespace fastocloud
|
17
src/base/stream_info.cpp
Normal file
17
src/base/stream_info.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
namespace fastocloud {} // namespace fastocloud
|
34
src/base/stream_info.h
Normal file
34
src/base/stream_info.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
#include "base/types.h"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef std::vector<ChannelStats> input_channels_info_t;
|
||||
typedef std::vector<ChannelStats> output_channels_info_t;
|
||||
|
||||
struct StreamInfo {
|
||||
fastotv::stream_id_t id;
|
||||
fastotv::StreamType type;
|
||||
input_t input;
|
||||
output_t output;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
98
src/base/stream_struct.cpp
Normal file
98
src/base/stream_struct.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/stream_struct.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/time.h>
|
||||
|
||||
#include "base/channel_stats.h"
|
||||
|
||||
namespace common {
|
||||
|
||||
std::string ConvertToString(fastocloud::StreamStatus st) {
|
||||
static const std::string kStreamStatuses[] = {
|
||||
"New", "Inited", "Started", "Ready", "Playing", "Frozen", "Waiting",
|
||||
};
|
||||
|
||||
return kStreamStatuses[st];
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
namespace {
|
||||
output_channels_info_t make_outputs(const std::vector<fastotv::OutputUri>& output) {
|
||||
output_channels_info_t res;
|
||||
for (auto out : output) {
|
||||
res.push_back(ChannelStats(out.GetID()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
input_channels_info_t make_inputs(const std::vector<fastotv::InputUri>& input) {
|
||||
input_channels_info_t res;
|
||||
for (auto in : input) {
|
||||
res.push_back(ChannelStats(in.GetID()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
StreamStruct::StreamStruct() : StreamStruct(StreamInfo()) {}
|
||||
|
||||
StreamStruct::StreamStruct(const StreamInfo& sha) : StreamStruct(sha, common::time::current_utc_mstime(), 0, 0) {}
|
||||
|
||||
StreamStruct::StreamStruct(const StreamInfo& sha,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest)
|
||||
: StreamStruct(sha.id, sha.type, NEW, make_inputs(sha.input), make_outputs(sha.output), start_time, lst, rest) {}
|
||||
|
||||
StreamStruct::StreamStruct(fastotv::stream_id_t sid,
|
||||
fastotv::StreamType type,
|
||||
StreamStatus status,
|
||||
input_channels_info_t input,
|
||||
output_channels_info_t output,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest)
|
||||
: id(sid),
|
||||
type(type),
|
||||
start_time(start_time),
|
||||
loop_start_time(lst),
|
||||
idle_time(0),
|
||||
restarts(rest),
|
||||
status(status),
|
||||
input(input),
|
||||
output(output) {}
|
||||
|
||||
bool StreamStruct::IsValid() const {
|
||||
return !id.empty();
|
||||
}
|
||||
|
||||
StreamStruct::~StreamStruct() {}
|
||||
|
||||
void StreamStruct::ResetDataWait() {
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
input[i].UpdateCheckPoint();
|
||||
}
|
||||
for (size_t i = 0; i < output.size(); ++i) {
|
||||
output[i].UpdateCheckPoint();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
62
src/base/stream_struct.h
Normal file
62
src/base/stream_struct.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
enum StreamStatus { NEW = 0, INIT = 1, STARTED = 2, READY = 3, PLAYING = 4, FROZEN = 5, WAITING = 6 };
|
||||
|
||||
struct StreamStruct {
|
||||
StreamStruct();
|
||||
explicit StreamStruct(const StreamInfo& sha);
|
||||
StreamStruct(const StreamInfo& sha, fastotv::timestamp_t start_time, fastotv::timestamp_t lst, size_t rest);
|
||||
StreamStruct(fastotv::stream_id_t sid,
|
||||
fastotv::StreamType type,
|
||||
StreamStatus status,
|
||||
input_channels_info_t input,
|
||||
output_channels_info_t output,
|
||||
fastotv::timestamp_t start_time,
|
||||
fastotv::timestamp_t lst,
|
||||
size_t rest);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
~StreamStruct();
|
||||
|
||||
void ResetDataWait();
|
||||
|
||||
fastotv::stream_id_t id;
|
||||
fastotv::StreamType type;
|
||||
|
||||
fastotv::timestamp_t start_time;
|
||||
fastotv::timestamp_t loop_start_time;
|
||||
fastotv::timestamp_t idle_time;
|
||||
size_t restarts;
|
||||
StreamStatus status;
|
||||
|
||||
input_channels_info_t input;
|
||||
output_channels_info_t output;
|
||||
};
|
||||
|
||||
} // namespace fastocloud
|
||||
|
||||
namespace common {
|
||||
std::string ConvertToString(fastocloud::StreamStatus st);
|
||||
}
|
17
src/base/types.cpp
Normal file
17
src/base/types.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/types.h"
|
||||
|
||||
namespace fastocloud {} // namespace fastocloud
|
40
src/base/types.h
Normal file
40
src/base/types.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/optional.h>
|
||||
|
||||
#include <fastotv/types/input_uri.h>
|
||||
#include <fastotv/types/output_uri.h>
|
||||
|
||||
#define TS_EXTENSION "ts"
|
||||
#define M3U8_EXTENSION "m3u8"
|
||||
#define DASH_EXTENSION "mpd"
|
||||
#define M3U8_CHUNK_MARKER "#EXTINF"
|
||||
#define CHUNK_EXT "." TS_EXTENSION
|
||||
|
||||
#define DUMP_FILE_NAME "dump.html"
|
||||
#define CONFIG_FILE_NAME "config.json"
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
typedef common::Optional<double> volume_t;
|
||||
typedef double alpha_t;
|
||||
typedef common::Optional<int> bit_rate_t;
|
||||
|
||||
typedef std::vector<fastotv::InputUri> input_t;
|
||||
typedef std::vector<fastotv::OutputUri> output_t;
|
||||
|
||||
} // namespace fastocloud
|
159
src/base/utils.cpp
Normal file
159
src/base/utils.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base/utils.h"
|
||||
|
||||
#include <common/file_system/file_system.h>
|
||||
#include <common/file_system/string_path_utils.h>
|
||||
#include <common/sprintf.h>
|
||||
#include <common/uri/gurl.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
common::Optional<common::net::HostAndPort> GetHostAndPortFromGurl(const common::uri::GURL& url) {
|
||||
if (!url.is_valid()) {
|
||||
return common::Optional<common::net::HostAndPort>();
|
||||
}
|
||||
|
||||
return common::net::HostAndPort(url.host(), url.IntPort());
|
||||
}
|
||||
|
||||
common::ErrnoError CreateAndCheckDir(const std::string& directory_path) {
|
||||
if (!common::file_system::is_directory_exist(directory_path)) {
|
||||
common::ErrnoError errn = common::file_system::create_directory(directory_path, true);
|
||||
if (errn) {
|
||||
return errn;
|
||||
}
|
||||
}
|
||||
return common::file_system::node_access(directory_path);
|
||||
}
|
||||
|
||||
void RemoveFilesByExtension(const common::file_system::ascii_directory_string_path& dir, const char* ext) {
|
||||
if (!dir.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string path = dir.GetPath();
|
||||
|
||||
DIR* dirp = opendir(path.c_str());
|
||||
if (!dirp) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG() << "Started clean up folder: " << path;
|
||||
struct dirent* dent;
|
||||
while ((dent = readdir(dirp)) != nullptr) {
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* pch = strstr(dent->d_name, ext);
|
||||
if (pch) {
|
||||
std::string file_path = common::MemSPrintf("%s%s", path, dent->d_name);
|
||||
time_t mtime;
|
||||
common::ErrnoError err = common::file_system::get_file_time_last_modification(file_path, &mtime);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't get timestamp file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
err = common::file_system::remove_file(file_path);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't remove file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
DEBUG_LOG() << "File path: " << file_path << " removed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
DEBUG_LOG() << "Finished clean up folder: " << path;
|
||||
}
|
||||
|
||||
void RemoveOldFilesByTime(const common::file_system::ascii_directory_string_path& dir,
|
||||
common::utctime_t max_life_secs,
|
||||
const char* pattern,
|
||||
bool recursive) {
|
||||
if (!dir.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string path = dir.GetPath();
|
||||
DIR* dirp = opendir(path.c_str());
|
||||
if (!dirp) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG() << "Started clean up folder: " << path;
|
||||
struct dirent* dent;
|
||||
while ((dent = readdir(dirp)) != nullptr) {
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef OS_WIN
|
||||
const std::string dir_str = common::file_system::make_path(path, dent->d_name);
|
||||
common::tribool is_dir_tr = common::file_system::is_directory(dir_str);
|
||||
if (is_dir_tr == common::INDETERMINATE) {
|
||||
continue;
|
||||
}
|
||||
bool is_dir = is_dir_tr == common::SUCCESS;
|
||||
#else
|
||||
bool is_dir = dent->d_type == DT_DIR;
|
||||
#endif
|
||||
|
||||
if (!is_dir) {
|
||||
if (common::MatchPattern(dent->d_name, pattern)) {
|
||||
std::string file_path = common::MemSPrintf("%s%s", path, dent->d_name);
|
||||
common::utctime_t mtime;
|
||||
common::ErrnoError err = common::file_system::get_file_time_last_modification(file_path, &mtime);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't get timestamp file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
if (mtime < max_life_secs) {
|
||||
err = common::file_system::remove_file(file_path);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't remove file: " << file_path << ", error: " << err->GetDescription();
|
||||
} else {
|
||||
DEBUG_LOG() << "File path: " << file_path << " removed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recursive) {
|
||||
auto folder = dir.MakeDirectoryStringPath(dent->d_name);
|
||||
if (folder) {
|
||||
RemoveOldFilesByTime(*folder, max_life_secs, pattern, recursive);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
DEBUG_LOG() << "Finished clean up folder: " << path;
|
||||
}
|
||||
|
||||
common::Optional<std::string> GetAudioMasterUrlFromQuery(const std::string& query_str) {
|
||||
common::uri::Component key, value;
|
||||
common::uri::Component query(0, query_str.length());
|
||||
while (common::uri::ExtractQueryKeyValue(query_str.c_str(), &query, &key, &value)) {
|
||||
std::string key_string(query_str.substr(key.begin, key.len));
|
||||
std::string param_text(query_str.substr(value.begin, value.len));
|
||||
if (common::EqualsASCII(key_string, "audio", false)) {
|
||||
return common::Optional<std::string>(param_text);
|
||||
}
|
||||
}
|
||||
|
||||
return common::Optional<std::string>();
|
||||
}
|
||||
|
||||
} // namespace fastocloud
|
37
src/base/utils.h
Normal file
37
src/base/utils.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/error.h>
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/net/types.h>
|
||||
#include <common/uri/gurl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fastocloud {
|
||||
|
||||
common::Optional<common::net::HostAndPort> GetHostAndPortFromGurl(const common::uri::GURL& url);
|
||||
|
||||
common::ErrnoError CreateAndCheckDir(const std::string& directory_path) WARN_UNUSED_RESULT;
|
||||
void RemoveOldFilesByTime(const common::file_system::ascii_directory_string_path& dir,
|
||||
common::utctime_t max_life_secs,
|
||||
const char* pattern,
|
||||
bool recursive = false);
|
||||
void RemoveFilesByExtension(const common::file_system::ascii_directory_string_path& dir, const char* ext);
|
||||
|
||||
common::Optional<std::string> GetAudioMasterUrlFromQuery(const std::string& query);
|
||||
|
||||
} // namespace fastocloud
|
391
src/server/CMakeLists.txt
Normal file
391
src/server/CMakeLists.txt
Normal file
|
@ -0,0 +1,391 @@
|
|||
# service variables
|
||||
SET(STREAMER_SERVICE_PORT 6317)
|
||||
SET(STREAMER_SERVICE_ALIAS "127.0.0.1")
|
||||
SET(STREAMER_SERVICE_HOST "${STREAMER_SERVICE_ALIAS}:${STREAMER_SERVICE_PORT}") # service endpoint
|
||||
SET(STREAMER_SERVICE_HLS_HOST "http://0.0.0.0:8000") # hls endpoint
|
||||
SET(STREAMER_SERVICE_VODS_HOST "http://0.0.0.0:7000") # vods endpoint
|
||||
SET(STREAMER_SERVICE_CODS_HOST "http://0.0.0.0:6000") # cods endpoint
|
||||
SET(STREAMER_SERVICE_CODS_TTL 600)
|
||||
SET(STREAMER_SERVICE_FILES_TTL 604800) #7 days (7 * 24 * 3600)
|
||||
SET(STREAMER_SERVICE_PYFASTOSTREAM_PATH "/usr/local/bin/pyfastostream")
|
||||
|
||||
SET(STREAMER_SERVICE_HLS_DIR "~/streamer/hls")
|
||||
SET(STREAMER_SERVICE_VODS_DIR "~/streamer/vods")
|
||||
SET(STREAMER_SERVICE_CODS_DIR "~/streamer/cods")
|
||||
SET(STREAMER_SERVICE_TIMESHIFTS_DIR "~/streamer/timeshifts")
|
||||
SET(STREAMER_SERVICE_FEEDBACK_DIR "~/streamer/feedback")
|
||||
SET(STREAMER_SERVICE_PROXY_DIR "~/streamer/proxy")
|
||||
SET(STREAMER_SERVICE_DATA_DIR "~/streamer/data")
|
||||
#
|
||||
SET(STREAMER_SERVICE_NAME_EXE ${STREAMER_SERVICE_NAME}_s)
|
||||
SET(STREAMER_EXE_NAME stream)
|
||||
|
||||
FIND_PACKAGE(Common REQUIRED)
|
||||
FIND_PACKAGE(FastoTvCPP REQUIRED)
|
||||
FIND_PACKAGE(JSON-C REQUIRED)
|
||||
FIND_PACKAGE(OpenSSL REQUIRED)
|
||||
|
||||
SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DHAVE_OPENSSL)
|
||||
|
||||
# platform specific
|
||||
IF(OS_WINDOWS)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES ws2_32 psapi)
|
||||
SET(RELATIVE_SOURCE_DIR .)
|
||||
ELSEIF(OS_LINUX)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES dl)
|
||||
SET(RELATIVE_SOURCE_DIR ..)
|
||||
|
||||
FIND_LIBRARY(UDEV_LIBRARY udev)
|
||||
FIND_PATH(UDEV_INCLUDE_DIR NAMES libudev.h)
|
||||
IF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${UDEV_LIBRARY})
|
||||
ENDIF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
|
||||
IF (PLATFORM_ARM)
|
||||
FIND_LIBRARY(ATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1)
|
||||
IF(ATOMIC_LIBRARY)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${ATOMIC_LIBRARY})
|
||||
ENDIF(ATOMIC_LIBRARY)
|
||||
ENDIF(PLATFORM_ARM)
|
||||
ELSEIF(OS_MACOSX)
|
||||
FIND_LIBRARY(FOUNDATION_LIBRARY Foundation)
|
||||
FIND_LIBRARY(IOKIT_LIBRARY IOKit)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} dl ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||
SET(RELATIVE_SOURCE_DIR ..)
|
||||
ELSEIF(OS_FREEBSD)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} dl)
|
||||
SET(RELATIVE_SOURCE_DIR ..)
|
||||
|
||||
FIND_LIBRARY(UDEV_LIBRARY udev)
|
||||
FIND_PATH(UDEV_INCLUDE_DIR NAMES libudev.h)
|
||||
IF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${UDEV_LIBRARY})
|
||||
ENDIF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
|
||||
ELSEIF(OS_POSIX)
|
||||
SET(PLATFORM_HEADER)
|
||||
SET(PLATFORM_SOURCES)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} udev dl)
|
||||
SET(RELATIVE_SOURCE_DIR ..)
|
||||
ENDIF(OS_WINDOWS)
|
||||
|
||||
IF(USE_PTHREAD)
|
||||
IF(NOT OS_ANDROID)
|
||||
SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} pthread)
|
||||
ENDIF(NOT OS_ANDROID)
|
||||
ENDIF(USE_PTHREAD)
|
||||
|
||||
SET(PIPE_HEADERS ${CMAKE_SOURCE_DIR}/src/server/pipe/client.h)
|
||||
SET(PIPE_SOURCES ${CMAKE_SOURCE_DIR}/src/server/pipe/client.cpp)
|
||||
|
||||
SET(TCP_HEADERS ${CMAKE_SOURCE_DIR}/src/server/tcp/client.h)
|
||||
SET(TCP_SOURCES ${CMAKE_SOURCE_DIR}/src/server/tcp/client.cpp)
|
||||
|
||||
SET(UTILS_HEADERS ${CMAKE_SOURCE_DIR}/src/server/utils/utils.h)
|
||||
SET(UTILS_SOURCES ${CMAKE_SOURCE_DIR}/src/server/utils/utils.cpp)
|
||||
|
||||
SET(OPTIONS_HEADERS ${CMAKE_SOURCE_DIR}/src/server/options/options.h)
|
||||
SET(OPTIONS_SOURCES ${CMAKE_SOURCE_DIR}/src/server/options/options.cpp)
|
||||
|
||||
SET(SERVER_HTTP_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/handler.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/client.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/server.h
|
||||
)
|
||||
|
||||
SET(SERVER_HTTP_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/handler.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/client.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/http/server.cpp
|
||||
)
|
||||
|
||||
SET(SERVER_DAEMON_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/client.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/server.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.h
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.h
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stream_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/start_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/quit_status_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/restart_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stop_info.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/get_log_info.h
|
||||
)
|
||||
|
||||
SET(SERVER_DAEMON_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/client.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/server.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.cpp
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.cpp
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stream_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/start_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/quit_status_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/restart_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stop_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/get_log_info.cpp
|
||||
)
|
||||
|
||||
SET(SERVER_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/server/base/iserver_handler.h
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/child.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/child_stream.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper.h
|
||||
${CMAKE_SOURCE_DIR}/src/server/config.h
|
||||
|
||||
${SERVER_HTTP_HEADERS}
|
||||
${SERVER_DAEMON_HEADERS}
|
||||
${PIPE_HEADERS}
|
||||
${TCP_HEADERS}
|
||||
${UTILS_HEADERS}
|
||||
${OPTIONS_HEADERS}
|
||||
)
|
||||
SET(SERVER_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/server/base/iserver_handler.cpp
|
||||
|
||||
${CMAKE_SOURCE_DIR}/src/server/child.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/child_stream.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/server/config.cpp
|
||||
|
||||
${SERVER_HTTP_SOURCES}
|
||||
${SERVER_DAEMON_SOURCES}
|
||||
${PIPE_SOURCES}
|
||||
${TCP_SOURCES}
|
||||
${UTILS_SOURCES}
|
||||
${OPTIONS_SOURCES}
|
||||
)
|
||||
|
||||
SET(PERF_OBSERVER_HEADERS
|
||||
${CMAKE_SOURCE_DIR}/src/server/gpu_stats/perf_monitor.h
|
||||
)
|
||||
SET(PERF_OBSERVER_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/server/gpu_stats/perf_monitor.cpp
|
||||
)
|
||||
|
||||
#gpu nvidia
|
||||
FIND_PACKAGE(NVML)
|
||||
IF(NVML_FOUND)
|
||||
SET(DAEMON_LIBRARIES ${DAEMON_LIBRARIES} ${NVML_LIBRARIES})
|
||||
SET(PERF_OBSERVER_HEADERS ${PERF_OBSERVER_HEADERS} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/nvidia_monitor.h)
|
||||
SET(PERF_OBSERVER_SOURCES ${PERF_OBSERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/nvidia_monitor.cpp)
|
||||
SET(PRIVATE_INCLUDE_DIRECTORIES_SLAVE ${PRIVATE_INCLUDE_DIRECTORIES_SLAVE} ${NVML_INCLUDE_DIRS})
|
||||
SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DHAVE_NVML)
|
||||
|
||||
# ibnvidia-ml.so.1
|
||||
GET_FILENAME_COMPONENT(NVML_LIBRARY_WITHOUT_SYMLINK ${NVML_LIBRARIES} REALPATH)
|
||||
GET_FILENAME_COMPONENT(NVML_LIBRARY_NAME ${NVML_LIBRARY_WITHOUT_SYMLINK} NAME)
|
||||
STRING(REGEX REPLACE "[^so]+$" ".1" NVML_LNNAME ${NVML_LIBRARY_NAME})
|
||||
#libSDL2-2.0.so.0
|
||||
INSTALL(FILES ${NVML_LIBRARY_WITHOUT_SYMLINK} DESTINATION ${LIB_INSTALL_DESTINATION} RENAME ${NVML_LNNAME} COMPONENT RUNTIME)
|
||||
ENDIF(NVML_FOUND)
|
||||
|
||||
#gpu intel
|
||||
SET(CTT_METRICS_PATH "/usr/local/share/mfx/samples/")
|
||||
FIND_LIBRARY(CTT_METRICS_LIBRARY NAMES cttmetrics PATHS ${CTT_METRICS_PATH})
|
||||
IF (CTT_METRICS_LIBRARY)
|
||||
SET(DAEMON_LIBRARIES ${DAEMON_LIBRARIES} ${CTT_METRICS_LIBRARY})
|
||||
SET(PERF_OBSERVER_HEADERS ${PERF_OBSERVER_HEADERS} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/intel_monitor.h)
|
||||
SET(PERF_OBSERVER_SOURCES ${PERF_OBSERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/intel_monitor.cpp)
|
||||
SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DHAVE_CTT_METRICS)
|
||||
INSTALL(FILES ${CTT_METRICS_LIBRARY} DESTINATION ${LIB_INSTALL_DESTINATION} COMPONENT RUNTIME)
|
||||
ENDIF(CTT_METRICS_LIBRARY)
|
||||
|
||||
#ssl libs install
|
||||
GET_FILENAME_COMPONENT(OPENSSL_CRYPTO_LIBRARY_SYMLINK ${OPENSSL_CRYPTO_LIBRARY} REALPATH)
|
||||
GET_FILENAME_COMPONENT(OPENSSL_CRYPTO_LIBRARY_NAME ${OPENSSL_CRYPTO_LIBRARY_SYMLINK} NAME)
|
||||
INSTALL(FILES ${OPENSSL_CRYPTO_LIBRARY_SYMLINK} DESTINATION ${LIB_INSTALL_DESTINATION} COMPONENT RUNTIME)
|
||||
|
||||
GET_FILENAME_COMPONENT(OPENSSL_SSL_LIBRARY_SYMLINK ${OPENSSL_SSL_LIBRARY} REALPATH)
|
||||
GET_FILENAME_COMPONENT(OPENSSL_SSL_LIBRARY_NAME ${OPENSSL_SSL_LIBRARY_SYMLINK} NAME)
|
||||
INSTALL(FILES ${OPENSSL_SSL_LIBRARY_SYMLINK} DESTINATION ${LIB_INSTALL_DESTINATION} COMPONENT RUNTIME)
|
||||
|
||||
#INSTALL(FILES ${OPENSSL_LIBRARIES} DESTINATION ${LIB_INSTALL_DESTINATION} COMPONENT RUNTIME)
|
||||
|
||||
IF(OS_POSIX)
|
||||
SET(SERVER_SOURCES ${SERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper_posix.cpp)
|
||||
ELSEIF(OS_WIN)
|
||||
SET(SERVER_SOURCES ${SERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper_win.cpp)
|
||||
ENDIF(OS_POSIX)
|
||||
|
||||
SET(DAEMON_SOURCES
|
||||
${SERVER_HEADERS} ${SERVER_SOURCES}
|
||||
${PERF_OBSERVER_HEADERS} ${PERF_OBSERVER_SOURCES}
|
||||
)
|
||||
SET(DAEMON_LIBRARIES
|
||||
${DAEMON_LIBRARIES}
|
||||
${FASTOTV_CPP_LIBRARIES}
|
||||
${COMMON_LIBRARIES}
|
||||
${JSONC_LIBRARIES}
|
||||
${PLATFORM_LIBRARIES}
|
||||
${STREAMER_COMMON}
|
||||
${OPENSSL_LIBRARIES}
|
||||
)
|
||||
SET(PRIVATE_INCLUDE_DIRECTORIES_SLAVE
|
||||
${PRIVATE_INCLUDE_DIRECTORIES_SLAVE}
|
||||
${FASTOTV_CPP_INCLUDE_DIRS}
|
||||
${COMMON_INCLUDE_DIRS}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
SET(CORE_LIBRARY ${LIB_INSTALL_DESTINATION}/${CMAKE_SHARED_LIBRARY_PREFIX}${STREAMER_CORE}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
|
||||
SET(RUN_DIR_PATH "/var/run/${STREAMER_SERVICE_NAME}")
|
||||
SET(PIDFILE_PATH "${RUN_DIR_PATH}/${STREAMER_SERVICE_NAME}.pid")
|
||||
SET(USER_NAME ${PROJECT_NAME_LOWERCASE})
|
||||
SET(USER_GROUP ${PROJECT_NAME_LOWERCASE})
|
||||
SET(CONFIG_PATH "/etc/${STREAMER_SERVICE_NAME}.conf")
|
||||
|
||||
SET(STREAM_DEFINITIONS
|
||||
-DRELATIVE_SOURCE_DIR="${RELATIVE_SOURCE_DIR}"
|
||||
-DCORE_LIBRARY="${CORE_LIBRARY}"
|
||||
-DSTREAMER_NAME="${STREAMER_NAME}"
|
||||
)
|
||||
|
||||
SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE
|
||||
${PRIVATE_COMPILE_DEFINITIONS_SLAVE}
|
||||
${STREAM_DEFINITIONS}
|
||||
-DCONFIG_PATH="${CONFIG_PATH}"
|
||||
-DPIDFILE_PATH="${PIDFILE_PATH}"
|
||||
-DSTREAMER_SERVICE_NAME="${STREAMER_SERVICE_NAME}"
|
||||
-DCLIENT_PORT=${STREAMER_SERVICE_PORT}
|
||||
|
||||
-DSTREAMER_SERVICE_HLS_HOST="${STREAMER_SERVICE_HLS_HOST}"
|
||||
-DSTREAMER_SERVICE_VODS_HOST="${STREAMER_SERVICE_VODS_HOST}"
|
||||
-DSTREAMER_SERVICE_CODS_HOST="${STREAMER_SERVICE_CODS_HOST}"
|
||||
|
||||
-DCODS_TTL=${STREAMER_SERVICE_CODS_TTL}
|
||||
-DFILES_TTL=${STREAMER_SERVICE_FILES_TTL}
|
||||
-DSTREAMER_SERVICE_PYFASTOSTREAM_PATH="${STREAMER_SERVICE_PYFASTOSTREAM_PATH}"
|
||||
|
||||
-DSTREAMER_SERVICE_ALIAS="${STREAMER_SERVICE_ALIAS}"
|
||||
-DSTREAMER_SERVICE_HLS_DIR="${STREAMER_SERVICE_HLS_DIR}"
|
||||
-DSTREAMER_SERVICE_VODS_DIR="${STREAMER_SERVICE_VODS_DIR}"
|
||||
-DSTREAMER_SERVICE_CODS_DIR="${STREAMER_SERVICE_CODS_DIR}"
|
||||
-DSTREAMER_SERVICE_TIMESHIFTS_DIR="${STREAMER_SERVICE_TIMESHIFTS_DIR}"
|
||||
-DSTREAMER_SERVICE_FEEDBACK_DIR="${STREAMER_SERVICE_FEEDBACK_DIR}"
|
||||
-DSTREAMER_SERVICE_PROXY_DIR="${STREAMER_SERVICE_PROXY_DIR}"
|
||||
-DSTREAMER_SERVICE_DATA_DIR="${STREAMER_SERVICE_DATA_DIR}"
|
||||
)
|
||||
|
||||
IF(OS_WIN)
|
||||
SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DSTREAMER_EXE_NAME="${STREAMER_EXE_NAME}")
|
||||
ENDIF(OS_WIN)
|
||||
|
||||
SET(EXE_DAEMON_SOURCES ${CMAKE_SOURCE_DIR}/src/server/daemon_slave.cpp)
|
||||
|
||||
ADD_EXECUTABLE(${STREAMER_SERVICE_NAME_EXE} ${DAEMON_SOURCES} ${EXE_DAEMON_SOURCES})
|
||||
TARGET_INCLUDE_DIRECTORIES(${STREAMER_SERVICE_NAME_EXE} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_SLAVE})
|
||||
TARGET_COMPILE_DEFINITIONS(${STREAMER_SERVICE_NAME_EXE} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE})
|
||||
TARGET_LINK_LIBRARIES(${STREAMER_SERVICE_NAME_EXE} ${DAEMON_LIBRARIES})
|
||||
|
||||
IF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
STRIP_TARGET(${STREAMER_SERVICE_NAME_EXE})
|
||||
ENDIF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
|
||||
INSTALL(TARGETS ${STREAMER_SERVICE_NAME_EXE} DESTINATION ${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS)
|
||||
|
||||
IF(OS_WIN)
|
||||
ADD_EXECUTABLE(${STREAMER_EXE_NAME} ${CMAKE_SOURCE_DIR}/src/server/stream_win.cpp ${TCP_SOURCES})
|
||||
TARGET_INCLUDE_DIRECTORIES(${STREAMER_EXE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
TARGET_COMPILE_DEFINITIONS(${STREAMER_EXE_NAME} PRIVATE ${STREAM_DEFINITIONS})
|
||||
TARGET_LINK_LIBRARIES(${STREAMER_EXE_NAME} ${COMMON_LIBRARIES} ${PLATFORM_LIBRARIES} ${STREAMER_COMMON} ${FASTOTV_CPP_LIBRARIES})
|
||||
|
||||
IF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
STRIP_TARGET(${STREAMER_EXE_NAME})
|
||||
ENDIF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
|
||||
INSTALL(TARGETS ${STREAMER_EXE_NAME} DESTINATION ${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS)
|
||||
ENDIF(OS_WIN)
|
||||
|
||||
SET(EXECUTABLE_FOLDER_PATH ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
||||
IF(OS_WINDOWS)
|
||||
ELSEIF(OS_MACOSX)
|
||||
ELSEIF(OS_LINUX OR OS_FREEBSD)
|
||||
SET(EXECUTABLE_PATH ${EXECUTABLE_FOLDER_PATH}/${STREAMER_SERVICE_NAME} CACHE INTERNAL "Daemon path: ${EXECUTABLE_PATH}")
|
||||
ENDIF(OS_WINDOWS)
|
||||
|
||||
# script
|
||||
SET(SERVICE_START_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME})
|
||||
GEN_START_SCRIPT(${SERVICE_START_SCRIPT_GEN_PATH} ${STREAMER_SERVICE_NAME_EXE})
|
||||
INSTALL(PROGRAMS ${SERVICE_START_SCRIPT_GEN_PATH} DESTINATION
|
||||
${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS
|
||||
)
|
||||
|
||||
# service
|
||||
IF(OS_LINUX OR OS_FREEBSD)
|
||||
SET(SERVICE_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.service)
|
||||
GEN_SERVICE_SERVICE_FILE(${SERVICE_SCRIPT_GEN_PATH}
|
||||
${STREAMER_SERVICE_NAME} ${STREAMER_SERVICE_NAME_EXE} forking
|
||||
${EXECUTABLE_PATH}
|
||||
${RUN_DIR_PATH}
|
||||
${PIDFILE_PATH}
|
||||
${USER_NAME} ${USER_GROUP}
|
||||
${PROJECT_SUMMARY}
|
||||
)
|
||||
INSTALL(FILES ${SERVICE_SCRIPT_GEN_PATH} DESTINATION /etc/systemd/system/)
|
||||
|
||||
SET(SERVICE_DEB_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.debian)
|
||||
GEN_DEBIAN_SERVICE_FILE(${SERVICE_DEB_SCRIPT_GEN_PATH}
|
||||
${STREAMER_SERVICE_NAME} ${STREAMER_SERVICE_NAME_EXE}
|
||||
${EXECUTABLE_PATH}
|
||||
${RUN_DIR_PATH}
|
||||
${PIDFILE_PATH}
|
||||
${USER_NAME} ${USER_GROUP}
|
||||
${PROJECT_SUMMARY}
|
||||
)
|
||||
INSTALL(FILES ${SERVICE_DEB_SCRIPT_GEN_PATH}
|
||||
DESTINATION /etc/init.d
|
||||
RENAME ${STREAMER_SERVICE_NAME}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
ENDIF(OS_LINUX OR OS_FREEBSD)
|
||||
|
||||
# config file
|
||||
SET(SERVICE_CONF_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.conf)
|
||||
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME_LOWERCASE}/service/service.conf.in
|
||||
${SERVICE_CONF_GEN_PATH} @ONLY IMMEDIATE
|
||||
)
|
||||
IF(NOT EXISTS ${CONFIG_PATH} OR CPACK_SUPPORT)
|
||||
INSTALL(FILES ${SERVICE_CONF_GEN_PATH} DESTINATION /etc/)
|
||||
ENDIF(NOT EXISTS ${CONFIG_PATH} OR CPACK_SUPPORT)
|
||||
|
||||
IF (DEVELOPER_CHECK_STYLE)
|
||||
SET(CHECK_SOURCES_DAEMON ${DAEMON_SOURCES} ${EXE_DAEMON_SOURCES})
|
||||
REGISTER_CHECK_STYLE_TARGET(check_style_${STREAMER_SERVICE_NAME} "${CHECK_SOURCES_DAEMON}")
|
||||
REGISTER_CHECK_INCLUDES_TARGET(${STREAMER_SERVICE_NAME_EXE})
|
||||
ENDIF(DEVELOPER_CHECK_STYLE)
|
||||
|
||||
IF(DEVELOPER_ENABLE_TESTS)
|
||||
FIND_PACKAGE(GTest REQUIRED)
|
||||
|
||||
## Unit tests
|
||||
SET(PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS
|
||||
${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
SET(UNIT_TESTS_LIBS
|
||||
${GTEST_BOTH_LIBRARIES}
|
||||
${STREAMER_COMMON}
|
||||
${PLATFORM_LIBRARIES})
|
||||
SET(UNIT_TESTS unit_tests_server)
|
||||
ADD_EXECUTABLE(${UNIT_TESTS}
|
||||
${CMAKE_SOURCE_DIR}/tests/server/unit_test_server.cpp ${OPTIONS_SOURCES}
|
||||
)
|
||||
TARGET_INCLUDE_DIRECTORIES(${UNIT_TESTS} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS} ${JSONC_INCLUDE_DIRS})
|
||||
TARGET_LINK_LIBRARIES(${UNIT_TESTS} ${UNIT_TESTS_LIBS} ${DAEMON_LIBRARIES})
|
||||
ADD_TEST_TARGET(${UNIT_TESTS})
|
||||
SET_PROPERTY(TARGET ${UNIT_TESTS} PROPERTY FOLDER "Unit tests")
|
||||
ENDIF(DEVELOPER_ENABLE_TESTS)
|
45
src/server/base/iserver_handler.cpp
Normal file
45
src/server/base/iserver_handler.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/base/iserver_handler.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace base {
|
||||
|
||||
IServerHandler::IServerHandler() : online_clients_(0) {}
|
||||
|
||||
size_t IServerHandler::GetOnlineClients() const {
|
||||
return online_clients_;
|
||||
}
|
||||
|
||||
void IServerHandler::Accepted(common::libev::IoClient* client) {
|
||||
UNUSED(client);
|
||||
online_clients_++;
|
||||
}
|
||||
|
||||
void IServerHandler::Moved(common::libev::IoLoop* server, common::libev::IoClient* client) {
|
||||
UNUSED(server);
|
||||
UNUSED(client);
|
||||
online_clients_--;
|
||||
}
|
||||
|
||||
void IServerHandler::Closed(common::libev::IoClient* client) {
|
||||
UNUSED(client);
|
||||
online_clients_--;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
51
src/server/base/iserver_handler.h
Normal file
51
src/server/base/iserver_handler.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/libev/io_loop_observer.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace base {
|
||||
|
||||
class IServerHandler : public common::libev::IoLoopObserver {
|
||||
public:
|
||||
typedef std::atomic<size_t> online_clients_t;
|
||||
IServerHandler();
|
||||
|
||||
size_t GetOnlineClients() const;
|
||||
|
||||
void PreLooped(common::libev::IoLoop* server) override = 0;
|
||||
|
||||
void Accepted(common::libev::IoClient* client) override;
|
||||
void Moved(common::libev::IoLoop* server, common::libev::IoClient* client) override;
|
||||
void Closed(common::libev::IoClient* client) override;
|
||||
void TimerEmited(common::libev::IoLoop* server, common::libev::timer_id_t id) override = 0;
|
||||
void Accepted(common::libev::IoChild* child) override = 0;
|
||||
void Moved(common::libev::IoLoop* server, common::libev::IoChild* child) override = 0;
|
||||
void ChildStatusChanged(common::libev::IoChild* child, int status, int signal) override = 0;
|
||||
|
||||
void DataReceived(common::libev::IoClient* client) override = 0;
|
||||
void DataReadyToWrite(common::libev::IoClient* client) override = 0;
|
||||
|
||||
void PostLooped(common::libev::IoLoop* server) override = 0;
|
||||
|
||||
private:
|
||||
online_clients_t online_clients_;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
91
src/server/child.cpp
Normal file
91
src/server/child.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/child.h"
|
||||
|
||||
#include <common/time.h>
|
||||
|
||||
#include "base/constants.h"
|
||||
|
||||
#include "stream_commands/commands_factory.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
Child::Child(common::libev::IoLoop* server)
|
||||
: IoChild(server), client_(nullptr), request_id_(0), last_update_(common::time::current_utc_mstime()) {}
|
||||
|
||||
Child::~Child() {}
|
||||
|
||||
Child::client_t* Child::GetClient() const {
|
||||
return client_;
|
||||
}
|
||||
|
||||
void Child::SetClient(client_t* pipe) {
|
||||
client_ = pipe;
|
||||
}
|
||||
|
||||
void Child::UpdateTimestamp() {
|
||||
last_update_ = common::time::current_utc_mstime();
|
||||
}
|
||||
|
||||
fastotv::timestamp_t Child::GetLastUpdate() const {
|
||||
return last_update_;
|
||||
}
|
||||
|
||||
common::ErrnoError Child::Stop() {
|
||||
if (!client_) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
fastotv::protocol::request_t req;
|
||||
common::Error err = StopStreamRequest(NextRequestID(), &req);
|
||||
if (err) {
|
||||
return common::make_errno_error(err->GetDescription(), EAGAIN);
|
||||
}
|
||||
return client_->WriteRequest(req);
|
||||
}
|
||||
|
||||
common::ErrnoError Child::Restart() {
|
||||
if (!client_) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
fastotv::protocol::request_t req;
|
||||
common::Error err = RestartStreamRequest(NextRequestID(), &req);
|
||||
if (err) {
|
||||
return common::make_errno_error(err->GetDescription(), EAGAIN);
|
||||
}
|
||||
return client_->WriteRequest(req);
|
||||
}
|
||||
|
||||
common::ErrnoError Child::Terminate() {
|
||||
#if defined(OS_POSIX)
|
||||
int result = kill(GetProcessID(), KILL_STREAM_SIGNAL);
|
||||
if (result != 0) {
|
||||
return common::make_errno_error(errno);
|
||||
}
|
||||
return common::ErrnoError();
|
||||
#else
|
||||
return common::make_errno_error("Not implemented", EAGAIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
fastotv::protocol::sequance_id_t Child::NextRequestID() {
|
||||
const fastotv::protocol::seq_id_t next_id = request_id_++;
|
||||
return common::protocols::json_rpc::MakeRequestID(next_id);
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
58
src/server/child.h
Normal file
58
src/server/child.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/libev/io_child.h>
|
||||
|
||||
#include <fastotv/protocol/protocol.h>
|
||||
#include <fastotv/protocol/types.h>
|
||||
#include <fastotv/types/input_uri.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
class Child : public common::libev::IoChild {
|
||||
public:
|
||||
typedef fastotv::protocol::protocol_client_t client_t;
|
||||
|
||||
virtual fastotv::stream_id_t GetStreamID() const = 0;
|
||||
|
||||
common::ErrnoError Stop() WARN_UNUSED_RESULT;
|
||||
common::ErrnoError Restart() WARN_UNUSED_RESULT;
|
||||
common::ErrnoError Terminate() WARN_UNUSED_RESULT;
|
||||
|
||||
client_t* GetClient() const;
|
||||
void SetClient(client_t* pipe);
|
||||
virtual ~Child();
|
||||
|
||||
void UpdateTimestamp();
|
||||
fastotv::timestamp_t GetLastUpdate() const;
|
||||
|
||||
protected:
|
||||
explicit Child(common::libev::IoLoop* server);
|
||||
|
||||
fastotv::protocol::sequance_id_t NextRequestID();
|
||||
|
||||
protected:
|
||||
client_t* client_;
|
||||
|
||||
private:
|
||||
std::atomic<fastotv::protocol::seq_id_t> request_id_;
|
||||
|
||||
fastotv::timestamp_t last_update_;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
55
src/server/child_stream.cpp
Normal file
55
src/server/child_stream.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/child_stream.h"
|
||||
|
||||
#include <common/file_system/file_system.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
ChildStream::ChildStream(common::libev::IoLoop* server, const StreamInfo& conf) : base_class(server), conf_(conf) {}
|
||||
|
||||
fastotv::stream_id_t ChildStream::GetStreamID() const {
|
||||
return conf_.id;
|
||||
}
|
||||
|
||||
fastotv::StreamType ChildStream::GetStreamType() const {
|
||||
return conf_.type;
|
||||
}
|
||||
|
||||
bool ChildStream::IsCOD() const {
|
||||
const fastotv::StreamType type = GetStreamType();
|
||||
return type == fastotv::COD_RELAY || type == fastotv::COD_ENCODE;
|
||||
}
|
||||
|
||||
void ChildStream::CleanUp() {
|
||||
if (conf_.type == fastotv::VOD_ENCODE || conf_.type == fastotv::VOD_RELAY || conf_.type == fastotv::CATCHUP ||
|
||||
conf_.type == fastotv::TIMESHIFT_RECORDER || conf_.type == fastotv::TEST_LIFE) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto out_uri : conf_.output) {
|
||||
auto ouri = out_uri.GetUrl();
|
||||
if (ouri.SchemeIsHTTPOrHTTPS()) {
|
||||
const auto http_root = out_uri.GetHttpRoot();
|
||||
if (http_root) {
|
||||
common::file_system::remove_directory(http_root->GetPath(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
40
src/server/child_stream.h
Normal file
40
src/server/child_stream.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/child.h"
|
||||
|
||||
#include "base/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
class ChildStream : public Child {
|
||||
public:
|
||||
typedef Child base_class;
|
||||
ChildStream(common::libev::IoLoop* server, const StreamInfo& conf);
|
||||
|
||||
fastotv::stream_id_t GetStreamID() const override;
|
||||
fastotv::StreamType GetStreamType() const;
|
||||
bool IsCOD() const;
|
||||
void CleanUp();
|
||||
|
||||
private:
|
||||
const StreamInfo conf_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ChildStream);
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
309
src/server/config.cpp
Normal file
309
src/server/config.cpp
Normal file
|
@ -0,0 +1,309 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/config.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <utility>
|
||||
|
||||
#include <common/convert2string.h>
|
||||
#include <common/file_system/path.h>
|
||||
#include <common/value.h>
|
||||
|
||||
#define SETTINGS_SECTION "[settings]"
|
||||
#define SERVICE_LOG_PATH_FIELD "log_path"
|
||||
#define SERVICE_LOG_LEVEL_FIELD "log_level"
|
||||
#define SERVICE_HOST_FIELD "host"
|
||||
#define SERVICE_ALIAS_FIELD "alias"
|
||||
|
||||
#define SERVICE_HLS_HOST_FIELD "hls_host"
|
||||
#define SERVICE_VODS_HOST_FIELD "vods_host"
|
||||
#define SERVICE_CODS_HOST_FIELD "cods_host"
|
||||
|
||||
#define SERVICE_HLS_DIR_FIELD "hls_dir"
|
||||
#define SERVICE_VODS_DIR_FIELD "vods_dir"
|
||||
#define SERVICE_CODS_DIR_FIELD "cods_dir"
|
||||
#define SERVICE_TIMESHIFTS_DIR_FIELD "timeshifts_dir"
|
||||
#define SERVICE_FEEDBACK_DIR_FIELD "feedback_dir"
|
||||
#define SERVICE_PROXY_DIR_FIELD "proxy_dir"
|
||||
#define SERVICE_DATA_DIR_FIELD "data_dir"
|
||||
|
||||
#define SERVICE_CODS_TTL_FIELD "cods_ttl"
|
||||
#define SERVICE_FILES_TTL_FIELD "files_ttl"
|
||||
#define SERVICE_PYFASTOSTREAM_PATH_FIELD "pyfastostream_path"
|
||||
#define SERVICE_REPORT_NODE_STATS_FIELD "report_node_stats"
|
||||
|
||||
#define DUMMY_LOG_FILE_PATH "/dev/null"
|
||||
#define REPORT_NODE_STATS 10
|
||||
|
||||
namespace {
|
||||
common::Optional<std::pair<std::string, std::string>> GetKeyValue(const std::string& line, char separator) {
|
||||
const size_t pos = line.find(separator);
|
||||
if (pos != std::string::npos) {
|
||||
const std::string key = line.substr(0, pos);
|
||||
const std::string value = line.substr(pos + 1);
|
||||
return std::make_pair(key, value);
|
||||
}
|
||||
|
||||
return common::Optional<std::pair<std::string, std::string>>();
|
||||
}
|
||||
|
||||
common::ErrnoError ReadConfigFile(const std::string& path, common::HashValue** args) {
|
||||
if (!args) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
if (path.empty()) {
|
||||
return common::make_errno_error("Invalid config path", EINVAL);
|
||||
}
|
||||
|
||||
std::ifstream config(path);
|
||||
if (!config.is_open()) {
|
||||
return common::make_errno_error("Failed to open config file", EINVAL);
|
||||
}
|
||||
|
||||
common::HashValue* options = new common::HashValue;
|
||||
std::string line;
|
||||
while (getline(config, line)) {
|
||||
if (line == SETTINGS_SECTION) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto kv = GetKeyValue(line, '=');
|
||||
if (!kv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto pair = *kv;
|
||||
if (pair.first == SERVICE_LOG_PATH_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_LOG_LEVEL_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_HOST_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_ALIAS_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_HLS_HOST_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_VODS_HOST_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_CODS_HOST_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_HLS_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_VODS_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_CODS_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_TIMESHIFTS_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_FEEDBACK_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_PROXY_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_DATA_DIR_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_PYFASTOSTREAM_PATH_FIELD) {
|
||||
options->Insert(pair.first, common::Value::CreateStringValueFromBasicString(pair.second));
|
||||
} else if (pair.first == SERVICE_CODS_TTL_FIELD) {
|
||||
common::utctime_t ttl;
|
||||
if (common::ConvertFromString(pair.second, &ttl)) {
|
||||
options->Insert(pair.first, common::Value::CreateTimeValue(ttl));
|
||||
}
|
||||
} else if (pair.first == SERVICE_FILES_TTL_FIELD) {
|
||||
common::utctime_t ttl;
|
||||
if (common::ConvertFromString(pair.second, &ttl)) {
|
||||
options->Insert(pair.first, common::Value::CreateTimeValue(ttl));
|
||||
}
|
||||
} else if (pair.first == SERVICE_REPORT_NODE_STATS_FIELD) {
|
||||
common::utctime_t report;
|
||||
if (common::ConvertFromString(pair.second, &report)) {
|
||||
options->Insert(pair.first, common::Value::CreateTimeValue(report));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*args = options;
|
||||
return common::ErrnoError();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
Config::Config()
|
||||
: host(GetDefaultHost()),
|
||||
log_path(DUMMY_LOG_FILE_PATH),
|
||||
log_level(common::logging::LOG_LEVEL_INFO),
|
||||
hls_dir(STREAMER_SERVICE_HLS_DIR),
|
||||
vods_dir(STREAMER_SERVICE_VODS_DIR),
|
||||
cods_dir(STREAMER_SERVICE_CODS_DIR),
|
||||
timeshifts_dir(STREAMER_SERVICE_TIMESHIFTS_DIR),
|
||||
feedback_dir(STREAMER_SERVICE_FEEDBACK_DIR),
|
||||
proxy_dir(STREAMER_SERVICE_PROXY_DIR),
|
||||
data_dir(STREAMER_SERVICE_DATA_DIR),
|
||||
pyfastostream_path(STREAMER_SERVICE_PYFASTOSTREAM_PATH),
|
||||
cods_ttl(CODS_TTL),
|
||||
files_ttl(FILES_TTL),
|
||||
report_node(REPORT_NODE_STATS) {}
|
||||
|
||||
common::net::HostAndPort Config::GetDefaultHost() {
|
||||
return common::net::HostAndPort::CreateLocalHostIPV4(CLIENT_PORT);
|
||||
}
|
||||
|
||||
bool Config::IsValid() const {
|
||||
return host.IsValid();
|
||||
}
|
||||
|
||||
common::ErrnoError load_config_from_file(const std::string& config_absolute_path, Config* config) {
|
||||
if (!config) {
|
||||
return common::make_errno_error_inval();
|
||||
}
|
||||
|
||||
Config lconfig;
|
||||
common::HashValue* slave_config_args = nullptr;
|
||||
common::ErrnoError err = ReadConfigFile(config_absolute_path, &slave_config_args);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
common::Value* log_path_field = slave_config_args->Find(SERVICE_LOG_PATH_FIELD);
|
||||
if (!log_path_field || !log_path_field->GetAsBasicString(&lconfig.log_path)) {
|
||||
lconfig.log_path = DUMMY_LOG_FILE_PATH;
|
||||
}
|
||||
|
||||
std::string level_str;
|
||||
common::logging::LOG_LEVEL level = common::logging::LOG_LEVEL_INFO;
|
||||
common::Value* level_field = slave_config_args->Find(SERVICE_LOG_LEVEL_FIELD);
|
||||
if (level_field && level_field->GetAsBasicString(&level_str)) {
|
||||
if (!common::logging::text_to_log_level(level_str.c_str(), &level)) {
|
||||
level = common::logging::LOG_LEVEL_INFO;
|
||||
}
|
||||
}
|
||||
lconfig.log_level = level;
|
||||
|
||||
common::Value* host_field = slave_config_args->Find(SERVICE_HOST_FIELD);
|
||||
std::string host_str;
|
||||
if (!host_field || !host_field->GetAsBasicString(&host_str) || !common::ConvertFromString(host_str, &lconfig.host)) {
|
||||
lconfig.host = Config::GetDefaultHost();
|
||||
}
|
||||
|
||||
common::Value* alias_field = slave_config_args->Find(SERVICE_ALIAS_FIELD);
|
||||
if (!alias_field || !alias_field->GetAsBasicString(&lconfig.alias)) {
|
||||
lconfig.alias = STREAMER_SERVICE_ALIAS;
|
||||
}
|
||||
|
||||
common::Value* http_host_field = slave_config_args->Find(SERVICE_HLS_HOST_FIELD);
|
||||
std::string http_host_str;
|
||||
if (http_host_field && http_host_field->GetAsBasicString(&http_host_str)) {
|
||||
common::uri::GURL gurl(http_host_str);
|
||||
if (gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS()) {
|
||||
lconfig.hls_host = gurl;
|
||||
} else {
|
||||
lconfig.hls_host = common::uri::GURL(SERVICE_HLS_HOST_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
common::Value* vods_host_field = slave_config_args->Find(SERVICE_VODS_HOST_FIELD);
|
||||
std::string vods_host_str;
|
||||
if (vods_host_field && vods_host_field->GetAsBasicString(&vods_host_str)) {
|
||||
common::uri::GURL gurl(vods_host_str);
|
||||
if (gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS()) {
|
||||
lconfig.vods_host = gurl;
|
||||
} else {
|
||||
lconfig.vods_host = common::uri::GURL(SERVICE_VODS_HOST_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
common::Value* cods_host_field = slave_config_args->Find(SERVICE_CODS_HOST_FIELD);
|
||||
std::string cods_host_str;
|
||||
if (cods_host_field && cods_host_field->GetAsBasicString(&cods_host_str)) {
|
||||
common::uri::GURL gurl(cods_host_str);
|
||||
if (gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS()) {
|
||||
lconfig.cods_host = gurl;
|
||||
} else {
|
||||
lconfig.cods_host = common::uri::GURL(SERVICE_CODS_HOST_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
common::Value* hls_field = slave_config_args->Find(SERVICE_HLS_DIR_FIELD);
|
||||
if (!hls_field || !hls_field->GetAsBasicString(&lconfig.hls_dir)) {
|
||||
lconfig.hls_dir = STREAMER_SERVICE_HLS_DIR;
|
||||
}
|
||||
lconfig.hls_dir = common::file_system::stable_dir_path(lconfig.hls_dir);
|
||||
|
||||
common::Value* vods_field = slave_config_args->Find(SERVICE_VODS_DIR_FIELD);
|
||||
if (!vods_field || !vods_field->GetAsBasicString(&lconfig.vods_dir)) {
|
||||
lconfig.vods_dir = STREAMER_SERVICE_VODS_DIR;
|
||||
}
|
||||
lconfig.vods_dir = common::file_system::stable_dir_path(lconfig.vods_dir);
|
||||
|
||||
common::Value* cods_field = slave_config_args->Find(SERVICE_CODS_DIR_FIELD);
|
||||
if (!cods_field || !cods_field->GetAsBasicString(&lconfig.cods_dir)) {
|
||||
lconfig.cods_dir = STREAMER_SERVICE_CODS_DIR;
|
||||
}
|
||||
lconfig.cods_dir = common::file_system::stable_dir_path(lconfig.cods_dir);
|
||||
|
||||
common::Value* timeshifts_field = slave_config_args->Find(SERVICE_TIMESHIFTS_DIR_FIELD);
|
||||
if (!timeshifts_field || !timeshifts_field->GetAsBasicString(&lconfig.timeshifts_dir)) {
|
||||
lconfig.timeshifts_dir = STREAMER_SERVICE_TIMESHIFTS_DIR;
|
||||
}
|
||||
lconfig.timeshifts_dir = common::file_system::stable_dir_path(lconfig.timeshifts_dir);
|
||||
|
||||
common::Value* feedback_field = slave_config_args->Find(SERVICE_FEEDBACK_DIR_FIELD);
|
||||
if (!feedback_field || !feedback_field->GetAsBasicString(&lconfig.feedback_dir)) {
|
||||
lconfig.feedback_dir = STREAMER_SERVICE_FEEDBACK_DIR;
|
||||
}
|
||||
lconfig.feedback_dir = common::file_system::stable_dir_path(lconfig.feedback_dir);
|
||||
|
||||
common::Value* proxy_field = slave_config_args->Find(SERVICE_PROXY_DIR_FIELD);
|
||||
if (!proxy_field || !proxy_field->GetAsBasicString(&lconfig.proxy_dir)) {
|
||||
lconfig.proxy_dir = STREAMER_SERVICE_PROXY_DIR;
|
||||
}
|
||||
lconfig.proxy_dir = common::file_system::stable_dir_path(lconfig.proxy_dir);
|
||||
|
||||
common::Value* data_field = slave_config_args->Find(SERVICE_DATA_DIR_FIELD);
|
||||
if (!data_field || !data_field->GetAsBasicString(&lconfig.data_dir)) {
|
||||
lconfig.data_dir = STREAMER_SERVICE_DATA_DIR;
|
||||
}
|
||||
lconfig.data_dir = common::file_system::stable_dir_path(lconfig.data_dir);
|
||||
|
||||
common::Value* PyFastoStream_field = slave_config_args->Find(SERVICE_PYFASTOSTREAM_PATH_FIELD);
|
||||
if (!PyFastoStream_field || !PyFastoStream_field->GetAsBasicString(&lconfig.pyfastostream_path)) {
|
||||
lconfig.pyfastostream_path = STREAMER_SERVICE_PYFASTOSTREAM_PATH;
|
||||
}
|
||||
lconfig.pyfastostream_path = common::file_system::prepare_path(lconfig.pyfastostream_path);
|
||||
|
||||
common::Value* cods_ttl_field = slave_config_args->Find(SERVICE_CODS_TTL_FIELD);
|
||||
if (!cods_ttl_field || !cods_ttl_field->GetAsTime(&lconfig.cods_ttl)) {
|
||||
lconfig.cods_ttl = CODS_TTL;
|
||||
}
|
||||
|
||||
common::Value* files_ttl_field = slave_config_args->Find(SERVICE_FILES_TTL_FIELD);
|
||||
if (!files_ttl_field || !files_ttl_field->GetAsTime(&lconfig.files_ttl)) {
|
||||
lconfig.files_ttl = FILES_TTL;
|
||||
}
|
||||
|
||||
common::Value* report_node_stats_field = slave_config_args->Find(SERVICE_REPORT_NODE_STATS_FIELD);
|
||||
if (!report_node_stats_field || !report_node_stats_field->GetAsTime(&lconfig.report_node)) {
|
||||
lconfig.report_node = REPORT_NODE_STATS;
|
||||
}
|
||||
|
||||
*config = lconfig;
|
||||
delete slave_config_args;
|
||||
return common::ErrnoError();
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
63
src/server/config.h
Normal file
63
src/server/config.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/error.h>
|
||||
#include <common/net/types.h>
|
||||
#include <common/types.h>
|
||||
#include <common/uri/gurl.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
struct Config {
|
||||
typedef common::utctime_t seconds_t;
|
||||
|
||||
Config();
|
||||
|
||||
static common::net::HostAndPort GetDefaultHost();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
common::net::HostAndPort host;
|
||||
std::string alias;
|
||||
|
||||
std::string log_path;
|
||||
common::logging::LOG_LEVEL log_level;
|
||||
// info
|
||||
common::uri::GURL hls_host;
|
||||
common::uri::GURL vods_host;
|
||||
common::uri::GURL cods_host;
|
||||
|
||||
std::string hls_dir;
|
||||
std::string vods_dir;
|
||||
std::string cods_dir;
|
||||
std::string timeshifts_dir;
|
||||
std::string feedback_dir;
|
||||
std::string proxy_dir;
|
||||
std::string data_dir;
|
||||
|
||||
std::string pyfastostream_path;
|
||||
seconds_t cods_ttl;
|
||||
seconds_t files_ttl;
|
||||
seconds_t report_node;
|
||||
};
|
||||
|
||||
common::ErrnoError load_config_from_file(const std::string& config_absolute_path, Config* config) WARN_UNUSED_RESULT;
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
271
src/server/daemon/client.cpp
Normal file
271
src/server/daemon/client.cpp
Normal file
|
@ -0,0 +1,271 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "server/daemon/client.h"
|
||||
|
||||
#include "server/daemon/commands_factory.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
ProtocoledDaemonClient::ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info)
|
||||
: base_class(std::make_shared<fastotv::protocol::FastoTVCompressor>(), server, info) {}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StopMe() {
|
||||
const common::daemon::commands::StopInfo stop_req;
|
||||
fastotv::protocol::request_t req;
|
||||
common::Error err_ser = StopServiceRequest(NextRequestID(), stop_req, &req);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteRequest(req);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::RestartMe() {
|
||||
const common::daemon::commands::RestartInfo stop_req;
|
||||
fastotv::protocol::request_t req;
|
||||
common::Error err_ser = RestartServiceRequest(NextRequestID(), stop_req, &req);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteRequest(req);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StopFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StopServiceResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StopSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StopServiceResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::Ping() {
|
||||
common::daemon::commands::ClientPingInfo server_ping_info;
|
||||
return Ping(server_ping_info);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::Ping(const common::daemon::commands::ClientPingInfo& server_ping_info) {
|
||||
fastotv::protocol::request_t ping_request;
|
||||
common::Error err_ser = PingRequest(NextRequestID(), server_ping_info, &ping_request);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteRequest(ping_request);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::PongFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = PingServiceResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::Pong(fastotv::protocol::sequance_id_t id) {
|
||||
common::daemon::commands::ServerPingInfo server_ping_info;
|
||||
return Pong(id, server_ping_info);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::Pong(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ServerPingInfo& pong) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = PingServiceResponseSuccess(id, pong, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::ActivateFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = ActivateResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::ActivateSuccess(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& result) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = ActivateResponseSuccess(id, result, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetLogServiceFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetLogServiceResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetLogServiceSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetLogServiceResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetLogStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetLogStreamResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetLogStreamSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetLogStreamResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetPipeStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetPipeStreamResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::GetPipeStreamSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = GetPipeStreamResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StartStreamResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StartStreamSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StartStreamResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::ReStartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = RestartStreamResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::ReStartStreamSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = RestartStreamResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StopStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) {
|
||||
const std::string error_str = err->GetDescription();
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StopStreamResponseFail(id, error_str, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::StopStreamSuccess(fastotv::protocol::sequance_id_t id) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = StopStreamResponseSuccess(id, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
common::ErrnoError ProtocoledDaemonClient::UnknownMethodError(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& method) {
|
||||
fastotv::protocol::response_t resp;
|
||||
common::Error err_ser = UnknownMethodResponse(id, method, &resp);
|
||||
if (err_ser) {
|
||||
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
|
||||
}
|
||||
|
||||
return WriteResponse(resp);
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
75
src/server/daemon/client.h
Normal file
75
src/server/daemon/client.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/daemon/client.h>
|
||||
#include <common/daemon/commands/license_info.h>
|
||||
#include <common/daemon/commands/ping_info.h>
|
||||
#include <common/license/types.h>
|
||||
|
||||
#include <fastotv/protocol/protocol.h>
|
||||
#include <fastotv/protocol/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
class ProtocoledDaemonClient : public fastotv::protocol::ProtocolClient<common::daemon::DaemonClient> {
|
||||
public:
|
||||
typedef fastotv::protocol::ProtocolClient<common::daemon::DaemonClient> base_class;
|
||||
ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info);
|
||||
|
||||
common::ErrnoError StopMe() WARN_UNUSED_RESULT;
|
||||
common::ErrnoError RestartMe() WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError StopFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError StopSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError Ping() WARN_UNUSED_RESULT;
|
||||
common::ErrnoError Ping(const common::daemon::commands::ClientPingInfo& server_ping_info) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError PongFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError Pong(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError Pong(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ServerPingInfo& pong) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError ActivateFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError ActivateSuccess(fastotv::protocol::sequance_id_t id, const std::string& result) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError GetLogServiceFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError GetLogServiceSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError GetLogStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError GetLogStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError GetPipeStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError GetPipeStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError StartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError StartStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError ReStartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError ReStartStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError StopStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT;
|
||||
common::ErrnoError StopStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT;
|
||||
|
||||
common::ErrnoError UnknownMethodError(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& method) WARN_UNUSED_RESULT;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
94
src/server/daemon/commands.cpp
Normal file
94
src/server/daemon/commands.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params, fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string changed_json;
|
||||
common::Error err_ser = params.SerializeToString(&changed_json);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
*req = fastotv::protocol::request_t::MakeNotification(STREAM_CHANGED_SOURCES_STREAM, changed_json);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StatisitcStreamBroadcast(const StatisticInfo& params, fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string stat_json;
|
||||
common::Error err_ser = params.SerializeToString(&stat_json);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
*req = fastotv::protocol::request_t::MakeNotification(STREAM_STATISTIC_STREAM, stat_json);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
#if defined(MACHINE_LEARNING)
|
||||
common::Error MlNotificationStreamBroadcast(const fastotv::commands_info::ml::NotificationInfo& params,
|
||||
fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string stat_json;
|
||||
common::Error err_ser = params.SerializeToString(&stat_json);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
*req = fastotv::protocol::request_t::MakeNotification(STREAM_ML_NOTIFICATION_STREAM, stat_json);
|
||||
return common::Error();
|
||||
}
|
||||
#endif
|
||||
|
||||
common::Error StatisitcServiceBroadcast(fastotv::protocol::serializet_params_t params,
|
||||
fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*req = fastotv::protocol::request_t::MakeNotification(STREAM_STATISTIC_SERVICE, params);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string quit_json;
|
||||
common::Error err_ser = params.SerializeToString(&quit_json);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
*req = fastotv::protocol::request_t::MakeNotification(STREAM_QUIT_STATUS_STREAM, quit_json);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
72
src/server/daemon/commands.h
Normal file
72
src/server/daemon/commands.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fastotv/protocol/types.h>
|
||||
|
||||
#if defined(MACHINE_LEARNING)
|
||||
#include <fastotv/commands_info/ml/notification_info.h>
|
||||
#endif
|
||||
|
||||
#include "server/daemon/commands_info/stream/quit_status_info.h"
|
||||
#include "stream_commands/commands_info/changed_sources_info.h"
|
||||
#include "stream_commands/commands_info/statistic_info.h"
|
||||
|
||||
// daemon
|
||||
// client commands
|
||||
|
||||
#define DAEMON_START_STREAM "start_stream" // {"config": {...}, "command_line": {...} }
|
||||
#define DAEMON_STOP_STREAM "stop_stream"
|
||||
#define DAEMON_RESTART_STREAM "restart_stream"
|
||||
#define DAEMON_GET_LOG_STREAM "get_log_stream"
|
||||
#define DAEMON_GET_PIPELINE_STREAM "get_pipeline_stream"
|
||||
|
||||
#define DAEMON_ACTIVATE "activate_request" // {"key": "XXXXXXXXXXXXXXXXXX"}
|
||||
#define DAEMON_STOP_SERVICE "stop_service" // {"delay": 0 }
|
||||
#define DAEMON_RESTART_SERVICE "restart_service" // {"delay": 0 }
|
||||
|
||||
#define DAEMON_GET_CONFIG_JSON_STREAM "get_config_json_stream"
|
||||
#define DAEMON_PING_SERVICE "ping_service"
|
||||
#define DAEMON_GET_LOG_SERVICE "get_log_service" // {"path":"http://localhost/service/id"}
|
||||
|
||||
#define DAEMON_SERVER_PING "ping_client"
|
||||
|
||||
// Broadcast
|
||||
#define STREAM_CHANGED_SOURCES_STREAM "changed_source_stream"
|
||||
#define STREAM_STATISTIC_STREAM "statistic_stream"
|
||||
#define STREAM_QUIT_STATUS_STREAM "quit_status_stream"
|
||||
#if defined(MACHINE_LEARNING)
|
||||
#define STREAM_ML_NOTIFICATION_STREAM "ml_notification_stream"
|
||||
#endif
|
||||
#define STREAM_STATISTIC_SERVICE "statistic_service"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
// Broadcast
|
||||
common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params, fastotv::protocol::request_t* req);
|
||||
common::Error StatisitcStreamBroadcast(const StatisticInfo& params, fastotv::protocol::request_t* req);
|
||||
#if defined(MACHINE_LEARNING)
|
||||
common::Error MlNotificationStreamBroadcast(const fastotv::commands_info::ml::NotificationInfo& params,
|
||||
fastotv::protocol::request_t* req);
|
||||
#endif
|
||||
common::Error StatisitcServiceBroadcast(fastotv::protocol::serializet_params_t params,
|
||||
fastotv::protocol::request_t* req);
|
||||
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, fastotv::protocol::request_t* req);
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
311
src/server/daemon/commands_factory.cpp
Normal file
311
src/server/daemon/commands_factory.cpp
Normal file
|
@ -0,0 +1,311 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_factory.h"
|
||||
|
||||
#include <common/sprintf.h>
|
||||
|
||||
#include "server/daemon/commands.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
common::Error StopServiceRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::StopInfo& params,
|
||||
fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string req_str;
|
||||
common::Error err_ser = params.SerializeToString(&req_str);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
fastotv::protocol::request_t lreq;
|
||||
lreq.id = id;
|
||||
lreq.method = DAEMON_STOP_SERVICE;
|
||||
lreq.params = req_str;
|
||||
*req = lreq;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error RestartServiceRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::RestartInfo& params,
|
||||
fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string req_str;
|
||||
common::Error err_ser = params.SerializeToString(&req_str);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
fastotv::protocol::request_t lreq;
|
||||
lreq.id = id;
|
||||
lreq.method = DAEMON_RESTART_SERVICE;
|
||||
lreq.params = req_str;
|
||||
*req = lreq;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error PingRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ClientPingInfo& params,
|
||||
fastotv::protocol::request_t* req) {
|
||||
if (!req) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string req_str;
|
||||
common::Error err_ser = params.SerializeToString(&req_str);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
fastotv::protocol::request_t lreq;
|
||||
lreq.id = id;
|
||||
lreq.method = DAEMON_SERVER_PING;
|
||||
lreq.params = req_str;
|
||||
*req = lreq;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StopServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StopServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetLogServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetLogServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error ActivateResponseSuccess(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& result,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeMessage(
|
||||
id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage(result));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error ActivateResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StartStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StopStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StopStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error RestartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error RestartStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetLogStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetLogStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetPipeStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetPipeStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error PingServiceResponseSuccess(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ServerPingInfo& ping,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
std::string ping_server_json;
|
||||
common::Error err_ser = ping.SerializeToString(&ping_server_json);
|
||||
if (err_ser) {
|
||||
return err_ser;
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeMessage(
|
||||
id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage(ping_server_json));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error PingServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp = fastotv::protocol::response_t::MakeError(
|
||||
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error UnknownMethodResponse(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& method,
|
||||
fastotv::protocol::response_t* resp) {
|
||||
if (!resp) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*resp =
|
||||
fastotv::protocol::response_t::MakeError(id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(
|
||||
common::MemSPrintf("Unknown method: %s", method)));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
96
src/server/daemon/commands_factory.h
Normal file
96
src/server/daemon/commands_factory.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/daemon/commands/activate_info.h>
|
||||
#include <common/daemon/commands/ping_info.h>
|
||||
#include <common/daemon/commands/restart_info.h>
|
||||
#include <common/daemon/commands/stop_info.h>
|
||||
|
||||
#include <fastotv/protocol/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
// requests
|
||||
common::Error StopServiceRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::StopInfo& params,
|
||||
fastotv::protocol::request_t* req);
|
||||
common::Error RestartServiceRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::RestartInfo& params,
|
||||
fastotv::protocol::request_t* req);
|
||||
common::Error PingRequest(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ClientPingInfo& params,
|
||||
fastotv::protocol::request_t* req);
|
||||
|
||||
// responses service
|
||||
common::Error StopServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error StopServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error GetLogServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error GetLogServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error ActivateResponseSuccess(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& result,
|
||||
fastotv::protocol::response_t* resp);
|
||||
common::Error ActivateResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error PingServiceResponseSuccess(fastotv::protocol::sequance_id_t id,
|
||||
const common::daemon::commands::ServerPingInfo& ping,
|
||||
fastotv::protocol::response_t* resp);
|
||||
common::Error PingServiceResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error UnknownMethodResponse(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& method,
|
||||
fastotv::protocol::response_t* resp) WARN_UNUSED_RESULT;
|
||||
|
||||
// responces streams
|
||||
common::Error StartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error StartStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error StopStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error StopStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error RestartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error RestartStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error GetLogStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error GetLogStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
common::Error GetPipeStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
|
||||
common::Error GetPipeStreamResponseFail(fastotv::protocol::sequance_id_t id,
|
||||
const std::string& error_text,
|
||||
fastotv::protocol::response_t* resp);
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
216
src/server/daemon/commands_info/service/details/shots.cpp
Normal file
216
src/server/daemon/commands_info/service/details/shots.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/service/details/shots.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX) || defined(OS_FREEBSD)
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include <common/system_info/system_info.h>
|
||||
#include <common/time.h>
|
||||
|
||||
#define CPU_FORMAT "cpu %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
|
||||
|
||||
#if defined(OS_WIN)
|
||||
namespace {
|
||||
|
||||
uint64_t FiletimeToInt(const FILETIME& ft) {
|
||||
ULARGE_INTEGER i;
|
||||
i.LowPart = ft.dwLowDateTime;
|
||||
i.HighPart = ft.dwHighDateTime;
|
||||
return i.QuadPart;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace service {
|
||||
|
||||
double GetCpuMachineLoad(const CpuShot& prev, const CpuShot& next) {
|
||||
double total = next.cpu_limit - prev.cpu_limit;
|
||||
if (total == 0.0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double busy = next.cpu_usage - prev.cpu_usage;
|
||||
return (busy / total) * 100;
|
||||
}
|
||||
|
||||
CpuShot GetMachineCpuShot() {
|
||||
uint64_t busy = 0, total = 0;
|
||||
#if defined(OS_LINUX)
|
||||
FILE* fp = fopen("/proc/stat", "r");
|
||||
uint64_t user, nice, system, idle;
|
||||
if (fscanf(fp, CPU_FORMAT, &user, &nice, &system, &idle) != 4) {
|
||||
// Something bad happened with the information, so assume it's all invalid
|
||||
user = nice = system = idle = 0;
|
||||
}
|
||||
fclose(fp);
|
||||
busy = user + nice + system;
|
||||
total = busy + idle;
|
||||
#elif defined(OS_MACOSX)
|
||||
host_cpu_load_info_data_t cpuinfo;
|
||||
mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
|
||||
if (host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpuinfo, &count) == KERN_SUCCESS) {
|
||||
for (int i = 0; i < CPU_STATE_MAX; i++) {
|
||||
total += cpuinfo.cpu_ticks[i];
|
||||
}
|
||||
busy = total - cpuinfo.cpu_ticks[CPU_STATE_IDLE];
|
||||
}
|
||||
#elif defined(OS_WINDOWS)
|
||||
FILETIME idle, kernel, user;
|
||||
if (GetSystemTimes(&idle, &kernel, &user) != 0) {
|
||||
total = FiletimeToInt(kernel) + FiletimeToInt(user);
|
||||
busy = total - FiletimeToInt(idle);
|
||||
}
|
||||
#else
|
||||
#pragma message "Please implement"
|
||||
#endif
|
||||
return {busy, total};
|
||||
}
|
||||
|
||||
MemoryShot::MemoryShot() : ram_bytes_total(0), ram_bytes_free(0) {}
|
||||
|
||||
MemoryShot GetMachineMemoryShot() {
|
||||
MemoryShot shot;
|
||||
const auto total = common::system_info::AmountOfTotalRAM();
|
||||
if (total) {
|
||||
shot.ram_bytes_total = *total;
|
||||
}
|
||||
const auto avail = common::system_info::AmountOfAvailableRAM();
|
||||
if (avail) {
|
||||
shot.ram_bytes_free = *avail;
|
||||
}
|
||||
return shot;
|
||||
}
|
||||
|
||||
HddShot::HddShot() : hdd_bytes_total(0), hdd_bytes_free(0) {}
|
||||
|
||||
HddShot GetMachineHddShot() {
|
||||
HddShot sh;
|
||||
const auto total = common::system_info::AmountOfTotalDiskSpace("/");
|
||||
if (total) {
|
||||
sh.hdd_bytes_total = *total;
|
||||
}
|
||||
const auto avail = common::system_info::AmountOfFreeDiskSpace("/");
|
||||
if (avail) {
|
||||
sh.hdd_bytes_free = *avail;
|
||||
}
|
||||
return sh;
|
||||
}
|
||||
|
||||
NetShot::NetShot() : bytes_recv(0), bytes_send(0) {}
|
||||
|
||||
NetShot GetMachineNetShot() {
|
||||
NetShot shot;
|
||||
#if defined(OS_LINUX)
|
||||
FILE* netinfo = fopen("/proc/net/dev", "r");
|
||||
if (!netinfo) {
|
||||
return shot;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
char interf[128] = {0};
|
||||
int pos = 0;
|
||||
while (fgets(line, sizeof(line), netinfo)) {
|
||||
// face |bytes packets errs drop fifo frame compressed multicast|
|
||||
// bytes packets errs drop fifo colls carrier compressed
|
||||
if (pos > 1) {
|
||||
unsigned long long int r_bytes, r_packets, r_errs, r_drop, r_fifo, r_frame, r_compressed, r_multicast;
|
||||
unsigned long long int s_bytes, s_packets, s_errs, s_drop, s_fifo, s_colls, s_carrier, s_compressed;
|
||||
sscanf(line,
|
||||
"%s %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu "
|
||||
"%16llu %16llu %16llu "
|
||||
"%16llu %16llu %16llu %16llu %16llu",
|
||||
interf, &r_bytes, &r_packets, &r_errs, &r_drop, &r_fifo, &r_frame, &r_compressed, &r_multicast, &s_bytes,
|
||||
&s_packets, &s_errs, &s_drop, &s_fifo, &s_colls, &s_carrier, &s_compressed);
|
||||
if (strncmp(interf, "lo", 2) != 0) {
|
||||
shot.bytes_recv += r_bytes;
|
||||
shot.bytes_send += s_bytes;
|
||||
}
|
||||
memset(interf, 0, sizeof(interf));
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
||||
fclose(netinfo);
|
||||
return shot;
|
||||
#else
|
||||
#pragma message "Please implement"
|
||||
return shot;
|
||||
#endif
|
||||
}
|
||||
|
||||
SysinfoShot::SysinfoShot() : loads{0}, uptime(0) {}
|
||||
|
||||
SysinfoShot GetMachineSysinfoShot() {
|
||||
SysinfoShot inf;
|
||||
#if defined(OS_LINUX)
|
||||
struct sysinfo info;
|
||||
int res = sysinfo(&info);
|
||||
if (res == ERROR_RESULT_VALUE) {
|
||||
return inf;
|
||||
}
|
||||
|
||||
memcpy(&inf.loads, &info.loads, sizeof(unsigned long) * SIZEOFMASS(info.loads));
|
||||
inf.uptime = info.uptime;
|
||||
return inf;
|
||||
#elif defined(OS_MACOSX) || defined(OS_FREEBSD)
|
||||
struct loadavg load;
|
||||
size_t load_len = sizeof(load);
|
||||
if (sysctlbyname("vm.loadavg", &load, &load_len, nullptr, 0) < 0) {
|
||||
return inf;
|
||||
}
|
||||
inf.loads[0] = load.ldavg[0] / load.fscale;
|
||||
inf.loads[1] = load.ldavg[1] / load.fscale;
|
||||
inf.loads[2] = load.ldavg[2] / load.fscale;
|
||||
|
||||
struct timeval boottime;
|
||||
size_t boottime_len = sizeof(boottime);
|
||||
if (sysctlbyname("kern.boottime", &boottime, &boottime_len, nullptr, 0) < 0) {
|
||||
return inf;
|
||||
}
|
||||
inf.uptime = (common::time::current_utc_mstime() - common::time::timeval2mstime(&boottime)) / 1000;
|
||||
return inf;
|
||||
#else
|
||||
#pragma message "Please implement"
|
||||
return inf;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace service
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
71
src/server/daemon/commands_info/service/details/shots.h
Normal file
71
src/server/daemon/commands_info/service/details/shots.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <common/error.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace service {
|
||||
|
||||
struct CpuShot {
|
||||
uint64_t cpu_usage;
|
||||
uint64_t cpu_limit;
|
||||
};
|
||||
|
||||
double GetCpuMachineLoad(const CpuShot& prev, const CpuShot& next);
|
||||
CpuShot GetMachineCpuShot();
|
||||
|
||||
struct MemoryShot {
|
||||
MemoryShot();
|
||||
|
||||
size_t ram_bytes_total;
|
||||
size_t ram_bytes_free;
|
||||
};
|
||||
|
||||
MemoryShot GetMachineMemoryShot();
|
||||
|
||||
struct HddShot {
|
||||
HddShot();
|
||||
|
||||
size_t hdd_bytes_total;
|
||||
size_t hdd_bytes_free;
|
||||
};
|
||||
|
||||
HddShot GetMachineHddShot();
|
||||
|
||||
struct NetShot {
|
||||
NetShot();
|
||||
|
||||
size_t bytes_recv;
|
||||
size_t bytes_send;
|
||||
};
|
||||
|
||||
NetShot GetMachineNetShot();
|
||||
|
||||
struct SysinfoShot {
|
||||
SysinfoShot();
|
||||
|
||||
unsigned long loads[3];
|
||||
time_t uptime;
|
||||
};
|
||||
|
||||
SysinfoShot GetMachineSysinfoShot();
|
||||
|
||||
} // namespace service
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
298
src/server/daemon/commands_info/service/server_info.cpp
Normal file
298
src/server/daemon/commands_info/service/server_info.cpp
Normal file
|
@ -0,0 +1,298 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/service/server_info.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/system_info/system_info.h>
|
||||
|
||||
#define ONLINE_USERS_FIELD "online_users"
|
||||
|
||||
#define OS_FIELD "os"
|
||||
#define PROJECT_FIELD "project"
|
||||
#define VERSION_FIELD "version"
|
||||
#define HLS_HOST_FIELD "hls_host"
|
||||
#define VODS_HOST_FIELD "vods_host"
|
||||
#define CODS_HOST_FIELD "cods_host"
|
||||
#define EXPIRATION_TIME_FIELD "expiration_time"
|
||||
|
||||
#define VSYSTEM_FIELD "vsystem"
|
||||
#define VROLE_FIELD "vrole"
|
||||
|
||||
#define HLS_DIR_FIELD "hls_dir"
|
||||
#define VODS_DIR_FIELD "vods_dir"
|
||||
#define CODS_DIR_FIELD "cods_dir"
|
||||
#define TIMESHIFTS_DIR_FIELD "timeshifts_dir"
|
||||
#define FEEDBACK_DIR_FIELD "feedback_dir"
|
||||
#define DATA_DIR_FIELD "data_dir"
|
||||
|
||||
#define ONLINE_USERS_DAEMON_FIELD "daemon"
|
||||
#define ONLINE_USERS_HTTP_FIELD "http"
|
||||
#define ONLINE_USERS_VODS_FIELD "vods"
|
||||
#define ONLINE_USERS_CODS_FIELD "cods"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace service {
|
||||
|
||||
OnlineUsers::OnlineUsers() : OnlineUsers(0, 0, 0, 0) {}
|
||||
|
||||
OnlineUsers::OnlineUsers(size_t daemon, size_t http, size_t vods, size_t cods)
|
||||
: daemon_(daemon), http_(http), vods_(vods), cods_(cods) {}
|
||||
|
||||
common::Error OnlineUsers::DoDeSerialize(json_object* serialized) {
|
||||
uint64_t daemon;
|
||||
ignore_result(GetUint64Field(serialized, ONLINE_USERS_DAEMON_FIELD, &daemon));
|
||||
|
||||
uint64_t http;
|
||||
ignore_result(GetUint64Field(serialized, ONLINE_USERS_HTTP_FIELD, &http));
|
||||
|
||||
uint64_t vods;
|
||||
ignore_result(GetUint64Field(serialized, ONLINE_USERS_VODS_FIELD, &vods));
|
||||
|
||||
uint64_t cods;
|
||||
ignore_result(GetUint64Field(serialized, ONLINE_USERS_CODS_FIELD, &cods));
|
||||
|
||||
*this = OnlineUsers(daemon, http, vods, cods);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error OnlineUsers::SerializeFields(json_object* out) const {
|
||||
ignore_result(SetUInt64Field(out, ONLINE_USERS_DAEMON_FIELD, daemon_));
|
||||
ignore_result(SetUInt64Field(out, ONLINE_USERS_HTTP_FIELD, http_));
|
||||
ignore_result(SetUInt64Field(out, ONLINE_USERS_VODS_FIELD, vods_));
|
||||
ignore_result(SetUInt64Field(out, ONLINE_USERS_CODS_FIELD, cods_));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
ServerInfo::ServerInfo() : base_class(), online_users_() {}
|
||||
|
||||
ServerInfo::ServerInfo(cpu_load_t cpu_load,
|
||||
gpu_load_t gpu_load,
|
||||
const std::string& load_average,
|
||||
size_t ram_bytes_total,
|
||||
size_t ram_bytes_free,
|
||||
size_t hdd_bytes_total,
|
||||
size_t hdd_bytes_free,
|
||||
fastotv::bandwidth_t net_bytes_recv,
|
||||
fastotv::bandwidth_t net_bytes_send,
|
||||
time_t uptime,
|
||||
fastotv::timestamp_t timestamp,
|
||||
const OnlineUsers& online_users,
|
||||
size_t net_total_bytes_recv,
|
||||
size_t net_total_bytes_send)
|
||||
: base_class(cpu_load,
|
||||
gpu_load,
|
||||
load_average,
|
||||
ram_bytes_total,
|
||||
ram_bytes_free,
|
||||
hdd_bytes_total,
|
||||
hdd_bytes_free,
|
||||
net_bytes_recv,
|
||||
net_bytes_send,
|
||||
uptime,
|
||||
timestamp,
|
||||
net_total_bytes_recv,
|
||||
net_total_bytes_send),
|
||||
online_users_(online_users) {}
|
||||
|
||||
common::Error ServerInfo::SerializeFields(json_object* out) const {
|
||||
common::Error err = base_class::SerializeFields(out);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
json_object* obj = nullptr;
|
||||
err = online_users_.Serialize(&obj);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ignore_result(SetObjectField(out, ONLINE_USERS_FIELD, obj));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error ServerInfo::DoDeSerialize(json_object* serialized) {
|
||||
ServerInfo inf;
|
||||
common::Error err = inf.base_class::DoDeSerialize(serialized);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
json_object* jonline = nullptr;
|
||||
json_bool jonline_exists = json_object_object_get_ex(serialized, ONLINE_USERS_FIELD, &jonline);
|
||||
if (jonline_exists) {
|
||||
common::Error err = inf.online_users_.DeSerialize(jonline);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
*this = inf;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
OnlineUsers ServerInfo::GetOnlineUsers() const {
|
||||
return online_users_;
|
||||
}
|
||||
|
||||
FullServiceInfo::FullServiceInfo()
|
||||
: base_class(),
|
||||
http_host_(),
|
||||
project_(PROJECT_NAME_LOWERCASE),
|
||||
proj_ver_(PROJECT_VERSION_HUMAN),
|
||||
os_(fastotv::commands_info::OperationSystemInfo::MakeOSSnapshot()),
|
||||
vsystem_(common::system_info::VirtualizationSystem()),
|
||||
vrole_(common::system_info::VirtualizationRole()) {}
|
||||
|
||||
FullServiceInfo::FullServiceInfo(const host_t& http_host,
|
||||
const host_t& vods_host,
|
||||
const host_t& cods_host,
|
||||
common::time64_t exp_time,
|
||||
const std::string& hls_dir,
|
||||
const std::string& vods_dir,
|
||||
const std::string& cods_dir,
|
||||
const std::string& timeshifts_dir,
|
||||
const std::string& feedback_dir,
|
||||
const std::string& proxy_dir,
|
||||
const std::string& data_dir,
|
||||
const base_class& base)
|
||||
: base_class(base),
|
||||
http_host_(http_host),
|
||||
vods_host_(vods_host),
|
||||
cods_host_(cods_host),
|
||||
exp_time_(exp_time),
|
||||
hls_dir_(hls_dir),
|
||||
vods_dir_(vods_dir),
|
||||
cods_dir_(cods_dir),
|
||||
timeshifts_dir_(timeshifts_dir),
|
||||
feedback_dir_(feedback_dir),
|
||||
proxy_dir_(proxy_dir),
|
||||
data_dir_(data_dir),
|
||||
project_(PROJECT_NAME_LOWERCASE),
|
||||
proj_ver_(PROJECT_VERSION_HUMAN),
|
||||
os_(fastotv::commands_info::OperationSystemInfo::MakeOSSnapshot()),
|
||||
vsystem_(common::system_info::VirtualizationSystem()),
|
||||
vrole_(common::system_info::VirtualizationRole()) {}
|
||||
|
||||
FullServiceInfo::host_t FullServiceInfo::GetHttpHost() const {
|
||||
return http_host_;
|
||||
}
|
||||
|
||||
FullServiceInfo::host_t FullServiceInfo::GetVodsHost() const {
|
||||
return vods_host_;
|
||||
}
|
||||
|
||||
FullServiceInfo::host_t FullServiceInfo::GetCodsHost() const {
|
||||
return cods_host_;
|
||||
}
|
||||
|
||||
std::string FullServiceInfo::GetProject() const {
|
||||
return project_;
|
||||
}
|
||||
|
||||
std::string FullServiceInfo::GetProjectVersion() const {
|
||||
return proj_ver_;
|
||||
}
|
||||
|
||||
std::string FullServiceInfo::GetVsystem() const {
|
||||
return vsystem_;
|
||||
}
|
||||
|
||||
std::string FullServiceInfo::GetVrole() const {
|
||||
return vrole_;
|
||||
}
|
||||
|
||||
common::Error FullServiceInfo::DoDeSerialize(json_object* serialized) {
|
||||
FullServiceInfo inf;
|
||||
common::Error err = inf.base_class::DoDeSerialize(serialized);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
json_object* jos;
|
||||
err = GetObjectField(serialized, OS_FIELD, &jos);
|
||||
if (!err) {
|
||||
common::Error err = inf.os_.DeSerialize(jos);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
std::string http_host;
|
||||
err = GetStringField(serialized, HLS_HOST_FIELD, &http_host);
|
||||
if (!err) {
|
||||
inf.http_host_ = host_t(http_host);
|
||||
}
|
||||
|
||||
std::string vods_host;
|
||||
err = GetStringField(serialized, VODS_HOST_FIELD, &vods_host);
|
||||
if (!err) {
|
||||
inf.vods_host_ = host_t(vods_host);
|
||||
}
|
||||
|
||||
std::string cods_host;
|
||||
err = GetStringField(serialized, CODS_HOST_FIELD, &cods_host);
|
||||
if (!err) {
|
||||
inf.cods_host_ = host_t(cods_host);
|
||||
}
|
||||
|
||||
ignore_result(GetInt64Field(serialized, EXPIRATION_TIME_FIELD, &inf.exp_time_));
|
||||
ignore_result(GetStringField(serialized, HLS_DIR_FIELD, &inf.hls_dir_));
|
||||
ignore_result(GetStringField(serialized, VODS_DIR_FIELD, &inf.vods_dir_));
|
||||
ignore_result(GetStringField(serialized, CODS_DIR_FIELD, &inf.cods_dir_));
|
||||
ignore_result(GetStringField(serialized, TIMESHIFTS_DIR_FIELD, &inf.timeshifts_dir_));
|
||||
ignore_result(GetStringField(serialized, FEEDBACK_DIR_FIELD, &inf.feedback_dir_));
|
||||
ignore_result(GetStringField(serialized, DATA_DIR_FIELD, &inf.data_dir_));
|
||||
ignore_result(GetStringField(serialized, PROJECT_FIELD, &inf.project_));
|
||||
ignore_result(GetStringField(serialized, VERSION_FIELD, &inf.proj_ver_));
|
||||
ignore_result(GetStringField(serialized, VSYSTEM_FIELD, &inf.vsystem_));
|
||||
ignore_result(GetStringField(serialized, VROLE_FIELD, &inf.vrole_));
|
||||
|
||||
*this = inf;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error FullServiceInfo::SerializeFields(json_object* out) const {
|
||||
json_object* jos = nullptr;
|
||||
common::Error err = os_.Serialize(&jos);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
std::string http_host_str = http_host_.spec();
|
||||
std::string vods_host_str = vods_host_.spec();
|
||||
std::string cods_host_str = cods_host_.spec();
|
||||
ignore_result(SetStringField(out, HLS_HOST_FIELD, http_host_str));
|
||||
ignore_result(SetStringField(out, VODS_HOST_FIELD, vods_host_str));
|
||||
ignore_result(SetStringField(out, CODS_HOST_FIELD, cods_host_str));
|
||||
ignore_result(SetInt64Field(out, EXPIRATION_TIME_FIELD, exp_time_));
|
||||
ignore_result(SetStringField(out, HLS_DIR_FIELD, hls_dir_));
|
||||
ignore_result(SetStringField(out, VODS_DIR_FIELD, vods_dir_));
|
||||
ignore_result(SetStringField(out, CODS_DIR_FIELD, cods_dir_));
|
||||
ignore_result(SetStringField(out, TIMESHIFTS_DIR_FIELD, timeshifts_dir_));
|
||||
ignore_result(SetStringField(out, FEEDBACK_DIR_FIELD, feedback_dir_));
|
||||
ignore_result(SetStringField(out, DATA_DIR_FIELD, data_dir_));
|
||||
ignore_result(SetStringField(out, VERSION_FIELD, proj_ver_));
|
||||
ignore_result(SetStringField(out, PROJECT_FIELD, project_));
|
||||
ignore_result(SetObjectField(out, OS_FIELD, jos));
|
||||
ignore_result(SetStringField(out, VSYSTEM_FIELD, vsystem_));
|
||||
ignore_result(SetStringField(out, VROLE_FIELD, vrole_));
|
||||
return base_class::SerializeFields(out);
|
||||
}
|
||||
|
||||
} // namespace service
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
130
src/server/daemon/commands_info/service/server_info.h
Normal file
130
src/server/daemon/commands_info/service/server_info.h
Normal file
|
@ -0,0 +1,130 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fastotv/commands_info/machine_info.h>
|
||||
|
||||
#include <common/uri/gurl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace service {
|
||||
|
||||
class OnlineUsers : public common::serializer::JsonSerializer<OnlineUsers> {
|
||||
public:
|
||||
typedef JsonSerializer<OnlineUsers> base_class;
|
||||
OnlineUsers();
|
||||
explicit OnlineUsers(size_t daemon, size_t http, size_t vods, size_t cods);
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
size_t daemon_;
|
||||
size_t http_;
|
||||
size_t vods_;
|
||||
size_t cods_;
|
||||
};
|
||||
|
||||
class ServerInfo : public fastotv::commands_info::MachineInfo {
|
||||
public:
|
||||
typedef fastotv::commands_info::MachineInfo base_class;
|
||||
ServerInfo();
|
||||
ServerInfo(cpu_load_t cpu_load,
|
||||
gpu_load_t gpu_load,
|
||||
const std::string& load_average,
|
||||
size_t ram_bytes_total,
|
||||
size_t ram_bytes_free,
|
||||
size_t hdd_bytes_total,
|
||||
size_t hdd_bytes_free,
|
||||
fastotv::bandwidth_t net_bytes_recv,
|
||||
fastotv::bandwidth_t net_bytes_send,
|
||||
time_t uptime,
|
||||
fastotv::timestamp_t timestamp,
|
||||
const OnlineUsers& online_users,
|
||||
size_t net_total_bytes_recv,
|
||||
size_t net_total_bytes_send);
|
||||
|
||||
OnlineUsers GetOnlineUsers() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
OnlineUsers online_users_;
|
||||
};
|
||||
|
||||
class FullServiceInfo : public ServerInfo {
|
||||
public:
|
||||
typedef ServerInfo base_class;
|
||||
typedef common::uri::GURL host_t;
|
||||
|
||||
FullServiceInfo();
|
||||
explicit FullServiceInfo(const host_t& http_host,
|
||||
const host_t& vods_host,
|
||||
const host_t& cods_host,
|
||||
common::time64_t exp_time,
|
||||
const std::string& hls_dir,
|
||||
const std::string& vods_dir,
|
||||
const std::string& cods_dir,
|
||||
const std::string& timeshifts_dir,
|
||||
const std::string& feedback_dir,
|
||||
const std::string& proxy_dir,
|
||||
const std::string& data_dir,
|
||||
const base_class& base);
|
||||
|
||||
host_t GetHttpHost() const;
|
||||
host_t GetVodsHost() const;
|
||||
host_t GetCodsHost() const;
|
||||
|
||||
std::string GetProject() const;
|
||||
std::string GetProjectVersion() const;
|
||||
|
||||
std::string GetVsystem() const;
|
||||
std::string GetVrole() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
host_t http_host_;
|
||||
host_t vods_host_;
|
||||
host_t cods_host_;
|
||||
common::time64_t exp_time_;
|
||||
|
||||
std::string hls_dir_;
|
||||
std::string vods_dir_;
|
||||
std::string cods_dir_;
|
||||
std::string timeshifts_dir_;
|
||||
std::string feedback_dir_;
|
||||
std::string proxy_dir_;
|
||||
std::string data_dir_;
|
||||
|
||||
std::string project_;
|
||||
std::string proj_ver_;
|
||||
fastotv::commands_info::OperationSystemInfo os_;
|
||||
|
||||
std::string vsystem_;
|
||||
std::string vrole_;
|
||||
};
|
||||
|
||||
} // namespace service
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
73
src/server/daemon/commands_info/stream/get_log_info.cpp
Normal file
73
src/server/daemon/commands_info/stream/get_log_info.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/get_log_info.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#define PATH_FIELD "path"
|
||||
#define FEEDBACK_DIR_FIELD "feedback_directory"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
GetLogInfo::GetLogInfo() : base_class(), feedback_dir_(), path_() {}
|
||||
|
||||
GetLogInfo::GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir, const url_t& path)
|
||||
: base_class(stream_id), feedback_dir_(feedback_dir), path_(path) {}
|
||||
|
||||
GetLogInfo::url_t GetLogInfo::GetLogPath() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
std::string GetLogInfo::GetFeedbackDir() const {
|
||||
return feedback_dir_;
|
||||
}
|
||||
|
||||
common::Error GetLogInfo::DoDeSerialize(json_object* serialized) {
|
||||
GetLogInfo inf;
|
||||
common::Error err = inf.base_class::DoDeSerialize(serialized);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
std::string feedback_dir;
|
||||
err = GetStringField(serialized, FEEDBACK_DIR_FIELD, &feedback_dir);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
inf.feedback_dir_ = feedback_dir;
|
||||
|
||||
std::string path;
|
||||
err = GetStringField(serialized, PATH_FIELD, &path);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
inf.path_ = url_t(path);
|
||||
|
||||
*this = inf;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error GetLogInfo::SerializeFields(json_object* out) const {
|
||||
const std::string path_str = path_.spec();
|
||||
ignore_result(SetStringField(out, PATH_FIELD, path_str));
|
||||
ignore_result(SetStringField(out, FEEDBACK_DIR_FIELD, feedback_dir_));
|
||||
return base_class::SerializeFields(out);
|
||||
}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
52
src/server/daemon/commands_info/stream/get_log_info.h
Normal file
52
src/server/daemon/commands_info/stream/get_log_info.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/uri/gurl.h>
|
||||
|
||||
#include "server/daemon/commands_info/stream/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class GetLogInfo : public StreamInfo {
|
||||
public:
|
||||
typedef StreamInfo base_class;
|
||||
typedef common::uri::GURL url_t;
|
||||
|
||||
GetLogInfo();
|
||||
explicit GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir, const url_t& log_path);
|
||||
|
||||
url_t GetLogPath() const;
|
||||
std::string GetFeedbackDir() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
std::string feedback_dir_;
|
||||
url_t path_;
|
||||
};
|
||||
|
||||
typedef GetLogInfo GetPipelineInfo;
|
||||
typedef GetLogInfo GetConfigJsonInfo;
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
70
src/server/daemon/commands_info/stream/quit_status_info.cpp
Normal file
70
src/server/daemon/commands_info/stream/quit_status_info.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/quit_status_info.h"
|
||||
|
||||
#define QUIT_STATUS_INFO_SIGNAL_FIELD "signal"
|
||||
#define QUIT_STATUS_INFO_EXIT_STATUS_FIELD "exit_status"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
QuitStatusInfo::QuitStatusInfo() : base_class(), exit_status_(), signal_() {}
|
||||
|
||||
QuitStatusInfo::QuitStatusInfo(fastotv::stream_id_t stream_id, int exit_status, int signal)
|
||||
: base_class(stream_id), exit_status_(exit_status), signal_(signal) {}
|
||||
|
||||
int QuitStatusInfo::GetSignal() const {
|
||||
return signal_;
|
||||
}
|
||||
|
||||
int QuitStatusInfo::GetExitStatus() const {
|
||||
return exit_status_;
|
||||
}
|
||||
|
||||
common::Error QuitStatusInfo::DoDeSerialize(json_object* serialized) {
|
||||
QuitStatusInfo inf;
|
||||
common::Error err = inf.base_class::DoDeSerialize(serialized);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
int sig;
|
||||
err = GetIntField(serialized, QUIT_STATUS_INFO_SIGNAL_FIELD, &sig);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
int exit_status;
|
||||
err = GetIntField(serialized, QUIT_STATUS_INFO_EXIT_STATUS_FIELD, &exit_status);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
inf.signal_ = sig;
|
||||
inf.exit_status_ = exit_status;
|
||||
*this = inf;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error QuitStatusInfo::SerializeFields(json_object* out) const {
|
||||
ignore_result(SetIntField(out, QUIT_STATUS_INFO_SIGNAL_FIELD, signal_));
|
||||
ignore_result(SetIntField(out, QUIT_STATUS_INFO_EXIT_STATUS_FIELD, exit_status_));
|
||||
return base_class::SerializeFields(out);
|
||||
}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
44
src/server/daemon/commands_info/stream/quit_status_info.h
Normal file
44
src/server/daemon/commands_info/stream/quit_status_info.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/daemon/commands_info/stream/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class QuitStatusInfo : public StreamInfo {
|
||||
public:
|
||||
typedef StreamInfo base_class;
|
||||
|
||||
QuitStatusInfo();
|
||||
explicit QuitStatusInfo(fastotv::stream_id_t stream_id, int exit_status, int signal);
|
||||
|
||||
int GetSignal() const;
|
||||
int GetExitStatus() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
int exit_status_;
|
||||
int signal_;
|
||||
};
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
27
src/server/daemon/commands_info/stream/restart_info.cpp
Normal file
27
src/server/daemon/commands_info/stream/restart_info.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/restart_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
RestartInfo::RestartInfo() : base_class() {}
|
||||
|
||||
RestartInfo::RestartInfo(const fastotv::stream_id_t& stream_id) : base_class(stream_id) {}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
33
src/server/daemon/commands_info/stream/restart_info.h
Normal file
33
src/server/daemon/commands_info/stream/restart_info.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/daemon/commands_info/stream/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class RestartInfo : public StreamInfo {
|
||||
public:
|
||||
typedef StreamInfo base_class;
|
||||
|
||||
RestartInfo();
|
||||
explicit RestartInfo(const fastotv::stream_id_t& stream_id);
|
||||
};
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
64
src/server/daemon/commands_info/stream/start_info.cpp
Normal file
64
src/server/daemon/commands_info/stream/start_info.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/start_info.h"
|
||||
|
||||
#include "base/stream_config_parse.h"
|
||||
|
||||
#define START_INFO_CONFIG_FIELD "config"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
StartInfo::StartInfo() : base_class(), config_() {}
|
||||
|
||||
StartInfo::StartInfo(const config_t& config) : config_(config) {}
|
||||
|
||||
StartInfo::config_t StartInfo::GetConfig() const {
|
||||
return config_;
|
||||
}
|
||||
|
||||
common::Error StartInfo::DoDeSerialize(json_object* serialized) {
|
||||
if (!serialized) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
json_object* jconfig;
|
||||
common::Error err = GetObjectField(serialized, START_INFO_CONFIG_FIELD, &jconfig);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
config_t conf = MakeConfigFromJson(jconfig);
|
||||
if (!conf) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
*this = StartInfo(conf);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StartInfo::SerializeFields(json_object*) const {
|
||||
if (!config_) {
|
||||
return common::make_error_inval();
|
||||
}
|
||||
|
||||
NOTREACHED() << "Not need";
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
44
src/server/daemon/commands_info/stream/start_info.h
Normal file
44
src/server/daemon/commands_info/stream/start_info.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
|
||||
#include "base/stream_config.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class StartInfo : public common::serializer::JsonSerializer<StartInfo> {
|
||||
public:
|
||||
typedef common::serializer::JsonSerializer<StartInfo> base_class;
|
||||
typedef StreamConfig config_t;
|
||||
StartInfo();
|
||||
explicit StartInfo(const config_t& config);
|
||||
|
||||
config_t GetConfig() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
config_t config_;
|
||||
};
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
56
src/server/daemon/commands_info/stream/stop_info.cpp
Normal file
56
src/server/daemon/commands_info/stream/stop_info.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/stop_info.h"
|
||||
|
||||
#define FORCE_FIELD "force"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
StopInfo::StopInfo() : base_class(), force_(false) {}
|
||||
|
||||
StopInfo::StopInfo(const fastotv::stream_id_t& stream_id, bool force) : base_class(stream_id), force_(force) {}
|
||||
|
||||
bool StopInfo::GetForce() const {
|
||||
return force_;
|
||||
}
|
||||
|
||||
common::Error StopInfo::DoDeSerialize(json_object* serialized) {
|
||||
StopInfo res;
|
||||
common::Error err = res.base_class::DoDeSerialize(serialized);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
bool force;
|
||||
err = GetBoolField(serialized, FORCE_FIELD, &force);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
res.force_ = force;
|
||||
*this = res;
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StopInfo::SerializeFields(json_object* out) const {
|
||||
ignore_result(SetBoolField(out, FORCE_FIELD, force_));
|
||||
return base_class::SerializeFields(out);
|
||||
}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
41
src/server/daemon/commands_info/stream/stop_info.h
Normal file
41
src/server/daemon/commands_info/stream/stop_info.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/daemon/commands_info/stream/stream_info.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class StopInfo : public StreamInfo {
|
||||
public:
|
||||
typedef StreamInfo base_class;
|
||||
StopInfo();
|
||||
explicit StopInfo(const fastotv::stream_id_t& stream_id, bool force);
|
||||
|
||||
bool GetForce() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
bool force_;
|
||||
};
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
49
src/server/daemon/commands_info/stream/stream_info.cpp
Normal file
49
src/server/daemon/commands_info/stream/stream_info.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/commands_info/stream/stream_info.h"
|
||||
|
||||
#define ID_FIELD "id"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
StreamInfo::StreamInfo() : base_class(), stream_id_() {}
|
||||
|
||||
StreamInfo::StreamInfo(const fastotv::stream_id_t& stream_id) : stream_id_(stream_id) {}
|
||||
|
||||
fastotv::stream_id_t StreamInfo::GetStreamID() const {
|
||||
return stream_id_;
|
||||
}
|
||||
|
||||
common::Error StreamInfo::DoDeSerialize(json_object* serialized) {
|
||||
fastotv::stream_id_t sid;
|
||||
common::Error err = GetStringField(serialized, ID_FIELD, &sid);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
*this = StreamInfo(sid);
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
common::Error StreamInfo::SerializeFields(json_object* out) const {
|
||||
ignore_result(SetStringField(out, ID_FIELD, stream_id_));
|
||||
return common::Error();
|
||||
}
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
45
src/server/daemon/commands_info/stream/stream_info.h
Normal file
45
src/server/daemon/commands_info/stream/stream_info.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <common/serializer/json_serializer.h>
|
||||
|
||||
#include <fastotv/types.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace stream {
|
||||
|
||||
class StreamInfo : public common::serializer::JsonSerializer<StreamInfo> {
|
||||
public:
|
||||
typedef JsonSerializer<StreamInfo> base_class;
|
||||
StreamInfo();
|
||||
explicit StreamInfo(const fastotv::stream_id_t& stream_id);
|
||||
|
||||
std::string GetStreamID() const;
|
||||
|
||||
protected:
|
||||
common::Error DoDeSerialize(json_object* serialized) override;
|
||||
common::Error SerializeFields(json_object* out) const override;
|
||||
|
||||
private:
|
||||
fastotv::stream_id_t stream_id_;
|
||||
};
|
||||
|
||||
} // namespace stream
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
31
src/server/daemon/server.cpp
Normal file
31
src/server/daemon/server.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/daemon/server.h"
|
||||
|
||||
#include "server/daemon/client.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
DaemonServer::DaemonServer(const common::net::HostAndPort& host, common::libev::IoLoopObserver* observer)
|
||||
: base_class(new common::net::ServerSocketEvTcp(host), true, observer) {}
|
||||
|
||||
common::libev::tcp::TcpClient* DaemonServer::CreateClient(const common::net::socket_info& info, void* user) {
|
||||
UNUSED(user);
|
||||
return new ProtocoledDaemonClient(this, info);
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
32
src/server/daemon/server.h
Normal file
32
src/server/daemon/server.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/daemon/server.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
class DaemonServer : public common::daemon::DaemonServer {
|
||||
public:
|
||||
typedef common::daemon::DaemonServer base_class;
|
||||
explicit DaemonServer(const common::net::HostAndPort& host, common::libev::IoLoopObserver* observer = nullptr);
|
||||
|
||||
private:
|
||||
common::libev::tcp::TcpClient* CreateClient(const common::net::socket_info& info, void* user) override;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
207
src/server/daemon_slave.cpp
Normal file
207
src/server/daemon_slave.cpp
Normal file
|
@ -0,0 +1,207 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#if defined(OS_WIN)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include <common/file_system/file.h>
|
||||
#include <common/file_system/file_system.h>
|
||||
#include <common/file_system/string_path_utils.h>
|
||||
|
||||
#include <iostream>
|
||||
#if defined(OS_POSIX)
|
||||
#include <common/utils.h>
|
||||
#endif
|
||||
|
||||
#include "server/process_slave_wrapper.h"
|
||||
|
||||
#define HELP_TEXT \
|
||||
"Usage: " STREAMER_SERVICE_NAME \
|
||||
" [option]\n\n" \
|
||||
" --version display version\n" \
|
||||
" --daemon run as a daemon\n" \
|
||||
" --reload restart service\n" \
|
||||
" --stop stop service\n"
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
struct WinsockInit {
|
||||
WinsockInit() {
|
||||
WSADATA d;
|
||||
if (WSAStartup(0x202, &d) != 0) {
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
~WinsockInit() { WSACleanup(); }
|
||||
} winsock_init;
|
||||
#else
|
||||
struct SigIgnInit {
|
||||
SigIgnInit() { signal(SIGPIPE, SIG_IGN); }
|
||||
} sig_init;
|
||||
#endif
|
||||
|
||||
const size_t kMaxSizeLogFile = 10 * 1024 * 1024; // 10 MB
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv, char** envp) {
|
||||
bool run_as_daemon = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "--version") == 0) {
|
||||
std::cout << PROJECT_VERSION_HUMAN << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
} else if (strcmp(argv[i], "--daemon") == 0) {
|
||||
run_as_daemon = true;
|
||||
} else if (strcmp(argv[i], "--stop") == 0) {
|
||||
fastocloud::server::Config config;
|
||||
common::ErrnoError err = fastocloud::server::load_config_from_file(CONFIG_PATH, &config);
|
||||
if (err) {
|
||||
std::cerr << "Can't read config, file path: " << CONFIG_PATH << ", error: " << err->GetDescription()
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
err = fastocloud::server::ProcessSlaveWrapper::SendStopDaemonRequest(config);
|
||||
sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1);
|
||||
if (err) {
|
||||
std::cerr << "Stop command failed error: " << err->GetDescription() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
} else if (strcmp(argv[i], "--reload") == 0) {
|
||||
fastocloud::server::Config config;
|
||||
common::ErrnoError err = fastocloud::server::load_config_from_file(CONFIG_PATH, &config);
|
||||
if (err) {
|
||||
std::cerr << "Can't read config, file path: " << CONFIG_PATH << ", error: " << err->GetDescription()
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
err = fastocloud::server::ProcessSlaveWrapper::SendRestartDaemonRequest(config);
|
||||
sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1);
|
||||
if (err) {
|
||||
std::cerr << "Reload command failed error: " << err->GetDescription() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
} else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||
std::cout << HELP_TEXT << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
std::cerr << HELP_TEXT << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (run_as_daemon) {
|
||||
#if defined(OS_POSIX)
|
||||
if (!common::create_as_daemon()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int res = EXIT_FAILURE;
|
||||
while (true) {
|
||||
fastocloud::server::Config config;
|
||||
common::ErrnoError err = fastocloud::server::load_config_from_file(CONFIG_PATH, &config);
|
||||
if (err) {
|
||||
std::cerr << "Can't read config, file path: " << CONFIG_PATH << ", error: " << err->GetDescription() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
common::logging::INIT_LOGGER(STREAMER_SERVICE_NAME, config.log_path, config.log_level,
|
||||
kMaxSizeLogFile); // initialization of logging system
|
||||
|
||||
const pid_t daemon_pid = getpid();
|
||||
const std::string folder_path_to_pid = common::file_system::get_dir_path(PIDFILE_PATH);
|
||||
if (folder_path_to_pid.empty()) {
|
||||
ERROR_LOG() << "Can't get pid file path: " << PIDFILE_PATH;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!common::file_system::is_directory_exist(folder_path_to_pid)) {
|
||||
common::ErrnoError errn = common::file_system::create_directory(folder_path_to_pid, true);
|
||||
if (errn) {
|
||||
ERROR_LOG() << "Pid file directory not exists, pid file path: " << PIDFILE_PATH;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
err = common::file_system::node_access(folder_path_to_pid);
|
||||
if (err) {
|
||||
ERROR_LOG() << "Can't have permissions to create, pid file path: " << PIDFILE_PATH;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
common::file_system::File pidfile;
|
||||
err = pidfile.Open(PIDFILE_PATH, common::file_system::File::FLAG_CREATE | common::file_system::File::FLAG_WRITE);
|
||||
if (err) {
|
||||
ERROR_LOG() << "Can't open pid file path: " << PIDFILE_PATH;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
err = pidfile.Lock();
|
||||
if (err) {
|
||||
ERROR_LOG() << "Can't lock pid file path: " << PIDFILE_PATH << "; message: " << err->GetDescription();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const std::string pid_str = common::MemSPrintf("%ld\n", static_cast<long>(daemon_pid));
|
||||
size_t writed;
|
||||
err = pidfile.WriteBuffer(pid_str, &writed);
|
||||
if (err) {
|
||||
ERROR_LOG() << "Failed to write pid file path: " << PIDFILE_PATH << "; message: " << err->GetDescription();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// start
|
||||
fastocloud::server::ProcessSlaveWrapper wrapper(config);
|
||||
NOTICE_LOG() << "Running " PROJECT_VERSION_HUMAN << " in " << (run_as_daemon ? "daemon" : "common") << " mode";
|
||||
|
||||
for (char** env = envp; *env != nullptr; env++) {
|
||||
char* cur_env = *env;
|
||||
DEBUG_LOG() << cur_env;
|
||||
}
|
||||
|
||||
res = wrapper.Exec(argc, argv);
|
||||
NOTICE_LOG() << "Quiting " PROJECT_VERSION_HUMAN;
|
||||
|
||||
err = pidfile.Unlock();
|
||||
if (err) {
|
||||
ERROR_LOG() << "Failed to unlock pidfile: " << PIDFILE_PATH << "; message: " << err->GetDescription();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
err = pidfile.Close();
|
||||
if (err) {
|
||||
ERROR_LOG() << "Failed to close pidfile: " << PIDFILE_PATH << "; message: " << err->GetDescription();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
err = common::file_system::remove_file(PIDFILE_PATH);
|
||||
if (err) {
|
||||
WARNING_LOG() << "Can't remove file: " << PIDFILE_PATH << ", error: " << err->GetDescription();
|
||||
}
|
||||
|
||||
if (wrapper.IsStoped()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
116
src/server/gpu_stats/intel_monitor.cpp
Normal file
116
src/server/gpu_stats/intel_monitor.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/* Copyright (C) 2014-2018 FastoGT. All right reserved.
|
||||
This file is part of iptv_cloud.
|
||||
iptv_cloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
iptv_cloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with iptv_cloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/gpu_stats/intel_monitor.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <cttmetrics.h>
|
||||
|
||||
#define METRIC_TIMEOUT_MSEC 1000
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
IntelMonitor::IntelMonitor(double* load) : load_(load), stop_mutex_(), stop_cond_(), stop_flag_(false) {}
|
||||
|
||||
IntelMonitor::~IntelMonitor() {}
|
||||
|
||||
bool IntelMonitor::IsGpuAvailable() {
|
||||
cttStatus status = CTTMetrics_Init(nullptr);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CTTMetrics_Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntelMonitor::Exec() {
|
||||
if (!load_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cttStatus status = CTTMetrics_Init(nullptr);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cttMetric metrics_ids[] = {CTT_USAGE_RENDER};
|
||||
static const unsigned int metric_cnt = sizeof(metrics_ids) / sizeof(metrics_ids[0]);
|
||||
static const unsigned int num_samples = 100;
|
||||
static const unsigned int period_ms = METRIC_TIMEOUT_MSEC;
|
||||
unsigned int metric_all_cnt = 0;
|
||||
status = CTTMetrics_GetMetricCount(&metric_all_cnt);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
CTTMetrics_Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
cttMetric metric_all_ids[CTT_MAX_METRIC_COUNT] = {CTT_WRONG_METRIC_ID};
|
||||
status = CTTMetrics_GetMetricInfo(metric_all_cnt, metric_all_ids);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
CTTMetrics_Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
status = CTTMetrics_Subscribe(metric_cnt, metrics_ids);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
CTTMetrics_Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
status = CTTMetrics_SetSampleCount(num_samples);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
CTTMetrics_Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
status = CTTMetrics_SetSamplePeriod(period_ms);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
CTTMetrics_Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
float metric_values[metric_cnt];
|
||||
memset(metric_values, 0, (size_t)metric_cnt * sizeof(float));
|
||||
|
||||
std::unique_lock<std::mutex> lock(stop_mutex_);
|
||||
while (!stop_flag_) {
|
||||
status = CTTMetrics_GetValue(metric_cnt, metric_values);
|
||||
if (CTT_ERR_NONE != status) {
|
||||
break;
|
||||
}
|
||||
*load_ = metric_values[0];
|
||||
|
||||
std::cv_status interrupt_status = stop_cond_.wait_for(lock, std::chrono::seconds(1));
|
||||
if (interrupt_status == std::cv_status::no_timeout) { // if notify
|
||||
if (stop_flag_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CTTMetrics_Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void IntelMonitor::Stop() {
|
||||
std::unique_lock<std::mutex> lock(stop_mutex_);
|
||||
stop_flag_ = true;
|
||||
stop_cond_.notify_one();
|
||||
}
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
44
src/server/gpu_stats/intel_monitor.h
Normal file
44
src/server/gpu_stats/intel_monitor.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
|
||||
#include "server/gpu_stats/perf_monitor.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
class IntelMonitor : public IPerfMonitor {
|
||||
public:
|
||||
explicit IntelMonitor(double* load);
|
||||
~IntelMonitor() override;
|
||||
|
||||
bool Exec() override;
|
||||
void Stop() override;
|
||||
|
||||
static bool IsGpuAvailable();
|
||||
|
||||
private:
|
||||
double* load_;
|
||||
std::mutex stop_mutex_;
|
||||
std::condition_variable stop_cond_;
|
||||
bool stop_flag_;
|
||||
};
|
||||
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
104
src/server/gpu_stats/nvidia_monitor.cpp
Normal file
104
src/server/gpu_stats/nvidia_monitor.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* Copyright (C) 2014-2017 FastoGT. All right reserved.
|
||||
This file is part of iptv_cloud.
|
||||
iptv_cloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
iptv_cloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with iptv_cloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/gpu_stats/nvidia_monitor.h"
|
||||
|
||||
#include <nvml.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
NvidiaMonitor::NvidiaMonitor(double* load) : load_(load), stop_mutex_(), stop_cond_(), stop_flag_(false) {}
|
||||
|
||||
NvidiaMonitor::~NvidiaMonitor() {}
|
||||
|
||||
bool NvidiaMonitor::IsGpuAvailable() {
|
||||
nvmlReturn_t ret = nvmlInit();
|
||||
if (ret != NVML_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned devices_num = 0;
|
||||
ret = nvmlDeviceGetCount(&devices_num);
|
||||
if (ret != NVML_SUCCESS || devices_num == 0) {
|
||||
nvmlShutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
nvmlShutdown();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NvidiaMonitor::Exec() {
|
||||
if (!load_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nvmlReturn_t ret = nvmlInit();
|
||||
if (ret != NVML_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned devices_num = 0;
|
||||
ret = nvmlDeviceGetCount(&devices_num);
|
||||
if (ret != NVML_SUCCESS || devices_num == 0) {
|
||||
nvmlShutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(stop_mutex_);
|
||||
while (!stop_flag_) {
|
||||
uint64_t total_enc = 0, total_dec = 0;
|
||||
for (unsigned i = 0; i != devices_num; ++i) {
|
||||
unsigned enc, dec, enc_sampling, dec_sampling;
|
||||
nvmlDevice_t device;
|
||||
ret = nvmlDeviceGetHandleByIndex(i, &device);
|
||||
if (ret != NVML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
ret = nvmlDeviceGetDecoderUtilization(device, &dec, &dec_sampling);
|
||||
if (ret != NVML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
ret = nvmlDeviceGetEncoderUtilization(device, &enc, &enc_sampling);
|
||||
if (ret != NVML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
total_dec += dec;
|
||||
total_enc += enc;
|
||||
}
|
||||
*load_ = static_cast<double>(total_dec + total_enc) / static_cast<double>(devices_num * 2); // 2 because enc + dec
|
||||
|
||||
std::cv_status interrupt_status = stop_cond_.wait_for(lock, std::chrono::seconds(1));
|
||||
if (interrupt_status == std::cv_status::no_timeout) { // if notify
|
||||
if (stop_flag_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nvmlShutdown();
|
||||
return true;
|
||||
}
|
||||
|
||||
void NvidiaMonitor::Stop() {
|
||||
std::unique_lock<std::mutex> lock(stop_mutex_);
|
||||
stop_flag_ = true;
|
||||
stop_cond_.notify_one();
|
||||
}
|
||||
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
44
src/server/gpu_stats/nvidia_monitor.h
Normal file
44
src/server/gpu_stats/nvidia_monitor.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
|
||||
#include "server/gpu_stats/perf_monitor.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
class NvidiaMonitor : public IPerfMonitor {
|
||||
public:
|
||||
explicit NvidiaMonitor(double* load);
|
||||
~NvidiaMonitor() override;
|
||||
|
||||
bool Exec() override;
|
||||
void Stop() override;
|
||||
|
||||
static bool IsGpuAvailable();
|
||||
|
||||
private:
|
||||
double* load_;
|
||||
std::mutex stop_mutex_;
|
||||
std::condition_variable stop_cond_;
|
||||
bool stop_flag_;
|
||||
};
|
||||
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
83
src/server/gpu_stats/perf_monitor.cpp
Normal file
83
src/server/gpu_stats/perf_monitor.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/gpu_stats/perf_monitor.h"
|
||||
|
||||
#include <common/macros.h>
|
||||
|
||||
#ifdef HAVE_NVML
|
||||
#include "server/gpu_stats/nvidia_monitor.h"
|
||||
#endif
|
||||
#ifdef HAVE_CTT_METRICS
|
||||
#include "server/gpu_stats/intel_monitor.h"
|
||||
#endif
|
||||
|
||||
#define MAX_LEN 1024
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsNvidiaGpuAvailable() {
|
||||
#ifdef HAVE_NVML
|
||||
return fastocloud::server::gpu_stats::NvidiaMonitor::IsGpuAvailable();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsIntelGpuAvailable() {
|
||||
#ifdef HAVE_CTT_METRICS
|
||||
return fastocloud::server::gpu_stats::IntelMonitor::IsGpuAvailable();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
IPerfMonitor::~IPerfMonitor() {}
|
||||
|
||||
IPerfMonitor* CreateNvidiaPerfMonitor(double* load) {
|
||||
#if !defined(HAVE_NVML) && !defined(HAVE_CTT_METRICS)
|
||||
UNUSED(load);
|
||||
#endif
|
||||
if (IsNvidiaGpuAvailable()) {
|
||||
#if defined(HAVE_NVML)
|
||||
return new NvidiaMonitor(load);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IPerfMonitor* CreateIntelPerfMonitor(double* load) {
|
||||
#if !defined(HAVE_NVML) && !defined(HAVE_CTT_METRICS)
|
||||
UNUSED(load);
|
||||
#endif
|
||||
if (IsIntelGpuAvailable()) {
|
||||
#if defined(HAVE_CTT_METRICS)
|
||||
return new IntelMonitor(load);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
34
src/server/gpu_stats/perf_monitor.h
Normal file
34
src/server/gpu_stats/perf_monitor.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
namespace gpu_stats {
|
||||
|
||||
class IPerfMonitor {
|
||||
public:
|
||||
virtual ~IPerfMonitor();
|
||||
|
||||
virtual bool Exec() = 0;
|
||||
virtual void Stop() = 0;
|
||||
};
|
||||
|
||||
IPerfMonitor* CreateIntelPerfMonitor(double* load);
|
||||
IPerfMonitor* CreateNvidiaPerfMonitor(double* load);
|
||||
|
||||
} // namespace gpu_stats
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
37
src/server/http/client.cpp
Normal file
37
src/server/http/client.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/http/client.h"
|
||||
|
||||
#include <common/net/socket_tcp_tls.h>
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
HttpClient::HttpClient(common::libev::IoLoop* server, const common::net::socket_info& info)
|
||||
: base_class(server, info) {}
|
||||
|
||||
const char* HttpClient::ClassName() const {
|
||||
return "HttpClient";
|
||||
}
|
||||
|
||||
HttpsClient::HttpsClient(common::libev::IoLoop* server, const common::net::socket_info& info, SSL* ssl)
|
||||
: base_class(server, new common::net::TcpTlsSocketHolder(info, ssl)) {}
|
||||
|
||||
const char* HttpsClient::ClassName() const {
|
||||
return "HttpsClient";
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
43
src/server/http/client.h
Normal file
43
src/server/http/client.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common/libev/http/http_client.h>
|
||||
|
||||
typedef struct ssl_st SSL;
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
class HttpClient : public common::libev::http::HttpClient {
|
||||
public:
|
||||
typedef common::libev::http::HttpClient base_class;
|
||||
|
||||
HttpClient(common::libev::IoLoop* server, const common::net::socket_info& info);
|
||||
|
||||
const char* ClassName() const override;
|
||||
};
|
||||
|
||||
class HttpsClient : public common::libev::http::HttpClient {
|
||||
public:
|
||||
typedef common::libev::http::HttpClient base_class;
|
||||
|
||||
HttpsClient(common::libev::IoLoop* server, const common::net::socket_info& info, SSL* ssl);
|
||||
|
||||
const char* ClassName() const override;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
202
src/server/http/handler.cpp
Normal file
202
src/server/http/handler.cpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
|
||||
This file is part of fastocloud.
|
||||
fastocloud is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
fastocloud is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "server/http/handler.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "server/http/client.h"
|
||||
|
||||
namespace fastocloud {
|
||||
namespace server {
|
||||
|
||||
HttpHandler::HttpHandler(const std::string& http_root) : base_class(), http_root_(http_root) {}
|
||||
|
||||
const HttpHandler::http_directory_path_t& HttpHandler::GetHttpRoot() const {
|
||||
return http_root_;
|
||||
}
|
||||
|
||||
void HttpHandler::PreLooped(common::libev::IoLoop* server) {
|
||||
UNUSED(server);
|
||||
}
|
||||
|
||||
void HttpHandler::Accepted(common::libev::IoClient* client) {
|
||||
base_class::Accepted(client);
|
||||
}
|
||||
|
||||
void HttpHandler::Moved(common::libev::IoLoop* server, common::libev::IoClient* client) {
|
||||
base_class::Moved(server, client);
|
||||
}
|
||||
|
||||
void HttpHandler::Closed(common::libev::IoClient* client) {
|
||||
base_class::Closed(client);
|
||||
}
|
||||
|
||||
void HttpHandler::TimerEmited(common::libev::IoLoop* server, common::libev::timer_id_t id) {
|
||||
UNUSED(server);
|
||||
UNUSED(id);
|
||||
}
|
||||
|
||||
void HttpHandler::Accepted(common::libev::IoChild* child) {
|
||||
UNUSED(child);
|
||||
}
|
||||
|
||||
void HttpHandler::Moved(common::libev::IoLoop* server, common::libev::IoChild* child) {
|
||||
UNUSED(server);
|
||||
UNUSED(child);
|
||||
}
|
||||
|
||||
void HttpHandler::ChildStatusChanged(common::libev::IoChild* child, int status, int signal) {
|
||||
UNUSED(child);
|
||||
UNUSED(status);
|
||||
UNUSED(signal);
|
||||
}
|
||||
|
||||
void HttpHandler::DataReceived(common::libev::IoClient* client) {
|
||||
char buff[BUF_SIZE] = {0};
|
||||
size_t nread = 0;
|
||||
common::ErrnoError errn = client->SingleRead(buff, BUF_SIZE - 1, &nread);
|
||||
if (errn || nread == 0) {
|
||||
ignore_result(client->Close());
|
||||
delete client;
|
||||
return;
|
||||
}
|
||||
|
||||
HttpClient* hclient = static_cast<server::HttpClient*>(client);
|
||||
ProcessReceived(hclient, buff, nread);
|
||||
}
|
||||
|
||||
void HttpHandler::DataReadyToWrite(common::libev::IoClient* client) {
|
||||
UNUSED(client);
|
||||
}
|
||||
|
||||
void HttpHandler::PostLooped(common::libev::IoLoop* server) {
|
||||
UNUSED(server);
|
||||
}
|
||||
|
||||
void HttpHandler::ProcessReceived(HttpClient* hclient, const char* request, size_t req_len) {
|
||||
static const common::libev::http::HttpServerInfo hinf(PROJECT_NAME_TITLE "/" PROJECT_VERSION, PROJECT_DOMAIN);
|
||||
common::http::HttpRequest hrequest;
|
||||
const auto result = common::http::parse_http_request(request, req_len, &hrequest);
|
||||
DEBUG_LOG() << "Http request:\n" << request;
|
||||
|
||||
common::http::headers_t extra_headers = {{"Access-Control-Allow-Origin", "*"}};
|
||||
if (result.second) {
|
||||
const std::string error_text = result.second->GetDescription();
|
||||
DEBUG_MSG_ERROR(result.second, common::logging::LOG_LEVEL_ERR);
|
||||
common::ErrnoError err =
|
||||
hclient->SendError(common::http::HP_1_0, result.first, extra_headers, error_text.c_str(), false, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
ignore_result(hclient->Close());
|
||||
delete hclient;
|
||||
return;
|
||||
}
|
||||
|
||||
// keep alive
|
||||
common::http::header_t connection_field;
|
||||
bool is_find_connection = hrequest.FindHeaderByKey("Connection", false, &connection_field);
|
||||
bool IsKeepAlive = is_find_connection ? common::EqualsASCII(connection_field.value, "Keep-Alive", false) : false;
|
||||
const common::http::http_protocol protocol = hrequest.GetProtocol();
|
||||
const common::http::http_method method = hrequest.GetMethod();
|
||||
if (method == common::http::http_method::HM_GET || method == common::http::http_method::HM_HEAD) {
|
||||
auto url = hrequest.GetURL();
|
||||
if (!url.is_valid()) { // for hls
|
||||
common::ErrnoError err =
|
||||
hclient->SendError(protocol, common::http::HS_NOT_FOUND, extra_headers, "File not found.", IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
const std::string path_abs = url.PathForRequest();
|
||||
auto file_path = http_root_.MakeConcatFileStringPath(path_abs.substr(1));
|
||||
if (!file_path) {
|
||||
common::ErrnoError err =
|
||||
hclient->SendError(protocol, common::http::HS_NOT_FOUND, extra_headers, "File not found.", IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
const std::string file_path_str = file_path->GetPath();
|
||||
int open_flags = O_RDONLY;
|
||||
struct stat sb;
|
||||
if (stat(file_path_str.c_str(), &sb) < 0) {
|
||||
common::ErrnoError err =
|
||||
hclient->SendError(protocol, common::http::HS_NOT_FOUND, extra_headers, "File not found.", IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (S_ISDIR(sb.st_mode)) {
|
||||
common::ErrnoError err =
|
||||
hclient->SendError(protocol, common::http::HS_BAD_REQUEST, extra_headers, "Bad filename.", IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
int file = open(file_path_str.c_str(), open_flags);
|
||||
if (file == INVALID_DESCRIPTOR) { /* open the file for reading */
|
||||
common::ErrnoError err = hclient->SendError(protocol, common::http::HS_FORBIDDEN, extra_headers,
|
||||
"File is protected.", IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
const std::string fileName = url.ExtractFileName();
|
||||
const char* mime = common::http::MimeTypes::GetType(fileName.c_str());
|
||||
common::ErrnoError err = hclient->SendHeaders(protocol, common::http::HS_OK, extra_headers, mime, &sb.st_size,
|
||||
&sb.st_mtime, IsKeepAlive, hinf);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
::close(file);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (hrequest.GetMethod() == common::http::http_method::HM_GET) {
|
||||
common::ErrnoError err = hclient->SendFileByFd(protocol, file, sb.st_size);
|
||||
if (err) {
|
||||
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
|
||||
} else {
|
||||
DEBUG_LOG() << "Sent file path: " << file_path_str << ", size: " << sb.st_size;
|
||||
}
|
||||
}
|
||||
|
||||
::close(file);
|
||||
}
|
||||
|
||||
finish:
|
||||
if (!IsKeepAlive) {
|
||||
ignore_result(hclient->Close());
|
||||
delete hclient;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace fastocloud
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue