Skip to content

Commit

Permalink
Merge pull request #5 from membraneframework/naming-update
Browse files Browse the repository at this point in the history
Rename from 'caps' and update template
  • Loading branch information
bblaszkow06 authored Feb 21, 2022
2 parents bdbf61e + b9a4f60 commit 60b196a
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 110 deletions.
38 changes: 31 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
version: 2.0
jobs:
build:
test:
docker:
- image: membrane/bionic-membrane:latest
environment:
MIX_ENV: test
working_directory: '~/app'
- image: membraneframeworklabs/docker_membrane:latest
environment:
MIX_ENV: test

working_directory: ~/app

steps:
- checkout
- 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
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`.
#
]
}
]
}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Membrane Multimedia Framework: Raw video format definition

[![CircleCI](https://circleci.com/gh/membraneframework/membrane-caps-video-raw.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane-caps-video-raw)
[![Hex.pm](https://img.shields.io/hexpm/v/membrane_raw_video_format.svg)](https://hex.pm/packages/membrane_raw_video_format)
[![API Docs](https://img.shields.io/badge/api-docs-yellow.svg?style=flat)](https://hexdocs.pm/membrane_raw_video_format/)
[![CircleCI](https://circleci.com/gh/membraneframework/membrane_raw_video_format.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane_raw_video_format)

This package provides raw video format definition (so-called caps) for the
This package provides the definition of raw (uncompressed) video frames format for the elements written with
[Membrane Multimedia Framework](https://membraneframework.org).

## Installation
Expand All @@ -16,7 +18,7 @@ reason, just add the following line to your `deps` in the `mix.exs` and run
`mix deps.get`.

```elixir
{:membrane_caps_video_raw, "~> 0.1"}
{:membrane_raw_video_format, "~> 0.2"}
```

## Copyright and License
Expand Down
32 changes: 21 additions & 11 deletions lib/membrane_caps_video_raw.ex → lib/membrane_raw_video.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.Caps.Video.Raw do
defmodule Membrane.RawVideo do
@moduledoc """
This module provides caps struct for raw video frames.
This module provides a struct (`t:#{inspect(__MODULE__)}.t/0`) describing raw video frames.
"""
require Integer

Expand All @@ -23,9 +23,10 @@ defmodule Membrane.Caps.Video.Raw do
@type framerate_t :: {frames :: non_neg_integer, seconds :: pos_integer}

@typedoc """
Format used to encode color of each pixel in each video frame.
Format used to encode the color of every pixel in each video frame.
"""
@type format_t :: :I420 | :I422 | :I444 | :RGB | :BGRA | :RGBA | :NV12 | :NV21 | :YV12 | :AYUV
@type pixel_format_t ::
:I420 | :I422 | :I444 | :RGB | :BGRA | :RGBA | :NV12 | :NV21 | :YV12 | :AYUV

@typedoc """
Determines, whether buffers are aligned i.e. each buffer contains one frame.
Expand All @@ -36,19 +37,22 @@ defmodule Membrane.Caps.Video.Raw do
width: width_t(),
height: height_t(),
framerate: framerate_t(),
format: format_t(),
pixel_format: pixel_format_t(),
aligned: aligned_t()
}

@enforce_keys [:width, :height, :framerate, :format, :aligned]
@enforce_keys [:width, :height, :framerate, :pixel_format, :aligned]
defstruct @enforce_keys

@supported_pixel_formats [:I420, :I422, :I444, :RGB, :BGRA, :RGBA, :NV12, :NV21, :YV12, :AYUV]

@doc """
Simple wrapper over `frame_size/3`. Returns the size of raw video frame
in bytes for the given caps.
"""
@spec frame_size(t()) :: Bunch.Type.try_t(pos_integer)
def frame_size(%__MODULE__{format: format, width: width, height: height}) do
@spec frame_size(t()) :: {:ok, pos_integer()} | {:error, reason}
when reason: :invalid_dimensions | :invalid_pixel_format
def frame_size(%__MODULE__{pixel_format: format, width: width, height: height}) do
frame_size(format, width, height)
end

Expand All @@ -58,7 +62,9 @@ defmodule Membrane.Caps.Video.Raw do
It may result in error when dimensions don't fulfill requirements for the given format
(e.g. I420 requires both dimensions to be divisible by 2).
"""
@spec frame_size(Raw.format_t(), Raw.width_t(), Raw.height()) :: Bunch.Type.try_t(pos_integer)
@spec frame_size(pixel_format_t(), width_t(), height_t()) ::
{:ok, pos_integer()} | {:error, reason}
when reason: :invalid_dimensions | :invalid_pixel_format
def frame_size(format, width, height)
when format in [:I420, :YV12, :NV12, :NV21] and Integer.is_even(width) and
Integer.is_even(height) do
Expand All @@ -85,7 +91,11 @@ defmodule Membrane.Caps.Video.Raw do
{:ok, width * height * 4}
end

def frame_size(_, _, _) do
{:error, :invalid_dims}
def frame_size(format, _width, _height) when format in @supported_pixel_formats do
{:error, :invalid_dimensions}
end

def frame_size(_format, _width, _height) do
{:error, :invalid_pixel_format}
end
end
24 changes: 14 additions & 10 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
defmodule Membrane.Caps.Video.Raw.Mixfile do
defmodule Membrane.RawVideo.Mixfile do
use Mix.Project

@version "0.1.0"
@github_url "https://github.com/membraneframework/membrane-caps-video-raw"
@version "0.2.0"
@github_url "https://github.com/membraneframework/membrane_raw_video_format"

def project do
[
app: :membrane_caps_video_raw,
app: :membrane_raw_video_format,
version: @version,
elixir: "~> 1.7",
description: "Membrane Multimedia Framework (Raw video format definition)",
elixir: "~> 1.12",
description:
"Definition of raw (uncompressed) video format for Membrane Multimedia Framework",
package: package(),
name: "Membrane Caps: Video Raw",
name: "Membrane: Raw video format",
source_url: @github_url,
docs: docs(),
deps: deps()
Expand All @@ -21,15 +22,16 @@ defmodule Membrane.Caps.Video.Raw.Mixfile 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 @@ -39,7 +41,9 @@ defmodule Membrane.Caps.Video.Raw.Mixfile do

defp deps do
[
{:ex_doc, "~> 0.19", only: :dev, runtime: false}
{:ex_doc, "~> 0.28", only: :dev, runtime: false},
{:dialyxir, "~> 1.1", only: :dev, runtime: false},
{:credo, "~> 1.6", only: :dev, runtime: false}
]
end
end
Loading

0 comments on commit 60b196a

Please sign in to comment.