Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

[RTC-32] Fetch actual bitrate of a variant #229

Merged
merged 31 commits into from
Mar 29, 2023

Conversation

LVala
Copy link
Contributor

@LVala LVala commented Jan 25, 2023

TODO:

  • fix integrations tests (js sdk from this pr required)
  • update media event docs

@LVala LVala self-assigned this Jan 25, 2023
@codecov
Copy link

codecov bot commented Jan 25, 2023

Codecov Report

Merging #229 (c20f387) into master (5136fd8) will increase coverage by 0.46%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   57.73%   58.20%   +0.46%     
==========================================
  Files          40       40              
  Lines        1791     1823      +32     
==========================================
+ Hits         1034     1061      +27     
- Misses        757      762       +5     
Impacted Files Coverage Δ
...rane_rtc_engine/endpoints/webrtc/track_receiver.ex 49.45% <0.00%> (-1.12%) ⬇️
...b/membrane_rtc_engine/endpoints/webrtc_endpoint.ex 0.00% <0.00%> (ø)
...embrane_rtc_engine/endpoints/webrtc/media_event.ex 24.24% <90.00%> (+18.88%) ⬆️
...mbrane_rtc_engine/endpoints/webrtc/track_sender.ex 73.83% <100.00%> (+2.40%) ⬆️
...ne_rtc_engine/endpoints/webrtc/variant_selector.ex 84.84% <100.00%> (+0.23%) ⬆️
lib/membrane_rtc_engine/tees/tee.ex 87.95% <100.00%> (+0.45%) ⬆️

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 5136fd8...c20f387. Read the comment docs.

@LVala
Copy link
Contributor Author

LVala commented Jan 25, 2023

I think this PR is ready for review except for the thing I mentioned above, also I was wondering whether I should add some more tests (webrtc_endpoint.ex specifically, even tho there's no tests for this file at the moment).

@LVala LVala marked this pull request as ready for review January 25, 2023 13:44
@LVala LVala requested a review from mickel8 as a code owner January 25, 2023 13:44
@@ -266,22 +289,45 @@ defmodule Membrane.RTC.Engine.Endpoint.WebRTC.MediaEvent do
"type" => "offer",
"sdp" => sdp
},
"trackIdToTrackMetadata" => track_id_to_track_metadata,
"midToTrackId" => mid_to_track_id
"trackIdToTrackInfo" => track_id_to_track_info
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to maintain backward compatibility. So, unfortunately, this change can't go in like that. I would recommend just going with the flow and adding another key to that object - if it's missing, I would simply generate a sensible default value, so that older clients can still connect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the refactor, I think I would skip it for now, as we will be moving to protocol buffers and we'll fix it then - it's just not worth it to mess with it right now

"""
@spec update_variant_bitrate(t(), Track.variant(), non_neg_integer()) :: t()
def update_variant_bitrate(%__MODULE__{} = selector, variant, bitrate) do
variant_bitrates = %{selector.variant_bitrates | variant => bitrate * 1024}
Copy link
Contributor

Choose a reason for hiding this comment

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

On the FE you divide bitrate by 1024 - these operations cancel each other out

@spec update_variant_bitrate(t(), Track.variant(), non_neg_integer()) :: t()
def update_variant_bitrate(%__MODULE__{} = selector, variant, bitrate) do
variant_bitrates = %{selector.variant_bitrates | variant => bitrate * 1024}
%{selector | variant_bitrates: variant_bitrates}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not enough. You need to update an allocation, if you received an update about the currently selected or queued variant, or update requested bitrate if this affects your next_desired_variant

@@ -142,6 +142,19 @@ defmodule Membrane.RTC.Engine.Endpoint.WebRTC.VariantSelector do
}
end

# TODO bytes per second or bits per second
Copy link
Contributor

Choose a reason for hiding this comment

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

bits per second

Comment on lines 938 to 940
|> Enum.filter(&Map.has_key?(variant_bitrates, to_rid(&1)))
|> Enum.map(&{&1, Map.get(variant_bitrates, to_rid(&1))})
|> Map.new()
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be easier to go the other way around with rids?

Suggested change
|> Enum.filter(&Map.has_key?(variant_bitrates, to_rid(&1)))
|> Enum.map(&{&1, Map.get(variant_bitrates, to_rid(&1))})
|> Map.new()
Map.new(variant_bitrates, fn {rid_str, bitrate} -> {to_track_variant(rid_str), bitrate} end)

@@ -703,6 +703,7 @@ defmodule Membrane.RTC.Engine.Endpoint.WebRTC do
def handle_pad_added(Pad.ref(:output, {track_id, variant}) = pad, _ctx, state) do
%Track{encoding: encoding} = track = Map.get(state.inbound_tracks, track_id)
extensions = Map.get(state.extensions, encoding, []) ++ Map.get(state.extensions, :any, [])
variant_bitrates = to_track_variants(track, Map.get(state.track_id_to_bitrates, track_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would use Map.fetch! to get a better error if we happen to not have this information in the state for whatever reason.

@LVala LVala requested a review from daniel-jodlos March 22, 2023 09:32
},
track_id_to_track_metadata: track_id_to_track_metadata,
# use default values in VariantSelector if "trackIdToTrackBitrates" is not present
track_id_to_track_bitrates: Map.merge(default_bitrates, bitrates),
Copy link
Contributor

Choose a reason for hiding this comment

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

Because of the merge, the server could in theory accept an invalid media event, with non exhaustive track_id_to_track_bitrates mapping

@LVala LVala requested a review from daniel-jodlos March 24, 2023 12:51
Co-authored-by: Daniel Jodłoś <daniel.jodlos@swmansion.com>
@LVala LVala merged commit 976e456 into master Mar 29, 2023
@LVala LVala deleted the fetch-bitrate-of-simulcast-variant branch March 29, 2023 12:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants