Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBraces: Custom
ColumnLimit: 120
DerivePointerAlignment: false
IncludeCategories:
- Regex: '^(<|")(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdargh|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h'
Priority: 1
- Regex: '^(<|")(cstdlib|csignal|csetjmp|cstdarg|typeinfo|typeindex|type_traits|bitset|functional|utility|ctime|chrono|cstddef|initializer_list|tuple|any|optional|variant|new|memory|scoped_allocator|memory_resource|climits|cfloat|cstdint|cinttypes|limits|exception|stdexcept|cassert|system_error|cerrno|cctype|cwctype|cstring|cwchar|cuchar|string|string_view|array|vector|deque|list|forward_list|set|map|unordered_set|unordered_map|stack|queue|algorithm|execution|teratorslibrary|iterator|cmath|complex|valarray|random|numeric|ratio|cfenv|iosfwd|ios|istream|ostream|iostream|fstream|sstream|strstream|iomanip|streambuf|cstdio|locale|clocale|codecvt|regex|atomic|thread|mutex|shared_mutex|future|condition_variable|filesystem|ciso646|ccomplex|ctgmath|cstdalign|cstdbool)(>|")$'
Priority: 2
- Regex: '^<.*\.(h|hpp)>'
Priority: 3
- Regex: '^".*"'
Priority: 4
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
---
Language: Json
BasedOnStyle: Google
...
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
default_stages: [pre-commit]

ci:
autoupdate_commit_msg: "chore(deps): pre-commit.ci autoupdate"
autoupdate_schedule: "monthly"
autofix_commit_msg: "chore: pre-commit.ci fixes"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-yaml
exclude: ".clang-format"
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.2
hooks:
- id: clang-format
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: ["cmakelang"]
- id: cmake-lint
additional_dependencies: ["cmakelang"]
exclude: "cmake/.*"
- repo: https://github.com/hukkin/mdformat
rev: 0.7.22
hooks:
- id: mdformat
- repo: https://github.com/crate-ci/typos
rev: v1.39.0
hooks:
- id: typos
- repo: https://github.com/hofbi/dev-tools
rev: 1.8.0
hooks:
- id: check-max-one-sentence-per-line
- id: check-snake-case
- id: check-no-dashes
- id: check-non-existing-and-duplicate-excludes
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ cmake_minimum_required(VERSION 3.1)

project(VideoStreamer C CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX17)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")

add_subdirectory(src)
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sudo apt install -y build-essential cmake ffmpeg libx264-dev x264 libopencv-dev
For compiling the Ximea sample (disabled by default), the following additional setup steps need to be performed:

