rtp marker tweaks on webrtc talkback (#1187)

* set rtp marker

* set marker if last packet was recevied 1s+ ago

* fix after merge

* reorder

* set marker if last packet was recevied 1s+ ago
This commit is contained in:
Brett Jia
2023-11-18 17:32:32 -05:00
committed by GitHub
parent 7460c714c1
commit eaeae02080
2 changed files with 9 additions and 3 deletions

View File

@@ -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;

View File

@@ -274,15 +274,18 @@ export async function createRTCPeerConnectionSource(options: {
const ffmpegInput = await mediaManager.convertMediaObjectToJSON<FFmpegInput>(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;
},
},
});