Skip to content

Commit 26e4630

Browse files
committed
Remove deprecated avcodec_close()
1 parent d9624b9 commit 26e4630

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

av/codec/context.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cdef class CodecContext:
1313

1414
# Whether AVCodecContext.extradata should be de-allocated upon destruction.
1515
cdef bint extradata_set
16+
cdef bint _is_open
1617

1718
# Used as a signal that this is within a stream, and also for us to access
1819
# that stream. This is set "manually" by the stream after constructing

av/codec/context.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ cdef class CodecContext:
130130

131131
self.options = {}
132132
self.stream_index = -1 # This is set by the container immediately.
133+
self._is_open = False
133134

134135
cdef _init(self, lib.AVCodecContext *ptr, const lib.AVCodec *codec):
135136
self.ptr = ptr
@@ -217,7 +218,7 @@ cdef class CodecContext:
217218

218219
@property
219220
def is_open(self):
220-
return lib.avcodec_is_open(self.ptr)
221+
return self._is_open
221222

222223
@property
223224
def is_encoder(self):
@@ -228,7 +229,7 @@ cdef class CodecContext:
228229
return lib.av_codec_is_decoder(self.ptr.codec)
229230

230231
cpdef open(self, bint strict=True):
231-
if lib.avcodec_is_open(self.ptr):
232+
if self._is_open:
232233
if strict:
233234
raise ValueError("CodecContext is already open.")
234235
return
@@ -241,25 +242,25 @@ cdef class CodecContext:
241242
self._set_default_time_base()
242243

243244
err_check(lib.avcodec_open2(self.ptr, self.codec.ptr, &options.ptr))
244-
245+
self._is_open = True
245246
self.options = dict(options)
246247

247248
cdef _set_default_time_base(self):
248249
self.ptr.time_base.num = 1
249250
self.ptr.time_base.den = lib.AV_TIME_BASE
250251

251252
cpdef close(self, bint strict=True):
252-
if not lib.avcodec_is_open(self.ptr):
253+
if not self._is_open:
253254
if strict:
254255
raise ValueError("CodecContext is already closed.")
255256
return
256-
err_check(lib.avcodec_close(self.ptr))
257+
self._is_open = False
258+
lib.avcodec_free_context(&self.ptr)
257259

258260
def __dealloc__(self):
259261
if self.ptr and self.extradata_set:
260262
lib.av_freep(&self.ptr.extradata)
261263
if self.ptr:
262-
lib.avcodec_close(self.ptr)
263264
lib.avcodec_free_context(&self.ptr)
264265
if self.parser:
265266
lib.av_parser_close(self.parser)
@@ -565,7 +566,7 @@ cdef class CodecContext:
565566

566567
@thread_count.setter
567568
def thread_count(self, int value):
568-
if lib.avcodec_is_open(self.ptr):
569+
if self._is_open:
569570
raise RuntimeError("Cannot change thread_count after codec is open.")
570571
self.ptr.thread_count = value
571572

@@ -580,7 +581,7 @@ cdef class CodecContext:
580581

581582
@thread_type.setter
582583
def thread_type(self, value):
583-
if lib.avcodec_is_open(self.ptr):
584+
if self._is_open:
584585
raise RuntimeError("Cannot change thread_type after codec is open.")
585586
self.ptr.thread_type = ThreadType[value].value
586587

include/libavcodec/avcodec.pxd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:
291291
AVDictionary **options,
292292
)
293293

294-
cdef int avcodec_is_open(AVCodecContext *ctx )
295-
cdef int avcodec_close(AVCodecContext *ctx)
296-
297294
cdef int AV_NUM_DATA_POINTERS
298295

299296
cdef enum AVPacketSideDataType:

0 commit comments

Comments
 (0)