Dev1an / Swift-Atem

Blackmagic Design Atem network protocol implementation in swift 5.1 using NIO 2
MIT License
58 stars 27 forks source link

Error while trying to connect and send message to switcher #9

Closed adamtow closed 3 years ago

adamtow commented 3 years ago

I'm having a problem trying to get the controller connected properly so I can send messages:

if let controller = try? Controller(ipAddress: "10.0.1.50") {
    print("Before sending message")
    controller.send(message: ChangeTransitionPosition(to: 5000))
}

This error occurs right after calling print in the EventLoopGroup extension of NIO.

NIO-ELT-1-#0 (10): Fatal error: BUG DETECTED: syncShutdownGracefully() must not be called when on an EventLoop.
Calling syncShutdownGracefully() on any EventLoop can lead to deadlocks.
Current eventLoop: SelectableEventLoop { selector = Selector { descriptor = 3 }, thread = NIOThread(name = NIO-ELT-1-#0) }

Do you have a sample app that uses the Swift-Atem package to send one or two commands to a switcher?

Dev1an commented 3 years ago

Here is an example of sending messages to the ATEM: /Sources/PreviewSwitcher/main.swift You can run that by cloning this repository, and typing swift run PreviewSwitcher in the command line.

Dev1an commented 3 years ago

Note that the Preview Switcher example I referred to, uses a newer version of this library that isn't released yet. I actually made quite some changes since the last release that are yet to be documented. You can take advantage of these changes by using the latest commit on the master branch and by looking at the example code that you can already find in the /Sources folder.

Let me know if you still have problems using this latest version, or if you have any questions on how to use it.

adamtow commented 3 years ago

Thanks for this. I got the controller to be instantiated and can see the PreviewBus updating in my console when I press the buttons on the switcher.

Now, I want to be able to send a message, such as turning the DSK1 to On, but I don't see any commands that send the "CDsL" message. Is that because it isn't implemented in your app, or is there a way to send arbitrary messages to the switcher?

Looking at the Config.Topology message, I don't see any listing for the upstreamKeyers. Is this also something that isn't yet implemented?

Finally, do you have plans to support listing out and running macros?

Dev1an commented 3 years ago

The preview switcher also has an example of how to send messages: https://github.com/Dev1an/Swift-Atem/blob/b1ab46e3e59353cf18a9093b8fc9ed53917f6e47/Sources/PreviewSwitcher/main.swift#L43

Changing the downstream keyers isn’t implemented yet. But yes, you can send your own arbitrary messages if you know how they are structured. Just look at the ChangePreviewBus example: https://github.com/Dev1an/Swift-Atem/blob/b1ab46e3e59353cf18a9093b8fc9ed53917f6e47/Sources/Atem/Messages/Actions.swift#L32-L54 Change the title from ‘CPvI’ to ‘CDsL’ and change the properties, initializer and the ‘dataBytes’. ‘dataBytes’ is the raw message that will be sent to the atem when you execute ‘ controller.send(message: yourMessage)’

Dev1an commented 3 years ago

The number of upstreamkeyers is not listed in the Topology command but it is instead listed in the Config.MixEffect command: https://github.com/Dev1an/Swift-Atem/blob/b1ab46e3e59353cf18a9093b8fc9ed53917f6e47/Sources/Atem/Messages/Configuration.swift#L190.

There is another library out there (LibAtem) that is quite complete where you can look into the implementation to figure out most of the blackmagic protocol: https://github.com/LibAtem/LibAtem/blob/27e1f7e3b6236eb1929f42b6b3cabd0575ee8652/LibAtem/Commands/DeviceProfile/MixEffectBlockConfigCommand.cs

They also implemented the macro commands: https://github.com/LibAtem/LibAtem/tree/master/LibAtem/Commands/Macro

adamtow commented 3 years ago

Thanks again. I've made some progress getting the USK and DSK commands working. I'll be submitting a pull request later.

adamtow commented 3 years ago

I submitted the following pull request which implements a bunch of features that I needed. Thank you for creating this library. It's been very helpful! https://github.com/Dev1an/Swift-Atem/pull/10