diff --git a/av/codec/context.pxd b/av/codec/context.pxd index 58bc6a07d..782a66f8f 100644 --- a/av/codec/context.pxd +++ b/av/codec/context.pxd @@ -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 diff --git a/av/codec/context.pyx b/av/codec/context.pyx index b995bc9f7..c00dec1dd 100644 --- a/av/codec/context.pyx +++ b/av/codec/context.pyx @@ -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 @@ -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): @@ -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 @@ -241,7 +242,7 @@ 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): @@ -249,17 +250,17 @@ cdef class CodecContext: 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) @@ -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 @@ -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 diff --git a/include/libavcodec/avcodec.pxd b/include/libavcodec/avcodec.pxd index f414e59d4..71121e976 100644 --- a/include/libavcodec/avcodec.pxd +++ b/include/libavcodec/avcodec.pxd @@ -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: