Skip to content

Conversation

SnirDecartAI
Copy link
Contributor

Hello! 👋

I tried to use RTCRtpTransceiver.setCodecPreferences, with codecs from factory.getRtpSenderCapabilities(MediaType.VIDEO), but it failed with this message:

java.lang.Error: Set codec preferences failed: [INVALID_MODIFICATION] Invalid codec preferences: Missing codec from codec capabilities.
        at dev.onvoid.webrtc.RTCRtpTransceiver.setCodecPreferences(Native Method)
        at Rtc_main.<init>(rtc.main.kts:71)

This seems to be because RTCRtpCodecCapability::toJava and RTCRtpCodecCapability::toNative don't preserve the capability object because the java conversion uses .value_or(0) on the std::optional<int> fields clock_rate and num_channels.
(and then libwebrtc's IsSameRtpCodec thinks the capability changed and rejects it)

I converted the int fields to Integer, like RTCRtpCodecParameters does for the same reason, and uncommented a setCodecPreferences that was previously causing a test to fail.
The code pretty much matches with RTCRtpCodecParameters.{java,cpp}.

What do you think? :)

@devopvoid devopvoid added bug Something isn't working enhancement New feature or request labels Aug 4, 2025
@SnirDecartAI
Copy link
Contributor Author

(the build failures are because it's trying to deploy to maven, unrelated to the code)

@devopvoid
Copy link
Owner

Thank you for your contribution! I will have a look at this in the morning and merge this then.

@devopvoid devopvoid self-requested a review August 5, 2025 07:18
Copy link
Owner

@devopvoid devopvoid left a comment

Choose a reason for hiding this comment

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

Potential std::bad_optional_access exceptions need to be fixed.

}

if (capability.clock_rate.has_value()) {
clockRate = Integer::create(env, capability.clock_rate.value());
Copy link
Owner

Choose a reason for hiding this comment

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

This may throw a std::bad_optional_access exception by using .value(). I am not sure if the values in this case are always present.
Please use the fail-safe approach:
capability.clock_rate.value_or(0)

Copy link
Owner

Choose a reason for hiding this comment

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

I missed the if statements before. So merging ...

@devopvoid devopvoid merged commit 28a9714 into devopvoid:main Aug 5, 2025
1 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants