async startLiveStream() {
        this.data.livestream.active = true

        // Start a P2J pipeline and server and get the listening TCP port
        const p2jPort = await this.startP2J()
        
        // Start livestream with MJPEG output directed to P2J server with one frame every 2 seconds 
        debug('Establishing connection to video stream for camera '+this.deviceId)
        try {
            const sipSession = await this.device.streamVideo({
                output: [
                    '-y',
                    '-c:v',
                    'mjpeg',
                    '-pix_fmt',
                    'yuvj422p',
                    '-f',
                    'image2pipe',
                    '-s',
                    '640:360',
                    '-r',
                    '.5',
                    '-q:v',
                    '2',
                    'tcp://localhost:'+p2jPort
                  ]
            })

            // If stream starts, set expire time, may be extended by new events
            this.data.livestream.expires = Math.floor(Date.now()/1000) + this.data.livestream.duration

            sipSession.onCallEnded.subscribe(() => {
                debug('Video stream ended for camera '+this.deviceId)
                this.data.livestream.active = false
            })

            // Don't stop SIP session until current tyime > expire time
            // Expire time may be extedned by new motion events
            while (Math.floor(Date.now()/1000) < this.data.livestream.expires) {
                const sleeptime = (this.data.livestream.expires - Math.floor(Date.now()/1000)) + 1
                await utils.sleep(sleeptime)
            }

            // Stream time has expired, stop the current SIP session
            sipSession.stop()

        } catch(e) {
            debug(e)
            this.data.livestream.active = false
        }
    }
// Start a live stream and send mjpeg stream to p2j server
Start a live stream and send mjpeg stream to p2j server
Start a live stream and send mjpeg stream to p2j server
async startLiveStream() {
        this.data.livestream.active = true
        const p2jPort = await this.startP2J()
        debug('Establishing connection to video stream for camera '+this.deviceId)
        try {
            const sipSession = await this.device.streamVideo({
                output: [
                    '-y',
                    '-c:v',
                    'mjpeg',
                    '-pix_fmt',
                    'yuvj422p',
                    '-f',
                    'image2pipe',
                    '-s',
                    '640:360',
                    '-r',
                    '.5',
                    '-q:v',
                    '2',
                    'tcp://localhost:'+p2jPort
                  ]
            })
            this.data.livestream.expires = Math.floor(Date.now()/1000) + this.data.livestream.duration
            sipSession.onCallEnded.subscribe(() => {
                debug('Video stream ended for camera '+this.deviceId)
                this.data.livestream.active = false
            })
            while (Math.floor(Date.now()/1000) < this.data.livestream.expires) {
                const sleeptime = (this.data.livestream.expires - Math.floor(Date.now()/1000)) + 1
                await utils.sleep(sleeptime)
            }
            sipSession.stop()
        } catch(e) {
            debug(e)
            this.data.livestream.active = false
        }
    }
async startLiveStream ( ) { this . data . livestream . active = true const p2jPort = await this . startP2J ( ) debug ( 'Establishing connection to video stream for camera ' + this . deviceId ) try { const sipSession = await this . device . streamVideo ( { output : [ '-y' , '-c:v' , 'mjpeg' , '-pix_fmt' , 'yuvj422p' , '-f' , 'image2pipe' , '-s' , '640:360' , '-r' , '.5' , '-q:v' , '2' , 'tcp://localhost:' + p2jPort ] } ) this . data . livestream . expires = Math . floor ( Date . now ( ) / 1000 ) + this . data . livestream . duration sipSession . onCallEnded . subscribe ( ( ) => { debug ( 'Video stream ended for camera ' + this . deviceId ) this . data . livestream . active = false } ) while ( Math . floor ( Date . now ( ) / 1000 ) < this . data . livestream . expires ) { const sleeptime = ( this . data . livestream . expires - Math . floor ( Date . now ( ) / 1000 ) ) + 1 await utils . sleep ( sleeptime ) } sipSession . stop ( ) } catch ( e ) { debug ( e ) this . data . livestream . active = false } }
Start a live stream and send mjpeg stream to p2j server
Start a live stream and send mjpeg stream to p2j server
// Start a P2J pipeline and server and get the listening TCP port // Start livestream with MJPEG output directed to P2J server with one frame every 2 seconds  // If stream starts, set expire time, may be extended by new events // Don't stop SIP session until current tyime > expire time // Expire time may be extedned by new motion events // Stream time has expired, stop the current SIP session