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

Add add_track/2 function to API #38

Merged
merged 6 commits into from
Dec 14, 2023
Merged

Add add_track/2 function to API #38

merged 6 commits into from
Dec 14, 2023

Conversation

LVala
Copy link
Member

@LVala LVala commented Dec 13, 2023

Additionally, I made the echo example to use add_track/2.

@LVala LVala self-assigned this Dec 13, 2023
Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Merging #38 (838ada2) into master (792184e) will increase coverage by 1.13%.
The diff coverage is 91.89%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage   85.59%   86.72%   +1.13%     
==========================================
  Files          14       14              
  Lines         611      633      +22     
==========================================
+ Hits          523      549      +26     
+ Misses         88       84       -4     
Files Coverage Δ
lib/ex_webrtc/rtp_sender.ex 100.00% <100.00%> (ø)
lib/ex_webrtc/rtp_transceiver.ex 91.80% <91.66%> (-0.20%) ⬇️
lib/ex_webrtc/peer_connection.ex 84.55% <90.47%> (+2.62%) ⬆️

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 792184e...838ada2. Read the comment docs.

@LVala LVala requested a review from mickel8 December 13, 2023 12:49
@LVala LVala marked this pull request as ready for review December 13, 2023 12:49
Copy link
Member

@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.

I would once again discuss whether we always want to create sender and receiver.

  • now we might end up with different codecs in transceiver and sender
  • I don't see any benefits of creating sender and receiver no matter what the direction is

Even if we decide to change the current behavior, I would do this in next PRs

{:ok, offer} = PeerConnection.create_offer(pc)
:ok = PeerConnection.set_local_description(pc, offer)
dbg(PeerConnection.get_transceivers(pc))
Copy link
Member

Choose a reason for hiding this comment

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

Leftover

%RTPTransceiver{
kind: ^kind,
sender: %RTPSender{track: nil},
current_direction: cr
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick but I am a little bit afraid of too many very short variable names:

  • it's hard to ctrl+f on them
  • at some point we might end up with a code that is hard to read e.g. cr, tr, ix
  • I am perfectly fine though with using those short names when the full name is very long and used very often. E.g. in our code base we very often use tr as a shortcut from transceiver and that's okay because it's common and appears in a lot of places. But when possible and it doesn't have an impact on the line length (i.e. formatter doesn't add a new line because of its length) I would favor a little bit longer names e.g. current_direction current_dir curr_dir or just direction. IMO direction is good enough as we use it in a very small context (two lines below)

Copy link
Member Author

Choose a reason for hiding this comment

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

I only use short variable names for guards, otherwise, guards get horribly long and usually these variables aren used anywhere else, and if they are, more verbose names make sense. Here that's not really an issue, as the guards are split into multiple lines, but overall, I'm fine with either option.

tr = RTPTransceiver.new(kind, track, state.config, direction: :sendrecv)
{state.transceivers ++ [tr], tr.sender}

ix ->
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ix ->
idx ->

@impl true
def handle_call({:add_track, %MediaStreamTrack{kind: kind} = track}, _from, state) do
# we ignore the condition that sender has never been used to send
free_transceiver =
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick but that's not really a transceiver

Suggested change
free_transceiver =
free_transceiver_idx =

or

Suggested change
free_transceiver =
tr_idx =

@@ -23,20 +23,33 @@ defmodule ExWebRTC.RTPSender do

@doc false
@spec new(MediaStreamTrack.t() | nil, RTPCodecParameters.t(), [Extmap.t()]) :: t()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@spec new(MediaStreamTrack.t() | nil, RTPCodecParameters.t(), [Extmap.t()]) :: t()
@spec new(MediaStreamTrack.t() | nil, RTPCodecParameters.t() | nil, [Extmap.t()]) :: t()

]

@doc false
def new(kind, sender_track, config, options) do
Copy link
Member

Choose a reason for hiding this comment

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

Let's always add specs for public functions

test/ex_webrtc/peer_connection_test.exs Show resolved Hide resolved
@LVala LVala merged commit 604ba89 into master Dec 14, 2023
4 checks passed
@LVala LVala deleted the add-track branch December 14, 2023 08:51
@mickel8 mickel8 mentioned this pull request Dec 14, 2023
54 tasks
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.

2 participants