-
Notifications
You must be signed in to change notification settings - Fork 4
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
Forward timestamps #57
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81933ba
pts forward, test
bartkrak 0ac7da5
end of stream pts
bartkrak 58039a7
format
bartkrak c39aa63
refactor
bartkrak bffb6fb
almost there
bartkrak e0285c7
one test fixed
bartkrak 3ccd0bf
might be good
bartkrak f3de578
cleanup, tests adjusted
bartkrak cd2486d
pts test update
bartkrak 7e7c7bb
little refactor
bartkrak d78762e
refactor
bartkrak 1473e39
cosmetic refactor
bartkrak 9ebe020
version bump
bartkrak 1751941
refactor
bartkrak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/membrane_ffmpeg_swresample_plugin/pts_forward_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
defmodule Membrane.FFmpeg.SWResample.PtsForwardTest do | ||
use ExUnit.Case | ||
|
||
import Membrane.ChildrenSpec | ||
import Membrane.Testing.Assertions | ||
|
||
alias Membrane.FFmpeg.SWResample.Converter | ||
alias Membrane.{RawAudio, Testing} | ||
|
||
@pts_multiplier 31_250_000 | ||
|
||
test "pts forward test" do | ||
input_stream_format = %RawAudio{sample_format: :s16le, sample_rate: 16_000, channels: 2} | ||
output_stream_format = %RawAudio{sample_format: :s32le, sample_rate: 32_000, channels: 2} | ||
|
||
# 32 frames * 2048 bytes | ||
fixture_path = "test/fixtures/input_s16le_stereo_16khz.raw" | ||
|
||
spec = [ | ||
child(:source, %Membrane.Testing.Source{output: buffers_from_file(fixture_path)}) | ||
|> child(:resampler, %Converter{ | ||
input_stream_format: input_stream_format, | ||
output_stream_format: output_stream_format | ||
}) | ||
|> child(:sink, Membrane.Testing.Sink) | ||
] | ||
|
||
pipeline = Testing.Pipeline.start_link_supervised!(spec: spec) | ||
assert_sink_buffer(pipeline, :sink, _buffer) | ||
|
||
Enum.each(0..30, fn index -> | ||
assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{pts: out_pts}) | ||
assert out_pts == index * @pts_multiplier | ||
end) | ||
|
||
assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{pts: last_out_pts}) | ||
assert last_out_pts == 30 * @pts_multiplier | ||
|
||
assert_end_of_stream(pipeline, :sink) | ||
Testing.Pipeline.terminate(pipeline) | ||
end | ||
|
||
defp buffers_from_file(path) do | ||
binary = File.read!(path) | ||
|
||
split_binary(binary) | ||
|> Enum.with_index() | ||
|> Enum.map(fn {payload, index} -> | ||
%Membrane.Buffer{ | ||
payload: payload, | ||
pts: index * @pts_multiplier | ||
} | ||
end) | ||
end | ||
|
||
@spec split_binary(binary(), list(binary())) :: list(binary()) | ||
def split_binary(binary, acc \\ []) | ||
|
||
def split_binary(<<binary::binary-size(2048), rest::binary>>, acc) do | ||
split_binary(rest, [binary] ++ acc) | ||
end | ||
|
||
def split_binary(rest, acc) when byte_size(rest) <= 2048 do | ||
Enum.reverse(acc) ++ [rest] | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be hard to have the chunk length differ from buffer to buffer? I guess we could have better coverage that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if it's too much work let's leave it as is