Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 381858c

Browse files
committed
First release
Signed-off-by: Zhou, Cheng <cheng.zhou@intel.com>
0 parents  commit 381858c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+11134
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
3+
Project(OVC NONE)
4+
5+
file(GLOB dirs "deployment" "*")
6+
list(REMOVE_DUPLICATES dirs)
7+
foreach(dir ${dirs})
8+
if(EXISTS ${dir}/CMakeLists.txt)
9+
add_subdirectory(${dir})
10+
endif()
11+
endforeach()
12+
13+
# legal message
14+
execute_process(COMMAND printf "\nThis script will build third party components licensed under various open source licenses into your container images. The terms under which those components may be used and distributed can be found with the license document that is provided with those components. Please familiarize yourself with those terms to ensure your distribution of those components complies with the terms of those licenses.\n\n")

LICENSE

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This project is for Open Visual Cloud CDN Transcode E2E Sample.
2+
3+
## Key ingredients in this repo
4+
- Dockerfiles
5+
- CMakefiles
6+
- Configuration files
7+
- Helper scripts
8+
- Reference Architecture document
9+
- User Guide (Getting Started Guide) document
10+
11+
## How to get started?
12+
- Refer to "doc/CDN_Transcode_Sample_RA.md" to understand the design.
13+
- Refer to "doc/CDN_Transcode_Sample_Getting_Started_Guide.md" to setup and run the sample.
14+

