rtsp: unrevert commits

This commit is contained in:
bordun 2018-03-26 23:50:02 +02:00
parent 57f1f916fa
commit f57e74ca4c
4 changed files with 56 additions and 1 deletions

View file

@ -59,7 +59,37 @@ var bindCallbacks = function(callbacks) {
}
// video streams
var rtsp = require('rtsp-ffmpeg'),
urls = settings.read('videoStreams'),
streams = {},
framerate = 10,
resolution = undefined
for (var i in urls) {
if (/framerate\s*=\s*[0-9]+/.test(urls[i])) {
framerate = Math.max(Math.min(parseInt(urls[i].split('=').pop()), 60), 0)
}
if (/resolution\s*=\s*[0-9]+x[0-9]+/.test(urls[i])) {
resolution = urls[i].split('=').pop().trim()
}
}
urls = urls.filter(item => item.indexOf('rtsp://') > -1)
for (let i = 0; i < urls.length; i++) {
streams[i] = new rtsp.FFMpeg({
input: urls[i],
rate: framerate,
resolution: resolution,
})
streams[i].on('data', (data)=>{
ipc.send('video', [i, data.toString('base64')])
})
}
///
console.log('App available at ' + appAddresses.join(' & '))

View file

@ -56,6 +56,7 @@ var options = {
true : 'examples can\'t be listed if --load is set'
}
},
'video-streams':{type:'array',describe:'video stream urls (rtsp://)'},
'url-options':{type:'array',describe:'url options (opt=value pairs)',
check: (u, argv)=>{
return (!u || !argv.n) ?
@ -120,6 +121,7 @@ var makeDefaultConfig = function(argv){
sessionFile: argv.l || false,
newSession: argv.b || false,
customModule: argv.c || false,
videoStreams: argv['video-streams'] || [],
fullScreen: argv['fullscreen'] || false,
noGui: argv.n || false,
guiOnly: typeof argv.g == 'string' ? argv.g.length ? argv.g : true : false,

View file

@ -27,6 +27,7 @@
"express": "4.16.3",
"osc": "2.2.0",
"python-shell": "0.5.0",
"rtsp-ffmpeg": "0.0.12",
"vmodule": "1.0.1",
"ws": "^5.0.0",
"yargs": "11.0.0"

View file

@ -1,5 +1,6 @@
var {mapToScale} = require('../utils'),
Widget = require('../common/widget')
Widget = require('../common/widget'),
ipc = require('../../ipc')
module.exports = class Led extends Widget {
@ -30,6 +31,7 @@ module.exports = class Led extends Widget {
repeat: 'no-repeat',
border: true,
cache: true,
stream: '',
_value: 'value',
default: '',
@ -58,6 +60,10 @@ module.exports = class Led extends Widget {
this.widget.style.setProperty('background-position', this.getProp('position'))
this.widget.style.setProperty('background-repeat', this.getProp('repeat'))
if (this.getProp('stream') !== '') {
this.bindedOnStreamUpdate = this.onStreamUpdate.bind(this)
ipc.on('video', this.bindedOnStreamUpdate)
}
}
@ -89,4 +95,20 @@ module.exports = class Led extends Widget {
}
onStreamUpdate(event) {
console.log(event)
var [stream, data] = event
if (stream === this.getProp('stream')) {
this.setValue('data:image/jpeg;base64,' + data)
}
}
onRemove() {
if (this.bindedOnStreamUpdate) ipc.off('video', this.bindedOnStreamUpdate)
super.onRemove()
}
}