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 static QRecursiveMutex lock;
205 static bool s_initialised =
false;
208 QMutexLocker locker(&lock);
211 s_initialised =
true;
213 if (__builtin_available(macOS 10.13, *))
224 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Unable to check hardware decode support. Assuming all.");
238 static QRecursiveMutex lock;
239 QMutexLocker locker(&lock);
240 static bool s_checked =
false;
241 static bool s_available =
false;
242 if (!s_checked || Reinit)
245 if (profiles.empty())
247 LOG(VB_GENERAL, LOG_INFO,
LOC +
"No VideoToolbox decoders found");
252 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Supported/available VideoToolbox decoders:");
256 LOG(VB_GENERAL, LOG_INFO,
LOC +
268 if (profiles.isEmpty())
272 Decoders.append(
"VideoToolbox:");
304 AVPixelFormat format = AV_PIX_FMT_NV12;
306 format = AV_PIX_FMT_P010;
310 auto *frames =
reinterpret_cast<AVHWFramesContext*
>(
m_framesContext->data);
311 if ((frames->sw_format == format) && (frames->width == Context->coded_width) &&
312 (frames->height == Context->coded_height))
326 AVBufferRef* framesref = av_hwframe_ctx_alloc(Context->hw_device_ctx);
327 auto *frames =
reinterpret_cast<AVHWFramesContext*
>(framesref->data);
329 frames->user_opaque =
nullptr;
330 frames->sw_format = format;
331 frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
332 frames->width = Context->coded_width;
333 frames->height = Context->coded_height;
334 if (av_hwframe_ctx_init(framesref) < 0)
336 av_buffer_unref(&framesref);
340 Context->hw_frames_ctx = framesref;