6 #define LOC QString("DRMPRIMECtx: ")
42 const AVCodec **Codec,
46 const QString &CodecName,
50 QString name = QString((*Codec)->name) +
"_" + CodecName;
51 if (name.startsWith(
"mpeg2video"))
52 name =
"mpeg2_" + CodecName;
53 const AVCodec *codec = avcodec_find_decoder_by_name(name.toLocal8Bit());
55 if (!codec || !decoder)
58 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Failed to find %1").arg(name));
62 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Found FFmpeg decoder '%1'").arg(name));
64 decoder->CodecMap()->FreeCodecContext(Stream);
65 *Context = decoder->CodecMap()->GetCodecContext(Stream, *Codec);
66 (*Context)->pix_fmt =
Format;
71 const AVCodec **Codec,
98 if (codecname.isEmpty())
103 failure, codecname, AV_PIX_FMT_DRM_PRIME);
110 if (Context->pix_fmt != AV_PIX_FMT_DRM_PRIME)
114 if (
auto * player =
GetPlayerUI(Context); player !=
nullptr)
123 if (Context->pix_fmt == AV_PIX_FMT_DRM_PRIME)
125 DirectRendering =
false;
141 if (AvFrame->format == AV_PIX_FMT_DRM_PRIME)
148 while (*PixFmt != AV_PIX_FMT_NONE)
150 if (*PixFmt == AV_PIX_FMT_DRM_PRIME)
151 return AV_PIX_FMT_DRM_PRIME;
154 return AV_PIX_FMT_NONE;
159 if (!Context || !AvFrame || !
Frame)
162 if (
Frame->m_type !=
FMT_DRMPRIME ||
static_cast<AVPixelFormat
>(AvFrame->format) != AV_PIX_FMT_DRM_PRIME)
164 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Not a DRM PRIME buffer");
168 Frame->m_width = AvFrame->width;
169 Frame->m_height = AvFrame->height;
170 Frame->m_pixFmt = Context->pix_fmt;
171 Frame->m_swPixFmt = Context->sw_pix_fmt;
172 Frame->m_directRendering =
true;
173 AvFrame->opaque =
Frame;
174 AvFrame->reordered_opaque = Context->reordered_opaque;
177 Frame->m_buffer = AvFrame->data[0];
179 Frame->m_priv[0] =
reinterpret_cast<unsigned char*
>(av_buffer_ref(AvFrame->buf[0]));
190 static bool s_needscheck =
true;
191 static QVector<AVCodecID> s_supportedCodecs;
195 if (s_needscheck || Reinit)
197 s_needscheck =
false;
198 s_supportedCodecs.clear();
201 const AVCodec* codec =
nullptr;
202 void* opaque =
nullptr;
203 QStringList debugcodecs;
205 while ((codec = av_codec_iterate(&opaque)))
207 if (!av_codec_is_decoder(codec))
211 if (QString(codec->name).contains(
"v4l2m2m"))
214 const AVCodecHWConfig* config =
nullptr;
215 for (
int i = 0; (config = avcodec_get_hw_config(codec, i)); ++i)
217 if (config->pix_fmt != AV_PIX_FMT_DRM_PRIME)
222 if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL)
224 QStringList name = QString(codec->name).split(
"_", Qt::SkipEmptyParts);
227 if (!s_supportedCodecs.contains(codec->id))
229 s_supportedCodecs.append(codec->id);
230 debugcodecs.append(avcodec_get_name(codec->id));
236 if (debugcodecs.isEmpty())
237 debugcodecs.append(
"None");
238 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"DRM PRIME codecs supported: %1 %2")
239 .arg(debugcodecs.join(
","),
244 return !s_supportedCodecs.isEmpty();
245 return s_supportedCodecs.contains(Codec);