Skip to content

Commit

Permalink
Fix issues identified by cython-lint and import AVError directly
Browse files Browse the repository at this point in the history
  • Loading branch information
daveisfera authored Nov 13, 2023
1 parent a4bde60 commit 040cb50
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 59 deletions.
2 changes: 1 addition & 1 deletion av/audio/resampler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cdef class AudioResampler:
output.append(self.graph.pull())
except EOFError:
break
except av.utils.AVError as e:
except av.AVError as e:
if e.errno != errno.EAGAIN:
raise
break
Expand Down
29 changes: 13 additions & 16 deletions av/error.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,20 @@ for enum in ErrorType:
# Mimick the builtin exception types.
# See https://www.python.org/dev/peps/pep-3151/#new-exception-classes
# Use the named ones we have, otherwise default to OSError for anything in errno.
r'''

See this command for the count of POSIX codes used:
egrep -IR 'AVERROR\(E[A-Z]+\)' vendor/ffmpeg-4.2 |\
sed -E 's/.*AVERROR\((E[A-Z]+)\).*/\1/' | \
sort | uniq -c
The biggest ones that don't map to PEP 3151 builtins:
2106 EINVAL -> ValueError
649 EIO -> IOError (if it is distinct from OSError)
4080 ENOMEM -> MemoryError
340 ENOSYS -> NotImplementedError
35 ERANGE -> OverflowError
'''
# See this command for the count of POSIX codes used:
#
# egrep -IR 'AVERROR\(E[A-Z]+\)' vendor/ffmpeg-4.2 |\
# sed -E 's/.*AVERROR\((E[A-Z]+)\).*/\1/' | \
# sort | uniq -c
#
# The biggest ones that don't map to PEP 3151 builtins:
#
# 2106 EINVAL -> ValueError
# 649 EIO -> IOError (if it is distinct from OSError)
# 4080 ENOMEM -> MemoryError
# 340 ENOSYS -> NotImplementedError
# 35 ERANGE -> OverflowError

classes = {}

Expand Down
33 changes: 14 additions & 19 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cdef extern from "libavcodec/avcodec.h" nogil:
AV_CODEC_PROP_BITMAP_SUB
AV_CODEC_PROP_TEXT_SUB

#AVCodec.capabilities
# AVCodec.capabilities
cdef enum:
AV_CODEC_CAP_DRAW_HORIZ_BAND
AV_CODEC_CAP_DR1
Expand Down Expand Up @@ -131,7 +131,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:

AVClass *priv_class


cdef int av_codec_is_encoder(AVCodec*)
cdef int av_codec_is_decoder(AVCodec*)

Expand All @@ -144,7 +143,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:

AVCodecDescriptor* avcodec_descriptor_get(AVCodecID)


cdef struct AVCodecContext:

AVClass *av_class
Expand Down Expand Up @@ -203,7 +201,7 @@ cdef extern from "libavcodec/avcodec.h" nogil:

AVPixelFormat pix_fmt
AVRational sample_aspect_ratio
int gop_size # The number of pictures in a group of pictures, or 0 for intra_only.
int gop_size # The number of pictures in a group of pictures, or 0 for intra_only.
int max_b_frames
int has_b_frames

Expand Down Expand Up @@ -288,26 +286,26 @@ cdef extern from "libavcodec/avcodec.h" nogil:

# See: http://ffmpeg.org/doxygen/trunk/structAVFrame.html
cdef struct AVFrame:
uint8_t *data[4];
int linesize[4];
uint8_t *data[4]
int linesize[4]
uint8_t **extended_data

int format # Should be AVPixelFormat or AVSampleFormat
int key_frame # 0 or 1.
int format # Should be AVPixelFormat or AVSampleFormat
int key_frame # 0 or 1.
AVPictureType pict_type

int interlaced_frame # 0 or 1.
int interlaced_frame # 0 or 1.

int width
int height

int nb_side_data
AVFrameSideData **side_data

