Skip to content

[WebRTCP] Identify duplicated logic around stream handling and consolidate it.#42864

Merged
mergify[bot] merged 3 commits intoproject-chip:masterfrom
yufengwangca:pr/webrtc/comments
Jan 29, 2026
Merged

[WebRTCP] Identify duplicated logic around stream handling and consolidate it.#42864
mergify[bot] merged 3 commits intoproject-chip:masterfrom
yufengwangca:pr/webrtc/comments

Conversation

@yufengwangca
Copy link
Copy Markdown
Contributor

@yufengwangca yufengwangca commented Jan 29, 2026

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:

  • PR title is
    descriptive
  • Apply the
    “When in Rome…”
    rule (coding style)
  • PR size is short
  • Try to avoid "squashing" and "force-update" in commit history
  • CI time didn't increase

See: Pull Request Guidelines

Copilot AI review requested due to automatic review settings January 29, 2026 04:30
@github-actions github-actions Bot added the app label Jan 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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, and ValidateAudioStreams
  • Refactored HandleSolicitOffer and HandleProvideOffer to use the new helper methods, eliminating ~240 lines of duplicated code
  • Fixed a critical bug where audio stream ID validation incorrectly called ValidateVideoStreamID instead of ValidateAudioStreamID
  • 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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 29, 2026

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)
platform target config section bd1cc4d d88eb91 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106440 1106440 0 0.0
RAM 178978 178978 0 0.0
bl702 lighting-app bl702+eth FLASH 661210 661210 0 0.0
RAM 135049 135049 0 0.0
bl702+wifi FLASH 837050 837050 0 0.0
RAM 124517 124517 0 0.0
bl706+mfd+rpc+littlefs FLASH 1070974 1070974 0 0.0
RAM 117389 117389 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903548 903548 0 0.0
RAM 105964 105964 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983620 983620 0 0.0
RAM 109884 109884 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771284 771284 0 0.0
RAM 103408 103408 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784320 784320 0 0.0
RAM 108736 108736 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729456 729456 0 0.0
RAM 97484 97484 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 714032 714032 0 0.0
RAM 97692 97692 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555340 555340 0 0.0
RAM 205496 205496 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589224 589224 0 0.0
RAM 205752 205752 0 0.0
efr32 lock-app BRD4187C FLASH 967504 967496 -8 -0.0
RAM 125704 125704 0 0.0
BRD4338a FLASH 761332 761332 0 0.0
RAM 237968 237968 0 0.0
window-app BRD4187C FLASH 1063848 1063840 -8 -0.0
RAM 126828 126828 0 0.0
esp32 all-clusters-app c3devkit DRAM 98204 98204 0 0.0
FLASH 1584468 1584468 0 0.0
IRAM 93514 93514 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 935932 935932 0 0.0
RAM 161974 161974 0 0.0
nxp contact mcxw71+release FLASH 744632 744632 0 0.0
RAM 67152 67152 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1696244 1696244 0 0.0
RAM 214484 214484 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597300 1597300 0 0.0
RAM 211476 211476 0 0.0
light cy8ckit_062s2_43012 FLASH 1460940 1460940 0 0.0
RAM 197808 197808 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495044 1495044 0 0.0
RAM 225688 225688 0 0.0
qpg lighting-app qpg6200+debug FLASH 838716 838716 0 0.0
RAM 128032 128032 0 0.0
lock-app qpg6200+debug FLASH 777164 777164 0 0.0
RAM 118972 118972 0 0.0
realtek light-switch-app rtl8777g FLASH 701992 701992 0 0.0
RAM 113548 113548 0 0.0
lighting-app rtl8777g FLASH 743872 743872 0 0.0
RAM 114768 114768 0 0.0
stm32 light STM32WB5MM-DK FLASH 470804 470804 0 0.0
RAM 141408 141408 0 0.0
telink bridge-app tl7218x FLASH 711642 711642 0 0.0
RAM 93088 93088 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 797432 797432 0 0.0
RAM 41272 41272 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 788762 788762 0 0.0
RAM 96172 96172 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 717432 717432 0 0.0
RAM 54264 54264 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 753242 753242 0 0.0
RAM 73288 73288 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 721814 721814 0 0.0
RAM 34992 34992 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 609728 609728 0 0.0
RAM 117960 117960 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 822266 822270 4 0.0
RAM 94560 94560 0 0.0

