Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow accessing gop_size, timebase as a decoder #1489

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

cimport libav as lib
from libc.errno cimport EAGAIN
from libc.stdint cimport uint8_t
Expand Down Expand Up @@ -504,19 +502,13 @@ cdef class CodecContext:
@property
def time_base(self):
if self.is_decoder:
warnings.warn(
"Using CodecContext.time_base for decoders is deprecated.",
AVDeprecationWarning
)
raise RuntimeError("Cannot access 'time_base' as a decoder")
return avrational_to_fraction(&self.ptr.time_base)

@time_base.setter
def time_base(self, value):
if self.is_decoder:
warnings.warn(
"Using CodecContext.time_base for decoders is deprecated.",
AVDeprecationWarning
)
raise RuntimeError("Cannot access 'time_base' as a decoder")
to_avrational(value, &self.ptr.time_base)

@property
Expand Down
14 changes: 2 additions & 12 deletions av/video/codeccontext.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

cimport libav as lib
from libc.stdint cimport int64_t

Expand All @@ -11,8 +9,6 @@ from av.video.format cimport VideoFormat, get_pix_fmt, get_video_format
from av.video.frame cimport VideoFrame, alloc_video_frame
from av.video.reformatter cimport VideoReformatter

from av.deprecation import AVDeprecationWarning


cdef class VideoCodecContext(CodecContext):
def __cinit__(self, *args, **kwargs):
Expand Down Expand Up @@ -161,19 +157,13 @@ cdef class VideoCodecContext(CodecContext):
:type: int
"""
if self.is_decoder:
warnings.warn(
"Using VideoCodecContext.gop_size for decoders is deprecated.",
AVDeprecationWarning
)
raise RuntimeError("Cannnot access 'gop_size' as a decoder")
return self.ptr.gop_size

@gop_size.setter
def gop_size(self, int value):
if self.is_decoder:
warnings.warn(
"Using VideoCodecContext.gop_size for decoders is deprecated.",
AVDeprecationWarning
)
raise RuntimeError("Cannnot access 'gop_size' as a decoder")
self.ptr.gop_size = value

@property
Expand Down
11 changes: 0 additions & 11 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ from av.utils cimport check_ndarray, check_ndarray_shape
from av.video.format cimport get_pix_fmt, get_video_format
from av.video.plane cimport VideoPlane

import warnings

from av.deprecation import AVDeprecationWarning


cdef object _cinit_bypass_sentinel

Expand Down Expand Up @@ -574,10 +570,3 @@ cdef class VideoFrame(Frame):
copy_array_to_plane(array, frame.planes[0], 1 if array.ndim == 2 else array.shape[2])

return frame

def __getattribute__(self, attribute):
# This method should be deleted when `frame.index` is removed
if attribute == "index":
warnings.warn("Using `frame.index` is deprecated.", AVDeprecationWarning)

return Frame.__getattribute__(self, attribute)
25 changes: 6 additions & 19 deletions tests/test_codec_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import warnings
from fractions import Fraction
from unittest import SkipTest

Expand Down Expand Up @@ -89,29 +88,17 @@ def test_decoder_extradata(self):
def test_decoder_gop_size(self):
ctx = av.codec.Codec("h264", "r").create()

with warnings.catch_warnings(record=True) as captured:
self.assertIsInstance(ctx.gop_size, int)
self.assertEqual(
captured[0].message.args[0],
"Using VideoCodecContext.gop_size for decoders is deprecated.",
)
with self.assertRaises(RuntimeError):
ctx.gop_size

def test_decoder_timebase(self):
def test_decoder_timebase(self) -> None:
ctx = av.codec.Codec("h264", "r").create()

with warnings.catch_warnings(record=True) as captured:
self.assertIsNone(ctx.time_base)
self.assertEqual(
captured[0].message.args[0],
"Using CodecContext.time_base for decoders is deprecated.",
)
with self.assertRaises(RuntimeError):
ctx.time_base

with warnings.catch_warnings(record=True) as captured:
with self.assertRaises(RuntimeError):
ctx.time_base = Fraction(1, 25)
self.assertEqual(
captured[0].message.args[0],
"Using CodecContext.time_base for decoders is deprecated.",
)

def test_encoder_extradata(self):
ctx = av.codec.Codec("h264", "w").create()
Expand Down
Loading