Skip to content

Commit

Permalink
feat: add missing videomodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jul 30, 2020
1 parent 2fb917b commit 543ef69
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 62 deletions.
10 changes: 6 additions & 4 deletions src/atem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,21 +528,23 @@ export class Atem extends BasicAtem {

public uploadStill(index: number, data: Buffer, name: string, description: string): Promise<DataTransfer> {
if (!this.state) return Promise.reject()
const resolution = Util.getResolution(this.state.settings.videoMode)
const resolution = Util.getVideoModeInfo(this.state.settings.videoMode)
if (!resolution) return Promise.reject()
return this.dataTransferManager.uploadStill(
index,
Util.convertRGBAToYUV422(resolution[0], resolution[1], data),
Util.convertRGBAToYUV422(resolution.width, resolution.height, data),
name,
description
)
}

public uploadClip(index: number, frames: Array<Buffer>, name: string): Promise<DataTransfer> {
if (!this.state) return Promise.reject()
const resolution = Util.getResolution(this.state.settings.videoMode)
const resolution = Util.getVideoModeInfo(this.state.settings.videoMode)
if (!resolution) return Promise.reject()
const data: Array<Buffer> = []
for (const frame of frames) {
data.push(Util.convertRGBAToYUV422(resolution[0], resolution[1], frame))
data.push(Util.convertRGBAToYUV422(resolution.width, resolution.height, frame))
}
return this.dataTransferManager.uploadClip(index, data, name)
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ const commandConverters: CommandTestConverterSet = {
propertyAliases: {
keyerIndex: (val: any): PropertyAliasResult => ({ val, name: 'upstreamKeyerId' }),
mode: (val: any): PropertyAliasResult => ({ val, name: 'mixEffectKeyType' }),
maskSettings: (v: UpstreamKeyerMaskSettings) => ({
maskSettings: (v: UpstreamKeyerMaskSettings): PropertyAliasResult => ({
val: {
maskLeft: Math.round(v.maskLeft * 1000),
maskRight: Math.round(v.maskRight * 1000),
Expand Down
1 change: 1 addition & 0 deletions src/commands/__tests__/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { CommandParser } from '../../lib/atemCommandParser'
import { ProtocolVersion } from '../../enums'
import { IDeserializedCommand, ISerializableCommand, SymmetricalCommand } from '../CommandBase'
Expand Down
56 changes: 33 additions & 23 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,39 @@ export enum TransferMode {
}

export enum VideoMode {
N525i5994NTSC,
P625i50PAL,
N525i5994169,
P625i50169,

P720p50,
N720p5994,
P1080i50,
N1080i5994,
N1080p2398,
N1080p24,
P1080p25,
N1080p2997,
P1080p50,
N1080p5994,

N4KHDp2398,
N4KHDp24,
P4KHDp25,
N4KHDp2997,

P4KHDp5000,
N4KHDp5994
N525i5994NTSC = 0,
P625i50PAL = 1,
N525i5994169 = 2,
P625i50169 = 3,

P720p50 = 4,
N720p5994 = 5,
P1080i50 = 6,
N1080i5994 = 7,
N1080p2398 = 8,
N1080p24 = 9,
P1080p25 = 10,
N1080p2997 = 11,
P1080p50 = 12,
N1080p5994 = 13,

N4KHDp2398 = 14,
N4KHDp24 = 15,
P4KHDp25 = 16,
N4KHDp2997 = 17,

P4KHDp5000 = 18,
N4KHDp5994 = 19,

N8KHDp2398 = 20,
N8KHDp24 = 21,
P8KHDp25 = 22,
N8KHDp2997 = 23,
P8KHDp50 = 24,
N8KHDp5994 = 25,

N1080p30 = 26,
N1080p60 = 27
}

export enum TransferState {
Expand Down
140 changes: 106 additions & 34 deletions src/lib/atemUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Enums } from '..'
import * as Enums from '../enums'
import WaveFile = require('wavefile')

export function bufToBase64String(buffer: Buffer, start: number, length: number): string {
Expand Down Expand Up @@ -91,39 +91,111 @@ export function convertRGBAToYUV422(width: number, height: number, data: Buffer)
return buffer
}

export type Resolution = [number, number]
export function getResolution(videoMode: Enums.VideoMode): Resolution {
const PAL: Resolution = [720, 576]
const NTSC: Resolution = [640, 480]
const HD: Resolution = [1280, 720]
const FHD: Resolution = [1920, 1080]
const UHD: Resolution = [3840, 2160]
// TODO - add 8k options

const enumToResolution = [
NTSC,
PAL,
NTSC,
PAL,
HD,
HD,
FHD,
FHD,
FHD,
FHD,
FHD,
FHD,
FHD,
FHD,
UHD,
UHD,
UHD,
UHD,
UHD,
UHD
]

return enumToResolution[videoMode]
export interface VideoModeInfo {
width: number
height: number
}

const dimsPAL: Pick<VideoModeInfo, 'width' | 'height'> = { width: 720, height: 576 }
const dimsNTSC: Pick<VideoModeInfo, 'width' | 'height'> = { width: 640, height: 480 }
const dims720p: Pick<VideoModeInfo, 'width' | 'height'> = { width: 1280, height: 720 }
const dims1080p: Pick<VideoModeInfo, 'width' | 'height'> = { width: 1920, height: 1080 }
const dims4k: Pick<VideoModeInfo, 'width' | 'height'> = { width: 3840, height: 2160 }
const dims8k: Pick<VideoModeInfo, 'width' | 'height'> = { width: 7680, height: 4260 }
const VideoModeInfoImpl: { [key in Enums.VideoMode]: VideoModeInfo } = {
[Enums.VideoMode.N525i5994NTSC]: {
...dimsNTSC
},
[Enums.VideoMode.P625i50PAL]: {
...dimsPAL
},
[Enums.VideoMode.N525i5994169]: {
...dimsNTSC
},
[Enums.VideoMode.P625i50169]: {
...dimsPAL
},

[Enums.VideoMode.P720p50]: {
...dims720p
},
[Enums.VideoMode.N720p5994]: {
...dims720p
},
[Enums.VideoMode.P1080i50]: {
...dims1080p
},
[Enums.VideoMode.N1080i5994]: {
...dims1080p
},
[Enums.VideoMode.N1080p2398]: {
...dims1080p
},
[Enums.VideoMode.N1080p24]: {
...dims1080p
},
[Enums.VideoMode.P1080p25]: {
...dims1080p
},
[Enums.VideoMode.N1080p2997]: {
...dims1080p
},
[Enums.VideoMode.P1080p50]: {
...dims1080p
},
[Enums.VideoMode.N1080p5994]: {
...dims1080p
},

[Enums.VideoMode.N4KHDp2398]: {
...dims4k
},
[Enums.VideoMode.N4KHDp24]: {
...dims4k
},
[Enums.VideoMode.P4KHDp25]: {
...dims4k
},
[Enums.VideoMode.N4KHDp2997]: {
...dims4k
},

[Enums.VideoMode.P4KHDp5000]: {
...dims4k
},
[Enums.VideoMode.N4KHDp5994]: {
...dims4k
},

[Enums.VideoMode.N8KHDp2398]: {
...dims8k
},
[Enums.VideoMode.N8KHDp24]: {
...dims8k
},
[Enums.VideoMode.P8KHDp25]: {
...dims8k
},
[Enums.VideoMode.N8KHDp2997]: {
...dims8k
},
[Enums.VideoMode.P8KHDp50]: {
...dims8k
},
[Enums.VideoMode.N8KHDp5994]: {
...dims8k
},

[Enums.VideoMode.N1080p30]: {
...dims1080p
},
[Enums.VideoMode.N1080p60]: {
...dims1080p
}
}

export function getVideoModeInfo(videoMode: Enums.VideoMode): VideoModeInfo | undefined {
return VideoModeInfoImpl[videoMode]
}

export function convertWAVToRaw(inputBuffer: Buffer): Buffer {
Expand Down

0 comments on commit 543ef69

Please sign in to comment.