Skip to content

Rename enforce_transcoding to force_transcoding #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/transcoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Membrane.Transcoder do
and is supposed to return the desired output stream format or its module.
"""
],
enforce_transcoding?: [
force_transcoding?: [
spec: boolean() | (stream_format() -> boolean()),
default: false,
description: """
Expand Down Expand Up @@ -113,16 +113,16 @@ defmodule Membrane.Transcoder do
|> resolve_output_stream_format()

state =
with %{enforce_transcoding?: f} when is_function(f) <- state do
%{state | enforce_transcoding?: f.(format)}
with %{force_transcoding?: f} when is_function(f) <- state do
%{state | force_transcoding?: f.(format)}
end

spec =
get_child(:forwarding_filter)
|> plug_transcoding(
format,
state.output_stream_format,
state.enforce_transcoding?
state.force_transcoding?
)
|> get_child(:output_funnel)

Expand Down Expand Up @@ -166,15 +166,15 @@ defmodule Membrane.Transcoder do
end
end

defp plug_transcoding(builder, input_format, output_format, enforce_transcoding?)
defp plug_transcoding(builder, input_format, output_format, force_transcoding?)
when Audio.is_audio_format(input_format) do
builder
|> Audio.plug_audio_transcoding(input_format, output_format, enforce_transcoding?)
|> Audio.plug_audio_transcoding(input_format, output_format, force_transcoding?)
end

defp plug_transcoding(builder, input_format, output_format, enforce_transcoding?)
defp plug_transcoding(builder, input_format, output_format, force_transcoding?)
when Video.is_video_format(input_format) do
builder
|> Video.plug_video_transcoding(input_format, output_format, enforce_transcoding?)
|> Video.plug_video_transcoding(input_format, output_format, force_transcoding?)
end
end
10 changes: 5 additions & 5 deletions lib/transcoder/audio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ defmodule Membrane.Transcoder.Audio do
audio_stream_format(),
boolean()
) :: ChildrenSpec.builder()
def plug_audio_transcoding(builder, input_format, output_format, enforce_transcoding?)
def plug_audio_transcoding(builder, input_format, output_format, force_transcoding?)
when is_audio_format(input_format) and is_audio_format(output_format) do
do_plug_audio_transcoding(builder, input_format, output_format, enforce_transcoding?)
do_plug_audio_transcoding(builder, input_format, output_format, force_transcoding?)
end

defp do_plug_audio_transcoding(
builder,
%format_module{},
%format_module{},
false = _enforce_transcoding?
false = _force_transcoding?
) do
Membrane.Logger.debug("""
This bin will only forward buffers, as the input stream format is the same as the output stream format.
Expand All @@ -57,12 +57,12 @@ defmodule Membrane.Transcoder.Audio do
builder,
%RemoteStream{content_format: Opus},
%Opus{},
false = _enforce_transcoding?
false = _force_transcoding?
) do
builder |> child(:opus_parser, Opus.Parser)
end

defp do_plug_audio_transcoding(builder, input_format, output_format, _enforce_transcoding?) do
defp do_plug_audio_transcoding(builder, input_format, output_format, _force_transcoding?) do
builder
|> maybe_plug_parser(input_format)
|> maybe_plug_decoder(input_format)
Expand Down
10 changes: 5 additions & 5 deletions lib/transcoder/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ defmodule Membrane.Transcoder.Video do
video_stream_format(),
boolean()
) :: ChildrenSpec.builder()
def plug_video_transcoding(builder, input_format, output_format, enforce_transcoding?)
def plug_video_transcoding(builder, input_format, output_format, force_transcoding?)
when is_video_format(input_format) and is_video_format(output_format) do
do_plug_video_transcoding(builder, input_format, output_format, enforce_transcoding?)
do_plug_video_transcoding(builder, input_format, output_format, force_transcoding?)
end

defp do_plug_video_transcoding(
builder,
%h26x{},
%h26x{} = output_format,
false = _enforce_transcoding?
false = _force_transcoding?
)
when h26x in [H264, H265] do
parser =
Expand All @@ -46,7 +46,7 @@ defmodule Membrane.Transcoder.Video do
builder,
%format_module{},
%format_module{},
false = _enforce_transcoding?
false = _force_transcoding?
) do
Membrane.Logger.debug("""
This bin will only forward buffers, as the input stream format is the same type as the output stream format.
Expand All @@ -55,7 +55,7 @@ defmodule Membrane.Transcoder.Video do
builder
end

defp do_plug_video_transcoding(builder, input_format, output_format, _enforce_transcoding?) do
defp do_plug_video_transcoding(builder, input_format, output_format, _force_transcoding?) do
builder
|> maybe_plug_parser_and_decoder(input_format)
|> maybe_plug_encoder_and_parser(output_format)
Expand Down
8 changes: 4 additions & 4 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ defmodule Membrane.Transcoder.IntegrationTest do
do: {[stream_format: {:output, state.format}], state}
end

test "if encoder and decoder are spawned or not, depending on the value of `enforce_transcoding?` option" do
test "if encoder and decoder are spawned or not, depending on the value of `force_transcoding?` option" do
for format <- [%AAC{channels: 1}, %H264{alignment: :au, stream_structure: :annexb}],
enforce_transcoding? <- [true, false] do
force_transcoding? <- [true, false] do
spec =
child(:source, %FormatSource{format: format})
|> child(:transcoder, %Membrane.Transcoder{
output_stream_format: format,
enforce_transcoding?: enforce_transcoding?
force_transcoding?: force_transcoding?
})
|> child(:sink, Testing.Sink)

Expand All @@ -89,7 +89,7 @@ defmodule Membrane.Transcoder.IntegrationTest do
|> Enum.each(fn child_name ->
get_child_result = Testing.Pipeline.get_child_pid(pipeline, [:transcoder, child_name])

if enforce_transcoding? do
if force_transcoding? do
assert {:ok, child_pid} = get_child_result
assert is_pid(child_pid)
else
Expand Down