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

Commit

Permalink
Full containerization of workflow (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Gegonz authored and Brendan LE GLAUNEC committed May 29, 2017
1 parent f7df3f9 commit 067ed91
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@

# Build artifacts
build/
camera_emulation_server
ces
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@

# min config
cmake_minimum_required(VERSION 2.8.1)

cmake_policy(SET CMP0042 NEW)

set(PROJECT_NAME camera_emulation_server)
set(PROJECT_NAME ces)

project(${PROJECT_NAME})

# function to retrieve files sources inside a list of folders
function(find_sources DIRS)
set(_headers "")
set(_srcs "")
foreach (dir ${ARGV})
file (GLOB_RECURSE h_${dir} "${dir}/*.h" "${dir}/*.ipp" "${dir}/*.hpp")
file (GLOB_RECURSE s_${dir} "${dir}/*.cpp" "${dir}/*.c" "${dir}/*.cxx")
source_group (${dir} FILES ${s_${dir}} ${h_${dir}})
set (_srcs ${_srcs} ${s_${dir}})
set (_headers ${_headers} ${h_${dir}})
endforeach ()
set (SOURCES ${_srcs} PARENT_SCOPE)
set (HEADERS ${_headers} PARENT_SCOPE)
endfunction()


# Cmake properties
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
Expand Down Expand Up @@ -64,6 +79,7 @@ include_directories (
"${GST_RTSP_SERVER_INCLUDE_DIRS}"
)


link_directories (
"${GSTREAMER_LIBRARY_DIRS}"
"${GST_RTSP_SERVER_LIBRARY_DIRS}"
Expand All @@ -79,6 +95,7 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
link_directories (${GSTREAMER_APP_LIBRARY_DIRS})
endif()

add_executable(camera_emulation_server "src/server.cpp")
find_sources("src" "include")
add_executable (ces ${HEADERS} ${SOURCES})

target_link_libraries (camera_emulation_server ${GSTREAMER_LIBRARIES} ${GST_RTSP_SERVER_LIBRARY_DIRS})
target_link_libraries (ces ${GSTREAMER_LIBRARIES} ${GST_RTSP_SERVER_LIBRARY_DIRS})
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
apt-get clean &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD camera_emulation_server /
ADD ces /
EXPOSE 8554
ENTRYPOINT ["/camera_emulation_server"]
ENTRYPOINT ["/ces"]
62 changes: 33 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
# CES : Camera Emulation Server 1.0.0
# CES : Camera Emulation Server 1.1.0

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

### RTSP server with authentication for testing purposes

## Dependencies

* `docker`

## Examples of use
## Usage from the official docker repository

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

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

To create a test stream with credentials, just add the RTSP_PASSWORD and RTSP_USERNAME arguments like so:

`docker run -p 8554:8554 -e RTSP_PASSWORD=mypass -e RTSP_USERNAME=myusername`

You can now access it on the URL `rtsp://myusername:[email protected]:8554/live.sdp`.

### Usage
## Override options

```
docker run \
[-e RTSP_LISTEN_ADDRESS=your_listen_address] \
docker run --rm \
[-e RTSP_ADDRESS=your_address] \
[-e RTSP_PORT=your_port] -p your_port:your_port \
[-e RTSP_PATH=your_path] \
[-e RTSP_ROUTE=your_route] \
[-e RTSP_INPUT_FILE=your_input_file] \
[-e RTSP_USERNAME=your_username] \
[-e RTSP_PASSWORD=your_password] \
[-e RTSP_RESOLUTION='your_width'x'your_height'] \
[-e RTSP_FRAMERATE=your_framerate] \
[-e GST_DEBUG=your_debug_level] \
ullaakut/CES
ullaakut/ces
```

### Parameters

All of these options override the default parameters for CES
* `your_listen_address`: The address you want your server to listen on [default: `0.0.0.0`]
* `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_
* `your_path`: The rtsp path at which you want your stream to be served [default: `/live.sdp`]
* `your_input_file`: The video file you want to broadcast using CES [default: none]
* `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]
* `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]
* `'your_width'x'your_height'`: The resolution at which you want to stream [default: `352x288`]
* `your_framerate`: The desired output framerate for your stream [default: `25`]
* `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_
All of these environment variables override the default parameters for CES
* `RTSP_ADDRESS`: The address you want your server to listen on [default: `0.0.0.0`]
* `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_
* `RTSP_ROUTE`: The rtsp route at which you want your stream to be served [default: `/live.sdp`]
* `RTSP_INPUT_FILE`: The video file you want to broadcast using CES [default: none]
* `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]
* `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]
* `RTSP_RESOLUTION`: The resolution at which you want to stream [default: `352x288`]
* `RTSP_FRAMERATE`: The desired output framerate for your stream [default: `25`]
* `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_

