qsvdec: make ff_qsv_map_pixfmt() return a MFX fourcc as well

Stop hardcoding NV12.

Also, move this function to the shared code, it will be used by the
encoder as well.
This commit is contained in:
Anton Khirnov 2016-06-22 11:41:26 +02:00
parent d20c118975
commit 536bb17e96
4 changed files with 17 additions and 15 deletions

View File

@ -89,6 +89,18 @@ int ff_qsv_error(int mfx_err)
} }
} }
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc)
{
switch (format) {
case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUVJ420P:
*fourcc = MFX_FOURCC_NV12;
return AV_PIX_FMT_NV12;
default:
return AVERROR(ENOSYS);
}
}
static int qsv_load_plugins(mfxSession session, const char *load_plugins, static int qsv_load_plugins(mfxSession session, const char *load_plugins,
void *logctx) void *logctx)
{ {

View File

@ -61,6 +61,8 @@ int ff_qsv_error(int mfx_err);
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id); int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,
const char *load_plugins); const char *load_plugins);

View File

@ -40,17 +40,6 @@
#include "qsv_internal.h" #include "qsv_internal.h"
#include "qsvdec.h" #include "qsvdec.h"
int ff_qsv_map_pixfmt(enum AVPixelFormat format)
{
switch (format) {
case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUVJ420P:
return AV_PIX_FMT_NV12;
default:
return AVERROR(ENOSYS);
}
}
static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session, static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
AVBufferRef *hw_frames_ref) AVBufferRef *hw_frames_ref)
{ {
@ -150,7 +139,7 @@ static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
param.mfx.FrameInfo.BitDepthLuma = 8; param.mfx.FrameInfo.BitDepthLuma = 8;
param.mfx.FrameInfo.BitDepthChroma = 8; param.mfx.FrameInfo.BitDepthChroma = 8;
param.mfx.FrameInfo.Shift = 0; param.mfx.FrameInfo.Shift = 0;
param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12; param.mfx.FrameInfo.FourCC = q->fourcc;
param.mfx.FrameInfo.Width = avctx->coded_width; param.mfx.FrameInfo.Width = avctx->coded_width;
param.mfx.FrameInfo.Height = avctx->coded_height; param.mfx.FrameInfo.Height = avctx->coded_height;
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420; param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
@ -463,7 +452,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
AV_PIX_FMT_NONE }; AV_PIX_FMT_NONE };
enum AVPixelFormat qsv_format; enum AVPixelFormat qsv_format;
qsv_format = ff_qsv_map_pixfmt(q->parser->format); qsv_format = ff_qsv_map_pixfmt(q->parser->format, &q->fourcc);
if (qsv_format < 0) { if (qsv_format < 0) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Only 8-bit YUV420 streams are supported.\n"); "Only 8-bit YUV420 streams are supported.\n");

View File

@ -56,6 +56,7 @@ typedef struct QSVContext {
AVCodecParserContext *parser; AVCodecParserContext *parser;
AVCodecContext *avctx_internal; AVCodecContext *avctx_internal;
enum AVPixelFormat orig_pix_fmt; enum AVPixelFormat orig_pix_fmt;
uint32_t fourcc;
// options set by the caller // options set by the caller
int async_depth; int async_depth;
@ -67,8 +68,6 @@ typedef struct QSVContext {
int nb_ext_buffers; int nb_ext_buffers;
} QSVContext; } QSVContext;
int ff_qsv_map_pixfmt(enum AVPixelFormat format);
int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
AVFrame *frame, int *got_frame, AVPacket *pkt); AVFrame *frame, int *got_frame, AVPacket *pkt);