Ring Daemon 16.0.0
Loading...
Searching...
No Matches
accel.h
Go to the documentation of this file.
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 "libav_deps.h"
20#include "media_codec.h"
21
22#include <memory>
23#include <string>
24#include <vector>
25#include <list>
26
27extern "C" {
28#include <libavutil/hwcontext.h>
29}
30
31namespace jami {
32namespace video {
33
34
35enum class DeviceState {
37 USABLE,
39};
40
45{
46public:
59 static std::unique_ptr<VideoFrame> transferToMainMemory(const VideoFrame& frame,
61
68 const std::string& name,
69 AVHWDeviceType hwType,
70 AVPixelFormat format,
71 AVPixelFormat swFormat,
72 CodecType type,
73 bool dynBitrate);
74
79
83 AVCodecID getCodecId() const { return id_; };
84
88 const std::string& getName() const { return name_; };
89
93 AVPixelFormat getFormat() const { return format_; };
94
101 AVPixelFormat getSoftwareFormat() const { return swFormat_; }
102
109 std::string getCodecName() const;
110
118 bool isLinked() const { return linked_; }
119
131
142 std::unique_ptr<VideoFrame> transfer(const VideoFrame& frame);
143
150
151 static std::list<HardwareAccel> getCompatibleAccel(AVCodecID id,
152 int width,
153 int height,
154 CodecType type);
156 bool dynBitrate() { return dynBitrate_; }
157
158private:
159 bool initDevice(const std::string& device);
160 bool initFrame();
161
163 std::string name_;
166 AVPixelFormat swFormat_ {AV_PIX_FMT_NONE};
167 CodecType type_ {CODEC_NONE};
168 bool linked_ {false};
169 int width_ {0};
170 int height_ {0};
171 bool dynBitrate_ {false};
172
173 AVBufferRef* deviceCtx_ {nullptr};
174 AVBufferRef* framesCtx_ {nullptr};
175
176 int init_device(const char* name, const char* device, int flags);
177 int init_device_type(std::string& dev);
178
179 std::list<std::pair<std::string, DeviceState>>* possible_devices_;
180};
181
182} // namespace video
183} // namespace jami
Provides an abstraction layer to the hardware acceleration APIs in FFmpeg.
Definition accel.h:45
AVPixelFormat getSoftwareFormat() const
Software format.
Definition accel.h:101
bool linkHardware(AVBufferRef *framesCtx)
Links this HardwareAccel's frames context with the passed in context.
Definition accel.cpp:350
static std::list< HardwareAccel > getCompatibleAccel(AVCodecID id, int width, int height, CodecType type)
Definition accel.cpp:424
static std::unique_ptr< VideoFrame > transferToMainMemory(const VideoFrame &frame, AVPixelFormat desiredFormat)
Transfers hardware frame to main memory.
Definition accel.cpp:372
std::string getCodecName() const
Gets the name of the codec.
Definition accel.cpp:246
std::unique_ptr< VideoFrame > transfer(const VideoFrame &frame)
Transfers a frame to/from the GPU memory.
Definition accel.cpp:257
const std::string & getName() const
Name of the hardware layer/API being used.
Definition accel.h:88
void setDetails(AVCodecContext *codecCtx)
Set some extra details in the codec context.
Definition accel.cpp:307
bool isLinked() const
If hardware decoder can feed hardware encoder directly.
Definition accel.h:118
~HardwareAccel()
Dereferences hardware contexts.
Definition accel.cpp:134
AVPixelFormat getFormat() const
Hardware format.
Definition accel.h:93
AVCodecID getCodecId() const
Codec that is being accelerated.
Definition accel.h:83
int initAPI(bool linkable, AVBufferRef *framesCtx)
Definition accel.cpp:406
Definition Address.h:25
void emitSignal(Args... args)
Definition ring_signal.h:64
@ CODEC_NONE
Definition media_codec.h:39