pjvds / SRTHaishinKit.swift

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SRTHaishinKit

GitHub license

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

🎨 Features

SRT

  • Publish and Recording (H264/AAC)
  • Playback
  • 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.1"

Swift Package Manager

https://github.com/shogo4405/HaishinKit.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

About

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

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Swift 96.8%Language:Ruby 2.7%Language:Objective-C 0.5%