-
Notifications
You must be signed in to change notification settings - Fork 15
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
Create transceivers on set_remote_description #2
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule ExWebRTC.MediaStreamTrack do | ||
@moduledoc """ | ||
MediaStreamTrack | ||
""" | ||
|
||
@type t() :: %__MODULE__{ | ||
kind: :audio | :video, | ||
id: integer(), | ||
mid: String.t() | ||
} | ||
|
||
@enforce_keys [:id, :kind] | ||
defstruct @enforce_keys ++ [:mid] | ||
|
||
def from_transceiver(tr) do | ||
%__MODULE__{kind: tr.kind, id: generate_id(), mid: tr.mid} | ||
end | ||
|
||
defp generate_id() do | ||
<<id::12*8>> = :crypto.strong_rand_bytes(12) | ||
id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule ExWebRTC.RTPTransceiver do | ||
LVala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@moduledoc """ | ||
RTPTransceiver | ||
""" | ||
|
||
@type t() :: %__MODULE__{ | ||
mid: String.t(), | ||
direction: :sendonly | :recvonly | :sendrecv | :inactive | :stopped, | ||
kind: :audio | :video | ||
} | ||
|
||
@enforce_keys [:mid, :direction, :kind] | ||
defstruct @enforce_keys | ||
|
||
@doc false | ||
def find_by_mid(transceivers, mid) do | ||
transceivers | ||
|> Enum.with_index(fn tr, idx -> {idx, tr} end) | ||
|> Enum.find(fn {_idx, tr} -> tr.mid == mid end) | ||
end | ||
|
||
# searches for transceiver for a given mline | ||
# if it exists, updates its configuration | ||
# if it doesn't exist, creats a new one | ||
# returns list of updated transceivers | ||
@doc false | ||
def update_or_create(transceivers, mid, mline) do | ||
case find_by_mid(transceivers, mid) do | ||
{idx, %__MODULE__{} = tr} -> | ||
List.replace_at(transceivers, idx, update(tr, mline)) | ||
|
||
nil -> | ||
transceivers ++ [%__MODULE__{mid: mid, direction: :recvonly, kind: mline.type}] | ||
end | ||
end | ||
|
||
defp update(transceiver, _mline), do: transceiver | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
defmodule ExWebRTC.PeerConnectionTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExWebRTC.{MediaStreamTrack, PeerConnection, SessionDescription} | ||
|
||
@single_audio_offer """ | ||
v=0 | ||
o=- 6788894006044524728 2 IN IP4 127.0.0.1 | ||
s=- | ||
t=0 0 | ||
a=group:BUNDLE 0 | ||
a=extmap-allow-mixed | ||
a=msid-semantic: WMS | ||
m=audio 9 UDP/TLS/RTP/SAVPF 111 | ||
c=IN IP4 0.0.0.0 | ||
a=rtcp:9 IN IP4 0.0.0.0 | ||
a=ice-ufrag:cDua | ||
a=ice-pwd:v9SCmZHxJWtgpyzn8Ts1puT6 | ||
a=ice-options:trickle | ||
a=fingerprint:sha-256 11:35:68:66:A4:C3:C0:AA:37:4E:0F:97:D7:9F:76:11:08:DB:56:DA:4B:83:77:50:9A:D2:71:8D:2A:A8:E3:07 | ||
a=setup:actpass | ||
a=mid:0 | ||
a=sendrecv | ||
a=msid:- 54f0751b-086f-433c-af40-79c179182423 | ||
a=rtcp-mux | ||
a=rtpmap:111 opus/48000/2 | ||
a=rtcp-fb:111 transport-cc | ||
a=fmtp:111 minptime=10;useinbandfec=1 | ||
a=ssrc:1463342914 cname:poWwjNZ4I2ZZgzY7 | ||
a=ssrc:1463342914 msid:- 54f0751b-086f-433c-af40-79c179182423 | ||
""" | ||
|
||
@audio_video_offer """ | ||
v=0 | ||
o=- 3253533641493747086 5 IN IP4 127.0.0.1 | ||
s=- | ||
t=0 0 | ||
a=group:BUNDLE 0 1 | ||
a=extmap-allow-mixed | ||
a=msid-semantic: WMS | ||
m=audio 9 UDP/TLS/RTP/SAVPF 111 | ||
c=IN IP4 0.0.0.0 | ||
a=rtcp:9 IN IP4 0.0.0.0 | ||
a=ice-ufrag:SOct | ||
a=ice-pwd:k9PRXt7zT32ADt/juUpt4Gx3 | ||
a=ice-options:trickle | ||
a=fingerprint:sha-256 45:B5:2D:3A:DA:29:93:27:B6:59:F1:5B:77:62:F5:C2:CE:16:8B:12:C7:B8:34:EF:C0:12:45:17:D0:1A:E6:F4 | ||
a=setup:actpass | ||
a=mid:0 | ||
a=sendrecv | ||
a=msid:- 0970fb0b-4750-4302-902e-70d2e403ad0d | ||
a=rtcp-mux | ||
a=rtpmap:111 opus/48000/2 | ||
a=rtcp-fb:111 transport-cc | ||
a=fmtp:111 minptime=10;useinbandfec=1 | ||
a=ssrc:560549895 cname:QQJypppcjR+gR484 | ||
a=ssrc:560549895 msid:- 0970fb0b-4750-4302-902e-70d2e403ad0d | ||
m=video 9 UDP/TLS/RTP/SAVPF 96 | ||
c=IN IP4 0.0.0.0 | ||
a=rtcp:9 IN IP4 0.0.0.0 | ||
a=ice-ufrag:SOct | ||
a=ice-pwd:k9PRXt7zT32ADt/juUpt4Gx3 | ||
a=ice-options:trickle | ||
a=fingerprint:sha-256 45:B5:2D:3A:DA:29:93:27:B6:59:F1:5B:77:62:F5:C2:CE:16:8B:12:C7:B8:34:EF:C0:12:45:17:D0:1A:E6:F4 | ||
a=setup:actpass | ||
a=mid:1 | ||
a=sendrecv | ||
a=msid:- 1259ea70-c6b7-445a-9c20-49cec7433ccb | ||
a=rtcp-mux | ||
a=rtcp-rsize | ||
a=rtpmap:96 VP8/90000 | ||
a=rtcp-fb:96 goog-remb | ||
a=rtcp-fb:96 transport-cc | ||
a=rtcp-fb:96 ccm fir | ||
a=rtcp-fb:96 nack | ||
a=rtcp-fb:96 nack pli | ||
a=ssrc-group:FID 381060598 184440407 | ||
a=ssrc:381060598 cname:QQJypppcjR+gR484 | ||
a=ssrc:381060598 msid:- 1259ea70-c6b7-445a-9c20-49cec7433ccb | ||
a=ssrc:184440407 cname:QQJypppcjR+gR484 | ||
a=ssrc:184440407 msid:- 1259ea70-c6b7-445a-9c20-49cec7433ccb | ||
""" | ||
|
||
test "transceivers" do | ||
{:ok, pc} = PeerConnection.start_link() | ||
|
||
offer = %SessionDescription{type: :offer, sdp: @single_audio_offer} | ||
:ok = PeerConnection.set_remote_description(pc, offer) | ||
|
||
assert_receive {:ex_webrtc, ^pc, {:track, %MediaStreamTrack{mid: "0", kind: :audio}}} | ||
|
||
offer = %SessionDescription{type: :offer, sdp: @audio_video_offer} | ||
:ok = PeerConnection.set_remote_description(pc, offer) | ||
|
||
assert_receive {:ex_webrtc, ^pc, {:track, %MediaStreamTrack{mid: "1", kind: :video}}} | ||
refute_receive {:ex_webrtc, ^pc, {:track, %MediaStreamTrack{}}} | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 suppose you know that and this is only temporary, but I believe this notification should appear when only tracks are negotiated.
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.
Now we accept everything :D