-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathSMPTE336MKLVTransport.ts
More file actions
52 lines (43 loc) · 1.45 KB
/
SMPTE336MKLVTransport.ts
File metadata and controls
52 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// De-packetize RC 6597 RTP packets to re-create SMPTE336M KLV Metadata including STANAG 4609
// Write data to a file as raw binary data.
// The RTP timestamp is not saved to the file.
// By Roger Hardiman, January 2026
import RTSPClient from "../RTSPClient";
import { RTPPacket } from "../util";
import * as transform from "sdp-transform";
import { Writable } from "stream";
interface Details {
codec: string;
mediaSource: transform.MediaDescription;
rtpChannel: number;
rtcpChannel: number;
}
export default class SMPTE336MKLVTransport {
client: RTSPClient;
stream: Writable;
rawData: Buffer[];
constructor(client: RTSPClient, stream: Writable, details: Details) {
this.client = client;
this.stream = stream;
this.rawData = [];
client.on("data", (channel, data, packet) => {
if (channel == details.rtpChannel) {
this.processRTPPacket(packet);
}
});
}
processRTPPacket(packet: RTPPacket): void {
// RTP Payload for ONVIF Metadata
// Accumulate payload
this.rawData.push(packet.payload)
if (packet.marker == 1) { // TODO... OR if the Timestamp has changed
// end of data. Write the file
// In this case we can just write each Buffer from the rawData array
// If we were passing the KLV to a caller, we would concatenate the Buffers in the rawData array first
for(const buffer of this.rawData) {
this.stream.write(buffer);
}
this.rawData = [];
}
}
}