## Build and tweak yourself

You can tweak CES and create your own docker image. For this simply run:
`./build.sh`

Then launch it with:
`docker run --rm -p 8554:8554 ces`

With default options, stream will be available at `rtsp://0.0.0.0:8554/live.sdp`
You can use [override options](#override-options)

## License

Expand Down
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
set -e
set -x

rm -f camera_emulation_server
rm -f ces

# Build binary
docker build -f build_image/Dockerfile-build -t "build-ces" .
docker run --rm -v $PWD:/tmp/CES -w/tmp/CES build-ces

# Build image
docker build -t "ces" .
2 changes: 1 addition & 1 deletion build_image/build_ces_inside_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cmake ../CES
make

# mv CES bin to mounted dir
mv camera_emulation_server ../CES
mv ces ../CES
18 changes: 8 additions & 10 deletions include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@

#pragma once

#include <ctype.h>
#include <gst/gst.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <memory>
#include <cstdlib>

#include <gst/rtsp-server/rtsp-server.h>
#include <memory>

typedef struct s_config {
gchar *username;
Expand All @@ -44,5 +36,11 @@ typedef struct s_server {
GstRTSPAuth *auth;
GstRTSPToken *token;
gchar *basic;
std::unique_ptr<t_config> config;
std::shared_ptr<t_config> config;
} t_server;

void init(t_server *serv);
int parse_args(std::shared_ptr<t_config> config, int argc, char **argv);
void parse_env(std::shared_ptr<t_config> config);
void init_server_auth(t_server *serv);
int server_launch(t_server *serv);
36 changes: 36 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2016 Etix Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "server.h"
#include <csignal>
#include <iostream>

void signal_handler(int signal) {
std::cout << "Signal " << std::to_string(signal) << " catched" << std::endl;
exit(1);
}

int main(int argc, char **argv) {
std::signal(SIGINT, signal_handler);

/* Config parsing from env */
t_server serv;
std::shared_ptr<t_config> config = std::make_shared<t_config>();
parse_env(config);
serv.config = config;

gst_init(NULL, NULL);
init_server_auth(&serv);
return server_launch(&serv);
}
73 changes: 73 additions & 0 deletions src/parsing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2016 Etix Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "server.h"
#include <string.h>

void parse_env(std::shared_ptr<t_config> config) {
if (const char *route = std::getenv("RTSP_PATH"))
config->route = strdup(route);
else
config->route = strdup("/live.sdp");

if (const char *username = std::getenv("RTSP_USERNAME"))
config->username = strdup(username);
else
config->username = strdup("");

if (const char *password = std::getenv("RTSP_PASSWORD"))
config->password = strdup(password);
else
config->password = strdup("");

if (const char *input = std::getenv("RTSP_INPUT_FILE"))
config->input = strdup(input);
else
config->input = strdup("");

if (const char *scale = std::getenv("RTSP_RESOLUTION")) {
size_t pos = 0;
std::string scale_str(scale);

if ((pos = scale_str.find("x")) == std::string::npos) {
fprintf(stderr, "No x token found between width and height in the scale "
"argument: %s\nUsing default values instead",
scale);
config->scale =
std::make_pair<gchar *, gchar *>(strdup("352"), strdup("288"));
} else {
config->scale = std::make_pair<gchar *, gchar *>(
strdup(scale_str.substr(0, pos).c_str()),
strdup(scale_str.substr(pos + 1).c_str()));
}
} else {
config->scale =
std::make_pair<gchar *, gchar *>(strdup("352"), strdup("288"));
}

if (const char *framerate = std::getenv("RTSP_FRAMERATE"))
config->framerate = strdup(framerate);
else
config->framerate = strdup("25");

if (const char *address = std::getenv("RTSP_ADDRESS"))
config->address = strdup(address);
else
config->address = strdup("0.0.0.0");

if (const char *port = std::getenv("RTSP_PORT"))
config->port = strdup(port);
else
config->port = strdup("8554");
}
Loading

0 comments on commit 067ed91

Please sign in to comment.