From c6a9c1ced5146745cb37cf9676e86aed7d49d773 Mon Sep 17 00:00:00 2001 From: Geno Date: Thu, 28 Jan 2021 02:08:06 +0100 Subject: [PATCH] dirty support for 0.8.0 - osp-rtmp daemon --- defaults/main.yml | 3 ++- handlers/main.yml | 6 ++++++ tasks/main.yml | 14 +++++++++++++- templates/config.py.dist | 2 ++ templates/ejabberd.yml | 2 +- templates/nginx.conf | 2 -- templates/osp-redirects.conf | 4 ++-- templates/osp-rtmp.conf | 30 +++++++++++++++++------------- templates/osp-rtmp.service | 24 ++++++++++++++++++++++++ 9 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 templates/osp-rtmp.service diff --git a/defaults/main.yml b/defaults/main.yml index 2258553..e7cab7c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,8 @@ --- osp_git_root: 'https://gitlab.com/Deamos/flask-nginx-rtmp-manager.git' osp_git_commit: '0.7.9' -osp_worker_start_port: 5000 +osp_worker_rtmp_port: 5999 +osp_worker_start_port: 5010 osp_worker_count: "{{ ansible_processor_nproc }}" osp_worker_timeout: 30 # should not be edited diff --git a/handlers/main.yml b/handlers/main.yml index 09e6051..fdc7491 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -22,3 +22,9 @@ name: osp.target state: restarted daemon_reload: yes + +- name: restart osp-rtmp + systemd: + name: osp-rtmp + state: restarted + daemon_reload: yes diff --git a/tasks/main.yml b/tasks/main.yml index b2e3983..a5db0e9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -165,6 +165,13 @@ dest: "/opt/osp/conf/config.py" state: link +- name: Configure supply rtmp + notify: restart osp-rtmp + file: + src: "/etc/osp.conf" + dest: "/opt/osp/installs/osp-rtmp/conf/config.py" + state: link + - name: Create logging directory file: path: /opt/osp @@ -198,9 +205,14 @@ loop: - osp-worker@.service - osp.target + - osp-rtmp.service - name: Start OSP systemd: - name: osp.target + name: "{{ item }}" state: started enabled: yes + loop: + - osp.target + - osp-rtmp.service + - osp.target diff --git a/templates/config.py.dist b/templates/config.py.dist index 873ab98..dbbe580 100644 --- a/templates/config.py.dist +++ b/templates/config.py.dist @@ -24,6 +24,8 @@ requireEmailRegistration={{ osp_require_email_registration }} # Enables Debug Mode debugMode = False +ospCoreAPI = "http://127.0.0.1:{{ osp_worker_start_port }}" + # EJabberD Configuration ejabberdAdmin = "admin" ejabberdPass = "{{ osp_ejabberd_password }}" diff --git a/templates/ejabberd.yml b/templates/ejabberd.yml index 07214cc..e05570c 100644 --- a/templates/ejabberd.yml +++ b/templates/ejabberd.yml @@ -161,7 +161,7 @@ shaper_rules: auth_use_cache: false auth_password_format: scram -extauth_program: "/usr/bin/python3 /opt/osp/setup/ejabberd/auth_osp.py" +extauth_program: "/usr/bin/python3 /opt/osp/installs/ejabberd/setup/auth_osp.py" extauth_instances: 3 host_config: diff --git a/templates/nginx.conf b/templates/nginx.conf index cd9cb4f..2b7804f 100644 --- a/templates/nginx.conf +++ b/templates/nginx.conf @@ -67,9 +67,7 @@ http { # sticky cookie srv_id expires=8h; hash $remote_addr consistent; {% for n in range(osp_worker_count) %} -{% if n != 0 or osp_worker_count == 1 %} server 127.0.0.1:{{ osp_worker_start_port + n }}; -{% endif %} {% endfor %} } diff --git a/templates/osp-redirects.conf b/templates/osp-redirects.conf index 2bbd396..8deb7a1 100644 --- a/templates/osp-redirects.conf +++ b/templates/osp-redirects.conf @@ -106,12 +106,12 @@ location /edge { auth_request /ospAuth; - rewrite ^/edge/(.*)$ $scheme://$ospedge_node/live/$1 redirect; + rewrite ^/edge/(.*)$ $scheme://$ospedge_node/edge/$1 redirect; } location /edge-adapt { auth_request /ospAuth; - rewrite ^/edge-adapt/(.*)$ $scheme://$ospedge_node/live-adapt/$1 redirect; + rewrite ^/edge-adapt/(.*)$ $scheme://$ospedge_node/edge-adapt/$1 redirect; } location /http-bind/ { # BOSH XMPP-HTTP diff --git a/templates/osp-rtmp.conf b/templates/osp-rtmp.conf index 541caa3..5f675ff 100644 --- a/templates/osp-rtmp.conf +++ b/templates/osp-rtmp.conf @@ -6,6 +6,9 @@ rtmp { #listen 1935; listen [::]:1935; chunk_size 4096; + ping 30s; + ping_timeout 15s; + drop_idle_publisher 15s; application stream { live on; @@ -17,8 +20,8 @@ rtmp { allow play 127.0.0.1; deny play all; - on_publish http://127.0.0.1:{{ osp_worker_start_port }}/auth-key; - on_publish_done http://127.0.0.1:{{ osp_worker_start_port }}/deauth-user; + on_publish http://127.0.0.1:{{ osp_worker_rtmp_port }}/auth-key; + on_publish_done http://127.0.0.1:{{ osp_worker_rtmp_port }}/deauth-user; } application stream-data { @@ -30,17 +33,18 @@ rtmp { allow play 127.0.0.1; deny play all; - on_publish http://127.0.0.1:{{ osp_worker_start_port }}/auth-user; + on_publish http://127.0.0.1:{{ osp_worker_rtmp_port }}/auth-user; push rtmp://127.0.0.1:1935/live/; push rtmp://127.0.0.1:1935/record/; hls on; hls_path {{ osp_http_path }}/live; hls_fragment 1; - hls_playlist_length 30s; + #hls_playlist_length 30s; + hls_playlist_length 30m; hls_nested on; - hls_fragment_naming system; + hls_fragment_naming sequential; recorder thumbnail { record video; @@ -62,12 +66,12 @@ rtmp { allow play 127.0.0.1; deny play all; - on_publish http://127.0.0.1:{{ osp_worker_start_port }}/auth-user; + on_publish http://127.0.0.1:{{ osp_worker_rtmp_port }}/auth-user; push rtmp://127.0.0.1:1935/live/; push rtmp://127.0.0.1:1935/record/; exec ffmpeg -i rtmp://127.0.0.1:1935/live/$name - -c:v libx264 -c:a aac -b:a 192k -vf "scale=-2:1080" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 4192k -bufsize 8384k -threads 4 -f flv rtmp://127.0.0.1:1935/show/$name_1080 + # -c:v libx264 -c:a aac -b:a 192k -vf "scale=-2:1080" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 4192k -bufsize 8384k -threads 4 -f flv rtmp://127.0.0.1:1935/show/$name_1080 -c:v libx264 -c:a aac -b:a 128k -vf "scale=-2:720" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 2096k -bufsize 4192k -threads 4 -f flv rtmp://127.0.0.1:1935/show/$name_720 -c:v libx264 -c:a aac -b:a 96k -vf "scale=-2:480" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 1200k -bufsize 2400k -threads 4 -f flv rtmp://127.0.0.1:1935/show/$name_480; # -c copy -f flv rtmp://127.0.0.1:1935/show/$name_src; @@ -98,9 +102,10 @@ rtmp { hls_path {{ osp_http_path }}/live-adapt; hls_nested on; hls_fragment 1; - hls_playlist_length 30s; + #hls_playlist_length 30s; + hls_playlist_length 30m; - hls_fragment_naming system; + hls_fragment_naming sequential; record off; @@ -121,7 +126,7 @@ rtmp { allow play 127.0.0.1; deny play all; - on_publish http://127.0.0.1:{{ osp_worker_start_port }}/auth-record; + on_publish http://127.0.0.1:{{ osp_worker_rtmp_port }}/auth-record; exec_push mkdir -m 764 {{ osp_http_path }}/videos/$name; recorder all { @@ -132,19 +137,18 @@ rtmp { exec_record_done bash -c "ffmpeg -y -i $path -codec copy -movflags +faststart {{ osp_http_path }}/videos/$name/$basename.mp4 && rm $path"; exec_record_done mv {{ osp_http_path }}/stream-thumb/$name.png {{ osp_http_path }}/videos/$name/$basename.png; exec_record_done mv {{ osp_http_path }}/stream-thumb/$name.gif {{ osp_http_path }}/videos/$name/$basename.gif; - on_record_done http://127.0.0.1:{{ osp_worker_start_port }}/deauth-record; + on_record_done http://127.0.0.1:{{ osp_worker_rtmp_port }}/deauth-record; } } application live { live on; - drop_idle_publisher 30s; allow publish ::1; allow publish 127.0.0.1; deny publish all; allow play all; - on_play http://127.0.0.1:{{ osp_worker_start_port }}/playbackAuth; + on_play http://127.0.0.1:{{ osp_worker_rtmp_port }}/playbackAuth; } } } diff --git a/templates/osp-rtmp.service b/templates/osp-rtmp.service new file mode 100644 index 0000000..2beb5c2 --- /dev/null +++ b/templates/osp-rtmp.service @@ -0,0 +1,24 @@ +[Unit] +Description=Gunicorn instance to serve OSP-RTMP +After=network.target ejabberd.service redis.service +PartOf=osp.target + +{% if osp_db_type == "postgresql" %} +After=postgresql.service +{% endif %} +{% if osp_db_type == "mysql" %} +After=mysql.service +{% endif %} + +[Service] +User=http +Group=http +WorkingDirectory=/opt/osp/installs/osp-rtmp/ +Environment="VIRTUAL_ENV=/opt/osp-venv" +Environment="PATH=/opt/osp-venv/bin:/usr/local/bin:/usr/bin:/bin" +ExecStart=/opt/osp-venv/bin/gunicorn app:app -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --bind 127.0.0.1:{{ osp_worker_rtmp_port }} --reload --access-logfile /var/log/osp/access.log --error-logfile /var/log/osp/error.log +Restart=on-failure +RestartSec=5m + +[Install] +WantedBy=multi-user.target