| // Created on: 2025-06-22 | |
| // Copyright (c) 2025 OPEN CASCADE SAS | |
| // | |
| // This file is part of Open CASCADE Technology software library. | |
| // | |
| // This library is free software; you can redistribute it and/or modify it under | |
| // the terms of the GNU Lesser General Public License version 2.1 as published | |
| // by the Free Software Foundation, with special exception defined in the file | |
| // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
| // distribution for complete text of the license and disclaimer of any warranty. | |
| // | |
| // Alternatively, this file may be used under the terms of Open CASCADE | |
| // commercial license or contractual agreement. | |
| //! FFmpeg compatibility layer for OCCT | |
| //! | |
| //! Provides compatibility between FFmpeg 4.4.x and 7.1.x by wrapping | |
| //! deprecated/removed functions and handling API changes automatically. | |
| #ifndef _FFmpeg_Compatibility_HeaderFile | |
| #define _FFmpeg_Compatibility_HeaderFile | |
| #ifdef HAVE_FFMPEG | |
| // activate some C99 macros like UINT64_C in "stdint.h" which used by FFmpeg | |
| #ifndef __STDC_CONSTANT_MACROS | |
| #define __STDC_CONSTANT_MACROS | |
| #endif | |
| // Standard C headers needed for compilation | |
| #include <stdint.h> | |
| #include <Standard_WarningsDisable.hxx> | |
| extern "C" | |
| { | |
| #include <libavcodec/avcodec.h> | |
| #include <libavformat/avformat.h> | |
| #include <libavutil/imgutils.h> | |
| #include <libswscale/swscale.h> | |
| }; | |
| #include <Standard_WarningsRestore.hxx> | |
| // Version detection macros | |
| #define FFMPEG_VERSION_4_4 AV_VERSION_INT(58, 0, 0) | |
| #define FFMPEG_VERSION_5_0 AV_VERSION_INT(59, 0, 0) | |
| #define FFMPEG_VERSION_6_0 AV_VERSION_INT(60, 0, 0) | |
| #define FFMPEG_VERSION_7_0 AV_VERSION_INT(61, 0, 0) | |
| // Check if we're using FFmpeg 5.0+ (major API change point) | |
| #if LIBAVCODEC_VERSION_INT >= FFMPEG_VERSION_5_0 | |
| #define FFMPEG_NEW_API 1 | |
| #else | |
| #define FFMPEG_NEW_API 0 | |
| #endif | |
| // Additional version checks for specific functions | |
| #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100) | |
| #define FFMPEG_HAVE_NEW_DECODE_API 1 | |
| #else | |
| #define FFMPEG_HAVE_NEW_DECODE_API 0 | |
| #endif | |
| #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 0, 0) | |
| #define FFMPEG_HAVE_AVCODEC_PARAMETERS 1 | |
| #else | |
| #define FFMPEG_HAVE_AVCODEC_PARAMETERS 0 | |
| #endif | |
| // Constant compatibility for different FFmpeg versions | |
| // Error buffer size might be different | |
| #ifndef AV_ERROR_MAX_STRING_SIZE | |
| #define AV_ERROR_MAX_STRING_SIZE 64 | |
| #endif | |
| // Codec flags compatibility | |
| #ifndef AV_CODEC_FLAG_GLOBAL_HEADER | |
| #define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER | |
| #endif | |
| // Pixel format compatibility - old names to new names | |
| #ifndef AV_PIX_FMT_YUV420P | |
| #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P | |
| #endif | |
| #ifndef AV_PIX_FMT_RGBA | |
| #define AV_PIX_FMT_RGBA PIX_FMT_RGBA | |
| #endif | |
| #ifndef AV_PIX_FMT_RGB24 | |
| #define AV_PIX_FMT_RGB24 PIX_FMT_RGB24 | |
| #endif | |
| #ifndef AV_PIX_FMT_NONE | |
| #define AV_PIX_FMT_NONE PIX_FMT_NONE | |
| #endif | |
| #ifndef AV_PIX_FMT_YUVJ420P | |
| #define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P | |
| #endif | |
| // For old FFmpeg versions that don't have AV_PIX_FMT_* constants | |
| #ifndef PIX_FMT_YUV420P | |
| #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P | |
| #endif | |
| #ifndef PIX_FMT_RGBA | |
| #define PIX_FMT_RGBA AV_PIX_FMT_RGBA | |
| #endif | |
| #ifndef PIX_FMT_RGB24 | |
| #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 | |
| #endif | |
| #ifndef PIX_FMT_NONE | |
| #define PIX_FMT_NONE AV_PIX_FMT_NONE | |
| #endif | |
| #ifndef PIX_FMT_YUVJ420P | |
| #define PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P | |
| #endif | |
| // AVRounding compatibility - handle missing AV_ prefix | |
| #ifndef AV_ROUND_NEAR_INF | |
| #ifdef AVROUND_NEAR_INF | |
| #define AV_ROUND_NEAR_INF AVROUND_NEAR_INF | |
| #else | |
| #define AV_ROUND_NEAR_INF 5 | |
| #endif | |
| #endif | |
| #ifndef AV_ROUND_PASS_MINMAX | |
| #ifdef AVROUND_PASS_MINMAX | |
| #define AV_ROUND_PASS_MINMAX AVROUND_PASS_MINMAX | |
| #else | |
| #define AV_ROUND_PASS_MINMAX 8192 | |
| #endif | |
| #endif | |
| // Also define the old names for compatibility | |
| #ifndef AVROUND_NEAR_INF | |
| #define AVROUND_NEAR_INF AV_ROUND_NEAR_INF | |
| #endif | |
| #ifndef AVROUND_PASS_MINMAX | |
| #define AVROUND_PASS_MINMAX AV_ROUND_PASS_MINMAX | |
| #endif | |
| // Compatibility functions and macros | |
| // av_register_all() - deprecated/removed in FFmpeg 4.0+ | |
| inline void ffmpeg_register_all() | |
| { | |
| #if !FFMPEG_NEW_API | |
| av_register_all(); | |
| #endif | |
| } | |
| // AVCodec constness changes | |
| inline AVCodec* ffmpeg_find_encoder(enum AVCodecID id) | |
| { | |
| #if FFMPEG_NEW_API | |
| return const_cast<AVCodec*>(avcodec_find_encoder(id)); | |
| #else | |
| return avcodec_find_encoder(id); | |
| #endif | |
| } | |
| inline AVCodec* ffmpeg_find_encoder_by_name(const char* name) | |
| { | |
| #if FFMPEG_NEW_API | |
| return const_cast<AVCodec*>(avcodec_find_encoder_by_name(name)); | |
| #else | |
| return avcodec_find_encoder_by_name(name); | |
| #endif | |
| } | |
| inline AVCodec* ffmpeg_find_decoder(enum AVCodecID id) | |
| { | |
| #if FFMPEG_NEW_API | |
| return const_cast<AVCodec*>(avcodec_find_decoder(id)); | |
| #else | |
| return avcodec_find_decoder(id); | |
| #endif | |
| } | |
| #endif // HAVE_FFMPEG | |
| #endif // _FFmpeg_Compatibility_HeaderFile |