MyCometG3 / DLABridging

Simple Objective-C++ wrapper for Blackmagic DeckLink API (C++ APIs).
MIT License
15 stars 7 forks source link

DLABridging.framework

Simple Objective-C++ wrapper for Blackmagic DeckLink API (C++ APIs).

NOTE: This framework is under development.

About unsupported feature(s):

: Following interfaces are not supported. (Section # are from SDK 12.9 pdf)
: 2.5.8 IDeckLinkVideoFrame3DExtensions
: 2.5.18 IDeckLinkMemoryAllocator
: 2.5.26 IDeckLinkGLScreenPreviewHelper
: 2.5.27 IDeckLinkCocoaScreenPreviewCallback
: 2.5.28 IDeckLinkDX9ScreenPreviewHelper
: 2.5.35 IDeckLinkEncoderInput
: 2.5.36 IDeckLinkEncoderInputCallback
: 2.5.37 IDeckLinkEncoderPacket
: 2.5.38 IDeckLinkEncoderVideoPacket
: 2.5.39 IDeckLinkEncoderAudioPacket
: 2.5.40 IDeckLinkH265NALPacket
: 2.5.41 IDeckLinkEncoderConfiguration
: 2.5.44 IDeckLinkVideoConversion
: 2.5.50 IDeskLinkMetalScreenPreviewHelper
: 2.5.51 IDeckLinkWPFDX9ScreenPreviewHelper
: 2.6.x Any Streaming Interface APIs

Basic usage (capture)

1. Find DLABDevice using DLABBrowser
import Cocoa
import DLABridging
var device :DLABDevice? = nil
var running :Bool = false
do {
  let browser = DLABBrowser()
  _ = browser.registerDevicesForInput()
  let deviceList = browser.allDevices
  device = deviceList.first!
}
2. Start input stream
if let device = device {
  try device.setInputScreenPreviewTo(parentView)

  // To capture HDMI
  var videoConnection :DLABVideoConnection = .HDMI
  var audioConnection :DLABAudioConnection = .embedded

  // To capture SVideo+RCA
  var videoConnection :DLABVideoConnection = .sVideo
  var audioConnection :DLABAudioConnection = .analogRCA

  // To prepare SD Video setting
  var vSetting:DLABVideoSetting? = nil
  try vSetting = device.createInputVideoSetting(of: .modeNTSC,
                                                pixelFormat: .format8BitYUV,
                                                inputFlag: [])

  // To prepare stereo Audio setting
  var aSetting:DLABAudioSetting? = nil
  try aSetting = device.createInputAudioSetting(of: .type16bitInteger,
                                                channelCount: 2,
                                                sampleRate: .rate48kHz)

  // To support NTSC-SD CleanAperture and PixelAspectRatio
  if let vSetting = vSetting {
    try vSetting.addClapExt(ofWidthN: 704, widthD: 1,
                            heightN: 480, heightD: 1,
                            hOffsetN: 4, hOffsetD: 1,
                            vOffsetN: 0, vOffsetD: 1)
    try vSetting.addPaspExt(ofHSpacing: 40,
                            vSpacing: 33)
  }

  // To capture using preferred CVPixelFormat
  var myCVPixelFormat :OSType = kCVPixelFormatType_32BGRA
  vSetting.cvPixelFormatType = myCVPixelFormat
  try vSetting.buildVideoFormatDescription()

  // To support HDMI surround audio; audioSetting channelCount should be 8
  var hdmiAudioChannels = 6 // HDMI surround 5.1ch
  var reverseCh3Ch4 = true // For layout of (ch3, ch4) == (LFE, C)
  if let aSetting = aSetting, videoConnection == .HDMI, audioConnection == .embedded,
    audioChannels == 8, audioChannels >= hdmiAudioChannels, hdmiAudioChannels > 0 {
    // rebuild formatDescription to support HDMI Audio Channel order
    try aSetting.buildAudioFormatDescription(forHDMIAudioChannels: hdmiAudioChannels,
                                             swap3chAnd4ch: reverseCh3Ch4)
  }

  if let vSetting = vSetting, let aSetting = aSetting {
    device.inputDelegate = self
    try device.enableVideoInput(with: vSetting, on: videoConnection)
    try device.enableAudioInput(with: aSetting, on: audioConnection)
    try device.startStreams()
    running = true
  }
} catch {
  print("ERROR!!")
  :
}
3. Handle CMSampleBuffer (Video/Audio)
public func processCapturedVideoSample(_ sampleBuffer: CMSampleBuffer,
                                       of sender:DLABDevice) {
  print("video")
}
public func processCapturedAudioSample(_ sampleBuffer: CMSampleBuffer,
                                       of sender:DLABDevice) {
  print("audio")
}
public func processCapturedVideoSample(_ sampleBuffer: CMSampleBuffer,
                                       timecodeSetting setting: DLABTimecodeSetting,
                                       of sender:DLABDevice) {
  print("video/timecode")
}
4. Stop input stream
running = false
if let device = device {
  try device.stopStreams()
  try device.disableVideoInput()
  try device.disableAudioInput()
  device.inputDelegate = nil
  try device.setInputScreenPreviewTo(nil)
} catch {
  print("ERROR!!")
}
device = nil

Developer Notice

1. AppEntitlements for Sandboxing
2. AppEntitlements for Hardened Runtime

Development environment

License

Copyright © 2017-2024年 MyCometG3. All rights reserved.