2013-08-14 13:47:18 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Stefano Pigozzi <stefano.pigozzi@gmail.com>
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libavcodec/version.h>
|
|
|
|
#include <libavcodec/vda.h>
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/av_common.h"
|
|
|
|
#include "common/msg.h"
|
2013-08-14 13:47:18 +00:00
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/decode/lavc.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-03-23 16:56:05 +00:00
|
|
|
|
|
|
|
static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
|
|
|
|
const char *decoder)
|
|
|
|
{
|
|
|
|
hwdec_request_api(info, "vda");
|
2015-04-11 15:17:52 +00:00
|
|
|
if (!info || !info->hwctx)
|
|
|
|
return HWDEC_ERR_NO_CTX;
|
2014-03-23 16:56:05 +00:00
|
|
|
if (mp_codec_to_av_codec_id(decoder) != AV_CODEC_ID_H264)
|
|
|
|
return HWDEC_ERR_NO_CODEC;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(struct lavc_ctx *ctx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-14 13:47:18 +00:00
|
|
|
struct vda_error {
|
|
|
|
int code;
|
|
|
|
char *reason;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct vda_error vda_errors[] = {
|
2014-08-01 07:16:42 +00:00
|
|
|
{ AVERROR(ENOSYS),
|
|
|
|
"Hardware doesn't support accelerated decoding for this stream" },
|
|
|
|
{ AVERROR(EINVAL),
|
2013-08-14 13:47:18 +00:00
|
|
|
"Invalid configuration provided to VDADecoderCreate" },
|
2014-08-01 07:16:42 +00:00
|
|
|
{ AVERROR_INVALIDDATA,
|
2013-08-14 13:47:18 +00:00
|
|
|
"Generic error returned by the decoder layer. The cause can range from"
|
|
|
|
" VDADecoder finding errors in the bitstream to another application"
|
|
|
|
" using VDA at the moment. Only one application can use VDA at a"
|
|
|
|
" givent time." },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
2013-12-21 16:47:38 +00:00
|
|
|
static void print_vda_error(struct mp_log *log, int lev, char *message,
|
|
|
|
int error_code)
|
2013-08-14 13:47:18 +00:00
|
|
|
{
|
|
|
|
for (int n = 0; vda_errors[n].code < 0; n++)
|
|
|
|
if (vda_errors[n].code == error_code) {
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, lev, "%s: %s (%d)\n",
|
2013-12-22 00:44:19 +00:00
|
|
|
message, vda_errors[n].reason, error_code);
|
2013-08-14 13:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, lev, "%s: %d\n", message, error_code);
|
2013-08-14 13:47:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 07:16:42 +00:00
|
|
|
static int init_decoder(struct lavc_ctx *ctx, int fmt, int w, int h)
|
2013-08-14 13:47:18 +00:00
|
|
|
{
|
2014-08-01 07:16:42 +00:00
|
|
|
av_vda_default_free(ctx->avctx);
|
2015-04-11 15:17:52 +00:00
|
|
|
#if HAVE_VDA_DEFAULT_INIT2
|
|
|
|
AVVDAContext *vdactx = av_vda_alloc_context();
|
|
|
|
vdactx->cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
|
|
|
|
int err = av_vda_default_init2(ctx->avctx, vdactx);
|
|
|
|
#else
|
2014-08-01 07:16:42 +00:00
|
|
|
int err = av_vda_default_init(ctx->avctx);
|
2015-04-11 15:17:52 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-01 07:16:42 +00:00
|
|
|
if (err < 0) {
|
|
|
|
print_vda_error(ctx->log, MSGL_ERR, "failed to init VDA decoder", err);
|
2013-08-14 13:47:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-01 07:16:42 +00:00
|
|
|
static void uninit(struct lavc_ctx *ctx)
|
2013-08-14 13:47:18 +00:00
|
|
|
{
|
2014-08-01 07:16:42 +00:00
|
|
|
if (ctx->avctx)
|
|
|
|
av_vda_default_free(ctx->avctx);
|
2013-08-14 13:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct vd_lavc_hwdec mp_vd_lavc_vda = {
|
|
|
|
.type = HWDEC_VDA,
|
2014-03-16 08:21:21 +00:00
|
|
|
.image_format = IMGFMT_VDA,
|
2013-08-14 13:47:18 +00:00
|
|
|
.probe = probe,
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
2014-08-01 07:16:42 +00:00
|
|
|
.init_decoder = init_decoder,
|
2013-08-14 13:47:18 +00:00
|
|
|
};
|