-
Notifications
You must be signed in to change notification settings - Fork 4
Add set_log_level on ffmpeg #46
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
Open
kipcole9
wants to merge
1
commit into
elixir-webrtc:master
Choose a base branch
from
kipcole9:loglevel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| defmodule Xav.Application do | ||
| @moduledoc false | ||
|
|
||
| use Application | ||
|
|
||
| @impl true | ||
| def start(_type, _args) do | ||
| maybe_set_log_level() | ||
|
|
||
| Supervisor.start_link([], strategy: :one_for_one, name: Xav.Supervisor) | ||
| end | ||
|
|
||
| # Applies the `:xav, :log_level` application env value, if set. | ||
| # Without this, FFmpeg's default log level (`AV_LOG_INFO`) | ||
| # remains unchanged, preserving existing behaviour for users who | ||
| # don't opt in. | ||
| defp maybe_set_log_level do | ||
| case Application.get_env(:xav, :log_level) do | ||
| nil -> :ok | ||
| level -> Xav.Reader.set_log_level(level) | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,102 @@ defmodule Xav.Reader do | |
| Xav.Reader.NIF.seek(ref, time_in_seconds) | ||
| end | ||
|
|
||
| @typedoc """ | ||
| A human-readable FFmpeg log level. | ||
|
|
||
| The mapping to FFmpeg's `AV_LOG_*` constants is: | ||
|
|
||
| | Atom | FFmpeg constant | Value | | ||
| |-------------|-------------------|-------| | ||
| | `:quiet` | `AV_LOG_QUIET` | -8 | | ||
| | `:panic` | `AV_LOG_PANIC` | 0 | | ||
| | `:fatal` | `AV_LOG_FATAL` | 8 | | ||
| | `:error` | `AV_LOG_ERROR` | 16 | | ||
| | `:warning` | `AV_LOG_WARNING` | 24 | | ||
| | `:info` | `AV_LOG_INFO` | 32 | | ||
| | `:verbose` | `AV_LOG_VERBOSE` | 40 | | ||
| | `:debug` | `AV_LOG_DEBUG` | 48 | | ||
| | `:trace` | `AV_LOG_TRACE` | 56 | | ||
|
|
||
| FFmpeg's default is `:info`. | ||
| """ | ||
| @type log_level :: | ||
| :quiet | ||
| | :panic | ||
| | :fatal | ||
| | :error | ||
| | :warning | ||
| | :info | ||
| | :verbose | ||
| | :debug | ||
| | :trace | ||
|
|
||
| @log_levels %{ | ||
| quiet: -8, | ||
| panic: 0, | ||
| fatal: 8, | ||
| error: 16, | ||
| warning: 24, | ||
| info: 32, | ||
| verbose: 40, | ||
| debug: 48, | ||
| trace: 56 | ||
| } | ||
|
|
||
| @doc """ | ||
| Sets the FFmpeg log level. | ||
|
|
||
| Accepts either one of the level atoms listed in `t:log_level/0` | ||
| or a raw integer level. Returns `:ok`. | ||
|
|
||
| This call wraps FFmpeg's `av_log_set_level/1`, which is | ||
| **process-global**: the level is shared across every `libav*` and | ||
| `libswscale` call in the current OS process, including readers, | ||
| decoders, encoders, and converters created elsewhere in the Elixir | ||
| VM. It is not scoped to a particular `Xav.Reader`. | ||
|
|
||
| Typical use is to silence the informational `[swscaler @ ...]` lines | ||
| that `libswscale` prints when it falls back to a non-SIMD | ||
| colorspace conversion path (which happens for example on | ||
| `yuv420p -> rgb24` on Apple Silicon): | ||
|
|
||
| Xav.Reader.set_log_level(:error) | ||
|
|
||
| To configure the level declaratively at application start, use the | ||
| `:log_level` key in your application env instead: | ||
|
|
||
| # config/runtime.exs | ||
| config :xav, log_level: :error | ||
|
|
||
| `Xav.Application` reads this on boot and calls `set_log_level/1` | ||
| for you. | ||
|
|
||
| ## Examples | ||
|
|
||
| iex> Xav.Reader.set_log_level(:error) | ||
| :ok | ||
|
|
||
| iex> Xav.Reader.set_log_level(:quiet) | ||
| :ok | ||
|
|
||
| """ | ||
| @spec set_log_level(log_level() | integer()) :: :ok | ||
| def set_log_level(level) when is_atom(level) do | ||
|
Collaborator
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. I don't think this function belongs to reader as it affects all logs of ffmpeg. I suggest we move this to For the |
||
| case Map.fetch(@log_levels, level) do | ||
| {:ok, int} -> | ||
| Xav.Reader.NIF.set_log_level(int) | ||
|
|
||
| :error -> | ||
| raise ArgumentError, | ||
| "invalid FFmpeg log level #{inspect(level)}. " <> | ||
| "Expected one of #{inspect(Map.keys(@log_levels))} or an integer." | ||
| end | ||
| end | ||
|
|
||
| def set_log_level(level) when is_integer(level) do | ||
| Xav.Reader.NIF.set_log_level(level) | ||
| end | ||
|
|
||
| @doc """ | ||
| Creates a new reader stream. | ||
|
|
||
|
|
||
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.
Isn't the name
log_levelconfusing, it may be interpreted as setting the Elixir log level. What aboutffmpeg_log_level?