Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit 067ed91

Browse files
GegonzBrendan LE GLAUNEC
authored and
Brendan LE GLAUNEC
committed
Full containerization of workflow (#14)
* Tweak CES and run it easily inside docker * Code refacto * Override CES defaults only through env * Catch signals (to stop container) * Fix port issue binding * Fix typo in README * Update binary and container name to ces * Update README to move override options section * Update gitignore for new binary name
1 parent f7df3f9 commit 067ed91

File tree

10 files changed

+186
-201
lines changed

10 files changed

+186
-201
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333

3434
# Build artifacts
3535
build/
36-
camera_emulation_server
36+
ces

CMakeLists.txt

+21-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,28 @@
1414

1515
# min config
1616
cmake_minimum_required(VERSION 2.8.1)
17-
1817
cmake_policy(SET CMP0042 NEW)
1918

20-
set(PROJECT_NAME camera_emulation_server)
19+
set(PROJECT_NAME ces)
2120

2221
project(${PROJECT_NAME})
2322

23+
# function to retrieve files sources inside a list of folders
24+
function(find_sources DIRS)
25+
set(_headers "")
26+
set(_srcs "")
27+
foreach (dir ${ARGV})
28+
file (GLOB_RECURSE h_${dir} "${dir}/*.h" "${dir}/*.ipp" "${dir}/*.hpp")
29+
file (GLOB_RECURSE s_${dir} "${dir}/*.cpp" "${dir}/*.c" "${dir}/*.cxx")
30+
source_group (${dir} FILES ${s_${dir}} ${h_${dir}})
31+
set (_srcs ${_srcs} ${s_${dir}})
32+
set (_headers ${_headers} ${h_${dir}})
33+
endforeach ()
34+
set (SOURCES ${_srcs} PARENT_SCOPE)
35+
set (HEADERS ${_headers} PARENT_SCOPE)
36+
endfunction()
37+
38+
2439
# Cmake properties
2540
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2641
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
@@ -64,6 +79,7 @@ include_directories (
6479
"${GST_RTSP_SERVER_INCLUDE_DIRS}"
6580
)
6681

82+
6783
link_directories (
6884
"${GSTREAMER_LIBRARY_DIRS}"
6985
"${GST_RTSP_SERVER_LIBRARY_DIRS}"
@@ -79,6 +95,7 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
7995
link_directories (${GSTREAMER_APP_LIBRARY_DIRS})
8096
endif()
8197

82-
add_executable(camera_emulation_server "src/server.cpp")
98+
find_sources("src" "include")
99+
add_executable (ces ${HEADERS} ${SOURCES})
83100

84-
target_link_libraries (camera_emulation_server ${GSTREAMER_LIBRARIES} ${GST_RTSP_SERVER_LIBRARY_DIRS})
101+
target_link_libraries (ces ${GSTREAMER_LIBRARIES} ${GST_RTSP_SERVER_LIBRARY_DIRS})

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
66
apt-get clean &&\
77
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
88

9-
ADD camera_emulation_server /
9+
ADD ces /
1010
EXPOSE 8554
11-
ENTRYPOINT ["/camera_emulation_server"]
11+
ENTRYPOINT ["/ces"]

README.md

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
# CES : Camera Emulation Server 1.0.0
1+
# CES : Camera Emulation Server 1.1.0
22

33
[![License](https://img.shields.io/badge/license-Apache-blue.svg)](#license)
4-
[![Latest release](https://img.shields.io/badge/release-1.0.0-green.svg)](https://github.com/EtixLabs/CES/releases/latest)
4+
[![Latest release](https://img.shields.io/badge/release-1.1.0-green.svg)](https://github.com/EtixLabs/CES/releases/latest)
55

66
### RTSP server with authentication for testing purposes
77

88
## Dependencies
99

1010
* `docker`
1111

12-
## Examples of use
12+
## Usage from the official docker repository
1313

14-
To create a simple test stream, just launch the following command:
15-
`docker run -p 8554:8554 ullaakut/CES`
14+
You can create a stream by launching the official docker image:
15+
`docker run --rm -p 8554:8554 ullaakut/ces`
1616

17-
You can now access it on the URL `rtsp://0.0.0.0:8554/live.sdp`.
17+
With default options, stream will be available at `rtsp://0.0.0.0:8554/live.sdp`
18+
You can use [override options](#override-options)
1819

19-
To create a test stream with credentials, just add the RTSP_PASSWORD and RTSP_USERNAME arguments like so:
20-
21-
`docker run -p 8554:8554 -e RTSP_PASSWORD=mypass -e RTSP_USERNAME=myusername`
22-
23-
You can now access it on the URL `rtsp://myusername:[email protected]:8554/live.sdp`.
24-
25-
### Usage
20+
## Override options
2621

2722
```
28-
docker run \
29-
[-e RTSP_LISTEN_ADDRESS=your_listen_address] \
23+
docker run --rm \
24+
[-e RTSP_ADDRESS=your_address] \
3025
[-e RTSP_PORT=your_port] -p your_port:your_port \
31-
[-e RTSP_PATH=your_path] \
26+
[-e RTSP_ROUTE=your_route] \
3227
[-e RTSP_INPUT_FILE=your_input_file] \
3328
[-e RTSP_USERNAME=your_username] \
3429
[-e RTSP_PASSWORD=your_password] \
3530
[-e RTSP_RESOLUTION='your_width'x'your_height'] \
3631
[-e RTSP_FRAMERATE=your_framerate] \
3732
[-e GST_DEBUG=your_debug_level] \
38-
ullaakut/CES
33+
ullaakut/ces
3934
```
4035

41-
### Parameters
42-
43-
All of these options override the default parameters for CES
44-
* `your_listen_address`: The address you want your server to listen on [default: `0.0.0.0`]
45-
* `your_port`: The port that you want your server to listen on [default: `8554`] _Don't forget to also expose the port in your container with the -p option like in the example above_
46-
* `your_path`: The rtsp path at which you want your stream to be served [default: `/live.sdp`]
47-
* `your_input_file`: The video file you want to broadcast using CES [default: none]
48-
* `your_username`: If you want to enable security on your stream, using this option will allow you to specify the username required to access your stream [default: none]
49-
* `your_password`: If you want to enable security on your stream, using this option will allow you to specify the password required to access your stream [default: none]
50-
* `'your_width'x'your_height'`: The resolution at which you want to stream [default: `352x288`]
51-
* `your_framerate`: The desired output framerate for your stream [default: `25`]
52-
* `your_debug_level`: The desired debug level for GStreamer [default: none] _See [this link](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html) for more information on this variable_
36+
All of these environment variables override the default parameters for CES
37+
* `RTSP_ADDRESS`: The address you want your server to listen on [default: `0.0.0.0`]
38+
* `RTSP_PORT`: The port that you want your server to listen on [default: `8554`] _Don't forget to also expose the port in your container with the -p option like in the example above_
39+
* `RTSP_ROUTE`: The rtsp route at which you want your stream to be served [default: `/live.sdp`]
40+
* `RTSP_INPUT_FILE`: The video file you want to broadcast using CES [default: none]
41+
* `RTSP_USERNAME`: If you want to enable security on your stream, using this option will allow you to specify the username required to access your stream [default: none]
42+
* `RTSP_PASSWORD`: If you want to enable security on your stream, using this option will allow you to specify the password required to access your stream [default: none]
43+
* `RTSP_RESOLUTION`: The resolution at which you want to stream [default: `352x288`]
44+
* `RTSP_FRAMERATE`: The desired output framerate for your stream [default: `25`]
45+
* `GST_DEBUG`: The desired debug level for GStreamer [default: none] _See [this link](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html) for more information on this variable_
46+
47+
## Build and tweak yourself
48+
49+
You can tweak CES and create your own docker image. For this simply run:
50+
`./build.sh`
51+
52+
Then launch it with:
53+
`docker run --rm -p 8554:8554 ces`
54+
55+
With default options, stream will be available at `rtsp://0.0.0.0:8554/live.sdp`
56+
You can use [override options](#override-options)
5357

5458
## License
5559

build.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
set -e
44
set -x
55

6-
rm -f camera_emulation_server
6+
rm -f ces
7+
8+
# Build binary
79
docker build -f build_image/Dockerfile-build -t "build-ces" .
810
docker run --rm -v $PWD:/tmp/CES -w/tmp/CES build-ces
11+
12+
# Build image
13+
docker build -t "ces" .

build_image/build_ces_inside_docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ cmake ../CES
1010
make
1111

1212
# mv CES bin to mounted dir
13-
mv camera_emulation_server ../CES
13+
mv ces ../CES

include/server.h

+8-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@
1414

1515
#pragma once
1616

17-
#include <ctype.h>
18-
#include <gst/gst.h>
19-
#include <stdio.h>
20-
#include <stdlib.h>
21-
#include <string.h>
22-
#include <unistd.h>
23-
#include <memory>
24-
#include <cstdlib>
25-
2617
#include <gst/rtsp-server/rtsp-server.h>
18+
#include <memory>
2719

2820
typedef struct s_config {
2921
gchar *username;
@@ -44,5 +36,11 @@ typedef struct s_server {
4436
GstRTSPAuth *auth;
4537
GstRTSPToken *token;
4638
gchar *basic;
47-
std::unique_ptr<t_config> config;
39+
std::shared_ptr<t_config> config;
4840
} t_server;
41+
42+
void init(t_server *serv);
43+
int parse_args(std::shared_ptr<t_config> config, int argc, char **argv);
44+
void parse_env(std::shared_ptr<t_config> config);
45+
void init_server_auth(t_server *serv);
46+
int server_launch(t_server *serv);

src/main.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 Etix Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "server.h"
16+
#include <csignal>
17+
#include <iostream>
18+
19+
void signal_handler(int signal) {
20+
std::cout << "Signal " << std::to_string(signal) << " catched" << std::endl;
21+
exit(1);
22+
}
23+
24+
int main(int argc, char **argv) {
25+
std::signal(SIGINT, signal_handler);
26+
27+
/* Config parsing from env */
28+
t_server serv;
29+
std::shared_ptr<t_config> config = std::make_shared<t_config>();
30+
parse_env(config);
31+
serv.config = config;
32+
33+
gst_init(NULL, NULL);
34+
init_server_auth(&serv);
35+
return server_launch(&serv);
36+
}

src/parsing.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2016 Etix Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "server.h"
16+
#include <string.h>
17+
18+
void parse_env(std::shared_ptr<t_config> config) {
19+
if (const char *route = std::getenv("RTSP_PATH"))
20+
config->route = strdup(route);
21+
else
22+
config->route = strdup("/live.sdp");
23+
24+
if (const char *username = std::getenv("RTSP_USERNAME"))
25+
config->username = strdup(username);
26+
else
27+
config->username = strdup("");
28+
29+
if (const char *password = std::getenv("RTSP_PASSWORD"))
30+
config->password = strdup(password);
31+
else
32+
config->password = strdup("");
33+
34+
if (const char *input = std::getenv("RTSP_INPUT_FILE"))
35+
config->input = strdup(input);
36+
else
37+
config->input = strdup("");
38+
39+
if (const char *scale = std::getenv("RTSP_RESOLUTION")) {
40+
size_t pos = 0;
41+
std::string scale_str(scale);
42+
43+
if ((pos = scale_str.find("x")) == std::string::npos) {
44+
fprintf(stderr, "No x token found between width and height in the scale "
45+
"argument: %s\nUsing default values instead",
46+
scale);
47+
config->scale =
48+
std::make_pair<gchar *, gchar *>(strdup("352"), strdup("288"));
49+
} else {
50+
config->scale = std::make_pair<gchar *, gchar *>(
51+
strdup(scale_str.substr(0, pos).c_str()),
52+
strdup(scale_str.substr(pos + 1).c_str()));
53+
}
54+
} else {
55+
config->scale =
56+
std::make_pair<gchar *, gchar *>(strdup("352"), strdup("288"));
57+
}
58+
59+
if (const char *framerate = std::getenv("RTSP_FRAMERATE"))
60+
config->framerate = strdup(framerate);
61+
else
62+
config->framerate = strdup("25");
63+
64+
if (const char *address = std::getenv("RTSP_ADDRESS"))
65+
config->address = strdup(address);
66+
else
67+
config->address = strdup("0.0.0.0");
68+
69+
if (const char *port = std::getenv("RTSP_PORT"))
70+
config->port = strdup(port);
71+
else
72+
config->port = strdup("8554");
73+
}

0 commit comments

Comments
 (0)