Skip to content
Snippets Groups Projects
Commit c7990573 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 792 additions and 0 deletions
bin
build
lib
\ No newline at end of file
image: docker.io/labrobotica/labrobotica:latest
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- test
- deploy
build-package:
stage: build
script:
#- git submodule sync --recursive
#- git submodule update --init --recursive
- apt update || apt -y install ca-certificates && apt update
##Install dependencies
#- apt -y install iri-dep1-dev iri-dep2-dev
- mkdir -pv build
- cd build
- cmake -DCMAKE_BUILD_TYPE=RELEASE -DCPACK_PACKAGE_VERSION=$CI_COMMIT_TAG ..
- make package -j $(nproc)
artifacts:
paths:
- build/*.deb
expire_in: 2 weeks
only:
- tags
update_repo:
stage: deploy
script:
- cd build
- "scp -i /root/.ssh/iriLabKeyNopwd -r *stream-srt-source*.deb irilabo@labrepo.iri.upc.edu:packages/"
- "ssh irilabo@labrepo.iri.upc.edu -i /root/.ssh/iriLabKeyNopwd -tt /home/irilabo/repo_scripts/update_repo.sh stream-srt-source $(lsb_release -cs)"
only:
- tags
\ No newline at end of file
# Pre-requisites about cmake itself
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
# The project name and the type of project
PROJECT(stream_srt_source)
SET(PACKAGE_NAME stream-srt-source)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
SET(CMAKE_INSTALL_PREFIX /usr/local)
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
ENDIF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -D_REENTRANT")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_REENTRANT")
ADD_SUBDIRECTORY(src)
FIND_PACKAGE(Doxygen)
FIND_PATH(IRI_DOC_DIR doxygen.conf ${CMAKE_SOURCE_DIR}/doc/iri_doc/)
IF (IRI_DOC_DIR)
ADD_CUSTOM_TARGET (doc ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/iri_doc/doxygen.conf)
ELSE (IRI_DOC_DIR)
ADD_CUSTOM_TARGET (doc ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/doxygen.conf)
ENDIF (IRI_DOC_DIR)
ADD_CUSTOM_TARGET (distclean @echo cleaning cmake files)
IF (UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "distribution clean"
COMMAND make ARGS clean
COMMAND rm ARGS -rf ${CMAKE_SOURCE_DIR}/build/*
TARGET distclean
)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "distclean only implemented in unix"
TARGET distclean
)
ENDIF(UNIX)
ADD_CUSTOM_TARGET (uninstall @echo uninstall package)
IF (UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "uninstall package"
COMMAND xargs ARGS rm < install_manifest.txt
COMMAND rm -rd ${CMAKE_INSTALL_PREFIX}/lib/iri/${PROJECT_NAME}
COMMAND rm -rd ${CMAKE_INSTALL_PREFIX}/include/iri/${PROJECT_NAME}
TARGET uninstall
)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "uninstall only implemented in unix"
TARGET uninstall
)
ENDIF(UNIX)
IF (UNIX)
SET(CPACK_PACKAGE_FILE_NAME "iri-${PACKAGE_NAME}-dev-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
SET(CPACK_PACKAGE_NAME "iri-${PACKAGE_NAME}-dev")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Part of IRI-laboratory libraries. More information at https://gitlab.iri.upc.edu/labrobotica")
SET(CPACK_PACKAGING_INSTALL_PREFIX /usr)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "labrobotica - labrobotica@iri.upc.edu")
#Uncomment to add the necessary mantainer scripts
#SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/preinst;${CMAKE_SOURCE_DIR}/scripts/debian/postinst;${CMAKE_SOURCE_DIR}/scripts/debian/prerm;${CMAKE_SOURCE_DIR}/scripts/debian/postrm")
#Uncomment to add dependencies comma separated
#SET(CPACK_DEBIAN_PACKAGE_DEPENDS "iri-dep1-dev (>= 1.0~${DISTRIB}), iri-dep2-dev (>= 1.0~${DISTRIB})")
INCLUDE(CPack)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "packaging only implemented in unix"
TARGET uninstall
)
ENDIF(UNIX)
\ No newline at end of file
#edit the following line to add the librarie's header files
SET(name stream_srt_source)
FIND_PATH(${name}_INCLUDE_DIRS ${name}.h /usr/local/include/iri/${name} /usr/include/iri/${name})
FIND_LIBRARY(${name}_LIBRARIES
NAMES ${name}
PATHS /usr/local/lib/iri/${name} /usr/lib/iri/${name})
SET(${name}_INCLUDE_DIR ${${name}_INCLUDE_DIRS})
SET(${name}_LIBRARY ${${name}_LIBRARIES})
IF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
SET(${name}_FOUND TRUE)
ENDIF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
IF (${name}_FOUND)
IF (NOT ${name}_FIND_QUIETLY)
MESSAGE(STATUS "Found ${name}: ${${name}_LIBRARIES}")
ENDIF (NOT ${name}_FIND_QUIETLY)
ELSE (${name}_FOUND)
IF (${name}_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find ${name}")
ENDIF (${name}_FIND_REQUIRED)
ENDIF (${name}_FOUND)
\ No newline at end of file
LICENSE 0 → 100644
GNU LESSER 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.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser 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
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
ReadMe.md 0 → 100644
stream_srt_source {#mainpage}
============
## Description
stream_srt_source
## Installation
* Add the labrobotica repository if it is not already added: run the commands on _add repository_ and _add key_ from [labrobotica_how_to installation](https://gitlab.iri.upc.edu/labrobotica/labrobotica_how_to/-/blob/master/README.md#installation)
* Install the package:
sudo apt update && sudo apt install iri-stream-srt-source-dev
## Disclaimer
Copyright (C) Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
Mantainer IRI labrobotica (labrobotica@iri.upc.edu)
This package is distributed in the hope that it will be useful, but without any warranty. It is provided "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, the GMR group does not assume the cost of any necessary servicing, repair or correction.
In no event unless required by applicable law the author will 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 the author has been advised of the possibility of such damages.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
## For developers
<details><summary>click here</summary>
<p>
## Dependencies
This package requires of the following system libraries and packages
* [cmake](https://www.cmake.org "CMake's Homepage"), a cross-platform build system.
* [doxygen](http://www.doxygen.org "Doxygen's Homepage") and [graphviz](http://www.graphviz.org "Graphviz's Homepage") to generate the documentation.
* stdc++ and pthread libraries.
Under linux all of these utilities are available in ready-to-use packages.
Under MacOS most of the packages are available via [fink](http://www.finkproject.org/ "Fink's Homepage")
This package also requires of the following dependencies:
## Compilation and installation from source
Clone this repository and create a build folder inside:
mkdir build
Inside the build folder execute the following commands:
cmake ..
The default build mode is DEBUG. That is, objects and executables include debug information.
The RELEASE build mode optimizes for speed. To build in this mode execute instead
cmake .. -DCMAKE_BUILD_TYPE=RELEASE
The release mode will be kept until next time cmake is executed.
make -j $(nproc)
In case no errors are reported, the generated libraries (if any) will be located at the
_lib_ folder and the executables (if any) will be located at the _bin_ folder.
In order to be able to use the library, it it necessary to copy it into the system.
To do that, execute
make install
as root and the shared libraries will be copied to */usr/local/lib/iri/stream_srt_source* directory
and the header files will be copied to */usr/local/include/iri/stream_srt_source* directory. At
this point, the library may be used by any user.
To remove the library from the system, exceute
make uninstall
as root, and all the associated files will be removed from the system.
To generate the documentation execute the following command:
make doc
## How to use it
To use this library in another library or application, in the CMakeLists.txt file, first it is necessary to locate if the library has been installed or not using the following command
FIND_PACKAGE(stream_srt_source)
In the case that the package is present, it is necessary to add the header files directory to the include directory path by using
INCLUDE_DIRECTORIES(${stream_srt_source_INCLUDE_DIRS})
and it is also necessary to link with the desired libraries by using the following command
TARGET_LINK_LIBRARIES(<executable name> ${stream_srt_source_LIBRARIES})
## Examples
There are examples that show how to use the different classes.
</p>
</details>
\ No newline at end of file
This diff is collapsed.
PROJECT_NAME = "stream_srt_source"
#ifndef _STREAM_SRT_SOURCE_H
#define _STREAM_SRT_SOURCE_H
#include "exceptions.h"
#include "threadserver.h"
#include "eventserver.h"
#include "mutex.h"
extern "C"
{
#include <libavformat/avformat.h>
#include <libavutil/timestamp.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
}
#include "portaudio.h"
#define NUM_VIDEO_BUFFERS 4
#define NUM_AUDIO_BUFFERS 4
typedef struct{
void *start;
size_t length;
}TVideoBuffer;
typedef struct{
// general config data
unsigned int width;
unsigned int height;
unsigned int y_size;
unsigned int uv_size;
float framerate;
// ffmpeg data
AVCodec *codec;
AVStream *stream;
AVCodecContext *encoder_context;
AVFrame *frame;
int64_t next_pts;
// device data
std::string video_device;
int fd;
TVideoBuffer *buffers;
unsigned int num_buffers;
}TVideoConfig;
typedef struct{
// general config data
int num_channels;
unsigned long int av_channels_layout;
int sample_rate;
PaSampleFormat pa_sample_format;
enum AVSampleFormat av_sample_format;
unsigned int sample_size;
// ffmpeg data
AVCodec *codec;
AVStream *stream;
AVCodecContext *encoder_context;
AVFrame *frame;
AVFrame *tmp_frame;
int64_t next_pts;
int nb_samples;
struct SwrContext *resampler;
int samples_count;
// device data
std::string audio_device;
PaStream *audio_stream;
CMutex access;
long long frame_time;
}TAudioConfig;
typedef struct{
std::string ip;
}TSRTConfig;
class CStreamSrtSource
{
private:
CThreadServer *thread_server;
std::string capture_video_thread_id;
std::string capture_audio_thread_id;
CEventServer *event_server;
std::string finish_video_thread_event_id;
std::string finish_audio_thread_event_id;
std::string new_audio_buffer_event_id;
// SRT
TSRTConfig srt_config;
// video
TVideoConfig video_config;
// audio
TAudioConfig audio_config;
AVFormatContext *output_context;
CMutex access;
protected:
// video
void open_video(void);
void close_video(void);
void open_video_device(void);
void start_video_device(void);
void stop_video_device(void);
void close_video_device(void);
int xioctl(int fd,int request,void *arg);
static void *capture_video_thread(void *param);
// audio
void open_audio(void);
void close_audio(void);
void open_audio_device(void);
void start_audio_device(void);
void stop_audio_device(void);
void close_audio_device(void);
static int audioCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
static void *capture_audio_thread(void *param);
public:
CStreamSrtSource();
void load_config(const std::string &filename);
void save_config(const std::string &filename);
void open(void);
void start(void);
void stop(void);
void close(void);
~CStreamSrtSource();
};
#endif
#ifndef _STREAM_SRT_SOURCE_EXCEPTIONS
#define _STREAM_SRT_SOURCE_EXCEPTIONS
#include "exceptions.h"
class CStreamSrtSourceVideoDeviceException : public CException
{
public:
CStreamSrtSourceVideoDeviceException(const std::string& where,const std::string &error_msg, int error_id, const std::string &detail);
};
class CStreamSrtSourceAudioDeviceException : public CException
{
public:
CStreamSrtSourceAudioDeviceException(const std::string& where,const std::string &error_msg, int error_id, const std::string &detail);
};
#endif
ADD_SUBDIRECTORY(xml)
# driver source files
SET(sources ${PROJECT_NAME}.cpp ${PROJECT_NAME}_exceptions.cpp ${XSD_SOURCES})
# application header files
SET(headers ../include/${PROJECT_NAME}.h ../include/${PROJECT_NAME}_exceptions.h)
# locate the necessary dependencies
# FIND_PACKAGE(my_example_library REQUIRED)
include(FindPkgConfig)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/opt/vc/lib/pkgconfig/")
pkg_search_module(AVCODEC REQUIRED libavcodec)
pkg_search_module(AVDEVICE REQUIRED libavdevice)
pkg_search_module(AVFILTER REQUIRED libavfilter)
pkg_search_module(AVAVFORMAT REQUIRED libavformat)
pkg_search_module(AVUTIL REQUIRED libavutil)
pkg_search_module(SWRESAMPLE REQUIRED libswresample)
pkg_search_module(MMAL REQUIRED mmal)
pkg_search_module(PORTAUDIO REQUIRED portaudiocpp)
find_package(iriutils REQUIRED)
# add the necessary include directories
INCLUDE_DIRECTORIES(../include)
include_directories(${AVCODEC_INCLUDE_DIRS})
include_directories(${AVDEVICE_INCLUDE_DIRS})
include_directories(${AVFILTER_INCLUDE_DIRS})
include_directories(${AVFORMAT_INCLUDE_DIRS})
include_directories(${AVUTIL_INCLUDE_DIRS})
include_directories(${SWRESAMPLE_INCLUDE_DIRS})
include_directories(${MMAL_INCLUDE_DIRS})
include_directories(${PORTAUDIO_INCLUDE_DIRS})
include_directories(${iriutils_INCLUDE_DIR})
link_directories(${AVCODEC_LIBRARY_DIRS})
link_directories(${AVDEVICE_LIBRARY_DIRS})
link_directories(${AVFILTER_LIBRARY_DIRS})
link_directories(${AVFORMAT_LIBRARY_DIRS})
link_directories(${AVUTIL_LIBRARY_DIRS})
link_directories(${SWRESAMPLE_LIBRARY_DIRS})
link_directories(${MMAL_LIBRARY_DIRS})
link_directories(${PORTAUDIO_LIBRARY_DIRS})
SET_SOURCE_FILES_PROPERTIES(${XSD_SOURCES} PROPERTIES GENERATED 1)
# create the shared library
ADD_LIBRARY(${PROJECT_NAME} SHARED ${sources})
# link necessary libraries
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${my_example_library_LIBRARIES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${XSD_LIBRARY})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${iriutils_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${AVCODEC_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVDEVICE_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVFILTER_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVUTIL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${SWRESAMPLE_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${MMAL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${PORTAUDIO_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVCODEC_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVDEVICE_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVFILTER_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVUTIL_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${SWRESAMPLE_LDFLAGS_OTHER})
#ADD_DEPENDENCIES(${PROJECT_NAME} my_example_library_target)
ADD_DEPENDENCIES(${PROJECT_NAME} xsd_files_gen)
INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib/iri/${PROJECT_NAME}
ARCHIVE DESTINATION lib/iri/${PROJECT_NAME})
INSTALL(FILES ${headers} DESTINATION include/iri/${PROJECT_NAME})
INSTALL(FILES ../Find${PROJECT_NAME}.cmake DESTINATION ${CMAKE_ROOT}/Modules/)
#Install script files if needed
#INSTALL(FILES ../scripts/<script_name>
# DESTINATION share/iri
# PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
ADD_SUBDIRECTORY(examples)
# create an example application
ADD_EXECUTABLE(${PROJECT_NAME}_test ${PROJECT_NAME}_test.cpp)
# link necessary libraries
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_test ${PROJECT_NAME})
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <iostream>
#include <chrono>
#include "stream_srt_source.h"
int main(int argc, char **argv)
{
try{
CStreamSrtSource stream;
stream.load_config("../src/xml/stream_config.xml");
stream.open();
stream.start();
sleep(1000000);
stream.stop();
stream.close();
}catch(CException &e){
std::cout << e.what() << std::endl;
}
return 0;
}
This diff is collapsed.
#include "stream_srt_source_exceptions.h"
#include <sstream>
#include <string.h>
#include <stdio.h>
const std::string stream_srt_source_video_device_error_message="StreamSrtSourceVideoDevice error - ";
const std::string stream_srt_source_audio_device_error_message="StreamSrtSourceAudioDevice error - ";
CStreamSrtSourceVideoDeviceException::CStreamSrtSourceVideoDeviceException(const std::string& where,const std::string &error_msg,int error_id,const std::string &detail):CException(where,stream_srt_source_video_device_error_message)
{
std::stringstream text;
this->error_msg+=error_msg;
this->error_msg+=" - Error ID: ";
text << error_id;
this->error_msg+=text.str();
this->error_msg+=" description: " + detail;
}
CStreamSrtSourceAudioDeviceException::CStreamSrtSourceAudioDeviceException(const std::string& where,const std::string &error_msg,int error_id,const std::string &detail):CException(where,stream_srt_source_audio_device_error_message)
{
std::stringstream text;
this->error_msg+=error_msg;
this->error_msg+=" - Error ID: ";
text << error_id;
this->error_msg+=text.str();
this->error_msg+=" description: " + detail;
}
#check the existance of the xsd library
IF(EXISTS "/usr/include/xsd/cxx")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_HAVE_XSD" PARENT_SCOPE)
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_HAVE_XSD" PARENT_SCOPE)
SET(XSD_FOUND TRUE)
MESSAGE(STATUS "Found the XML library ... adding support for XML files")
FIND_LIBRARY(XSD_LIBRARY
NAMES xerces-c
PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu/)
ELSE(EXISTS "/usr/include/xsd/cxx")
MESSAGE(STATUS "XML library not found ... it will be impossible to handle XML files")
ENDIF(EXISTS "/usr/include/xsd/cxx")
IF(XSD_FOUND)
SET(XSD_LIBRARY ${XSD_LIBRARY} PARENT_SCOPE)
SET(XSD_FILES stream_config_cfg_file.xsd)
IF(XSD_FILES)
SET(XSD_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FOREACH(xsd_file ${XSD_FILES})
STRING(REGEX REPLACE "xsd" "cxx" xsd_source ${xsd_file})
SET(XSD_SOURCES_INT ${XSD_SOURCES_INT} ${XSD_PATH}/${xsd_source})
SET(XSD_SOURCES ${XSD_SOURCES} ${XSD_PATH}/${xsd_source})
STRING(REGEX REPLACE "xsd" "hxx" xsd_header ${xsd_file})
SET(XSD_HEADERS_INT ${XSD_HEADERS_INT} ${XSD_PATH}/${xsd_header})
SET(XSD_HEADERS ${XSD_HEADERS} ${XSD_PATH}/${xsd_header})
SET(XSD_PATH_FILES ${XSD_PATH_FILES} ${XSD_PATH}/${xsd_file})
ENDFOREACH(xsd_file)
SET(XSD_SOURCES ${XSD_SOURCES_INT} PARENT_SCOPE)
SET(XSD_HEADERS ${XSD_HEADERS_INT} PARENT_SCOPE)
ADD_CUSTOM_TARGET(xsd_files_gen DEPENDS ${XSD_SOURCES_INT})
ADD_CUSTOM_COMMAND(
OUTPUT ${XSD_SOURCES_INT}
COMMAND xsdcxx cxx-tree --std c++11 --generate-serialization ${XSD_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${XSD_PATH_FILES}
COMMENT "Parsing the xml template file ${XSD_FILES}")
INSTALL(FILES ${XSD_PATH_FILES} DESTINATION include/iri/pan_tilt/xml)
INSTALL(FILES ${XSD_HEADERS_INT} DESTINATION include/iri/pan_tilt/xml)
ENDIF(XSD_FILES)
ENDIF(XSD_FOUND)
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<stream_config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stream_config_cfg_file.xsd">
<video_config>
<video_device>/dev/video0</video_device>
<width>1280</width>
<height>720</height>
<framerate>30.0</framerate>
</video_config>
<audio_config>
<audio_device>hw:0,0</audio_device>
<num_channels>2</num_channels>
<sample_rate>48000</sample_rate>
<sample_format>S32</sample_format>
</audio_config>
<srt_port>8888</srt_port>
</stream_config>
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment