Skip to content

Latest commit

 

History

History
108 lines (92 loc) · 2.58 KB

File metadata and controls

108 lines (92 loc) · 2.58 KB

SRTHaishinKit

This module supports the SRT protocol.

Overview

This is a module that supports SRT protocol. It internally uses a library that is built from libsrt and converted into an xcframework.

🎨 Features

  • Ingest
    • H264, HEVC and AAC support.
  • Playback
    • H264, HEVC and AAC support.
  • SRT Mode
    • caller
    • listener
    • rendezvous

📓 Usage

Ingest

let mixer = MediaMixer()
let connection = SRTConnection()
let stream = SRTStream(connection: connection)
let hkView = MTHKView(frame: view.bounds)

Task {
  do {
    try await mixer.attachAudio(AVCaptureDevice.default(for: .audio))
  } catch {
    print(error)
  }

  do {
    try await mixer.attachVideo(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back))
  } catch {
    print(error)
  }

  await mixer.addOutput(stream)
}

Task { MainActor in
  await stream.addOutput(hkView)
  // add ViewController#view
  view.addSubview(hkView)
}

Task {
  stream.attachAudioPlayer(audioPlayer)
  do {
    try await connection.connect("srt://host:port")
    try await stream.publish()
  } catch {
    print(error)
  }
}

Playback

let connection = SRTConnection()
let stream = SRTStream(connection: connection)
let hkView = MTHKView(frame: view.bounds)
let audioPlayer = AudioPlayer(AVAudioEngine())

Task { MainActor in
  await stream.addOutput(hkView)
  // add ViewController#view
  view.addSubview(hkView)
}

Task {
  // requires attachAudioPlayer
  await stream.attachAudioPlayer(audioPlayer)

  do {
    try await connection.connect("srt://host:port")
    try await stream.play()
  } catch {
    print(error)
  }
}

Specify socket options.

  • On the HaishinKit side, the default settings of libsrt are used.
  • Many SRT options can be defined as query parameters in the connection URL as follows.
try await connection.connect("srt://host:port?key=value")

🔧 Test

ffplay as a SRT service for ingest HaishinKit.

$ ffplay -i 'srt://${YOUR_IP_ADDRESS}?mode=listener'

ffmpeg as a SRT service for playback HaishinKit.

$ ffmpeg -stream_loop -1 -re -i input.mp4 -c copy -f mpegts 'srt://0.0.0.0:9998?mode=listener'

📜 License

SRTHaishinKit

  • SRTHaishinKit is licensed under the BSD-3-Clause.

libsrt.xcframework