diff options
Diffstat (limited to 'src/gstreamer/gstlibcameraprovider.cpp')
0 files changed, 0 insertions, 0 deletions
![]() |
index : libcamera/vivid.git | |
libcamera pipeline handler for VIVID | git repository hosting on libcamera.org |
summaryrefslogtreecommitdiff |
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
from typing import Any
import argparse
import binascii
import libcamera as libcam
import libcamera.utils
import sys
import traceback
class CameraContext:
camera: libcam.Camera
id: str
idx: int
opt_stream: str
opt_strict_formats: bool
opt_crc: bool
opt_metadata: bool
opt_save_frames: bool
opt_capture: int
stream_names: dict[libcam.Stream, str]
streams: list[libcam.Stream]
allocator: libcam.FrameBufferAllocator
requests: list[libcam.Request]
reqs_queued: int
reqs_completed: int
last: int = 0
fps: float
def __init__(self, camera, idx):
self.camera = camera
self.idx = idx
self.id = 'cam' + str(idx)
self.reqs_queued = 0
self.reqs_completed = 0
def do_cmd_list_props(self):
print('Properties for', self.id)
for cid, val in self.camera.properties.items():
print('\t{}: {}'.format(cid, val))
def do_cmd_list_controls(self):
print('Controls for', self.id)
for cid, info in self.camera.controls.items():
print('\t{}: {}'.format(cid, info))
def do_cmd_info(self):
print('Stream info for', self.id)
roles = [libcam.StreamRole.Viewfinder]
camconfig = self.camera.generate_configuration(roles)
if camconfig is None:
raise Exception('Generating config failed')
for i, stream_config in enumerate(camconfig):
print('\t{}: {}'.format(i, stream_config))
formats = stream_config.formats
for fmt in formats.pixel_formats:
print('\t * Pixelformat:', fmt, formats.range(fmt))
for size in formats.sizes(fmt):
print('\t -', size)
def acquire(self):
self.camera.acquire()
def release(self):
self.camera.release()
def __parse_streams(self):
streams = []
for stream_desc in self.opt_stream:
stream_opts: dict[str, Any]
stream_opts = {'role': libcam.StreamRole.Viewfinder}
for stream_opt in stream_desc.split(','):
if stream_opt == 0:
continue
arr = stream_opt.split('=')
if len(arr) != 2:
print('Bad stream option', stream_opt)
sys.exit(-1)
key = arr[0]
value = arr[1]
if key in ['width', 'height']:
value = int(value)
elif key == 'role':
rolemap = {
'still': libcam.StreamRole.StillCapture,
'raw': libcam.StreamRole.Raw,
'video': libcam.StreamRole.VideoRecording,
'viewfinder': libcam.StreamRole.Viewfinder,
}
role = rolemap.get(value.lower(), None)
if role is None:
print('Bad stream role', value)
sys.exit(-1)
value = role
elif key == 'pixelformat':
pass
else:
print('Bad stream option key', key)
sys.exit(-1)
stream_opts[key] = value
streams.append(stream_opts)
return streams
def configure(self):
streams = self.__parse_streams()
roles = [opts['role'] for opts in streams]
camconfig = self.camera.generate_configuration(roles)
if camconfig is None:
raise Exception('Generating config failed')