From d7d3b9152816584534176be7d1a8e639e17bb9b1 Mon Sep 17 00:00:00 2001 From: David Ventura Date: Fri, 3 May 2024 15:57:23 +0200 Subject: [PATCH] add debug message on corrupt frames --- handlers.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/handlers.ts b/handlers.ts index a116a9a..98cd34a 100644 --- a/handlers.ts +++ b/handlers.ts @@ -158,18 +158,12 @@ const deal_with_data = (session: Session, dv: DataView) => { const stream_type = dv.add(12).readU8(); if (stream_type == STREAM_TYPE_AUDIO) { const audio_len = u16_swap(dv.add(8 + 16).readU16()); - // may have received the next 'data' packet id as an audio frame -- jpeg was fine - if (pkt_id == session.rcvSeqId + 1) { - session.rcvSeqId = session.rcvSeqId + 1; - } const audio_buf = dv.add(32 + 8).readByteArray(audio_len).buffer; // 8 for pkt header, 32 for `stream_head_t` session.eventEmitter.emit("audio", { gap: false, data: Buffer.from(audio_buf) }); } else if (stream_type == STREAM_TYPE_JPEG) { const to_read = pkt_len - 4 - 32; if (to_read > 0) { - // some cameras do not send the data with the frame, but rather - // as a followup message - logger.debug(`Reading ${to_read} bytes - should be 992?`); + // some cameras do not send the data with the frame, but rather as a followup message // skip 8 bytes (drw header) + 32 bytes (data frame) const data = dv.add(32 + 8).readByteArray(to_read); startNewFrame(data.buffer); @@ -200,7 +194,10 @@ const deal_with_data = (session: Session, dv: DataView) => { let b = Buffer.from(data.buffer); if (pkt_id > session.rcvSeqId + 1) { - session.frame_is_bad = true; + if (!session.frame_is_bad) { + session.frame_is_bad = true; + logger.debug(`Dropping corrupt frame ${pkt_id}, expected ${session.rcvSeqId + 1}`); + } // this should always be enabled but currently it seems to cause more visual distortion // than just missing some frames if (!session.options.attempt_to_fix_packet_loss) {