Skip to content
Snippets Groups Projects
Commit 15fd0552 authored by Philippe Gorley's avatar Philippe Gorley Committed by Philippe Gorley
Browse files

video: add multi gpu support for vaapi

This iterates over all DRM devices under
/dev/dri (card* and renderD*) and returns the first
device that works

Change-Id: I4a4aea565122abf81786b0ccc69539631f10b5f8
Tuleap: #1082
(cherry picked from commit d6a90bf9)
parent 224b2559
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,8 @@
#include "video/v4l2/vaapi.h"
#include "video/accel.h"
#include "fileutils.h"
#include <sstream>
#include <stdexcept>
#include <map>
......@@ -94,6 +96,30 @@ VaapiAccel::extractData(AVCodecContext* codecCtx, VideoFrame& container)
bool
VaapiAccel::init(AVCodecContext* codecCtx)
{
#ifdef HAVE_VAAPI_ACCEL_DRM
// try all possible devices, use first one that works
const std::string path = "/dev/dri/";
for (auto& entry : ring::fileutils::readDirectory(path)) {
// a drm device is either a card or a render node, check both
const std::string prefixCard = "card";
if (!entry.compare(0, prefixCard.size(), prefixCard.c_str()))
if (open(codecCtx, path + entry))
return true;
const std::string prefixNode = "renderD";
if (!entry.compare(0, prefixNode.size(), prefixNode.c_str()))
if (open(codecCtx, path + entry))
return true;
}
return false;
#elif HAVE_VAAPI_ACCEL_X11
return open(codecCtx, ":0"); // this is the default x11 device
#endif
}
bool
VaapiAccel::open(AVCodecContext* codecCtx, std::string deviceName)
{
vaProfile_ = VAProfileNone;
vaEntryPoint_ = VAEntrypointVLD;
......@@ -121,16 +147,9 @@ VaapiAccel::init(AVCodecContext* codecCtx)
};
VAStatus status;
#ifdef HAVE_VAAPI_ACCEL_DRM
const char* deviceName = "/dev/dri/card0"; // check for renderDX first?
#else
const char* deviceName = nullptr; // use default device
#endif
AVBufferRef* hardwareDeviceCtx;
if (av_hwdevice_ctx_create(&hardwareDeviceCtx, AV_HWDEVICE_TYPE_VAAPI, deviceName, nullptr, 0) < 0) {
RING_ERR("Failed to create VAAPI device");
if (av_hwdevice_ctx_create(&hardwareDeviceCtx, AV_HWDEVICE_TYPE_VAAPI, deviceName.c_str(), nullptr, 0) < 0) {
RING_ERR("Failed to create VAAPI device using %s", deviceName.c_str());
av_buffer_unref(&hardwareDeviceCtx);
return false;
}
......@@ -216,7 +235,7 @@ VaapiAccel::init(AVCodecContext* codecCtx)
return false;
}
RING_DBG("VAAPI decoder initialized");
RING_DBG("VAAPI decoder initialized via device: %s", deviceName.c_str());
ffmpegAccelCtx_.display = hardwareContext->display;
ffmpegAccelCtx_.config_id = vaConfig_;
......
......@@ -76,6 +76,8 @@ class VaapiAccel : public HardwareAccel {
VAContextID vaContext_;
struct vaapi_context ffmpegAccelCtx_;
bool open(AVCodecContext* codecCtx, std::string deviceName);
};
}} // namespace ring::video
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment