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

Start generating timestamps #53

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions lib/membrane_portaudio_plugin/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Membrane.PortAudio.Source do
accepted_format: %RawAudio{sample_format: format} when format in @sample_formats

def_options endpoint_id: [
spec: integer | :default,
spec: integer() | :default,
default: :default,
description: """
PortAudio device id. Defaults to the default input device.
Expand All @@ -31,7 +31,7 @@ defmodule Membrane.PortAudio.Source do
"""
],
portaudio_buffer_size: [
spec: pos_integer,
spec: pos_integer(),
default: 256,
description: "Size of the PortAudio buffer (in frames)"
],
Expand Down Expand Up @@ -86,7 +86,8 @@ defmodule Membrane.PortAudio.Source do
latency: latency,
sample_format: sample_format,
channels: channels,
sample_rate: sample_rate
sample_rate: sample_rate,
init_time: nil
} = state

endpoint_id = if endpoint_id == :default, do: @pa_no_device, else: endpoint_id
Expand Down Expand Up @@ -118,7 +119,11 @@ defmodule Membrane.PortAudio.Source do

@impl true
def handle_info({:portaudio_payload, payload}, %{playback: :playing}, state) do
{[buffer: {:output, %Buffer{payload: payload}}], state}
time = Membrane.Time.monotonic_time()
init_time = state.init_time || time
buffer = %Buffer{payload: payload, pts: time - init_time}

{[buffer: {:output, buffer}], %{state | init_time: init_time}}
end

@impl true
Expand Down
3 changes: 2 additions & 1 deletion test/membrane_portaudio_plugin/source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Membrane.Portaudio.SourceTest do
channels: 0,
sample_rate: nil,
latency: :high,
native: nil
native: nil,
init_time: nil
}

%{state: state}
Expand Down
Loading