-
Notifications
You must be signed in to change notification settings - Fork 14
[RTC-32] Fetch actual bitrate of a variant #229
Conversation
…ndwidth through it
Codecov Report
@@ 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
Continue to review full report in Codecov by Sentry.
|
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 ( |
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bits per second
|> Enum.filter(&Map.has_key?(variant_bitrates, to_rid(&1))) | ||
|> Enum.map(&{&1, Map.get(variant_bitrates, to_rid(&1))}) | ||
|> Map.new() |
There was a problem hiding this comment.
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?
|> 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)) |
There was a problem hiding this comment.
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.
}, | ||
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), |
There was a problem hiding this comment.
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
Co-authored-by: Daniel Jodłoś <daniel.jodlos@swmansion.com>
TODO: