-
Notifications
You must be signed in to change notification settings - Fork 0
/
scribe_endpoint_test.exs
100 lines (79 loc) · 2.58 KB
/
scribe_endpoint_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
defmodule Membrane.RTC.ScribeEndpointTest do
use ExUnit.Case
alias ExSDP.Attribute.FMTP
alias Membrane.RTC.Engine
alias Membrane.RTC.Engine.Endpoint
alias Membrane.RTC.Engine.Message
alias Membrane.Testing
@fixtures_dir "./test/fixtures/audio"
setup do
options = [id: "test_rtc"]
{:ok, pid} = Engine.start_link(options, [])
Engine.register(pid, self())
on_exit(fn -> Engine.terminate(pid) end)
[rtc_engine: pid]
end
@sink_endpoint_id "sink-endpoint-id"
@scribe_endpoint_id "scribe-endpoint-id"
describe "Scribe Endpoint test" do
test "adding the endpoint", %{rtc_engine: rtc_engine} do
scribe_endpoint = %Endpoint.Scribe{
rtc_engine: rtc_engine
}
:ok = Engine.add_endpoint(rtc_engine, scribe_endpoint, id: @scribe_endpoint_id)
assert_receive %Message.EndpointAdded{endpoint_id: @scribe_endpoint_id}, 25_000
Process.sleep(10_000)
add_audio_files(rtc_engine, files: ["female.aac"])
end
end
defp add_audio_files(rtc_engine, files: files) do
Enum.each(files, fn file ->
endpoint_id = "endpoint-#{file}"
file_path = Path.join(@fixtures_dir, file)
file_endpoint = create_audio_endpoint(rtc_engine, file_path)
:ok = Engine.add_endpoint(rtc_engine, file_endpoint, id: endpoint_id)
assert_receive %Message.EndpointAdded{endpoint_id: endpoint_id}, 25_000
assert_receive %Message.EndpointMessage{
endpoint_id: endpoint_id,
message: :tracks_added
},
25_000
assert_receive %Message.EndpointMessage{
message: :tracks_subscribed
},
25_000
end)
end
defp create_audio_endpoint(
rtc_engine,
path
) do
ext = String.split(path, ".") |> List.last()
audio_track_config = %Endpoint.File.TrackConfig{
type: :audio,
encoding: :OPUS,
clock_rate: 48_000,
fmtp: %FMTP{
pt: 108
}
}
%Endpoint.File{
rtc_engine: rtc_engine,
file_path: path,
track_config: audio_track_config,
payload_type: 108,
playback_mode: :autoplay,
after_source_transformation: fn link_builder ->
link_builder
|> Membrane.ChildrenSpec.child(:decoder, Membrane.AAC.FDK.Decoder)
|> Membrane.ChildrenSpec.child(:encoder, %Membrane.Opus.Encoder{
input_stream_format: %Membrane.RawAudio{
channels: 1,
sample_rate: 48_000,
sample_format: :s16le
}
})
end
}
end
end