From 8bc639f4857620146d3991b62821afe392eb4a41 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Tue, 18 Aug 2026 21:52:19 -0400 Subject: [PATCH 1/2] Pack Container and HWAccel, and narrow four object fields Container held buffer_size between two pointers and HWAccel led with an int and split its pointers with three more, so both structs carried holes that grouping the pointers first removes: Container 160 -> 152 HWAccel 88 -> 80 --- av/codec/hwaccel.pxd | 6 +++--- av/container/core.pxd | 4 ++-- av/filter/context.pxd | 4 ++-- av/filter/filter.pxd | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/av/codec/hwaccel.pxd b/av/codec/hwaccel.pxd index fd9bb1720..20faba21b 100644 --- a/av/codec/hwaccel.pxd +++ b/av/codec/hwaccel.pxd @@ -11,13 +11,13 @@ cdef class HWConfig: cdef HWConfig wrap_hwconfig(const lib.AVCodecHWConfig *ptr) cdef class HWAccel: - cdef int _device_type cdef str _device cdef readonly Codec codec cdef readonly HWConfig config cdef lib.AVBufferRef *ptr + cdef public dict options + cdef int _device_type cdef readonly int device_id + cdef public int flags cdef readonly bint is_hw_owned cdef public bint allow_software_fallback - cdef public dict options - cdef public int flags diff --git a/av/container/core.pxd b/av/container/core.pxd index a879f362a..e385163cb 100644 --- a/av/container/core.pxd +++ b/av/container/core.pxd @@ -18,9 +18,8 @@ cdef class Container: cdef lib.AVFormatContext *ptr cdef readonly str name cdef readonly PyIOFile file - cdef int buffer_size cdef readonly object io_open - cdef readonly object open_files + cdef readonly dict open_files cdef readonly ContainerFormat format cdef readonly dict options cdef readonly dict container_options @@ -32,6 +31,7 @@ cdef class Container: cdef HWAccel hwaccel cdef timeout_info interrupt_callback_info + cdef int buffer_size cdef uint8_t _myflag # enum: writeable, input_was_opened, started, done, extradata_planned cdef void _assert_open(self) diff --git a/av/filter/context.pxd b/av/filter/context.pxd index 654d8e0a6..8a0724406 100644 --- a/av/filter/context.pxd +++ b/av/filter/context.pxd @@ -8,8 +8,8 @@ cdef class FilterContext: cdef lib.AVFilterContext *ptr cdef readonly Graph graph cdef readonly Filter filter - cdef object _inputs - cdef object _outputs + cdef tuple _inputs + cdef tuple _outputs cdef bint inited cdef unsigned char _kind diff --git a/av/filter/filter.pxd b/av/filter/filter.pxd index d74065a19..b77f5790d 100644 --- a/av/filter/filter.pxd +++ b/av/filter/filter.pxd @@ -3,8 +3,8 @@ cimport libav as lib cdef class Filter: cdef const lib.AVFilter *ptr - cdef object _inputs - cdef object _outputs + cdef tuple _inputs + cdef tuple _outputs cdef Filter wrap_filter(const lib.AVFilter *ptr) From 0bc3468f874bff1d04239aaadb422d468fb799c4 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Tue, 18 Aug 2026 21:55:27 -0400 Subject: [PATCH 2/2] Compute `AudioPlane.buffer_size` instead of storing it It only held `frame.ptr.linesize[0]`, and Buffer already exposes buffer_size as a property over _buffer_size() so the field was shadowing that property with a copy of what the override could return directly. AudioPlane 48 -> 40 --- av/audio/plane.pxd | 1 - av/audio/plane.py | 6 ++---- av/audio/plane.pyi | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/av/audio/plane.pxd b/av/audio/plane.pxd index de912ac22..2da06bae6 100644 --- a/av/audio/plane.pxd +++ b/av/audio/plane.pxd @@ -2,5 +2,4 @@ from av.plane cimport Plane cdef class AudioPlane(Plane): - cdef readonly size_t buffer_size cdef size_t _buffer_size(self) diff --git a/av/audio/plane.py b/av/audio/plane.py index b0cf6052f..ab37ff217 100644 --- a/av/audio/plane.py +++ b/av/audio/plane.py @@ -12,9 +12,7 @@ def __cinit__(self, frame: AudioFrame, index: cython.int): if index < 0 or index >= nb_planes: raise ValueError(f"plane index {index} out of range for {nb_planes} planes") - # Only the first linesize is ever populated, but it applies to every plane. - self.buffer_size = self.frame.ptr.linesize[0] - @cython.cfunc def _buffer_size(self) -> cython.size_t: - return self.buffer_size + # Only the first linesize is ever populated, but it applies to every plane. + return self.frame.ptr.linesize[0] diff --git a/av/audio/plane.pyi b/av/audio/plane.pyi index 64524dcdb..b3e947937 100644 --- a/av/audio/plane.pyi +++ b/av/audio/plane.pyi @@ -1,4 +1,3 @@ from av.plane import Plane -class AudioPlane(Plane): - buffer_size: int +class AudioPlane(Plane): ...