xine-lib  1.2.9
ffmpeg_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2017 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() */
88 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,32,0)
89 # define XFF_VIDEO 2
90 #else
91 # define XFF_VIDEO 1
92 #endif
93 
94 /* avcodec_decode_audio() */
95 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(54,0,0)
96 # define XFF_AUDIO 4
97 #elif LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(52,32,0)
98 # define XFF_AUDIO 3
99 #else
100 # define XFF_AUDIO 2
101 #endif
102 
103 /* avcodec_encode_video(), av_packet_unref */
104 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(55,25,100)
105 # define XFF_ENCVIDEO 2
106 #else
107 # define XFF_ENCVIDEO 1
108 #endif
109 
110 /* AVFrame.age not sure about this - original condition was broken */
111 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(53,28,1) && LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,0,0)
112 # define XFF_FRAME_AGE 1
113 #endif
114 
115 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,0,0)
116 /* release 0.7.x (libavcodec 52) has deprecated AVCodecContext.palctrl but for backwards compatibility no
117  working alternative. */
118 # define XFF_PALETTE 1
119 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,92,100)
120 /* pass palette as AVPacket side data, free with av_destruct_packet () after NULLing main data pointer */
121 # define XFF_PALETTE 2
122 #else
123 /* dito, free with av_free_packet () after NULLing main data pointer */
124 # define XFF_PALETTE 3
125 #endif
126 
127 #if LIBAVUTIL_VERSION_INT >= XFF_INT_VERSION(52,0,0)
128 # define PIX_FMT_NONE AV_PIX_FMT_NONE
129 # define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P
130 # define PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P
131 # define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P
132 # define PIX_FMT_YUVJ444P AV_PIX_FMT_YUVJ444P
133 # define PIX_FMT_YUV410P AV_PIX_FMT_YUV410P
134 # define PIX_FMT_YUV411P AV_PIX_FMT_YUV411P
135 # define PIX_FMT_VAAPI_VLD AV_PIX_FMT_VAAPI_VLD
136 # define PIX_FMT_ARGB AV_PIX_FMT_ARGB
137 # define PIX_FMT_BGRA AV_PIX_FMT_BGRA
138 # define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
139 # define PIX_FMT_BGR24 AV_PIX_FMT_BGR24
140 # define PIX_FMT_RGB555BE AV_PIX_FMT_RGB555BE
141 # define PIX_FMT_RGB555LE AV_PIX_FMT_RGB555LE
142 # define PIX_FMT_RGB565BE AV_PIX_FMT_RGB565BE
143 # define PIX_FMT_RGB565LE AV_PIX_FMT_RGB565LE
144 # define PIX_FMT_PAL8 AV_PIX_FMT_PAL8
145 # define PixelFormat AVPixelFormat
146 /* video_out/video_out_vaapi */
147 # define PIX_FMT_VAAPI_IDCT AV_PIX_FMT_VAAPI_IDCT
148 # define PIX_FMT_VAAPI_MOCO AV_PIX_FMT_VAAPI_MOCO
149 #endif
150 
151 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(54,25,0)
152 /* dxr3/ffmpeg_encoder */
153 # define CODEC_ID_MPEG1VIDEO AV_CODEC_ID_MPEG1VIDEO
154 /* video_out/video_out_vaapi */
155 # define CODEC_ID_MPEG2VIDEO AV_CODEC_ID_MPEG2VIDEO
156 # define CODEC_ID_MPEG4 AV_CODEC_ID_MPEG4
157 # define CODEC_ID_H263 AV_CODEC_ID_H263
158 # define CODEC_ID_H264 AV_CODEC_ID_H264
159 # define CODEC_ID_WMV3 AV_CODEC_ID_WMV3
160 /* video_out/video_out_vaapi, ff_video_decoder */
161 # define CODEC_ID_VC1 AV_CODEC_ID_VC1
162 /* ff_video_decoder */
163 # define CODEC_ID_SVQ3 AV_CODEC_ID_SVQ3
164 # define CODEC_ID_MSMPEG4V1 AV_CODEC_ID_MSMPEG4V1
165 # define CODEC_ID_MSMPEG4V2 AV_CODEC_ID_MSMPEG4V2
166 # define CODEC_ID_MSMPEG4V3 AV_CODEC_ID_MSMPEG4V3
167 # define CODEC_ID_WMV1 AV_CODEC_ID_WMV1
168 # define CODEC_ID_WMV2 AV_CODEC_ID_WMV2
169 /* demux_avformat */
170 # define CODEC_ID_PCM_S16LE AV_CODEC_ID_PCM_S16LE
171 # define CODEC_ID_PCM_S16BE AV_CODEC_ID_PCM_S16BE
172 # define CODEC_ID_MP2 AV_CODEC_ID_MP2
173 # define CODEC_ID_AC3 AV_CODEC_ID_AC3
174 /* ff_*_decoder mapping is already handled by mkcodeclists.pl */
175 #endif
176 
177 #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
178 # define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
179 #endif
180 
181 #if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(55,0,100)
182 # define XFF_AV_BUFFER 1
183 #endif
184 
185 /* function aliases */
186 
187 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(52,66,0)
188 # define XFF_EDGE_WIDTH() (16)
189 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,48,102)
190 # define XFF_EDGE_WIDTH() avcodec_get_edge_width()
191 #else
192 /* edges not needed anymore supposedly */
193 # define XFF_EDGE_WIDTH() (0)
194 #endif
195 
196 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,8,0)
197 # define XFF_AVCODEC_INIT() avcodec_init()
198 #else
199 # define XFF_AVCODEC_INIT() do {} while(0)
200 #endif
201 
202 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,6,0)
203 # define XFF_ALLOC_CONTEXT() avcodec_alloc_context()
204 #else
205 # define XFF_ALLOC_CONTEXT() avcodec_alloc_context3(NULL)
206 #endif
207 
208 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(53,6,0)
209 # define XFF_AVCODEC_OPEN(ctx,codec) avcodec_open(ctx,codec)
210 #else
211 # define XFF_AVCODEC_OPEN(ctx,codec) avcodec_open2(ctx, codec, NULL)
212 #endif
213 
214 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,63,100)
215 # define XFF_FREE_CONTEXT(pp) do {av_free(pp); pp = NULL;} while (0)
216 #else
217 # define XFF_FREE_CONTEXT(pp) avcodec_free_context(&(pp))
218 #endif
219 
220 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,59,100)
221 # define XFF_ALLOC_FRAME() avcodec_alloc_frame()
222 # define XFF_FREE_FRAME(pp) do {av_free(pp); pp = NULL;} while (0)
223 #elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,45,101)
224 # define XFF_ALLOC_FRAME() avcodec_alloc_frame()
225 # define XFF_FREE_FRAME(pp) avcodec_free_frame(&(pp))
226 #else
227 # define XFF_ALLOC_FRAME() av_frame_alloc()
228 # define XFF_FREE_FRAME(pp) av_frame_free(&(pp))
229 #endif
230 
231 #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(57,12,100)
232 #define XFF_PACKET_UNREF av_free_packet
233 #else
234 #define XFF_PACKET_UNREF av_packet_unref
235 #endif
236 
237 #ifndef AV_INPUT_BUFFER_PADDING_SIZE
238 # define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
239 #endif
240 #ifndef AV_CODEC_CAP_DR1
241 # define AV_CODEC_CAP_DR1 CODEC_CAP_DR1
242 #endif
243 #ifndef AV_CODEC_FLAG2_FAST
244 # define AV_CODEC_FLAG2_FAST CODEC_FLAG2_FAST
245 #endif
246 
247 
248 #endif /* XINE_AVCODEC_COMPAT_H */