Skip to content

Commit 94ba73c

Browse files
committed
Use layout_compare() for AudioLayout.__eq__()
And use AVCodecContext.frame_num instead of keeping track ourselves.
1 parent e50b0fb commit 94ba73c

5 files changed

Lines changed: 14 additions & 20 deletions

File tree

CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ v17.0.1 (next)
3131
Fixes:
3232

3333
- A cdivision decorator for faster division.
34+
- Adjust tests so they work with 8.1 by :gh-user:`strophy`.
3435
- Make VideoFormat.components lazy by :gh-user:`WyattBlue`.
3536
- Break reference cycle ``StreamContainer.get()`` by :gh-user:`lgeiger`.
3637
- Expose threads in filter graph by :gh-user:`lgeiger`.
3738
- Fix crash with container closing with GC by :gh-user:`WyattBlue`.
38-
- Fix regression in 17.0.0 :issue:`2223`.
39+
- Fix "Writing packets to data stream broken in av>=17" regression :issue:`2223` by :gh-user:`WyattBlue`.
3940
- Remove ``_send_packet_and_recv`` to simplify ``decode()`` by :gh-user:`lgeiger`.
4041
- Reuse a ``AVPacket`` read buffer when demuxing by :gh-user:`lgeiger` and :gh-user:`WyattBlue`.
42+
- Use ``AVCodecContext.frame_num`` instead of counting ourselves by :gh-user:`WyattBlue`.
43+
- Use ``av_channel_layout_compare()`` for ``AudioLayout.__eq__()`` by :gh-user:`WyattBlue`.
4144

4245
v17.0.0
4346
-------

av/audio/layout.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ def __repr__(self):
4848
return f"<av.{self.__class__.__name__} {self.name!r}>"
4949

5050
def __eq__(self, other):
51+
if not isinstance(other, AudioLayout):
52+
return False
53+
c_other: lib.AVChannelLayout = cython.cast(AudioLayout, other).layout
5154
return (
52-
isinstance(other, AudioLayout)
53-
and self.name == other.name
54-
and self.nb_channels == other.nb_channels
55+
lib.av_channel_layout_compare(
56+
cython.address(self.layout), cython.address(c_other)
57+
)
58+
== 0
5559
)
5660

5761
@property

av/video/codeccontext.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ cdef struct AVCodecPrivateData:
1818
cdef class VideoCodecContext(CodecContext):
1919
cdef AVCodecPrivateData _private_data
2020
cdef readonly VideoReformatter reformatter
21-
cdef readonly int encoded_frame_count
2221
cdef VideoFrame next_frame

av/video/codeccontext.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,12 @@ def _init(
7272
# is_hwaccel() function on each stream's codec context.
7373
self.hwaccel_ctx = None
7474

75-
self.encoded_frame_count = 0
76-
7775
@cython.cfunc
7876
def _prepare_frames_for_encode(self, input: Frame | None) -> list:
7977
if input is None or not input:
8078
return [None]
8179

8280
vframe: VideoFrame = input
83-
# Reformat if it doesn't match.
8481
if (
8582
vframe.format.pix_fmt != self.pix_fmt
8683
or vframe.width != self.ptr.width
@@ -97,11 +94,9 @@ def _prepare_frames_for_encode(self, input: Frame | None) -> list:
9794
threads=self.ptr.thread_count,
9895
)
9996

100-
# There is no pts, so create one.
10197
if vframe.ptr.pts == lib.AV_NOPTS_VALUE:
102-
vframe.ptr.pts = cython.cast(int64_t, self.encoded_frame_count)
98+
vframe.ptr.pts = self.ptr.frame_num
10399

104-
self.encoded_frame_count += 1
105100
return [vframe]
106101

107102
@cython.cfunc

include/avcodec.pxd

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
from libc.stdint cimport int64_t, uint8_t, uint16_t, uint32_t, uint64_t
22

33
cdef extern from "libavutil/channel_layout.h" nogil:
4-
ctypedef enum AVChannelOrder:
5-
pass
64
ctypedef enum AVChannel:
75
AV_CHAN_NONE = -1
86
AV_CHAN_FRONT_LEFT
97
AV_CHAN_FRONT_RIGHT
108
AV_CHAN_FRONT_CENTER
119
ctypedef struct AVChannelLayout:
12-
AVChannelOrder order
1310
int nb_channels
14-
uint64_t mask
15-
# union:
16-
# uint64_t mask
17-
# AVChannelCustom *map
18-
void *opaque
1911

2012
int av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
2113
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
2214
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
2315
int av_channel_name(char *buf, size_t buf_size, AVChannel channel_id)
2416
int av_channel_description(char *buf, size_t buf_size, AVChannel channel_id)
17+
int av_channel_layout_compare(AVChannelLayout *chl, AVChannelLayout *chl1)
2518
AVChannel av_channel_layout_channel_from_index(AVChannelLayout *channel_layout, unsigned int idx)
2619

2720
cdef extern from "libavcodec/avcodec.h" nogil:
28-
cdef set pyav_get_available_codecs()
2921
cdef int avcodec_version()
3022
cdef char* avcodec_configuration()
3123
cdef char* avcodec_license()
@@ -290,6 +282,7 @@ cdef extern from "libavcodec/avcodec.h" nogil:
290282

291283
int subtitle_header_size
292284
uint8_t *subtitle_header
285+
int64_t frame_num
293286

294287
cdef AVCodecContext* avcodec_alloc_context3(const AVCodec *codec)
295288
cdef void avcodec_free_context(AVCodecContext **ctx)

0 commit comments

Comments
 (0)