Skip to content

Commit 8b18d58

Browse files
committed
Add workaround for interoperability issue with out-of-tree FFmpeg zero-copy v4l2m2m patches and libplacebo
Fixes moonlight-stream#1786
1 parent 5e1ac6d commit 8b18d58

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • app/streaming/video/ffmpeg-renderers

app/streaming/video/ffmpeg-renderers/plvk.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <SDL_vulkan.h>
1111

1212
extern "C" {
13+
#include <libavutil/hwcontext_drm.h>
1314
#include <libavutil/hwcontext_vulkan.h>
1415
}
1516

@@ -1146,6 +1147,24 @@ bool PlVkRenderer::testRenderFrame(AVFrame *frame)
11461147
}
11471148
#endif
11481149

1150+
if (frame->format == AV_PIX_FMT_DRM_PRIME) {
1151+
auto drmFrame = (AVDRMFrameDescriptor*)frame->data[0];
1152+
1153+
// This can happen with out-of-tree FFmpeg patches if the V4L2
1154+
// format lacks a mapping to a DRM format.
1155+
if (drmFrame->nb_layers == 0) {
1156+
return false;
1157+
}
1158+
1159+
// Current versions of libplacebo only support one plane per layer
1160+
// and will assert if provided a frame that violates this constraint.
1161+
for (int i = 0; i < drmFrame->nb_layers; i++) {
1162+
if (drmFrame->layers[i].nb_planes != 1) {
1163+
return false;
1164+
}
1165+
}
1166+
}
1167+
11491168
// Test if the frame can be mapped to libplacebo
11501169
pl_frame mappedFrame;
11511170
if (!mapAvFrameToPlacebo(frame, &mappedFrame)) {

0 commit comments

Comments
 (0)