mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-09-26 21:01:12 +08:00
Remove useless tweaks
This commit is contained in:
@@ -34,7 +34,9 @@ export default class Camera extends RingPolledDevice {
|
||||
this.data = {
|
||||
motion: {
|
||||
active_ding: false,
|
||||
duration: savedState?.motion?.duration ? savedState.motion.duration : 30,
|
||||
duration: savedState?.motion?.duration
|
||||
? savedState.motion.duration
|
||||
: this.device.data.settings.video_settings.clip_length_max,
|
||||
publishedDuration: false,
|
||||
last_ding: 0,
|
||||
last_ding_expires: 0,
|
||||
@@ -48,8 +50,10 @@ export default class Camera extends RingPolledDevice {
|
||||
...this.device.isDoorbot ? {
|
||||
ding: {
|
||||
active_ding: false,
|
||||
duration: savedState?.ding?.duration ? savedState.ding.duration : 30,
|
||||
publishedDurations: false,
|
||||
duration: savedState?.ding?.duration
|
||||
? savedState.ding.duration
|
||||
: this.device.data.settings.video_settings.clip_length_max,
|
||||
publishedDuration: false,
|
||||
last_ding: 0,
|
||||
last_ding_expires: 0,
|
||||
last_ding_time: 'none',
|
||||
|
@@ -51,7 +51,7 @@ export class WeriftPeerConnection extends Subscribed {
|
||||
{ type: 'nack', parameter: 'pli' },
|
||||
{ type: 'goog-remb' },
|
||||
],
|
||||
parameters: 'packetization-mode=1;profile-level-id=42001f;level-asymmetry-allowed=1',
|
||||
parameters: 'packetization-mode=1;profile-level-id=64002a;level-asymmetry-allowed=1',
|
||||
}),
|
||||
new RTCRtpCodecParameters({
|
||||
mimeType: "video/rtx",
|
||||
|
@@ -114,12 +114,8 @@ export class StreamingSession extends Subscribed {
|
||||
|
||||
this.onCallEnded.pipe(take(1)).subscribe(() => ff.stop())
|
||||
|
||||
console.log(inputSdp)
|
||||
ff.writeStdin(inputSdp)
|
||||
|
||||
// Request a key frame now that ffmpeg is ready to receive
|
||||
this.requestKeyFrame()
|
||||
|
||||
return {
|
||||
port: altVideoPort,
|
||||
sdp: altVideoSdp
|
||||
|
@@ -3,11 +3,11 @@ import { WebrtcConnection } from './lib/webrtc-connection.js'
|
||||
import { StreamingSession } from './lib/streaming-session.js'
|
||||
|
||||
class LiveStreamWorker {
|
||||
constructor(deviceName, doorbotId) {
|
||||
this.deviceName = deviceName
|
||||
this.doorbotId = doorbotId
|
||||
constructor(workerData) {
|
||||
this.deviceName = workerData.deviceName
|
||||
this.deviceId = workerData.deviceId
|
||||
this.doorbotId = workerData.doorbotId
|
||||
this.liveStream = null
|
||||
this.altVideoData = null
|
||||
this.stopping = false
|
||||
|
||||
this.processMessages()
|
||||
@@ -69,8 +69,8 @@ class LiveStreamWorker {
|
||||
const streamConnection = new WebrtcConnection(streamData.ticket, cameraData)
|
||||
this.liveStream = new StreamingSession(cameraData, streamConnection)
|
||||
|
||||
this.handleCallState()
|
||||
this.handleCallEnded()
|
||||
this.subscribeCallState()
|
||||
this.subscribeCallEnded()
|
||||
await this.startTranscoding(streamData.rtspPublishUrl)
|
||||
} catch (error) {
|
||||
this.logError(error)
|
||||
@@ -79,7 +79,7 @@ class LiveStreamWorker {
|
||||
}
|
||||
}
|
||||
|
||||
handleCallState() {
|
||||
subscribeCallState() {
|
||||
this.liveStream.connection.pc.onConnectionState.subscribe(async (state) => {
|
||||
switch(state) {
|
||||
case 'connected':
|
||||
@@ -97,7 +97,7 @@ class LiveStreamWorker {
|
||||
})
|
||||
}
|
||||
|
||||
handleCallEnded() {
|
||||
subscribeCallEnded() {
|
||||
this.liveStream.onCallEnded.subscribe(() => {
|
||||
this.logInfo('Live stream WebRTC session has disconnected')
|
||||
this.updateState('inactive')
|
||||
@@ -112,26 +112,26 @@ class LiveStreamWorker {
|
||||
input: [
|
||||
'-probesize', '32K',
|
||||
'-analyzeduration', '0',
|
||||
'-buffer_size', '1048576'
|
||||
],
|
||||
audio: [
|
||||
'-map', '0:a',
|
||||
'-c:a:0', 'aac',
|
||||
'-c:a:0', 'aac',
|
||||
'-map', '0:a',
|
||||
'-c:a:1', 'copy'
|
||||
'-c:a:0', 'copy'
|
||||
],
|
||||
video: [
|
||||
'-map', '0:v',
|
||||
'-c:v', 'copy'
|
||||
],
|
||||
output: [
|
||||
'-ss', '0.2',
|
||||
'-flags', '+global_header',
|
||||
'-f', 'rtsp',
|
||||
'-rtsp_transport', 'tcp',
|
||||
rtspPublishUrl
|
||||
]}
|
||||
|
||||
this.altVideoData = await this.liveStream.startTranscoding(transcodingConfig)
|
||||
await this.liveStream.startTranscoding(transcodingConfig)
|
||||
this.logInfo('Live stream transcoding process has started')
|
||||
}
|
||||
|
||||
@@ -170,10 +170,10 @@ class LiveStreamWorker {
|
||||
}
|
||||
|
||||
updateState(state) {
|
||||
parentPort.postMessage({ type: 'state', data: state, altVideoData: this.altVideoData })
|
||||
parentPort.postMessage({ type: 'state', data: state })
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the worker
|
||||
const worker = new LiveStreamWorker(workerData.deviceName, workerData.doorbotId)
|
||||
const worker = new LiveStreamWorker(workerData)
|
||||
export default worker
|
@@ -48,13 +48,13 @@ export class LiveStream {
|
||||
}
|
||||
|
||||
clearSession(status) {
|
||||
this.status = status
|
||||
this.session = false
|
||||
this.altVideoData = false
|
||||
this.session = false
|
||||
this.status = status
|
||||
this.unbindAltVideoPorts()
|
||||
}
|
||||
|
||||
bindAltVideoPorts() {
|
||||
console.log(this.altVideoData.sdp)
|
||||
if (this.altVideoData) {
|
||||
this.rtpSocket = dgram.createSocket('udp4')
|
||||
this.rtcpSocket = dgram.createSocket('udp4')
|
||||
@@ -108,7 +108,6 @@ export class LiveStream {
|
||||
}
|
||||
|
||||
async stop() {
|
||||
this.unbindAltVideoPorts()
|
||||
if (this.session) {
|
||||
this.worker.postMessage({ command: 'stop' })
|
||||
}
|
||||
|
@@ -48,10 +48,13 @@ export class SnapshotStream {
|
||||
'-f', 'mpegts',
|
||||
'-probesize', '32k',
|
||||
'-analyzeduration', '0',
|
||||
'-fflags', '+discardcorrupt+genpts',
|
||||
'-r', '5',
|
||||
'-ss', '0.2',
|
||||
'-i', 'pipe:',
|
||||
'-ss', '.2',
|
||||
'-c:v', 'copy',
|
||||
'-avioflags', 'direct',
|
||||
'-flags', '+global_header',
|
||||
'-f', 'rtsp',
|
||||
'-rtsp_transport', 'tcp',
|
||||
rtspPublishUrl
|
||||
@@ -71,11 +74,12 @@ export class SnapshotStream {
|
||||
'-f', 'image2pipe',
|
||||
'-probesize', '32k',
|
||||
'-analyzeduration', '0',
|
||||
'-r', '20',
|
||||
'-i', 'pipe:',
|
||||
'-vf', 'scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2',
|
||||
'-sws_flags', 'lanczos',
|
||||
'-c:v', 'libx264',
|
||||
'-b:v', '6M',
|
||||
'-b:v', '3M',
|
||||
'-r', '5',
|
||||
'-g', '1',
|
||||
'-preset', 'ultrafast',
|
||||
@@ -130,18 +134,17 @@ export class SnapshotStream {
|
||||
this.livesnaps.session = spawn(pathToFfmpeg, [
|
||||
'-hide_banner',
|
||||
'-protocol_whitelist', 'pipe,udp,rtp,fd,file,crypto',
|
||||
'-fflags', 'nobuffer',
|
||||
'-flags', 'low_delay',
|
||||
'-use_wallclock_as_timestamps', '1',
|
||||
'-itsoffset', '-0.2',
|
||||
'-probesize', '32K',
|
||||
'-analyzeduration', '0',
|
||||
'-fflags', '+genpts',
|
||||
'-r', '20',
|
||||
'-f', 'sdp',
|
||||
'-i', 'pipe:',
|
||||
'-vf', 'scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2',
|
||||
'-sws_flags', 'lanczos',
|
||||
'-c:v', 'libx264',
|
||||
'-b:v', '6M',
|
||||
'-b:v', '3M',
|
||||
'-preset', 'ultrafast',
|
||||
'-tune', 'zerolatency',
|
||||
'-r', '5',
|
||||
@@ -163,6 +166,7 @@ export class SnapshotStream {
|
||||
})
|
||||
|
||||
this.livesnaps.session.on('close', async () => {
|
||||
liveStream.bindAltVideoPorts()
|
||||
this.mqttCamera.debug('The live snapshot stream has stopped')
|
||||
this.mqttCamera.updateSnapshot('interval')
|
||||
this.livesnaps.session.stdout.unpipe(this.rtsp.session.stdin)
|
||||
@@ -171,20 +175,20 @@ export class SnapshotStream {
|
||||
})
|
||||
|
||||
// The livesnap stream will stop after the specified duration
|
||||
this.livesnaps.timeout = Date.now() + 5000 + (duration * 1000)
|
||||
while (this.livesnaps.active && (Date.now() < this.livesnaps.timeout)) {
|
||||
const livesnapsTimeout = Date.now() + 5000 + (duration * 1000)
|
||||
while (this.livesnaps.active && (Date.now() < livesnapsTimeout)) {
|
||||
await utils.sleep(1)
|
||||
}
|
||||
} else {
|
||||
this.mqttCamera.debug('The live snapshot stream failed starting the live stream')
|
||||
}
|
||||
|
||||
if (this.livesnaps.session) {
|
||||
this.livesnaps.session.kill()
|
||||
if (this.livesnaps.active && this.livesnaps.session) {
|
||||
this.livesnaps.session?.kill()
|
||||
}
|
||||
|
||||
if (this.keepalive.session) {
|
||||
this.keepalive.session.kill()
|
||||
if (this.keepalive.active && this.keepalive.session) {
|
||||
this.keepalive.session?.kill()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -198,7 +202,7 @@ export class SnapshotStream {
|
||||
this.interval = setInterval(async () => {
|
||||
if (this.status === 'active') {
|
||||
try {
|
||||
this.snapshot.session.stdin.write(this.mqttCamera.data.snapshot.image)
|
||||
this.snapshot.session?.stdin?.write(this.mqttCamera.data.snapshot.image)
|
||||
} catch {
|
||||
this.mqttCamera.debug('Writing image to snapshot stream failed')
|
||||
this.stop()
|
||||
|
Reference in New Issue
Block a user