-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic dispatch for (de)payloaders (#152)
- Loading branch information
Showing
6 changed files
with
172 additions
and
16 deletions.
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
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,44 @@ | ||
defmodule ExWebRTC.RTP.DepayloaderTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExWebRTC.RTPCodecParameters | ||
alias ExWebRTC.RTP.Depayloader | ||
alias ExWebRTC.RTP.{Opus, VP8} | ||
|
||
@packet %ExRTP.Packet{ | ||
payload_type: 96, | ||
sequence_number: 0, | ||
timestamp: 0, | ||
ssrc: 0, | ||
payload: <<0, 1, 2, 3>> | ||
} | ||
|
||
test "creates a VP8 depayloader and dispatches calls to its module" do | ||
assert {:ok, depayloader} = | ||
%RTPCodecParameters{payload_type: 96, mime_type: "video/VP8", clock_rate: 90_000} | ||
|> Depayloader.new() | ||
|
||
assert Depayloader.depayload(depayloader, @packet) == | ||
VP8.Depayloader.depayload(depayloader, @packet) | ||
end | ||
|
||
test "creates an Opus depayloader and dispatches calls to its module" do | ||
assert {:ok, depayloader} = | ||
%RTPCodecParameters{ | ||
payload_type: 96, | ||
mime_type: "audio/opus", | ||
clock_rate: 48_000, | ||
channels: 2 | ||
} | ||
|> Depayloader.new() | ||
|
||
assert Depayloader.depayload(depayloader, @packet) == | ||
Opus.Depayloader.depayload(depayloader, @packet) | ||
end | ||
|
||
test "returns error if no depayloader exists for given codec" do | ||
assert {:error, :no_depayloader_for_codec} = | ||
%RTPCodecParameters{payload_type: 97, mime_type: "video/H264", clock_rate: 90_000} | ||
|> Depayloader.new() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule ExWebRTC.RTP.PayloaderTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExWebRTC.RTPCodecParameters | ||
alias ExWebRTC.RTP.Payloader | ||
alias ExWebRTC.RTP.{Opus, VP8} | ||
|
||
@frame <<0, 1, 2, 3>> | ||
|
||
test "creates a VP8 payloader and dispatches calls to its module" do | ||
assert {:ok, _payloader} = | ||
%RTPCodecParameters{payload_type: 96, mime_type: "video/VP8", clock_rate: 90_000} | ||
|> Payloader.new() | ||
|
||
# with options | ||
assert {:ok, payloader} = | ||
%RTPCodecParameters{payload_type: 96, mime_type: "video/VP8", clock_rate: 90_000} | ||
|> Payloader.new(800) | ||
|
||
assert Payloader.payload(payloader, @frame) == VP8.Payloader.payload(payloader, @frame) | ||
end | ||
|
||
test "creates an Opus payloader and dispatches calls to its module" do | ||
assert {:ok, payloader} = | ||
%RTPCodecParameters{ | ||
payload_type: 111, | ||
mime_type: "audio/opus", | ||
clock_rate: 48_000, | ||
channels: 2 | ||
} | ||
|> Payloader.new() | ||
|
||
assert Payloader.payload(payloader, @frame) == Opus.Payloader.payload(payloader, @frame) | ||
end | ||
|
||
test "returns error if no payloader exists for given codec" do | ||
assert {:error, :no_payloader_for_codec} = | ||
%RTPCodecParameters{payload_type: 97, mime_type: "video/H264", clock_rate: 90_000} | ||
|> Payloader.new() | ||
end | ||
end |