Skip to content
Open
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
15 changes: 10 additions & 5 deletions RMS/ConfigReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,16 +1107,21 @@ def parseCapture(config, parser):
pass

if parser.has_option(section, "protocol"):
config.protocol = parser.get(section, "protocol")
config.protocol = parser.get(section, "protocol").strip().lower()

if parser.has_option(section, "udp_buffer_size"):
config.udp_buffer_size = parser.getint(section, "udp_buffer_size")

if parser.has_option(section, "media_backend"):
config.media_backend = parser.get(section, "media_backend")
config.media_backend = parser.get(section, "media_backend").strip().lower()

if parser.has_option(section, "gst_colorspace"):
config.gst_colorspace = parser.get(section, "gst_colorspace")
gst_colorspace = parser.get(section, "gst_colorspace").strip()

# Normalize the formats explicitly supported by RMS, while preserving the case of other
# GStreamer formats (e.g. RGBx and v210) whose canonical names are case-sensitive.
supported_gst_colorspaces = {'bgr': 'BGR', 'gray8': 'GRAY8'}
config.gst_colorspace = supported_gst_colorspaces.get(gst_colorspace.lower(), gst_colorspace)

if parser.has_option(section, "gst_decoder"):
config.gst_decoder = parser.get(section, "gst_decoder")
Expand Down Expand Up @@ -1225,7 +1230,7 @@ def parseCapture(config, parser):
config.save_frames = save_requested

if parser.has_option(section, "frame_file_type"):
config.frame_file_type = parser.get(section, "frame_file_type")
config.frame_file_type = parser.get(section, "frame_file_type").strip().lower()

# Load the JPEG quality
if parser.has_option(section, "jpgs_quality"):
Expand All @@ -1252,7 +1257,7 @@ def parseCapture(config, parser):

# Set whether to delete, archive, or leave saved frames after making timelapse ('delete', 'tar', 'none')
if parser.has_option(section, "frame_cleanup"):
config.frame_cleanup = parser.get(section, "frame_cleanup")
config.frame_cleanup = parser.get(section, "frame_cleanup").strip().lower()

# Enable/disable showing a slideshow of last night's meteor detections on the screen during the day
if parser.has_option(section, "slideshow_enable"):
Expand Down
47 changes: 47 additions & 0 deletions Tests/test_ConfigReader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Focused tests for capture option parsing."""

import pytest

from RMS import ConfigReader as cr


def _parseCaptureOptions(monkeypatch, tmp_path, options):
"""Parse a minimal Capture section with the supplied options."""
parser = cr.RawConfigParser()
parser.add_section('Capture')
parser.set('Capture', 'save_frames', 'false')

for option, value in options.items():
parser.set('Capture', option, value)

config = cr.Config()
config.config_file_path = str(tmp_path)
monkeypatch.setattr(cr, 'isFfmpegWorking', lambda: False)
cr.parseCapture(config, parser)

return config


def testCaptureEnumOptionsAreNormalized(monkeypatch, tmp_path):
config = _parseCaptureOptions(monkeypatch, tmp_path, {
'protocol': ' UDP ',
'media_backend': ' GST ',
'gst_colorspace': ' gray8 ',
'frame_file_type': ' PNG ',
'frame_cleanup': ' Delete ',
})

assert config.protocol == 'udp'
assert config.media_backend == 'gst'
assert config.gst_colorspace == 'GRAY8'
assert config.frame_file_type == 'png'
assert config.frame_cleanup == 'delete'


@pytest.mark.parametrize('gst_colorspace', ['RGBx', 'xRGB', 'v210', 'r210'])
def testCapturePreservesCanonicalGstColorspaceCase(monkeypatch, tmp_path, gst_colorspace):
config = _parseCaptureOptions(monkeypatch, tmp_path, {
'gst_colorspace': ' {} '.format(gst_colorspace),
})

assert config.gst_colorspace == gst_colorspace