Skip to content

Commit

Permalink
wip: downloadStill
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 15, 2024
1 parent 362c807 commit 4b86708
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/atem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { InputChannel } from './state/input'
import { DownstreamKeyerGeneral, DownstreamKeyerMask } from './state/video/downstreamKeyers'
import * as DT from './dataTransfer'
import * as Util from './lib/atemUtil'
import { getVideoModeInfo } from './lib/videoMode'
import { VideoModeInfo, getVideoModeInfo } from './lib/videoMode'
import * as Enums from './enums'
import {
ClassicAudioMonitorChannel,
Expand Down Expand Up @@ -56,6 +56,8 @@ import { TimeInfo } from './state/info'
import { SomeAtemAudioLevels } from './state/levels'
import { generateUploadBufferInfo, UploadBufferInfo } from './dataTransfer/dataTransferUploadBuffer'
import { convertWAVToRaw } from './lib/converters/wavAudio'
import { decodeRLE } from './lib/converters/rle'
import { convertYUV422ToRGBA } from './lib/converters/yuv422ToRgba'

export interface AtemOptions {
address?: string
Expand Down Expand Up @@ -147,6 +149,12 @@ export class BasicAtem extends EventEmitter<AtemEvents> {
return this._state
}

get videoMode(): Readonly<VideoModeInfo> | undefined {
if (!this.state) return undefined

return getVideoModeInfo(this.state.settings.videoMode)
}

public async connect(address: string, port?: number): Promise<void> {
return this.socket.connect(address, port)
}
Expand Down Expand Up @@ -758,18 +766,24 @@ export class Atem extends BasicAtem {
}

public async downloadStill(index: number, format: 'raw' | 'rgba' | 'yuv' = 'rgba'): Promise<Buffer> {
const rawBuffer = this.dataTransferManager.downloadStill(index)
let rawBuffer = await this.dataTransferManager.downloadStill(index)

if (format === 'raw') {
return rawBuffer
}

if (!this.state) throw new Error('Unable to check current resolution')
const resolution = getVideoModeInfo(this.state.settings.videoMode)
if (!resolution) throw new Error('Failed to determine required resolution')

rawBuffer = decodeRLE(rawBuffer, resolution.width * resolution.height * 4)

switch (format) {
case 'raw':
return rawBuffer
case 'yuv':
// TODO - decode rle
return rawBuffer
case 'rgba':
default:
// TODO - decode rle and convert to rgba
return rawBuffer
return convertYUV422ToRGBA(resolution.width, resolution.height, rawBuffer)
}
}

Expand Down

0 comments on commit 4b86708

Please sign in to comment.