Skip to content

Commit

Permalink
Fix can't playback audio streo.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Nov 20, 2023
1 parent ae3edd1 commit 9072439
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
5 changes: 2 additions & 3 deletions Examples/visionOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftUI

struct ContentView: View {
@ObservedObject var viewModel = ViewModel()

private var lfView: PiPHKSwiftUiView!

init() {
Expand All @@ -16,7 +16,7 @@ struct ContentView: View {
VStack {
lfView
.ignoresSafeArea()
.onTapGesture { location in
.onTapGesture { _ in
self.viewModel.startPlaying()
}
Text("Hello, world!")
Expand All @@ -27,4 +27,3 @@ struct ContentView: View {
#Preview(windowStyle: .automatic) {
ContentView()
}

3 changes: 1 addition & 2 deletions Examples/visionOS/PiPHKSwiftUiView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SwiftUI
import HaishinKit
import SwiftUI

struct PiPHKSwiftUiView: UIViewRepresentable {
var piphkView = PiPHKView(frame: .zero)
Expand All @@ -15,4 +15,3 @@ struct PiPHKSwiftUiView: UIViewRepresentable {
piphkView.attachStream(rtmpStream)
}
}

36 changes: 13 additions & 23 deletions Sources/Codec/AudioCodecSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct AudioCodecSettings: Codable {
case .aac:
return UInt32(MPEG4ObjectID.AAC_LC.rawValue)
case .pcm:
return kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat
return kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved
}
}

Expand Down Expand Up @@ -108,28 +108,18 @@ public struct AudioCodecSettings: Codable {
}

func makeAudioFormat(_ format: AVAudioFormat) -> AVAudioFormat? {
switch self {
case .aac:
var streamDescription = AudioStreamBasicDescription(
mSampleRate: format.sampleRate,
mFormatID: formatID,
mFormatFlags: formatFlags,
mBytesPerPacket: bytesPerPacket,
mFramesPerPacket: framesPerPacket,
mBytesPerFrame: bytesPerFrame,
mChannelsPerFrame: min(format.channelCount, AudioCodecSettings.maximumNumberOfChannels),
mBitsPerChannel: bitsPerChannel,
mReserved: 0
)
return AVAudioFormat(streamDescription: &streamDescription)
case .pcm:
return AVAudioFormat(
commonFormat: .pcmFormatFloat32,
sampleRate: format.sampleRate,
channels: min(format.channelCount, AudioCodecSettings.maximumNumberOfChannels),
interleaved: true
)
}
var streamDescription = AudioStreamBasicDescription(
mSampleRate: format.sampleRate,
mFormatID: formatID,
mFormatFlags: formatFlags,
mBytesPerPacket: bytesPerPacket,
mFramesPerPacket: framesPerPacket,
mBytesPerFrame: bytesPerFrame,
mChannelsPerFrame: min(format.channelCount, AudioCodecSettings.maximumNumberOfChannels),
mBitsPerChannel: bitsPerChannel,
mReserved: 0
)
return AVAudioFormat(streamDescription: &streamDescription)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/IO/IOTellyUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class IOTellyUnit {

var delegate: (any IOTellyUnitDelegate)?

private lazy var mediaLink: MediaLink = {
private lazy var mediaLink = {
var mediaLink = MediaLink<IOTellyUnit>()
mediaLink.delegate = self
return mediaLink
Expand Down

0 comments on commit 9072439

Please sign in to comment.