-
Notifications
You must be signed in to change notification settings - Fork 3
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
Negotiate many video codecs #9
Changes from 2 commits
7702977
d0507b9
cd52c0d
2ce1dfe
321ec2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we spoke, let's use the ForwardingFilter, so that it can be easily replaced when we release it |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
defmodule Membrane.WebRTC.Sink.VideoDispatcher do | ||
@moduledoc false | ||
use Membrane.Filter | ||
|
||
alias Membrane.{H264, RemoteStream, VP8} | ||
|
||
def_input_pad :input, accepted_format: any_of(H264, VP8, %RemoteStream{content_format: VP8}) | ||
def_output_pad :h264_output, accepted_format: H264 | ||
def_output_pad :vp8_output, accepted_format: any_of(VP8, %RemoteStream{content_format: VP8}) | ||
|
||
@impl true | ||
def handle_init(ctx, _opts) do | ||
buffered_events = Map.keys(ctx.pads) |> Map.new(&{&1, []}) | ||
{[], %{selected_output_pad: nil, buffered_events: buffered_events}} | ||
end | ||
|
||
@impl true | ||
def handle_stream_format(:input, stream_format, _ctx, state) do | ||
selected_output_pad = | ||
case stream_format do | ||
%H264{} -> :h264_output | ||
%VP8{} -> :vp8_output | ||
%RemoteStream{content_format: VP8} -> :vp8_output | ||
end | ||
|
||
event_actions = | ||
state.buffered_events | ||
|> Enum.flat_map(fn | ||
{_pad, []} -> [] | ||
{:input, events} -> [event: {selected_output_pad, Enum.reverse(events)}] | ||
{^selected_output_pad, events} -> [event: {:input, Enum.reverse(events)}] | ||
{_ignored_output_pad, _events} -> [] | ||
end) | ||
|
||
state = %{state | selected_output_pad: selected_output_pad, buffered_events: %{}} | ||
actions = event_actions ++ [stream_format: {selected_output_pad, stream_format}] | ||
{actions, state} | ||
end | ||
|
||
@impl true | ||
def handle_buffer(:input, buffer, _ctx, state) do | ||
{[buffer: {state.selected_output_pad, buffer}], state} | ||
end | ||
|
||
@impl true | ||
def handle_end_of_stream(:input, _ctx, state) do | ||
{[end_of_stream: :h264_output, end_of_stream: :vp8_output], state} | ||
end | ||
|
||
@impl true | ||
def handle_event(pad, event, _ctx, %{selected_output_pad: nil} = state) do | ||
state = update_in(state, [:buffered_events, pad], &[event | &1]) | ||
{[], state} | ||
end | ||
|
||
@impl true | ||
def handle_event(pad, event, _ctx, %{selected_output_pad: selected_output_pad} = state) do | ||
case pad do | ||
:input -> {[event: {selected_output_pad, event}], state} | ||
^selected_output_pad -> {[event: {:input, event}], state} | ||
_ignored_output_pad -> {[], state} | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,11 +188,16 @@ defmodule Membrane.WebRTC.IntegrationTest do | |
|
||
import Utils | ||
|
||
@tag :dupa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover |
||
@tag :tmp_dir | ||
test "send and receive a file", %{tmp_dir: tmp_dir} do | ||
signaling = SignalingChannel.new() | ||
send_pipeline = Testing.Pipeline.start_link_supervised!() | ||
prepare_input(send_pipeline, webrtc: %WebRTC.Sink{signaling: signaling}) | ||
|
||
prepare_input(send_pipeline, | ||
webrtc: %WebRTC.Sink{signaling: signaling, video_codec: [:vp8, :h264]} | ||
) | ||
|
||
receive_pipeline = Testing.Pipeline.start_link_supervised!() | ||
|
||
prepare_output(receive_pipeline, tmp_dir, webrtc: %WebRTC.Source{signaling: signaling}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ExUnit.start(capture_log: true) | ||
# ExUnit.start() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. letfover |
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.