@@ -80,16 +80,35 @@ defmodule Membrane.Transcoder do
8080 and is supposed to return the desired output stream format or its module.
8181 """
8282 ] ,
83- force_transcoding?: [
84- spec: boolean ( ) | ( stream_format ( ) -> boolean ( ) ) ,
85- default: false ,
83+ transcoding_policy: [
84+ spec:
85+ :always
86+ | :if_needed
87+ | :never
88+ | ( stream_format ( ) -> :always | :if_needed | :never ) ,
89+ default: :if_needed ,
8690 description: """
87- If set to `true`, the input media stream will be decoded and encoded, even
88- if the input stream format and the output stream format are the same type.
91+ Specifies, when transcoding should be applied.
8992
9093 Can be either:
91- * a boolean,
92- * a function that receives the input stream format and returns a boolean.
94+ * an atom: `:always`, `:if_needed` (default) or `:never`,
95+ * a function that receives the input stream format and returns either `:always`,
96+ `:if_needed` or `:never`.
97+
98+ If set to `:always`, the input media stream will be decoded and encoded, even
99+ if the input stream format and the output stream format are the same type.
100+
101+ If set to `:if_needed`, the input media stream will be transcoded only if the input
102+ stream format and the output stream format are different types.
103+ This is the default behavior.
104+
105+ If set to `:never`, the input media stream won't be neither decoded nor encoded.
106+ Changing alignment, encapsulation or stream structure is still possible. This option
107+ is helpful when you want to ensure that #{ inspect ( __MODULE__ ) } will not use too much
108+ of resources, e.g. CPU or memory.
109+
110+ If the transition from the input stream format to the output stream format is not
111+ possible without decoding or encoding the stream, an error will be raised.
93112 """
94113 ] ,
95114 assumed_input_stream_format: [
@@ -152,16 +171,16 @@ defmodule Membrane.Transcoder do
152171 |> resolve_output_stream_format ( )
153172
154173 state =
155- with % { force_transcoding? : f } when is_function ( f ) <- state do
156- % { state | force_transcoding? : f . ( format ) }
174+ with % { transcoding_policy : f } when is_function ( f ) <- state do
175+ % { state | transcoding_policy : f . ( format ) }
157176 end
158177
159178 spec =
160179 get_child ( :connector )
161180 |> plug_transcoding (
162181 format ,
163182 state . output_stream_format ,
164- state . force_transcoding?
183+ state . transcoding_policy
165184 )
166185 |> get_child ( :output_funnel )
167186
@@ -203,15 +222,15 @@ defmodule Membrane.Transcoder do
203222 end
204223 end
205224
206- defp plug_transcoding ( builder , input_format , output_format , force_transcoding? )
225+ defp plug_transcoding ( builder , input_format , output_format , transcoding_policy )
207226 when Audio . is_audio_format ( input_format ) do
208227 builder
209- |> Audio . plug_audio_transcoding ( input_format , output_format , force_transcoding? )
228+ |> Audio . plug_audio_transcoding ( input_format , output_format , transcoding_policy )
210229 end
211230
212- defp plug_transcoding ( builder , input_format , output_format , force_transcoding? )
231+ defp plug_transcoding ( builder , input_format , output_format , transcoding_policy )
213232 when Video . is_video_format ( input_format ) do
214233 builder
215- |> Video . plug_video_transcoding ( input_format , output_format , force_transcoding? )
234+ |> Video . plug_video_transcoding ( input_format , output_format , transcoding_policy )
216235 end
217236end
0 commit comments