Modified to throw an error for unsupported codecs. - #1746
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces throwing behavior for unsupported codecs by validating codec formats in SRTStream and updating related APIs and call sites to handle errors.
- Added
supportedAudioCodecsandsupportedVideoCodecsinSRTStream, and madesetAudioSettingsthrowunsupportedCodecfor invalid formats. - Updated
HKStreamprotocol and its implementations (SRTStream,RTMPStream) so thatsetAudioSettingsandsetVideoSettingsarethrows. - Changed all codec-setting calls to use
try? awaitand updated example imports accordingly.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SRTHaishinKit/Tests/SRT/SRTStreamTests.swift | Added test for unsupported audio codec throwing behavior. |
| SRTHaishinKit/Sources/SRT/SRTStream.swift | Added supported codec sets; made audio/video setting methods throw. |
| RTMPHaishinKit/Sources/RTMP/RTMPStream.swift | Updated setAudioSettings/setVideoSettings signatures to throws. |
| HaishinKit/Sources/HKStream/HKStreamBitRateStrategy.swift | Wrapped setVideoSettings calls with try? await. |
| HaishinKit/Sources/HKStream/HKStream.swift | Updated HKStream protocol to include throws on codec setters. |
| HaishinKit/Sources/Extension/CMVideoFormatDescription+Extension.swift | Changed isCompressed access level to package. |
| HaishinKit/Sources/Codec/VideoCodecSettings.swift | Made Format enum package and added CaseIterable. |
| Examples/visionOS/ViewModel.swift | Added import RTMPHaishinKit. |
| Examples/visionOS/PiPHKSwiftUiView.swift | Added import RTMPHaishinKit. |
| Examples/visionOS/ContentView.swift | Added import RTMPHaishinKit. |
| Examples/tvOS/AppDelegate.swift | Added import RTMPHaishinKit. |
| Examples/iOS/Screencast/SampleHandler.swift | Wrapped setVideoSettings call with try? await. |
| Examples/iOS/IngestViewController.swift | Wrapped setAudioSettings and setVideoSettings with try? await. |
Comments suppressed due to low confidence (1)
HaishinKit/Sources/HKStream/HKStreamBitRateStrategy.swift:37
- The variable name mamimumVideoBitRate appears to be misspelled; consider renaming it to maximumVideoBitRate for clarity.
let incremental = mamimumVideoBitRate / 10
| } | ||
|
|
||
| public func setVideoSettings(_ videoSettings: VideoCodecSettings) { | ||
| public func setVideoSettings(_ videoSettings: VideoCodecSettings) throws { |
There was a problem hiding this comment.
The method setVideoSettings is now throwable but doesn’t validate supportedVideoCodecs or throw for unsupported formats. Consider adding a guard for Self.supportedVideoCodecs.contains(videoSettings.format) and throwing Error.unsupportedCodec when the codec is not supported.
| public func setVideoSettings(_ videoSettings: VideoCodecSettings) throws { | |
| public func setVideoSettings(_ videoSettings: VideoCodecSettings) throws { | |
| guard Self.supportedVideoCodecs.contains(videoSettings.format) else { | |
| throw Error.unsupportedCodec | |
| } |
| } | ||
|
|
||
| public func setAudioSettings(_ audioSettings: AudioCodecSettings) { | ||
| public func setAudioSettings(_ audioSettings: AudioCodecSettings) throws { |
There was a problem hiding this comment.
[nitpick] This throwing method currently doesn’t throw under any condition. Either implement validation for unsupported codecs to throw an error, or remove the throws declaration to avoid confusion.
| public func setAudioSettings(_ audioSettings: AudioCodecSettings) throws { | |
| public func setAudioSettings(_ audioSettings: AudioCodecSettings) { |
042cfc1 to
574893e
Compare
574893e to
7741aee
Compare
Description & motivation
Type of change
Screenshots: