@@ -80,16 +80,35 @@ defmodule Membrane.Transcoder do
80
80
and is supposed to return the desired output stream format or its module.
81
81
"""
82
82
] ,
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 ,
86
90
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.
89
92
90
93
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.
93
112
"""
94
113
] ,
95
114
assumed_input_stream_format: [
@@ -152,16 +171,16 @@ defmodule Membrane.Transcoder do
152
171
|> resolve_output_stream_format ( )
153
172
154
173
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 ) }
157
176
end
158
177
159
178
spec =
160
179
get_child ( :connector )
161
180
|> plug_transcoding (
162
181
format ,
163
182
state . output_stream_format ,
164
- state . force_transcoding?
183
+ state . transcoding_policy
165
184
)
166
185
|> get_child ( :output_funnel )
167
186
@@ -203,15 +222,15 @@ defmodule Membrane.Transcoder do
203
222
end
204
223
end
205
224
206
- defp plug_transcoding ( builder , input_format , output_format , force_transcoding? )
225
+ defp plug_transcoding ( builder , input_format , output_format , transcoding_policy )
207
226
when Audio . is_audio_format ( input_format ) do
208
227
builder
209
- |> Audio . plug_audio_transcoding ( input_format , output_format , force_transcoding? )
228
+ |> Audio . plug_audio_transcoding ( input_format , output_format , transcoding_policy )
210
229
end
211
230
212
- defp plug_transcoding ( builder , input_format , output_format , force_transcoding? )
231
+ defp plug_transcoding ( builder , input_format , output_format , transcoding_policy )
213
232
when Video . is_video_format ( input_format ) do
214
233
builder
215
- |> Video . plug_video_transcoding ( input_format , output_format , force_transcoding? )
234
+ |> Video . plug_video_transcoding ( input_format , output_format , transcoding_policy )
216
235
end
217
236
end
0 commit comments