int nb_samples # Audio samples
int sample_rate # Audio Sample rate
int channels # Number of audio channels
int channel_layout # Audio channel_layout
int nb_samples # Audio samples
int sample_rate # Audio Sample rate
int channels # Number of audio channels
int channel_layout # Audio channel_layout

int64_t pts
int64_t pkt_dts
Expand All @@ -320,7 +318,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:
int flags
int decode_error_flags


cdef AVFrame* avcodec_alloc_frame()

cdef struct AVPacket:
Expand All @@ -337,7 +334,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:

int64_t pos


cdef int avcodec_fill_audio_frame(
AVFrame *frame,
int nb_channels,
Expand Down Expand Up @@ -367,8 +363,8 @@ cdef extern from "libavcodec/avcodec.h" nogil:
int w
int h
int nb_colors
uint8_t *data[4];
int linesize[4];
uint8_t *data[4]
int linesize[4]
AVSubtitleType type
char *text
char *ass
Expand Down Expand Up @@ -402,7 +398,7 @@ cdef extern from "libavcodec/avcodec.h" nogil:

cdef void avcodec_flush_buffers(AVCodecContext *ctx)

# TODO: avcodec_default_get_buffer is deprecated for avcodec_default_get_buffer2 in newer versions of FFmpeg
# TODO: avcodec_default_get_buffer is deprecated for avcodec_default_get_buffer2 in newer versions of FFmpeg
cdef int avcodec_default_get_buffer(AVCodecContext *ctx, AVFrame *frame)
cdef void avcodec_default_release_buffer(AVCodecContext *ctx, AVFrame *frame)

Expand Down Expand Up @@ -440,7 +436,6 @@ cdef extern from "libavcodec/avcodec.h" nogil:
)
cdef void av_parser_close(AVCodecParserContext *s)


cdef struct AVCodecParameters:
AVMediaType codec_type
AVCodecID codec_id
Expand Down
2 changes: 1 addition & 1 deletion include/libavfilter/avfilter.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cdef extern from "libavfilter/avfilter.h" nogil:
cdef AVFilter* avfilter_get_by_name(const char *name)
cdef const AVFilter* av_filter_iterate(void **opaque)

cdef struct AVFilterLink # Defined later.
cdef struct AVFilterLink # Defined later.

cdef struct AVFilterContext:

Expand Down
1 change: 0 additions & 1 deletion include/libavfilter/avfiltergraph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ cdef extern from "libavfilter/avfilter.h" nogil:
int pad_idx
AVFilterInOut *next


cdef AVFilterGraph* avfilter_graph_alloc()
cdef void avfilter_graph_free(AVFilterGraph **ptr)

Expand Down
11 changes: 5 additions & 6 deletions include/libavformat/avformat.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ cdef extern from "libavformat/avformat.h" nogil:
cdef int AVSEEK_FLAG_ANY
cdef int AVSEEK_FLAG_FRAME


cdef int AVIO_FLAG_WRITE

cdef enum AVMediaType:
Expand Down Expand Up @@ -207,10 +206,10 @@ cdef extern from "libavformat/avformat.h" nogil:
# .. seealso:: FFmpeg's docs: :ffmpeg:`avformat_open_input`
#
cdef int avformat_open_input(
AVFormatContext **ctx, # NULL will allocate for you.
AVFormatContext **ctx, # NULL will allocate for you.
char *filename,
AVInputFormat *format, # Can be NULL.
AVDictionary **options # Can be NULL.
AVInputFormat *format, # Can be NULL.
AVDictionary **options # Can be NULL.
)

cdef int avformat_close_input(AVFormatContext **ctx)
Expand All @@ -224,7 +223,7 @@ cdef extern from "libavformat/avformat.h" nogil:
#
cdef int avformat_write_header(
AVFormatContext *ctx,
AVDictionary **options # Can be NULL
AVDictionary **options # Can be NULL
)

cdef int av_write_trailer(AVFormatContext *ctx)
Expand Down Expand Up @@ -269,7 +268,7 @@ cdef extern from "libavformat/avformat.h" nogil:

