Skip to content

Commit

Permalink
Adjust to core 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Nov 9, 2023
1 parent a3a43bb commit e843b3c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 27 deletions.
13 changes: 6 additions & 7 deletions lib/deserializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ defmodule Membrane.Element.IVF.Deserializer do
Membrane timebase (it is 1 nanosecond = 1/(10^9)[s])
"""
use Membrane.Filter
use Ratio
use Numbers, overload_operators: true

alias Membrane.Element.IVF.Headers
alias Membrane.Element.IVF.Headers.FrameHeader
alias Membrane.{Buffer, RemoteStream, Time}
alias Membrane.{VP8, VP9}

def_input_pad :input, accepted_format: _any, demand_mode: :auto, demand_unit: :buffers
def_input_pad :input, accepted_format: _any

def_output_pad :output,
accepted_format:
%RemoteStream{content_format: format, type: :packetized} when format in [VP9, VP8],
demand_mode: :auto
%RemoteStream{content_format: format, type: :packetized} when format in [VP9, VP8]

defmodule State do
@moduledoc false
Expand All @@ -37,12 +36,12 @@ defmodule Membrane.Element.IVF.Deserializer do
@impl true
def handle_stream_format(_pad, _stream_format, _ctx, state) do
# ignore incoming stream_format, we will send our own
# in handle_process
# in handle_buffer
{[], state}
end

@impl true
def handle_process(:input, buffer, _ctx, %State{start_of_stream?: true} = state) do
def handle_buffer(:input, buffer, _ctx, %State{start_of_stream?: true} = state) do
state = %State{state | frame_acc: state.frame_acc <> buffer.payload}

with {:ok, file_header, rest} <- Headers.parse_ivf_header(state.frame_acc),
Expand All @@ -68,7 +67,7 @@ defmodule Membrane.Element.IVF.Deserializer do
end
end

def handle_process(:input, buffer, _ctx, state) do
def handle_buffer(:input, buffer, _ctx, state) do
state = %State{state | frame_acc: state.frame_acc <> buffer.payload}

case flush_acc(state, []) do
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane_element_ivf/headers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Membrane.Element.IVF.Headers do

@spec create_ivf_frame_header(integer, number | Ratio.t(), number | Ratio.t()) :: binary
def create_ivf_frame_header(size, timestamp, timebase) do
ivf_timestamp = Membrane.Time.round_to_timebase(timestamp, Membrane.Time.seconds(timebase))
ivf_timestamp = Membrane.Time.divide_by_timebase(timestamp, Membrane.Time.seconds(timebase))
# conversion to little-endian binary strings
size_le = <<size::32-little>>
timestamp_le = <<ivf_timestamp::64-little>>
Expand Down
7 changes: 4 additions & 3 deletions lib/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ defmodule Membrane.Element.IVF.Serializer do
def_input_pad :input,
accepted_format:
%RemoteStream{content_format: format, type: :packetized} when format in [VP9, VP8],
flow_control: :manual,
demand_unit: :buffers

def_output_pad :output, accepted_format: _any
def_output_pad :output, flow_control: :manual, accepted_format: _any

defmodule State do
@moduledoc false
Expand All @@ -29,7 +30,7 @@ defmodule Membrane.Element.IVF.Serializer do

@impl true
def handle_init(_ctx, options) do
use Ratio
use Numbers, overload_operators: true

{[],
%State{
Expand All @@ -47,7 +48,7 @@ defmodule Membrane.Element.IVF.Serializer do
end

@impl true
def handle_process(:input, buffer, ctx, state) do
def handle_buffer(:input, buffer, ctx, state) do
%Buffer{payload: frame, pts: timestamp} = buffer

ivf_frame =
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Membrane.IVF.Plugin.MixProject do
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:dialyxir, ">= 0.0.0", only: :dev, runtime: false},
{:credo, ">= 0.0.0", only: :dev, runtime: false},
{:membrane_file_plugin, "~> 0.13.0", only: :test}
{:membrane_file_plugin, "~> 0.16.0", only: :test}
]
end

Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"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.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"membrane_core": {:hex, :membrane_core, "0.12.1", "aa98c9ef66d109ea9f0395df8d12434d255941cbfe51c154e5fd49d3488a1dfc", [:mix], [{:bunch, "~> 1.6", [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", "94469345cd55c3bca98c5aa14e56812d1e8aad2eaa63f217be45a51c556bbc3f"},
"membrane_file_plugin": {:hex, :membrane_file_plugin, "0.13.3", "aaf40a72e5fccf6da47ec85ef525234acbec828425f1300f74c464bca1487f40", [:mix], [{:membrane_core, "~> 0.11", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "1c1acf610d4fc0279b7fd65a5db06c8bc3ef6a276bf40fb033c2c735c25839ba"},
"membrane_core": {:hex, :membrane_core, "1.0.0", "1b543aefd952283be1f2a215a1db213aa4d91222722ba03cd35280622f1905ee", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 3.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "352c90fd0a29942143c4bf7a727cc05c632e323f50a1a4e99321b1e8982f1533"},
"membrane_file_plugin": {:hex, :membrane_file_plugin, "0.16.0", "7917f6682c22b9bcfc2ca20ed960eee0f7d03ad31fd5f59ed850f1fe3ddd545a", [:mix], [{:membrane_core, "~> 1.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "b0727998f75a9b4dab8a2baefdfc13c3eac00a04e061ab1b0e61dc5566927acc"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"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"},
"qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"},
"ratio": {:hex, :ratio, "2.4.2", "c8518f3536d49b1b00d88dd20d49f8b11abb7819638093314a6348139f14f9f9", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:numbers, "~> 5.2.0", [hex: :numbers, repo: "hexpm", optional: false]}], "hexpm", "441ef6f73172a3503de65ccf1769030997b0d533b1039422f1e5e0e0b4cbf89e"},
"ratio": {:hex, :ratio, "3.0.2", "60a5976872a4dc3d873ecc57eed1738589e99d1094834b9c935b118231297cfb", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:numbers, "~> 5.2.0", [hex: :numbers, repo: "hexpm", optional: false]}], "hexpm", "3a13ed5a30ad0bfd7e4a86bf86d93d2b5a06f5904417d38d3f3ea6406cdfc7bb"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
}
6 changes: 2 additions & 4 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Membrane.Element.IVF.IntegrationTest do
|> child(:file_sink, %Membrane.File.Sink{location: options.result_file})
]

{[spec: spec, playback: :playing], %{}}
{[spec: spec], %{}}
end

@impl true
Expand Down Expand Up @@ -63,11 +63,9 @@ defmodule Membrane.Element.IVF.IntegrationTest do
]
|> Testing.Pipeline.start_link_supervised!()

assert_pipeline_play(pipeline)

assert_end_of_stream(pipeline, :file_sink)

Testing.Pipeline.terminate(pipeline, blocking?: true)
Testing.Pipeline.terminate(pipeline)

assert File.read!(input.path) ==
File.read!(result_file)
Expand Down
12 changes: 4 additions & 8 deletions test/serializer_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.Element.IVF.SerializerTest do
use ExUnit.Case
use Ratio
use Numbers, overload_operators: true

import Membrane.Testing.Assertions

Expand Down Expand Up @@ -33,7 +33,7 @@ defmodule Membrane.Element.IVF.SerializerTest do
|> child(:sink, sink)
]

{[spec: spec, playback: :playing], %{}}
{[spec: spec], %{}}
end

@impl true
Expand Down Expand Up @@ -64,8 +64,6 @@ defmodule Membrane.Element.IVF.SerializerTest do
]
|> Testing.Pipeline.start_supervised!()

assert_pipeline_play(pipeline)

assert_start_of_stream(pipeline, :sink)

assert_sink_buffer(pipeline, :sink, ivf_buffer)
Expand Down Expand Up @@ -107,7 +105,7 @@ defmodule Membrane.Element.IVF.SerializerTest do

assert_end_of_stream(pipeline, :sink)

Testing.Pipeline.terminate(pipeline, blocking?: true)
Testing.Pipeline.terminate(pipeline)
end

test "serialize real vp9 buffers" do
Expand All @@ -124,15 +122,13 @@ defmodule Membrane.Element.IVF.SerializerTest do
]
|> Testing.Pipeline.start_supervised!()

assert_pipeline_play(pipeline)

assert_start_of_stream(pipeline, :sink)

assert_end_of_stream(pipeline, :sink)

assert File.read!(@results_dir <> @result_file) ==
File.read!(@fixtures_dir <> @input_file)

Testing.Pipeline.terminate(pipeline, blocking?: true)
Testing.Pipeline.terminate(pipeline)
end
end

0 comments on commit e843b3c

Please sign in to comment.