mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-01 07:15:27 +00:00
Consolidate decoder checks to reduce code duplication
This commit is contained in:
parent
952ebcd0d2
commit
52583f5c71
@ -1,6 +1,5 @@
|
||||
#include <Limelight.h>
|
||||
#include "ffmpeg.h"
|
||||
#include "streaming/streamutils.h"
|
||||
#include "streaming/session.h"
|
||||
|
||||
#include <h264_stream.h>
|
||||
@ -1181,24 +1180,6 @@ bool FFmpegVideoDecoder::tryInitializeRendererForUnknownDecoder(const AVCodec* d
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FFmpegVideoDecoder::isDecoderIgnored(const AVCodec *decoder)
|
||||
{
|
||||
Q_UNUSED(decoder);
|
||||
|
||||
#if defined(HAVE_MMAL) && !defined(ALLOW_EGL_WITH_MMAL)
|
||||
// Only enable V4L2M2M by default on non-MMAL (RPi) builds. The performance
|
||||
// of the V4L2M2M wrapper around MMAL is not enough for 1080p 60 FPS, so we
|
||||
// would rather show the missing hardware acceleration warning when the user
|
||||
// is in Full KMS mode rather than try to use a poorly performing hwaccel.
|
||||
// See discussion on https://github.com/jc-kynesim/rpi-ffmpeg/pull/25
|
||||
if (strcmp(decoder->name, "h264_v4l2m2m") == 0) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int FFmpegVideoDecoder::getAVCodecCapabilities(const AVCodec *codec)
|
||||
{
|
||||
int caps = codec->capabilities;
|
||||
@ -1215,6 +1196,26 @@ int FFmpegVideoDecoder::getAVCodecCapabilities(const AVCodec *codec)
|
||||
return caps;
|
||||
}
|
||||
|
||||
bool FFmpegVideoDecoder::isDecoderMatchForParams(const AVCodec *decoder, PDECODER_PARAMETERS params)
|
||||
{
|
||||
SDL_assert(params->videoFormat & (VIDEO_FORMAT_MASK_H264 | VIDEO_FORMAT_MASK_H265 | VIDEO_FORMAT_MASK_AV1));
|
||||
|
||||
#if defined(HAVE_MMAL) && !defined(ALLOW_EGL_WITH_MMAL)
|
||||
// Only enable V4L2M2M by default on non-MMAL (RPi) builds. The performance
|
||||
// of the V4L2M2M wrapper around MMAL is not enough for 1080p 60 FPS, so we
|
||||
// would rather show the missing hardware acceleration warning when the user
|
||||
// is in Full KMS mode rather than try to use a poorly performing hwaccel.
|
||||
// See discussion on https://github.com/jc-kynesim/rpi-ffmpeg/pull/25
|
||||
if (strcmp(decoder->name, "h264_v4l2m2m") == 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ((params->videoFormat & VIDEO_FORMAT_MASK_H264) && decoder->id == AV_CODEC_ID_H264) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_H265) && decoder->id == AV_CODEC_ID_HEVC) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_AV1) && decoder->id == AV_CODEC_ID_AV1);
|
||||
}
|
||||
|
||||
bool FFmpegVideoDecoder::tryInitializeHwAccelDecoder(PDECODER_PARAMETERS params, int pass, QSet<const AVCodec*>& terminallyFailedHardwareDecoders)
|
||||
{
|
||||
const AVCodec* decoder;
|
||||
@ -1230,10 +1231,8 @@ bool FFmpegVideoDecoder::tryInitializeHwAccelDecoder(PDECODER_PARAMETERS params,
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip decoders that don't match our codec
|
||||
if (((params->videoFormat & VIDEO_FORMAT_MASK_H264) && decoder->id != AV_CODEC_ID_H264) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_H265) && decoder->id != AV_CODEC_ID_HEVC) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_AV1) && decoder->id != AV_CODEC_ID_AV1)) {
|
||||
// Skip decoders that don't match our decoding parameters
|
||||
if (!isDecoderMatchForParams(decoder, params)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1242,11 +1241,6 @@ bool FFmpegVideoDecoder::tryInitializeHwAccelDecoder(PDECODER_PARAMETERS params,
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip ignored decoders
|
||||
if (isDecoderIgnored(decoder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip hardware decoders that have returned a terminal failure status
|
||||
if (terminallyFailedHardwareDecoders.contains(decoder)) {
|
||||
continue;
|
||||
@ -1297,10 +1291,8 @@ bool FFmpegVideoDecoder::tryInitializeNonHwAccelDecoder(PDECODER_PARAMETERS para
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip decoders that don't match our codec
|
||||
if (((params->videoFormat & VIDEO_FORMAT_MASK_H264) && decoder->id != AV_CODEC_ID_H264) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_H265) && decoder->id != AV_CODEC_ID_HEVC) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_AV1) && decoder->id != AV_CODEC_ID_AV1)) {
|
||||
// Skip decoders that don't match our decoding parameters
|
||||
if (!isDecoderMatchForParams(decoder, params)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1309,11 +1301,6 @@ bool FFmpegVideoDecoder::tryInitializeNonHwAccelDecoder(PDECODER_PARAMETERS para
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip ignored decoders
|
||||
if (isDecoderIgnored(decoder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip decoders without zero-copy output formats if requested
|
||||
if (requireZeroCopyFormat) {
|
||||
bool foundZeroCopyFormat = false;
|
||||
@ -1449,10 +1436,8 @@ bool FFmpegVideoDecoder::initialize(PDECODER_PARAMETERS params)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip decoders that don't match our codec
|
||||
if (((params->videoFormat & VIDEO_FORMAT_MASK_H264) && decoder->id != AV_CODEC_ID_H264) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_H265) && decoder->id != AV_CODEC_ID_HEVC) ||
|
||||
((params->videoFormat & VIDEO_FORMAT_MASK_AV1) && decoder->id != AV_CODEC_ID_AV1)) {
|
||||
// Skip decoders that don't match our decoding parameters
|
||||
if (!isDecoderMatchForParams(decoder, params)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1466,11 +1451,6 @@ bool FFmpegVideoDecoder::initialize(PDECODER_PARAMETERS params)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip ignored decoders
|
||||
if (isDecoderIgnored(decoder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try this decoder without hwaccel
|
||||
if (tryInitializeRendererForUnknownDecoder(decoder, params, false)) {
|
||||
return true;
|
||||
|
@ -46,7 +46,7 @@ private:
|
||||
bool createFrontendRenderer(PDECODER_PARAMETERS params, bool useAlternateFrontend);
|
||||
|
||||
static
|
||||
bool isDecoderIgnored(const AVCodec* decoder);
|
||||
bool isDecoderMatchForParams(const AVCodec *decoder, PDECODER_PARAMETERS params);
|
||||
|
||||
static
|
||||
bool isZeroCopyFormat(AVPixelFormat format);
|
||||
|
Loading…
x
Reference in New Issue
Block a user