add debug message on corrupt frames

This commit is contained in:
David Ventura
2024-05-03 15:57:23 +02:00
parent 204677ceae
commit d7d3b91528
+4 -7
View File
@@ -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) {
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) {