i965_drv_video: improved MV quality for VME
[platform/upstream/libva.git] / i965_drv_video / i965_encoder.c
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Zhou Chang <chang.zhou@intel.com>
26  *
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <assert.h>
33
34 #include <va/va_backend.h>
35
36 #include "intel_batchbuffer.h"
37 #include "intel_driver.h"
38
39 #include "i965_defines.h"
40 #include "i965_drv_video.h"
41 #include "i965_encoder.h"
42
43 static void 
44 gen6_encoder_end_picture(VADriverContextP ctx, 
45                          VAProfile profile, 
46                          union codec_state *codec_state,
47                          struct hw_context *hw_context)
48 {
49     struct gen6_encoder_context *gen6_encoder_context = (struct gen6_encoder_context *)hw_context;
50     struct encode_state *encode_state = &codec_state->enc;
51     VAStatus vaStatus;
52
53     vaStatus = gen6_vme_pipeline(ctx, profile, encode_state, gen6_encoder_context);
54
55     if (vaStatus == VA_STATUS_SUCCESS)
56         gen6_mfc_pipeline(ctx, profile, encode_state, gen6_encoder_context);
57 }
58 static void
59 gen6_encoder_context_destroy(void *hw_context)
60 {
61     struct gen6_encoder_context *gen6_encoder_context = (struct gen6_encoder_context *)hw_context;
62
63     gen6_mfc_context_destroy(&gen6_encoder_context->mfc_context);
64     gen6_vme_context_destroy(&gen6_encoder_context->vme_context);
65     intel_batchbuffer_free(gen6_encoder_context->base.batch);
66     free(gen6_encoder_context);
67 }
68
69 struct hw_context *
70 gen6_enc_hw_context_init(VADriverContextP ctx, VAProfile profile)
71 {
72     struct intel_driver_data *intel = intel_driver_data(ctx);
73     struct gen6_encoder_context *gen6_encoder_context = calloc(1, sizeof(struct gen6_encoder_context));
74
75     gen6_encoder_context->base.destroy = gen6_encoder_context_destroy;
76     gen6_encoder_context->base.run = gen6_encoder_end_picture;
77     gen6_encoder_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
78
79     gen6_vme_context_init(ctx, &gen6_encoder_context->vme_context);
80     gen6_mfc_context_init(ctx, &gen6_encoder_context->mfc_context);
81
82     return (struct hw_context *)gen6_encoder_context;
83 }