Blender V2.61 - r43446

ffmpeg_compat.h

Go to the documentation of this file.
00001 #ifndef __ffmpeg_compat_h_included__
00002 #define __ffmpeg_compat_h_included__ 1
00003 
00004 /*
00005  *
00006  * compatibility macros to make every ffmpeg installation appear
00007  * like the most current installation (wrapping some functionality sometimes)
00008  * it also includes all ffmpeg header files at once, no need to do it 
00009  * seperately.
00010  *
00011  * Copyright (c) 2011 Peter Schlaile
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  */
00024 
00025 
00026 #include <libavformat/avformat.h>
00027 
00028 
00029 /* check our ffmpeg is new enough, avoids user complaints */
00030 #if (LIBAVFORMAT_VERSION_MAJOR < 52) || ((LIBAVFORMAT_VERSION_MAJOR == 52) && (LIBAVFORMAT_VERSION_MINOR <= 64))
00031 #  error "FFmpeg 0.7 or newer is needed, Upgrade your FFmpeg or disable it"
00032 #endif
00033 /* end sanity check */
00034 
00035 
00036 #include <libavcodec/avcodec.h>
00037 #include <libavutil/rational.h>
00038 
00039 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101))
00040 #define FFMPEG_HAVE_PARSE_UTILS 1
00041 #include <libavutil/parseutils.h>
00042 #endif
00043 
00044 #include <libswscale/swscale.h>
00045 #include <libavcodec/opt.h>
00046 
00047 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 105))
00048 #define FFMPEG_HAVE_AVIO 1
00049 #endif
00050 
00051 #if (LIBAVCODEC_VERSION_MAJOR > 53) || ((LIBAVCODEC_VERSION_MAJOR == 53) && (LIBAVCODEC_VERSION_MINOR > 1)) || ((LIBAVCODEC_VERSION_MAJOR == 53) && (LIBAVCODEC_VERSION_MINOR == 1) && (LIBAVCODEC_VERSION_MICRO >= 1)) || ((LIBAVCODEC_VERSION_MAJOR == 52) && (LIBAVCODEC_VERSION_MINOR >= 121))
00052 #define FFMPEG_HAVE_DEFAULT_VAL_UNION 1
00053 #endif
00054 
00055 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101))
00056 #define FFMPEG_HAVE_AV_DUMP_FORMAT 1
00057 #endif
00058 
00059 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 45))
00060 #define FFMPEG_HAVE_AV_GUESS_FORMAT 1
00061 #endif
00062 
00063 #if (LIBAVCODEC_VERSION_MAJOR > 52) || ((LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 23))
00064 #define FFMPEG_HAVE_DECODE_AUDIO3 1
00065 #define FFMPEG_HAVE_DECODE_VIDEO2 1
00066 #endif
00067 
00068 #if (LIBAVCODEC_VERSION_MAJOR > 52) || ((LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 64))
00069 #define FFMPEG_HAVE_AVMEDIA_TYPES 1
00070 #endif
00071 
00072 #if ((LIBAVCODEC_VERSION_MAJOR > 52) || (LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 29)) && \
00073     ((LIBSWSCALE_VERSION_MAJOR > 0) || (LIBSWSCALE_VERSION_MAJOR >= 0) && (LIBSWSCALE_VERSION_MINOR >= 10))
00074 #define FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
00075 #endif
00076 
00077 #ifndef FFMPEG_HAVE_AVIO
00078 #define AVIO_FLAG_WRITE URL_WRONLY
00079 #define avio_open url_fopen
00080 #define avio_tell url_ftell
00081 #define avio_close url_fclose
00082 #define avio_size url_fsize
00083 #endif
00084 
00085 /* there are some version inbetween, which have avio_... functions but no
00086    AVIO_FLAG_... */
00087 #ifndef AVIO_FLAG_WRITE
00088 #define AVIO_FLAG_WRITE URL_WRONLY
00089 #endif
00090 
00091 #ifndef AV_PKT_FLAG_KEY
00092 #define AV_PKT_FLAG_KEY PKT_FLAG_KEY
00093 #endif
00094 
00095 #ifndef FFMPEG_HAVE_AV_DUMP_FORMAT
00096 #define av_dump_format dump_format
00097 #endif
00098 
00099 #ifndef FFMPEG_HAVE_AV_GUESS_FORMAT
00100 #define av_guess_format guess_format
00101 #endif
00102 
00103 #ifndef FFMPEG_HAVE_PARSE_UTILS
00104 #define av_parse_video_rate av_parse_video_frame_rate
00105 #endif
00106 
00107 #ifdef FFMPEG_HAVE_DEFAULT_VAL_UNION
00108 #define FFMPEG_DEF_OPT_VAL_INT(OPT) OPT->default_val.i64
00109 #define FFMPEG_DEF_OPT_VAL_DOUBLE(OPT) OPT->default_val.dbl
00110 #else
00111 #define FFMPEG_DEF_OPT_VAL_INT(OPT) OPT->default_val
00112 #define FFMPEG_DEF_OPT_VAL_DOUBLE(OPT) OPT->default_val
00113 #endif
00114 
00115 #ifndef FFMPEG_HAVE_AVMEDIA_TYPES
00116 #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
00117 #define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
00118 #endif
00119 
00120 #ifndef FFMPEG_HAVE_DECODE_AUDIO3
00121 static inline 
00122 int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
00123               int *frame_size_ptr, AVPacket *avpkt)
00124 {
00125     return avcodec_decode_audio2(avctx, samples,
00126                      frame_size_ptr, avpkt->data,
00127                      avpkt->size);
00128 }
00129 #endif
00130 
00131 #ifndef FFMPEG_HAVE_DECODE_VIDEO2
00132 static inline
00133 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
00134                          int *got_picture_ptr,
00135                          AVPacket *avpkt)
00136 {
00137     return avcodec_decode_video(avctx, picture, got_picture_ptr,
00138                     avpkt->data, avpkt->size);
00139 }
00140 #endif
00141 
00142 static inline
00143 int64_t av_get_pts_from_frame(AVFormatContext *avctx, AVFrame * picture)
00144 {
00145     int64_t pts = picture->pkt_pts;
00146 
00147     if (pts == AV_NOPTS_VALUE) {
00148         pts = picture->pkt_dts;
00149     }
00150     if (pts == AV_NOPTS_VALUE) {
00151         pts = 0;
00152     }
00153 
00154     (void)avctx;
00155     return pts;
00156 }
00157 
00158 #endif