-
Notifications
You must be signed in to change notification settings - Fork 3
Fix 60 FPS bitrate negotiation #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #include "nvst_sdp.hpp" | ||
|
|
||
| #include "../video_quality_policy.hpp" | ||
|
|
||
| #include <algorithm> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace opennow::webrtc | ||
| { | ||
| namespace | ||
| { | ||
|
|
||
| std::string ExtractSdpValue(const std::string& sdp, const std::string& prefix) | ||
| { | ||
| size_t start = 0; | ||
| while (start < sdp.size()) { | ||
| size_t end = sdp.find('\n', start); | ||
| const size_t length = end == std::string::npos ? std::string::npos : end - start; | ||
| std::string line = sdp.substr(start, length); | ||
| if (!line.empty() && line.back() == '\r') | ||
| line.pop_back(); | ||
| if (line.rfind(prefix, 0) == 0) | ||
| return line.substr(prefix.size()); | ||
| if (end == std::string::npos) | ||
| break; | ||
| start = end + 1; | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| std::string BuildNvstSdp( | ||
| const std::string& answer_sdp, | ||
| const StreamSettings& settings, | ||
| const RiInputCapabilities& ri_caps) | ||
| { | ||
| constexpr int kOfficialMinimumBitrateKbps = 4000; | ||
| const std::string ice_ufrag = ExtractSdpValue(answer_sdp, "a=ice-ufrag:"); | ||
| const std::string ice_pwd = ExtractSdpValue(answer_sdp, "a=ice-pwd:"); | ||
| const std::string fingerprint = ExtractSdpValue(answer_sdp, "a=fingerprint:sha-256 "); | ||
| const auto tuning = video::ResolveQualityTuning(settings.image_quality_mode); | ||
| const int max_bitrate = std::max(kOfficialMinimumBitrateKbps, settings.bitrate_kbps); | ||
| const int initial_bitrate = std::max(kOfficialMinimumBitrateKbps, max_bitrate / 4); | ||
|
|
||
| const std::vector<std::string> lines = { | ||
| "v=0", | ||
| "o=SdpTest test_id_13 14 IN IPv4 127.0.0.1", | ||
| "s=-", | ||
| "t=0 0", | ||
| "a=general.icePassword:" + ice_pwd, | ||
| "a=general.iceUserNameFragment:" + ice_ufrag, | ||
| "a=general.dtlsFingerprint:" + fingerprint, | ||
| "m=video 0 RTP/AVP", | ||
| "a=msid:fbc-video-0", | ||
| "a=vqos.fec.rateDropWindow:10", | ||
| "a=vqos.fec.minRequiredFecPackets:2", | ||
| "a=vqos.drc.minRequiredBitrateCheckEnabled:1", | ||
| "a=vqos.fec.repairMinPercent:" + std::to_string(tuning.fec_repair_min_percent), | ||
| "a=vqos.fec.repairPercent:" + std::to_string(tuning.fec_repair_percent), | ||
| "a=vqos.fec.repairMaxPercent:" + std::to_string(tuning.fec_repair_max_percent), | ||
| "a=vqos.dynamicStreamingMode:3", | ||
| "a=vqos.bllFec.enable:0", | ||
| "a=vqos.drc.enable:1", | ||
| "a=video.dx9EnableNv12:1", | ||
| "a=video.dx9EnableHdr:1", | ||
| "a=vqos.qpg.enable:1", | ||
| "a=vqos.resControl.qp.qpg.featureSetting:7", | ||
| "a=bwe.useOwdCongestionControl:1", | ||
| "a=video.enableRtpNack:1", | ||
| "a=vqos.bw.txRxLag.minFeedbackTxDeltaMs:200", | ||
| "a=vqos.drc.bitrateIirFilterFactor:18", | ||
| "a=video.packetSize:1140", | ||
| "a=packetPacing.minNumPacketsPerGroup:" + | ||
| std::to_string(tuning.pacing_min_packets_per_group), | ||
| "a=vqos.adjustStreamingFpsDuringOutOfFocus:1", | ||
| "a=vqos.resControl.cpmRtc.ignoreOutOfFocusWindowState:1", | ||
| "a=vqos.resControl.perfHistory.rtcIgnoreOutOfFocusWindowState:1", | ||
| "a=vqos.resControl.cpmRtc.featureMask:3", | ||
| "a=packetPacing.numGroups:" + std::to_string(tuning.pacing_groups), | ||
| "a=packetPacing.maxDelayUs:" + std::to_string(tuning.pacing_max_delay_us), | ||
| "a=packetPacing.minNumPacketsFrame:10", | ||
| "a=video.rtpNackQueueLength:1024", | ||
| "a=video.rtpNackQueueMaxPackets:512", | ||
| "a=video.rtpNackMaxPacketCount:25", | ||
| "a=video.clientViewportWd:" + std::to_string(settings.width), | ||
| "a=video.clientViewportHt:" + std::to_string(settings.height), | ||
| "a=video.maxFPS:" + std::to_string(settings.fps), | ||
| "a=video.initialBitrateKbps:" + std::to_string(initial_bitrate), | ||
| "a=video.initialPeakBitrateKbps:" + std::to_string(initial_bitrate), | ||
| "a=vqos.bw.maximumBitrateKbps:" + std::to_string(max_bitrate), | ||
| "a=vqos.bw.minimumBitrateKbps:" + std::to_string(kOfficialMinimumBitrateKbps), | ||
| "a=video.maxNumReferenceFrames:4", | ||
| "a=video.mapRtpTimestampsToFrames:1", | ||
| "a=video.encoderCscMode:3", | ||
| "a=video.encoderHdrCscMode:4", | ||
| "a=video.dynamicRangeMode:0", | ||
| "a=video.bitDepth:8", | ||
| "a=video.scalingFeature1:0", | ||
| "a=video.prefilterParams.prefilterMode:0", | ||
| "a=video.prefilterParams.prefilterModel:0", | ||
| "a=video.prefilterParams.denoiseLevel:0", | ||
| "a=video.prefilterParams.sharpnessLevel:0", | ||
| "m=audio 0 RTP/AVP", | ||
| "a=msid:audio", | ||
| "m=mic 0 RTP/AVP", | ||
| "a=msid:mic", | ||
| "a=rtpmap:0 PCMU/8000", | ||
| "m=application 0 RTP/AVP", | ||
| "a=msid:input_1", | ||
| "a=ri.partialReliableThresholdMs:" + std::to_string(ri_caps.partial_reliable_threshold_ms), | ||
| "a=ri.hidDeviceMask:" + std::to_string(ri_caps.hid_device_mask), | ||
| "a=ri.enablePartiallyReliableTransferGamepad:" + | ||
| std::to_string(ri_caps.partial_reliable_gamepad_mask), | ||
| "a=ri.enablePartiallyReliableTransferHid:" + | ||
| std::to_string(ri_caps.partial_reliable_hid_mask), | ||
| "", | ||
| }; | ||
|
|
||
| std::string result; | ||
| for (const auto& line : lines) { | ||
| result += line; | ||
| result += "\n"; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace opennow::webrtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "../stream_settings.hpp" | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| namespace opennow::webrtc | ||
| { | ||
|
|
||
| struct RiInputCapabilities | ||
| { | ||
| int partial_reliable_threshold_ms = 16; | ||
| std::uint32_t hid_device_mask = 0xffffffffu; | ||
| std::uint32_t partial_reliable_gamepad_mask = 0x0fu; | ||
| std::uint32_t partial_reliable_hid_mask = 0xffffffffu; | ||
| }; | ||
|
|
||
| std::string BuildNvstSdp( | ||
| const std::string& answer_sdp, | ||
| const StreamSettings& settings, | ||
| const RiInputCapabilities& ri_caps); | ||
|
|
||
| } // namespace opennow::webrtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "gfn/cloud_session_internal.hpp" | ||
|
|
||
| #include <jansson.h> | ||
|
|
||
| #include <cassert> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| int main() | ||
| { | ||
| opennow::StreamSettings settings; | ||
| settings.width = 1280; | ||
| settings.height = 720; | ||
| settings.fps = 60; | ||
| settings.bitrate_kbps = 12000; | ||
|
|
||
| const std::string body = opennow::gfn::cloud_session::BuildSessionBody( | ||
| "app-id", "title", "device-id", "sub-session-id", "network-test-id", settings); | ||
| json_error_t error {}; | ||
| std::unique_ptr<json_t, decltype(&json_decref)> root( | ||
| json_loads(body.c_str(), 0, &error), &json_decref); | ||
| assert(root); | ||
|
|
||
| json_t* session_request = json_object_get(root.get(), "sessionRequestData"); | ||
| assert(json_is_object(session_request)); | ||
| json_t* features = json_object_get(session_request, "requestedStreamingFeatures"); | ||
| assert(json_is_object(features)); | ||
| assert(json_integer_value(json_object_get(features, "maxBitrateKbps")) == 12000); | ||
| assert(json_integer_value(json_object_get(features, "codec")) == 1); | ||
| assert(json_is_false(json_object_get(features, "vsync"))); | ||
| assert(json_integer_value(json_object_get(features, "dynamicStreamingMode")) == 3); | ||
| assert(json_integer_value(json_object_get(features, "audioChannelCount")) == 2); | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: OpenCloudGaming/OpenNOW-Switch
Length of output: 19502
🏁 Script executed:
Repository: OpenCloudGaming/OpenNOW-Switch
Length of output: 5691
🏁 Script executed:
Repository: OpenCloudGaming/OpenNOW-Switch
Length of output: 13493
🏁 Script executed:
Repository: OpenCloudGaming/OpenNOW-Switch
Length of output: 21784
Keep regression assertions active in every test build.
These host tests use standard
assert, and-DNDEBUGremoves every JSON check. Since no CMake test target controls the standalone test flags, a Release-style build can pass with incorrect streaming feature values. Use always-on test assertions or explicitly excludeNDEBUGfrom test builds.🤖 Prompt for AI Agents