1 /* 2 * ffmpeglib.h - Interface to access the ffmpeg libs. 3 * 4 * Written by 5 * Andreas Matthies <andreas.matthies@gmx.net> 6 * 7 * This file is part of VICE, the Versatile Commodore Emulator. 8 * See README for copyright notice. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 23 * 02111-1307 USA. 24 * 25 */ 26 27 #ifndef VICE_FFMPEGLIB_H 28 #define VICE_FFMPEGLIB_H 29 30 #include "vice.h" 31 32 #include "archdep.h" 33 34 #ifdef HAVE_FFMPEG_HEADER_SUBDIRS 35 # include "libavutil/rational.h" 36 # include "libavformat/avformat.h" 37 # include "libswscale/swscale.h" 38 #ifndef HAVE_FFMPEG_AVRESAMPLE 39 # include "libswresample/swresample.h" 40 #else 41 # include "libavresample/avresample.h" 42 #endif 43 #else 44 # include "rational.h" 45 # include "avformat.h" 46 # include "swscale.h" 47 #ifndef HAVE_FFMPEG_AVRESAMPLE 48 # include "swresample.h" 49 #else 50 # include "avresample.h" 51 #endif 52 #endif 53 54 /* "libavutil/opt.h" */ 55 int av_opt_set_int(void*, const char*, int64_t, int); 56 int av_opt_set_sample_fmt(void*, const char*, enum AVSampleFormat, int); 57 58 /* generic version function */ 59 typedef unsigned (*ffmpeg_version_t)(void); 60 61 /* Use new names */ 62 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,18,102) 63 #define AV_CODEC_ID_MP2 CODEC_ID_MP2 64 #define AV_CODEC_ID_MP3 CODEC_ID_MP3 65 #define AV_CODEC_ID_FLAC CODEC_ID_FLAC 66 #define AV_CODEC_ID_PCM_S16LE CODEC_ID_PCM_S16LE 67 #define AV_CODEC_ID_PCM_S16BE CODEC_ID_PCM_S16BE 68 #define AV_CODEC_ID_PCM_U16LE CODEC_ID_PCM_U16LE 69 #define AV_CODEC_ID_PCM_U16BE CODEC_ID_PCM_U16BE 70 #define AV_CODEC_ID_MPEG4 CODEC_ID_MPEG4 71 #define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO 72 #define AV_CODEC_ID_FFV1 CODEC_ID_FFV1 73 #define AV_CODEC_ID_H264 CODEC_ID_H264 74 #define AV_CODEC_ID_THEORA CODEC_ID_THEORA 75 #define AV_CODEC_ID_NONE CODEC_ID_NONE 76 #define AVCodecID CodecID 77 #endif 78 79 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(55,17,103) 80 #define VICE_AV_PIX_FMT_RGB24 PIX_FMT_RGB24 81 #define VICE_AV_PixelFormat PixelFormat 82 #else 83 #define VICE_AV_PIX_FMT_RGB24 AV_PIX_FMT_RGB24 84 #define VICE_AV_PixelFormat AVPixelFormat 85 #endif 86 87 /* avcodec fucntions */ 88 typedef void(*av_init_packet_t)(AVPacket *pkt); 89 typedef int(*avcodec_open2_t)(AVCodecContext*, AVCodec*, AVDictionary **); 90 typedef int (*avcodec_close_t)(AVCodecContext*); 91 typedef AVCodec* (*avcodec_find_encoder_t)(enum AVCodecID); 92 typedef int(*avcodec_encode_audio2_t)(AVCodecContext*, AVPacket*, const AVFrame*, int*); 93 typedef int(*avcodec_encode_video2_t)(AVCodecContext*, AVPacket*, const AVFrame*, int*); 94 typedef int (*avpicture_fill_t)(AVPicture*, uint8_t*, int, int, int); 95 typedef int (*avpicture_get_size_t)(int, int, int); 96 typedef void(*av_packet_rescale_ts_t)(AVPacket*, AVRational, AVRational); 97 98 /* avformat functions */ 99 typedef void (*av_register_all_t)(void); 100 typedef AVFormatContext* (*avformat_alloc_context_t)(void); 101 typedef AVStream* (*avformat_new_stream_t)(AVFormatContext*, AVCodec *); 102 typedef int (*avformat_write_header_t) (AVFormatContext*,AVDictionary **); 103 typedef int (*av_interleaved_write_frame_t)(AVFormatContext*, AVPacket*); 104 typedef int (*av_write_trailer_t)(AVFormatContext*); 105 typedef int (*avio_open_t) (AVIOContext**, const char*, int); 106 typedef int (*avio_close_t) (AVIOContext*); 107 typedef void (*av_dump_format_t) (AVFormatContext *, int, const char*, int); 108 typedef AVOutputFormat* (*av_guess_format_t)(const char*, const char*, const char*); 109 typedef int (*img_convert_t)(AVPicture*, int, AVPicture*, int, int, int); 110 111 /* avutil functions */ 112 typedef void (*av_free_t)(void**); 113 typedef AVFrame* (*av_frame_alloc_t)(void); 114 typedef int (*av_frame_get_buffer_t)(AVFrame*, int); 115 typedef int(*av_compare_ts_t)(int64_t, AVRational, int64_t, AVRational); 116 typedef int(*av_get_channel_layout_nb_channels_t)(uint64_t); 117 typedef int(*av_opt_set_int_t)(void*, const char*, int64_t, int); 118 typedef int(*av_opt_set_sample_fmt_t)(void*, const char*, enum AVSampleFormat, int); 119 typedef int64_t(*av_rescale_rnd_t)(int64_t, int64_t, int64_t, enum AVRounding); 120 typedef int64_t(*av_rescale_q_t)(int64_t, AVRational, AVRational); 121 typedef AVRational(*av_d2q_t)(double d, int max); 122 typedef int(*av_frame_make_writable_t)(AVFrame*); 123 typedef void(*av_frame_free_t)(AVFrame**); 124 typedef int(*av_dict_set_t)(AVDictionary**, const char*, const char*, int); 125 typedef void(*av_dict_free_t)(AVDictionary**); 126 127 /* swscale functions */ 128 typedef struct SwsContext * (*sws_getContext_t)(int srcW, int srcH, 129 enum VICE_AV_PixelFormat srcFormat, int dstW, int dstH, enum VICE_AV_PixelFormat dstFormat, 130 int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); 131 typedef void (*sws_freeContext_t)(struct SwsContext *swsContext); 132 typedef int (*sws_scale_t)(struct SwsContext *context, uint8_t* srcSlice[], 133 int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], 134 int dstStride[]); 135 136 #ifndef HAVE_FFMPEG_AVRESAMPLE 137 /* swresample functions */ 138 typedef struct SwrContext* (*swr_alloc_t)(void); 139 typedef int (*swr_init_t)(struct SwrContext*); 140 typedef int (*swr_convert_t)(struct SwrContext*, uint8_t**, int, const uint8_t**, int); 141 typedef void (*swr_free_t)(struct SwrContext**); 142 typedef int64_t (*swr_get_delay_t)(struct SwrContext*, int64_t); 143 #else 144 /* avresample functions */ 145 typedef struct AVAudioResampleContext* (*avresample_alloc_context_t)(void); 146 typedef int (*avresample_convert_t)(struct AVAudioResampleContext*, uint8_t**, int, int, const uint8_t**, int, int); 147 typedef int (*avresample_open_t)(struct AVAudioResampleContext*); 148 typedef void (*avresample_free_t)(struct AVAudioResampleContext**); 149 typedef int64_t (*avresample_get_delay_t)(struct AVAudioResampleContext*, int64_t); 150 #endif 151 152 struct ffmpeglib_s { 153 /* avcodec */ 154 avcodec_open2_t p_avcodec_open2; 155 avcodec_close_t p_avcodec_close; 156 avcodec_find_encoder_t p_avcodec_find_encoder; 157 avcodec_encode_audio2_t p_avcodec_encode_audio2; 158 avcodec_encode_video2_t p_avcodec_encode_video2; 159 avpicture_fill_t p_avpicture_fill; 160 avpicture_get_size_t p_avpicture_get_size; 161 av_packet_rescale_ts_t p_av_packet_rescale_ts; 162 163 /* avformat */ 164 av_init_packet_t p_av_init_packet; 165 av_register_all_t p_av_register_all; 166 avformat_alloc_context_t p_avformat_alloc_context; 167 avformat_new_stream_t p_avformat_new_stream; 168 avformat_write_header_t p_avformat_write_header; 169 av_interleaved_write_frame_t p_av_interleaved_write_frame; 170 av_write_trailer_t p_av_write_trailer; 171 avio_open_t p_avio_open; 172 avio_close_t p_avio_close; 173 av_dump_format_t p_av_dump_format; 174 av_guess_format_t p_av_guess_format; 175 176 /* avutil */ 177 av_free_t p_av_free; 178 av_frame_alloc_t p_av_frame_alloc; 179 av_frame_get_buffer_t p_av_frame_get_buffer; 180 av_compare_ts_t p_av_compare_ts; 181 av_get_channel_layout_nb_channels_t p_av_get_channel_layout_nb_channels; 182 av_opt_set_int_t p_av_opt_set_int; 183 av_opt_set_sample_fmt_t p_av_opt_set_sample_fmt; 184 av_rescale_rnd_t p_av_rescale_rnd; 185 av_rescale_q_t p_av_rescale_q; 186 av_d2q_t p_av_d2q; 187 av_frame_make_writable_t p_av_frame_make_writable; 188 av_frame_free_t p_av_frame_free; 189 av_dict_set_t p_av_dict_set; 190 av_dict_free_t p_av_dict_free; 191 192 /* swscale */ 193 sws_getContext_t p_sws_getContext; 194 sws_freeContext_t p_sws_freeContext; 195 sws_scale_t p_sws_scale; 196 197 #ifndef HAVE_FFMPEG_AVRESAMPLE 198 /* swresample */ 199 swr_alloc_t p_swr_alloc; 200 swr_init_t p_swr_init; 201 swr_convert_t p_swr_convert; 202 swr_get_delay_t p_swr_get_delay; 203 swr_free_t p_swr_free; 204 #else 205 /* avresample */ 206 avresample_alloc_context_t p_avresample_alloc_context; 207 avresample_open_t p_avresample_open; 208 avresample_convert_t p_avresample_convert; 209 avresample_free_t p_avresample_free; 210 avresample_get_delay_t p_avresample_get_delay; 211 #endif 212 }; 213 214 typedef struct ffmpeglib_s ffmpeglib_t; 215 216 extern int ffmpeglib_open(ffmpeglib_t *lib); 217 extern void ffmpeglib_close(ffmpeglib_t *lib); 218 219 #endif 220