Line data Source code
1 : /* 2 : * Copyright (C) 2004-2025 Savoir-faire Linux Inc. 3 : * 4 : * This program is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This program is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 : */ 17 : #pragma once 18 : 19 : #include <libavutil/samplefmt.h> 20 : 21 : #include <vector> 22 : #include <map> 23 : #include <string> 24 : #include <memory> 25 : 26 : extern "C" { 27 : struct AVDictionary; 28 : struct AVFrame; 29 : struct AVPixFmtDescriptor; 30 : struct AVBufferRef; 31 : struct AVCodec; 32 : void av_buffer_unref(AVBufferRef **buf); 33 : } 34 : 35 : namespace jami { 36 : namespace libav_utils { 37 : 38 : void av_init(); 39 : 40 : const char* const DEFAULT_H264_PROFILE_LEVEL_ID = "profile-level-id=428029"; 41 : const char* const MAX_H264_PROFILE_LEVEL_ID = "profile-level-id=640034"; 42 : 43 : enum AVSampleFormat choose_sample_fmt(const AVCodec* codec, const enum AVSampleFormat* preferred_formats, int preferred_formats_count); 44 : enum AVSampleFormat choose_sample_fmt_default(const AVCodec* codec, enum AVSampleFormat defaultFormat); 45 : 46 : bool is_yuv_planar(const AVPixFmtDescriptor& desc); 47 : 48 : std::string getError(int err); 49 : 50 : const char* getDictValue(const AVDictionary* d, const std::string& key, int flags = 0); 51 : 52 : void setDictValue(AVDictionary** d, const std::string& key, const std::string& value, int flags = 0); 53 : 54 : void fillWithBlack(AVFrame* frame); 55 : 56 : void fillWithSilence(AVFrame* frame); 57 : 58 : struct AVBufferRef_deleter { 59 194 : void operator()(AVBufferRef* buf) const { av_buffer_unref(&buf); } 60 : }; 61 : 62 : typedef std::unique_ptr<AVBufferRef, AVBufferRef_deleter> AVBufferPtr; 63 : 64 : } // namespace libav_utils 65 : } // namespace jami