Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Refactor comparing manifests in hls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Karolk99 committed Feb 22, 2023
1 parent 8f28ddf commit ce8e1be
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/membrane_rtc_engine/hls_endpoint_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Membrane.RTC.HLSEndpointTest do

@fixtures_dir "./test/fixtures/"
@reference_dir "./test/hls_reference/"
@main_manifest "index.m3u8"
@accaptable_bandwidth_diff 100_000

setup do
options = [
Expand Down Expand Up @@ -508,7 +510,10 @@ defmodule Membrane.RTC.HLSEndpointTest do

defp check_correctness_of_output_files(output_dir, reference_dir) do
output_files = output_dir |> File.ls!() |> Enum.sort()
output_manifests = Enum.filter(output_files, &String.match?(&1, ~r/\.m3u8$/))

output_manifests =
Enum.filter(output_files, &String.match?(&1, ~r/\.m3u8$/))
|> Enum.filter(&(&1 != @main_manifest))

for manifest <- output_manifests do
manifest_path = Path.join(output_dir, manifest)
Expand All @@ -517,6 +522,8 @@ defmodule Membrane.RTC.HLSEndpointTest do
assert File.read!(manifest_path) == File.read!(reference_path)
end

compare_main_manifests(output_dir, reference_dir)

reference_files = reference_dir |> File.ls!() |> Enum.sort()
assert output_files == reference_files

Expand All @@ -526,4 +533,35 @@ defmodule Membrane.RTC.HLSEndpointTest do
assert size > 0
end
end

defp compare_main_manifests(output_dir, reference_dir) do
output_file = Path.join(output_dir, @main_manifest) |> File.read!()
reference_file = Path.join(reference_dir, @main_manifest) |> File.read!()

%{
bandwidth: ["#EXT-X-STREAM-INF:BANDWIDTH=" <> output_bandwidth],
other: output_without_bandwidth
} = filter_manifest(output_file)

%{
bandwidth: ["#EXT-X-STREAM-INF:BANDWIDTH=" <> reference_bandwidth],
other: reference_without_bandwidth
} = filter_manifest(reference_file)

output_bandwidth = String.to_integer(output_bandwidth)
reference_bandwidth = String.to_integer(reference_bandwidth)

assert output_bandwidth + @accaptable_bandwidth_diff > reference_bandwidth and
output_bandwidth < reference_bandwidth + @accaptable_bandwidth_diff

assert output_without_bandwidth == reference_without_bandwidth
end

defp filter_manifest(index_file) do
index_file
|> String.split(["\n", ","])
|> Enum.group_by(fn x ->
if String.starts_with?(x, "#EXT-X-STREAM-INF:"), do: :bandwidth, else: :other
end)
end
end

0 comments on commit ce8e1be

Please sign in to comment.