[Libva] [PATCH] JPEG Encode: Added support for UYVY/YUY2/Y8 Input formats

Muppavarapu, Sirisha sirisha.muppavarapu at intel.com
Tue Dec 9 20:57:28 PST 2014


Thanks for your inputs Emil. Feedback noted.

-Sirisha

-----Original Message-----
From: Emil Velikov [mailto:emil.l.velikov at gmail.com] 
Sent: Tuesday, December 09, 2014 1:43 PM
To: Muppavarapu, Sirisha; libva at lists.freedesktop.org
Cc: emil.l.velikov at gmail.com
Subject: Re: [Libva] [PATCH] JPEG Encode: Added support for UYVY/YUY2/Y8 Input formats

Hi Sirisha,

Admittedly I'm not a va developer, despite an occasional patch that I've sent, so pardon my noobish question.

Afaics this patch does following
 - Promotes jpeg_{luma,chroma}_quant to static const.
 - Reworks slightly intel_encoder_sanity_check_input.
 - Kills off some white space.
 - Drops a print statement.
 - Adds the mentioned UYVY/YUY2/Y8 support.

Maybe split the patch a bit ? I'm guessing that an actual commit message won't be too bad either :)

Thanks
Emil

On 09/12/14 21:07, Sirisha Muppavarapu wrote:
> ---
>  src/gen8_mfc.c         |  11 ++--
>  src/i965_device_info.c |   2 +-
>  src/i965_encoder.c     | 147 ++++++++++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 147 insertions(+), 13 deletions(-)
> 
> diff --git a/src/gen8_mfc.c b/src/gen8_mfc.c index ca37b06..b596020 
> 100644
> --- a/src/gen8_mfc.c
> +++ b/src/gen8_mfc.c
> @@ -70,7 +70,7 @@ static const uint32_t zigzag_direct[64] = {
>  
>  //Default Luminance quantization table
>  //Source: Jpeg Spec ISO/IEC 10918-1, Annex K, Table K.1 -uint8_t 
> jpeg_luma_quant[64] = {
> +static const uint8_t jpeg_luma_quant[64] = {
>      16, 11, 10, 16, 24,  40,  51,  61,
>      12, 12, 14, 19, 26,  58,  60,  55,
>      14, 13, 16, 24, 40,  57,  69,  56, @@ -83,7 +83,7 @@ uint8_t 
> jpeg_luma_quant[64] = {
>  
>  //Default Chroma quantization table
>  //Source: Jpeg Spec ISO/IEC 10918-1, Annex K, Table K.2 -uint8_t 
> jpeg_chroma_quant[64] = {
> +static const uint8_t jpeg_chroma_quant[64] = {
>      17, 18, 24, 47, 99, 99, 99, 99,
>      18, 21, 26, 66, 99, 99, 99, 99,
>      24, 26, 56, 99, 99, 99, 99, 99,
> @@ -2498,7 +2498,8 @@ gen8_mfc_jpeg_set_surface_state(VADriverContextP ctx,
>              surface_format = MFX_SURFACE_YCRCB_NORMAL;
>              break;
>          }
> -        case VA_FOURCC_RGBA: { 
> +        case VA_FOURCC_RGBA:  
> +        case VA_FOURCC_444P: {
>              surface_format = MFX_SURFACE_R8G8B8A8_UNORM;
>              break;
>          }
> @@ -2576,6 +2577,8 @@ gen8_mfc_jpeg_pic_state(VADriverContextP ctx,
>              output_mcu_format = JPEG_ENC_MCU_YUV422H_2Y; 
>              break;
>          }
> +
> +        case VA_FOURCC_RGBA: 
>          case VA_FOURCC_444P: { 
>              input_surface_format = JPEG_ENC_SURFACE_RGB; 
>              output_mcu_format = JPEG_ENC_MCU_RGB; @@ -2703,7 +2706,6 
> @@ gen8_mfc_jpeg_fqm_state(VADriverContextP ctx,
>  
>      } else {
>          //If the app doesnt send the qmatrix, use the buffered/default qmatrix
> -        printf("App didnt send any qmatrix, using default....\n");
>          qmatrix = &mfc_context->buffered_qmatrix;
>          qmatrix->load_lum_quantiser_matrix = 1;
>          qmatrix->load_chroma_quantiser_matrix = 
> (pic_param->num_components > 1) ? 1 : 0; @@ -2978,6 +2980,7 @@ static void get_Y_sampling_factors(uint32_t surface_format, uint8_t *h_factor, u
>              (* v_factor) = 1;
>              break;
>          }
> +        case VA_FOURCC_RGBA: 
>          case VA_FOURCC_444P: { 
>              (* h_factor) = 1; 
>              (* v_factor) = 1;
> diff --git a/src/i965_device_info.c b/src/i965_device_info.c index 
> 9547360..52d6f37 100755
> --- a/src/i965_device_info.c
> +++ b/src/i965_device_info.c
> @@ -43,7 +43,7 @@
>  
>  /* Extra set of chroma formats supported for JPEG encoding (beyond 
> YUV 4:2:0) */  #define EXTRA_JPEG_ENC_CHROMA_FORMATS \
> -    (VA_RT_FORMAT_YUV400| VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444)     
> +    (VA_RT_FORMAT_YUV400| VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_RGB32)     
>       
>  /* Defines VA profile as a 32-bit unsigned integer mask */  #define 
> VA_PROFILE_MASK(PROFILE) \ diff --git a/src/i965_encoder.c 
> b/src/i965_encoder.c index e10f58d..a9bc8fa 100644
> --- a/src/i965_encoder.c
> +++ b/src/i965_encoder.c
> @@ -105,7 +105,7 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
>      encode_state->input_yuv_object = obj_surface;
>      assert(obj_surface);
>      i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
> -    
> +
>      dst_surface.base = (struct object_base *)obj_surface;
>      dst_surface.type = I965_SURFACE_TYPE_SURFACE;
>      dst_surface.flags = I965_SURFACE_FLAG_FRAME; @@ -122,6 +122,131 
> @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
>      return VA_STATUS_SUCCESS;
>  }
>  
> +
> +static VAStatus
> +intel_encoder_check_jpeg_yuv_surface(VADriverContextP ctx,
> +                                VAProfile profile,
> +                                struct encode_state *encode_state,
> +                                struct intel_encoder_context 
> +*encoder_context) {
> +    struct i965_driver_data *i965 = i965_driver_data(ctx);
> +    struct i965_surface src_surface, dst_surface;
> +    struct object_surface *obj_surface;
> +    VAStatus status;
> +    VARectangle rect;
> +    int format=0, fourcc=0, subsample=0;
> +
> +    /* releae the temporary surface */
> +    if (encoder_context->is_tmp_id) {
> +        i965_DestroySurfaces(ctx, &encoder_context->input_yuv_surface, 1);
> +        encode_state->input_yuv_object = NULL;
> +    }
> +
> +    encoder_context->is_tmp_id = 0;
> +    obj_surface = SURFACE(encode_state->current_render_target);
> +    assert(obj_surface && obj_surface->bo);
> +
> +    if (!obj_surface || !obj_surface->bo)
> +        return VA_STATUS_ERROR_INVALID_PARAMETER;
> +
> +    unsigned int tiling = 0, swizzle = 0;
> +
> +    dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
> +
> +    if (tiling == I915_TILING_Y) {
> +        if( (obj_surface->fourcc==VA_FOURCC_NV12)  || (obj_surface->fourcc==VA_FOURCC_UYVY) ||
> +            (obj_surface->fourcc==VA_FOURCC_YUY2)  || (obj_surface->fourcc==VA_FOURCC_Y800) ||
> +            (obj_surface->fourcc==VA_FOURCC_RGBA)  || (obj_surface->fourcc==VA_FOURCC_444P) ) { 
> +            encoder_context->input_yuv_surface = encode_state->current_render_target;
> +            encode_state->input_yuv_object = obj_surface;
> +            return VA_STATUS_SUCCESS;
> +        }
> +    }
> +
> +    rect.x = 0;
> +    rect.y = 0;
> +    rect.width = obj_surface->orig_width;
> +    rect.height = obj_surface->orig_height;
> +    
> +    src_surface.base = (struct object_base *)obj_surface;
> +    src_surface.type = I965_SURFACE_TYPE_SURFACE;
> +    src_surface.flags = I965_SURFACE_FLAG_FRAME;
> +    
> +    switch( obj_surface->fourcc) {
> +    
> +        case VA_FOURCC_YUY2:
> +            fourcc = VA_FOURCC_YUY2;
> +            format = VA_RT_FORMAT_YUV422;
> +            subsample = SUBSAMPLE_YUV422H;
> +            break;
> +
> +        case VA_FOURCC_UYVY:
> +            fourcc = VA_FOURCC_UYVY;
> +            format = VA_RT_FORMAT_YUV422;
> +            subsample = SUBSAMPLE_YUV422H;
> +            break;
> +
> +        case VA_FOURCC_Y800:
> +            fourcc = VA_FOURCC_Y800;
> +            format = VA_RT_FORMAT_YUV400;
> +            subsample = SUBSAMPLE_YUV400;
> +            break;
> +
> +        case VA_FOURCC_444P:
> +            fourcc = VA_FOURCC_444P;
> +            format = VA_RT_FORMAT_YUV444;
> +            subsample = SUBSAMPLE_YUV444;
> +            break;
> +
> +        case VA_FOURCC_RGBA:
> +            fourcc = VA_FOURCC_RGBA;
> +            format = VA_RT_FORMAT_RGB32;
> +            subsample = SUBSAMPLE_RGBX;
> +            break;
> +
> +        default: //All other scenarios will have NV12 format
> +            fourcc = VA_FOURCC_NV12;
> +            format = VA_RT_FORMAT_YUV420;
> +            subsample = SUBSAMPLE_YUV420;
> +            break;
> +    }
> +
> +    status = i965_CreateSurfaces(ctx,
> +                                 obj_surface->orig_width,
> +                                 obj_surface->orig_height,
> +                                 format,
> +                                 1,
> +                                 &encoder_context->input_yuv_surface);
> +    assert(status == VA_STATUS_SUCCESS);
> +
> +    if (status != VA_STATUS_SUCCESS)
> +        return status;
> +
> +    obj_surface = SURFACE(encoder_context->input_yuv_surface);
> +    encode_state->input_yuv_object = obj_surface;
> +    assert(obj_surface);
> +    i965_check_alloc_surface_bo(ctx, obj_surface, 1, fourcc, 
> + subsample);
> +    
> +    dst_surface.base = (struct object_base *)obj_surface;
> +    dst_surface.type = I965_SURFACE_TYPE_SURFACE;
> +    dst_surface.flags = I965_SURFACE_FLAG_FRAME;
> +
> +    //The Y800 format is expected to be tiled.
> +    //Linear Y800 is a corner case and needs code in the i965_image_processing.
> +    if(obj_surface->fourcc != VA_FOURCC_Y800){
> +        status = i965_image_processing(ctx,
> +                                   &src_surface,
> +                                   &rect,
> +                                   &dst_surface,
> +                                   &rect);
> +        assert(status == VA_STATUS_SUCCESS);
> +    }
> +
> +    encoder_context->is_tmp_id = 1;
> +
> +    return VA_STATUS_SUCCESS;
> +}
> +
>  static VAStatus
>  intel_encoder_check_misc_parameter(VADriverContextP ctx,
>                                    struct encode_state *encode_state, 
> @@ -309,17 +434,28 @@ intel_encoder_sanity_check_input(VADriverContextP ctx,
>      case VAProfileH264Main:
>      case VAProfileH264High:
>      case VAProfileH264MultiviewHigh:
> -    case VAProfileH264StereoHigh:
> +    case VAProfileH264StereoHigh: {
>          vaStatus = intel_encoder_check_avc_parameter(ctx, 
> encode_state, encoder_context);
> +        if (vaStatus != VA_STATUS_SUCCESS)
> +            goto out;
> +        vaStatus = intel_encoder_check_yuv_surface(ctx, profile, 
> + encode_state, encoder_context);
>          break;
> +    }
>  
>      case VAProfileMPEG2Simple:
> -    case VAProfileMPEG2Main:
> +    case VAProfileMPEG2Main: {
>          vaStatus = intel_encoder_check_mpeg2_parameter(ctx, 
> encode_state, encoder_context);
> +        if (vaStatus != VA_STATUS_SUCCESS)
> +            goto out;
> +        vaStatus = intel_encoder_check_yuv_surface(ctx, profile, 
> + encode_state, encoder_context);
>          break;
> +    }
>  
>      case VAProfileJPEGBaseline:  {
>          vaStatus = intel_encoder_check_jpeg_parameter(ctx, 
> encode_state, encoder_context);
> +        if (vaStatus != VA_STATUS_SUCCESS)
> +            goto out;
> +        vaStatus = intel_encoder_check_jpeg_yuv_surface(ctx, profile, 
> + encode_state, encoder_context);
>          break;
>      }
>  
> @@ -328,11 +464,6 @@ intel_encoder_sanity_check_input(VADriverContextP ctx,
>          break;
>      }
>  
> -    if (vaStatus != VA_STATUS_SUCCESS)
> -        goto out;
> -
> -    vaStatus = intel_encoder_check_yuv_surface(ctx, profile, encode_state, encoder_context);
> -
>      if (vaStatus == VA_STATUS_SUCCESS)
>          vaStatus = intel_encoder_check_misc_parameter(ctx, 
> encode_state, encoder_context);
>  
> 



More information about the Libva mailing list