Skip to content

Commit

Permalink
fix: adjust numbers based on real atem
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 1, 2023
1 parent 3384972 commit edd4571
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/atem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { Atem, DEFAULT_MTU, DEFAULT_PORT } from '../atem'
import { Atem, DEFAULT_MAX_PACKET_SIZE, DEFAULT_PORT } from '../atem'
import { CutCommand } from '../commands'
import { promisify } from 'util'
import { EventEmitter } from 'events'
Expand Down Expand Up @@ -35,14 +35,14 @@ describe('Atem', () => {
disableMultithreaded: true,
log: (conn as any)._log,
port: DEFAULT_PORT,
packetMtu: DEFAULT_MTU,
maxPacketSize: DEFAULT_MAX_PACKET_SIZE,
})
} finally {
await conn.destroy()
}
})
test('constructor test 2', async () => {
const conn = new Atem({ debugBuffers: true, address: 'test1', port: 23, packetMtu: 500 })
const conn = new Atem({ debugBuffers: true, address: 'test1', port: 23, maxPacketSize: 500 })

try {
const socket = (conn as any).socket as AtemSocket
Expand All @@ -56,7 +56,7 @@ describe('Atem', () => {
disableMultithreaded: false,
log: (conn as any)._log,
port: 23,
packetMtu: 500,
maxPacketSize: 500,
})
} finally {
await conn.destroy()
Expand Down
6 changes: 3 additions & 3 deletions src/atem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface AtemOptions {
/**
* Maximum size of packets to transmit
*/
packetMtu?: number
maxPacketSize?: number
}

export type AtemEvents = {
Expand All @@ -89,7 +89,7 @@ export enum AtemConnectionStatus {
}

export const DEFAULT_PORT = 9910
export const DEFAULT_MTU = 1500
export const DEFAULT_MAX_PACKET_SIZE = 1416 // Matching ATEM software

export class BasicAtem extends EventEmitter<AtemEvents> {
private readonly socket: AtemSocket
Expand All @@ -109,7 +109,7 @@ export class BasicAtem extends EventEmitter<AtemEvents> {
port: options?.port || DEFAULT_PORT,
disableMultithreaded: options?.disableMultithreaded ?? false,
childProcessTimeout: options?.childProcessTimeout || 600,
packetMtu: options?.packetMtu ?? DEFAULT_MTU,
maxPacketSize: options?.maxPacketSize ?? DEFAULT_MAX_PACKET_SIZE,
})
this.dataTransferManager = new DT.DataTransferManager(this.sendCommands.bind(this))

Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/atemSocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('AtemSocket', () => {
port: 890,
disableMultithreaded: true,
childProcessTimeout: 100,
packetMtu: 1500,
maxPacketSize: 1416,
})
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/atemSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface AtemSocketOptions {
debugBuffers: boolean
disableMultithreaded: boolean
childProcessTimeout: number
packetMtu: number
maxPacketSize: number
}

export type AtemSocketEvents = {
Expand All @@ -29,7 +29,7 @@ export class AtemSocket extends EventEmitter<AtemSocketEvents> {
private readonly _debugBuffers: boolean
private readonly _disableMultithreaded: boolean
private readonly _childProcessTimeout: number
private readonly _packetMtu: number
private readonly _maxPacketSize: number
private readonly _commandParser: CommandParser = new CommandParser()

private _nextPacketTrackingId = 0
Expand All @@ -47,7 +47,7 @@ export class AtemSocket extends EventEmitter<AtemSocketEvents> {
this._debugBuffers = options.debugBuffers
this._disableMultithreaded = options.disableMultithreaded
this._childProcessTimeout = options.childProcessTimeout
this._packetMtu = options.packetMtu
this._maxPacketSize = options.maxPacketSize
}

public async connect(address?: string, port?: number): Promise<void> {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AtemSocket extends EventEmitter<AtemSocketEvents> {
public async sendCommands(commands: Array<ISerializableCommand>): Promise<number[]> {
if (!this._socketProcess) throw new Error('Socket process is not open')

const maxPacketSize = this._packetMtu - 28 - 12 // MTU minus UDP header and ATEM header
const maxPacketSize = this._maxPacketSize - 12 // MTU minus ATEM header
const packetBuilder = new PacketBuilder(maxPacketSize, this._commandParser.version)

for (const cmd of commands) {
Expand Down

0 comments on commit edd4571

Please sign in to comment.