Fix build with ffmpeg

i9m
Arkady L. Shane 8 months ago
parent 84121f3a77
commit edd6374a4e
Signed by: tigro
GPG Key ID: 1EC08A25C9DB2503

@ -0,0 +1,229 @@
--- a/src/utils/ffmpeg-priv.c
+++ b/src/utils/ffmpeg-priv.c
@@ -21,7 +21,7 @@
#include "ffmpeg-priv.h"
-#ifndef HAVE_FUN_avcodec_encode_video2
+#if 0 //ndef HAVE_FUN_avcodec_encode_video2
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) {
int error = avcodec_encode_video(avctx, avpkt->data, avpkt->size, frame);
if (error < 0) {
@@ -40,13 +40,17 @@ int avcodec_encode_video2 (AVCodecContex
#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec) {
+#if LIBAVCODEC_VERSION_MAJOR < 59
avcodec_get_context_defaults(s);
+#endif
return 0;
}
+#if LIBAVCODEC_VERSION_MAJOR < 59
AVCodecContext *avcodec_alloc_context3(AVCodec *codec) {
return avcodec_alloc_context();
}
+#endif
#endif
--- a/src/utils/ffmpeg-priv.h
+++ b/src/utils/ffmpeg-priv.h
@@ -121,8 +121,10 @@ int avcodec_encode_video2 (AVCodecContex
#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
+#if LIBAVCODEC_VERSION_MAJOR < 59
AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
#endif
+#endif
#ifndef HAVE_FUN_avcodec_open2 /**/
int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
@@ -173,5 +175,4 @@ void av_frame_unref (AVFrame *frame);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
-
#endif /* FFMPEG_PRIV_H */
--- a/src/videofilters/h264dec.cpp
+++ b/src/videofilters/h264dec.cpp
@@ -66,13 +66,15 @@ typedef struct _DecData{
static void ffmpeg_init(void) {
static bool_t done = FALSE;
if (!done) {
+#if LIBAVCODEC_VERSION_MAJOR < 59
avcodec_register_all();
+#endif
done = TRUE;
}
}
static void dec_open(DecData *d) {
- AVCodec *codec;
+ const AVCodec *codec;
int error;
codec = avcodec_find_decoder(CODEC_ID_H264);
if (codec == NULL) ms_fatal("Could not find H264 decoder in ffmpeg.");
@@ -164,7 +166,11 @@ static mblk_t *get_as_yuvmsg(MSFilter *f
ms_error("%s: error in sws_scale().", f->desc->name);
}
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 43, 0) // backward compatibility with Debian Squeeze (6.0)
+#if LIBAVUTIL_VERSION_MAJOR < 57
mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
+#else
+ mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
+#endif
#endif
return yuv_msg;
}
@@ -325,7 +331,17 @@ static void dec_process(MSFilter *f){
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 43, 0) // backward compatibility with Debian Squeeze (6.0)
pkt.pts = frame_ts;
#endif
+#if LIBAVCODEC_VERSION_MAJOR < 59
len = avcodec_decode_video2(&d->av_context, d->orig, &got_picture, &pkt);
+#else
+ int ret = avcodec_receive_frame(&d->av_context, d->orig);
+ got_picture = (ret == 0);
+ ret = avcodec_send_packet(&d->av_context, &pkt);
+ if(ret < 0)
+ len = ret;
+ else
+ len = pkt.size;
+#endif
if (len <= 0) {
ms_warning("ms_AVdecoder_process: error %i.", len);
ms_filter_notify_no_arg(f, MS_VIDEO_DECODER_DECODING_ERRORS);
--- a/src/videofilters/videodec.c
+++ b/src/videofilters/videodec.c
@@ -49,7 +49,7 @@ extern void ms_ffmpeg_check_init(void);
typedef struct DecState {
AVCodecContext av_context;
- AVCodec *av_codec;
+ const AVCodec *av_codec;
enum CodecID codec;
mblk_t *input;
YuvBuf outbuf;
@@ -661,7 +661,11 @@ static mblk_t *get_as_yuvmsg(MSFilter *f
#endif
ms_error("%s: error in ms_sws_scale().", f->desc->name);
}
+#if LIBAVCODEC_VERSION_MAJOR < 59
mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
+#else
+ mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
+#endif
return yuv_msg;
}
/* Bitmasks to select bits of a byte from low side */
@@ -719,7 +723,17 @@ static void dec_process_frame(MSFilter *
pkt.data = frame->b_rptr;
pkt.size = remain;
pkt.pts = frame_ts;
+#if LIBAVCODEC_VERSION_MAJOR < 59
len = avcodec_decode_video2(&s->av_context, s->orig, &got_picture, &pkt);
+#else
+ int ret = avcodec_receive_frame(&s->av_context, s->orig);
+ got_picture = (ret == 0);
+ ret = avcodec_send_packet(&s->av_context, &pkt);
+ if (ret < 0)
+ len = ret;
+ else
+ len = pkt.size;
+#endif
if (len <= 0) {
ms_warning("ms_AVdecoder_process: error %i.", len);
--- a/src/videofilters/videoenc.c
+++ b/src/videofilters/videoenc.c
@@ -34,6 +34,10 @@
#include <netinet/in.h> /* ntohl(3) */
#endif
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+#include <libavutil/imgutils.h>
+#endif
+
#include "rfc2429.h"
#if LIBAVCODEC_VERSION_MAJOR >= 57
@@ -128,7 +132,9 @@ void ms_ffmpeg_log_callback(void* ptr, i
void ms_ffmpeg_check_init() {
if (!avcodec_initialized) {
+#if LIBAVCODEC_VERSION_MAJOR < 59
avcodec_register_all();
+#endif
avcodec_initialized = TRUE;
#ifdef ENABLE_LOG_FFMPEG
av_log_set_level(AV_LOG_WARNING);
@@ -139,7 +145,7 @@ void ms_ffmpeg_check_init(){
typedef struct EncState {
AVCodecContext av_context;
- AVCodec *av_codec;
+ const AVCodec *av_codec;
AVFrame *pict;
enum CodecID codec;
mblk_t *comp_buf;
@@ -325,14 +331,20 @@ static void prepare(EncState *s){
ms_message("Codec size set to w=%i/h=%i, bitrate=%i", c->width, c->height, (int)c->bit_rate);
}
+static AVDictionary **codecopts = NULL;
+
static void prepare_h263(EncState *s) {
+#if LIBAVCODEC_VERSION_MAJOR < 59
AVCodecContext *c = &s->av_context;
+ c->rtp_payload_size = s->mtu/2;
+#else
+ av_dict_set_int(codecopts, "ps", s->mtu/2, 0);
+#endif
/* we don't use the rtp_callback but use rtp_mode that forces ffmpeg to insert
Start Codes as much as possible in the bitstream */
#if LIBAVCODEC_VERSION_INT < ((52 << 16) + (0 << 8) + 0)
c->rtp_mode = 1;
#endif
- c->rtp_payload_size = s->mtu / 2;
if (s->profile == 0) {
s->codec = CODEC_ID_H263;
} else {
@@ -382,7 +394,7 @@ static void enc_preprocess(MSFilter *f){
ms_error("could not find encoder for codec id %i", s->codec);
return;
}
- error = avcodec_open2(&s->av_context, s->av_codec, NULL);
+ error=avcodec_open2(&s->av_context, s->av_codec, codecopts);
if (error != 0) {
ms_error("avcodec_open() failed: %i", error);
return;
@@ -815,7 +827,11 @@ static void process_frame(MSFilter *f, m
ms_yuv_buf_init_from_mblk(&yuv, inm);
/* convert image if necessary */
av_frame_unref(s->pict);
+#if LIBAVCODEC_VERSION_MAJOR < 59
avpicture_fill((AVPicture *)s->pict, yuv.planes[0], c->pix_fmt, c->width, c->height);
+#else
+ av_image_fill_arrays(s->pict->data, s->pict->linesize, yuv.planes[0], c->pix_fmt, c->width, c->height, 1);
+#endif
/* timestamp used by ffmpeg, unset here */
s->pict->pts = AV_NOPTS_VALUE;
@@ -840,7 +856,15 @@ static void process_frame(MSFilter *f, m
#endif
packet.data = comp_buf->b_wptr;
packet.size = comp_buf_sz;
+#if LIBAVCODEC_VERSION_MAJOR < 59
error = avcodec_encode_video2(c, &packet, s->pict, &got_packet);
+#else
+ error=avcodec_send_frame(c, s->pict);
+ if(!error) {
+ got_packet = 1;
+ error=avcodec_receive_packet(c, &packet);
+ }
+#endif
if (error < 0) ms_warning("ms_AVencoder_process: error %i.", error);
else if (got_packet) {

@ -14,6 +14,7 @@ Source0: https://gitlab.linphone.org/BC/public/mediastreamer2/-/archive/%{versio
Patch3: mediastreamer-cmake-config-location.patch
Patch4: mediastreamer-system-OpenGL.patch
Patch5: mediastreamer-soname.patch
Patch6: mediastreamer2-5.0.66-ffmpeg-6.0.patch
BuildRequires: libmatroska-devel
BuildRequires: cmake

Loading…
Cancel
Save