1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

qsv{dec,enc}: always use an internal mfxFrameSurface1

For encoding, this avoids modifying the input surface, which we are not
allowed to do.
This will also be useful in the following commits.

Signed-off-by: Maxym Dmytrychenko <maxym.dmytrychenko@intel.com>
This commit is contained in:
Anton Khirnov 2016-08-09 12:05:49 +02:00
parent e8bbacbf52
commit 404e51478e
3 changed files with 36 additions and 33 deletions

View File

@ -38,11 +38,10 @@
typedef struct QSVFrame {
AVFrame *frame;
mfxFrameSurface1 *surface;
mfxFrameSurface1 surface_internal;
mfxFrameSurface1 surface;
int queued;
int used;
struct QSVFrame *next;
} QSVFrame;

View File

@ -179,17 +179,17 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
return ret;
if (frame->frame->format == AV_PIX_FMT_QSV) {
frame->surface = (mfxFrameSurface1*)frame->frame->data[3];
frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
} else {
frame->surface_internal.Info = q->frame_info;
frame->surface.Info = q->frame_info;
frame->surface_internal.Data.PitchLow = frame->frame->linesize[0];
frame->surface_internal.Data.Y = frame->frame->data[0];
frame->surface_internal.Data.UV = frame->frame->data[1];
frame->surface = &frame->surface_internal;
frame->surface.Data.PitchLow = frame->frame->linesize[0];
frame->surface.Data.Y = frame->frame->data[0];
frame->surface.Data.UV = frame->frame->data[1];
}
frame->used = 1;
return 0;
}
@ -197,8 +197,8 @@ static void qsv_clear_unused_frames(QSVContext *q)
{
QSVFrame *cur = q->work_frames;
while (cur) {
if (cur->surface && !cur->surface->Data.Locked && !cur->queued) {
cur->surface = NULL;
if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
cur->used = 0;
av_frame_unref(cur->frame);
}
cur = cur->next;
@ -215,11 +215,11 @@ static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **
frame = q->work_frames;
last = &q->work_frames;
while (frame) {
if (!frame->surface) {
if (!frame->used) {
ret = alloc_frame(avctx, q, frame);
if (ret < 0)
return ret;
*surf = frame->surface;
*surf = &frame->surface;
return 0;
}
@ -241,7 +241,7 @@ static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **
if (ret < 0)
return ret;
*surf = frame->surface;
*surf = &frame->surface;
return 0;
}
@ -250,7 +250,7 @@ static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
{
QSVFrame *cur = q->work_frames;
while (cur) {
if (surf == cur->surface)
if (surf == &cur->surface)
return cur;
cur = cur->next;
}
@ -346,7 +346,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
if (ret < 0)
return ret;
outsurf = out_frame->surface;
outsurf = &out_frame->surface;
#if FF_API_PKT_PTS
FF_DISABLE_DEPRECATION_WARNINGS
@ -364,6 +364,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
frame->interlaced_frame =
!(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
/* update the surface properties */
if (avctx->pix_fmt == AV_PIX_FMT_QSV)
((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
*got_frame = 1;
}

View File

@ -813,9 +813,9 @@ static void clear_unused_frames(QSVEncContext *q)
{
QSVFrame *cur = q->work_frames;
while (cur) {
if (cur->surface && !cur->surface->Data.Locked) {
cur->surface = NULL;
if (cur->used && !cur->surface.Data.Locked) {
av_frame_unref(cur->frame);
cur->used = 0;
}
cur = cur->next;
}
@ -830,8 +830,9 @@ static int get_free_frame(QSVEncContext *q, QSVFrame **f)
frame = q->work_frames;
last = &q->work_frames;
while (frame) {
if (!frame->surface) {
if (!frame->used) {
*f = frame;
frame->used = 1;
return 0;
}
@ -850,6 +851,7 @@ static int get_free_frame(QSVEncContext *q, QSVFrame **f)
*last = frame;
*f = frame;
frame->used = 1;
return 0;
}
@ -869,7 +871,7 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame,
if (ret < 0)
return ret;
qf->surface = (mfxFrameSurface1*)qf->frame->data[3];
qf->surface = *(mfxFrameSurface1*)qf->frame->data[3];
} else {
/* make a copy if the input is not padded as libmfx requires */
if (frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) {
@ -893,29 +895,27 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame,
return ret;
}
qf->surface_internal.Info = q->param.mfx.FrameInfo;
qf->surface.Info = q->param.mfx.FrameInfo;
qf->surface_internal.Info.PicStruct =
qf->surface.Info.PicStruct =
!frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
MFX_PICSTRUCT_FIELD_BFF;
if (frame->repeat_pict == 1)
qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
else if (frame->repeat_pict == 2)
qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
else if (frame->repeat_pict == 4)
qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
qf->surface_internal.Data.PitchLow = qf->frame->linesize[0];
qf->surface_internal.Data.Y = qf->frame->data[0];
qf->surface_internal.Data.UV = qf->frame->data[1];
qf->surface = &qf->surface_internal;
qf->surface.Data.PitchLow = qf->frame->linesize[0];
qf->surface.Data.Y = qf->frame->data[0];
qf->surface.Data.UV = qf->frame->data[1];
}
qf->surface->Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, (AVRational){1, 90000});
qf->surface.Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, (AVRational){1, 90000});
*surface = qf->surface;
*surface = &qf->surface;
return 0;
}