Copilot AI review requested due to automatic review settings January 29, 2026 15:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 29, 2026

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)
platform target config section bd1cc4d 12042df change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106440 1106440 0 0.0
RAM 178978 178978 0 0.0
bl702 lighting-app bl702+eth FLASH 661210 661210 0 0.0
RAM 135049 135049 0 0.0
bl702+wifi FLASH 837050 837050 0 0.0
RAM 124517 124517 0 0.0
bl706+mfd+rpc+littlefs FLASH 1070974 1070974 0 0.0
RAM 117389 117389 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903548 903548 0 0.0
RAM 105964 105964 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983620 983620 0 0.0
RAM 109884 109884 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771284 771284 0 0.0
RAM 103408 103408 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784320 784320 0 0.0
RAM 108736 108736 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729456 729456 0 0.0
RAM 97484 97484 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 714032 714032 0 0.0
RAM 97692 97692 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555340 555340 0 0.0
RAM 205496 205496 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589224 589224 0 0.0
RAM 205752 205752 0 0.0
efr32 lock-app BRD4187C FLASH 967504 967496 -8 -0.0
RAM 125704 125704 0 0.0
BRD4338a FLASH 761332 761332 0 0.0
RAM 237968 237968 0 0.0
window-app BRD4187C FLASH 1063848 1063840 -8 -0.0
RAM 126828 126828 0 0.0
esp32 all-clusters-app c3devkit DRAM 98204 98204 0 0.0
FLASH 1584468 1584460 -8 -0.0
IRAM 93514 93514 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 935932 935928 -4 -0.0
RAM 161974 161974 0 0.0
nxp contact mcxw71+release FLASH 744632 744632 0 0.0
RAM 67152 67152 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1696244 1696236 -8 -0.0
RAM 214484 214484 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597300 1597300 0 0.0
RAM 211476 211476 0 0.0
light cy8ckit_062s2_43012 FLASH 1460940 1460940 0 0.0
RAM 197808 197808 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495044 1495044 0 0.0
RAM 225688 225688 0 0.0
qpg lighting-app qpg6200+debug FLASH 838716 838716 0 0.0
RAM 128032 128032 0 0.0
lock-app qpg6200+debug FLASH 777164 777164 0 0.0
RAM 118972 118972 0 0.0
realtek light-switch-app rtl8777g FLASH 701992 701992 0 0.0
RAM 113548 113548 0 0.0
lighting-app rtl8777g FLASH 743872 743872 0 0.0
RAM 114768 114768 0 0.0
stm32 light STM32WB5MM-DK FLASH 470804 470804 0 0.0
RAM 141408 141408 0 0.0
telink bridge-app tl7218x FLASH 711642 711642 0 0.0
RAM 93088 93088 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 797432 797432 0 0.0
RAM 41272 41272 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 788762 788762 0 0.0
RAM 96172 96172 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 717432 717432 0 0.0
RAM 54264 54264 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 753242 753242 0 0.0
RAM 73288 73288 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 721814 721814 0 0.0
RAM 34992 34992 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 609728 609728 0 0.0
RAM 117960 117960 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 822266 822270 4 0.0
RAM 94560 94560 0 0.0

@mergify mergify Bot merged commit 29da34c into project-chip:master Jan 29, 2026
82 checks passed
@yufengwangca yufengwangca deleted the pr/webrtc/comments branch January 29, 2026 21:47
andy31415 pushed a commit that referenced this pull request Feb 2, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Trivial] Address trivial comments in a follow-up PR.

4 participants