2 * Copyright © 2011 Intel Corporation
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
25 * Li Xiaowei <xiaowei.a.li@intel.com>
32 #include "intel_batchbuffer.h"
33 #include "intel_driver.h"
34 #include "i965_defines.h"
35 #include "i965_structs.h"
37 #include "i965_drv_video.h"
38 #include "i965_post_processing.h"
39 #include "gen75_picture_process.h"
42 i965_proc_picture(VADriverContextP ctx,
44 union codec_state *codec_state,
45 struct hw_context *hw_context);
47 extern struct hw_context *
48 i965_proc_context_init(VADriverContextP ctx,
49 struct object_config *obj_config);
52 gen75_vpp_fmt_cvt(VADriverContextP ctx,
54 union codec_state *codec_state,
55 struct hw_context *hw_context)
57 VAStatus va_status = VA_STATUS_SUCCESS;
58 struct intel_video_process_context *proc_ctx =
59 (struct intel_video_process_context *)hw_context;
61 /* implicity surface format coversion and scaling */
62 if(proc_ctx->vpp_fmt_cvt_ctx == NULL){
63 proc_ctx->vpp_fmt_cvt_ctx = i965_proc_context_init(ctx, NULL);
66 i965_proc_picture(ctx, profile, codec_state,
67 proc_ctx->vpp_fmt_cvt_ctx);
73 gen75_vpp_vebox(VADriverContextP ctx,
74 struct intel_video_process_context* proc_ctx)
76 VAStatus va_status = VA_STATUS_SUCCESS;
77 VAProcPipelineParameterBuffer* pipeline_param = proc_ctx->pipeline_param;
79 /* vpp features based on VEBox fixed function */
80 if(proc_ctx->vpp_vebox_ctx == NULL) {
81 proc_ctx->vpp_vebox_ctx = gen75_vebox_context_init(ctx);
84 proc_ctx->vpp_vebox_ctx->pipeline_param = pipeline_param;
85 proc_ctx->vpp_vebox_ctx->surface_input_object = proc_ctx->surface_pipeline_input_object;
86 proc_ctx->vpp_vebox_ctx->surface_output_object = proc_ctx->surface_render_output_object;
88 va_status = gen75_vebox_process_picture(ctx, proc_ctx->vpp_vebox_ctx);
94 gen75_vpp_gpe(VADriverContextP ctx,
95 struct intel_video_process_context* proc_ctx)
97 VAStatus va_status = VA_STATUS_SUCCESS;
99 if(proc_ctx->vpp_gpe_ctx == NULL){
100 proc_ctx->vpp_gpe_ctx = gen75_gpe_context_init(ctx);
103 proc_ctx->vpp_gpe_ctx->pipeline_param = proc_ctx->pipeline_param;
104 proc_ctx->vpp_gpe_ctx->surface_pipeline_input_object = proc_ctx->surface_pipeline_input_object;
105 proc_ctx->vpp_gpe_ctx->surface_output_object = proc_ctx->surface_render_output_object;
107 va_status = gen75_gpe_process_picture(ctx, proc_ctx->vpp_gpe_ctx);
113 gen75_proc_picture(VADriverContextP ctx,
115 union codec_state *codec_state,
116 struct hw_context *hw_context)
118 struct i965_driver_data *i965 = i965_driver_data(ctx);
119 struct proc_state* proc_st = &(codec_state->proc);
120 struct intel_video_process_context *proc_ctx =
121 (struct intel_video_process_context *)hw_context;
122 VAProcPipelineParameterBuffer *pipeline_param =
123 (VAProcPipelineParameterBuffer *)proc_st->pipeline_param->buffer;
124 struct object_surface *obj_dst_surf = NULL;
125 struct object_surface *obj_src_surf = NULL;
128 proc_ctx->pipeline_param = pipeline_param;
130 if (proc_st->current_render_target == VA_INVALID_SURFACE ||
131 pipeline_param->surface == VA_INVALID_SURFACE) {
132 status = VA_STATUS_ERROR_INVALID_SURFACE;
136 obj_dst_surf = SURFACE(proc_st->current_render_target);
139 status = VA_STATUS_ERROR_INVALID_SURFACE;
143 obj_src_surf = SURFACE(proc_ctx->pipeline_param->surface);
146 status = VA_STATUS_ERROR_INVALID_SURFACE;
150 if (!obj_src_surf->bo) {
151 status = VA_STATUS_ERROR_INVALID_VALUE; /* The input surface is created without valid content */
155 if (pipeline_param->num_filters && !pipeline_param->filters) {
156 status = VA_STATUS_ERROR_INVALID_PARAMETER;
160 if (!obj_dst_surf->bo) {
161 unsigned int is_tiled = 0;
162 unsigned int fourcc = VA_FOURCC('N','V','1','2');
163 int sampling = SUBSAMPLE_YUV420;
164 i965_check_alloc_surface_bo(ctx, obj_dst_surf, is_tiled, fourcc, sampling);
167 proc_ctx->surface_render_output_object = obj_dst_surf;
168 proc_ctx->surface_pipeline_input_object = obj_src_surf;
169 assert(pipeline_param->num_filters <= 4);
171 VABufferID *filter_id = (VABufferID*) pipeline_param->filters;
173 if(pipeline_param->num_filters == 0 || pipeline_param->filters == NULL ){
174 /* implicity surface format coversion and scaling */
175 gen75_vpp_fmt_cvt(ctx, profile, codec_state, hw_context);
176 }else if(pipeline_param->num_filters == 1) {
177 struct object_buffer * obj_buf = BUFFER((*filter_id) + 0);
179 assert(obj_buf && obj_buf->buffer_store && obj_buf->buffer_store->buffer);
182 !obj_buf->buffer_store ||
183 !obj_buf->buffer_store->buffer) {
184 status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
188 VAProcFilterParameterBuffer* filter =
189 (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
191 if (filter->type == VAProcFilterNoiseReduction ||
192 filter->type == VAProcFilterDeinterlacing ||
193 filter->type == VAProcFilterColorBalance){
194 gen75_vpp_vebox(ctx, proc_ctx);
195 }else if(filter->type == VAProcFilterSharpening){
196 if (obj_src_surf->fourcc != VA_FOURCC('N', 'V', '1', '2') ||
197 obj_dst_surf->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
198 status = VA_STATUS_ERROR_UNIMPLEMENTED;
202 gen75_vpp_gpe(ctx, proc_ctx);
204 }else if (pipeline_param->num_filters >= 2) {
206 for (i = 0; i < pipeline_param->num_filters; i++){
207 struct object_buffer * obj_buf = BUFFER(pipeline_param->filters[i]);
210 !obj_buf->buffer_store ||
211 !obj_buf->buffer_store->buffer) {
212 status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
216 VAProcFilterParameterBuffer* filter =
217 (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
219 if (filter->type != VAProcFilterNoiseReduction &&
220 filter->type != VAProcFilterDeinterlacing &&
221 filter->type != VAProcFilterColorBalance) {
222 printf("Do not support multiply filters outside vebox pipeline \n");
226 gen75_vpp_vebox(ctx, proc_ctx);
229 return VA_STATUS_SUCCESS;
236 gen75_proc_context_destroy(void *hw_context)
238 struct intel_video_process_context *proc_ctx =
239 (struct intel_video_process_context *)hw_context;
240 VADriverContextP ctx = (VADriverContextP)(proc_ctx->driver_context);
242 if(proc_ctx->vpp_fmt_cvt_ctx){
243 proc_ctx->vpp_fmt_cvt_ctx->destroy(proc_ctx->vpp_fmt_cvt_ctx);
244 proc_ctx->vpp_fmt_cvt_ctx = NULL;
247 if(proc_ctx->vpp_vebox_ctx){
248 gen75_vebox_context_destroy(ctx,proc_ctx->vpp_vebox_ctx);
249 proc_ctx->vpp_vebox_ctx = NULL;
252 if(proc_ctx->vpp_gpe_ctx){
253 gen75_gpe_context_destroy(ctx,proc_ctx->vpp_gpe_ctx);
254 proc_ctx->vpp_gpe_ctx = NULL;
261 gen75_proc_context_init(VADriverContextP ctx,
262 struct object_config *obj_config)
264 struct intel_video_process_context *proc_context
265 = calloc(1, sizeof(struct intel_video_process_context));
267 proc_context->base.destroy = gen75_proc_context_destroy;
268 proc_context->base.run = gen75_proc_picture;
270 proc_context->vpp_vebox_ctx = NULL;
271 proc_context->vpp_gpe_ctx = NULL;
272 proc_context->vpp_fmt_cvt_ctx = NULL;
274 proc_context->driver_context = ctx;
276 return (struct hw_context *)proc_context;