Fix feed crash, more api bindings

master
informatic 2018-06-18 21:39:04 +02:00
parent eda5b4de5e
commit f718823d21
3 changed files with 49 additions and 14 deletions

View File

@ -61,7 +61,19 @@ def patch_scene(scene_id, req):
if 'text_alpha' in req:
app.snowmix.scene_alpha(scene_id, req['text_alpha'], -2)
if 'background_alpha' in req:
app.snowmix.scene_alpha(scene_id, req['text_alpha'], -3)
app.snowmix.scene_alpha(scene_id, req['background_alpha'], -3)
def patch_frame(scene_id, frame_id, req):
if 'active' in req:
app.snowmix.frame_set_active(scene_id, frame_id, bool(req['active']))
if 'alpha' in req.get('front', {}):
app.snowmix.scene_alpha(scene_id, req['front']['alpha'], frame_id)
if 'alpha' in req.get('back', {}):
app.snowmix.scene_alpha(scene_id, req['back']['alpha'], frame_id, back=True)
if 'source' in req.get('front', {}):
app.snowmix.frame_set_source(scene_id, frame_id, req['front']['source'])
if 'source' in req.get('back', {}):
app.snowmix.frame_set_source(scene_id, frame_id, req['back']['source'], True)
@app.route('/api/1/scenes/<int:scene_id>', methods=['PATCH'])
def scene_patch(scene_id):
@ -90,6 +102,10 @@ def command(cmd):
def on_scene_mod(data):
patch_scene(int(data.pop('id')), data)
@socketio.on('frame_mod')
def on_frame_mod(data):
patch_frame(int(data.pop('scene_id')), int(data.pop('frame_id')), data)
@socketio.on('scene_cut')
def on_scene_cut(data):
app.snowmix.scene_cut(int(data.pop('id')))

View File

@ -10,7 +10,8 @@ tclparser = nestedExpr('{', '}')
scene_head_re = re.compile(r'Scene (\d+) active ([01])"? WxH (\d+)x(\d+) at (\d+),(\d+) name (.*)')
scene_back_re = re.compile(r'- back : (\w+) (\d+) WxH (\d+)x(\d+) at ([\d.]+),([\d.]+) shape (\d+) place (\d+)')
scene_frame_re = re.compile(r'- frame (\d+) active (\d+) : (\d+)x(\d+) at (\d+),(\d+) source ([\w-]+),([\w-]+) id ([\d-]+),([\d-]+) shape (\d+),(\d+) place (\d+),(\d+)')
image_list_re = re.compile('^image load (\d+) <(.*)> (\d+)x(\d+) bit depth (\d+) type (.*) seqno (\d+)$')
image_list_re = re.compile(r'^image load (\d+) <(.*)> (\d+)x(\d+) bit depth (\d+) type (.*) seqno (\d+)$')
image_name_re = re.compile(r'^image name (\d+) <(.*)>$')
feed_list_re = re.compile(r'^feed (\d+) : (.*) (.*) (.*) (\d+)x(\d+) (\d+),(\d+) (\d+)x(\d+) (\d+),(\d+) (\d+):(\d+) (\d+) (\d+) (\d+) <(.*)>$')
def parse_tcl(data):
@ -117,7 +118,7 @@ class SnowmixClient(object):
return s
def image_list(self):
images = []
images = {}
for l in self.call('image load'):
img = {}
img['id'], img['source'], img['width'], img['height'], \
@ -125,8 +126,13 @@ class SnowmixClient(object):
image_list_re.match(l).groups()
cast(img, int, ['width', 'height', 'bit', 'seqno'])
images.append(img)
return images
images[img['id']] = img
for l in self.call('image name'):
img_id, name = image_name_re.match(l).groups()
images[img_id]['name'] = name
return list(images.values())
def feed_list(self):
feeds = []
@ -151,13 +157,26 @@ class SnowmixClient(object):
def scene_fade(self, scene_id):
self.tcl('SceneSetState %d 1 1' % scene_id)
def scene_alpha(self, scene_id, alpha, frame_id=-1):
self.tcl('SceneAlpha %d %d %f' % (scene_id, frame_id, alpha))
def scene_alpha(self, scene_id, alpha, frame_id=-1, back=False):
if back:
self.tcl('SceneAlpha %d %d - %f' % (scene_id, frame_id, alpha))
else:
self.tcl('SceneAlpha %d %d %f' % (scene_id, frame_id, alpha))
def frame_set_source(self, scene_id, frame_id, source, back=False):
source = source.split(':')
self.tcl('SceneSetFrameSource %d %d %s %s %d 1' % (scene_id, frame_id, source[0], source[1], not back))
def frame_set_active(self, scene_id, frame_id, active):
print(scene_id, frame_id, active)
print(next(self.call('tcl eval SceneSetFrameActive %d %d %d 0' % (scene_id, frame_id, active))))
if __name__ == "__main__":
c = SnowmixClient('127.0.0.1')
c = SnowmixClient('snowmix')
for l in c.call('feed info', 'STAT:'):
print('Result: %s' % (l,))
print(c.tcl('SceneAlpha 1'))
import pprint
pprint.pprint(c.image_list())

View File

@ -1,12 +1,11 @@
#!/bin/bash
set -euo pipefail
SNOWMIX_IP=snowmix
SNOWMIX_PORT=9999
mode=$1
if [ $# != 1 ] ; then
mode=you1
fi
mode=${1:-you1}
################### YouTube Settings ###################
# These data are available to you when you create a Live event in YouTube
@ -76,7 +75,7 @@ fi
case $mode in
you|you1|you2|youtube|youtube1|youtube2)
if [ $1 = you2 -o $1 = youtube2 ] ; then
if [ $mode = you2 -o $mode = youtube2 ] ; then
auth="$youtube_auth2"
else
auth="$youtube_auth1"
@ -133,7 +132,7 @@ audiosink=1
VIDEOSRC='shmsrc socket-path='$ctrsocket' do-timestamp=true is-live=true'
AUDIOSRC="fdsrc fd=0 do-timestamp=true"
( echo "audio sink ctr isaudio $audiosink" ; sleep 100000000 ) | \
( echo "audio sink ctr isaudio $audiosink" ) | \
/bin/nc $SNOWMIX_IP $SNOWMIX_PORT | \
(head -1
$gstlaunch -v \
@ -158,5 +157,6 @@ AUDIOSRC="fdsrc fd=0 do-timestamp=true"
fakesink \
encvid. ! rtph264pay config-interval=1 pt=96 ! udpsink host=janus port=8004 \
mirror. ! queue ! tcpserversink port=20001 host=0.0.0.0
exit 1
)
#rtmpsink location="$location" \