[WebRTCP] Identify duplicated logic around stream handling and consolidate it.#42864
Conversation
There was a problem hiding this comment.
Pull request overview
This PR consolidates duplicated stream handling logic in the WebRTC Transport Provider cluster by extracting common validation patterns into reusable helper methods. This refactoring addresses issue #42858 which requested consolidation of repeated stream handling code across different commands.
Changes:
- Added four new stream validation helper methods:
ValidateVideoStreamID,ValidateAudioStreamID,ValidateVideoStreams, andValidateAudioStreams - Refactored
HandleSolicitOfferandHandleProvideOfferto use the new helper methods, eliminating ~240 lines of duplicated code - Fixed a critical bug where audio stream ID validation incorrectly called
ValidateVideoStreamIDinstead ofValidateAudioStreamID - Improved comment grammar by changing "and" to "or" in validation requirement descriptions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| WebRTCTransportProviderCluster.h | Added declarations for four new stream validation helper methods |
| WebRTCTransportProviderCluster.cpp | Implemented the four helper methods and refactored HandleSolicitOffer and HandleProvideOffer to use them, fixing a validation bug in the process |
There was a problem hiding this comment.
Code Review
This pull request does a great job of consolidating duplicated stream handling logic from HandleSolicitOffer and HandleProvideOffer into new helper functions, significantly improving code readability and maintainability. This aligns with the practice of extracting common logic to reduce duplication. It also commendably fixes a subtle bug in HandleSolicitOffer where ValidateVideoStreamID was incorrectly used for an audio stream. I've added a couple of suggestions to take the consolidation a step further by using templates for the new helper functions, which would reduce duplication even more, further enhancing maintainability.
|
PR #42864: Size comparison from bd1cc4d to d88eb91 Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42864: Size comparison from bd1cc4d to 12042df Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
…42923) * [WebRTCP] Identify duplicated logic around stream handling and consolidate it. (#42864) * Identify duplicated logic around stream handling and consolidate it. * Addres copilot comments * Fix build error * [Camera] Fix camera app crashes on unexpected SDPs (#42875) * Fix camera app crashes on unexpected SDPs * Address review comments * Add extra mandatory fields check * AVSUM: Use NotifyAttributeChanged instead of MatterReportingAttributeChangeCallback (#42909) * AVSUM: Use NotifyAttributeChanged instead of MatterReportingAttributeChangeCallback Replace legacy MatterReportingAttributeChangeCallback with NotifyAttributeChanged for CameraAvSettingsUserLevelMgmtServerLogic. This aligns with the code-driven cluster pattern where NotifyAttributeChanged properly increments the cluster data version and notifies through the ServerClusterContext. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Breaks the circular dependency --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Consolidated the duplicated stream handling logic in the WebRTC Transport Provider cluster
Benefits:
Consistency: Both commands use identical validation logic, reducing the risk of divergence
Related issues
Fixes: #42858
Testing
Validate by CI
Readability checklist
The checklist below will help the reviewer finish PR review in time and keep the
code readable:
descriptive
“When in Rome…”
rule (coding style)
See: Pull Request Guidelines