diff --git a/plugins/webrtc/src/ffmpeg-to-wrtc.ts b/plugins/webrtc/src/ffmpeg-to-wrtc.ts index 392f8baa22..b5bb29bdbd 100644 --- a/plugins/webrtc/src/ffmpeg-to-wrtc.ts +++ b/plugins/webrtc/src/ffmpeg-to-wrtc.ts @@ -217,6 +217,7 @@ export async function createTrackForwarder(options: { } let opusRepacketizer: OpusRepacketizer; + let lastPacketTs: number = 0; const audioRtpTrack: RtpTrack = { codecCopy: audioCodecCopy, onRtp: buffer => { @@ -230,11 +231,13 @@ export async function createTrackForwarder(options: { } else { const rtp = RtpPacket.deSerialize(buffer); - rtp.header.marker = false; + const now = Date.now(); + rtp.header.marker = now - lastPacketTs > 1000; // set the marker if it's been more than 1s since the last packet rtp.header.payloadType = audioTransceiver.sender.codec.payloadType; // pcm audio can be concatenated. // hikvision seems to send 40ms duration packets, so 25 packets per second. audioTransceiver.sender.sendRtp(rtp.serialize()); + lastPacketTs = now; } }, encoderArguments: [ @@ -257,7 +260,7 @@ export async function createTrackForwarder(options: { // 1/9/2023: // 1378 is what homekit requests, regardless of local or remote network. // so setting 1378 as the fixed value seems wise, given apple probably has - // better knowledge of network capabilities, and also mirrors + // better knowledge of network capabilities, and also mirrors // from my cursory research into ipv6, the MTU is no lesser than ipv4, in fact // the min mtu is larger. const videoPacketSize = 1378; diff --git a/plugins/webrtc/src/wrtc-to-rtsp.ts b/plugins/webrtc/src/wrtc-to-rtsp.ts index 6df4bf185c..8652fe5da5 100644 --- a/plugins/webrtc/src/wrtc-to-rtsp.ts +++ b/plugins/webrtc/src/wrtc-to-rtsp.ts @@ -274,15 +274,18 @@ export async function createRTCPeerConnectionSource(options: { const ffmpegInput = await mediaManager.convertMediaObjectToJSON(media, ScryptedMimeTypes.FFmpegInput); + let lastPacketTs: number = 0; const { kill: destroy } = await startRtpForwarderProcess(console, ffmpegInput, { audio: { codecCopy: audioCodec.name, encoderArguments: getFFmpegRtpAudioOutputArguments(ffmpegInput.mediaStreamOptions?.audio?.codec, audioTransceiver.sender.codec, maximumCompatibilityMode), onRtp: (rtp) => { const packet = RtpPacket.deSerialize(rtp); + const now = Date.now(); packet.header.payloadType = audioCodec.payloadType; - packet.header.marker = false; + packet.header.marker = now - lastPacketTs > 1000; // set the marker if it's been more than 1s since the last packet audioTransceiver.sender.sendRtp(packet.serialize()); + lastPacketTs = now; }, }, });