2019-01-13 11:37:15 +00:00
|
|
|
"""
|
|
|
|
- Test Output classes.
|
|
|
|
- Integration tests (see conftest.py).
|
|
|
|
"""
|
2019-01-18 07:04:36 +00:00
|
|
|
import errno
|
2018-12-23 21:18:56 +00:00
|
|
|
import shutil
|
2018-11-25 12:43:43 +00:00
|
|
|
from fractions import Fraction
|
2018-08-27 11:55:36 +00:00
|
|
|
from pathlib import Path
|
2018-08-18 08:46:33 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2019-05-08 11:57:17 +00:00
|
|
|
import attr
|
2018-08-18 08:46:33 +00:00
|
|
|
import pytest
|
2018-08-18 09:16:01 +00:00
|
|
|
|
2018-12-20 10:31:55 +00:00
|
|
|
from corrscope.channel import ChannelConfig
|
2019-06-03 00:49:16 +00:00
|
|
|
from corrscope.corrscope import template_config, Config, CorrScope, Arguments
|
2019-01-03 08:57:30 +00:00
|
|
|
from corrscope.outputs import (
|
|
|
|
FFmpegOutput,
|
|
|
|
FFmpegOutputConfig,
|
|
|
|
FFplayOutput,
|
|
|
|
FFplayOutputConfig,
|
2019-01-18 07:04:36 +00:00
|
|
|
Stop,
|
2019-01-03 08:57:30 +00:00
|
|
|
)
|
2020-04-20 22:20:45 +00:00
|
|
|
from corrscope.renderer import RendererConfig, Renderer, RenderInput
|
2019-02-18 10:10:17 +00:00
|
|
|
from tests.test_renderer import RENDER_Y_ZEROS, WIDTH, HEIGHT
|
2019-01-20 07:29:03 +00:00
|
|
|
|
2018-08-18 08:46:33 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
import pytest_mock
|
|
|
|
|
2018-12-23 21:18:56 +00:00
|
|
|
|
2019-05-08 11:57:17 +00:00
|
|
|
parametrize = pytest.mark.parametrize
|
2019-04-11 14:57:05 +00:00
|
|
|
BYTES_PER_PIXEL = Renderer.bytes_per_pixel
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Global setup
|
2019-01-03 08:57:30 +00:00
|
|
|
if not shutil.which("ffmpeg"):
|
2019-02-18 04:17:15 +00:00
|
|
|
pytestmark = pytest.mark.xfail(
|
|
|
|
reason="Missing ffmpeg, ignoring failed output tests",
|
|
|
|
raises=FileNotFoundError, # includes MissingFFmpegError
|
|
|
|
strict=False,
|
|
|
|
)
|
2018-12-23 21:18:56 +00:00
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
class DummyException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-01-18 05:33:03 +00:00
|
|
|
NULL_FFMPEG_OUTPUT = FFmpegOutputConfig(None, "-f null")
|
|
|
|
|
2019-01-20 07:29:03 +00:00
|
|
|
render_cfg = RendererConfig(WIDTH, HEIGHT)
|
2019-06-03 00:49:16 +00:00
|
|
|
CFG = template_config(render=render_cfg)
|
2019-01-18 05:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def sine440_config():
|
2019-06-03 00:49:16 +00:00
|
|
|
cfg = template_config(
|
2019-01-18 05:33:03 +00:00
|
|
|
channels=[ChannelConfig("tests/sine440.wav")],
|
|
|
|
master_audio="tests/sine440.wav",
|
|
|
|
end_time=0.5, # Reduce test duration
|
2019-01-20 07:29:03 +00:00
|
|
|
render=render_cfg,
|
2019-01-18 05:33:03 +00:00
|
|
|
)
|
|
|
|
return cfg
|
2018-08-18 08:46:33 +00:00
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
## Begin tests
|
|
|
|
# Calls MatplotlibRenderer, FFmpegOutput, FFmpeg.
|
2018-08-18 08:46:33 +00:00
|
|
|
def test_render_output():
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure rendering to output does not raise exceptions."""
|
2019-04-04 11:13:21 +00:00
|
|
|
datas = [RENDER_Y_ZEROS]
|
|
|
|
|
2023-12-01 07:52:18 +00:00
|
|
|
renderer = Renderer.from_obj(CFG.render, CFG.layout, datas, None, None)
|
2019-01-18 05:33:03 +00:00
|
|
|
out: FFmpegOutput = NULL_FFMPEG_OUTPUT(CFG)
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2022-03-10 13:49:17 +00:00
|
|
|
renderer.update_main_lines(RenderInput.wrap_datas(datas), [0])
|
2018-08-18 08:46:33 +00:00
|
|
|
out.write_frame(renderer.get_frame())
|
|
|
|
|
|
|
|
assert out.close() == 0
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Calls FFmpegOutput and FFmpeg.
|
2018-08-18 08:46:33 +00:00
|
|
|
def test_output():
|
2019-01-18 05:33:03 +00:00
|
|
|
out: FFmpegOutput = NULL_FFMPEG_OUTPUT(CFG)
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2019-04-07 16:10:15 +00:00
|
|
|
frame = bytes(WIDTH * HEIGHT * BYTES_PER_PIXEL)
|
2018-08-18 08:46:33 +00:00
|
|
|
out.write_frame(frame)
|
|
|
|
|
|
|
|
assert out.close() == 0
|
2018-08-27 11:55:36 +00:00
|
|
|
# Ensure video is written to stdout, and not current directory.
|
2019-01-03 08:57:30 +00:00
|
|
|
assert not Path("-").exists()
|
2018-08-18 08:46:33 +00:00
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
## Ensure CorrScope closes pipe to output upon completion.
|
|
|
|
# Calls FFplayOutput, mocks Popen.
|
2019-01-03 08:57:30 +00:00
|
|
|
@pytest.mark.usefixtures("Popen")
|
2018-08-29 08:08:05 +00:00
|
|
|
def test_close_output(Popen):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""FFplayOutput unit test: Ensure ffmpeg and ffplay are terminated when Python
|
2018-08-29 08:08:05 +00:00
|
|
|
exceptions occur.
|
|
|
|
"""
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2018-08-29 08:08:05 +00:00
|
|
|
ffplay_cfg = FFplayOutputConfig()
|
|
|
|
output: FFplayOutput
|
|
|
|
with ffplay_cfg(CFG) as output:
|
|
|
|
pass
|
|
|
|
|
|
|
|
output._pipeline[0].stdin.close.assert_called()
|
|
|
|
for popen in output._pipeline:
|
|
|
|
popen.wait.assert_called() # Does wait() need to be called?
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2018-08-29 08:08:05 +00:00
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Calls CorrScope, mocks FFmpegOutput.
|
2019-01-18 05:33:03 +00:00
|
|
|
def test_corrscope_main_uses_contextmanager(mocker: "pytest_mock.MockFixture"):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure CorrScope() main wraps output in context manager."""
|
2019-01-18 05:33:03 +00:00
|
|
|
FFmpegOutput = mocker.patch.object(FFmpegOutputConfig, "cls")
|
|
|
|
output = FFmpegOutput.return_value
|
|
|
|
|
|
|
|
cfg = sine440_config()
|
|
|
|
cfg.master_audio = None
|
|
|
|
corr = CorrScope(cfg, Arguments(".", [NULL_FFMPEG_OUTPUT]))
|
|
|
|
corr.play()
|
|
|
|
|
|
|
|
FFmpegOutput.assert_called()
|
|
|
|
output.__enter__.assert_called()
|
|
|
|
output.__exit__.assert_called()
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Calls FFplayOutput, mocks Popen.
|
2019-01-03 08:57:30 +00:00
|
|
|
@pytest.mark.usefixtures("Popen")
|
2018-08-18 08:46:33 +00:00
|
|
|
def test_terminate_ffplay(Popen):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""FFplayOutput unit test: Ensure ffmpeg and ffplay are terminated when Python
|
2018-08-18 08:46:33 +00:00
|
|
|
exceptions occur.
|
|
|
|
"""
|
|
|
|
|
|
|
|
ffplay_cfg = FFplayOutputConfig()
|
|
|
|
try:
|
|
|
|
output: FFplayOutput
|
|
|
|
with ffplay_cfg(CFG) as output:
|
|
|
|
raise DummyException
|
|
|
|
|
|
|
|
except DummyException:
|
|
|
|
for popen in output._pipeline:
|
|
|
|
popen.terminate.assert_called()
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Integration: Calls CorrScope, mocks Popen.
|
2019-01-03 08:57:30 +00:00
|
|
|
@pytest.mark.usefixtures("Popen")
|
|
|
|
def test_corr_terminate_ffplay(Popen, mocker: "pytest_mock.MockFixture"):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Integration test: Ensure corrscope calls terminate() on ffmpeg and ffplay when
|
|
|
|
Python exceptions occur."""
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2018-11-25 12:43:43 +00:00
|
|
|
cfg = sine440_config()
|
2019-01-03 08:57:30 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", [FFplayOutputConfig()]))
|
2018-08-18 09:16:01 +00:00
|
|
|
|
2019-04-11 14:57:05 +00:00
|
|
|
update_main_lines = mocker.patch.object(Renderer, "update_main_lines")
|
2019-04-04 11:13:21 +00:00
|
|
|
update_main_lines.side_effect = DummyException()
|
2018-08-18 08:46:33 +00:00
|
|
|
with pytest.raises(DummyException):
|
2018-12-20 10:31:55 +00:00
|
|
|
corr.play()
|
2018-08-18 08:46:33 +00:00
|
|
|
|
2018-12-20 10:31:55 +00:00
|
|
|
assert len(corr.outputs) == 1
|
|
|
|
output: FFplayOutput = corr.outputs[0]
|
2018-08-18 08:46:33 +00:00
|
|
|
|
|
|
|
for popen in output._pipeline:
|
|
|
|
popen.terminate.assert_called()
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
# Integration: Calls CorrScope and FFplay.
|
2019-05-08 11:57:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@attr.dataclass(kw_only=True)
|
|
|
|
class TestMode:
|
|
|
|
should_abort: bool = False
|
|
|
|
should_raise: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
@parametrize(
|
|
|
|
"test", [TestMode(should_abort=True), TestMode(should_raise=True)], ids=str
|
|
|
|
)
|
|
|
|
def test_corr_terminate_works(test):
|
|
|
|
"""
|
|
|
|
Ensure that output exits quickly after output.terminate() is called.
|
|
|
|
|
|
|
|
What calls output.terminate() -> popen.terminate()?
|
|
|
|
|
|
|
|
- Cancelling a GUI render sets is_aborted()=True.
|
|
|
|
- corrscope may throw an exception.
|
|
|
|
|
|
|
|
Either way, ffmpeg should be terminated so it stops writing audio.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
from corrscope.outputs import IOutputConfig, register_output, PipeOutput
|
|
|
|
|
|
|
|
class StayOpenOutputConfig(IOutputConfig):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@register_output(StayOpenOutputConfig)
|
|
|
|
class StayOpenOutput(PipeOutput):
|
|
|
|
def __init__(self, corr_cfg: "Config", cfg: StayOpenOutputConfig):
|
|
|
|
super().__init__(corr_cfg, cfg)
|
|
|
|
|
|
|
|
sleep_process = subprocess.Popen(
|
|
|
|
[sys.executable, "-c", "import time; time.sleep(10)"],
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
)
|
|
|
|
self.open(sleep_process)
|
|
|
|
|
|
|
|
def is_aborted() -> bool:
|
|
|
|
if test.should_raise:
|
|
|
|
raise DummyException
|
|
|
|
return test.should_abort
|
2018-08-28 10:03:19 +00:00
|
|
|
|
2018-11-25 12:43:43 +00:00
|
|
|
cfg = sine440_config()
|
2019-05-08 11:57:17 +00:00
|
|
|
arg = Arguments(".", [StayOpenOutputConfig()], is_aborted=is_aborted)
|
|
|
|
corr = CorrScope(cfg, arg)
|
2018-08-28 10:03:19 +00:00
|
|
|
|
2019-05-08 11:57:17 +00:00
|
|
|
if test.should_raise:
|
|
|
|
with pytest.raises(DummyException):
|
|
|
|
# Raises `subprocess.TimeoutExpired` if popen.terminate() doesn't work.
|
|
|
|
corr.play()
|
|
|
|
|
|
|
|
else:
|
2018-08-28 10:03:19 +00:00
|
|
|
# Raises `subprocess.TimeoutExpired` if popen.terminate() doesn't work.
|
2018-12-20 10:31:55 +00:00
|
|
|
corr.play()
|
2018-08-28 10:03:19 +00:00
|
|
|
|
|
|
|
|
2019-01-18 07:04:36 +00:00
|
|
|
# Simulate user closing ffplay window.
|
|
|
|
# Why OSError? See comment at PipeOutput.write_frame().
|
2019-01-20 05:24:39 +00:00
|
|
|
# Calls FFplayOutput, mocks Popen.
|
2019-05-08 11:57:17 +00:00
|
|
|
@pytest.mark.usefixtures("Popen")
|
2019-01-18 07:04:36 +00:00
|
|
|
@pytest.mark.parametrize("errno_id", [errno.EPIPE, errno.EINVAL])
|
2019-05-08 11:57:17 +00:00
|
|
|
def test_closing_ffplay_stops_main(Popen, errno_id):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Closing FFplay should make FFplayOutput.write_frame() return Stop
|
|
|
|
to main loop."""
|
2019-01-18 07:04:36 +00:00
|
|
|
|
|
|
|
# Create mocks.
|
|
|
|
exc = OSError(errno_id, "Simulated ffplay-closed error")
|
|
|
|
if errno_id == errno.EPIPE:
|
|
|
|
assert type(exc) == BrokenPipeError
|
|
|
|
|
2019-05-08 11:57:17 +00:00
|
|
|
Popen.set_exception(exc)
|
2019-01-18 07:04:36 +00:00
|
|
|
assert Popen.side_effect
|
|
|
|
|
|
|
|
# Launch corrscope
|
|
|
|
with FFplayOutputConfig()(CFG) as output:
|
2019-05-08 11:57:17 +00:00
|
|
|
# Writing to Popen instance raises exc.
|
2019-01-18 07:04:36 +00:00
|
|
|
ret = output.write_frame(b"")
|
|
|
|
|
|
|
|
# Ensure FFplayOutput catches OSError.
|
|
|
|
# Also ensure it returns Stop after exception.
|
|
|
|
assert ret is Stop, ret
|
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
## Integration tests (calls CorrScope and FFmpeg).
|
|
|
|
# Duplicate test test_no_audio() removed.
|
2018-12-20 10:31:55 +00:00
|
|
|
def test_corr_output_without_audio():
|
|
|
|
"""Ensure running CorrScope with FFmpeg output, with master audio disabled,
|
2018-11-25 12:43:43 +00:00
|
|
|
does not crash.
|
|
|
|
"""
|
|
|
|
cfg = sine440_config()
|
|
|
|
cfg.master_audio = None
|
|
|
|
|
2019-01-18 05:33:03 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", [NULL_FFMPEG_OUTPUT]))
|
2018-11-25 12:43:43 +00:00
|
|
|
# Should not raise exception.
|
2018-12-20 10:31:55 +00:00
|
|
|
corr.play()
|
2018-11-25 12:43:43 +00:00
|
|
|
|
|
|
|
|
2019-01-18 07:04:36 +00:00
|
|
|
# Test framerate subsampling
|
2018-11-25 12:43:43 +00:00
|
|
|
def test_render_subfps_one():
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure video gets rendered when render_subfps=1.
|
2018-11-25 12:43:43 +00:00
|
|
|
This test fails if ceildiv is used to calculate `ahead`.
|
|
|
|
"""
|
2018-12-20 10:31:55 +00:00
|
|
|
from corrscope.outputs import IOutputConfig, Output, register_output
|
2018-11-25 12:43:43 +00:00
|
|
|
|
|
|
|
# region DummyOutput
|
|
|
|
class DummyOutputConfig(IOutputConfig):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@register_output(DummyOutputConfig)
|
|
|
|
class DummyOutput(Output):
|
|
|
|
frames_written = 0
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def write_frame(cls, frame: bytes) -> None:
|
|
|
|
cls.frames_written += 1
|
|
|
|
|
|
|
|
assert DummyOutput
|
|
|
|
# endregion
|
|
|
|
|
2018-12-20 10:31:55 +00:00
|
|
|
# Create CorrScope with render_subfps=1. Ensure multiple frames are outputted.
|
2018-11-25 12:43:43 +00:00
|
|
|
cfg = sine440_config()
|
|
|
|
cfg.render_subfps = 1
|
|
|
|
|
2019-01-03 08:57:30 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", [DummyOutputConfig()]))
|
2018-12-20 10:31:55 +00:00
|
|
|
corr.play()
|
2018-11-25 12:43:43 +00:00
|
|
|
assert DummyOutput.frames_written >= 2
|
|
|
|
|
|
|
|
|
2019-01-03 08:57:30 +00:00
|
|
|
def test_render_subfps_non_integer(mocker: "pytest_mock.MockFixture"):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure we output non-integer subfps as fractions,
|
2018-11-25 12:43:43 +00:00
|
|
|
and that ffmpeg doesn't crash.
|
|
|
|
TODO does ffmpeg understand decimals??
|
|
|
|
"""
|
|
|
|
|
|
|
|
cfg = sine440_config()
|
|
|
|
cfg.fps = 60
|
|
|
|
cfg.render_subfps = 7
|
|
|
|
|
|
|
|
# By default, we output render_fps (ffmpeg -framerate) as a fraction.
|
|
|
|
assert isinstance(cfg.render_fps, Fraction)
|
|
|
|
assert cfg.render_fps != int(cfg.render_fps)
|
|
|
|
assert Fraction(1) == int(1)
|
|
|
|
|
2019-01-18 05:33:03 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", [NULL_FFMPEG_OUTPUT]))
|
2018-12-20 10:31:55 +00:00
|
|
|
corr.play()
|
2018-11-25 12:43:43 +00:00
|
|
|
|
|
|
|
# But it seems FFmpeg actually allows decimal -framerate (although a bad idea).
|
2018-12-20 10:31:55 +00:00
|
|
|
# from corrscope.corrscope import Config
|
2018-11-25 12:43:43 +00:00
|
|
|
# render_fps = mocker.patch.object(Config, 'render_fps',
|
|
|
|
# new_callable=mocker.PropertyMock)
|
|
|
|
# render_fps.return_value = 60 / 7
|
|
|
|
# assert isinstance(cfg.render_fps, float)
|
2019-01-18 05:33:03 +00:00
|
|
|
# corr = CorrScope(cfg, '.', outputs=[NULL_FFMPEG_OUTPUT])
|
2018-12-20 10:31:55 +00:00
|
|
|
# corr.play()
|
2018-11-25 12:43:43 +00:00
|
|
|
|
2018-08-24 08:21:05 +00:00
|
|
|
|
2018-11-25 12:43:43 +00:00
|
|
|
# Possibility: add a test to ensure that we render slightly ahead in time
|
|
|
|
# when subfps>1, to avoid frames lagging behind audio.
|
2018-08-24 08:21:05 +00:00
|
|
|
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
## Tests for Output-dependent performance options
|
|
|
|
def cfg_192x108():
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Return config which reduces rendering workload when previewing."""
|
2019-01-13 11:37:15 +00:00
|
|
|
cfg = sine440_config()
|
|
|
|
|
|
|
|
# Skip frames.
|
|
|
|
assert cfg.end_time == 0.5
|
|
|
|
cfg.render_subfps = 2
|
|
|
|
|
|
|
|
# Divide dimensions.
|
|
|
|
cfg.render.width = 192
|
|
|
|
cfg.render.height = 108
|
|
|
|
cfg.render.res_divisor = 1.5
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
|
|
|
|
|
|
|
|
def previews_records(mocker):
|
2019-01-20 05:24:39 +00:00
|
|
|
"""Returns 2 lists of method MagicMock."""
|
2019-01-13 11:37:15 +00:00
|
|
|
configs = (Config, RendererConfig)
|
|
|
|
|
|
|
|
previews = [mocker.spy(cls, "before_preview") for cls in configs]
|
|
|
|
records = [mocker.spy(cls, "before_record") for cls in configs]
|
|
|
|
return previews, records
|
|
|
|
|
|
|
|
|
|
|
|
NO_FFMPEG = [[], [FFplayOutputConfig()]]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("Popen") # Prevents FFplayOutput from launching processes.
|
|
|
|
@pytest.mark.parametrize("outputs", NO_FFMPEG)
|
|
|
|
def test_preview_performance(Popen, mocker: "pytest_mock.MockFixture", outputs):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure performance optimizations enabled
|
|
|
|
if all outputs are FFplay or others."""
|
2019-04-11 14:57:05 +00:00
|
|
|
get_frame = mocker.spy(Renderer, "get_frame")
|
2019-01-13 11:37:15 +00:00
|
|
|
previews, records = previews_records(mocker)
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
cfg = cfg_192x108()
|
2019-01-13 11:37:15 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", outputs))
|
2019-04-08 12:23:01 +00:00
|
|
|
|
|
|
|
# Run corrscope main loop.
|
2019-01-13 11:37:15 +00:00
|
|
|
corr.play()
|
|
|
|
|
|
|
|
# Check that only before_preview() called.
|
|
|
|
for p in previews:
|
|
|
|
p.assert_called()
|
|
|
|
for r in records:
|
|
|
|
r.assert_not_called()
|
|
|
|
|
|
|
|
# Check renderer is 128x72
|
2019-04-08 12:23:01 +00:00
|
|
|
assert corr.renderer.w == 128
|
|
|
|
assert corr.renderer.h == 72
|
2019-01-13 11:37:15 +00:00
|
|
|
|
|
|
|
# Ensure subfps is enabled (only odd frames are rendered, 1..29).
|
|
|
|
# See CorrScope `should_render` variable.
|
|
|
|
assert (
|
|
|
|
get_frame.call_count == round(cfg.end_time * cfg.fps / cfg.render_subfps) == 15
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
YES_FFMPEG = [l + [FFmpegOutputConfig(None)] for l in NO_FFMPEG]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("Popen")
|
|
|
|
@pytest.mark.parametrize("outputs", YES_FFMPEG)
|
|
|
|
def test_record_performance(Popen, mocker: "pytest_mock.MockFixture", outputs):
|
2021-06-14 22:09:24 +00:00
|
|
|
"""Ensure performance optimizations disabled
|
|
|
|
if any FFmpegOutputConfig is found."""
|
2019-04-11 14:57:05 +00:00
|
|
|
get_frame = mocker.spy(Renderer, "get_frame")
|
2019-01-13 11:37:15 +00:00
|
|
|
previews, records = previews_records(mocker)
|
|
|
|
|
2019-01-20 05:24:39 +00:00
|
|
|
cfg = cfg_192x108()
|
2019-01-13 11:37:15 +00:00
|
|
|
corr = CorrScope(cfg, Arguments(".", outputs))
|
|
|
|
corr.play()
|
|
|
|
|
|
|
|
# Check that only before_record() called.
|
|
|
|
for p in previews:
|
|
|
|
p.assert_not_called()
|
|
|
|
for r in records:
|
|
|
|
r.assert_called()
|
|
|
|
|
|
|
|
# Check renderer is 192x108
|
|
|
|
assert corr.renderer.cfg.width == 192
|
|
|
|
assert corr.renderer.cfg.height == 108
|
|
|
|
|
|
|
|
# Ensure subfps is disabled.
|
|
|
|
assert get_frame.call_count == round(cfg.end_time * cfg.fps) + 1 == 31
|