File 0001-Add-compatibility-with-FFMPEG-7.0.patch of Package xpra-5
From 6722df9aeb90857bc1c979c92d47e57903e0ebd6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert-Andr=C3=A9=20Mauchin?= <zebob.m@gmail.com>
Date: Tue, 7 May 2024 07:23:07 +0200
Subject: [PATCH] Add compatibility with FFMPEG 7.0
channel_layout has been replaced with ch_layout
avcodec_close has been deprecated in favor of avcodec_free_context
avio: Constify data pointees of write callbacks
FF_API_FRAME_PICTURE_NUMBER has been deprecated
AV_PIX_FMT_XVMC has been deprecated
---
xpra/codecs/ffmpeg/decoder.pyx | 9 ++-------
xpra/codecs/ffmpeg/encoder.pyx | 37 ++++++++++++++++++++++------------
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/xpra/codecs/ffmpeg/decoder.pyx b/xpra/codecs/ffmpeg/decoder.pyx
index 4f71b5bf1f..f1df36a85a 100644
--- a/xpra/codecs/ffmpeg/decoder.pyx
+++ b/xpra/codecs/ffmpeg/decoder.pyx
@@ -295,6 +295,7 @@ cdef extern from "libavcodec/avcodec.h":
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
AVFrame* av_frame_alloc()
void av_frame_free(AVFrame **frame)
+ int avcodec_close(AVCodecContext *avctx)
#actual decoding:
AVPacket *av_packet_alloc() nogil
@@ -818,7 +819,10 @@ cdef class Decoder:
img.clone_pixel_data()
log("clean_decoder() freeing AVCodecContext: %#x", <uintptr_t> self.codec_ctx)
if self.codec_ctx!=NULL:
- avcodec_free_context(&self.codec_ctx)
+ r = avcodec_close(self.codec_ctx)
+ if r!=0:
+ log.error("Error: failed to close decoder context %#x:", <uintptr_t> self.codec_ctx)
+ log.error(" %s", av_error_str(r))
f = self.file
if f:
self.file = None
diff --git a/xpra/codecs/ffmpeg/encoder.pyx b/xpra/codecs/ffmpeg/encoder.pyx
index 6af88a5629..5df0c590c0 100644
--- a/xpra/codecs/ffmpeg/encoder.pyx
+++ b/xpra/codecs/ffmpeg/encoder.pyx
@@ -120,10 +120,26 @@ cdef extern from "libavformat/avio.h":
AVIOContext *avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag,
void *opaque,
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
- int (*write_packet)(void *opaque, uint8_t *buf, int buf_size) except 0,
+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size) except 0,
int64_t (*seek)(void *opaque, int64_t offset, int whence))
+cdef extern from "libavutil/channel_layout.h":
+ ctypedef int AVChannelOrder
+ ctypedef int AVChannel
+ ctypedef struct AVChannelCustom:
+ AVChannel id
+ char name[16]
+ void *opaque
+ ctypedef union ChannelUnion:
+ uint64_t mask
+ AVChannelCustom* map
+ ctypedef struct AVChannelLayout:
+ AVChannelOrder order
+ int nb_channels
+ ChannelUnion u
+ void *opaque
+
cdef extern from "libavcodec/avcodec.h":
int FF_THREAD_SLICE #allow more than one thread per frame
int FF_THREAD_FRAME #Decode more than one frame at once
@@ -190,8 +206,6 @@ cdef extern from "libavcodec/avcodec.h":
int format
int key_frame
int64_t pts
- int coded_picture_number
- int display_picture_number
int quality
void *opaque
AVPictureType pict_type
@@ -288,14 +302,12 @@ cdef extern from "libavcodec/avcodec.h":
#skipped: AVColor*
int slices
int sample_rate
- int channels
AVSampleFormat sample_fmt
+ AVChannelLayout ch_layout
int frame_size
int frame_number
int block_align
int cutoff
- uint64_t channel_layout
- uint64_t request_channel_layout
#skipped: AVAudioServiceType
# AVSampleFormat
int refcounted_frames
@@ -483,7 +495,7 @@ cdef extern from "libavutil/opt.h":
AVOptionType AV_OPT_TYPE_VIDEO_RATE
AVOptionType AV_OPT_TYPE_DURATION
AVOptionType AV_OPT_TYPE_COLOR
- AVOptionType AV_OPT_TYPE_CHANNEL_LAYOUT
+ AVOptionType AV_OPT_TYPE_CHLAYOUT
AVOptionType AV_OPT_TYPE_BOOL
int AV_OPT_SEARCH_CHILDREN
@@ -686,7 +698,7 @@ AV_OPT_TYPES = {
AV_OPT_TYPE_VIDEO_RATE : "VIDEO_RATE",
AV_OPT_TYPE_DURATION : "DURATION",
AV_OPT_TYPE_COLOR : "COLOR",
- AV_OPT_TYPE_CHANNEL_LAYOUT : "CHANNEL_LAYOUT",
+ AV_OPT_TYPE_CHLAYOUT : "CHANNEL_LAYOUT",
AV_OPT_TYPE_BOOL : "BOOL",
}
@@ -1137,7 +1149,7 @@ cdef list_options(void *obj, const AVClass *av_class, int skip=1):
list_options(child, child_class, skip-1)
-cdef int write_packet(void *opaque, uint8_t *buf, int buf_size) except 0:
+cdef int write_packet(void *opaque, const uint8_t *buf, int buf_size) except 0:
global GEN_TO_ENCODER
encoder = GEN_TO_ENCODER.get(<uintptr_t> opaque)
#log.warn("write_packet(%#x, %#x, %#x) encoder=%s", <uintptr_t> opaque, <uintptr_t> buf, buf_size, type(encoder))
@@ -1504,7 +1517,7 @@ cdef class Encoder:
self.audio_ctx.time_base.num = 1
self.audio_ctx.bit_rate = 64000
self.audio_ctx.sample_rate = 44100
- self.audio_ctx.channels = 2
+ self.audio_ctx.ch_layout.nb_channels = 2
#if audio_codec.capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE:
# pass
#cdef AVDictionary *opts = NULL
@@ -1689,8 +1702,6 @@ cdef class Encoder:
self.av_frame.height = self.height
self.av_frame.format = self.pix_fmt
self.av_frame.pts = self.frames+1
- self.av_frame.coded_picture_number = self.frames+1
- self.av_frame.display_picture_number = self.frames+1
#if self.frames==0:
self.av_frame.pict_type = AV_PICTURE_TYPE_I
#self.av_frame.key_frame = 1
@@ -1823,7 +1834,7 @@ cdef class Encoder:
def write_packet(self, uintptr_t buf, int buf_size):
log("write_packet(%#x, %#x)", <uintptr_t> buf, buf_size)
- cdef uint8_t *cbuf = <uint8_t*> buf
+ cdef const uint8_t *cbuf = <const uint8_t*> buf
buffer = cbuf[:buf_size]
self.buffers.append(buffer)
return buf_size
--
2.44.0