cdef int avformat_find_stream_info(
AVFormatContext *ctx,
AVDictionary **options, # Can be NULL.
AVDictionary **options, # Can be NULL.
)

cdef AVStream* avformat_new_stream(
Expand Down
14 changes: 5 additions & 9 deletions include/libavutil/avutil.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ cdef extern from "libavutil/avutil.h" nogil:
# This is nice, but only in FFMpeg:
# AV_ROUND_PASS_MINMAX


cdef double M_PI

cdef void* av_malloc(size_t size)
Expand Down Expand Up @@ -67,9 +66,9 @@ cdef extern from "libavutil/avutil.h" nogil:

# Rescales from one time base to another
cdef int64_t av_rescale_q(
int64_t a, # time stamp
AVRational bq, # source time base
AVRational cq # target time base
int64_t a, # time stamp
AVRational bq, # source time base
AVRational cq # target time base
)

# Rescale a 64-bit integer with specified rounding.
Expand All @@ -78,14 +77,14 @@ cdef extern from "libavutil/avutil.h" nogil:
int64_t a,
int64_t b,
int64_t c,
int r # should be AVRounding, but then we can't use bitwise logic.
int r # should be AVRounding, but then we can't use bitwise logic.
)

cdef int64_t av_rescale_q_rnd(
int64_t a,
AVRational bq,
AVRational cq,
int r # should be AVRounding, but then we can't use bitwise logic.
int r # should be AVRounding, but then we can't use bitwise logic.
)

cdef int64_t av_rescale(
Expand Down Expand Up @@ -146,7 +145,6 @@ cdef extern from "libavutil/pixdesc.h" nogil:
int av_get_padded_bits_per_pixel(AVPixFmtDescriptor *pixdesc)



cdef extern from "libavutil/channel_layout.h" nogil:

# Layouts.
Expand All @@ -166,8 +164,6 @@ cdef extern from "libavutil/channel_layout.h" nogil:
cdef char* av_get_channel_description(uint64_t channel)




cdef extern from "libavutil/audio_fifo.h" nogil:

cdef struct AVAudioFifo:
Expand Down
1 change: 0 additions & 1 deletion include/libavutil/error.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cdef extern from "libavutil/error.h" nogil:
cdef int ENOMEM
cdef int EAGAIN


cdef int AVERROR_BSF_NOT_FOUND
cdef int AVERROR_BUG
cdef int AVERROR_BUFFER_TOO_SMALL
Expand Down
3 changes: 1 addition & 2 deletions include/libavutil/samplefmt.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef extern from "libavutil/samplefmt.h" nogil:
AV_SAMPLE_FMT_S32P
AV_SAMPLE_FMT_FLTP
AV_SAMPLE_FMT_DBLP
AV_SAMPLE_FMT_NB # Number.
AV_SAMPLE_FMT_NB # Number.

# Find by name.
cdef AVSampleFormat av_get_sample_fmt(char* name)
Expand Down Expand Up @@ -43,7 +43,6 @@ cdef extern from "libavutil/samplefmt.h" nogil:
int align
)


cdef int av_samples_fill_arrays(
uint8_t **audio_data,
int *linesize,
Expand Down
3 changes: 1 addition & 2 deletions include/libswresample/swresample.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cdef extern from "libswresample/swresample.h" nogil:
cdef char* swresample_configuration()
cdef char* swresample_license()


cdef struct SwrContext:
pass

Expand All @@ -20,7 +19,7 @@ cdef extern from "libswresample/swresample.h" nogil:
AVSampleFormat in_sample_fmt,
int in_sample_rate,
int log_offset,
void *log_ctx #logging context, can be NULL
void *log_ctx # logging context, can be NULL
)

cdef int swr_convert(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def pull_until_blocked(graph):
while True:
try:
frames.append(graph.pull())
except av.utils.AVError as e:
except av.AVError as e:
if e.errno != errno.EAGAIN:
raise
return frames
Expand Down

0 comments on commit 040cb50

Please sign in to comment.