shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.
https://docs.haishinkit.com/swift/latest
BSD 3-Clause "New" or "Revised" License
2.78k stars 618 forks source link

Choppy audio after updating to iOS 13 #627

Closed hraza-simublade closed 4 years ago

hraza-simublade commented 4 years ago

Describe the bug I'm running the example iOS app in iOS 13 and streaming with Mux (tried it with Wowza as well) and am having issues with the audio being incredibly choppy. Using different bitrates is not fixing the issue. This was not an issue in iOS 12.

To Reproduce Steps to reproduce the behavior:

  1. Launch HaishinKit example on device running iOS13
  2. Start stream
  3. Listen to stream playback, it is choppy

Expected behavior Clear/smooth audio

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context This problem was not occurring in iOS12.

nestor82 commented 4 years ago

I found this bug on only iPhone 11 series. iPhone XS on iOS 13.3 work well, but the steaming by iPhone 11 Pro on iOS 13.3 , sound is very chopping. I tried to change Audiosseion mode, category. but it didn't get well. i tested both recently sdk version and 0.11.9 version, the result was same.

mkrn commented 4 years ago

I can confirm the issue on the latest iPhones this is how the audio sounds (reproduction after conversion to HLS) https://dwy2ap2fjt6gi.cloudfront.net/b5bcef28-c744-472e-892b-96e1e2589fc4/choppysound.m3u8

ryo-liveplanet commented 4 years ago

Having this issue as well with iOS13.2 on iPhone 7 Plus. Any workarounds would be appreciated!

wolfcon commented 4 years ago

Try this sampleRate: 48_000

ryo0ka commented 4 years ago

Try this sampleRate: 48_000

Not working.

DaveMurchison83 commented 4 years ago

That fixed the issue for me. Audio is much improved by setting sampleRate to 48_000

shogo4405 commented 4 years ago

HaishinKit has no feature (down|up)Sample rate.

Xcode console log:

2020-09-02 17:01:41.565 [Info] [com.haishinkit.HaishinKit] [AudioConverter.swift:89] inSourceFormat > Optional(__C.AudioStreamBasicDescription(mSampleRate: 48000.0, mFormatID: 1819304813, mFormatFlags: 41, mBytesPerPacket: 4, mFramesPerPacket: 1, mBytesPerFrame: 4, mChannelsPerFrame: 1, mBitsPerChannel: 32, mReserved: 0))

Solution 1. Please set a same value, mSampleRate.

rtmpStream.audioSettings = [
    .sampleRate: sampleRate, 
]

Solution 2. Please unset a sampleRate value.

rtmpStream.audioSettings = [
    .sampleRate: 0, 
]
ryo-liveplanet commented 4 years ago

@shogo4405 Thanks, the 2nd solution worked. Set .sampleRate to 0.

mkrn commented 4 years ago

@ryo-liveplanet 2nd solution didn't work for me. avAudioSampleRate: Double = 0

On the server-side I'm converting with FFPMEG to -b:a 48000 \ -r 30 \

WIth iPhone 11 and latest iOS it still came out choppy.

https://live.eventlive.pro/marinaachernova/test-event-1

It works good with iPhone 8 however.

shogo4405 commented 4 years ago

I think might be fixed it #640. Please update and try master branch. Don't forget.

rtmpStream.audioSettings = [ .sampleRate: 0, ]

MikeDonahue commented 4 years ago

@shogo4405 Tried master on an iPhone 11, iOS 13.1. Still choppy audio

mkrn commented 4 years ago

Any ideas? @shogo4405 Could it be related to different aspect ratios? Anything has changed in iOS APIs for new version phones?

shogo4405 commented 4 years ago

@mkrn How about master branch?

I want two informations. print(sampleBuffer) print(sampleBuffer.numSamples)

shogo4405 commented 4 years ago

I belived fixed this issue #640. If not fixed this issue, please open an new issue.

mkrn commented 4 years ago

@shogo4405 the master fixes the problem. Thank you very much!