summarylogtreecommitdiffstats
path: root/ffmpeg5.patch
blob: c2441e11bd1357d8374d218916781d7ad98f3878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
diff --git a/src/utils/ffmpeg-priv.c b/src/utils/ffmpeg-priv.c
index a3a801a9..9d696f17 100644
--- a/src/utils/ffmpeg-priv.c
+++ b/src/utils/ffmpeg-priv.c
@@ -23,31 +23,22 @@
 
 #ifndef 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){
-		return error;
-	}else{
-		if (error>0) {
-			*got_packet_ptr=1;
-			avpkt->size=error;
-		}else *got_packet_ptr=0;
-	}
-	return 0;
-}
-#endif
+    int ret;
 
+    *got_packet_ptr = 0;
 
+    ret = avcodec_send_frame(avctx, frame);
+    if (ret < 0)
+        return ret;
 
-#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
-int avcodec_get_context_defaults3 (AVCodecContext *s, AVCodec *codec) {
-	avcodec_get_context_defaults(s);
-	return 0;
-}
+    ret = avcodec_receive_packet(avctx, avpkt);
+    if (!ret)
+        *got_packet_ptr = 1;
+    if (ret == AVERROR(EAGAIN))
+        return 0;
 
-AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
-	return avcodec_alloc_context();
+    return ret;
 }
-
 #endif
 
 
diff --git a/src/utils/ffmpeg-priv.h b/src/utils/ffmpeg-priv.h
index 18338201..3ffeb088 100644
--- a/src/utils/ffmpeg-priv.h
+++ b/src/utils/ffmpeg-priv.h
@@ -79,6 +79,29 @@ static inline int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
                          AVPacket *avpkt){
 	return avcodec_decode_video(avctx,picture, got_picture_ptr,avpkt->data,avpkt->size);
 }
+#else
+static inline int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
+{
+    int ret;
+
+    *got_frame = 0;
+
+    if (pkt) {
+        ret = avcodec_send_packet(avctx, pkt);
+        // In particular, we don't expect AVERROR(EAGAIN), because we read all
+        // decoded frames with avcodec_receive_frame() until done.
+        if (ret < 0)
+            return ret == AVERROR_EOF ? 0 : ret;
+    }
+
+    ret = avcodec_receive_frame(avctx, frame);
+    if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
+        return ret;
+    if (ret >= 0)
+        *got_frame = 1;
+
+    return 0;
+}
 #endif
 #if HAVE_AVCODEC_OLD_CODEC_IDS
 #include <libavcodec/old_codec_ids.h>
@@ -119,11 +142,6 @@ extern "C" {
 int avcodec_encode_video2 (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr);
 #endif
 
-#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
-int avcodec_get_context_defaults3 (AVCodecContext *s, AVCodec *codec);
-AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
-#endif
-
 #ifndef HAVE_FUN_avcodec_open2 /**/
 int avcodec_open2 (AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
 #endif
diff --git a/src/utils/jpgloader-ffmpeg.c b/src/utils/jpgloader-ffmpeg.c
index 62cf41db..9952fab7 100644
--- a/src/utils/jpgloader-ffmpeg.c
+++ b/src/utils/jpgloader-ffmpeg.c
@@ -75,7 +75,6 @@ mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize){
 		return NULL;
 	}
 
-	avcodec_get_context_defaults3(&av_context,NULL);
 	if (avcodec_open2(&av_context,codec,NULL)<0){
 		ms_error("jpeg2yuv: avcodec_open failed");
 		return NULL;
diff --git a/src/videofilters/ffmpegjpegwriter.c b/src/videofilters/ffmpegjpegwriter.c
index 5ee16b8d..8d1638f6 100644
--- a/src/videofilters/ffmpegjpegwriter.c
+++ b/src/videofilters/ffmpegjpegwriter.c
@@ -174,7 +174,7 @@ static void jpg_process(MSFilter *f){
 			sws_freeContext(sws_ctx);
 
 			av_frame_unref(s->pict);
-			avpicture_fill((AVPicture*)s->pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
+			av_image_fill_arrays(s->pict->data,s->pict->linesize,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height, 1);
 			packet.data=comp_buf;
 			packet.size=(int)comp_buf_sz;
 			packet.pts = frame_ts;
diff --git a/src/videofilters/h264dec.cpp b/src/videofilters/h264dec.cpp
index e3cd82cc..bed94bb0 100644
--- a/src/videofilters/h264dec.cpp
+++ b/src/videofilters/h264dec.cpp
@@ -66,17 +66,15 @@ typedef struct _DecData{
 static void ffmpeg_init(void){
 	static bool_t done=FALSE;
 	if (!done){
-		avcodec_register_all();
 		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.");
-	avcodec_get_context_defaults3(&d->av_context, NULL);
 	error=avcodec_open2(&d->av_context,codec, NULL);
 	if (error!=0){
 		ms_fatal("avcodec_open() failed.");
@@ -164,7 +162,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f, DecData *s, AVFrame *orig){
 		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)
-	mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
+	mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
 #endif
 	return yuv_msg;
 }
diff --git a/src/videofilters/videodec.c b/src/videofilters/videodec.c
index d5dbcaa2..2b223349 100644
--- a/src/videofilters/videodec.c
+++ b/src/videofilters/videodec.c
@@ -69,7 +69,6 @@ static void dec_init(MSFilter *f, enum CodecID cid){
 	DecState *s=(DecState *)ms_new0(DecState,1);
 	ms_ffmpeg_check_init();
 
-	avcodec_get_context_defaults3(&s->av_context, NULL);
 	s->allocator = ms_yuv_buf_allocator_new();
 	s->av_codec=NULL;
 	s->codec=cid;
@@ -661,7 +660,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f, DecState *s, AVFrame *orig){
 #endif
 		ms_error("%s: error in ms_sws_scale().",f->desc->name);
 	}
-	mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pkt_pts);
+	mblk_set_timestamp_info(yuv_msg, (uint32_t)orig->pts);
 	return yuv_msg;
 }
 /* Bitmasks to select bits of a byte from low side */
diff --git a/src/videofilters/videoenc.c b/src/videofilters/videoenc.c
index 42d3a05e..7e3575d4 100644
--- a/src/videofilters/videoenc.c
+++ b/src/videofilters/videoenc.c
@@ -128,7 +128,6 @@ void ms_ffmpeg_log_callback(void* ptr, int level, const char* fmt, va_list vl)
 
 void ms_ffmpeg_check_init(){
 	if(!avcodec_initialized){
-		avcodec_register_all();
 		avcodec_initialized=TRUE;
 #ifdef ENABLE_LOG_FFMPEG
 		av_log_set_level(AV_LOG_WARNING);
@@ -268,7 +267,6 @@ static void prepare(EncState *s){
 	AVCodecContext *c=&s->av_context;
 	const int max_br_vbv=128000;
 
-	avcodec_get_context_defaults3(c, NULL);
 	if (s->codec==CODEC_ID_MJPEG)
 	{
 		ms_message("Codec bitrate set to %i",(int)c->bit_rate);
@@ -332,7 +330,6 @@ static void prepare_h263(EncState *s){
 #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{
@@ -815,7 +812,7 @@ static void process_frame(MSFilter *f, mblk_t *inm){
 	ms_yuv_buf_init_from_mblk(&yuv, inm);
 	/* convert image if necessary */
 	av_frame_unref(s->pict);
-	avpicture_fill((AVPicture*)s->pict,yuv.planes[0],c->pix_fmt,c->width,c->height);
+	av_image_fill_arrays(s->pict->data,s->pict->linesize,yuv.planes[0],c->pix_fmt,c->width,c->height,1);
 
 	/* timestamp used by ffmpeg, unset here */
 	s->pict->pts=AV_NOPTS_VALUE;