cdn-server/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CMakeLists.txt
2+
*.sh
3+
*.m4
4+
test/*

cdn-server/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(service "ovc_cdn_service")
2+
include("${CMAKE_SOURCE_DIR}/script/service.cmake")

cdn-server/Dockerfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
FROM ubuntu:18.04 AS build
3+
WORKDIR /home
4+
5+
# COMMON BUILD TOOLS
6+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y -q --no-install-recommends build-essential autoconf make git wget pciutils cpio libtool lsb-release ca-certificates pkg-config bison flex
7+
8+
# Install cmake
9+
ARG CMAKE_VER=3.13.1
10+
ARG CMAKE_REPO=https://cmake.org/files
11+
RUN wget -O - ${CMAKE_REPO}/v${CMAKE_VER%.*}/cmake-${CMAKE_VER}.tar.gz | tar xz && \
12+
cd cmake-${CMAKE_VER} && \
13+
./bootstrap --prefix="/usr" && \
14+
make -j8 && \
15+
make install
16+
17+
# Install automake, use version 1.14 on CentOS
18+
ARG AUTOMAKE_VER=1.14
19+
ARG AUTOMAKE_REPO=https://ftp.gnu.org/pub/gnu/automake/automake-${AUTOMAKE_VER}.tar.xz
20+
RUN apt-get install -y -q automake
21+
22+
# Build nginx-rtmp
23+
ARG NGINX_RTMP_VER=v1.2.1
24+
ARG NGINX_RTMP_REPO=https://github.com/arut/nginx-rtmp-module/archive/${NGINX_RTMP_VER}.tar.gz
25+
ARG NGINX_RTMP_PATCH_HLS=https://raw.githubusercontent.com/VCDP/CDN/master/0001-add-hevc-support-for-rtmp-and-hls.patch
26+
ARG NGINX_RTMP_PATCH_DASH=https://raw.githubusercontent.com/VCDP/CDN/master/0002-add-HEVC-support-for-dash.patch
27+
28+
RUN wget -O - ${NGINX_RTMP_REPO} | tar xz && mv nginx-rtmp-module-${NGINX_RTMP_VER#v} nginx-rtmp-module && \
29+
cd nginx-rtmp-module && \
30+
wget -O - ${NGINX_RTMP_PATCH_HLS} | patch -p1 && \
31+
wget -O - ${NGINX_RTMP_PATCH_DASH} | patch -p1
32+
33+
34+
# Build nginx & nginx-rtmp
35+
ARG NGINX_VER=1.14.2
36+
ARG NGINX_REPO=https://nginx.org/download/nginx-${NGINX_VER}.tar.gz
37+
38+
RUN apt-get update && apt-get install -y -q --no-install-recommends libssl-dev libpcre3-dev zlib1g-dev libxslt1-dev
39+
40+
RUN wget -O - ${NGINX_REPO} | tar xz && \
41+
cd nginx-${NGINX_VER} && \
42+
./configure --prefix=/var/www --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/x86_64-linux-gnu/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/www/log/error.log --pid-path=/var/www/nginx.pid --lock-path=/var/www/nginx.lock --http-log-path=/var/www/log/access.log --http-client-body-temp-path=/var/www/tmp/client_body --http-proxy-temp-path=/var/www/tmp/proxy --http-fastcgi-temp-path=/var/www/tmp/fastcgi --http-uwsgi-temp-path=/var/www/tmp/uwsgi --http-scgi-temp-path=/var/www/tmp/scgi --user=www-data --group=www-data --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-pcre --add-module=../nginx-rtmp-module && \
43+
make -j8 && \
44+
make install DESTDIR=/home/build
45+
46+
# NGINX Setup
47+
RUN mkdir -p /home/build/var/www/tmp/client_body && \
48+
mkdir -p /home/build/var/www/tmp/proxy && \
49+
mkdir -p /home/build/var/www/tmp/fastcgi && \
50+
mkdir -p /home/build/var/www/tmp/uwsgi && \
51+
mkdir -p /home/build/var/www/tmp/scgi && \
52+
mkdir -p /home/build/var/www/cache && \
53+
mkdir -p /home/build/var/www/html
54+
55+
56+
FROM ubuntu:18.04
57+
LABEL Description="This is the base image for a NGINX+RTMP service"
58+
LABEL Vendor="Intel Corporation"
59+
WORKDIR /home
60+
61+
# Prerequisites
62+
RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime && \
63+
DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y -q --no-install-recommends libxml2 libssl-dev libpcre3 zlib1g libxslt1.1 python3-tornado python3-kafka python3-bs4 python3-kazoo vim && \
64+
rm -rf /var/lib/apt/lists/*
65+
# Install
66+
COPY --from=build /home/build /
67+
COPY *.xsl /etc/nginx/
68+
COPY *.conf /etc/nginx/
69+
COPY *.ini /home/
70+
COPY *.py /home/
71+
CMD ["/bin/bash","-c","/home/main.py&/usr/sbin/nginx"]
72+
VOLUME /etc/nginx /var/www/html /var/www/tmp/client_body /var/www/tmp/proxy /var/www/tmp/fastcgi /var/www/tmp/uwsgi /var/www/tmp/scgi /var/www/cache /var/www/dash /var/www/hls
73+
EXPOSE 8080

cdn-server/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -e
2+
3+
IMAGE="ovc_cdn_service"
4+
DIR=$(dirname $(readlink -f "$0"))
5+
6+
. "${DIR}/../script/build.sh"

cdn-server/config.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
timeSpan=20000
3+
[mode]
4+
srcMode=local
5+
[path]
6+
srcPath=/var/www/archive
7+

cdn-server/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/python3
2+
3+
from tornado import ioloop, web
4+
from tornado.options import define, options, parse_command_line
5+
from playlist import PlayListHandler
6+
from schedule import ScheduleHandler
7+
8+
APP = web.Application([
9+
(r'/playlist', PlayListHandler),
10+
(r'/schedule/.*', ScheduleHandler),
11+
])
12+
13+
if __name__ == "__main__":
14+
define("port", default=2222, help="the binding port", type=int)
15+
define("ip", default="127.0.0.1", help="the binding ip")
16+
parse_command_line()
17+
print("Listening to " + options.ip + ":" + str(options.port))
18+
APP.listen(options.port, address=options.ip)
19+
ioloop.IOLoop.instance().start()

cdn-server/messaging.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/python3
2+
3+
import socket
4+
from kafka import KafkaProducer, KafkaConsumer, TopicPartition
5+
6+
KAFKA_HOSTS = ["kafka:9092"]
7+
8+
class Producer():
9+
def __init__(self):
10+
super(Producer, self).__init__()
11+
self._client_id = socket.gethostname()
12+
self._producer = None
13+
14+
def send(self, topic, message):
15+
if not self._producer:
16+
try:
17+
self._producer = KafkaProducer(bootstrap_servers=KAFKA_HOSTS,
18+
client_id=self._client_id,
19+
api_version=(0, 10), retries=1)
20+
except Exception as e:
21+
print(str(e))
22+
self._producer = None
23+
24+
if self._producer:
25+
try:
26+
self._producer.send(topic, message.encode('utf-8'))
27+
print("send "+topic+": ")
28+
print(message)
29+
except Exception as e:
30+
print(str(e))
31+
else:
32+
print("producer not available")
33+
34+
def flush(self):
35+
if self._producer:
36+
self._producer.flush()
37+
38+
def close(self):
39+
if self._producer:
40+
self.flush()
41+
self._producer.close()
42+
43+
class Consumer():
44+
def __init__(self, group=None):
45+
super(Consumer, self).__init__()
46+
self._client_id = socket.gethostname()
47+
self._group = group
48+
49+
def messages(self, topic, timeout=None):
50+
c = KafkaConsumer(topic, bootstrap_servers=KAFKA_HOSTS, client_id=self._client_id,
51+
group_id=self._group, api_version=(0, 10))
52+
53+
partitions = c.partitions_for_topic(topic)
54+
if not partitions:
55+
raise Exception("Topic "+topic+" not exist")
56+
57+
timeout1 = 100 if timeout is None else timeout
58+
while True:
59+
partitions = c.poll(timeout1)
60+
if partitions:
61+
for p in partitions:
62+
for msg in partitions[p]:
63+
yield msg.value.decode('utf-8')
64+
if timeout is not None:
65+
yield ""
66+
67+
c.close()
68+
69+
def debug(self, topic):
70+
c = KafkaConsumer(bootstrap_servers=KAFKA_HOSTS, client_id=self._client_id,
71+
group_id=None, api_version=(0, 10))
72+
73+
# assign/subscribe topic
74+
partitions = c.partitions_for_topic(topic)
75+
if not partitions:
76+
raise Exception("Topic "+topic+" not exist")
77+
c.assign([TopicPartition(topic, p) for p in partitions])
78+
79+
# seek to beginning if needed
80+
c.seek_to_beginning()
81+
82+
# fetch messages
83+
while True:
84+
partitions = c.poll(100)
85+
if partitions:
86+
for p in partitions:
87+
for msg in partitions[p]:
88+
yield msg.value.decode('utf-8')
89+
yield ""
90+
91+
c.close()

cdn-server/nginx.conf

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
2+
worker_processes auto;
3+
worker_rlimit_nofile 8192;
4+
daemon off;
5+
6+
events {
7+
worker_connections 4096;
8+
}
9+
10+
rtmp {
11+
server {
12+
listen 1935;
13+
chunk_size 4000;
14+
15+
application stream {
16+
live on;
17+
}
18+
19+
application hls {
20+
live on;
21+
hls on;
22+
hls_path /var/www/hls;
23+
hls_nested on;
24+
hls_fragment 3;
25+
hls_playlist_length 60;
26+
}
27+
28+
application dash {
29+
live on;
30+
dash on;
31+
dash_path /var/www/dash;
32+
dash_fragment 3;
33+
dash_playlist_length 60;
34+
dash_nested on;
35+
}
36+
}
37+
}
38+
39+
http {
40+
include mime.types;
41+
default_type application/octet-stream;
42+
proxy_cache_path /var/www/cache levels=1:2 keys_zone=one:10m use_temp_path=off;
43+
44+
server {
45+
listen 8080 ssl;
46+
server_name _;
47+
client_body_timeout 5s;
48+
client_header_timeout 5s;
49+
50+
ssl_certificate /run/secrets/self.crt;
51+
ssl_certificate_key /run/secrets/self.key;
52+
ssl_dhparam /run/secrets/dhparam.pem;
53+
54+
ssl_protocols TLSv1.2;
55+
ssl_prefer_server_ciphers on;
56+
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
57+
ssl_ecdh_curve secp384r1;
58+
ssl_session_cache shared:SSL:10m;
59+
ssl_session_tickets off;
60+
ssl_stapling off;
61+
ssl_stapling_verify off;
62+
63+
location / {
64+
root /var/www/html;
65+
sendfile on;
66+
67+
# proxy cache settings
68+
proxy_cache one;
69+
proxy_no_cache $http_pragma $http_authorization;
70+
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
71+
proxy_cache_valid 200 302 10m;
72+
proxy_cache_valid 303 1m;
73+
74+
add_header 'Access-Control-Allow-Origin' '*' always;
75+
add_header 'X-Frame-Options' 'deny' always;
76+
add_header 'X-XSS-Protection' '1' always;
77+
add_header 'X-Content-Type-Options' 'nosniff' always;
78+
ssi on;
79+
}
80+
81+
location /api/playlist {
82+
add_header Cache-Control no-cache;
83+
rewrite ^/api(/playlist.*) $1 break;
84+
proxy_pass http://localhost:2222;
85+
}
86+
87+
location /hls/ {
88+
alias /var/www/hls/;
89+
add_header Cache-Control no-cache;
90+
add_header 'Access-Control-Allow-Origin' '*' always;
91+
add_header 'Access-Control-Expose-Headers' 'Content-Length';
92+
types {
93+
application/vnd.apple.mpegurl m3u8;
94+
video/mp2t ts;
95+
}
96+
}
97+
98+
location /dash/ {
99+
alias /var/www/dash/;
100+
add_header Cache-Control no-cache;
101+
add_header 'Access-Control-Allow-Origin' '*' always;
102+
add_header 'Access-Control-Expose-Headers' 'Content-Length';
103+
types {
104+
application/dash+xml mpd;
105+
}
106+
}
107+
108+
location ~* /dash/.*/index.mpd$ {
109+
alias /var/www;
110+
add_header Cache-Control no-cache;
111+
add_header 'Access-Control-Allow-Origin' '*' always;
112+
add_header 'Access-Control-Expose-Headers' 'Content-Length';
113+
types {
114+
application/dash+xml mpd;
115+
}
116+
try_files $uri @dashls;
117+
}
118+
119+
location ~* /hls/.*/index.m3u8$ {
120+
alias /var/www;
121+
add_header Cache-Control no-cache;
122+
add_header 'Access-Control-Allow-Origin' '*' always;
123+
add_header 'Access-Control-Expose-Headers' 'Content-Length';
124+
types {
125+
application/vnd.apple.mpegurl m3u8;
126+
}
127+
try_files $uri @dashls;
128+
}
129+
130+
location @dashls {
131+
add_header Cache-Control no-cache;
132+
rewrite ^/(dash|hls)/(.*) /schedule/$1/$2 break;
133+
proxy_pass http://localhost:2222;
134+
}
135+
136+
location ~* /thumbnail/.*.png$ {
137+
root /var/www/archive;
138+
add_header Cache-Control no-cache;
139+
rewrite ^/thumbnail(/.*) $1 break;
140+
}
141+
142+
location /stat {
143+
rtmp_stat all;
144+
rtmp_stat_stylesheet stat.xsl;
145+
}
146+
147+
location /stat.xsl {
148+
root /etc/nginx/;
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)