1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * OpenH264 shared utils 3cabdff1aSopenharmony_ci * Copyright (C) 2014 Martin Storsjo 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci#include <string.h> 23cabdff1aSopenharmony_ci#include <wels/codec_api.h> 24cabdff1aSopenharmony_ci#include <wels/codec_ver.h> 25cabdff1aSopenharmony_ci 26cabdff1aSopenharmony_ci#include "libavutil/error.h" 27cabdff1aSopenharmony_ci#include "libavutil/log.h" 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_ci#include "libopenh264.h" 30cabdff1aSopenharmony_ci 31cabdff1aSopenharmony_ci// Convert libopenh264 log level to equivalent ffmpeg log level. 32cabdff1aSopenharmony_cistatic int libopenh264_to_ffmpeg_log_level(int libopenh264_log_level) 33cabdff1aSopenharmony_ci{ 34cabdff1aSopenharmony_ci if (libopenh264_log_level >= WELS_LOG_DETAIL) return AV_LOG_TRACE; 35cabdff1aSopenharmony_ci else if (libopenh264_log_level >= WELS_LOG_DEBUG) return AV_LOG_DEBUG; 36cabdff1aSopenharmony_ci else if (libopenh264_log_level >= WELS_LOG_INFO) return AV_LOG_VERBOSE; 37cabdff1aSopenharmony_ci else if (libopenh264_log_level >= WELS_LOG_WARNING) return AV_LOG_WARNING; 38cabdff1aSopenharmony_ci else if (libopenh264_log_level >= WELS_LOG_ERROR) return AV_LOG_ERROR; 39cabdff1aSopenharmony_ci else return AV_LOG_QUIET; 40cabdff1aSopenharmony_ci} 41cabdff1aSopenharmony_ci 42cabdff1aSopenharmony_civoid ff_libopenh264_trace_callback(void *ctx, int level, const char *msg) 43cabdff1aSopenharmony_ci{ 44cabdff1aSopenharmony_ci // The message will be logged only if the requested EQUIVALENT ffmpeg log level is 45cabdff1aSopenharmony_ci // less than or equal to the current ffmpeg log level. 46cabdff1aSopenharmony_ci int equiv_ffmpeg_log_level = libopenh264_to_ffmpeg_log_level(level); 47cabdff1aSopenharmony_ci av_log(ctx, equiv_ffmpeg_log_level, "%s\n", msg); 48cabdff1aSopenharmony_ci} 49cabdff1aSopenharmony_ci 50cabdff1aSopenharmony_ciint ff_libopenh264_check_version(void *logctx) 51cabdff1aSopenharmony_ci{ 52cabdff1aSopenharmony_ci // Mingw GCC < 4.7 on x86_32 uses an incorrect/buggy ABI for the WelsGetCodecVersion 53cabdff1aSopenharmony_ci // function (for functions returning larger structs), thus skip the check in those 54cabdff1aSopenharmony_ci // configurations. 55cabdff1aSopenharmony_ci#if !defined(_WIN32) || !defined(__GNUC__) || !ARCH_X86_32 || AV_GCC_VERSION_AT_LEAST(4, 7) 56cabdff1aSopenharmony_ci OpenH264Version libver = WelsGetCodecVersion(); 57cabdff1aSopenharmony_ci if (memcmp(&libver, &g_stCodecVersion, sizeof(libver))) { 58cabdff1aSopenharmony_ci av_log(logctx, AV_LOG_ERROR, "Incorrect library version loaded\n"); 59cabdff1aSopenharmony_ci return AVERROR(EINVAL); 60cabdff1aSopenharmony_ci } 61cabdff1aSopenharmony_ci#endif 62cabdff1aSopenharmony_ci return 0; 63cabdff1aSopenharmony_ci} 64