From e33113d293456e849aa5ce33f8edb4ff2af6dd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jod=C5=82o=C5=9B?= Date: Fri, 18 Mar 2022 12:09:49 +0100 Subject: [PATCH] Move to `membrane_raw_audio_format` and update credo | MS-43 (#28) --- README.md | 6 ++--- .../converter.spec.exs | 2 +- .../converter.ex | 22 ++++++++++-------- mix.exs | 2 +- mix.lock | 4 ++-- .../converter_native_test.exs | 23 ++++++++++--------- .../converter_test.exs | 20 ++++++++-------- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 27456cb..63c8541 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ defmodule Resampling.Pipeline do alias Membrane.Element.File alias Membrane.FFmpeg.SWResample.Converter - alias Membrane.Caps.Audio.Raw + alias Membrane.RawAudio @doc false @impl true @@ -35,8 +35,8 @@ defmodule Resampling.Pipeline do children = [ file_src: %File.Source{location: "/tmp/input.raw"}, converter: %Converter{ - input_caps: %Raw{channels: 2, format: :s24le, sample_rate: 48_000}, - output_caps: %Raw{channels: 2, format: :f32le, sample_rate: 44_100} + input_caps: %RawAudio{channels: 2, sample_format: :s24le, sample_rate: 48_000}, + output_caps: %RawAudio{channels: 2, sample_format: :f32le, sample_rate: 44_100} }, file_sink: %File.Sink{location: "/tmp/output.raw"}, ] diff --git a/c_src/membrane_ffmpeg_swresample_plugin/converter.spec.exs b/c_src/membrane_ffmpeg_swresample_plugin/converter.spec.exs index 576d3ed..a4d9f26 100644 --- a/c_src/membrane_ffmpeg_swresample_plugin/converter.spec.exs +++ b/c_src/membrane_ffmpeg_swresample_plugin/converter.spec.exs @@ -5,7 +5,7 @@ state_type "ConverterState" # Function creating native handler of converter. # # Expects sample format (encoded as integer, using -# `Membrane.Caps.Audio.Raw.Format.serialize/1`), sample rate and number of channels +# `Membrane.RawAudio.SampleFormat.serialize/1`), sample rate and number of channels # for input and output data, respectively. # # Currently supported formats are u8, s16le, s32le, f32le, f64le and s24le (input only) diff --git a/lib/membrane_ffmpeg_swresample_plugin/converter.ex b/lib/membrane_ffmpeg_swresample_plugin/converter.ex index b3a9a90..df848ad 100644 --- a/lib/membrane_ffmpeg_swresample_plugin/converter.ex +++ b/lib/membrane_ffmpeg_swresample_plugin/converter.ex @@ -5,23 +5,21 @@ defmodule Membrane.FFmpeg.SWResample.Converter do """ use Membrane.Filter - import Mockery.Macro - alias Membrane.Caps.Audio.Raw, as: RawAudio - alias Membrane.Buffer + alias Membrane.{RawAudio, Buffer} alias Membrane.Caps.Matcher alias __MODULE__.Native @supported_caps {RawAudio, - format: Matcher.one_of([:u8, :s16le, :s32le, :f32le, :f64le]), + sample_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, {RawAudio, format: :s24le, channels: one_of([1, 2])}] + caps: [@supported_caps, {RawAudio, sample_format: :s24le, channels: one_of([1, 2])}] def_options input_caps: [ type: :caps, @@ -37,7 +35,7 @@ defmodule Membrane.FFmpeg.SWResample.Converter do type: :caps, spec: RawAudio.t(), description: """ - Audio caps for souce pad (output) + Audio caps for source pad (output) """ ], frames_per_buffer: [ @@ -132,14 +130,18 @@ defmodule Membrane.FFmpeg.SWResample.Converter do end defp mk_native( - %RawAudio{format: input_format, sample_rate: input_rate, channels: input_channels}, - %RawAudio{format: out_format, sample_rate: out_rate, channels: out_channels} + %RawAudio{ + sample_format: input_format, + sample_rate: input_rate, + channels: input_channels + }, + %RawAudio{sample_format: out_format, sample_rate: out_rate, channels: out_channels} ) do mockable(Native).create( - input_format |> RawAudio.Format.serialize(), + input_format |> RawAudio.SampleFormat.serialize(), input_rate, input_channels, - out_format |> RawAudio.Format.serialize(), + out_format |> RawAudio.SampleFormat.serialize(), out_rate, out_channels ) diff --git a/mix.exs b/mix.exs index 076f066..3599bc4 100644 --- a/mix.exs +++ b/mix.exs @@ -66,7 +66,7 @@ defmodule Membrane.FFmpeg.SWResample.Mixfile do defp deps do [ {:membrane_core, "~> 0.9.0"}, - {:membrane_caps_audio_raw, "~> 0.6.0"}, + {:membrane_raw_audio_format, "~> 0.8.0"}, {:bunch, "~> 1.3.0"}, {:unifex, "~> 0.7.0"}, {:membrane_common_c, "~> 0.11.0"}, diff --git a/mix.lock b/mix.lock index c034234..88cd0ac 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"}, "credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.21", "7299db854f6d63730c15c8a781862889bb0fbf4432d7c306b3e63ce825d64baa", [:mix], [], "hexpm", "60664e1bdf7a02d8cbec2ac1d5b6fe0a68cf1d749ba955990d647346fac421e4"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.23", "1d5f22a2802160fd454404fbf5e8f5d14cd8eb727c63701397b72d8c35267e69", [:mix], [], "hexpm", "2ec13bf14b2f4bbb4a15480970e295eede8bb01087fad6ceca27b724ab8e9d18"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.28.2", "e031c7d1a9fc40959da7bf89e2dc269ddc5de631f9bd0e326cbddf7d8085a9da", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "51ee866993ffbd0e41c084a7677c570d0fc50cb85c6b5e76f8d936d9587fa719"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, @@ -15,9 +15,9 @@ "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, - "membrane_caps_audio_raw": {:hex, :membrane_caps_audio_raw, "0.6.1", "f5772ef28c086d0950b16f85e913b1ea35a4c240cb7d2f42fef3388394b58d5a", [:mix], [{:bimap, "~> 1.1", [hex: :bimap, repo: "hexpm", optional: false]}, {:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "ff827313b18e38f647264c46b0486682a1fbf84c2e43242cea0f127691c748dd"}, "membrane_common_c": {:hex, :membrane_common_c, "0.11.0", "1706631a80b065725bddb34cf182e17af04aa1a753efc47a0043fa20715ac57b", [:mix], [{:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:shmex, "~> 0.4.0", [hex: :shmex, repo: "hexpm", optional: false]}, {:unifex, "~> 0.7.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2c0f5a21116466bfa3242fe00aea56097c6336029d1d7558e6bd1dd2c02b4b09"}, "membrane_core": {:hex, :membrane_core, "0.9.0", "91a79636c6b2fcc6ae2e611670cdca33a0b38ff4dabe8fb7c1d56cba426db787", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 2.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ab252e7aa944d23fbb22ce0e8bc75b088cfe3ed1c2c7ba203b1cc2fd794a85ed"}, + "membrane_raw_audio_format": {:hex, :membrane_raw_audio_format, "0.8.0", "1f73b70a0fb1d56e582823a097d061a364e4781cdfa55810777b2cfdacaa0410", [:mix], [{:bimap, "~> 1.1", [hex: :bimap, repo: "hexpm", optional: false]}, {:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "3194f10acc832da778f085d54f731a7b19be02e4d695480f764cf7d208de6ecf"}, "mockery": {:hex, :mockery, "2.3.1", "a02fd60b10ac9ed37a7a2ecf6786c1f1dd5c75d2b079a60594b089fba32dc087", [:mix], [], "hexpm", "1d0971d88ebf084e962da3f2cfee16f0ea8e04ff73a7710428500d4500b947fa"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, "numbers": {:hex, :numbers, "5.2.4", "f123d5bb7f6acc366f8f445e10a32bd403c8469bdbce8ce049e1f0972b607080", [:mix], [{:coerce, "~> 1.0", [hex: :coerce, repo: "hexpm", optional: false]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "eeccf5c61d5f4922198395bf87a465b6f980b8b862dd22d28198c5e6fab38582"}, diff --git a/test/membrane_ffmpeg_swresample_plugin/converter_native_test.exs b/test/membrane_ffmpeg_swresample_plugin/converter_native_test.exs index a84b2fd..8ded0ec 100644 --- a/test/membrane_ffmpeg_swresample_plugin/converter_native_test.exs +++ b/test/membrane_ffmpeg_swresample_plugin/converter_native_test.exs @@ -1,6 +1,7 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do + @moduledoc false use ExUnit.Case, async: true - alias Membrane.Caps.Audio.Raw + alias Membrane.RawAudio @module Membrane.FFmpeg.SWResample.Converter.Native @@ -17,10 +18,10 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do out_rate <- rates, out_channels <- channels do [ - input_fmt |> Raw.Format.serialize(), + input_fmt |> RawAudio.SampleFormat.serialize(), input_rate, input_channels, - out_fmt |> Raw.Format.serialize(), + out_fmt |> RawAudio.SampleFormat.serialize(), out_rate, out_channels ] @@ -40,10 +41,10 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do ] = input [ - input_fmt |> Raw.Format.serialize(), + input_fmt |> RawAudio.SampleFormat.serialize(), input_rate, input_channels, - out_fmt |> Raw.Format.serialize(), + out_fmt |> RawAudio.SampleFormat.serialize(), out_rate, out_channels ] @@ -51,10 +52,10 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do defp mk_simple_converter(out_fmt, dst_fmt) do @module.create( - out_fmt |> Raw.Format.serialize(), + out_fmt |> RawAudio.SampleFormat.serialize(), 48_000, 1, - dst_fmt |> Raw.Format.serialize(), + dst_fmt |> RawAudio.SampleFormat.serialize(), 48_000, 1 ) @@ -134,10 +135,10 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do for size <- [1234, 5120, 20_480, 384_000] do {:ok, handle} = @module.create( - :s16le |> Raw.Format.serialize(), + :s16le |> RawAudio.SampleFormat.serialize(), 48_000, 2, - :u8 |> Raw.Format.serialize(), + :u8 |> RawAudio.SampleFormat.serialize(), 24_000, 1 ) @@ -154,10 +155,10 @@ defmodule Membrane.FFmpeg.SWResample.Converter.NativeTest do for n <- [1, 10, 100] do {:ok, handle} = @module.create( - :f32le |> Raw.Format.serialize(), + :f32le |> RawAudio.SampleFormat.serialize(), 48_000, 2, - :s16le |> Raw.Format.serialize(), + :s16le |> RawAudio.SampleFormat.serialize(), 44_100, 2 ) diff --git a/test/membrane_ffmpeg_swresample_plugin/converter_test.exs b/test/membrane_ffmpeg_swresample_plugin/converter_test.exs index 7b2a9ae..27e3847 100644 --- a/test/membrane_ffmpeg_swresample_plugin/converter_test.exs +++ b/test/membrane_ffmpeg_swresample_plugin/converter_test.exs @@ -1,21 +1,21 @@ defmodule Membrane.FFmpeg.SWResample.ConverterTest do use ExUnit.Case, async: true use Mockery - alias Membrane.Caps.Audio.Raw + alias Membrane.RawAudio alias Membrane.FFmpeg.SWResample.Converter @module Converter @native Converter.Native - @s16le_caps %Raw{ + @s16le_caps %RawAudio{ channels: 2, - format: :s16le, + sample_format: :s16le, sample_rate: 48_000 } - @u8_caps %Raw{ + @u8_caps %RawAudio{ channels: 1, - format: :u8, + sample_format: :u8, sample_rate: 44_100 } @@ -43,10 +43,10 @@ defmodule Membrane.FFmpeg.SWResample.ConverterTest do assert %{native: :mock_handle} = new_state - input_fmt = @s16le_caps.format |> Raw.Format.serialize() + input_fmt = @s16le_caps.sample_format |> RawAudio.SampleFormat.serialize() input_rate = @s16le_caps.sample_rate input_channel = @s16le_caps.channels - out_fmt = @u8_caps.format |> Raw.Format.serialize() + out_fmt = @u8_caps.sample_format |> RawAudio.SampleFormat.serialize() out_rate = @u8_caps.sample_rate out_channel = @u8_caps.channels @@ -78,10 +78,10 @@ defmodule Membrane.FFmpeg.SWResample.ConverterTest do assert %{native: :mock_handle} = new_state - input_fmt = @s16le_caps.format |> Raw.Format.serialize() + input_fmt = @s16le_caps.sample_format |> RawAudio.SampleFormat.serialize() input_rate = @s16le_caps.sample_rate input_channel = @s16le_caps.channels - out_fmt = @u8_caps.format |> Raw.Format.serialize() + out_fmt = @u8_caps.sample_format |> RawAudio.SampleFormat.serialize() out_rate = @u8_caps.sample_rate out_channel = @u8_caps.channels @@ -150,7 +150,7 @@ defmodule Membrane.FFmpeg.SWResample.ConverterTest do assert {{:ok, actions}, ^state} = @module.handle_demand(:output, 2, :buffers, nil, state) buffers_size = - 2 * state.frames_per_buffer * Raw.sample_size(state.input_caps) * + 2 * state.frames_per_buffer * RawAudio.sample_size(state.input_caps) * state.input_caps.channels assert actions == [demand: {:input, buffers_size}]