Skip to content

Commit

Permalink
Fixes for previous work
Browse files Browse the repository at this point in the history
Signed-off-by: Tomi Valkeinen <[email protected]>
  • Loading branch information
tomba committed Jan 8, 2024
1 parent b8e50d7 commit b80b45c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
17 changes: 16 additions & 1 deletion v4l2/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import Enum
import v4l2.uapi

__all__ = [ 'BufType', 'MemType' ]
__all__ = [ 'fourcc_to_str', 'str_to_fourcc', 'BufType', 'MemType' ]

def filepath_for_major_minor(major, minor):
for fname in glob.glob('/dev/video*'):
Expand All @@ -26,6 +26,21 @@ def filepath_for_major_minor(major, minor):

raise Exception(f'No device-node found for ({major},{minor})')

def fourcc_to_str(fourcc: int):
return ''.join((
chr((fourcc >> 0) & 0xff),
chr((fourcc >> 8) & 0xff),
chr((fourcc >> 16) & 0xff),
chr((fourcc >> 24) & 0xff)
))

def str_to_fourcc(s: str):
return \
ord(s[0]) << 0 | \
ord(s[1]) << 8 | \
ord(s[2]) << 16 | \
ord(s[3]) << 24

class BufType(Enum):
VIDEO_CAPTURE = v4l2.uapi.V4L2_BUF_TYPE_VIDEO_CAPTURE
VIDEO_OUTPUT = v4l2.uapi.V4L2_BUF_TYPE_VIDEO_OUTPUT
Expand Down
6 changes: 5 additions & 1 deletion v4l2/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import v4l2.uapi
from .helpers import filepath_for_major_minor

__all__ = [ 'MediaDevice' ]
__all__ = [
'MediaObject', 'MediaEntity', 'MediaInterface', 'MediaPad', 'MediaLink',
'MediaDevice',
'MediaLinkFlag'
]

class MediaTopology:
def __init__(self, topology, entities, interfaces, pads, links) -> None:
Expand Down
4 changes: 2 additions & 2 deletions v4l2/videodev.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_format(self):
fmt = v4l2.uapi.v4l2_format()

if self.has_mplane_capture:
fmt.type = v4l2.BufType.VIDEO_CAPTURE_MPLANE
fmt.type = v4l2.BufType.VIDEO_CAPTURE_MPLANE.value
elif self.has_capture:
fmt.type = v4l2.BufType.VIDEO_CAPTURE
fmt.type = v4l2.BufType.VIDEO_CAPTURE.value
else:
raise NotImplementedError()

Expand Down

0 comments on commit b80b45c

Please sign in to comment.