Ring Daemon
Loading...
Searching...
No Matches
accel.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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#include "video/video_base.h"
22
23#include <memory>
24#include <string>
25#include <list>
26
27extern "C" {
28#include <libavutil/hwcontext.h>
29}
30
31namespace jami {
32namespace video {
33
35
40{
41public:
54 static std::unique_ptr<VideoFrame> transferToMainMemory(const VideoFrame& frame, AVPixelFormat desiredFormat);
55
62 const std::string& name,
63 AVHWDeviceType hwType,
64 AVPixelFormat format,
65 AVPixelFormat swFormat,
66 CodecType type,
67 bool dynBitrate);
68
73
77 AVCodecID getCodecId() const { return id_; };
78
82 const std::string& getName() const { return name_; };
83
87 AVPixelFormat getFormat() const { return format_; };
88
95 AVPixelFormat getSoftwareFormat() const { return swFormat_; }
96
103 std::string getCodecName() const;
104
112 bool isLinked() const { return linked_; }
113
125
136 std::unique_ptr<VideoFrame> transfer(const VideoFrame& frame);
137
144
145 static std::list<HardwareAccel> getCompatibleAccel(AVCodecID id, int width, int height, CodecType type);
147 bool dynBitrate() { return dynBitrate_; }
148
149private:
150 bool initDevice(const std::string& device);
151 bool initFrame();
152
154 std::string name_;
157 AVPixelFormat swFormat_ {AV_PIX_FMT_NONE};
158 CodecType type_ {CODEC_NONE};
159 bool linked_ {false};
160 int width_ {0};
161 int height_ {0};
162 bool dynBitrate_ {false};
163
164 AVBufferRef* deviceCtx_ {nullptr};
165 AVBufferRef* framesCtx_ {nullptr};
166
167 int init_device(const char* name, const char* device, int flags);
168 int init_device_type(std::string& dev);
169
170 std::list<std::pair<std::string, DeviceState>>* possible_devices_;
171};
172
173} // namespace video
174} // namespace jami
Provides an abstraction layer to the hardware acceleration APIs in FFmpeg.
Definition accel.h:40
AVPixelFormat getSoftwareFormat() const
Software format.
Definition accel.h:95
bool linkHardware(AVBufferRef *framesCtx)
Links this HardwareAccel's frames context with the passed in context.
Definition accel.cpp:345
static std::list< HardwareAccel > getCompatibleAccel(AVCodecID id, int width, int height, CodecType type)
Definition accel.cpp:417
static std::unique_ptr< VideoFrame > transferToMainMemory(const VideoFrame &frame, AVPixelFormat desiredFormat)
Transfers hardware frame to main memory.
Definition accel.cpp:367
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:82
void setDetails(AVCodecContext *codecCtx)
Set some extra details in the codec context.
Definition accel.cpp:304
bool isLinked() const
If hardware decoder can feed hardware encoder directly.
Definition accel.h:112
~HardwareAccel()
Dereferences hardware contexts.
Definition accel.cpp:134
AVPixelFormat getFormat() const
Hardware format.
Definition accel.h:87
AVCodecID getCodecId() const
Codec that is being accelerated.
Definition accel.h:77
int initAPI(bool linkable, AVBufferRef *framesCtx)
Definition accel.cpp:399
Definition Address.h:25
void emitSignal(Args... args)
Definition jami_signal.h:64
@ CODEC_NONE
Definition media_codec.h:38