Skip to content

Commit

Permalink
Merge pull request #14 from membraneframework/release/v0.8.0
Browse files Browse the repository at this point in the history
auto demands, core update, credo
  • Loading branch information
mat-hek authored Feb 23, 2022
2 parents d2c3bab + 1638599 commit 367bf9d
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 97 deletions.
26 changes: 24 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.0
jobs:
build:
test:
docker:
- image: membraneframeworklabs/docker_membrane:latest
environment:
Expand All @@ -11,6 +11,28 @@ jobs:
steps:
- checkout
- run: mix deps.get
- run: mix format --check-formatted
- 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
186 changes: 186 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# 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},
{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`.
#
]
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The package can be installed by adding `membrane_rtp_mpegaudio_plugin` to your l
```elixir
def deps do
[
{:membrane_rtp_mpegaudio_plugin, "~> 0.7.0"}
{:membrane_rtp_mpegaudio_plugin, "~> 0.8.0"}
]
end
```
Expand Down
44 changes: 8 additions & 36 deletions lib/membrane_element_mpeg_audio/depayloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ defmodule Membrane.RTP.MPEGAudio.Depayloader do
alias Membrane.{Buffer, RTP, RemoteStream}
alias Membrane.Caps.Audio.MPEG

@default_demand 1
def_input_pad :input, caps: RTP, demand_mode: :auto

def_input_pad :input, caps: RTP, demand_unit: :buffers
def_output_pad :output, caps: {RemoteStream, content_format: MPEG, type: :packetized}
def_output_pad :output,
caps: {RemoteStream, content_format: MPEG, type: :packetized},
demand_mode: :auto

defmodule State do
@moduledoc false
defstruct [:buffer_size]

@type t :: %State{
buffer_size: pos_integer()
}
@impl true
def handle_init(_opts) do
{:ok, %{}}
end

@impl true
Expand All @@ -39,38 +36,13 @@ defmodule Membrane.RTP.MPEGAudio.Depayloader do
end

@impl true
def handle_process(:input, buffer, context, %State{buffer_size: nil}) do
buffer_size = byte_size(buffer.payload)
handle_process(:input, buffer, context, %State{buffer_size: buffer_size})
end

def handle_process(:input, buffer, _ctx, state) do
with %Buffer{
payload: <<0::16, _offset::16, depayloaded::binary>>
} <- buffer do
{{:ok, buffer: {:output, %Buffer{buffer | payload: depayloaded}}, redemand: :output}, state}
{{:ok, buffer: {:output, %Buffer{buffer | payload: depayloaded}}}, state}
else
%Buffer{} -> {{:error, :invalid_payload}, state}
end
end

@impl true
def handle_demand(:output, size, :buffers, _ctx, state) do
{{:ok, demand: {:input, size}}, state}
end

def handle_demand(:output, _size, :bytes, _context, %State{buffer_size: nil} = state) do
{{:ok, demand: {:input, @default_demand}}, state}
end

def handle_demand(:output, size, :bytes, _context, %State{buffer_size: buffer_size} = state)
when is_number(buffer_size) do
# Demand in buffer needs to be bigger or equal to one in bytes
demand_size =
(size / buffer_size)
|> Float.ceil()
|> trunc()

{{:ok, demand: {:input, demand_size}}, state}
end
end
1 change: 1 addition & 0 deletions lib/membrane_element_mpeg_audio/plugin_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Membrane.RTP.MPEGAudio.Plugin.App do
use Application
alias Membrane.RTP.{MPEGAudio, PayloadFormat}

@impl true
def start(_type, _args) do
PayloadFormat.register(%PayloadFormat{
encoding_name: :MPA,
Expand Down
14 changes: 8 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule Membrane.RTP.MPEGAudio.MixProject do
use Mix.Project

@version "0.7.0"
@version "0.8.0"
@github_url "https://github.com/membraneframework/membrane_rtp_mpegaudio_plugin"

def project do
[
app: :membrane_rtp_mpegaudio_plugin,
version: @version,
elixir: "~> 1.9",
elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()),
deps: deps(),

Expand Down Expand Up @@ -37,15 +37,16 @@ defmodule Membrane.RTP.MPEGAudio.MixProject do
defp docs do
[
main: "readme",
extras: ["README.md"],
extras: ["README.md", LICENSE: [title: "License"]],
formatters: ["html"],
source_ref: "v#{@version}"
]
end

defp package do
[
maintainers: ["Membrane Team"],
licenses: ["Apache 2.0"],
licenses: ["Apache-2.0"],
links: %{
"GitHub" => @github_url,
"Membrane Framework Homepage" => "https://membraneframework.org"
Expand All @@ -55,13 +56,14 @@ defmodule Membrane.RTP.MPEGAudio.MixProject do

defp deps do
[
{:membrane_core, "~> 0.8.0"},
{:membrane_core, "~> 0.9.0"},
{:membrane_rtp_format, "~> 0.3.0"},
{:membrane_caps_audio_mpeg, "~> 0.2.0"},

# dev
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0", only: :dev, runtime: false}
{:dialyxir, "~> 1.0", only: :dev, runtime: false},
{:credo, "~> 1.5", only: :dev, runtime: false}
]
end
end
Loading

0 comments on commit 367bf9d

Please sign in to comment.