Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop ignoring timestamps #34

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the following line to your `deps` in `mix.exs`. Run `mix deps.get`.
```elixir
def deps do
[
{:membrane_sdl_plugin, "~> 0.18.1"}
{:membrane_sdl_plugin, "~> 0.18.2"}
]
end
```
Expand Down
34 changes: 20 additions & 14 deletions lib/membrane_sdl/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ defmodule Membrane.SDL.Player do

@impl true
def handle_init(_options, _ctx) do
state = %{cnode: nil, timer_started?: false}
{[latency: @latency], state}
{[latency: @latency], %{cnode: nil, last_pts: nil, last_payload: nil}}
end

@impl true
Expand All @@ -32,9 +31,8 @@ defmodule Membrane.SDL.Player do
end

@impl true
def handle_stream_format(:input, stream_format, ctx, state) do
def handle_stream_format(:input, stream_format, ctx, %{cnode: cnode} = state) do
%{input: input} = ctx.pads
%{cnode: cnode} = state

if !input.stream_format || stream_format == input.stream_format do
:ok = CNode.call(cnode, :create, [stream_format.width, stream_format.height])
Expand All @@ -45,23 +43,31 @@ defmodule Membrane.SDL.Player do
end

@impl true
def handle_start_of_stream(:input, ctx, state) do
use Numbers, overload_operators: true
{nom, denom} = ctx.pads.input.stream_format.framerate
timer = {:demand_timer, Ratio.new(Time.seconds(denom), nom)}

{[demand: :input, start_timer: timer], %{state | timer_started?: true}}
def handle_start_of_stream(:input, _ctx, state) do
{[demand: :input, start_timer: {:demand_timer, :no_interval}], state}
end

@impl true
def handle_buffer(:input, %Buffer{payload: payload}, _ctx, state) do
def handle_buffer(:input, %Buffer{payload: payload, pts: pts}, _ctx, state) do
payload = Membrane.Payload.to_binary(payload)
:ok = CNode.call(state.cnode, :display_frame, [payload])
{[], state}

actions =
case state do
%{last_pts: nil, last_payload: nil} ->
:ok = CNode.call(state.cnode, :display_frame, [payload])

[demand: :input]

%{last_pts: last_pts} ->
[timer_interval: {:demand_timer, pts - last_pts}]
end

{actions, %{state | last_pts: pts, last_payload: payload}}
end

@impl true
def handle_tick(:demand_timer, _ctx, state) do
{[demand: :input], state}
:ok = CNode.call(state.cnode, :display_frame, [state.last_payload])
{[timer_interval: {:demand_timer, :no_interval}, demand: :input], state}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.SDL.Plugin.MixProject do
use Mix.Project

@version "0.18.1"
@version "0.18.2"
@github_url "https://github.com/membraneframework/membrane_sdl_plugin"

def project do
Expand Down