Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -2,11 +2,12 @@ from typing import Iterator, Literal, get_args
|
|||
|
||||
import cython
|
||||
from cython.cimports import libav as lib
|
||||
from cython.cimports.av.buffer import Buffer
|
||||
from cython.cimports.av.bytesource import bytesource
|
||||
from cython.cimports.av.buffer import Buffer, ByteSource, bytesource
|
||||
from cython.cimports.av.error import err_check
|
||||
from cython.cimports.av.opaque import opaque_container
|
||||
from cython.cimports.av.utils import avrational_to_fraction, to_avrational
|
||||
from cython.cimports.cpython.ref import Py_DECREF, Py_INCREF
|
||||
from cython.cimports.libc.stdint import uint8_t
|
||||
from cython.cimports.libc.string import memcpy
|
||||
|
||||
# Check https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/packet.h#L41
|
||||
|
|
@ -64,6 +65,7 @@ def packet_sidedata_type_from_literal(dtype: PktSideDataT) -> lib.AVPacketSideDa
|
|||
return get_args(PktSideDataT).index(dtype)
|
||||
|
||||
|
||||
@cython.final
|
||||
@cython.cclass
|
||||
class PacketSideData(Buffer):
|
||||
@staticmethod
|
||||
|
|
@ -194,6 +196,19 @@ def _packet_sidedata_from_packet(
|
|||
return sdata
|
||||
|
||||
|
||||
@cython.cfunc
|
||||
@cython.nogil
|
||||
@cython.exceptval(check=False)
|
||||
def _python_free(
|
||||
opaque: cython.p_void,
|
||||
data: cython.pointer[uint8_t],
|
||||
) -> cython.void:
|
||||
if opaque != cython.NULL:
|
||||
with cython.gil:
|
||||
Py_DECREF(cython.cast(object, opaque))
|
||||
|
||||
|
||||
@cython.final
|
||||
@cython.cclass
|
||||
class Packet(Buffer):
|
||||
"""A packet of encoded data within a :class:`~av.format.Stream`.
|
||||
|
|
@ -213,24 +228,34 @@ class Packet(Buffer):
|
|||
def __init__(self, input=None):
|
||||
size: cython.size_t = 0
|
||||
source: ByteSource = None
|
||||
buf: cython.pointer[lib.AVBufferRef]
|
||||
|
||||
if input is None:
|
||||
return
|
||||
|
||||
if isinstance(input, int):
|
||||
size = input
|
||||
if size:
|
||||
err_check(lib.av_new_packet(self.ptr, size))
|
||||
else:
|
||||
source = bytesource(input)
|
||||
size = source.length
|
||||
|
||||
if size:
|
||||
err_check(lib.av_new_packet(self.ptr, size))
|
||||
|
||||
if source is not None:
|
||||
self.update(source)
|
||||
# TODO: Hold onto the source, and copy its pointer
|
||||
# instead of its data.
|
||||
# self.source = source
|
||||
if size:
|
||||
# Create a buffer that references the source data directly.
|
||||
Py_INCREF(source)
|
||||
buf = lib.av_buffer_create(
|
||||
source.ptr,
|
||||
size,
|
||||
_python_free,
|
||||
cython.cast(cython.p_void, source),
|
||||
0,
|
||||
)
|
||||
if buf == cython.NULL:
|
||||
Py_DECREF(source)
|
||||
raise MemoryError("Could not allocate AVBufferRef")
|
||||
self.ptr.buf = buf
|
||||
self.ptr.data = source.ptr
|
||||
self.ptr.size = size
|
||||
|
||||
def __repr__(self):
|
||||
stream = self._stream.index if self._stream else 0
|
||||
|
|
@ -442,7 +467,7 @@ class Packet(Buffer):
|
|||
def get_sidedata(self, dtype: str) -> PacketSideData:
|
||||
"""get a copy of the side data
|
||||
|
||||
:param dtype: side data type (:method:`~av.packet.PacketSideData.sidedata_types` for the full list of options)
|
||||
:param dtype: side data type (:meth:`~av.packet.PacketSideData.sidedata_types` for the full list of options)
|
||||
:type dtype: str
|
||||
:return: newly created copy of the side data if the side data of the
|
||||
requested type is found in the packet, else an empty object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue