-
Notifications
You must be signed in to change notification settings - Fork 0
transcoding_policy option #11
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2ff2591
Implement transcoding_policy option
FelonEkonom b2cc3b1
Start capturing logs
FelonEkonom 784e2f3
Fix typo
FelonEkonom b897667
Bump version to 0.3.0
FelonEkonom 11b60c4
Fix typespec
FelonEkonom b8e23d3
Update lib/transcoder.ex
FelonEkonom 3115694
Implement suggestion from CR
FelonEkonom 407d663
Merge remote-tracking branch 'origin/master' into transcoding_policy
FelonEkonom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,16 +80,35 @@ defmodule Membrane.Transcoder do | |
and is supposed to return the desired output stream format or its module. | ||
""" | ||
], | ||
force_transcoding?: [ | ||
spec: boolean() | (stream_format() -> boolean()), | ||
default: false, | ||
transcoding_policy: [ | ||
spec: | ||
:always | ||
| :if_needed | ||
| :never | ||
| (stream_format() -> :always | :if_needed | :never), | ||
default: :if_needed, | ||
description: """ | ||
If set to `true`, the input media stream will be decoded and encoded, even | ||
if the input stream format and the output stream format are the same type. | ||
Specifies, when transcoding should be applied. | ||
|
||
Can be either: | ||
* a boolean, | ||
* a function that receives the input stream format and returns a boolean. | ||
* an atom: `:always`, `:if_needed` (default) or `:never`, | ||
* a function that receives the input stream format and returns either `:always`, | ||
`:if_needed` or `:never`. | ||
|
||
If set to `:always`, the input media stream will be decoded and encoded, even | ||
if the input stream format and the output stream format are the same type. | ||
|
||
If set to `:if_needed`, the input media stream will be transcoded only if the input | ||
stream format and the output stream format are different types. | ||
This is the default behavior. | ||
|
||
If set to `:never`, the input media stream won't be neither decoded nor encoded. | ||
Changing alignment, encapsulation or stream structure is still possible. This option | ||
is helpful when you want to ensure that #{inspect(__MODULE__)} will not use too much | ||
of resources, e.g. CPU or memory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mention that transcoder will fail if the output format doesn't match input. |
||
|
||
If the transition from the input stream format to the output stream format is not | ||
possible without decoding or encoding the stream, an error will be raised. | ||
""" | ||
], | ||
assumed_input_stream_format: [ | ||
|
@@ -152,16 +171,16 @@ defmodule Membrane.Transcoder do | |
|> resolve_output_stream_format() | ||
|
||
state = | ||
with %{force_transcoding?: f} when is_function(f) <- state do | ||
%{state | force_transcoding?: f.(format)} | ||
with %{transcoding_policy: f} when is_function(f) <- state do | ||
%{state | transcoding_policy: f.(format)} | ||
end | ||
|
||
spec = | ||
get_child(:connector) | ||
|> plug_transcoding( | ||
format, | ||
state.output_stream_format, | ||
state.force_transcoding? | ||
state.transcoding_policy | ||
) | ||
|> get_child(:output_funnel) | ||
|
||
|
@@ -203,15 +222,15 @@ defmodule Membrane.Transcoder do | |
end | ||
end | ||
|
||
defp plug_transcoding(builder, input_format, output_format, force_transcoding?) | ||
defp plug_transcoding(builder, input_format, output_format, transcoding_policy) | ||
when Audio.is_audio_format(input_format) do | ||
builder | ||
|> Audio.plug_audio_transcoding(input_format, output_format, force_transcoding?) | ||
|> Audio.plug_audio_transcoding(input_format, output_format, transcoding_policy) | ||
end | ||
|
||
defp plug_transcoding(builder, input_format, output_format, force_transcoding?) | ||
defp plug_transcoding(builder, input_format, output_format, transcoding_policy) | ||
when Video.is_video_format(input_format) do | ||
builder | ||
|> Video.plug_video_transcoding(input_format, output_format, force_transcoding?) | ||
|> Video.plug_video_transcoding(input_format, output_format, transcoding_policy) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit off to me, having a transcoder with
transcoding_policy: :never
:D Let's try thinking aboutother option name, perhaps emphasising somehow that there are "heavy" operations and "light operations" would be helpful here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, my first idea was to add
forbid_transcoding?
flag next to theforce_transcoding?
, then I thought thattranscoding_policy
will sound much better that these 2 combined. Do you propose any specific option name and values?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option could be called something like
:heavy_operations_policy
, or perhaps we should rename the bin since it not only does transcoding