-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Media): Media Pool Description Commands
- Loading branch information
Balte de Wit
authored and
Alex Van Camp
committed
Sep 11, 2018
1 parent
e3e69a1
commit fbae9b1
Showing
7 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,3 +242,8 @@ export enum TransferState { | |
Transferring, | ||
Finished | ||
} | ||
|
||
export enum MediaSourceType { | ||
Still, | ||
Clip | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> = [] | ||
} |