Skip to content
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

[RTC-477] Allow for muting tracks without renegotiation #392

Merged
merged 10 commits into from
May 25, 2024

Conversation

roznawsk
Copy link
Member

@roznawsk roznawsk commented May 13, 2024

This allows for explicitly muting and then unmuting tracks.

The flow is as follows:

  1. Send mute event from frontend AND replace the track with null so no data is sent.

This is how it looks like on the FE:

webrtc.replaceTrack(videoStreamIdRef.current, null, null, "mute");

const mediaEvent = generateMediaEvent("muteTrack", { trackId: trackId });
this.sendMediaEvent(mediaEvent);

The above is POC, and will probably end up with a dedicated function in membrane-webrtc-js.

  1. The mute event is handled by TrackSender which sends %TrackVariantPaused{reason: :muted} events.
  2. Upon receiving this events the TrackReceiver marks the currently active variant as muted_variant
  3. The unmute event is sent from FE as well as the track being replaced with an actual video
  4. The TrackSender sends TrackVariantResumed events to TrackReceiver
  5. The VariantSelector within TrackReceiver requests the last paused variant, ignoring the limitation of the bandwidth, which at this point is probably 0.

I don't think that setting muted variant as inactive is possible. That's because both when switching to muted and inactive state we check whether the variant is in the active state first.

Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 38.46154% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 54.89%. Comparing base (acc80de) to head (d7c54c8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
- Coverage   55.19%   54.89%   -0.31%     
==========================================
  Files          75       75              
  Lines        3299     3339      +40     
==========================================
+ Hits         1821     1833      +12     
- Misses       1478     1506      +28     
Files Coverage Δ
webrtc/lib/webrtc/variant_selector.ex 84.72% <100.00%> (+1.38%) ⬆️
webrtc/lib/webrtc/media_event.ex 19.27% <0.00%> (-0.48%) ⬇️
webrtc/lib/webrtc/track_receiver.ex 0.00% <0.00%> (ø)
webrtc/lib/webrtc_endpoint.ex 0.00% <0.00%> (ø)
webrtc/lib/webrtc/variant_tracker.ex 70.00% <0.00%> (-25.46%) ⬇️
webrtc/lib/webrtc/track_sender.ex 63.49% <5.26%> (-9.66%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update acc80de...d7c54c8. Read the comment docs.

@roznawsk roznawsk force-pushed the RTC-477-mute-tracks branch 3 times, most recently from edd670f to 4df211a Compare May 13, 2024 15:08
@roznawsk roznawsk marked this pull request as ready for review May 13, 2024 15:14
@@ -41,6 +41,7 @@ defmodule Membrane.RTC.Engine.Integration.MixProject do
{:membrane_rtc_engine_file, path: "../file"},
{:membrane_rtc_engine_sip, path: "../sip"},
{:membrane_rtc_engine_recording, path: "../recording"},
{:membrane_rtc_engine_webrtc, path: "../webrtc", override: true},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need override?

Copy link
Member

Choose a reason for hiding this comment

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

The monorepo structure introduces some problems during the process of releasing our packages. Setting override: true here for packages which other packages depend on (engine, webrtc) helps alleviate some of these issues -- namely, CI will be able to run the tests even if other endpoints are locked onto hex versions of engine and webrtc instead of relative paths. This has virtually no downsides here, in the integration test suite.

You can take a look at /release.sh for some insights into the process of releasing the engine and its endpoints

Copy link
Member

@sgfn sgfn left a comment

Choose a reason for hiding this comment

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

Engine changes LGTM

Copy link
Contributor

@mickel8 mickel8 left a comment

Choose a reason for hiding this comment

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

Could we add PR description? In particular:

  1. How is a track muted on the FE side?
  2. If track is muted, does it send any data?
  3. What do we do with bandwidth estimation when current track is muted? Do we try to keep it on the same level?
  4. Can it happen that muted track becomes inactive?

@type t :: %__MODULE__{variant: Track.variant()}
@type t :: %__MODULE__{
variant: Track.variant(),
reason: :inactive | :muted
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we describe the difference between those two?

Copy link
Member Author

Choose a reason for hiding this comment

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

The track variant can be paused due to two reasons.
:inactive means that VariantTracker has detected reduced or no activity of the variant and has set it to this state
:muted means that we have explicitly paused variant, indicating that the lack of data sent is deliberate and that we may resume it in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but let's write this in docs

webrtc/lib/webrtc/track_sender.ex Outdated Show resolved Hide resolved
webrtc/lib/webrtc/variant_selector.ex Outdated Show resolved Hide resolved
@type t :: %__MODULE__{variant: Track.variant()}
@type t :: %__MODULE__{
variant: Track.variant(),
reason: :inactive | :muted
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but let's write this in docs

@spec variant_inactive(t(), Track.variant()) :: {t(), selector_action_t()}
def variant_inactive(selector, variant) do
@spec variant_paused(t(), Track.variant(), :inactive | :muted) :: {t(), selector_action_t()}
def variant_paused(selector, variant, :inactive) do
Membrane.Logger.debug("Variant inactive #{variant}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Membrane.Logger.debug("Variant inactive #{variant}")
Membrane.Logger.debug("Variant paused #{variant}")

webrtc/lib/webrtc/variant_selector.ex Show resolved Hide resolved
@roznawsk roznawsk requested a review from mickel8 May 23, 2024 09:03
@roznawsk roznawsk merged commit 79d6aa2 into master May 25, 2024
33 checks passed
@roznawsk roznawsk deleted the RTC-477-mute-tracks branch May 25, 2024 09:26
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.

None yet

4 participants