diff options
author | Austin Yuan <shengquan.yuan@intel.com> | 2013-06-08 10:22:36 +0800 |
---|---|---|
committer | buildbot <buildbot@intel.com> | 2013-07-09 19:28:36 -0700 |
commit | 7d9a3d51091eff4c2c32653ad011ecae99dad4fe (patch) | |
tree | 2e10579bc758a7fa033dd1ec87bffcaf006a0ffd /test | |
parent | 7b38de70eec885e25c0603c56732bd80db48e911 (diff) | |
download | libva-7d9a3d51091eff4c2c32653ad011ecae99dad4fe.tar.gz |
Sync with new fdo staging branch
BZ: 119038
Change-Id: I4bf6b90e3bf0bee8f09a919d0a5fd548a1be5238
Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
Signed-off-by: pingshix <pingx.shi@intel.com>
Reviewed-on: http://android.intel.com:8080/115742
Reviewed-by: Sun, Jing A <jing.a.sun@intel.com>
Reviewed-by: Guo, Nana N <nana.n.guo@intel.com>
Reviewed-by: Wang, Kun K <kun.k.wang@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/basic/Android.mk | 20 | ||||
-rw-r--r-- | test/decode/tinyjpeg-internal.h | 5 | ||||
-rw-r--r-- | test/decode/tinyjpeg.c | 475 | ||||
-rw-r--r-- | test/encode/mpeg2enc.c | 13 | ||||
-rwxr-xr-x | test/putsurface/putsurface_common.c | 188 |
5 files changed, 448 insertions, 253 deletions
diff --git a/test/basic/Android.mk b/test/basic/Android.mk index ec1afaa..1755ec9 100755 --- a/test/basic/Android.mk +++ b/test/basic/Android.mk @@ -232,23 +232,3 @@ LOCAL_SHARED_LIBRARIES := libva-android libva libdl libdrm libcutils libutils li include $(BUILD_EXECUTABLE) -# For test_vaSurfaceAttrib -# ===================================================== -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - test_vaSurfaceAttrib.c - -LOCAL_CFLAGS += \ - -DANDROID - -LOCAL_C_INCLUDES += \ - $(TARGET_OUT_HEADERS)/libva \ - $(TOPDIR)/vendor/intel/hardware/libva/va/ - -LOCAL_MODULE_TAGS := optional -LOCAL_MODULE := test_vaSurfaceAttrib - -LOCAL_SHARED_LIBRARIES := libva-android libva libdl libdrm libcutils libutils libui libsurfaceflinger - -include $(BUILD_EXECUTABLE) diff --git a/test/decode/tinyjpeg-internal.h b/test/decode/tinyjpeg-internal.h index 9caead5..6801c31 100644 --- a/test/decode/tinyjpeg-internal.h +++ b/test/decode/tinyjpeg-internal.h @@ -48,6 +48,7 @@ struct jdec_private; #define COMPONENTS 4 #define JPEG_MAX_WIDTH 2048 #define JPEG_MAX_HEIGHT 2048 +#define JPEG_SCAN_MAX 4 enum std_markers { DQT = 0xDB, /* Define Quantization Table */ @@ -95,10 +96,10 @@ struct jpeg_sos struct jdec_private { /* Public variables */ - unsigned int width, height; /* Size of the image */ + unsigned int width[JPEG_SCAN_MAX], height[JPEG_SCAN_MAX]; /* Size of the image */ /* Private variables */ - const unsigned char *stream_begin, *stream_end; + const unsigned char *stream_begin, *stream_end,*stream_scan; unsigned int stream_length; const unsigned char *stream; /* Pointer to the current stream */ diff --git a/test/decode/tinyjpeg.c b/test/decode/tinyjpeg.c index 34a8b82..417c88c 100644 --- a/test/decode/tinyjpeg.c +++ b/test/decode/tinyjpeg.c @@ -80,7 +80,9 @@ snprintf(error_string, sizeof(error_string), fmt, ## args); \ return -1; \ } while(0) - +/* The variables for different image scans */ +static int scan_num=0; +static int next_image_found=0; /* Global variable to return the last error found while deconding */ static char error_string[256]; static VAHuffmanTableBufferJPEGBaseline default_huffman_table_param={ @@ -261,8 +263,8 @@ static int parse_SOF(struct jdec_private *priv, const unsigned char *stream) cid, c->Hfactor, c->Vfactor, Q_table ); } - priv->width = width; - priv->height = height; + priv->width[scan_num] = width; + priv->height[scan_num] = height; trace("< SOF marker\n"); @@ -384,6 +386,32 @@ static int parse_DRI(struct jdec_private *priv, const unsigned char *stream) return 0; } +static int findEOI(struct jdec_private *priv,const unsigned char *stream) +{ + while (!(*stream == 0xff && *(stream+1) == 0xd9 )&& stream<=priv->stream_end) //searching for the end of image marker + { + stream++; + continue; + } + priv->stream_scan=stream; + return 0; +} + +static int findSOI(struct jdec_private *priv,const unsigned char *stream) +{ + while (!(*stream == 0xff && *(stream+1) == 0xd8 ) ) //searching for the start of image marker + { + if(stream<=priv->stream_end) + { + stream++; + continue; + } + else + return 0; // No more images in the file. + } + priv->stream=stream+2; + return 1; +} static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream) { @@ -394,15 +422,14 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream) int dqt_marker_found = 0; const unsigned char *next_chunck; - /* Parse marker */ - while (!sos_marker_found) - { - if (*stream++ != 0xff) - goto bogus_jpeg_format; - /* Skip any padding ff byte (this is normal) */ - while (*stream == 0xff) - stream++; + next_image_found = findSOI(priv,stream); + stream=priv->stream; + while (!sos_marker_found && stream<=priv->stream_end) + { + while((*stream == 0xff)) + stream++; + marker = *stream++; chuck_len = be16_to_cpu(stream); next_chunck = stream + chuck_len; @@ -439,14 +466,15 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream) stream = next_chunck; } - if (!dht_marker_found) { - trace("No Huffman table loaded, using the default one\n"); - build_default_huffman_tables(priv); - } - if (!dqt_marker_found) { - error("ERROR:No Quantization table loaded, using the default one\n"); - } - + if(next_image_found){ + if (!dht_marker_found) { + trace("No Huffman table loaded, using the default one\n"); + build_default_huffman_tables(priv); + } + if (!dqt_marker_found) { + error("ERROR:No Quantization table loaded, using the default one\n"); + } + } #ifdef SANITY_CHECK if ( (priv->component_infos[cY].Hfactor < priv->component_infos[cCb].Hfactor) || (priv->component_infos[cY].Hfactor < priv->component_infos[cCr].Hfactor)) @@ -460,11 +488,8 @@ static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream) || (priv->component_infos[cCr].Vfactor!=1)) printf("ERROR:Sampling other than 1x1 for Cr and Cb is not supported"); #endif - - return 0; -bogus_jpeg_format: - trace("Bogus jpeg format\n"); - return -1; + findEOI(priv,stream); + return next_image_found; } /******************************************************************************* @@ -517,12 +542,12 @@ int tinyjpeg_parse_header(struct jdec_private *priv, const unsigned char *buf, u if ((buf[0] != 0xFF) || (buf[1] != SOI)) error("Not a JPG file ?\n"); - priv->stream_begin = buf+2; - priv->stream_length = size-2; + priv->stream_begin = buf; + priv->stream_length = size; priv->stream_end = priv->stream_begin + priv->stream_length; - ret = parse_JFIF(priv, priv->stream_begin); - + priv->stream = priv->stream_begin; + ret = parse_JFIF(priv, priv->stream); return ret; } @@ -549,6 +574,16 @@ int tinyjpeg_decode(struct jdec_private *priv) int putsurface=1; unsigned int i, j; + int surface_type; + char *type; + int ChromaTypeIndex; + + VASurfaceAttrib forcc; + forcc.type =VASurfaceAttribPixelFormat; + forcc.flags=VA_SURFACE_ATTRIB_SETTABLE; + forcc.value.type=VAGenericValueTypeInteger; + + va_dpy = va_open_display(); va_status = vaInitialize(va_dpy, &major_ver, &minor_ver); assert(va_status == VA_STATUS_SUCCESS); @@ -579,169 +614,245 @@ int tinyjpeg_decode(struct jdec_private *priv) &attrib, 1,&config_id); CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints"); - va_status = vaCreateSurfaces(va_dpy,VA_RT_FORMAT_YUV420, - priv->width,priv->height, //alignment? - &surface_id, 1, NULL, 0); - CHECK_VASTATUS(va_status, "vaCreateSurfaces"); - - /* Create a context for this decode pipe */ - va_status = vaCreateContext(va_dpy, config_id, - priv->width, priv->height, // alignment? - VA_PROGRESSIVE, - &surface_id, - 1, - &context_id); - CHECK_VASTATUS(va_status, "vaCreateContext"); - - VAPictureParameterBufferJPEGBaseline pic_param; - memset(&pic_param, 0, sizeof(pic_param)); - pic_param.picture_width = priv->width; - pic_param.picture_height = priv->height; - pic_param.num_components = priv->nf_components; - - for (i=0; i<pic_param.num_components; i++) { // tinyjpeg support 3 components only, does it match va? - pic_param.components[i].component_id = priv->component_infos[i].cid; - pic_param.components[i].h_sampling_factor = priv->component_infos[i].Hfactor; - pic_param.components[i].v_sampling_factor = priv->component_infos[i].Vfactor; - pic_param.components[i].quantiser_table_selector = priv->component_infos[i].quant_table_index; - } - - va_status = vaCreateBuffer(va_dpy, context_id, - VAPictureParameterBufferType, // VAPictureParameterBufferJPEGBaseline? - sizeof(VAPictureParameterBufferJPEGBaseline), - 1, &pic_param, - &pic_param_buf); - CHECK_VASTATUS(va_status, "vaCreateBuffer"); - - VAIQMatrixBufferJPEGBaseline iq_matrix; - const unsigned int num_quant_tables = - MIN(COMPONENTS, ARRAY_ELEMS(iq_matrix.load_quantiser_table)); - // todo, only mask it if non-default quant matrix is used. do we need build default quant matrix? - memset(&iq_matrix, 0, sizeof(VAIQMatrixBufferJPEGBaseline)); - for (i = 0; i < num_quant_tables; i++) { - if (!priv->Q_tables_valid[i]) - continue; - iq_matrix.load_quantiser_table[i] = 1; - for (j = 0; j < 64; j++) - iq_matrix.quantiser_table[i][j] = priv->Q_tables[i][j]; - } - va_status = vaCreateBuffer(va_dpy, context_id, - VAIQMatrixBufferType, // VAIQMatrixBufferJPEGBaseline? - sizeof(VAIQMatrixBufferJPEGBaseline), - 1, &iq_matrix, - &iqmatrix_buf ); - CHECK_VASTATUS(va_status, "vaCreateBuffer"); - - VAHuffmanTableBufferJPEGBaseline huffman_table; - const unsigned int num_huffman_tables = - MIN(COMPONENTS, ARRAY_ELEMS(huffman_table.load_huffman_table)); - memset(&huffman_table, 0, sizeof(VAHuffmanTableBufferJPEGBaseline)); - assert(sizeof(huffman_table.huffman_table[0].num_dc_codes) == + while (next_image_found){ + VAPictureParameterBufferJPEGBaseline pic_param; + memset(&pic_param, 0, sizeof(pic_param)); + pic_param.picture_width = priv->width[scan_num]; + pic_param.picture_height = priv->height[scan_num]; + pic_param.num_components = priv->nf_components; + + + for (i=0; i<pic_param.num_components; i++) { // tinyjpeg support 3 components only, does it match va? + pic_param.components[i].component_id = priv->component_infos[i].cid; + pic_param.components[i].h_sampling_factor = priv->component_infos[i].Hfactor; + pic_param.components[i].v_sampling_factor = priv->component_infos[i].Vfactor; + pic_param.components[i].quantiser_table_selector = priv->component_infos[i].quant_table_index; + } + int h1, h2, h3, v1, v2, v3; + h1 = pic_param.components[0].h_sampling_factor; + h2 = pic_param.components[1].h_sampling_factor; + h3 = pic_param.components[2].h_sampling_factor; + v1 = pic_param.components[0].v_sampling_factor; + v2 = pic_param.components[1].v_sampling_factor; + v3 = pic_param.components[2].v_sampling_factor; + + if (h1 == 2 && h2 == 1 && h3 == 1 && + v1 == 2 && v2 == 1 && v3 == 1) { + //surface_type = VA_RT_FORMAT_IMC3; + surface_type = VA_RT_FORMAT_YUV420; + forcc.value.value.i = VA_FOURCC_IMC3; + ChromaTypeIndex = 1; + type = "VA_FOURCC_IMC3"; + } + else if (h1 == 2 && h2 == 1 && h3 == 1 && + v1 == 1 && v2 == 1 && v3 == 1) { + //surface_type = VA_RT_FORMAT_YUV422H; + surface_type = VA_RT_FORMAT_YUV422; + forcc.value.value.i = VA_FOURCC_422H; + ChromaTypeIndex = 2; + type = "VA_FOURCC_422H"; + } + else if (h1 == 1 && h2 == 1 && h3 == 1 && + v1 == 1 && v2 == 1 && v3 == 1) { + surface_type = VA_RT_FORMAT_YUV444; + forcc.value.value.i = VA_FOURCC_444P; + //forcc.value.value.i = VA_FOURCC_RGBP; + ChromaTypeIndex = 3; + type = "VA_FOURCC_444P"; + } + else if (h1 == 4 && h2 == 1 && h3 == 1 && + v1 == 1 && v2 == 1 && v3 == 1) { + surface_type = VA_RT_FORMAT_YUV411; + forcc.value.value.i = VA_FOURCC_411P; + ChromaTypeIndex = 4; + type = "VA_FOURCC_411P"; + } + else if (h1 == 1 && h2 == 1 && h3 == 1 && + v1 == 2 && v2 == 1 && v3 == 1) { + //surface_type = VA_RT_FORMAT_YUV422V; + surface_type = VA_RT_FORMAT_YUV422; + forcc.value.value.i = VA_FOURCC_422V; + ChromaTypeIndex = 5; + type = "VA_FOURCC_422V"; + } + else if (h1 == 2 && h2 == 1 && h3 == 1 && + v1 == 2 && v2 == 2 && v3 == 2) { + //surface_type = VA_RT_FORMAT_YUV422H; + surface_type = VA_RT_FORMAT_YUV422; + forcc.value.value.i = VA_FOURCC_422H; + ChromaTypeIndex = 6; + type = "VA_FOURCC_422H"; + } + else if (h2 == 2 && h2 == 2 && h3 == 2 && + v1 == 2 && v2 == 1 && v3 == 1) { + //surface_type = VA_RT_FORMAT_YUV422V; + surface_type = VA_RT_FORMAT_YUV422; + forcc.value.value.i = VA_FOURCC_422V; + ChromaTypeIndex = 7; + type = "VA_FOURCC_422V"; + } + else + { + surface_type = VA_RT_FORMAT_YUV400; + forcc.value.value.i = VA_FOURCC('4','0','0','P'); + ChromaTypeIndex = 0; + type = "Format_400P"; + } + + va_status = vaCreateSurfaces(va_dpy,VA_RT_FORMAT_YUV420, + priv->width[scan_num],priv->height[scan_num], //alignment? + &surface_id, 1, &forcc, 1); + CHECK_VASTATUS(va_status, "vaCreateSurfaces"); + + /* Create a context for this decode pipe */ + va_status = vaCreateContext(va_dpy, config_id, + priv->width[scan_num], priv->height[scan_num], // alignment? + VA_PROGRESSIVE, + &surface_id, + 1, + &context_id); + CHECK_VASTATUS(va_status, "vaCreateContext"); + + va_status = vaCreateBuffer(va_dpy, context_id, + VAPictureParameterBufferType, // VAPictureParameterBufferJPEGBaseline? + sizeof(VAPictureParameterBufferJPEGBaseline), + 1, &pic_param, + &pic_param_buf); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); + + VAIQMatrixBufferJPEGBaseline iq_matrix; + const unsigned int num_quant_tables = + MIN(COMPONENTS, ARRAY_ELEMS(iq_matrix.load_quantiser_table)); + // todo, only mask it if non-default quant matrix is used. do we need build default quant matrix? + memset(&iq_matrix, 0, sizeof(VAIQMatrixBufferJPEGBaseline)); + for (i = 0; i < num_quant_tables; i++) { + if (!priv->Q_tables_valid[i]) + continue; + iq_matrix.load_quantiser_table[i] = 1; + for (j = 0; j < 64; j++) + iq_matrix.quantiser_table[i][j] = priv->Q_tables[i][j]; + } + va_status = vaCreateBuffer(va_dpy, context_id, + VAIQMatrixBufferType, // VAIQMatrixBufferJPEGBaseline? + sizeof(VAIQMatrixBufferJPEGBaseline), + 1, &iq_matrix, + &iqmatrix_buf ); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); + + VAHuffmanTableBufferJPEGBaseline huffman_table; + const unsigned int num_huffman_tables = + MIN(COMPONENTS, ARRAY_ELEMS(huffman_table.load_huffman_table)); + memset(&huffman_table, 0, sizeof(VAHuffmanTableBufferJPEGBaseline)); + assert(sizeof(huffman_table.huffman_table[0].num_dc_codes) == sizeof(priv->HTDC[0].bits)); - assert(sizeof(huffman_table.huffman_table[0].dc_values[0]) == + assert(sizeof(huffman_table.huffman_table[0].dc_values[0]) == sizeof(priv->HTDC[0].values[0])); - for (i = 0; i < num_huffman_tables; i++) { - if (!priv->HTDC_valid[i] || !priv->HTAC_valid[i]) - continue; - huffman_table.load_huffman_table[i] = 1; - memcpy(huffman_table.huffman_table[i].num_dc_codes, priv->HTDC[i].bits, - sizeof(huffman_table.huffman_table[i].num_dc_codes)); - memcpy(huffman_table.huffman_table[i].dc_values, priv->HTDC[i].values, - sizeof(huffman_table.huffman_table[i].dc_values)); - memcpy(huffman_table.huffman_table[i].num_ac_codes, priv->HTAC[i].bits, - sizeof(huffman_table.huffman_table[i].num_ac_codes)); - memcpy(huffman_table.huffman_table[i].ac_values, priv->HTAC[i].values, - sizeof(huffman_table.huffman_table[i].ac_values)); - memset(huffman_table.huffman_table[i].pad, 0, - sizeof(huffman_table.huffman_table[i].pad)); - } - - va_status = vaCreateBuffer(va_dpy, context_id, - VAHuffmanTableBufferType, // VAHuffmanTableBufferJPEGBaseline? - sizeof(VAHuffmanTableBufferJPEGBaseline), - 1, &huffman_table, - &huffmantable_buf ); - CHECK_VASTATUS(va_status, "vaCreateBuffer"); - - // one slice for whole image? - max_h_factor = priv->component_infos[0].Hfactor; - max_v_factor = priv->component_infos[0].Vfactor; - static VASliceParameterBufferJPEGBaseline slice_param; - slice_param.slice_data_size = priv->stream_end - priv->stream; - slice_param.slice_data_offset = 0; - slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; - slice_param.slice_horizontal_position = 0; - slice_param.slice_vertical_position = 0; - slice_param.num_components = priv->cur_sos.nr_components; - for (i = 0; i < slice_param.num_components; i++) { - slice_param.components[i].component_selector = priv->cur_sos.components[i].component_id; /* FIXME: set to values specified in SOS */ - slice_param.components[i].dc_table_selector = priv->cur_sos.components[i].dc_selector; /* FIXME: set to values specified in SOS */ - slice_param.components[i].ac_table_selector = priv->cur_sos.components[i].ac_selector; /* FIXME: set to values specified in SOS */ - } - slice_param.restart_interval = priv->restart_interval; - slice_param.num_mcus = ((priv->width+max_h_factor*8-1)/(max_h_factor*8))* - ((priv->height+max_v_factor*8-1)/(max_v_factor*8)); // ?? 720/16? - - va_status = vaCreateBuffer(va_dpy, context_id, - VASliceParameterBufferType, // VASliceParameterBufferJPEGBaseline? - sizeof(VASliceParameterBufferJPEGBaseline), - 1, - &slice_param, &slice_param_buf); - CHECK_VASTATUS(va_status, "vaCreateBuffer"); - - va_status = vaCreateBuffer(va_dpy, context_id, - VASliceDataBufferType, - priv->stream_end - priv->stream, - 1, - (void*)priv->stream, // jpeg_clip, - &slice_data_buf); - CHECK_VASTATUS(va_status, "vaCreateBuffer"); - - va_status = vaBeginPicture(va_dpy, context_id, surface_id); - CHECK_VASTATUS(va_status, "vaBeginPicture"); - - va_status = vaRenderPicture(va_dpy,context_id, &pic_param_buf, 1); - CHECK_VASTATUS(va_status, "vaRenderPicture"); - - va_status = vaRenderPicture(va_dpy,context_id, &iqmatrix_buf, 1); - CHECK_VASTATUS(va_status, "vaRenderPicture"); - - va_status = vaRenderPicture(va_dpy,context_id, &huffmantable_buf, 1); - CHECK_VASTATUS(va_status, "vaRenderPicture"); + for (i = 0; i < num_huffman_tables; i++) { + if (!priv->HTDC_valid[i] || !priv->HTAC_valid[i]) + continue; + huffman_table.load_huffman_table[i] = 1; + memcpy(huffman_table.huffman_table[i].num_dc_codes, priv->HTDC[i].bits, + sizeof(huffman_table.huffman_table[i].num_dc_codes)); + memcpy(huffman_table.huffman_table[i].dc_values, priv->HTDC[i].values, + sizeof(huffman_table.huffman_table[i].dc_values)); + memcpy(huffman_table.huffman_table[i].num_ac_codes, priv->HTAC[i].bits, + sizeof(huffman_table.huffman_table[i].num_ac_codes)); + memcpy(huffman_table.huffman_table[i].ac_values, priv->HTAC[i].values, + sizeof(huffman_table.huffman_table[i].ac_values)); + memset(huffman_table.huffman_table[i].pad, 0, + sizeof(huffman_table.huffman_table[i].pad)); + } + va_status = vaCreateBuffer(va_dpy, context_id, + VAHuffmanTableBufferType, // VAHuffmanTableBufferJPEGBaseline? + sizeof(VAHuffmanTableBufferJPEGBaseline), + 1, &huffman_table, + &huffmantable_buf ); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); - va_status = vaRenderPicture(va_dpy,context_id, &slice_param_buf, 1); - CHECK_VASTATUS(va_status, "vaRenderPicture"); + // one slice for whole image? + max_h_factor = priv->component_infos[0].Hfactor; + max_v_factor = priv->component_infos[0].Vfactor; + static VASliceParameterBufferJPEGBaseline slice_param; + slice_param.slice_data_size = (priv->stream_scan - priv->stream); + slice_param.slice_data_offset = 0; + slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; + slice_param.slice_horizontal_position = 0; + slice_param.slice_vertical_position = 0; + slice_param.num_components = priv->cur_sos.nr_components; + for (i = 0; i < slice_param.num_components; i++) { + slice_param.components[i].component_selector = priv->cur_sos.components[i].component_id; /* FIXME: set to values specified in SOS */ + slice_param.components[i].dc_table_selector = priv->cur_sos.components[i].dc_selector; /* FIXME: set to values specified in SOS */ + slice_param.components[i].ac_table_selector = priv->cur_sos.components[i].ac_selector; /* FIXME: set to values specified in SOS */ + } + slice_param.restart_interval = priv->restart_interval; + slice_param.num_mcus = ((priv->width[scan_num]+max_h_factor*8-1)/(max_h_factor*8))* + ((priv->height[scan_num]+max_v_factor*8-1)/(max_v_factor*8)); // ?? 720/16? + + va_status = vaCreateBuffer(va_dpy, context_id, + VASliceParameterBufferType, // VASliceParameterBufferJPEGBaseline? + sizeof(VASliceParameterBufferJPEGBaseline), + 1, + &slice_param, &slice_param_buf); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); + + va_status = vaCreateBuffer(va_dpy, context_id, + VASliceDataBufferType, + priv->stream_scan - priv->stream, + 1, + (void*)priv->stream, // jpeg_clip, + &slice_data_buf); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); + + va_status = vaBeginPicture(va_dpy, context_id, surface_id); + CHECK_VASTATUS(va_status, "vaBeginPicture"); + + va_status = vaRenderPicture(va_dpy,context_id, &pic_param_buf, 1); + CHECK_VASTATUS(va_status, "vaRenderPicture"); + + va_status = vaRenderPicture(va_dpy,context_id, &iqmatrix_buf, 1); + CHECK_VASTATUS(va_status, "vaRenderPicture"); + + va_status = vaRenderPicture(va_dpy,context_id, &huffmantable_buf, 1); + CHECK_VASTATUS(va_status, "vaRenderPicture"); + + va_status = vaRenderPicture(va_dpy,context_id, &slice_param_buf, 1); + CHECK_VASTATUS(va_status, "vaRenderPicture"); - va_status = vaRenderPicture(va_dpy,context_id, &slice_data_buf, 1); - CHECK_VASTATUS(va_status, "vaRenderPicture"); + va_status = vaRenderPicture(va_dpy,context_id, &slice_data_buf, 1); + CHECK_VASTATUS(va_status, "vaRenderPicture"); - va_status = vaEndPicture(va_dpy,context_id); - CHECK_VASTATUS(va_status, "vaEndPicture"); - - va_status = vaSyncSurface(va_dpy, surface_id); - CHECK_VASTATUS(va_status, "vaSyncSurface"); + va_status = vaEndPicture(va_dpy,context_id); + CHECK_VASTATUS(va_status, "vaEndPicture"); - if (putsurface) { - VARectangle src_rect, dst_rect; + va_status = vaSyncSurface(va_dpy, surface_id); + CHECK_VASTATUS(va_status, "vaSyncSurface"); - src_rect.x = 0; - src_rect.y = 0; - src_rect.width = priv->width; - src_rect.height = priv->height; - dst_rect = src_rect; + if (putsurface) { + VARectangle src_rect, dst_rect; - va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect); - CHECK_VASTATUS(va_status, "vaPutSurface"); - } - printf("press any key to exit\n"); - getchar(); + src_rect.x = 0; + src_rect.y = 0; + src_rect.width = priv->width[scan_num]; + src_rect.height = priv->height[scan_num]; + dst_rect = src_rect; - vaDestroySurfaces(va_dpy,&surface_id,1); - vaDestroyConfig(va_dpy,config_id); - vaDestroyContext(va_dpy,context_id); + va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect); + CHECK_VASTATUS(va_status, "vaPutSurface"); + } + scan_num++; + vaDestroySurfaces(va_dpy,&surface_id,1); + vaDestroyConfig(va_dpy,config_id); + vaDestroyContext(va_dpy,context_id); + + parse_JFIF(priv,priv->stream); + if(priv->width[scan_num] == 0 && priv->height[scan_num] == 0) + break; + } + // va_close_display(va_dpy); vaTerminate(va_dpy); - va_close_display(va_dpy); + printf("press any key to exit23\n"); + getchar(); return 0; } const char *tinyjpeg_get_errorstring(struct jdec_private *priv) @@ -752,8 +863,8 @@ const char *tinyjpeg_get_errorstring(struct jdec_private *priv) } void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned int *height) { - *width = priv->width; - *height = priv->height; + *width = priv->width[scan_num]; + *height = priv->height[scan_num]; } diff --git a/test/encode/mpeg2enc.c b/test/encode/mpeg2enc.c index 5d517a1..4e1776d 100644 --- a/test/encode/mpeg2enc.c +++ b/test/encode/mpeg2enc.c @@ -330,7 +330,6 @@ pps_rbsp(const VAEncSequenceParameterBufferMPEG2 *seq_param, const VAEncPictureParameterBufferMPEG2 *pic_param, bitstream *bs) { - int i; int chroma_420_type; if (seq_param->sequence_extension.bits.chroma_format == CHROMA_FORMAT_420) @@ -382,16 +381,6 @@ pps_rbsp(const VAEncSequenceParameterBufferMPEG2 *seq_param, bitstream_put_ui(bs, pic_param->picture_coding_extension.bits.composite_display_flag, 1); bitstream_byte_aligning(bs, 0); - - if (pic_param->user_data_length) { - bitstream_put_ui(bs, START_CODE_USER, 32); - - for (i = 0; i < pic_param->user_data_length; i++) { - bitstream_put_ui(bs, pic_param->user_data[i], 8); - } - - bitstream_byte_aligning(bs, 0); - } } static int @@ -823,8 +812,6 @@ mpeg2enc_init_picture_parameter(struct mpeg2enc_context *ctx, pic_param->picture_coding_extension.bits.repeat_first_field = 0; pic_param->picture_coding_extension.bits.progressive_frame = 1; pic_param->picture_coding_extension.bits.composite_display_flag = 0; - - pic_param->user_data_length = 0; } static void diff --git a/test/putsurface/putsurface_common.c b/test/putsurface/putsurface_common.c index 2bef579..e52bf45 100755 --- a/test/putsurface/putsurface_common.c +++ b/test/putsurface/putsurface_common.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <stdint.h> #include <getopt.h> #include <sys/time.h> @@ -59,7 +60,11 @@ if (va_status != VA_STATUS_SUCCESS) { \ static void *win_display; static VADisplay va_dpy; -static VAConfigID config_id; +static VAImageFormat *va_image_formats; +static int va_num_image_formats = -1; +static VAConfigID vpp_config_id = VA_INVALID_ID; +static VASurfaceAttrib *va_surface_attribs; +static int va_num_surface_attribs = -1; static VASurfaceID surface_id[SURFACE_NUM]; static pthread_mutex_t surface_mutex[SURFACE_NUM]; @@ -123,46 +128,151 @@ char* map_vafourcc_to_str (unsigned int format) } -int csc_preparation () +static int +va_value_equals(const VAGenericValue *v1, const VAGenericValue *v2) +{ + if (v1->type != v2->type) + return 0; + + switch (v1->type) { + case VAGenericValueTypeInteger: + return v1->value.i == v2->value.i; + case VAGenericValueTypeFloat: + return v1->value.f == v2->value.f; + case VAGenericValueTypePointer: + return v1->value.p == v2->value.p; + case VAGenericValueTypeFunc: + return v1->value.fn == v2->value.fn; + } + return 0; +} + +static int +ensure_image_formats(void) { VAStatus va_status; + VAImageFormat *image_formats; + int num_image_formats; + + if (va_num_image_formats >= 0) + return va_num_image_formats; + + num_image_formats = vaMaxNumImageFormats(va_dpy); + if (num_image_formats == 0) + return 0; + + image_formats = malloc(num_image_formats * sizeof(*image_formats)); + if (!image_formats) + return 0; + + va_status = vaQueryImageFormats(va_dpy, image_formats, &num_image_formats); + CHECK_VASTATUS(va_status, "vaQuerySurfaceAttributes()"); + + va_image_formats = image_formats; + va_num_image_formats = num_image_formats; + return num_image_formats; +} + +static const VAImageFormat * +lookup_image_format(uint32_t fourcc) +{ int i; - - // 1. make sure dst fourcc is supported for vaImage - #define MAX_IMAGE_FORMAT_COUNT 10 - VAImageFormat format_list[MAX_IMAGE_FORMAT_COUNT]; - int num_formats = 0, find_dst_fourcc = 0; - - va_status = vaQueryImageFormats(va_dpy, format_list,&num_formats); - printf("num_formats: %d\n", num_formats); - assert(num_formats<MAX_IMAGE_FORMAT_COUNT); - for (i=0; i<num_formats; i++) { - if (format_list[i].fourcc == csc_dst_fourcc) { - find_dst_fourcc = 1; + + if (!ensure_image_formats()) + return NULL; + + for (i = 0; i < va_num_image_formats; i++) { + const VAImageFormat * const image_format = &va_image_formats[i]; + if (image_format->fourcc == fourcc) + return image_format; + } + return NULL; +} + +static int +ensure_surface_attribs(void) +{ + VAStatus va_status; + VASurfaceAttrib *surface_attribs; + unsigned int num_image_formats, num_surface_attribs; + + if (va_num_surface_attribs >= 0) + return va_num_surface_attribs; + + num_image_formats = vaMaxNumImageFormats(va_dpy); + if (num_image_formats == 0) + return 0; + + va_status = vaCreateConfig(va_dpy, VAProfileNone, VAEntrypointVideoProc, + NULL, 0, &vpp_config_id); + CHECK_VASTATUS(va_status, "vaCreateConfig()"); + + /* Guess the number of surface attributes, thus including any + pixel-format supported by the VA driver */ + num_surface_attribs = VASurfaceAttribCount + num_image_formats; + surface_attribs = malloc(num_surface_attribs * sizeof(*surface_attribs)); + if (!surface_attribs) + return 0; + + va_status = vaQuerySurfaceAttributes(va_dpy, vpp_config_id, + surface_attribs, &num_surface_attribs); + if (va_status == VA_STATUS_SUCCESS) + va_surface_attribs = surface_attribs; + else if (va_status == VA_STATUS_ERROR_MAX_NUM_EXCEEDED) { + va_surface_attribs = realloc(surface_attribs, + num_surface_attribs * sizeof(*va_surface_attribs)); + if (!va_surface_attribs) { + free(surface_attribs); + return 0; } + va_status = vaQuerySurfaceAttributes(va_dpy, vpp_config_id, + va_surface_attribs, &num_surface_attribs); + } + CHECK_VASTATUS(va_status, "vaQuerySurfaceAttributes()"); + va_num_surface_attribs = num_surface_attribs; + return num_surface_attribs; +} + +static const VASurfaceAttrib * +lookup_surface_attrib(VASurfaceAttribType type, const VAGenericValue *value) +{ + int i; + + if (!ensure_surface_attribs()) + return NULL; + + for (i = 0; i < va_num_surface_attribs; i++) { + const VASurfaceAttrib * const surface_attrib = &va_surface_attribs[i]; + if (surface_attrib->type != type) + continue; + if (!(surface_attrib->flags & VA_SURFACE_ATTRIB_SETTABLE)) + continue; + if (va_value_equals(&surface_attrib->value, value)) + return surface_attrib; } - if (!find_dst_fourcc) { + return NULL; +} + +int csc_preparation () +{ + VAStatus va_status; + + // 1. make sure dst fourcc is supported for vaImage + if (!lookup_image_format(csc_dst_fourcc)) { test_color_conversion = 0; - printf("vaImage doesn't support %s, skip additional color conversion\n", map_vafourcc_to_str(csc_dst_fourcc)); + printf("VA driver doesn't support %s image, skip additional color conversion\n", map_vafourcc_to_str(csc_dst_fourcc)); goto cleanup; } // 2. make sure src_fourcc is supported for vaSurface - VASurfaceAttrib s_attrib[1]; - va_status = vaCreateConfig(va_dpy, VAProfileNone, VAEntrypointVideoProc, - NULL, 0,&config_id); - CHECK_VASTATUS(va_status, "vaCreateConfig"); - - s_attrib[0].flags = VA_SURFACE_ATTRIB_SETTABLE; - s_attrib[0].type = VASurfaceAttribPixelFormat; - s_attrib[0].value.type = VAGenericValueTypeInteger; - s_attrib[0].value.value.i = csc_src_fourcc; - - va_status = vaGetSurfaceAttributes(va_dpy, config_id, s_attrib, 1); - CHECK_VASTATUS(va_status,"vaGetSurfaceAttributes"); - if (! (s_attrib[0].flags & VA_SURFACE_ATTRIB_SETTABLE)) { - printf("vaSurface doesn't support %s, skip additional color conversion\n", map_vafourcc_to_str(csc_src_fourcc)); - vaDestroyConfig (va_dpy, config_id); + VASurfaceAttrib surface_attribs[1], * const s_attrib = &surface_attribs[0]; + s_attrib->type = VASurfaceAttribPixelFormat; + s_attrib->flags = VA_SURFACE_ATTRIB_SETTABLE; + s_attrib->value.type = VAGenericValueTypeInteger; + s_attrib->value.value.i = csc_src_fourcc; + + if (!lookup_surface_attrib(VASurfaceAttribPixelFormat, &s_attrib->value)) { + printf("VA driver doesn't support %s surface, skip additional color conversion\n", map_vafourcc_to_str(csc_src_fourcc)); test_color_conversion = 0; goto cleanup; } @@ -173,7 +283,7 @@ int csc_preparation () va_dpy, VA_RT_FORMAT_YUV420, surface_width, surface_height, &surface_id[0], SURFACE_NUM, - s_attrib, 1 + surface_attribs, 1 ); CHECK_VASTATUS(va_status,"vaCreateSurfaces"); @@ -190,11 +300,11 @@ int csc_preparation () // 3.3 create a temp VASurface for final rendering(vaPutSurface) - s_attrib[0].value.value.i = VA_FOURCC_NV12; + s_attrib->value.value.i = VA_FOURCC_NV12; va_status = vaCreateSurfaces(va_dpy, VA_RT_FORMAT_YUV420, surface_width, surface_height, &csc_render_surface, 1, - s_attrib, 1); + surface_attribs, 1); CHECK_VASTATUS(va_status,"vaCreateSurfaces"); @@ -559,12 +669,18 @@ int main(int argc,char **argv) va_status = vaDestroyImage(va_dpy, csc_dst_fourcc_image.image_id); CHECK_VASTATUS(va_status,"vaDestroyImage"); - vaDestroyConfig (va_dpy, config_id); } - + + if (vpp_config_id != VA_INVALID_ID) { + vaDestroyConfig (va_dpy, vpp_config_id); + vpp_config_id = VA_INVALID_ID; + } + vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM); vaTerminate(va_dpy); + free(va_image_formats); + free(va_surface_attribs); close_display(win_display); return 0; |