Skip to content

Modified to throw an error for unsupported codecs. - #1746

Merged
shogo4405 merged 1 commit into
mainfrom
feature/throws-unsupported-format
Jul 14, 2025
Merged

Modified to throw an error for unsupported codecs.#1746
shogo4405 merged 1 commit into
mainfrom
feature/throws-unsupported-format

Conversation

@shogo4405

Copy link
Copy Markdown
Collaborator

Description & motivation

  • Modified to throw an error for unsupported codecs.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Screenshots:

@shogo4405 shogo4405 added this to the 2.1.0 milestone Jul 14, 2025
@shogo4405
shogo4405 requested a review from Copilot July 14, 2025 14:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 supportedAudioCodecs and supportedVideoCodecs in SRTStream, and made setAudioSettings throw unsupportedCodec for invalid formats.
  • Updated HKStream protocol and its implementations (SRTStream, RTMPStream) so that setAudioSettings and setVideoSettings are throws.
  • Changed all codec-setting calls to use try? await and 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 {

Copilot AI Jul 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
public func setVideoSettings(_ videoSettings: VideoCodecSettings) throws {
public func setVideoSettings(_ videoSettings: VideoCodecSettings) throws {
guard Self.supportedVideoCodecs.contains(videoSettings.format) else {
throw Error.unsupportedCodec
}

Copilot uses AI. Check for mistakes.
}

public func setAudioSettings(_ audioSettings: AudioCodecSettings) {
public func setAudioSettings(_ audioSettings: AudioCodecSettings) throws {

Copilot AI Jul 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
public func setAudioSettings(_ audioSettings: AudioCodecSettings) throws {
public func setAudioSettings(_ audioSettings: AudioCodecSettings) {

Copilot uses AI. Check for mistakes.
@shogo4405
shogo4405 force-pushed the feature/throws-unsupported-format branch 2 times, most recently from 042cfc1 to 574893e Compare July 14, 2025 15:04
@shogo4405
shogo4405 force-pushed the feature/throws-unsupported-format branch from 574893e to 7741aee Compare July 14, 2025 15:08
@shogo4405
shogo4405 merged commit 886b2c7 into main Jul 14, 2025
1 check passed
@shogo4405
shogo4405 deleted the feature/throws-unsupported-format branch July 14, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants