Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Camera and Microphone streaming library via SRT for iOS, macOS.

License

Notifications You must be signed in to change notification settings

shogo4405/SRTHaishinKit.swift

Repository files navigation

[Archived] SRTHaishinKit

GitHub license

  • Camera and Microphone streaming library via SRT for iOS.
  • API Documentation
  • This project status is working in progress.

This project has been integrated into HaishinKit.swift

🎨 Features

SRT

  • Publish and Recording (H264/AAC)
  • Playback(beta)
  • mode
    • caller
    • listener
    • rendezvous

🌏 Requirements

- iOS Xcode Swift
0.1.0+ 11.0+ 14.0+ 5.7
0.0.0+ 8.0+ 10.0+ 4.2

🔧 Installation

Not available.

  • CocoaPods

Carthage

github "shogo4405/SRTHaishinKit.swift" "0.1.2"

Swift Package Manager

https://github.com/shogo4405/SRTHaishinKit.swift

☕ Cocoa Keys

Please contains Info.plist.

iOS 10.0+

  • NSMicrophoneUsageDescription
  • NSCameraUsageDescription

Prerequisites

Make sure you setup and activate your AVAudioSession.

import AVFoundation
let session: AVAudioSession = AVAudioSession.sharedInstance()
do {
    try session.setPreferredSampleRate(44_100)
    // https://stackoverflow.com/questions/51010390/avaudiosession-setcategory-swift-4-2-ios-12-play-sound-on-silent
    if #available(iOS 10.0, *) {
        try session.setCategory(.playAndRecord, mode: .default, options: [.allowBluetooth])
    } else {
        session.perform(NSSelectorFromString("setCategory:withOptions:error:"), with: AVAudioSession.Category.playAndRecord, with:  [AVAudioSession.CategoryOptions.allowBluetooth])
    }
    try session.setMode(AVAudioSessionModeDefault)
    try session.setActive(true)
} catch {
}

SRT Usage

let connection = SRTConnection()
let stream = SRTStream(connection: connection)
stream.attachAudio(AVCaptureDevice.default(for: .audio)) { error in
    // print(error)
}
stream.attachCamera(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)) { error in
    // print(error)
}

let hkView = HKView(frame: view.bounds)
hkView.videoGravity = AVLayerVideoGravity.resizeAspectFill
hkView.attachStream(rtmpStream)

// add ViewController#view
view.addSubview(hkView)

connection.connect("srt://host:port?option=foo")
stream.publish()
let connection = SRTConnection()
let stream = SRTStream(connection: connection)

let hkView = MTHKView(frame: view.bounds)
hkView.videoGravity = AVLayerVideoGravity.resizeAspectFill
hkView.attachStream(rtmpStream)

// add ViewController#view
view.addSubview(hkView)

connection.connect("srt://host:port?option=foo")
stream.play("")

🐾 Examples

SRTHaishinKit needs other dependencies. Please build.

Prerequisites

brew install cmake

iOS

carthage update --use-xcframeworks --platform iOS

You can run the ffplay as SRT service.

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

📖 References

📜 License

BSD-3-Clause