vf_vavpp: remove dummy loop, unindent

This used a do-while loop, which runs only once, as replacement for a
cleanup goto. While this is ok, doing a goto directly is easier to
follow and is closer to idiomatic C. But mainly remove it so that the
indentation can be reduced.
This commit is contained in:
wm4 2015-06-01 01:34:00 +02:00
parent 4c20e45561
commit 8e010a500d
1 changed files with 57 additions and 47 deletions

View File

@ -130,37 +130,45 @@ static struct mp_image *render(struct vf_instance *vf, struct mp_image *in,
VASurfaceID in_id = va_surface_id(in);
if (!p->pipe.filters || in_id == VA_INVALID_ID)
return NULL;
struct mp_image *img = mp_image_pool_get(p->pool, IMGFMT_VAAPI, in->w, in->h);
if (!img)
return NULL;
enum {Begun = 1, Rendered = 2};
int state = 0;
do { // not a loop, just for break
bool need_end_picture = false;
bool success = false;
VASurfaceID id = va_surface_id(img);
if (id == VA_INVALID_ID)
break;
goto cleanup;
VAStatus status = vaBeginPicture(p->display, p->context, id);
if (!check_error(vf, status, "vaBeginPicture()"))
break;
state |= Begun;
goto cleanup;
need_end_picture = true;
VABufferID buffer = VA_INVALID_ID;
VAProcPipelineParameterBuffer *param = NULL;
status = vaCreateBuffer(p->display, p->context,
VAProcPipelineParameterBufferType,
sizeof(*param), 1, NULL, &buffer);
if (!check_error(vf, status, "vaCreateBuffer()"))
break;
goto cleanup;
status = vaMapBuffer(p->display, buffer, (void**)&param);
if (!check_error(vf, status, "vaMapBuffer()"))
break;
goto cleanup;
VAProcFilterParameterBufferDeinterlacing *filter_params;
status = vaMapBuffer(p->display, *(p->pipe.filters), (void**)&filter_params);
if (!check_error(vf, status, "vaMapBuffer()"))
break;
goto cleanup;
filter_params->flags = flags & VA_TOP_FIELD ? 0 : VA_DEINTERLACING_BOTTOM_FIELD;
if (!(in->fields & MP_IMGFIELD_TOP_FIRST))
filter_params->flags |= VA_DEINTERLACING_BOTTOM_FIELD_FIRST;
vaUnmapBuffer(p->display, *(p->pipe.filters));
param->surface = in_id;
@ -179,12 +187,14 @@ static struct mp_image *render(struct vf_instance *vf, struct mp_image *in,
status = vaRenderPicture(p->display, p->context, &buffer, 1);
if (!check_error(vf, status, "vaRenderPicture()"))
break;
state |= Rendered;
} while (false);
if (state & Begun)
goto cleanup;
success = true;
cleanup:
if (need_end_picture)
vaEndPicture(p->display, p->context);
if (state & Rendered)
if (success)
return img;
talloc_free(img);
return NULL;