Skip to content

Commit 5eb23e1

Browse files
authored
Merge pull request #172 from misl6/move-to-cython3
Migrate to Cython 3
2 parents 93d1c33 + 6b6dfe6 commit 5eb23e1

6 files changed

Lines changed: 22 additions & 21 deletions

File tree

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
ls $env:FFMPEG_ROOT
6262
- name: Install pip deps
6363
run: |
64-
python -m pip install --upgrade pip virtualenv wheel setuptools cython~=0.29.36 pytest
64+
python -m pip install --upgrade pip virtualenv wheel setuptools cython~=3.0.11 pytest
6565
- name: Make sdist
6666
if: matrix.python == '3.12'
6767
run: python setup.py sdist --formats=gztar

doc/source/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Requirements
2828

2929
To compile ffpyplayer we need:
3030

31-
* Cython (``pip install --upgrade cython~=0.29.36``).
31+
* Cython (``pip install --upgrade cython~=3.0.11``).
3232
* A c compiler e.g. gcc or MSVC.
3333
* SDL2 or SDL1.2 (SDL1.2 is not recommended). See :ref:`compille` for how to get it.
3434
* SDL2_mixer If wanting to play multiple audio files simultaneously (``USE_SDL2_MIXER`` must be set). See :ref:`compille` for how to get it.
@@ -41,7 +41,7 @@ Compiling ffpyplayer
4141
* Download or compile FFMpeg and SDL2 as shown below and set the appropriate environment variables as needed.
4242
* Install Cython with e.g.::
4343

44-
pip install --upgrade cython~=0.29.36
44+
pip install --upgrade cython~=3.0.11
4545

4646
* You can select the FFmpeg libraries to be used by defining values for CONFIG_XXX.
4747
For example, CONFIG_AVFILTER=0 will disable inclusion of the FFmpeg avfilter libraries.

ffpyplayer/player/core.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ cdef class VideoState(object):
16161616
if self.audio_dev == -1:
16171617
return -1
16181618

1619-
if not Mix_RegisterEffect(self.audio_dev, <void (*)(int, void *, int, void *) nogil>sdl_mixer_callback, NULL, self.self_id):
1619+
if not Mix_RegisterEffect(self.audio_dev, <void (*)(int, void *, int, void *) noexcept nogil>sdl_mixer_callback, NULL, self.self_id):
16201620
return -1
16211621

