Skip to content

Commit b1ab46e

Browse files
committed
Add MediaPlayerFrameDescription change decoder
1 parent 97b0283 commit b1ab46e

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

Sources/Atem/MediaPool.swift

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Damiaan on 05/12/2020.
6+
//
7+
8+
public enum MediaPool {
9+
public enum Bank: RawRepresentable {
10+
public typealias RawValue = UInt8
11+
12+
case still
13+
case clip(index: UInt8)
14+
15+
public init?(rawValue: UInt8) {
16+
switch rawValue {
17+
case 0: self = .still
18+
case 1...4:
19+
self = .clip(index: rawValue - 1)
20+
default:
21+
return nil
22+
}
23+
}
24+
25+
public var rawValue: UInt8 {
26+
switch self {
27+
case .still: return 0
28+
case .clip(let index): return index + 1
29+
}
30+
}
31+
}
32+
33+
public struct ID {
34+
let bank: Bank
35+
let frame: UInt16
36+
}
37+
}

Sources/Atem/Messages/Actions.swift

+39
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ extension Message.Did {
305305
}
306306
}
307307

308+
// MARK: Tally lights
309+
308310
extension Message.Did {
309311
/// Informs a controller that the some tally lights might have changed.
310312
public struct ChangeSourceTallies: SerializableMessage {
@@ -351,6 +353,8 @@ extension Message.Did {
351353
}
352354
}
353355

356+
// MARK: Key DVE
357+
354358
import Foundation
355359
extension Message.Do {
356360
@available(OSX 10.12, iOS 10.0, *)
@@ -411,3 +415,38 @@ extension Message.Do {
411415
}
412416
}
413417
}
418+
419+
// MARK: Change Media Player
420+
421+
public extension Message.Did {
422+
struct ChangeMediaPlayerFrameDescription: DeserializableMessage {
423+
public static let title = Message.Title(string: "MPfe")
424+
425+
public let id: MediaPool.ID
426+
public let name: String
427+
428+
public init(with bytes: ArraySlice<UInt8>) throws {
429+
let bank = bytes[relative: Position.bank]
430+
let frameIndex = UInt16(from: bytes[relative: Position.frameIndex])
431+
id = .init(bank: try .decode(from: bank), frame: frameIndex)
432+
433+
// Read name
434+
let nameLength = UInt16(from: bytes[relative: Position.nameLength])
435+
let nameBytes = bytes[relative: Position.name( Int(nameLength) )]
436+
guard let decodedName = String(bytes: nameBytes, encoding: .utf8) else {
437+
throw Message.Error.stringNotDecodable(nameBytes)
438+
}
439+
name = decodedName
440+
}
441+
442+
public var debugDescription: String { "Media player \(id): '\(name)'" }
443+
444+
enum Position {
445+
static let bank = 0
446+
static let frameIndex = 2..<4
447+
static let nameLength = 22..<24
448+
static let name = { length in nameLength.endIndex ..< nameLength.endIndex + length }
449+
}
450+
}
451+
}
452+

Sources/Atem/Messages/Message.swift

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum Message {
3636
case serialising
3737
case stringTooLong(String, Int)
3838
case titleNotDeserializable
39+
case stringNotDecodable(ArraySlice<UInt8>)
3940
case unknownModel(UInt8)
4041

4142
var localizedDescription: String {
@@ -48,6 +49,8 @@ public enum Message {
4849
return "Message.Error: serialising"
4950
case .unknownModel(let modelNumber):
5051
return "Message error: unknown model \(modelNumber)"
52+
case .stringNotDecodable(let bytes):
53+
return "Message error: unable to decode \(bytes) as UTF8"
5154
}
5255
}
5356
}

Sources/Atem/UploadManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class UploadManager {
2121

2222
init() {}
2323

24-
func createTransfer(store: UInt16, frameNumber: UInt16, data: Data, uncompressedSize: UInt32, mode: Do.StartDataTransfer.Mode, name optionalName: String? = nil, description: String = "") -> Do.StartDataTransfer {
24+
func createTransfer(store: UInt16, frameNumber: UInt16, data: Data, uncompressedSize: UInt32, mode: Do.StartDataTransfer.Mode, hash: [UInt8] = .init(repeating: 1, count: 16), name optionalName: String? = nil, description: String = "") -> Do.StartDataTransfer {
2525

2626
let id = transferCounter
2727
transferCounter += 1
@@ -30,7 +30,7 @@ public class UploadManager {
3030

3131
let transfer = Transfer(
3232
start: Do.StartDataTransfer(transferID: id, store: store, frameNumber: frameNumber, size: uncompressedSize, mode: mode),
33-
description: Do.SetFileDescription(transferID: id, name: name, description: description),
33+
description: Do.SetFileDescription(transferID: id, name: name, description: description, hash: hash),
3434
data: data
3535
)
3636

0 commit comments

Comments
 (0)