add comments, tweak dimensions for debugging.
[gnash.git] / macros / ffmpeg.m4
blob4dd8e8745a7ae449a6e95e4f873e0c38f8b2c24a
1 dnl  
2 dnl  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 dnl  2011 Free Software Foundation, Inc.
4 dnl  
5 dnl  This program is free software; you can redistribute it and/or modify
6 dnl  it under the terms of the GNU General Public License as published by
7 dnl  the Free Software Foundation; either version 3 of the License, or
8 dnl  (at your option) any later version.
9 dnl  
10 dnl  This program is distributed in the hope that it will be useful,
11 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 dnl  GNU General Public License for more details.
14 dnl  You should have received a copy of the GNU General Public License
15 dnl  along with this program; if not, write to the Free Software
16 dnl  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 AC_DEFUN([GNASH_PATH_FFMPEG],
21   dnl Backup LIBS and CFLAGS vars, we'll add user-specified dirs there
22   backupLIBS="$LIBS"
23   backupCFLAGS="$CFLAGS"
24   avcodec_h=""
25   avcodec_version_h=""
26   ffmpeg_top_incl=""
28   dnl If the user specify an path to include headers from, we assume it's the full
29   dnl path to the header file, and not the top level path without the 'ffmpeg' node
30   dnl of the path. This is made more fun my the way ffmpeg changes directory layout
31   dnl reasonably often.
32   dnl
33   dnl ffmpeg_top_level - the top level directory without the ffmpeg specific part.
34   dnl           ie... /usr/local/include/ffmpeg becomes /usr/local/include, and
35   dnl           /usr/local/include/ffmpeg/libavcodec becomes /usr/local/include/ffmpeg.
36   dnl avcode_h - stores the path and file name for avcodec.h, which is used later on
37   dnl           in this macro to extract the version number of ffmpeg we're using.
38   AC_ARG_WITH(ffmpeg_incl, AC_HELP_STRING([--with-ffmpeg-incl], [directory where avcodec.h is]), with_ffmpeg_incl=${withval})
39   AC_CACHE_VAL(ac_cv_path_ffmpeg_incl,[
40     if test x"${with_ffmpeg_incl}" != x ; then
41       dnl top level path for include files minus the last directory from the user
42       dnl specified path.
43       ffmpeg_top_incl=`dirname ${with_ffmpeg_incl}`
44       if test -f ${with_ffmpeg_incl}/avcodec.h; then
45         ac_cv_path_ffmpeg_incl="-I`(cd ${ffmpeg_top_incl}; pwd)`"
46         avcodec_h=${with_ffmpeg_incl}/avcodec.h
47       else
48         AC_MSG_ERROR([${with_ffmpeg_incl} directory does not contain the avcodec.h header])
49       fi
50       if test -f ${with_ffmpeg_incl}/version.h; then
51         avcodec_version_h=${with_ffmpeg_incl}/version.h
52       fi
53     fi
54   ])
56   dnl Try to find avcodec.h ourselves
57   if test x${ffmpeg_top_incl} = x; then
58     AC_MSG_CHECKING([location of avcodec.h])
59     dnl Try PKG_CONFIG if available
60     if test x"$PKG_CONFIG" != x; then dnl {
61       if $PKG_CONFIG --exists libavcodec; then dnl {
62         dnl Some systems return /usr/include/ffmpeg, others /usr/include.
63         dnl We use #include <ffmpeg/avcodec.h> everywhere so weed out funny
64         dnl values into the short form.
65         ffmpeg_pkg=`$PKG_CONFIG --cflags-only-I libavcodec`
66         ffmpeg_top_incl=`echo ${ffmpeg_pkg} | sed  -e 's:-I::'`
67         dnl Make sure a header file really exists in the given path.
68         dnl Ubuntu like the headers here in the top level ffmpeg directory.
69         for i in "" ffmpeg libavcodec ffmpeg/libavcodec; do
70           if test -f ${ffmpeg_top_incl}/${i}/avcodec.h; then
71             ac_cv_path_ffmpeg_incl="-I`(cd ${ffmpeg_top_incl}; pwd)`"
72             avcodec_h="${ffmpeg_top_incl}/${i}/avcodec.h"
73             if test -f ${ffmpeg_top_incl}/${i}/version.h; then
74               avcodec_version_h=${ffmpeg_top_incl}/${i}/version.h
75             fi
76             break
77           fi
78         done
79       fi
80     fi
81   fi
83   dnl if pkg-config doesn't have the values we want, or they're plain wrong, look
84   dnl in several common places ourselves. Note that the variable ffmpeg_top_incl
85   dnl contains the value of the top level path that has been found.
86   if test x"${ac_cv_path_ffmpeg_incl}" = x ; then
87     newlist="/usr/include/ffmpeg $incllist"
88     for ffmpeg_top_incl in $newlist; do
89       for i in ffmpeg libavcodec ffmpeg/libavcodec; do
90         if test -f ${ffmpeg_top_incl}/${i}/avcodec.h; then
91           ac_cv_path_ffmpeg_incl="-I`(cd ${ffmpeg_top_incl}/${i}; pwd)`"
92           avcodec_h=${ffmpeg_top_incl}/${i}/avcodec.h
93           if test -f ${ffmpeg_top_incl}/${i}/version.h; then
94             avcodec_version_h=${ffmpeg_top_incl}/${i}/version.h
95           fi
96           break
97         fi
98       done
99       if test x"${ac_cv_path_ffmpeg_incl}" != x ; then
100         break
101       fi
102     done
103   fi
105   dnl Because the avcodec.h header file might be found by any one of
106   dnl the above ways, we set the version macros after all those tests
107   dnl are done so we only have to do it once.
108   newer_ffmpeg=`echo ${avcodec_h} | grep -c libavcodec`
109   if test ${newer_ffmpeg} -eq 0; then
110     AC_DEFINE(HAVE_FFMPEG_AVCODEC_H, 1, [Define if you have avcodec.h installed.])
111   else
112     AC_DEFINE(HAVE_LIBAVCODEC_AVCODEC_H, 1, [Define if you have avcodec.h installed.])
113   fi
115   if test x"${ac_cv_path_ffmpeg_incl}" = x ; then
116     have_ffmpeg=no
117     AC_MSG_RESULT(none found)
118   else
119     have_ffmpeg=yes
120     AC_MSG_RESULT(${ac_cv_path_ffmpeg_incl})
121   fi
123   dnl Find and check libavcodec version number to make sure we have a usable
124   dnl version and to enable/disable features according to version.
125   dnl We need LIBAVCODEC VERSION of at least 51.29.0 to get avcodec_decode_audio2
126   dnl
127   dnl We try to get the avcodec version as a decimal number
128   dnl so that we can compare it numerically against what we require.
129   dnl
130   dnl This previous version makes ffmpeg fail and then grubs the version string
131   dnl out of the resulting usage message e.g. "  libavcodec version: 51.40.2"
132   dnl Early versions of ffmpeg do not output this string at all.
133   dnl
134   dnl   AC_PATH_PROG(FFMPEG, ffmpeg, ,[${pathlist}])
135   dnl   if test "x$FFMPEG" = "x" ; then
136   dnl     ffmpeg_version=`$FFMPEG uglyhack 2>&1 | grep "libavcodec version" | cut -d ' ' -f 5 | tr -d '.'`
137   dnl     if test "$ffmpeg_version" -lt 51290; then
138   dnl       AC_MSG_ERROR([])
139   dnl     fi
140   dnl   fi
141   dnl
142   dnl These days we check avcodec.h and pick the version out of the constants,
143   dnl simply throwing away all non-digits.
144   dnl
145   dnl In earlier versions we have:
146   dnl #define FFMPEG_VERSION_INT     0x000409
147   dnl #define FFMPEG_VERSION         "0.4.9-pre1"
148   dnl #define LIBAVCODEC_BUILD       4731
149   dnl #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
150   dnl #define LIBAVCODEC_VERSION     FFMPEG_VERSION
151   dnl
152   dnl elsewhere, FFMPEG_VERSION may also be the quoted string "CVS"
153   dnl
154   dnl This changed from the above to
155   dnl #define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+0)
156   dnl #define LIBAVCODEC_VERSION     49.0.0
157   dnl #define LIBAVCODEC_BUILD       LIBAVCODEC_VERSION_INT
158   dnl (note, LIBAVCODEC_VERSION also changes from a quoted string to unquoted)
159   dnl see http://lists.mplayerhq.hu/pipermail/ffmpeg-cvslog/2005-July/000570.html
160   dnl
161   dnl
162   dnl This changed from the above to
163   dnl #define LIBAVCODEC_VERSION_MAJOR 51
164   dnl #define LIBAVCODEC_VERSION_MINOR 54
165   dnl #define LIBAVCODEC_VERSION_MICRO  0
166   dnl 
167   dnl #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
168   dnl                                                LIBAVCODEC_VERSION_MINOR, \
169   dnl                                                LIBAVCODEC_VERSION_MICRO)
170   dnl #define LIBAVCODEC_VERSION      AV_VERSION(LIBAVCODEC_VERSION_MAJOR,    \
171   dnl                                            LIBAVCODEC_VERSION_MINOR,    \
172   dnl                                            LIBAVCODEC_VERSION_MICRO)
173   
174   dnl Those deb-heads at Debian redefine LIBAVCODEC_VERSION in their versions to
175   dnl (e.g.) 1d.51.38.0 or dnl 0d.51.11.0 - we need to discard the prefixed
176   dnl rubbish.
177   dnl
178   dnl Other values or LIBAVCODEC_VERSION spotted in the wild:
179   dnl 50.0.0  50.5.0  51.7.0  51.8.0  0d.51.8.0  51.40.4
180   dnl presumably this will change to 52.0.0 at some point...
181   dnl
182   dnl We can ignore the very early versions because 51.10.0 is necessary to decode
183   dnl Flash video at all. However the current solution will incorrectly succeed
184   dnl on early debian/ubuntu 1d.* version numbers and incorrectly fail
185   dnl when 52.0.0 happens.
186   dnl
187   dnl The most reliable way is to compile a test program to print the value of
188   dnl LIBAVCODEC_BUILD, which got up to dnl 4718 at version 0.4.9-pre1,
189   dnl then changed to (major<<16 + minor<<8 + micro) from then on.
190   dnl There is code to do this in transcode's configure.in, but when
191   dnl cross-compiling we cannot run a test program, which suggests that
192   dnl a modified form of grepping may be better, making sure all old kinds of
193   dnl version numbering fail gracefully.
195   versionfile=""
197   dnl Check avcodec version number, if it was found
198   if test x"${avcodec_version_h}" != x; then
199     versionfile=${avcodec_version_h}
200   else
201     if test x"${avcodec_h}" != x; then
202       versionfile=${avcodec_h}
203     fi
204   fi
206   if test x"${versionfile}" != x; then
208     AC_MSG_CHECKING([ffmpeg version])
210     ffmpeg_major_version=`$EGREP "define LIBAVCODEC_VERSION_MAJOR " ${versionfile} | sed -e "s%[[^0-9]]%%g"`
211     ffmpeg_minor_version=`$EGREP "define LIBAVCODEC_VERSION_MINOR " ${versionfile} | sed -e "s%[[^0-9]]%%g"`
212     ffmpeg_micro_version=`$EGREP "define LIBAVCODEC_VERSION_MICRO " ${versionfile} | sed -e "s%[[^0-9]]%%g"`
214     if test x"${ffmpeg_major_version}" != x ; then
216       ffmpeg_version="${ffmpeg_major_version}.${ffmpeg_minor_version}.${ffmpeg_micro_version}"
218     else
220       dnl #define LIBAVCODEC_VERSION_TRIPLET 51,50,1
221       ffmpeg_version=`$EGREP "define LIBAVCODEC_VERSION_TRIPLET " ${versionfile} | awk '{print $'3'}' | sed -e "s%,%.%g"`
223       if test x"${ffmpeg_version}" = x ; then
225         dnl NOTE: the [0-9]*d. pattern discards deb-heads rubbish prefix
226         ffmpeg_version=`$EGREP "define LIBAVCODEC_VERSION " ${versionfile} | awk '{print $'3'}' | sed -e "s%^[[0-9]]d\.%%"` 
228         if test x"${ffmpeg_version}" = x ; then
229           ffmpeg_version=`$EGREP "define LIBAVCODEC_BUILD " ${versionfile} | awk '{print $'3'}'`
230         fi
231       fi
233       if test x"${ffmpeg_version}" != x ; then
234         ffmpeg_major_version=`echo ${ffmpeg_version} | cut -d. -f1`
235         ffmpeg_minor_version=`echo ${ffmpeg_version} | cut -d. -f2`
236         ffmpeg_micro_version=`echo ${ffmpeg_version} | cut -d. -f3`
237       fi
239     fi
241     ffmpeg_num_version=`printf %02d%02d%02d $ffmpeg_major_version $ffmpeg_minor_version $ffmpeg_micro_version`
243     AC_MSG_RESULT($ffmpeg_version ($ffmpeg_num_version))
246 dnl   AC_EGREP_HEADER(avcodec_decode_audio2, ${avcodec_h}, [avfound=yes], [avfound=no])
247   
248     if test -z "$ffmpeg_num_version" -o "$ffmpeg_num_version" -lt 512800; then
249       AC_MSG_WARN([Wrong ffmpeg/libavcodec version! 51.28.0 or greater required, $ffmpeg_version detected.])
250     else
251       ffmpeg_version_check=ok
252     fi
254     if test -z "$ffmpeg_num_version" -o "$ffmpeg_num_version" -lt 514900; then
255       dnl 51.49.0 or higher required
256       AC_MSG_WARN([This version of ffmpeg/libavcodec ($ffmpeg_version) is not able to play VP6A encoded video: 51.49.0 or higher required!])
257     else
258       AC_DEFINE(FFMPEG_VP6A, 1, [Define if ffmpeg can play VP6A.])
259     fi
261     if test -z "$ffmpeg_num_version" -o "$ffmpeg_num_version" -lt 514600; then
262       dnl 51.46.0 (r10741) or higher required for CODEC_ID_NELLYMOSER
263       AC_MSG_WARN([This version of ffmpeg/libavcodec ($ffmpeg_version) is not able to decode NELLYMOSER encoded audio: 51.46.0 (r10741) or higher required!])
264     else
265       AC_DEFINE(FFMPEG_NELLYMOSER, 1, [Define if ffmpeg can decode NELLYMOSER audio])
266     fi
267   else
268     AC_MSG_WARN([Could not check ffmpeg version (can't find avcodec.h file)])
269     # ffmpeg_version_check=ok # this is NOT ok, why would it be ?! 
270   fi
272   LIBAVCODEC_IDENT=${ffmpeg_version}
273   FFMPEG_CFLAGS="-D__STDC_CONSTANT_MACROS ${ac_cv_path_ffmpeg_incl}"
275   AC_MSG_CHECKING([for avformat.h])
276   if test -f "${ffmpeg_top_incl}/avformat.h"; then
277     AC_DEFINE(HAVE_FFMPEG_AVFORMAT_H, 1, [Define if avformat.h is found])
278     avformat_h="${ffmpeg_top_incl}/avformat.h"
279   else
280     if test -f "${ffmpeg_top_incl}/libavformat/avformat.h"; then
281       AC_DEFINE(HAVE_LIBAVFORMAT_AVFORMAT_H, 1, [Define if avformat.h is found])
282       avformat_h="${ffmpeg_top_incl}/libavformat/avformat.h"
283     else
284       avformat_h=""
285     fi
286   fi
287   AC_MSG_RESULT($avformat_h)
289   AC_MSG_CHECKING([for swscale.h])
290   have_ffmpeg_swscale=no
291   if test -f "${ffmpeg_top_incl}/ffmpeg/swscale.h"; then
292     have_ffmpeg_swscale=yes
293     AC_DEFINE(HAVE_FFMPEG_SWSCALE_H, 1, [Define if swscale.h is found])
294   fi
295   if test -f "${ffmpeg_top_incl}/libswscale/swscale.h"; then
296     have_ffmpeg_swscale=yes
297     AC_DEFINE(HAVE_LIBSWSCALE_SWSCALE_H, 1, [Define if swscale.h is found])
298   fi
299   if test -f "${ffmpeg_top_incl}/swscale.h"; then
300     have_ffmpeg_swscale=yes
301     AC_DEFINE(HAVE_SWSCALE_H, 1, [Define if swscale.h is found])
302   fi
303   AC_MSG_RESULT($have_ffmpeg_swscale)
305   if test x"$have_ffmpeg_swscale" = "xno" -a 1$ffmpeg_num_version -ge 1"520000"; then
306      AC_MSG_WARN([Cannot find swscale.h, required for ffmpeg versions >= 52.0.0 (detected version: $ffmpeg_version)])
307      ffmpeg_version_check=
308   fi
310   AC_MSG_CHECKING([for libavcodec/vaapi.h])
311   have_ffmpeg_vaapi="no"
312   if test -f "${ffmpeg_top_incl}/ffmpeg/vaapi.h"; then
313     have_ffmpeg_vaapi="yes"
314     AC_DEFINE(HAVE_FFMPEG_VAAPI_H, 1, [Defined if ffmpeg/vaapi.h is found])
315   fi
316   if test -f "${ffmpeg_top_incl}/libavcodec/vaapi.h"; then
317     have_ffmpeg_vaapi="yes"
318     AC_DEFINE(HAVE_LIBAVCODEC_VAAPI_H, 1, [Defined if libavcodec/vaapi.h is found])
319   fi
320   AC_MSG_RESULT($have_ffmpeg_vaapi)
322   dnl ---------------------------------
323   dnl
324   dnl FFMPEG libs checking
325   dnl
326   dnl ---------------------------------
328   top_lib_dir=""
330   dnl Did they tell us where the libs are ?
331   AC_ARG_WITH(ffmpeg_lib, AC_HELP_STRING([--with-ffmpeg-lib], [directory where ffmpeg libraries are]), with_ffmpeg_lib=${withval})
332   AC_CACHE_VAL(ac_cv_path_ffmpeg_lib, [
333     if test x"${with_ffmpeg_lib}" != x ; then
334       if test -f ${with_ffmpeg_lib}/libavcodec.a -o -f ${with_ffmpeg_lib}/libavcodec.${shlibext}; then
335               ac_cv_path_ffmpeg_lib="-L`(cd ${with_ffmpeg_lib}; pwd)`"
336           libavcodec="-lavcodec"
337           LIBS="${ac_cv_path_ffmpeg_lib} $LIBS" dnl <-- What is this needed for ?
338           top_lib_dir=${with_ffmpeg_lib}
339       else
340               AC_MSG_ERROR([${with_ffmpeg_lib} directory doesn't contain libavcodec libraries.])
341       fi
342       if test -f ${with_ffmpeg_lib}/libavformat.a -o -f ${with_ffmpeg_lib}/libavformat.${shlibext}; then
343               ac_cv_path_ffmpeg_lib="-L`(cd ${with_ffmpeg_lib}; pwd)`"
344           libavformat="-lavformat"
345           top_lib_dir=${with_ffmpeg_lib}
346       else
347               AC_MSG_ERROR([${with_ffmpeg_lib} directory doesn't contain libavformat libraries.])
348       fi
349     fi
350   ])
352   dnl Look for the AVCODEC library
354   dnl Try with pkg-config (if not cross-compiling)
355   if test x"${cross_compiling}" = xno; then
356     if test x"$PKG_CONFIG" != x -a x"${libavcodec}" = x; then
357       $PKG_CONFIG --exists libavcodec && libavcodec=`$PKG_CONFIG --libs libavcodec`
358       dnl
359       dnl WARNING: we won't be able to set top_lib_dir here, as pkg-config doesn't
360       dnl          return any -L when not neeed.
361       dnl          We won't need top_lib_dir either, as the only use for it
362       dnl          is to look for other required libraries, while pkg-config 
363       dnl          probably include them all, so not a big deal.
364       dnl
365     fi
366   fi
368   if test x"${libavcodec}" != x; then
369     ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libavcodec}"
370   else
371     AC_MSG_CHECKING([for libavcodec library])
372     for i in $libslist; do
373       if test -f $i/libavcodec.a -o -f $i/libavcodec.${shlibext}; then
374         if test x${top_lib_dir} = x; then top_lib_dir=$i; fi
375         AC_MSG_RESULT(${top_lib_dir}/libavcodec)
376             if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
377           ac_cv_path_ffmpeg_lib="-L$i -lavcodec"
378           break
379         else
380           ac_cv_path_ffmpeg_lib="-lavcodec"
381               break
382         fi
383       fi
384     done
386     if test x"${libavcodec}" = x; then
387       AC_MSG_RESULT(no)
388       if test x${cross_compiling} = xno; then
389         dnl avcodec_decode_audio2 starts 51.29.0
390         AC_CHECK_LIB(avcodec, ff_eval, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lavcodec"])
391       fi
392     fi
393   fi
395   if test x$top_lib_dir != x; then
396     AC_MSG_NOTICE([ffmpeg top lib dir is $top_lib_dir])
397   fi
399   dnl Start of all optional library tests {
400   dnl
401   dnl TODO: skip these tests if we got ac_cv_path_ffmpeg_lib
402   dnl       from pkg-config, as it would likely bring all
403   dnl       required libs in. 
404   dnl
405   if test x"${ac_cv_path_ffmpeg_lib}" != x; then
407     dnl Look for the DTS library, which is required on some systems. {
408     dnl
409     dnl TODO: skip this if -ldts is already in due to pkg-config 
410     dnl
411     AC_MSG_CHECKING([for libdts library])
412     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
413       $PKG_CONFIG --exists libdts && libdts=`$PKG_CONFIG --libs-only-l libdts`
414     else
415       libdts=""
416     fi
417     if test x"${libdts}" = x; then
418       if test -f ${top_lib_dir}/libdts.a -o -f ${top_lib_dir}/libdts.${shlibext}; then
419         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ldts"
420         AC_MSG_RESULT(${top_lib_dir}/libdts)
421       else
422         AC_MSG_RESULT(no)
423         if test x${cross_compiling} = xno; then
424           AC_CHECK_LIB(dts, dts_init, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ldts"])
425         fi
426       fi
427     else
428       AC_MSG_RESULT(${libdts})
429       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libdts}"      
430     fi
431     dnl End of DTS library looking }
432         
433     dnl Look for the VORBISENC library, which is required on some systems. {
434     AC_MSG_CHECKING([for libvorbisenc library])
435     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
436       $PKG_CONFIG --exists vorbisenc && libvorbisenc=`$PKG_CONFIG --libs-only-l vorbisenc`
437     else
438       libvorbisenc=""
439     fi
440     if test x"${libvorbisenc}" = x; then
441       if test -f ${top_lib_dir}/libvorbisenc.a -o -f ${top_lib_dir}/libvorbisenc.${shlibext}; then
442         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lvorbisenc"
443         AC_MSG_RESULT(${top_lib_dir}/libvorbisenc)
444       else
445         AC_MSG_RESULT(no)
446         if test x${cross_compiling} = xno; then
447           AC_CHECK_LIB(vorbisenc, vorbis_encode_init, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lvorbisenc"])
448         fi
449       fi
450     else
451       AC_MSG_RESULT(${libvorbisenc})
452       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libvorbisenc}"
453     fi
454     dnl End of VORBINSEC library looking }
455         
457     dnl Look for the AVFORMAT library {
458     dnl
459     dnl TODO: libavformat be mandatory, thus linked in already ?
460     dnl
462     AC_MSG_CHECKING([for libavformat library])
464     dnl Try with pkg-config (if not cross-compiling)
465     if test x"${cross_compiling}" = xno; then
466       if test x"$PKG_CONFIG" != x -a x${libavformat} = x; then
467         $PKG_CONFIG --exists libavformat && libavformat=`$PKG_CONFIG --libs-only-l libavformat`
468       fi
469     fi
471     if test x"${libavformat}" = x; then
472       if test -f ${top_lib_dir}/libavformat.a -o -f ${top_lib_dir}/libavformat.${shlibext}; then
473         ac_cv_path_ffmpeg_lib="-lavformat ${ac_cv_path_ffmpeg_lib}" 
474         AC_MSG_RESULT(${top_lib_dir}/libavformat)
475       else
476         AC_MSG_RESULT(no)
477         if test x${cross_compiling} = xno; then
478           AC_CHECK_LIB(libavformat, av_open_input_file, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lavformat"])
479         fi
480       fi
481     else
482       AC_MSG_RESULT(${libavformat})
483       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libavformat}"      
484     fi
486     dnl End of AVFORMAT library looking }
488     dnl Look for the AVUTIL library, which is required on some systems. {
489     dnl
490     dnl TODO: skip this if -lavutil is already in due to pkg-config 
491     dnl
492     AC_MSG_CHECKING([for libavutil library])
493     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
494       $PKG_CONFIG --exists libavutil && libavutil=`$PKG_CONFIG --libs-only-l libavutil`
495     else
496       libavutil=""
497     fi
498     if test x"${libavutil}" = x; then
499       if test -f ${top_lib_dir}/libavutil.a -o -f ${top_lib_dir}/libavutil.${shlibext}; then
500         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lavutil"
501         AC_MSG_RESULT(${top_lib_dir}/libavutil)
502       else
503         AC_MSG_RESULT(no)
504         if test x${cross_compiling} = xno; then
505            AC_CHECK_LIB(avutil, av_log, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lavutil"])
506         fi
507       fi
508     else
509       AC_MSG_RESULT(${libavutil})
510       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libavutil}"
511     fi
512     dnl End of AVUTIL library looking }
513         
514     dnl Look for the THEORA library, which is required on some systems. {
515     dnl
516     dnl TODO: skip this if -ltheora is already in due to pkg-config 
517     dnl
518     AC_MSG_CHECKING([for libtheora library])
519     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
520       $PKG_CONFIG --exists theora && libtheora=`$PKG_CONFIG --libs-only-l theora`
521     else
522       libtheora=""
523     fi
524     if test x"${libtheora}" = x; then
525       if test -f ${top_lib_dir}/libtheora.a -o -f ${top_lib_dir}/libtheora.${shlibext}; then
526         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ltheora"
527         AC_MSG_RESULT(${top_lib_dir}/libtheora)
528       else
529         AC_MSG_RESULT(no)
530         if test x${cross_compiling} = xno; then
531           AC_CHECK_LIB(theora, theora_encode_init, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ltheora"])
532         fi
533       fi
534     else
535       AC_MSG_RESULT(${libtheora})
536       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libtheora}"      
537     fi
538     dnl End of THEORA library looking }
540     dnl Look for the GSM library, which is required on some systems. {
541     AC_MSG_CHECKING([for libgsm library])
542     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
543       $PKG_CONFIG --exists gsm && libgsm=`$PKG_CONFIG --libs-only-l gsm`
544     else
545       libgsm=""
546     fi
548     if test x"${libgsm}" = x; then
549       if test -f ${top_lib_dir}/libgsm.a -o -f ${top_lib_dir}/libgsm.${shlibext}; then
550         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lgsm"
551         AC_MSG_RESULT(${top_lib_dir}/libgsm)
552       else
553         AC_MSG_RESULT(no)
554         if test x${cross_compiling} = xno; then
555           AC_CHECK_LIB(gsm, gsm_destroy, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lgsm"])
556         fi
557       fi
558     fi
560     AC_MSG_RESULT(${libgsm})
561     ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libgsm}"
562     dnl End of GSM library looking }
563     
564     dnl Look for the DC1394 library, which is required on some systems. {
565     dnl
566     dnl TODO: skip this if -ldc1394 is already in due to pkg-config 
567     dnl
568     AC_MSG_CHECKING([for libdc1394 library])
569     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
570       $PKG_CONFIG --exists libdc  && libdc=`$PKG_CONFIG --libs-only-l libdc1394`
571     else
572       libtdc=""
573     fi
574     if test x"${libdc}" = x; then
575       if test -f ${top_lib_dir}/libdc1394.a -o -f ${top_lib_dir}/libdc1394.${shlibext}; then
576         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ldc1394"
577         AC_MSG_RESULT(${top_lib_dir}/libdc1394)
578       else
579         AC_MSG_RESULT(no)
580         if test x${cross_compiling} = xno; then
581           AC_CHECK_LIB(dc1394_control, dc1394_is_camera, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -ldc1394_control"])
582         fi
583       fi
584     else
585       AC_MSG_RESULT(${libdc})
586       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libdc}"
587     fi
588     dnl End of DC1394 library looking }
590     dnl Look for the SWSCALE library {
591     dnl
592     dnl This is required on some system if ffmpeg is
593     dnl configured with --enable-gpl --enable-swscale.
594     AC_MSG_CHECKING([for libswscale library])
595     if test x"$PKG_CONFIG" != x -a x${cross_compiling} = xno; then
596       $PKG_CONFIG --exists libswscale  && libsws=`$PKG_CONFIG --libs-only-l libswscale`
597     else
598       libsws=""
599     fi
600     if test x"${libsws}" = x; then
601       if test -f ${top_lib_dir}/libswscale.a -o -f ${top_lib_dir}/libswscale.${shlibext}; then
602         ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lswscale"
603         AC_MSG_RESULT(yes)
604       else
605         AC_MSG_RESULT(no)
606         if test x${cross_compiling} = xno; then
607           AC_CHECK_LIB(swscale, sws_scale, [ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} -lswscale"])
608         fi
609       fi
610     else
611       AC_MSG_RESULT(${libsws})
612       ac_cv_path_ffmpeg_lib="${ac_cv_path_ffmpeg_lib} ${libsws}"
613     fi
614     dnl End of SWSCALE library looking }
616   fi
617   dnl End of all optional library tests }
619   # Set final compilation flags, eliminating the pointless "-I/usr/include"
620   if test x"${ac_cv_path_ffmpeg_lib}" != x ; then
621     FFMPEG_LIBS="${ac_cv_path_ffmpeg_lib}"
622   else
623     FFMPEG_LIBS=""
624   fi
626   AC_SUBST(LIBAVCODEC_IDENT)
627   AC_SUBST(FFMPEG_CFLAGS)  
628   AC_SUBST(FFMPEG_LIBS)
630   LIBS="$backupLIBS"
631   CFLAGS="$backupCFLAGS"
634 # Local Variables:
635 # c-basic-offset: 2
636 # tab-width: 2
637 # indent-tabs-mode: nil
638 # End: