Skip to content

Commit

Permalink
Fix flake8 compliance
Browse files Browse the repository at this point in the history
Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed Oct 3, 2023
1 parent 6fc614d commit d17c008
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 59 deletions.
9 changes: 6 additions & 3 deletions picamera2/allocators/dmaallocator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import fcntl
import logging
import mmap
import os

import libcamera

from picamera2.allocators.allocator import Allocator, Sync
from picamera2.dma_heap import *
from picamera2.dma_heap import (DMA_BUF_IOCTL_SYNC, DMA_BUF_SYNC_END,
DMA_BUF_SYNC_READ, DMA_BUF_SYNC_RW,
DMA_BUF_SYNC_START, DmaHeap, dma_buf_sync)

_log = logging.getLogger("picamera2")

Expand Down Expand Up @@ -47,7 +51,7 @@ def allocate(self, libcamera_config):
plane[0].fd = fd.get()
plane[0].offset = 0
plane[0].length = stream_config.frame_size

self.libcamera_fds.append(plane[0].fd)
self.mapped_buffers_used[plane[0].fd] = False

Expand Down Expand Up @@ -83,7 +87,6 @@ def cleanup(self):
for k in [k for k, v in self.mapped_buffers.items() if v.closed]:
del self.mapped_buffers[k]


class DmaSync(Sync):
"""Dma Buffer Sync"""

Expand Down
42 changes: 0 additions & 42 deletions picamera2/buffer_sync.py

This file was deleted.

25 changes: 15 additions & 10 deletions picamera2/dma_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import fcntl
import logging
import os
from v4l2 import _IOWR, _IOW

from v4l2 import _IOW, _IOWR

_log = logging.getLogger("picamera2")
heapNames = [
Expand All @@ -17,11 +18,12 @@ class dma_buf_sync(ctypes.Structure):
('flags', ctypes.c_uint64),
]

DMA_BUF_SYNC_READ = (1 << 0)
DMA_BUF_SYNC_WRITE = (2 << 0)
DMA_BUF_SYNC_RW = (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE)
DMA_BUF_SYNC_START = (0 << 2)
DMA_BUF_SYNC_END = (1 << 2)

DMA_BUF_SYNC_READ = (1 << 0)
DMA_BUF_SYNC_WRITE = (2 << 0)
DMA_BUF_SYNC_RW = (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE)
DMA_BUF_SYNC_START = (0 << 2)
DMA_BUF_SYNC_END = (1 << 2)

DMA_BUF_BASE = 'b'
DMA_BUF_IOCTL_SYNC = _IOW(DMA_BUF_BASE, 0, dma_buf_sync)
Expand All @@ -38,14 +40,16 @@ class dma_heap_allocation_data(ctypes.Structure):
('heap_flags', ctypes.c_uint64),
]


DMA_HEAP_IOC_MAGIC = 'H'

DMA_HEAP_IOCTL_ALLOC = _IOWR(DMA_HEAP_IOC_MAGIC, 0, dma_heap_allocation_data)


# Libcamera C++ classes
class UniqueFD:
"""Libcamera UniqueFD Class """
"""Libcamera UniqueFD Class"""

def __init__(self, fd=-1):
if isinstance(fd, UniqueFD):
self.__fd = fd.release()
Expand All @@ -56,16 +60,17 @@ def release(self):
fd = self.__fd
self.__fd = -1
return fd

def get(self):
return self.__fd

def isValid(self):
return self.__fd >= 0


class DmaHeap:
"""DmaHeap"""

def __init__(self):
self.__dmaHeapHandle = UniqueFD()
for name in heapNames:
Expand Down Expand Up @@ -100,5 +105,5 @@ def alloc(self, name, size) -> UniqueFD:
if not isinstance(ret, bytes) and ret < 0:
_log.error(f"dmaHeap naming failure for {name}")
return UniqueFD()

return allocFd
1 change: 0 additions & 1 deletion picamera2/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import picamera2.formats as formats

from .controls import Controls
from .buffer_sync import BufferSync
from .sensor_format import SensorFormat
from .utils import convert_from_libcamera_type

Expand Down
7 changes: 4 additions & 3 deletions tests/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def do_encode_by_hand(encoder, stream_name, output_name):
request.release()
encoder.stop()
print(encoder, "finished!")



def do_encode_auto(encoder, stream_name, output_name):
print("Start encode by hand using", encoder, "to", output_name)
picam2.start_encoder(encoder, output=output_name, name=stream_name)
Expand Down Expand Up @@ -51,10 +52,10 @@ def do_encode_auto(encoder, stream_name, output_name):

do_encode_auto(H264Encoder(), "lores", "outb.h264")

jpeg_encoder = JpegEncoder() # needs RGB
jpeg_encoder = JpegEncoder() # needs RGB
jpeg_encoder.size = config["main"]["size"]
jpeg_encoder.format = config["main"]["format"]
jpeg_encoder.q = 50 # wants a quality parameter, not a bitrate (and no framerate)
jpeg_encoder.q = 50 # wants a quality parameter, not a bitrate (and no framerate)
do_encode_by_hand(jpeg_encoder, "main", "out2.mjpeg")

do_encode_auto(JpegEncoder(), "main", "out2b.mjpeg")

0 comments on commit d17c008

Please sign in to comment.