Skip to content
Merged
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
2 changes: 0 additions & 2 deletions av/dictionary.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ cimport libav as lib


cdef class _Dictionary:

cdef lib.AVDictionary *ptr

cpdef _Dictionary copy(self)


Expand Down
62 changes: 62 additions & 0 deletions av/dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from collections.abc import MutableMapping

import cython
from cython.cimports.av.error import err_check


@cython.cclass
class _Dictionary:
def __cinit__(self, *args, **kwargs):
for arg in args:
self.update(arg)
if kwargs:
self.update(kwargs)

def __dealloc__(self):
if self.ptr != cython.NULL:
lib.av_dict_free(cython.address(self.ptr))

def __getitem__(self, key: cython.str):
element = cython.declare(
cython.pointer[lib.AVDictionaryEntry],
lib.av_dict_get(self.ptr, key, cython.NULL, 0),
)
if element == cython.NULL:
raise KeyError(key)
return element.value

def __setitem__(self, key: cython.str, value: cython.str):
err_check(lib.av_dict_set(cython.address(self.ptr), key, value, 0))

def __delitem__(self, key: cython.str):
err_check(lib.av_dict_set(cython.address(self.ptr), key, cython.NULL, 0))

def __len__(self):
return err_check(lib.av_dict_count(self.ptr))

def __iter__(self):
element = cython.declare(cython.pointer[lib.AVDictionaryEntry], cython.NULL)
while True:
element = lib.av_dict_get(self.ptr, "", element, lib.AV_DICT_IGNORE_SUFFIX)
if element == cython.NULL:
break
yield element.key

def __repr__(self):
return f"bv.Dictionary({dict(self)!r})"

def copy(self):
other = cython.declare(_Dictionary, Dictionary())
lib.av_dict_copy(cython.address(other.ptr), self.ptr, 0)
return other


class Dictionary(_Dictionary, MutableMapping):
pass


@cython.cfunc
def wrap_dictionary(input_: cython.pointer[lib.AVDictionary]) -> _Dictionary:
output = cython.declare(_Dictionary, Dictionary())
output.ptr = input_
return output
57 changes: 0 additions & 57 deletions av/dictionary.pyx

This file was deleted.

2 changes: 0 additions & 2 deletions av/plane.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ from av.frame cimport Frame


cdef class Plane(Buffer):

cdef Frame frame
cdef int index

cdef size_t _buffer_size(self)
cdef void* _buffer_ptr(self)
10 changes: 7 additions & 3 deletions av/plane.pyx → av/plane.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import cython

cdef class Plane(Buffer):

@cython.cclass
class Plane(Buffer):
"""
Base class for audio and video planes.

See also :class:`~av.audio.plane.AudioPlane` and :class:`~av.video.plane.VideoPlane`.
"""

def __cinit__(self, Frame frame, int index):
def __cinit__(self, frame: Frame, index: cython.int):
self.frame = frame
self.index = index

Expand All @@ -16,5 +19,6 @@ def __repr__(self):
f"buffer_ptr=0x{self.buffer_ptr:x}; at 0x{id(self):x}>"
)

cdef void* _buffer_ptr(self):
@cython.cfunc
def _buffer_ptr(self) -> cython.p_void:
return self.frame.ptr.extended_data[self.index]
Loading