projects/aports·blob master · refs

224 lines · 7.9 KiB

1Based on: https://build.opensuse.org/projects/openSUSE:Factory/packages/mediastreamer2/files/fix-build-ffmpeg5.patch
2
3Index: mediastreamer2-5.3.4/src/utils/ffmpeg-priv.c
4===================================================================
5--- mediastreamer2-5.3.4.orig/src/utils/ffmpeg-priv.c
6+++ mediastreamer2-5.3.4/src/utils/ffmpeg-priv.c
7@@ -23,29 +23,22 @@
8
9 #ifndef HAVE_FUN_avcodec_encode_video2
10 int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) {
11- int error = avcodec_encode_video(avctx, avpkt->data, avpkt->size, frame);
12- if (error < 0) {
13- return error;
14- } else {
15- if (error > 0) {
16- *got_packet_ptr = 1;
17- avpkt->size = error;
18- } else *got_packet_ptr = 0;
19- }
20- return 0;
21-}
22-#endif
23+ int ret;
24
25-#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
26-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec) {
27- avcodec_get_context_defaults(s);
28- return 0;
29-}
30+ *got_packet_ptr = 0;
31+
32+ ret = avcodec_send_frame(avctx, frame);
33+ if (ret < 0)
34+ return ret;
35
36-AVCodecContext *avcodec_alloc_context3(AVCodec *codec) {
37- return avcodec_alloc_context();
38-}
39+ ret = avcodec_receive_packet(avctx, avpkt);
40+ if (!ret)
41+ *got_packet_ptr = 1;
42+ if (ret == AVERROR(EAGAIN))
43+ return 0;
44
45+ return ret;
46+}
47 #endif
48
49 #ifndef HAVE_FUN_avcodec_open2 /**/
50Index: mediastreamer2-5.3.4/src/utils/ffmpeg-priv.h
51===================================================================
52--- mediastreamer2-5.3.4.orig/src/utils/ffmpeg-priv.h
53+++ mediastreamer2-5.3.4/src/utils/ffmpeg-priv.h
54@@ -76,6 +76,29 @@ static inline int
55 avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) {
56 return avcodec_decode_video(avctx, picture, got_picture_ptr, avpkt->data, avpkt->size);
57 }
58+#else
59+static inline int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
60+{
61+ int ret;
62+
63+ *got_frame = 0;
64+
65+ if (pkt) {
66+ ret = avcodec_send_packet(avctx, pkt);
67+ // In particular, we don't expect AVERROR(EAGAIN), because we read all
68+ // decoded frames with avcodec_receive_frame() until done.
69+ if (ret < 0)
70+ return ret == AVERROR_EOF ? 0 : ret;
71+ }
72+
73+ ret = avcodec_receive_frame(avctx, frame);
74+ if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
75+ return ret;
76+ if (ret >= 0)
77+ *got_frame = 1;
78+
79+ return 0;
80+}
81 #endif
82 #if HAVE_AVCODEC_OLD_CODEC_IDS
83 #include <libavcodec/old_codec_ids.h>
84@@ -116,11 +139,6 @@ extern "C" {
85 int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr);
86 #endif
87
88-#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
89-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
90-AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
91-#endif
92-
93 #ifndef HAVE_FUN_avcodec_open2 /**/
94 int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
95 #endif
96Index: mediastreamer2-5.3.4/src/utils/jpgloader-ffmpeg.c
97===================================================================
98--- mediastreamer2-5.3.4.orig/src/utils/jpgloader-ffmpeg.c
99+++ mediastreamer2-5.3.4/src/utils/jpgloader-ffmpeg.c
100@@ -76,7 +76,6 @@ mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bu
101 return NULL;
102 }
103
104- avcodec_get_context_defaults3(&av_context, NULL);
105 if (avcodec_open2(&av_context, codec, NULL) < 0) {
106 ms_error("jpeg2yuv: avcodec_open failed");
107 return NULL;
108Index: mediastreamer2-5.3.4/src/videofilters/ffmpegjpegwriter.c
109===================================================================
110--- mediastreamer2-5.3.4.orig/src/videofilters/ffmpegjpegwriter.c
111+++ mediastreamer2-5.3.4/src/videofilters/ffmpegjpegwriter.c
112@@ -190,7 +190,7 @@ static void jpg_process_frame_task(void
113 sws_freeContext(sws_ctx);
114
115 av_frame_unref(s->pict);
116- avpicture_fill((AVPicture *)s->pict, (uint8_t *)jpegm->b_rptr, avctx->pix_fmt, avctx->width, avctx->height);
117+ av_image_fill_arrays(s->pict->data,s->pict->linesize,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height, 1);
118 packet.data = comp_buf;
119 packet.size = (int)comp_buf_sz;
120 packet.pts = frame_ts;
121Index: mediastreamer2-5.3.4/src/videofilters/h264dec.cpp
122===================================================================
123--- mediastreamer2-5.3.4.orig/src/videofilters/h264dec.cpp
124+++ mediastreamer2-5.3.4/src/videofilters/h264dec.cpp
125@@ -66,17 +66,15 @@ typedef struct _DecData {
126 static void ffmpeg_init(void) {
127 static bool_t done = FALSE;
128 if (!done) {
129- avcodec_register_all();
130 done = TRUE;
131 }
132 }
133
134 static void dec_open(DecData *d) {
135- AVCodec *codec;
136+ const AVCodec *codec;
137 int error;
138 codec = avcodec_find_decoder(CODEC_ID_H264);
139 if (codec == NULL) ms_fatal("Could not find H264 decoder in ffmpeg.");
140- avcodec_get_context_defaults3(&d->av_context, NULL);
141 error = avcodec_open2(&d->av_context, codec, NULL);
142 if (error != 0) {
143 ms_fatal("avcodec_open() failed.");
144@@ -162,7 +160,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f
145 ms_error("%s: error in sws_scale().", f->desc->name);
146 }
147 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 43, 0) // backward compatibility with Debian Squeeze (6.0)
148- mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
149+ mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
150 #endif
151 return yuv_msg;
152 }
153Index: mediastreamer2-5.3.4/src/videofilters/videodec.c
154===================================================================
155--- mediastreamer2-5.3.4.orig/src/videofilters/videodec.c
156+++ mediastreamer2-5.3.4/src/videofilters/videodec.c
157@@ -67,7 +67,6 @@ static void dec_init(MSFilter *f, enum C
158 DecState *s = (DecState *)ms_new0(DecState, 1);
159 ms_ffmpeg_check_init();
160
161- avcodec_get_context_defaults3(&s->av_context, NULL);
162 s->allocator = ms_yuv_buf_allocator_new();
163 s->av_codec = NULL;
164 s->codec = cid;
165@@ -591,7 +590,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f
166 #endif
167 ms_error("%s: error in ms_sws_scale().", f->desc->name);
168 }
169- mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
170+ mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
171 return yuv_msg;
172 }
173 /* Bitmasks to select bits of a byte from low side */
174Index: mediastreamer2-5.3.4/src/videofilters/videoenc.c
175===================================================================
176--- mediastreamer2-5.3.4.orig/src/videofilters/videoenc.c
177+++ mediastreamer2-5.3.4/src/videofilters/videoenc.c
178@@ -109,7 +109,6 @@ void ms_ffmpeg_log_callback(void *ptr, i
179
180 void ms_ffmpeg_check_init() {
181 if (!avcodec_initialized) {
182- avcodec_register_all();
183 avcodec_initialized = TRUE;
184 #ifdef ENABLE_LOG_FFMPEG
185 av_log_set_level(AV_LOG_WARNING);
186@@ -250,7 +249,6 @@ static void prepare(EncState *s) {
187 AVCodecContext *c = &s->av_context;
188 const int max_br_vbv = 128000;
189
190- avcodec_get_context_defaults3(c, NULL);
191 if (s->codec == CODEC_ID_MJPEG) {
192 ms_message("Codec bitrate set to %i", (int)c->bit_rate);
193 c->width = s->vconf.vsize.width;
194@@ -312,7 +310,6 @@ static void prepare_h263(EncState *s) {
195 #if LIBAVCODEC_VERSION_INT < ((52 << 16) + (0 << 8) + 0)
196 c->rtp_mode = 1;
197 #endif
198- c->rtp_payload_size = s->mtu / 2;
199 if (s->profile == 0) {
200 s->codec = CODEC_ID_H263;
201 } else {
202@@ -787,7 +784,7 @@ static void process_frame(MSFilter *f, m
203 ms_yuv_buf_init_from_mblk(&yuv, inm);
204 /* convert image if necessary */
205 av_frame_unref(s->pict);
206- avpicture_fill((AVPicture *)s->pict, yuv.planes[0], c->pix_fmt, c->width, c->height);
207+ av_image_fill_arrays(s->pict->data,s->pict->linesize,yuv.planes[0],c->pix_fmt,c->width,c->height,1);
208
209 /* timestamp used by ffmpeg, unset here */
210 s->pict->pts = AV_NOPTS_VALUE;
211
212
213diff --git a/src/utils/ffmpeg-priv.h b/src/utils/ffmpeg-priv.h
214index f8113d5..c31c1b2 100644
215--- a/src/utils/ffmpeg-priv.h
216+++ b/src/utils/ffmpeg-priv.h
217@@ -50,6 +50,7 @@ extern "C" {
218 /* new layout */
219 #include <libavcodec/avcodec.h>
220 #include <libavutil/avutil.h>
221+#include <libavutil/imgutils.h>
222 #include <libavutil/mem.h>
223 #endif
224