Skip to content

Commit 111c95d

Browse files
gBillalConnorRigby
authored andcommitted
Add tests for sink
1 parent 56a3372 commit 111c95d

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# Ignore .fetch files in case you like to edit your project deps locally.
1414
/.fetch
1515

16+
# Ignore tmp dir used in tests via :tmp_dir tag
17+
/tmp/
18+
1619
# If the VM crashes, it generates a dump, let's ignore it too.
1720
erl_crash.dump
1821

lib/turbojpeg/sink.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ defmodule Turbojpeg.Sink do
6363
else
6464
error ->
6565
raise """
66-
could not create a JPG file
66+
could not create a JPEG file
6767
#{inspect(error)}
6868
"""
6969
end

mix.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ defmodule Turbojpeg.MixProject do
3939
{:ex_doc, "~> 0.24", only: [:test], runtime: false},
4040
{:propcheck, "~> 1.4.0", only: [:test]},
4141
{:mogrify, "~> 0.9.0", only: [:test, :dev]},
42-
{:membrane_raw_video_parser_plugin, "~> 0.11", only: :test},
4342
{:dialyxir, "~> 1.3", only: [:dev], runtime: false}
4443
]
4544
end

mix.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@
44
"bundlex": {:hex, :bundlex, "1.1.1", "e637b79a1eaab1bf019de4100b6db262aa3b660beff0cd2f3617949b1618eeda", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:secure_random, "~> 0.5", [hex: :secure_random, repo: "hexpm", optional: false]}], "hexpm", "1fdfa3d6240baa5a2d5496a86e2e43116f80105e93d9adfd4f1fc75be487ea30"},
55
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
66
"dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"},
7-
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
87
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
98
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
109
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [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", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
1110
"libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"},
1211
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
1312
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
1413
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
15-
"membrane_caps_video_raw": {:hex, :membrane_caps_video_raw, "0.1.0", "6aa751b0c338ea6672540b7ec7ad2be0d23bad931b8a8776757da9b279070a3b", [:mix], [], "hexpm", "3f60d65189bd9e3b0ab77e0ebf2e0c1b04d0fd6f67c546fc1d54d9958c362ce4"},
16-
"membrane_common_c": {:hex, :membrane_common_c, "0.3.0", "eb17da0e469eacb8f4afbfc47752bd80d749397951d971cd1df67332a5cf77c6", [:mix], [{:bundlex, "~> 0.2.0", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.5.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:shmex, "~> 0.2.0", [hex: :shmex, repo: "hexpm", optional: false]}, {:unifex, "~> 0.2.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "4c09fd3d802aa36f65225778b1fe819d63df835ac6c113a2be1222ab454175bb"},
1714
"membrane_core": {:hex, :membrane_core, "0.12.7", "9d3dd564e32768919c1105b4579bd2eef12df7473da5d789185544ae22610e2d", [: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", "321e4009b7068ca04b65daf5c79b8c3772d4286c27d05e50939ec6d9b4d50e59"},
18-
"membrane_element_file": {:hex, :membrane_element_file, "0.3.0", "45a7e5d42f794253752f14d15db3749596f32f44e42cc4e001c6b426915fdf4f", [:mix], [{:membrane_core, "~> 0.5.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:mockery, "~> 2.2", [hex: :mockery, repo: "hexpm", optional: false]}], "hexpm", "a80ad07f8c772c7c420ded2ef67f3fc9c55c736a2cd94a02fb0f33853b83d10e"},
19-
"membrane_element_rawvideo_parser": {:hex, :membrane_element_rawvideo_parser, "0.3.0", "8cb5e6ddeef4fe9a83ff6d2e5155968b2c0079e904147d88daf9b0b6448ea751", [:mix], [{:membrane_caps_video_raw, "~> 0.1.0", [hex: :membrane_caps_video_raw, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.6.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "a2a40bae940042c94d0457bf8bdfa207d5295934120295ce07fbf4f7768c4523"},
20-
"membrane_file_plugin": {:hex, :membrane_file_plugin, "0.14.0", "87f19f5f5afbfbaf2219b8f1d8496534cb9ad01fca74687910bf3f7aa866e244", [:mix], [{:membrane_core, "~> 0.12.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "28956f8d5d87735d499c57f1c24f62aeab71e0211863759e7e695ead966eb433"},
2115
"membrane_raw_video_format": {:hex, :membrane_raw_video_format, "0.3.0", "ba10f475e0814a6fe79602a74536b796047577c7ef5b0e33def27cd344229699", [:mix], [], "hexpm", "2f08760061c8a5386ecf04273480f10e48d25a1a40aa99476302b0bcd34ccb1c"},
22-
"membrane_raw_video_parser_plugin": {:hex, :membrane_raw_video_parser_plugin, "0.11.1", "f73c9b950abb6529ac04e84f7dd2c0da51206bc34f2c65f5bac7c013cb1bff2d", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.12.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_file_plugin, "~> 0.14.0", [hex: :membrane_file_plugin, repo: "hexpm", optional: false]}, {:membrane_raw_video_format, "~> 0.3.0", [hex: :membrane_raw_video_format, repo: "hexpm", optional: false]}], "hexpm", "1e6302119fc1bab7809009d7b2abbc1d9eb08dc90c163efcdb0384de5718ae1d"},
23-
"mockery": {:hex, :mockery, "2.3.1", "a02fd60b10ac9ed37a7a2ecf6786c1f1dd5c75d2b079a60594b089fba32dc087", [:mix], [], "hexpm", "1d0971d88ebf084e962da3f2cfee16f0ea8e04ff73a7710428500d4500b947fa"},
2416
"mogrify": {:hex, :mogrify, "0.9.3", "238c782f00271dace01369ad35ae2e9dd020feee3443b9299ea5ea6bed559841", [:mix], [], "hexpm", "0189b1e1de27455f2b9ae8cf88239cefd23d38de9276eb5add7159aea51731e6"},
2517
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
2618
"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"},

test/turbojpeg/sink_test.exs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
defmodule Turbojpeg.SinkTest do
2+
@moduledoc false
3+
4+
use ExUnit.Case
5+
6+
alias Turbojpeg.Sink
7+
8+
@moduletag :tmp_dir
9+
10+
@stream_format %Membrane.RawVideo{
11+
width: 1920,
12+
height: 1080,
13+
aligned: true,
14+
pixel_format: :I420,
15+
framerate: nil
16+
}
17+
18+
@in_path "fixture/i420.yuv"
19+
@ctx %{pads: %{input: %{stream_format: @stream_format}}}
20+
21+
setup %{tmp_dir: tmp_dir} do
22+
%{out_path: Path.join(tmp_dir, "image.jpeg")}
23+
end
24+
25+
test "write yuv data to a jpeg file", %{out_path: out_path} do
26+
yuv = File.read!(@in_path)
27+
{:ok, jpeg} = Turbojpeg.yuv_to_jpeg(yuv, 1920, 1080, 56, :I420)
28+
29+
assert {[], state} = Sink.handle_init(@ctx, %Sink{filename: out_path, quality: 56})
30+
31+
assert {[], %{width: 1920, height: 1080, format: :I420} = state} =
32+
Sink.handle_stream_format(:input, @stream_format, @ctx, state)
33+
34+
assert {[], _state} = Sink.handle_write(:input, %Membrane.Buffer{payload: yuv}, @ctx, state)
35+
36+
assert File.exists?(out_path)
37+
assert File.read!(out_path) == jpeg
38+
end
39+
40+
test "raise if stream format is updated" do
41+
new_stream_format = get_in(@ctx, [:pads, :input, :stream_format])
42+
assert {[], state} = Sink.handle_init(@ctx, %Sink{filename: ""})
43+
44+
assert_raise RuntimeError, fn ->
45+
Sink.handle_stream_format(
46+
:input,
47+
%Membrane.RawVideo{new_stream_format | height: 1440},
48+
@ctx,
49+
state
50+
)
51+
end
52+
end
53+
end

test/turbojpeg_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
defmodule TurbojpegTest do
2+
@moduledoc false
3+
24
use ExUnit.Case
35
use PropCheck, numtests: 10
46
use Mogrify.Options
57

8+
alias Turbojpeg.JpegHeader
9+
610
@jpeg_header <<255, 216, 255>>
711
@i420_fixture "fixture/i420.yuv"
812
@ff0000_fixture "fixture/ff0000_i444.jpg"
@@ -22,7 +26,7 @@ defmodule TurbojpegTest do
2226

2327
test "get jpeg header" do
2428
jpeg = File.read!(@ff0000_fixture)
25-
{:ok, result} = Turbojpeg.get_jpeg_header(jpeg)
29+
{:ok, %JpegHeader{} = result} = Turbojpeg.get_jpeg_header(jpeg)
2630
assert result.width == 64
2731
assert result.height == 64
2832
assert result.format == :I444

0 commit comments

Comments
 (0)