Skip to content

Commit 25be745

Browse files
committed
Refactor resolving output stream format
1 parent 765436a commit 25be745

2 files changed

Lines changed: 9 additions & 18 deletions

File tree

lib/membrane_ffmpeg_swresample_plugin/converter.ex

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,13 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
211211
end
212212

213213
defp resolve_output_stream_format(input_format, output_format) do
214-
%RawAudio{
215-
sample_format:
216-
if(output_format.sample_format == :keep,
217-
do: input_format.sample_format,
218-
else: output_format.sample_format
219-
),
220-
sample_rate:
221-
if(output_format.sample_rate == :keep,
222-
do: input_format.sample_rate,
223-
else: output_format.sample_rate
224-
),
225-
channels:
226-
if(output_format.channels == :keep,
227-
do: input_format.channels,
228-
else: output_format.channels
229-
)
230-
}
214+
overrides =
215+
output_format |> Map.from_struct() |> Map.reject(fn {_key, val} -> val == :keep end)
216+
217+
merged =
218+
input_format |> Map.from_struct() |> Map.merge(overrides)
219+
220+
struct!(RawAudio, merged)
231221
end
232222

233223
defp check_dropped_frames(state) do

test/membrane_ffmpeg_swresample_plugin/converter_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ defmodule Membrane.FFmpeg.SWResample.ConverterTest do
2424
state: %{
2525
input_stream_format: nil,
2626
input_stream_format_provided?: false,
27-
options_output_stream_format: Map.from_struct(@u8_format),
27+
options_output_stream_format:
28+
Map.from_struct(@u8_format) |> then(&struct!(Converter.OutputFormat, &1)),
2829
resolved_output_stream_format: @u8_format,
2930
frames_per_buffer: 2048,
3031
native: nil,

0 commit comments

Comments
 (0)