Skip to content

Conversation

@Brazol
Copy link
Contributor

@Brazol Brazol commented Aug 19, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an Android initialization crash that occurred with certain audio configurations.
    • Improved video layer selection to choose the best available base layer, enhancing reliability and quality in variable network conditions.
  • Refactor
    • Streamlined internal video encoding selection logic for more consistent behavior across devices.
  • Chores
    • No changes to public APIs.

@Brazol Brazol requested a review from a team as a code owner August 19, 2025 07:21
@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Conditionalizes androidAudioConfiguration usage in Android WebRTC initialization to avoid null dereference. Revises SVC encodings generation to select the highest available base layer among f, h, q and emit a single encoding mapped to rid 'q' with copied parameters.

Changes

Cohort / File(s) Summary
Android init null-guard
packages/stream_video/lib/src/stream_video.dart
Adds a null check so androidAudioConfiguration is passed to rtc.WebRTC.initialize only when non-null on Android; iOS path unchanged; no API changes.
SVC encoding selection logic
packages/stream_video/lib/src/webrtc/rtc_manager.dart
Reworks toSvcEncodings: introduces helper to find layer by rid, selects highest available among f→h→q, returns single encoding with rid 'q' copying fields from selected layer; includes null/empty handling; no API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant StreamVideo
  participant WebRTC

  App->>StreamVideo: new StreamVideo(options)
  alt Platform == Android
    alt options.androidAudioConfiguration != null
      StreamVideo->>WebRTC: initialize({ androidAudioConfiguration })
    else androidAudioConfiguration is null
      StreamVideo->>WebRTC: initialize({})
    end
  else Platform == iOS
    StreamVideo->>WebRTC: initialize(iOS options)
  end
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant RtcManager
  participant LayerHelper as findLayerByRid()

  Caller->>RtcManager: toSvcEncodings(layers)
  RtcManager->>LayerHelper: find 'f'
  alt 'f' not found
    RtcManager->>LayerHelper: find 'h'
    alt 'h' not found
      RtcManager->>LayerHelper: find 'q'
      alt none found
        RtcManager-->>Caller: []
      else 'q' found
        RtcManager-->>Caller: [encoding rid 'q' from 'q']
      end
    else 'h' found
      RtcManager-->>Caller: [encoding rid 'q' from 'h']
    end
  else 'f' found
    RtcManager-->>Caller: [encoding rid 'q' from 'f']
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • xsahil03x

Poem

I twitch my ears at layers three,
From f to h to q, I see—
I pick the highest, hop with glee,
And guard null fields on Android, whee!
Encodings neat, initialization sweet—
A rabbit’s job is now complete. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/minor-code-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/stream_video/lib/src/webrtc/rtc_manager.dart (1)

761-784: SVC encoding: add fallback for rid-less inputs and simplify lookup

Current logic assumes rids among {'f','h','q'}. If upstream returns encodings without rids (or different labels), toSvcEncodings returns an empty list, delegating defaults to the engine. Consider a small robustness bump:

  • Use firstWhereOrNull to simplify findByRid.
  • Fall back to layers.firstOrNull if none of f/h/q are present to still honor upstream bitrate/framerate/scalabilityMode decisions.

Proposed diff:

   List<rtc.RTCRtpEncoding> toSvcEncodings(List<rtc.RTCRtpEncoding> layers) {
-    rtc.RTCRtpEncoding? findByRid(String rid) {
-      for (final layer in layers) {
-        if (layer.rid == rid) return layer;
-      }
-      return null;
-    }
-
-    final highestLayer = findByRid('f') ?? findByRid('h') ?? findByRid('q');
-    if (highestLayer == null) return [];
+    rtc.RTCRtpEncoding? findByRid(String rid) =>
+        layers.firstWhereOrNull((e) => e.rid == rid);
+
+    // Prefer full > half > quarter; if no known rid present, use the first layer as a best-effort fallback.
+    final highestLayer =
+        findByRid('f') ?? findByRid('h') ?? findByRid('q') ?? layers.firstOrNull;
+    if (highestLayer == null) return [];
 
     return [
       rtc.RTCRtpEncoding(
         rid: 'q',
         active: highestLayer.active,
         maxBitrate: highestLayer.maxBitrate,
         maxFramerate: highestLayer.maxFramerate,
         minBitrate: highestLayer.minBitrate,
         numTemporalLayers: highestLayer.numTemporalLayers,
         scaleResolutionDownBy: highestLayer.scaleResolutionDownBy,
         ssrc: highestLayer.ssrc,
         scalabilityMode: highestLayer.scalabilityMode,
       )
     ];
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4824444 and c606c99.

📒 Files selected for processing (2)
  • packages/stream_video/lib/src/stream_video.dart (1 hunks)
  • packages/stream_video/lib/src/webrtc/rtc_manager.dart (1 hunks)
🔇 Additional comments (2)
packages/stream_video/lib/src/stream_video.dart (1)

183-187: Null-safe Android audio config injection looks correct

Conditionalizing androidAudioConfiguration on both Android platform and non-null value avoids the previous null dereference while keeping iOS/other platforms unaffected. Good defensive fix.

packages/stream_video/lib/src/webrtc/rtc_manager.dart (1)

761-784: Fallback logic validated
Verified that findOptimalVideoLayers only ever emits rid values from ['f', 'h', 'q'], so the findByRid('f') ?? findByRid('h') ?? findByRid('q') fallback always covers the highest available layer. No changes needed.

@codecov
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 4.83%. Comparing base (4824444) to head (c606c99).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...kages/stream_video/lib/src/webrtc/rtc_manager.dart 0.00% 15 Missing ⚠️
packages/stream_video/lib/src/stream_video.dart 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1051      +/-   ##
========================================
- Coverage   4.83%   4.83%   -0.01%     
========================================
  Files        577     577              
  Lines      38826   38830       +4     
========================================
  Hits        1877    1877              
- Misses     36949   36953       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Brazol Brazol merged commit 2a65574 into main Aug 19, 2025
12 of 15 checks passed
@Brazol Brazol deleted the fix/minor-code-fixes branch August 19, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants