xine-lib  1.2.10
ffmpeg_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2018 the xine project
3  *
4  * This file is part of xine, a unix video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * Compability macros for various ffmpeg versions
21  */
22 
23 #ifndef XINE_AVCODEC_COMPAT_H
24 #define XINE_AVCODEC_COMPAT_H
25 
26 #define XFF_INT_VERSION(major,minor,micro) ((major<<16)|(minor<<8)|micro)
27 
28 #ifndef LIBAVCODEC_VERSION_INT
29 # if defined(LIBAVCODEC_VERSION_MAJOR) && defined(LIBAVCODEC_VERSION_MINOR)
30 # define LIBAVCODEC_VERSION_INT XFF_INT_VERSION(LIBAVCODEC_VERSION_MAJOR,LIBAVCODEC_VERSION_MINOR,0)
31 # else
32 # error ffmpeg headers must be included first !
33 # endif
34 #endif
35 
36 #ifndef LIBAVUTIL_VERSION_INT
37 # if defined(LIBAVUTIL_VERSION_MAJOR) && defined(LIBAVUTIL_VERSION_MINOR)
38 # define LIBAVUTIL_VERSION_INT XFF_INT_VERSION(LIBAVUTIL_VERSION_MAJOR,LIBAVUTIL_VERSION_MINOR,0)
39 # else
40 # error ffmpeg headers must be included first !
41 # endif
42 #endif
43 
44 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,0,0)
45 # define bits_per_sample bits_per_coded_sample
46 #endif
47 
48 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,32,0)
49 #else
50 # define pp_context pp_context_t
51 # define pp_mode pp_mode_t
52 #endif
53 
54 /* reordered_opaque appeared in libavcodec 51.68.0 */
55 #define XFF_AVCODEC_REORDERED_OPAQUE
56 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(51,68,0)
57 # undef XFF_AVCODEC_REORDERED_OPAQUE
58 #endif
59 
60 /* colorspace and color_range were added before 52.29.0 */
61 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,29,0)
62 # define XFF_AVCODEC_COLORSPACE
63 #endif
64 
65 /* "unused" as of v54 */
66 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,0,0)
67 # define XFF_AVCODEC_SUB_ID
68 #endif
69 
70 /* not 100% sure about this (between 55.19 and 56.56) */
71 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(56,0,0)
72 # define XFF_AVCODEC_STREAM_CODEC_TAG
73 #endif
74 
75 /* avcodec_thread_init() */
76 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,112,0)
77 # define DEPRECATED_AVCODEC_THREAD_INIT 1
78 #endif
79 
80 /* av_parser_parse() */
81 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,94,0)
82 # define XFF_PARSE 2
83 #else
84 # define XFF_PARSE 1
85 #endif
86 
87 /* avcodec_decode_video* (), avcodec_send_packet (), avcodec_receive_frame () */
88 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(57,106,102)
89 # define XFF_VIDEO 3
90 #elif LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,32,0)
91 # define XFF_VIDEO 2
92 #else
93 # define XFF_VIDEO 1
94 #endif
95 
96 /* avcodec_decode_audio* (), avcodec_send_packet (), avcodec_receive_frame () */
97 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(57,106,102)
98 # define XFF_AUDIO 5
99 #elif LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(54,0,0)
100 # define XFF_AUDIO 4
101 #elif LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,32,0)
102 # define XFF_AUDIO 3
103 #else
104 # define XFF_AUDIO 2
105 #endif
106 
107 /* avcodec_encode_video(), av_packet_unref, avcodec_send_frame (), avcodec_receive_packet () */
108 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(57,106,102)
109 # define XFF_ENCVIDEO 3
110 #elif LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(55,25,100)
111 # define XFF_ENCVIDEO 2
112 #else
113 # define XFF_ENCVIDEO 1
114 #endif
115 
116 /* AVFrame.age not sure about this - original condition was broken */
117 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(53,28,1) && LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,0,0)
118 # define XFF_FRAME_AGE 1
119 #endif
120 
121 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,0,0)
122 /* release 0.7.x (libavcodec 52) has deprecated AVCodecContext.palctrl but for backwards compatibility no
123  working alternative. */
124 # define XFF_PALETTE 1
125 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,92,100)
126 /* pass palette as AVPacket side data, free with av_destruct_packet () after NULLing main data pointer */
127 # define XFF_PALETTE 2
128 #else
129 /* dito, free with av_free_packet () after NULLing main data pointer */
130 # define XFF_PALETTE 3
131 #endif
132 
133 #if LIBAVUTIL_VERSION_INT >= XFF_INT_VERSION(52,0,0)
134 # define PIX_FMT_NONE AV_PIX_FMT_NONE
135 # define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P
136 # define PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P
137 # define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P
138 # define PIX_FMT_YUVJ444P AV_PIX_FMT_YUVJ444P
139 # define PIX_FMT_YUV410P AV_PIX_FMT_YUV410P
140 # define PIX_FMT_YUV411P AV_PIX_FMT_YUV411P
141 # define PIX_FMT_VAAPI_VLD AV_PIX_FMT_VAAPI_VLD
142 # define PIX_FMT_ARGB AV_PIX_FMT_ARGB
143 # define PIX_FMT_BGRA AV_PIX_FMT_BGRA
144 # define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
145 # define PIX_FMT_BGR24 AV_PIX_FMT_BGR24
146 # define PIX_FMT_RGB555BE AV_PIX_FMT_RGB555BE
147 # define PIX_FMT_RGB555LE AV_PIX_FMT_RGB555LE
148 # define PIX_FMT_RGB565BE AV_PIX_FMT_RGB565BE
149 # define PIX_FMT_RGB565LE AV_PIX_FMT_RGB565LE
150 # define PIX_FMT_PAL8 AV_PIX_FMT_PAL8
151 # define PixelFormat AVPixelFormat
152 /* video_out/video_out_vaapi */
153 # define PIX_FMT_VAAPI_IDCT AV_PIX_FMT_VAAPI_IDCT
154 # define PIX_FMT_VAAPI_MOCO AV_PIX_FMT_VAAPI_MOCO
155 #endif
156 
157 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(54,25,0)
158 /* dxr3/ffmpeg_encoder */
159 # define CODEC_ID_MPEG1VIDEO AV_CODEC_ID_MPEG1VIDEO
160 /* video_out/video_out_vaapi */
161 # define CODEC_ID_MPEG2VIDEO AV_CODEC_ID_MPEG2VIDEO
162 # define CODEC_ID_MPEG4 AV_CODEC_ID_MPEG4
163 # define CODEC_ID_H263 AV_CODEC_ID_H263
164 # define CODEC_ID_H264 AV_CODEC_ID_H264
165 # define CODEC_ID_WMV3 AV_CODEC_ID_WMV3
166 /* video_out/video_out_vaapi, ff_video_decoder */
167 # define CODEC_ID_VC1 AV_CODEC_ID_VC1
168 /* ff_video_decoder */
169 # define CODEC_ID_SVQ3 AV_CODEC_ID_SVQ3
170 # define CODEC_ID_MSMPEG4V1 AV_CODEC_ID_MSMPEG4V1
171 # define CODEC_ID_MSMPEG4V2 AV_CODEC_ID_MSMPEG4V2
172 # define CODEC_ID_MSMPEG4V3 AV_CODEC_ID_MSMPEG4V3
173 # define CODEC_ID_WMV1 AV_CODEC_ID_WMV1
174 # define CODEC_ID_WMV2 AV_CODEC_ID_WMV2
175 /* demux_avformat */
176 # define CODEC_ID_PCM_S16LE AV_CODEC_ID_PCM_S16LE
177 # define CODEC_ID_PCM_S16BE AV_CODEC_ID_PCM_S16BE
178 # define CODEC_ID_MP2 AV_CODEC_ID_MP2
179 # define CODEC_ID_AC3 AV_CODEC_ID_AC3
180 /* ff_*_decoder mapping is already handled by mkcodeclists.pl */
181 #endif
182 
183 #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
184 # define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
185 #endif
186 
187 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(55,0,100)
188 # define XFF_AV_BUFFER 1
189 #endif
190 
191 /* function aliases */
192 
193 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(52,66,0)
194 # define XFF_EDGE_WIDTH() (16)
195 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,48,102)
196 # define XFF_EDGE_WIDTH() avcodec_get_edge_width()
197 #else
198 /* edges not needed anymore supposedly */
199 # define XFF_EDGE_WIDTH() (0)
200 #endif
201 
202 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,8,0)
203 # define XFF_AVCODEC_INIT() avcodec_init()
204 #else
205 # define XFF_AVCODEC_INIT() do {} while(0)
206 #endif
207 
208 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,6,0)
209 # define XFF_ALLOC_CONTEXT() avcodec_alloc_context()
210 #else
211 # define XFF_ALLOC_CONTEXT() avcodec_alloc_context3(NULL)
212 #endif
213 
214 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,6,0)
215 # define XFF_AVCODEC_OPEN(ctx,codec) avcodec_open(ctx,codec)
216 #else
217 # define XFF_AVCODEC_OPEN(ctx,codec) avcodec_open2(ctx, codec, NULL)
218 #endif
219 
220 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,63,100)
221 # define XFF_FREE_CONTEXT(pp) do {av_free(pp); pp = NULL;} while (0)
222 #else
223 # define XFF_FREE_CONTEXT(pp) avcodec_free_context(&(pp))
224 #endif
225 
226 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,59,100)
227 # define XFF_ALLOC_FRAME() avcodec_alloc_frame()
228 # define XFF_FREE_FRAME(pp) do {av_free(pp); pp = NULL;} while (0)
229 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,45,101)
230 # define XFF_ALLOC_FRAME() avcodec_alloc_frame()
231 # define XFF_FREE_FRAME(pp) avcodec_free_frame(&(pp))
232 #else
233 # define XFF_ALLOC_FRAME() av_frame_alloc()
234 # define XFF_FREE_FRAME(pp) av_frame_free(&(pp))
235 #endif
236 
237 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(57,12,100)
238 #define XFF_PACKET_UNREF av_free_packet
239 #else
240 #define XFF_PACKET_UNREF av_packet_unref
241 #endif
242 
243 #ifndef AV_INPUT_BUFFER_PADDING_SIZE
244 # define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
245 #endif
246 #ifndef AV_CODEC_CAP_DR1
247 # define AV_CODEC_CAP_DR1 CODEC_CAP_DR1
248 #endif
249 #ifndef AV_CODEC_FLAG2_FAST
250 # define AV_CODEC_FLAG2_FAST CODEC_FLAG2_FAST
251 #endif
252 
253 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(58,10,100)
254 # define XFF_AVCODEC_REGISTER_ALL() avcodec_register_all()
255 #else
256 # define XFF_AVCODEC_REGISTER_ALL() do {} while(0)
257 #endif
258 
259 #endif /* XINE_AVCODEC_COMPAT_H */