summaryrefslogtreecommitdiffstats
path: root/video/filter
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-01 01:34:00 +0200
committerwm4 <wm4@nowhere>2015-06-01 01:34:00 +0200
commit8e010a500d4e7d74249606ee130f9e29d373fc5b (patch)
tree8106b394eae0a95ef6f102de1adb749116f855f2 /video/filter
parent4c20e45561817dfe13634289161da11cf85e560e (diff)
downloadmpv-8e010a500d4e7d74249606ee130f9e29d373fc5b.tar.bz2
mpv-8e010a500d4e7d74249606ee130f9e29d373fc5b.tar.xz
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.
Diffstat (limited to 'video/filter')
-rw-r--r--video/filter/vf_vavpp.c112
1 files changed, 61 insertions, 51 deletions
diff --git a/video/filter/vf_vavpp.c b/video/filter/vf_vavpp.c
index 5c9fcf3bbc..c8b3bfdf25 100644
--- a/video/filter/vf_vavpp.c
+++ b/video/filter/vf_vavpp.c
@@ -130,61 +130,71 @@ 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
- VASurfaceID id = va_surface_id(img);
- if (id == VA_INVALID_ID)
- break;
- VAStatus status = vaBeginPicture(p->display, p->context, id);
- if (!check_error(vf, status, "vaBeginPicture()"))
- break;
- state |= Begun;
- 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;
- status = vaMapBuffer(p->display, buffer, (void**)&param);
- if (!check_error(vf, status, "vaMapBuffer()"))
- break;
-
- VAProcFilterParameterBufferDeinterlacing *filter_params;
- status = vaMapBuffer(p->display, *(p->pipe.filters), (void**)&filter_params);
- if (!check_error(vf, status, "vaMapBuffer()"))
- break;
- 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;
- param->surface_region = NULL;
- param->output_region = NULL;
- param->output_background_color = 0;
- param->filter_flags = flags;
- param->filters = p->pipe.filters;
- param->num_filters = p->pipe.num_filters;
- param->forward_references = p->pipe.forward.surfaces;
- param->backward_references = p->pipe.backward.surfaces;
- param->num_forward_references = 0;
- param->num_backward_references = 0;
-
- vaUnmapBuffer(p->display, buffer);
-
- status = vaRenderPicture(p->display, p->context, &buffer, 1);
- if (!check_error(vf, status, "vaRenderPicture()"))
- break;
- state |= Rendered;
- } while (false);
- if (state & Begun)
+
+ bool need_end_picture = false;
+ bool success = false;
+
+ VASurfaceID id = va_surface_id(img);
+ if (id == VA_INVALID_ID)
+ goto cleanup;
+
+ VAStatus status = vaBeginPicture(p->display, p->context, id);
+ if (!check_error(vf, status, "vaBeginPicture()"))
+ 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()"))
+ goto cleanup;
+
+ status = vaMapBuffer(p->display, buffer, (void**)&param);
+ if (!check_error(vf, status, "vaMapBuffer()"))
+ goto cleanup;
+
+ VAProcFilterParameterBufferDeinterlacing *filter_params;
+ status = vaMapBuffer(p->display, *(p->pipe.filters), (void**)&filter_params);
+ if (!check_error(vf, status, "vaMapBuffer()"))
+ 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;
+ param->surface_region = NULL;
+ param->output_region = NULL;
+ param->output_background_color = 0;
+ param->filter_flags = flags;
+ param->filters = p->pipe.filters;
+ param->num_filters = p->pipe.num_filters;
+ param->forward_references = p->pipe.forward.surfaces;
+ param->backward_references = p->pipe.backward.surfaces;
+ param->num_forward_references = 0;
+ param->num_backward_references = 0;
+
+ vaUnmapBuffer(p->display, buffer);
+
+ status = vaRenderPicture(p->display, p->context, &buffer, 1);
+ if (!check_error(vf, status, "vaRenderPicture()"))
+ 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;