Skip to content

Commit

Permalink
Core update plus houskeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
bblaszkow06 committed Mar 14, 2022
1 parent 920ee3e commit f779a3e
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 66 deletions.
37 changes: 30 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
version: 2.0
jobs:
build:
test:
docker:
- image: membrane/membrane:latest
environment:
MIX_ENV: test
working_directory: '~/app'
- image: membraneframeworklabs/docker_membrane:latest
environment:
MIX_ENV: test

working_directory: ~/app

steps:
- checkout
- run: mix deps.get
- run: mix format --check-formatted
- run: mix
- run: mix compile --force --warnings-as-errors
- run: mix test

lint:
docker:
- image: membraneframeworklabs/docker_membrane:latest
environment:
MIX_ENV: dev

working_directory: ~/app

steps:
- checkout
- run: mix deps.get
- run: mix format --check-formatted
- run: mix compile
- run: mix credo
- run: mix docs && mix docs 2>&1 | (! grep -q "warning:")

workflows:
version: 2
build:
jobs:
- test
- lint
187 changes: 187 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: false,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 0]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, parens: true},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, false},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MapInto, false},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, false},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.UnsafeExec, []},

#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Readability.StrictModuleLayout,
priority: :normal, order: ~w/shortdoc moduledoc behaviour use import require alias/a},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, force: :meaningful},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
13 changes: 0 additions & 13 deletions lib/membrane_ffmpeg_swresample.ex

This file was deleted.

31 changes: 17 additions & 14 deletions lib/membrane_ffmpeg_swresample_plugin/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
This element performs audio conversion/resampling/channel mixing, using SWResample
module of FFmpeg library.
"""

use Membrane.Filter
alias Membrane.Caps.Audio.Raw, as: Caps

import Mockery.Macro

alias Membrane.Caps.Audio.Raw, as: RawAudio
alias Membrane.Buffer
alias Membrane.Caps.Matcher
alias __MODULE__.Native
import Mockery.Macro

@supported_caps {Caps,
@supported_caps {RawAudio,
format: Matcher.one_of([:u8, :s16le, :s32le, :f32le, :f64le]),
channels: Matcher.one_of([1, 2])}

def_output_pad :output, caps: @supported_caps

def_input_pad :input,
demand_unit: :bytes,
caps: [@supported_caps, {Caps, format: :s24le, channels: one_of([1, 2])}]
caps: [@supported_caps, {RawAudio, format: :s24le, channels: one_of([1, 2])}]

def_options input_caps: [
type: :caps,
spec: Caps.t() | nil,
spec: RawAudio.t() | nil,
default: nil,
description: """
Caps for the input pad. If set to nil (default value),
Expand All @@ -32,7 +35,7 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
],
output_caps: [
type: :caps,
spec: Caps.t(),
spec: RawAudio.t(),
description: """
Audio caps for souce pad (output)
"""
Expand Down Expand Up @@ -98,21 +101,21 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
def handle_demand(:output, size, :bytes, ctx, state) do
size =
size
|> Caps.bytes_to_time(ctx.pads.output.caps)
|> Caps.time_to_bytes(state.input_caps)
|> RawAudio.bytes_to_time(ctx.pads.output.caps)
|> RawAudio.time_to_bytes(state.input_caps)

{{:ok, demand: {:input, size}}, state}
end

def handle_demand(:output, n_buffers, :buffers, _ctx, state) do
size = n_buffers * Caps.frames_to_bytes(state.frames_per_buffer, state.input_caps)
size = n_buffers * RawAudio.frames_to_bytes(state.frames_per_buffer, state.input_caps)
{{:ok, demand: {:input, size}}, state}
end

@impl true
def handle_process(:input, %Buffer{payload: payload}, _ctx, state) do
conversion_result =
convert(state.native, Caps.frame_size(state.input_caps), payload, state.queue)
convert(state.native, RawAudio.frame_size(state.input_caps), payload, state.queue)

with {:ok, {result, queue}} when byte_size(result) > 0 <- conversion_result do
{{:ok, buffer: {:output, %Buffer{payload: result}}, redemand: :output},
Expand All @@ -129,14 +132,14 @@ defmodule Membrane.FFmpeg.SWResample.Converter do
end

defp mk_native(
%Caps{format: input_format, sample_rate: input_rate, channels: input_channels},
%Caps{format: out_format, sample_rate: out_rate, channels: out_channels}
%RawAudio{format: input_format, sample_rate: input_rate, channels: input_channels},
%RawAudio{format: out_format, sample_rate: out_rate, channels: out_channels}
) do
mockable(Native).create(
input_format |> Caps.Format.serialize(),
input_format |> RawAudio.Format.serialize(),
input_rate,
input_channels,
out_format |> Caps.Format.serialize(),
out_format |> RawAudio.Format.serialize(),
out_rate,
out_channels
)
Expand Down
Loading

0 comments on commit f779a3e

Please sign in to comment.