Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2011 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.  *   Li Xiaowei <xiaowei.a.li@intel.com>
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <assert.h>
  31.  
  32. #include "intel_batchbuffer.h"
  33. #include "intel_driver.h"
  34. #include "i965_defines.h"
  35. #include "i965_structs.h"
  36.  
  37. #include "i965_drv_video.h"
  38. #include "i965_post_processing.h"
  39. #include "gen75_picture_process.h"
  40.  
  41. extern struct hw_context *
  42. i965_proc_context_init(VADriverContextP ctx,
  43.                        struct object_config *obj_config);
  44.  
  45. static VAStatus
  46. gen75_vpp_fmt_cvt(VADriverContextP ctx,
  47.                   VAProfile profile,
  48.                   union codec_state *codec_state,
  49.                   struct hw_context *hw_context)
  50. {
  51.     VAStatus va_status = VA_STATUS_SUCCESS;
  52.     struct intel_video_process_context *proc_ctx =
  53.              (struct intel_video_process_context *)hw_context;
  54.  
  55.     /* implicity surface format coversion and scaling */
  56.     if(proc_ctx->vpp_fmt_cvt_ctx == NULL){
  57.          proc_ctx->vpp_fmt_cvt_ctx = i965_proc_context_init(ctx, NULL);
  58.     }
  59.  
  60.     va_status = i965_proc_picture(ctx, profile, codec_state,
  61.                                   proc_ctx->vpp_fmt_cvt_ctx);
  62.  
  63.     return va_status;
  64. }
  65.  
  66. static VAStatus
  67. gen75_vpp_vebox(VADriverContextP ctx,
  68.                 struct intel_video_process_context* proc_ctx)
  69. {
  70.      VAStatus va_status = VA_STATUS_SUCCESS;
  71.      VAProcPipelineParameterBuffer* pipeline_param = proc_ctx->pipeline_param;
  72.      struct i965_driver_data *i965 = i965_driver_data(ctx);
  73.  
  74.      /* vpp features based on VEBox fixed function */
  75.      if(proc_ctx->vpp_vebox_ctx == NULL) {
  76.          proc_ctx->vpp_vebox_ctx = gen75_vebox_context_init(ctx);
  77.      }
  78.  
  79.      proc_ctx->vpp_vebox_ctx->pipeline_param  = pipeline_param;
  80.      proc_ctx->vpp_vebox_ctx->surface_input_object = proc_ctx->surface_pipeline_input_object;
  81.      proc_ctx->vpp_vebox_ctx->surface_output_object  = proc_ctx->surface_render_output_object;
  82.  
  83.      if (IS_HASWELL(i965->intel.device_info))
  84.          va_status = gen75_vebox_process_picture(ctx, proc_ctx->vpp_vebox_ctx);
  85.      else if (IS_GEN8(i965->intel.device_info))
  86.          va_status = gen8_vebox_process_picture(ctx, proc_ctx->vpp_vebox_ctx);
  87.      else if (IS_GEN9(i965->intel.device_info))
  88.          va_status = gen9_vebox_process_picture(ctx, proc_ctx->vpp_vebox_ctx);
  89.  
  90.      return va_status;
  91. }
  92.  
  93. static VAStatus
  94. gen75_vpp_gpe(VADriverContextP ctx,
  95.               struct intel_video_process_context* proc_ctx)
  96. {
  97.      VAStatus va_status = VA_STATUS_SUCCESS;
  98.  
  99.      if(proc_ctx->vpp_gpe_ctx == NULL){
  100.          proc_ctx->vpp_gpe_ctx = vpp_gpe_context_init(ctx);
  101.      }
  102.    
  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;
  106.  
  107.      va_status = vpp_gpe_process_picture(ctx, proc_ctx->vpp_gpe_ctx);
  108.  
  109.      return va_status;    
  110. }
  111.  
  112. VAStatus
  113. gen75_proc_picture(VADriverContextP ctx,
  114.                    VAProfile profile,
  115.                    union codec_state *codec_state,
  116.                    struct hw_context *hw_context)
  117. {
  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;
  126.     VAStatus status;
  127.  
  128.     proc_ctx->pipeline_param = pipeline_param;
  129.  
  130.     if (proc_st->current_render_target == VA_INVALID_SURFACE ||
  131.         pipeline_param->surface == VA_INVALID_SURFACE) {
  132.         status = VA_STATUS_ERROR_INVALID_SURFACE;
  133.         goto error;
  134.     }
  135.  
  136.     obj_dst_surf = SURFACE(proc_st->current_render_target);
  137.  
  138.     if (!obj_dst_surf) {
  139.         status = VA_STATUS_ERROR_INVALID_SURFACE;
  140.         goto error;
  141.     }
  142.  
  143.     obj_src_surf = SURFACE(proc_ctx->pipeline_param->surface);
  144.  
  145.     if (!obj_src_surf) {
  146.         status = VA_STATUS_ERROR_INVALID_SURFACE;
  147.         goto error;
  148.     }
  149.  
  150.     if (!obj_src_surf->bo) {
  151.         status = VA_STATUS_ERROR_INVALID_VALUE; /* The input surface is created without valid content */
  152.         goto error;
  153.     }
  154.  
  155.     if (pipeline_param->num_filters && !pipeline_param->filters) {
  156.         status = VA_STATUS_ERROR_INVALID_PARAMETER;
  157.         goto error;
  158.     }
  159.  
  160.     if (!obj_dst_surf->bo) {
  161.         unsigned int is_tiled = 1;
  162.         unsigned int fourcc = VA_FOURCC_NV12;
  163.         int sampling = SUBSAMPLE_YUV420;
  164.         i965_check_alloc_surface_bo(ctx, obj_dst_surf, is_tiled, fourcc, sampling);
  165.     }  
  166.  
  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);
  170.  
  171.     VABufferID *filter_id = (VABufferID*) pipeline_param->filters;
  172.  
  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);
  178.  
  179.        assert(obj_buf && obj_buf->buffer_store && obj_buf->buffer_store->buffer);
  180.        
  181.        if (!obj_buf ||
  182.            !obj_buf->buffer_store ||
  183.            !obj_buf->buffer_store->buffer) {
  184.            status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
  185.            goto error;
  186.        }
  187.  
  188.        VAProcFilterParameterBuffer* filter =
  189.            (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
  190.  
  191.        if (filter->type == VAProcFilterNoiseReduction         ||
  192.            filter->type == VAProcFilterDeinterlacing          ||
  193.            filter->type == VAProcFilterSkinToneEnhancement    ||
  194.            filter->type == VAProcFilterColorBalance){
  195.            gen75_vpp_vebox(ctx, proc_ctx);
  196.        }else if(filter->type == VAProcFilterSharpening){
  197.            if (obj_src_surf->fourcc != VA_FOURCC_NV12 ||
  198.                obj_dst_surf->fourcc != VA_FOURCC_NV12) {
  199.                status = VA_STATUS_ERROR_UNIMPLEMENTED;
  200.                goto error;
  201.            }
  202.  
  203.            gen75_vpp_gpe(ctx, proc_ctx);
  204.        }
  205.     }else if (pipeline_param->num_filters >= 2) {
  206.          unsigned int i = 0;
  207.          for (i = 0; i < pipeline_param->num_filters; i++){
  208.              struct object_buffer * obj_buf = BUFFER(pipeline_param->filters[i]);
  209.  
  210.              if (!obj_buf ||
  211.                  !obj_buf->buffer_store ||
  212.                  !obj_buf->buffer_store->buffer) {
  213.                  status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
  214.                  goto error;
  215.              }
  216.  
  217.              VAProcFilterParameterBuffer* filter =
  218.                  (VAProcFilterParameterBuffer*)obj_buf-> buffer_store->buffer;
  219.  
  220.              if (filter->type != VAProcFilterNoiseReduction       &&
  221.                  filter->type != VAProcFilterDeinterlacing        &&
  222.                  filter->type != VAProcFilterSkinToneEnhancement  &&
  223.                  filter->type != VAProcFilterColorBalance) {
  224.                  fprintf(stderr, "Do not support multiply filters outside vebox pipeline \n");
  225.                  assert(0);
  226.              }
  227.          }
  228.          gen75_vpp_vebox(ctx, proc_ctx);
  229.     }    
  230.  
  231.     return VA_STATUS_SUCCESS;
  232.  
  233. error:
  234.     return status;
  235. }
  236.  
  237. static void
  238. gen75_proc_context_destroy(void *hw_context)
  239. {
  240.     struct intel_video_process_context *proc_ctx =
  241.                       (struct intel_video_process_context *)hw_context;
  242.     VADriverContextP ctx = (VADriverContextP)(proc_ctx->driver_context);
  243.  
  244.     if(proc_ctx->vpp_fmt_cvt_ctx){
  245.         proc_ctx->vpp_fmt_cvt_ctx->destroy(proc_ctx->vpp_fmt_cvt_ctx);
  246.         proc_ctx->vpp_fmt_cvt_ctx = NULL;
  247.     }
  248.  
  249.     if(proc_ctx->vpp_vebox_ctx){
  250.        gen75_vebox_context_destroy(ctx,proc_ctx->vpp_vebox_ctx);
  251.        proc_ctx->vpp_vebox_ctx = NULL;
  252.     }
  253.  
  254.     if(proc_ctx->vpp_gpe_ctx){
  255.        vpp_gpe_context_destroy(ctx,proc_ctx->vpp_gpe_ctx);
  256.        proc_ctx->vpp_gpe_ctx = NULL;
  257.     }
  258.  
  259.     free(proc_ctx);
  260. }
  261.  
  262. struct hw_context *
  263. gen75_proc_context_init(VADriverContextP ctx,
  264.                         struct object_config *obj_config)
  265. {
  266.    struct intel_video_process_context *proc_context
  267.            = calloc(1, sizeof(struct intel_video_process_context));
  268.  
  269.     assert(proc_context);
  270.     proc_context->base.destroy = gen75_proc_context_destroy;
  271.     proc_context->base.run     = gen75_proc_picture;
  272.  
  273.     proc_context->vpp_vebox_ctx    = NULL;
  274.     proc_context->vpp_gpe_ctx      = NULL;
  275.     proc_context->vpp_fmt_cvt_ctx  = NULL;
  276.  
  277.     proc_context->driver_context = ctx;
  278.  
  279.     return (struct hw_context *)proc_context;
  280. }
  281.  
  282.