Skip to content

Commit

Permalink
Remove deprecated avcodec_close()
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 19, 2024
1 parent d9624b9 commit 26e4630
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions av/codec/context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cdef class CodecContext:

# Whether AVCodecContext.extradata should be de-allocated upon destruction.
cdef bint extradata_set
cdef bint _is_open

# Used as a signal that this is within a stream, and also for us to access
# that stream. This is set "manually" by the stream after constructing
Expand Down
17 changes: 9 additions & 8 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ cdef class CodecContext:

self.options = {}
self.stream_index = -1 # This is set by the container immediately.
self._is_open = False

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

@property
def is_open(self):
return lib.avcodec_is_open(self.ptr)
return self._is_open

@property
def is_encoder(self):
Expand All @@ -228,7 +229,7 @@ cdef class CodecContext:
return lib.av_codec_is_decoder(self.ptr.codec)

cpdef open(self, bint strict=True):
if lib.avcodec_is_open(self.ptr):
if self._is_open:
if strict:
raise ValueError("CodecContext is already open.")
return
Expand All @@ -241,25 +242,25 @@ cdef class CodecContext:
self._set_default_time_base()

err_check(lib.avcodec_open2(self.ptr, self.codec.ptr, &options.ptr))

self._is_open = True
self.options = dict(options)

cdef _set_default_time_base(self):
self.ptr.time_base.num = 1
self.ptr.time_base.den = lib.AV_TIME_BASE

cpdef close(self, bint strict=True):
if not lib.avcodec_is_open(self.ptr):
if not self._is_open:
if strict:
raise ValueError("CodecContext is already closed.")
return
err_check(lib.avcodec_close(self.ptr))
self._is_open = False
lib.avcodec_free_context(&self.ptr)

def __dealloc__(self):
if self.ptr and self.extradata_set:
lib.av_freep(&self.ptr.extradata)
if self.ptr:
lib.avcodec_close(self.ptr)
lib.avcodec_free_context(&self.ptr)
if self.parser:
lib.av_parser_close(self.parser)
Expand Down Expand Up @@ -565,7 +566,7 @@ cdef class CodecContext:

@thread_count.setter
def thread_count(self, int value):
if lib.avcodec_is_open(self.ptr):
if self._is_open:
raise RuntimeError("Cannot change thread_count after codec is open.")
self.ptr.thread_count = value

Expand All @@ -580,7 +581,7 @@ cdef class CodecContext:

@thread_type.setter
def thread_type(self, value):
if lib.avcodec_is_open(self.ptr):
if self._is_open:
raise RuntimeError("Cannot change thread_type after codec is open.")
self.ptr.thread_type = ThreadType[value].value

Expand Down
3 changes: 0 additions & 3 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:
AVDictionary **options,
)

cdef int avcodec_is_open(AVCodecContext *ctx )
cdef int avcodec_close(AVCodecContext *ctx)

cdef int AV_NUM_DATA_POINTERS

cdef enum AVPacketSideDataType:
Expand Down

0 comments on commit 26e4630

Please sign in to comment.