Skip to content

Commit 84379c9

Browse files
committed
Combine av/indexenr* to av/index.py
1 parent 1f47525 commit 84379c9

9 files changed

Lines changed: 74 additions & 86 deletions

File tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
cimport libav as lib
22

33

4+
cdef class IndexEntry:
5+
cdef lib.AVIndexEntry *ptr
6+
cdef _init(self, lib.AVIndexEntry *ptr)
7+
48
cdef class IndexEntries:
59
cdef lib.AVStream *stream_ptr
610
cdef _init(self, lib.AVStream *ptr)
711

8-
912
cdef IndexEntries wrap_index_entries(lib.AVStream *ptr)

av/indexentries.py renamed to av/index.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,69 @@
11
import cython
22
import cython.cimports.libav as lib
3-
from cython.cimports.av.indexentry import wrap_index_entry
43
from cython.cimports.libc.stdint import int64_t
54

65
_cinit_bypass_sentinel = cython.declare(object, object())
76

87

8+
@cython.cfunc
9+
def wrap_index_entry(ptr: cython.pointer[lib.AVIndexEntry]) -> IndexEntry:
10+
obj: IndexEntry = IndexEntry(_cinit_bypass_sentinel)
11+
obj._init(ptr)
12+
return obj
13+
14+
15+
@cython.cclass
16+
class IndexEntry:
17+
"""A single entry from a stream's index.
18+
19+
This is a thin wrapper around FFmpeg's ``AVIndexEntry``.
20+
21+
The exact meaning of the fields depends on the container/demuxer.
22+
"""
23+
24+
def __cinit__(self, sentinel):
25+
if sentinel is not _cinit_bypass_sentinel:
26+
raise RuntimeError("cannot manually instantiate IndexEntry")
27+
28+
@cython.cfunc
29+
def _init(self, ptr: cython.pointer[lib.AVIndexEntry]):
30+
self.ptr = ptr
31+
32+
def __repr__(self):
33+
return (
34+
f"<av.IndexEntry pos={self.pos} timestamp={self.timestamp} flags={self.flags} "
35+
f"size={self.size} min_distance={self.min_distance}>"
36+
)
37+
38+
@property
39+
def pos(self):
40+
return self.ptr.pos
41+
42+
@property
43+
def timestamp(self):
44+
return self.ptr.timestamp
45+
46+
@property
47+
def flags(self):
48+
return self.ptr.flags
49+
50+
@property
51+
def is_keyframe(self):
52+
return bool(self.ptr.flags & lib.AVINDEX_KEYFRAME)
53+
54+
@property
55+
def is_discard(self):
56+
return bool(self.ptr.flags & lib.AVINDEX_DISCARD_FRAME)
57+
58+
@property
59+
def size(self):
60+
return self.ptr.size
61+
62+
@property
63+
def min_distance(self):
64+
return self.ptr.min_distance
65+
66+
967
@cython.cfunc
1068
def wrap_index_entries(ptr: cython.pointer[lib.AVStream]) -> IndexEntries:
1169
obj: IndexEntries = IndexEntries(_cinit_bypass_sentinel)
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from typing import Iterator, overload
22

3-
from av.indexentry import IndexEntry
3+
class IndexEntry:
4+
pos: int
5+
timestamp: int
6+
flags: int
7+
is_keyframe: bool
8+
is_discard: bool
9+
size: int
10+
min_distance: int
411

512
class IndexEntries:
613
def __len__(self) -> int: ...

av/indexentry.pxd

Lines changed: 0 additions & 9 deletions
This file was deleted.

av/indexentry.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

av/indexentry.pyi

Lines changed: 0 additions & 8 deletions
This file was deleted.

av/stream.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cimport libav as lib
33
from av.codec.context cimport CodecContext
44
from av.container.core cimport Container
55
from av.frame cimport Frame
6-
from av.indexentries cimport IndexEntries
6+
from av.index cimport IndexEntries
77
from av.packet cimport Packet
88

99

av/stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import cython
44
from cython.cimports import libav as lib
55
from cython.cimports.av.error import err_check
6-
from cython.cimports.av.indexentries import wrap_index_entries
6+
from cython.cimports.av.index import wrap_index_entries
77
from cython.cimports.av.packet import Packet
88
from cython.cimports.av.utils import (
99
avdict_to_dict,

av/stream.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing import Literal, cast
44

55
from .codec import Codec, CodecContext
66
from .container import Container
7-
from .indexentries import IndexEntries
7+
from .index import IndexEntries
88

99
class Disposition(Flag):
1010
default = cast(int, ...)

0 commit comments

Comments
 (0)