Skip to content

Commit

Permalink
feat(Media): Media Pool Description Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Balte de Wit authored and Alex Van Camp committed Sep 11, 2018
1 parent e3e69a1 commit fbae9b1
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 3 deletions.
55 changes: 55 additions & 0 deletions src/commands/Media/MediaPlayerSourceCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { AtemState } from '../../state'
import { MediaPlayerSource } from '../../state/media'
import AbstractCommand from '../AbstractCommand'
import { Enums } from '../..'

export class MediaPlayerSourceCommand extends AbstractCommand {
rawName = 'MPCE'
mediaPlayerId: number

properties: MediaPlayerSource
newProperties: {
sourceType: Enums.MediaSourceType,
stillIndex: number,
clipIndex: number
}
MaskFlags = {
sourceType: 1 << 0,
stillIndex: 1 << 1,
clipIndex: 1 << 2
}

updateProps (newProps: Partial<{ sourceType: Enums.MediaSourceType, stillIndex: number, clipIndex: number }>) {
this._updateProps(newProps)
}

deserialize (rawCommand: Buffer) {
this.mediaPlayerId = rawCommand[0]
this.properties = {
sourceType: rawCommand[1],
sourceIndex: rawCommand[3]
}
}

serialize () {
const rawCommand = 'MPSS'
return new Buffer([
...Buffer.from(rawCommand),
this.flag,
this.mediaPlayerId,
this.newProperties.sourceType,
this.newProperties.clipIndex,
this.newProperties.stillIndex,
0x00,
0x00,
0x00
])
}

applyToState (state: AtemState) {
state.media.players[this.mediaPlayerId] = {
...state.media.players[this.mediaPlayerId],
...this.properties
}
}
}
1 change: 1 addition & 0 deletions src/commands/Media/MediaPlayerStatusCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MediaPlayerStatusCommand extends AbstractCommand {

applyToState (state: AtemState) {
state.media.players[this.mediaPlayerId] = {
...state.media.players[this.mediaPlayerId],
...this.properties
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/commands/Media/MediaPoolClipDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AtemState } from '../../state'
import { ClipBank } from '../../state/media'
import AbstractCommand from '../AbstractCommand'
import { Util } from '../..'

export class MediaPoolClipDescriptionCommand extends AbstractCommand {
rawName = 'MPCS'

mediaPool: number
properties: ClipBank

deserialize (rawCommand: Buffer) {
this.mediaPool = rawCommand[0]
this.properties = {
isUsed: rawCommand[1] === 1,
name: Util.bufToNullTerminatedString(rawCommand, 2, 64),
frameCount: rawCommand.readUInt16BE(66),
frames: []
}
}

applyToState (state: AtemState) {
const newProps = { ...this.properties }

// @todo: check if the undefined check makes sense, maybe check for frameCount instead?
if (typeof state.media.clipPool[this.mediaPool - 1] !== 'undefined') {
newProps.frames = state.media.clipPool[this.mediaPool - 1].frames
}
state.media.clipPool[this.mediaPool - 1] = newProps
}
}
30 changes: 30 additions & 0 deletions src/commands/Media/MediaPoolFrameDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AtemState } from '../../state'
import { StillFrame } from '../../state/media'
import AbstractCommand from '../AbstractCommand'
import { Util } from '../..'

export class MediaPoolFrameDescriptionCommand extends AbstractCommand {
rawName = 'MPfe'

mediaPool: number
frameIndex: number
properties: StillFrame

deserialize (rawCommand: Buffer) {
this.mediaPool = rawCommand[0]
this.frameIndex = rawCommand.readUInt16BE(2)
this.properties = {
isUsed: rawCommand[4] === 1,
hash: Util.bufToNullTerminatedString(rawCommand, 5, 16),
fileName: Util.bufToNullTerminatedString(rawCommand, 22, 20)
}
}

applyToState (state: AtemState) {
if (this.mediaPool === 0) {
state.media.stillPool[this.frameIndex] = this.properties
} else if (this.mediaPool < 3) {
state.media.clipPool[this.mediaPool - 1].frames[this.frameIndex] = this.properties
}
}
}
3 changes: 3 additions & 0 deletions src/commands/Media/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from './MediaPlayerSourceCommand'
export * from './MediaPlayerStatusCommand'
export * from './MediaPoolClearClipCommand'
export * from './MediaPoolClipDescription'
export * from './MediaPoolFrameDescription'
export * from './MediaPoolSetClipCommand'
5 changes: 5 additions & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ export enum TransferState {
Transferring,
Finished
}

export enum MediaSourceType {
Still,
Clip
}
26 changes: 23 additions & 3 deletions src/state/media.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import * as Enums from '../enums'

export interface MediaPlayer {
playing: boolean
loop: boolean
atBeginning: boolean
clipFrame: number
}

export interface MediaPlayerSource {
sourceType: Enums.MediaSourceType
sourceIndex: number
}

export class MediaState {
stillPool = {}
clipPool = {}
players: Array<MediaPlayer> = []
stillPool: Array<StillFrame> = []
clipPool: Array<ClipBank> = []
players: Array<MediaPlayer & MediaPlayerSource> = []
}

export class StillFrame {
isUsed: boolean
hash: string
fileName: string
}

export class ClipBank {
isUsed: boolean
name: string
frameCount: number
frames: Array<StillFrame> = []
}

0 comments on commit fbae9b1

Please sign in to comment.