16 #include "libavutil/hwcontext_videotoolbox.h"
17 #include "libavcodec/videotoolbox.h"
18 #include "libavutil/pixdesc.h"
21 #define LOC QString("VTBDec: ")
38 Context->slice_flags = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
39 DirectRendering =
false;
48 if (AvFrame->format != AV_PIX_FMT_VIDEOTOOLBOX)
64 Context->hw_device_ctx = device;
77 const AVCodec ** Codec,
81 bool decodeonly =
Decoder ==
"vtb-dec";
111 QString codec = avcodec_get_name((*Context)->codec_id);
112 QString
profile = avcodec_profile_name((*Context)->codec_id, (*Context)->profile);
113 QString pixfmt = av_get_pix_fmt_name((*Context)->pix_fmt);
116 if (!profiles.contains(mythprofile))
118 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"VideoToolbox does not support decoding '%1 %2 %3'")
119 .arg(codec).arg(
profile).arg(pixfmt));
125 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"VideoToolbox MAY support decoding '%1 %2 %3'")
126 .arg(codec).arg(
profile).arg(pixfmt));
127 (*Context)->pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX;
154 auto * deviceref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VIDEOTOOLBOX);
157 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create device context");
163 auto * devicectx =
reinterpret_cast<AVHWDeviceContext*
>(deviceref->data);
164 devicectx->user_opaque = interop;
168 if (av_hwdevice_ctx_init(deviceref) < 0)
170 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to initialise device context");
171 av_buffer_unref(&deviceref);
175 Context->hw_device_ctx = deviceref;
176 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Created hw device '%1'")
177 .arg(av_hwdevice_get_type_name(AV_HWDEVICE_TYPE_VIDEOTOOLBOX)));
183 enum AVPixelFormat ret = AV_PIX_FMT_NONE;
184 while (*PixFmt != AV_PIX_FMT_NONE)
186 if (*PixFmt == AV_PIX_FMT_VIDEOTOOLBOX)
191 auto* me =
dynamic_cast<MythVTBContext*
>(decoder->GetMythCodecContext());
204 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
205 static QMutex lock(QMutex::Recursive);
207 static QRecursiveMutex lock;
209 static bool s_initialised =
false;
212 QMutexLocker locker(&lock);
215 s_initialised =
true;
217 if (__builtin_available(macOS 10.13, *))
228 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Unable to check hardware decode support. Assuming all.");
242 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
243 static QMutex lock(QMutex::Recursive);
245 static QRecursiveMutex lock;
247 QMutexLocker locker(&lock);
248 static bool s_checked =
false;
249 static bool s_available =
false;
250 if (!s_checked || Reinit)
253 if (profiles.empty())
255 LOG(VB_GENERAL, LOG_INFO,
LOC +
"No VideoToolbox decoders found");
260 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Supported/available VideoToolbox decoders:");
264 LOG(VB_GENERAL, LOG_INFO,
LOC +
276 if (profiles.isEmpty())
280 Decoders.append(
"VideoToolbox:");
312 AVPixelFormat format = AV_PIX_FMT_NV12;
314 format = AV_PIX_FMT_P010;
318 auto *frames =
reinterpret_cast<AVHWFramesContext*
>(
m_framesContext->data);
319 if ((frames->sw_format == format) && (frames->width == Context->coded_width) &&
320 (frames->height == Context->coded_height))
332 av_videotoolbox_default_free(Context);
335 AVBufferRef* framesref = av_hwframe_ctx_alloc(Context->hw_device_ctx);
336 auto *frames =
reinterpret_cast<AVHWFramesContext*
>(framesref->data);
338 frames->user_opaque =
nullptr;
339 frames->sw_format = format;
340 frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
341 frames->width = Context->coded_width;
342 frames->height = Context->coded_height;
343 if (av_hwframe_ctx_init(framesref) < 0)
345 av_buffer_unref(&framesref);
349 Context->hw_frames_ctx = framesref;