-
Notifications
You must be signed in to change notification settings - Fork 12
Bump ex_webrtc, set RTP sender codec #21
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7fb93d
Bump ex_webrtc, set RTP sender codec
FelonEkonom 8914fed
Remove leftovers
FelonEkonom 7bffb3b
Bump version to v0.23.3
FelonEkonom 3426497
Implement suggestions from CR
FelonEkonom d9b5252
mix format
FelonEkonom 7c7c66e
Refactor error message
FelonEkonom 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ defmodule Membrane.WebRTC.ExWebRTCSink do | |
| def_input_pad :input, | ||
| accepted_format: Membrane.RTP, | ||
| availability: :on_request, | ||
| options: [kind: []] | ||
| options: [kind: [], codec: [default: nil]] | ||
|
|
||
| @max_rtp_timestamp 2 ** 32 - 1 | ||
| @max_rtp_seq_num 2 ** 16 - 1 | ||
|
|
@@ -114,6 +114,64 @@ defmodule Membrane.WebRTC.ExWebRTCSink do | |
| {[], state} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_start_of_stream(pad, ctx, state) do | ||
| case ctx.pads[pad].options do | ||
| %{kind: :audio} -> | ||
| :ok | ||
|
|
||
| %{kind: :video, codec: nil} -> | ||
| supported_video_codecs = get_video_transceiver(state.pc).codecs | ||
|
|
||
| if length(supported_video_codecs) > 1 do | ||
| Membrane.Logger.warning(""" | ||
| Cannot select expicitly video codec, while various video codecs have been negotiated. \ | ||
| This might be caused be passing `Membrane.RTP` to `Membrane.WebRTC.Sink` and allowing \ | ||
| to negotiate more than one video codec. | ||
|
|
||
| Negotiated video codecs: #{inspect(supported_video_codecs, pretty: true)} | ||
| """) | ||
| end | ||
|
|
||
| :ok | ||
|
|
||
| %{kind: :video, codec: codec} -> | ||
| :ok = set_pc_sender_video_codec(state.pc, codec) | ||
| end | ||
|
|
||
| {[], state} | ||
| end | ||
|
|
||
| defp set_pc_sender_video_codec(pc, codec) when codec in [:vp8, :h264] do | ||
| mime_type = if codec == :vp8, do: "video/VP8", else: "video/H264" | ||
| video_transceiver = get_video_transceiver(pc) | ||
|
|
||
| if video_transceiver == nil do | ||
| raise """ | ||
| Pad with `kind: :video` was linked, but #{inspect(PeerConnection)} doesn't have any video \ | ||
| transceiver. | ||
| """ | ||
| end | ||
|
|
||
| selected_codec = | ||
| video_transceiver.codecs | ||
| |> Enum.find(&(&1.mime_type == mime_type)) | ||
|
|
||
| if selected_codec == nil do | ||
| raise """ | ||
| Cannot select codec #{inspect(codec)} with video transceiver #{inspect(video_transceiver)} | ||
| """ | ||
| end | ||
|
|
||
| :ok = PeerConnection.set_sender_codec(pc, video_transceiver.sender.id, selected_codec) | ||
| end | ||
|
|
||
| defp get_video_transceiver(pc) do | ||
| pc | ||
| |> PeerConnection.get_transceivers() | ||
| |> Enum.find(&(&1.kind == :video)) | ||
| end | ||
|
||
|
|
||
| @impl true | ||
| def handle_buffer(pad, buffer, _ctx, state) do | ||
| state = send_buffer(pad, buffer, state) | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Is this going to fail randomly, like before the fix? Shouldn't we raise here?