Skip to content

Commit 253655f

Browse files
committed
Make audio/format pure
1 parent 506f6ac commit 253655f

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

av/audio/format.pxd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ cimport libav as lib
22

33

44
cdef class AudioFormat:
5-
65
cdef lib.AVSampleFormat sample_fmt
76

8-
cdef _init(self, lib.AVSampleFormat sample_fmt)
9-
10-
117
cdef AudioFormat get_audio_format(lib.AVSampleFormat format)
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
import sys
22

3+
import cython
34

4-
cdef str container_format_postfix = "le" if sys.byteorder == "little" else "be"
5+
container_format_postfix: str = "le" if sys.byteorder == "little" else "be"
6+
_cinit_bypass_sentinel = object()
57

68

7-
cdef object _cinit_bypass_sentinel
8-
9-
cdef AudioFormat get_audio_format(lib.AVSampleFormat c_format):
9+
@cython.cfunc
10+
def get_audio_format(c_format: lib.AVSampleFormat) -> AudioFormat:
1011
"""Get an AudioFormat without going through a string."""
1112

1213
if c_format < 0:
1314
return None
1415

15-
cdef AudioFormat format = AudioFormat.__new__(AudioFormat, _cinit_bypass_sentinel)
16-
format._init(c_format)
16+
format: AudioFormat = AudioFormat(_cinit_bypass_sentinel)
17+
format.sample_fmt = c_format
1718
return format
1819

1920

20-
cdef class AudioFormat:
21+
@cython.cclass
22+
class AudioFormat:
2123
"""Descriptor of audio formats."""
2224

2325
def __cinit__(self, name):
2426
if name is _cinit_bypass_sentinel:
2527
return
2628

27-
cdef lib.AVSampleFormat sample_fmt
29+
sample_fmt: lib.AVSampleFormat
2830
if isinstance(name, AudioFormat):
29-
sample_fmt = (<AudioFormat>name).sample_fmt
31+
sample_fmt = cython.cast(AudioFormat, name).sample_fmt
3032
else:
3133
sample_fmt = lib.av_get_sample_fmt(name)
3234

3335
if sample_fmt < 0:
3436
raise ValueError(f"Not a sample format: {name!r}")
3537

36-
self._init(sample_fmt)
37-
38-
cdef _init(self, lib.AVSampleFormat sample_fmt):
3938
self.sample_fmt = sample_fmt
4039

4140
def __repr__(self):
@@ -49,7 +48,7 @@ def name(self):
4948
's16p'
5049
5150
"""
52-
return <str>lib.av_get_sample_fmt_name(self.sample_fmt)
51+
return lib.av_get_sample_fmt_name(self.sample_fmt)
5352

5453
@property
5554
def bytes(self):
@@ -82,7 +81,7 @@ def is_planar(self):
8281

8382
@property
8483
def is_packed(self):
85-
"""Is this a packed format?
84+
"""Is this a planar format?
8685
8786
Strictly opposite of :attr:`is_planar`.
8887

0 commit comments

Comments
 (0)