Skip to content

Commit 4eec10a

Browse files
committed
Apply reviewers suggestions
1 parent ec8ecd0 commit 4eec10a

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

lib/membrane_ffmpeg_swresample_plugin/converter.ex

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
1616
@supported_channels [1, 2]
1717

1818
@type output_stream_format :: %{
19-
sample_format: RawAudio.SampleFormat.t() | :keep,
20-
sample_rate: RawAudio.sample_rate_t() | :keep,
21-
channels: RawAudio.channels_t() | :keep
19+
optional(:sample_format) => RawAudio.SampleFormat.t() | :keep,
20+
optional(:sample_rate) => RawAudio.sample_rate_t() | :keep,
21+
optional(:channels) => RawAudio.channels_t() | :keep
2222
}
2323

2424
def_output_pad :output,
@@ -46,8 +46,8 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
4646
output_stream_format: [
4747
spec: output_stream_format(),
4848
description: """
49-
Defines how the output stream format will be determined. If a field is set to
50-
`:keep`, then it's value will be preserved from input stream format.
49+
Defines how the output stream format will be determined. If a field is not set or
50+
set to `:keep`, then its value will be preserved from input stream format.
5151
"""
5252
]
5353

@@ -59,14 +59,6 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
5959
_other -> raise ":input_stream_format must be nil or %RawAudio{}"
6060
end
6161

62-
case options.output_stream_format do
63-
%{sample_format: _format, sample_rate: _rate, channels: _channels} ->
64-
:ok
65-
66-
_other ->
67-
raise ":output_stream_format must be a map with :sample_format, :sample_rate and :channels"
68-
end
69-
7062
state =
7163
%{
7264
native: nil,
@@ -212,17 +204,17 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
212204
defp resolve_output_stream_format(input_format, output_format) do
213205
%RawAudio{
214206
sample_format:
215-
if(output_format.sample_format == :keep,
207+
if(Map.get(output_format, :sample_format, :keep) == :keep,
216208
do: input_format.sample_format,
217209
else: output_format.sample_format
218210
),
219211
sample_rate:
220-
if(output_format.sample_rate == :keep,
212+
if(Map.get(output_format, :sample_rate, :keep) == :keep,
221213
do: input_format.sample_rate,
222214
else: output_format.sample_rate
223215
),
224216
channels:
225-
if(output_format.channels == :keep,
217+
if(Map.get(output_format, :channels, :keep) == :keep,
226218
do: input_format.channels,
227219
else: output_format.channels
228220
)

0 commit comments

Comments
 (0)