From 91ed667bf4b8fcb0f96a15713ddabbc108a674db Mon Sep 17 00:00:00 2001 From: Julian Rother <julianr@fsmpi.rwth-aachen.de> Date: Thu, 4 Jan 2018 19:56:19 +0100 Subject: [PATCH] Extended legacy livestream api to support job-based encoding --- db_schema.sql | 3 ++- livestreams.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/db_schema.sql b/db_schema.sql index 67227e4..7086fa1 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -176,7 +176,8 @@ CREATE TABLE IF NOT EXISTS `streams` ( `visible` INTEGER NOT NULL, `lecture_id` INTEGER NOT NULL, `description` text NOT NULL, - `poster` text NOT NULL + `poster` text NOT NULL, + `job_id` INTEGER ); CREATE TABLE IF NOT EXISTS `stream_stats` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, diff --git a/livestreams.py b/livestreams.py index 626eea2..42ebc0d 100644 --- a/livestreams.py +++ b/livestreams.py @@ -7,7 +7,8 @@ def livestream_thumbnail(): schedule_job('thumbnail', {'lectureid': str(v['lecture_id']), 'path': v['path']}) @app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST']) -def streamauth(): +@app.route('/internal/streaming/legacy_auth/<server>', methods=['GET', 'POST']) +def streamauth(server=None): internal = False for net in config.get('FSMPI_IP_RANGES', []): if ip_address(request.headers['X-Real-IP']) in ip_network(net): @@ -33,10 +34,25 @@ def streamauth(): modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, 0, 1, -1, "", "")", request.values['name']) except: pass - modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", match['id'], request.values['name']) + if server: + data = {'src': 'rtmp://%s/live/%s'%(server, request.values['name']), + 'destbase': 'rtmp://%s/hls/%s'%(server, request.values['name'])} + job_id = schedule_job('simple_live_transcode', data, priority=10) + modify("UPDATE streams SET active = 1, lecture_id = ?, job_id = ? WHERE handle = ?", + match['id'], job_id, request.values['name']) + else: + modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", + match['id'], request.values['name']) elif request.values['call'] == 'publish_done': + job_id = query('SELECT job_id FROM streams WHERE handle = ?', request.values['name'])[0]['job_id'] modify("UPDATE streams SET active = 0 WHERE handle = ?", request.values['name']) + if job_id: + cancel_job(job_id) else: return 'Bad request', 400 return 'OK', 200 +@job_handler('simple_live_transcode', state='failed') +def restart_failed_live_transcode(id, type, data, state, status): + restart_job(id) + -- GitLab