- Install the [Camera driver and SDK](https://www.ximea.com/support/wiki/apis/XIMEA_Linux_Software_Package).
Installation is described on the linked webpage. During installation, do not use the -pcie argument.
Installation is described on the linked webpage.
During installation, do not use the -pcie argument.
- After installation, increase the USB buffer size in Linux (add 'echo 0 > /sys/module/usbcore/parameters/usbfs_memory_mb' to /etc/rc.local) and [allow the application to run in realtime](https://www.ximea.com/support/wiki/apis/Linux_USB30_Support#Allow-to-Run-Application-Realtime).

## Building
Expand Down Expand Up @@ -86,4 +87,4 @@ Then, run the program when the streamer is already running, from your build dire

This repository is [licensed under GPL-3.0](./LICENSE).
We'd prefer to have a more permissive license, however, we're depending on [x264](https://www.videolan.org/developers/x264.html) which itself has a GPL license.
That [forces us to use GPL as well](https://en.wikipedia.org/wiki/GNU_General_Public_License#:~:text=Only%20if%20GPLed%20parts%20are%20used%20in%20a%20program%20(and%20the%20program%20is%20distributed)%2C%20then%20all%20other%20source%20code%20of%20the%20program%20needs%20to%20be%20made%20available%20under%20the%20same%20license%20terms).
That [forces us to use GPL as well](<https://en.wikipedia.org/wiki/GNU_General_Public_License#:~:text=Only%20if%20GPLed%20parts%20are%20used%20in%20a%20program%20(and%20the%20program%20is%20distributed)%2C%20then%20all%20other%20source%20code%20of%20the%20program%20needs%20to%20be%20made%20available%20under%20the%20same%20license%20terms>).
17 changes: 6 additions & 11 deletions src/receiver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ set(CMAKE_CXX_STANDARD 11)

find_package(SDL2 REQUIRED)

add_library(decoder Decoder.cpp)
add_library(decoder decoder.cpp)

target_include_directories(decoder
PUBLIC .
)
target_include_directories(decoder PUBLIC .)

target_link_libraries(decoder
PUBLIC x264 swscale avformat avcodec avutil pthread
)
target_link_libraries(decoder PUBLIC x264 swscale avformat avcodec avutil
pthread)

add_executable(video_player VideoPlayer.cpp)
add_executable(video_player video_player.cpp)

target_link_libraries(video_player
PUBLIC decoder ${SDL2_LIBRARIES}
)
target_link_libraries(video_player PUBLIC decoder ${SDL2_LIBRARIES})
14 changes: 8 additions & 6 deletions src/receiver/Decoder.cpp → src/receiver/decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Decoder.h"
#include "decoder.h"

#include <list>

Expand All @@ -11,18 +11,20 @@

// Serial port includes
#include <errno.h> //Error number definitions

#include <iomanip>

#include <fcntl.h> //File control definitions
#include <termios.h> //POSIX terminal control definitions
#include <unistd.h>

//#define ARDUINO_MSMT
// #define ARDUINO_MSMT
#define MSGLENGTH 30

void Decoder(const char* video_address, uint8_t** argb_raw, bool* newImg)
{
//---------------------------------------------------------------------------------------------------
//---------------------------- Variable intializations
//---------------------------- Variable initializations
//--------------------------------------------
//---------------------------------------------------------------------------------------------------

Expand All @@ -38,7 +40,7 @@ void Decoder(const char* video_address, uint8_t** argb_raw, bool* newImg)
std::list<AVPacket> pktlist;
#endif
//---------------------------------------------------------------------------------------------------
//---------------------------- Arduino intialization --------------------------------------------
//---------------------------- Arduino initialization --------------------------------------------
//---------------------------------------------------------------------------------------------------

#ifdef ARDUINO_MSMT
Expand Down Expand Up @@ -112,7 +114,7 @@ void Decoder(const char* video_address, uint8_t** argb_raw, bool* newImg)
#endif

//---------------------------------------------------------------------------------------------------
//---------------------------- Libav intialization
//---------------------------- Libav initialization
//----------------------------------------------
//---------------------------------------------------------------------------------------------------
// Simple startup without retrieving any stream info
Expand Down Expand Up @@ -154,7 +156,7 @@ void Decoder(const char* video_address, uint8_t** argb_raw, bool* newImg)
}

//---------------------------------------------------------------------------------------------------
//---------------------------- CSP conversion intialization
//---------------------------- CSP conversion initialization
//-------------------------------------
//---------------------------------------------------------------------------------------------------
m_pSwsCtxYuv2Bgra = sws_getContext(
Expand Down
1 change: 1 addition & 0 deletions src/receiver/Decoder.h → src/receiver/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// System includes
#include <stdio.h>
#include <stdlib.h>

#include <chrono>
#include <iostream>
#include <sstream>
Expand Down
10 changes: 6 additions & 4 deletions src/receiver/VideoPlayer.cpp → src/receiver/video_player.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <iomanip>

#include <SDL2/SDL.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "Decoder.h"

#include "decoder.h"

const char* video_url = "tcp://127.0.0.1:5001";
// const char * video_url = "tcp://10.152.4.207:5000";
Expand Down Expand Up @@ -45,7 +47,7 @@ int main(int argc, char* argv[])
int display = 0;
// if (SDL_GetNumVideoDisplays() > 1) {
// cout << "Choose display for video output.\n\n 0 = default desktop,\n 1 = secondary screen,\n etc." <<
//endl;
// endl;
// cin >> display;
// }

Expand Down Expand Up @@ -198,8 +200,8 @@ int main(int argc, char* argv[])

// Reset the newImage flag
newImage = false;
// std::cout << "t_cpy=" << std::chrono::duration_cast<std::chrono::microseconds>(m_end_time -
//m_start_time).count() << "\n";
// std::cout << "t_cpy=" <<
// std::chrono::duration_cast<std::chrono::microseconds>(m_end_time - m_start_time).count() << "\n";
}
}

Expand Down
44 changes: 25 additions & 19 deletions src/sender/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
cmake_minimum_required(VERSION 3.1)

option(BUILD_XIMEA "Build the ximea streaming application. Requires the Ximea SDK." OFF)
option(BUILD_XIMEA
"Build the ximea streaming application. Requires the Ximea SDK." OFF)

# Build instructions for USB cam application
find_package(OpenCV 4.0.0 REQUIRED)
set(LIBS
opencv_core opencv_highgui opencv_imgproc opencv_videoio # OpenCV related libs
x264 swscale avformat avcodec avutil swresample # x264 and ffmpeg libs
dl m z pthread va # libs required for ffmpeg
)
add_executable(usbCamStreamer
VideoStreamerTCP.cpp
usbCameraFrameGrabber.cpp
encoder.cpp
tcpSocket.cpp
opencv_core
opencv_highgui
opencv_imgproc
opencv_videoio # OpenCV related libs
x264
swscale
avformat
avcodec
avutil
swresample # x264 and ffmpeg libs
dl
m
z
pthread
va # libs required for ffmpeg
)
add_executable(
usbCamStreamer video_streamer_tcp.cpp usb_camera_frame_grabber.cpp
encoder.cpp tcp_socket.cpp)
target_link_libraries(usbCamStreamer PRIVATE ${LIBS})

if(BUILD_XIMEA)
set(LIBS ${LIBS} m3api) # Ximea API
add_executable(ximeaStreamer
VideoStreamerTCP.cpp
xiApiPlusOcv.cpp
ximeaCameraFrameGrabber.cpp
encoder.cpp
tcpSocket.cpp
)
set(LIBS ${LIBS} m3api) # Ximea API
add_executable(
ximeaStreamer video_streamer_tcp.cpp xi_api_plus_ocv.cpp
ximea_camera_frame_grabber.cpp encoder.cpp tcp_socket.cpp)
target_link_libraries(ximeaStreamer ${LIBS})
endif(BUILD_XIMEA)
endif(BUILD_XIMEA)
Loading
Loading