From 795fd0cd386affe836b609efed1c034926eec976 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 31 Mar 2025 15:59:40 -0700 Subject: [PATCH] working with tv --- scripts.bash | 2 +- src/server.ts | 37 +++++++++++++++++++++++++++++++++---- static/index.html | 1 + 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/scripts.bash b/scripts.bash index 44c397c..76319a8 100644 --- a/scripts.bash +++ b/scripts.bash @@ -1,6 +1,6 @@ curl https://git.linuxtv.org/dtv-scan-tables.git/plain/atsc/us-ATSC-center-frequencies-8VSB -dvbv5-zap -c dvb_channel.conf -CUS -IZAP "ION" +dvbv5-zap -r -c dvb_channel.conf -CUS -IZAP "ION" dvbv5-scan -Cus -o dvb_channel.conf -O zap -v us-ATSC-center-frequencies-8VSB \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index dcff874..f3adad9 100644 --- a/src/server.ts +++ b/src/server.ts @@ -14,7 +14,8 @@ import { i420ToRgba, RTCVideoSource } from '@roamhq/wrtc/types/nonstandard'; // const {mediaDevices} = wrtc // Constants -const VIDEO_DEVICE = '/dev/video0'; // Video source device +// const VIDEO_DEVICE = '/dev/video0'; // Video source device +const VIDEO_DEVICE = '/dev/dvb/adapter0/dvr0'; // Video source device const WIDTH = 640; // Video width const HEIGHT = 480; // Video height const FRAME_SIZE = WIDTH * HEIGHT * 1.5; // YUV420p frame size (460800 bytes) @@ -40,15 +41,37 @@ class VideoStream extends Readable { // Function to start FFmpeg and capture raw video function startFFmpeg(): ChildProcessWithoutNullStreams { - return spawn('ffmpeg', [ - '-f', 'v4l2', // Use Video4Linux2 for video capture + const p = spawn('ffmpeg', [ + '-loglevel', 'debug', '-i', VIDEO_DEVICE, // Input device '-vf', `scale=${WIDTH}:${HEIGHT}`, // Scale video resolution '-vcodec', 'rawvideo', // Output raw video codec '-pix_fmt', 'yuv420p', // Pixel format for WebRTC '-f', 'rawvideo', // Output format 'pipe:1' // Pipe to stdout - ]); + ], { +// stdio: ['ignore', 'pipe', 'pipe'], +// detached: true + }); + process.on('SIGINT', () => { + console.log('🔻 Server shutting down... KILLING'); + let b = p.kill('SIGINT'); + // let b = process.kill(p.pid) + process.exit(0); + }); + + process.on('SIGTERM', () => { + console.log('🔻 SIGTERM received'); + p.kill('SIGTERM'); + process.exit(0); + }); + process.on('exit', () => { + p.kill('SIGHUP'); //this one + let b = p.kill('SIGTERM'); + console.log("b ",b) + }); + + return p; } // const videoSource = @@ -58,6 +81,8 @@ function startFFmpeg(): ChildProcessWithoutNullStreams { let frameBuffer = Buffer.alloc(0); const ffmpegProcess = startFFmpeg(); + + const videoSource = new nonstandard.RTCVideoSource(); // Function to create a WebRTC PeerConnection async function createPeerConnection(): Promise { @@ -99,10 +124,14 @@ async function createPeerConnection(): Promise { // console.error('FFmpeg Error:', data.toString()); }); + + ffmpegProcess.on('exit', (code) => { console.log(`FFmpeg exited with code ${code}`); }); + + // Add the track to the PeerConnection const track: MediaStreamTrack = videoSource.createTrack(); console.log('vdei src ',videoSource.isScreencast) diff --git a/static/index.html b/static/index.html index ee479f8..e39ec6a 100644 --- a/static/index.html +++ b/static/index.html @@ -42,6 +42,7 @@ ws.onopen = async () => { pc.addTransceiver('video', { direction: 'recvonly' }); + pc.addTransceiver('audio', { direction: 'recvonly' }) const offer = await pc.createOffer(); await pc.setLocalDescription(offer); // ws.send(JSON.stringify(offer));