16221622
ELSE:
@@ -1654,7 +1654,7 @@ cdef class VideoState(object):
16541654
wanted_spec.format = AUDIO_S16SYS
16551655
wanted_spec.silence = 0
16561656
wanted_spec.samples = FFMAX(AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq // AUDIO_MAX_CALLBACKS_PER_SEC))
1657-
wanted_spec.callback = <void (*)(void *, uint8_t *, int) nogil>self.sdl_audio_callback
1657+
wanted_spec.callback = <void (*)(void *, uint8_t *, int) noexcept nogil>self.sdl_audio_callback
16581658
wanted_spec.userdata = self.self_id
16591659

16601660
error = self.open_audio_device(&wanted_spec, &spec)
@@ -1869,7 +1869,7 @@ cdef class VideoState(object):
18691869
if codecpar.codec_type == AVMEDIA_TYPE_AUDIO:
18701870
self.auddec.decoder_abort(self.sampq)
18711871
IF USE_SDL2_MIXER:
1872-
Mix_UnregisterEffect(self.audio_dev, <void (*)(int, void *, int, void *) nogil>sdl_mixer_callback)
1872+
Mix_UnregisterEffect(self.audio_dev, <void (*)(int, void *, int, void *) noexcept nogil>sdl_mixer_callback)
18731873
Mix_HaltChannel(self.audio_dev)
18741874
Mix_FreeChunk(self.chunk)
18751875
self.chunk = NULL
@@ -1942,7 +1942,7 @@ cdef class VideoState(object):
19421942
av_log(NULL, AV_LOG_FATAL, b"Could not allocate context.\n");
19431943
return self.failed(AVERROR(ENOMEM), ic, &pkt)
19441944
#av_opt_set_int(ic, b"threads", 1, 0)
1945-
ic.interrupt_callback.callback = <int (*)(void *)>self.decode_interrupt_cb
1945+
ic.interrupt_callback.callback = <int (*)(void *) noexcept>self.decode_interrupt_cb
19461946
ic.interrupt_callback.opaque = self.self_id
19471947

19481948
if not av_dict_get(self.player.format_opts, b"scan_all_pmts", NULL, AV_DICT_MATCH_CASE):

ffpyplayer/tools.pyx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ the log.
7878
'''
7979
_loglevel_inverse = {v:k for k, v in loglevels.iteritems()}
8080

81-
codecs_enc = get_codecs(encode=True, video=True)
82-
'''A list of all the codecs available for encoding video. '''
83-
codecs_dec = get_codecs(decode=True, video=True, audio=True)
84-
'''A list of all the codecs available for decoding video and audio. '''
85-
pix_fmts = list_pixfmts()
86-
'''A list of all the pixel formats available to ffmpeg. '''
87-
formats_in = get_fmts(input=True)[0]
88-
'''A list of all the formats (e.g. file formats) available for reading. '''
89-
formats_out = get_fmts(output=True)[0]
90-
'''A list of all the formats (e.g. file formats) available for writing. '''
91-
9281
cdef object _log_callback = None
9382
cdef MTMutex _log_mutex= MTMutex(SDL_MT)
9483
cdef int log_level = AV_LOG_WARNING
@@ -105,7 +94,7 @@ cdef void call_callback(char *line, int level) nogil:
10594
with gil:
10695
gil_call_callback(line, level)
10796

108-
cdef void _log_callback_func(void* ptr, int level, const char* fmt, va_list vl) nogil:
97+
cdef void _log_callback_func(void* ptr, int level, const char* fmt, va_list vl) noexcept nogil:
10998
cdef char line[2048]
11099
if fmt == NULL or level > log_level:
111100
return
@@ -278,6 +267,11 @@ cpdef get_codecs(
278267
codec = av_codec_iterate(&iter_codec)
279268
return sorted(codecs)
280269

270+
codecs_enc = get_codecs(encode=True, video=True)
271+
'''A list of all the codecs available for encoding video. '''
272+
codecs_dec = get_codecs(decode=True, video=True, audio=True)
273+
'''A list of all the codecs available for decoding video and audio. '''
274+
281275
cdef list list_pixfmts():
282276
cdef list fmts = []
283277
cdef const AVPixFmtDescriptor *desc = NULL
@@ -288,6 +282,9 @@ cdef list list_pixfmts():
288282
desc = av_pix_fmt_desc_next(desc)
289283
return sorted(fmts)
290284

285+
pix_fmts = list_pixfmts()
286+
'''A list of all the pixel formats available to ffmpeg. '''
287+
291288
cpdef get_fmts(int input=False, int output=False):
292289
'''Returns the formats available in FFmpeg.
293290
@@ -350,6 +347,10 @@ cpdef get_fmts(int input=False, int output=False):
350347
fmts = sorted(fmts)
351348
return fmts, full_names, exts
352349

350+
formats_in = get_fmts(input=True)[0]
351+
'''A list of all the formats (e.g. file formats) available for reading. '''
352+
formats_out = get_fmts(output=True)[0]
353+
'''A list of all the formats (e.g. file formats) available for writing. '''
353354

354355
def get_format_codec(filename=None, fmt=None):
355356
'''Returns the best codec associated with the file format. The format

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[build-system]
22
requires = [
3-
"setuptools", "wheel", "cython~=0.29.36",
3+
"setuptools", "wheel", "cython~=3.0.11",
44
]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def get_wheel_data():
376376

377377
setup_requires = []
378378
if declare_cython:
379-
setup_requires.append('cython~=0.29.36')
379+
setup_requires.append('cython~=3.0.11')
380380

381381
setup(name='ffpyplayer',
382382
version=ffpyplayer.__version__,

0 commit comments

Comments
 (0)