OSDN Git Service

Test write permission
[android-x86/hardware-intel-common-libva.git] / test / test_12.c
1 /*
2  * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
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
25 #define TEST_DESCRIPTION        "Sample MPEG2 VLD Decoding"
26
27 #include "test_common.c"
28
29 #include <X11/Xlib.h>
30
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34
35 #include "va_x11.h"
36
37 void pre()
38 {
39     test_init();
40 }
41
42 /* Data dump of a 16x16 MPEG2 video clip,it has one I frame
43  */
44 static unsigned char mpeg2_clip[]={
45     0x00,0x00,0x01,0xb3,0x01,0x00,0x10,0x13,0xff,0xff,0xe0,0x18,0x00,0x00,0x01,0xb5,
46     0x14,0x8a,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0xb8,0x00,0x08,0x00,0x00,0x00,0x00,
47     0x01,0x00,0x00,0x0f,0xff,0xf8,0x00,0x00,0x01,0xb5,0x8f,0xff,0xf3,0x41,0x80,0x00,
48     0x00,0x01,0x01,0x13,0xe1,0x00,0x15,0x81,0x54,0xe0,0x2a,0x05,0x43,0x00,0x2d,0x60,
49     0x18,0x01,0x4e,0x82,0xb9,0x58,0xb1,0x83,0x49,0xa4,0xa0,0x2e,0x05,0x80,0x4b,0x7a,
50     0x00,0x01,0x38,0x20,0x80,0xe8,0x05,0xff,0x60,0x18,0xe0,0x1d,0x80,0x98,0x01,0xf8,
51     0x06,0x00,0x54,0x02,0xc0,0x18,0x14,0x03,0xb2,0x92,0x80,0xc0,0x18,0x94,0x42,0x2c,
52     0xb2,0x11,0x64,0xa0,0x12,0x5e,0x78,0x03,0x3c,0x01,0x80,0x0e,0x80,0x18,0x80,0x6b,
53     0xca,0x4e,0x01,0x0f,0xe4,0x32,0xc9,0xbf,0x01,0x42,0x69,0x43,0x50,0x4b,0x01,0xc9,
54     0x45,0x80,0x50,0x01,0x38,0x65,0xe8,0x01,0x03,0xf3,0xc0,0x76,0x00,0xe0,0x03,0x20,
55     0x28,0x18,0x01,0xa9,0x34,0x04,0xc5,0xe0,0x0b,0x0b,0x04,0x20,0x06,0xc0,0x89,0xff,
56     0x60,0x12,0x12,0x8a,0x2c,0x34,0x11,0xff,0xf6,0xe2,0x40,0xc0,0x30,0x1b,0x7a,0x01,
57     0xa9,0x0d,0x00,0xac,0x64
58 };
59
60 /* hardcoded here without a bitstream parser helper
61  * please see picture mpeg2-I.jpg for bitstream details
62  */
63 static VAPictureParameterBufferMPEG2 pic_param={
64   horizontal_size:16,
65   vertical_size:16,
66   forward_reference_picture:0xffffffff,
67   backward_reference_picture:0xffffffff,
68   picture_coding_type:1,
69   f_code:0xffff,
70   {
71       {
72         intra_dc_precision:0,
73         picture_structure:3,
74         top_field_first:0,
75         frame_pred_frame_dct:1,
76         concealment_motion_vectors:0,
77         q_scale_type:0,
78         intra_vlc_format:0,
79         alternate_scan:0,
80         repeat_first_field:0,
81         progressive_frame:1 ,
82         is_first_field:1
83       },
84   }
85 };
86
87 /* see MPEG2 spec65 for the defines of matrix */
88 static VAIQMatrixBufferMPEG2 iq_matrix = {
89   load_intra_quantiser_matrix:1,
90   load_non_intra_quantiser_matrix:1,
91   load_chroma_intra_quantiser_matrix:0,
92   load_chroma_non_intra_quantiser_matrix:0,
93   intra_quantiser_matrix:{
94          8, 16, 16, 19, 16, 19, 22, 22,
95         22, 22, 22, 22, 26, 24, 26, 27,
96         27, 27, 26, 26, 26, 26, 27, 27,
97         27, 29, 29, 29, 34, 34, 34, 29,
98         29, 29, 27, 27, 29, 29, 32, 32,
99         34, 34, 37, 38, 37, 35, 35, 34,
100         35, 38, 38, 40, 40, 40, 48, 48,
101         46, 46, 56, 56, 58, 69, 69, 83
102     },
103   non_intra_quantiser_matrix:{16},
104   chroma_intra_quantiser_matrix:{0},
105   chroma_non_intra_quantiser_matrix:{0}
106 };
107
108 static VASliceParameterBufferMPEG2 slice_param={
109   slice_data_size:150,
110   slice_data_offset:0,
111   slice_data_flag:0,
112   macroblock_offset:38,/* 4byte + 6bits=38bits */
113   slice_vertical_position:0,
114   quantiser_scale_code:2,
115   intra_slice_flag:0
116 };
117
118 #define CLIP_WIDTH  16
119 #define CLIP_HEIGHT 16
120
121 int surf_width=CLIP_WIDTH,surf_height=CLIP_HEIGHT;
122 int win_width=CLIP_WIDTH<<1,win_height=CLIP_HEIGHT<<1;
123
124 void test()
125 {
126     VAEntrypoint entrypoints[5];
127     int num_entrypoints,vld_entrypoint;
128     VAConfigAttrib attrib;
129     VAConfigID config_id;
130     VASurfaceID vaSurface;
131     VAContextID vaContext;
132     VABufferID vaPicParamBuf,vaIQMatrixBuf,vaSliceParamBuf,vaSliceDataBuf;
133     Window win = 0;
134     
135     va_status = vaQueryConfigEntrypoints(va_dpy, VAProfileMPEG2Main, entrypoints, 
136                              &num_entrypoints);
137     ASSERT( VA_STATUS_SUCCESS == va_status );
138
139     for (vld_entrypoint = 0; vld_entrypoint < num_entrypoints; vld_entrypoint++) {
140         if (entrypoints[vld_entrypoint] == VAEntrypointVLD)
141             break;
142     }
143     if (vld_entrypoint == num_entrypoints) {
144         /* not find VLD entry point */
145         ASSERT(0);
146     }
147
148     /* Assuming finding VLD, find out the format for the render target */
149     attrib.type = VAConfigAttribRTFormat;
150     va_status = vaGetConfigAttributes(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD,
151                           &attrib, 1);
152     ASSERT( VA_STATUS_SUCCESS == va_status );
153     if ((attrib.value & VA_RT_FORMAT_YUV420) == 0) {
154         /* not find desired YUV420 RT format */
155         ASSERT(0);
156     }
157     
158     va_status = vaCreateConfig(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD,
159                               &attrib, 1,&config_id);
160     ASSERT( VA_STATUS_SUCCESS == va_status );
161     
162     va_status = vaCreateSurfaces(va_dpy,surf_width,surf_height,
163                                 VA_RT_FORMAT_YUV420, 1, &vaSurface);
164     ASSERT( VA_STATUS_SUCCESS == va_status );
165
166     /* Create a context for this decode pipe */
167     va_status = vaCreateContext(va_dpy, config_id,
168                                CLIP_WIDTH,
169                                ((CLIP_HEIGHT+15)/16)*16,
170                                VA_PROGRESSIVE,
171                                &vaSurface,
172                                1,
173                                &vaContext);
174     ASSERT( VA_STATUS_SUCCESS == va_status );
175     
176     va_status = vaCreateBuffer(va_dpy, vaContext,
177                               VAPictureParameterBufferType,
178                               sizeof(VAPictureParameterBufferMPEG2),
179                               1, &pic_param,
180                               &vaPicParamBuf);
181     ASSERT( VA_STATUS_SUCCESS == va_status );
182
183     va_status = vaCreateBuffer(va_dpy, vaContext,
184                               VAIQMatrixBufferType,
185                               sizeof(VAIQMatrixBufferMPEG2),
186                               1, &iq_matrix,
187                               &vaIQMatrixBuf );
188     ASSERT( VA_STATUS_SUCCESS == va_status );
189                 
190     va_status = vaCreateBuffer(va_dpy, vaContext,
191                               VASliceParameterBufferType,
192                               sizeof(VASliceParameterBufferMPEG2),
193                               1,
194                               &slice_param, &vaSliceParamBuf);
195     ASSERT( VA_STATUS_SUCCESS == va_status );
196
197     va_status = vaCreateBuffer(va_dpy, vaContext,
198                               VASliceDataBufferType,
199                               0xc4-0x2f+1,
200                               1,
201                               mpeg2_clip+0x2f,
202                               &vaSliceDataBuf);
203     ASSERT( VA_STATUS_SUCCESS == va_status );
204
205     va_status = vaBeginPicture(va_dpy, vaContext, vaSurface);
206     ASSERT( VA_STATUS_SUCCESS == va_status );
207     
208     va_status = vaRenderPicture(va_dpy,vaContext, &vaPicParamBuf, 1);
209     ASSERT( VA_STATUS_SUCCESS == va_status );
210
211     va_status = vaRenderPicture(va_dpy,vaContext, &vaIQMatrixBuf, 1);
212     ASSERT( VA_STATUS_SUCCESS == va_status );
213
214     va_status = vaRenderPicture(va_dpy,vaContext, &vaSliceParamBuf, 1);
215     ASSERT( VA_STATUS_SUCCESS == va_status );
216
217     va_status = vaRenderPicture(va_dpy,vaContext, &vaSliceDataBuf, 1);
218     ASSERT( VA_STATUS_SUCCESS == va_status );
219
220     va_status = vaEndPicture(va_dpy,vaContext);
221     ASSERT( VA_STATUS_SUCCESS == va_status );
222
223     va_status = vaSyncSurface(va_dpy, vaContext, vaSurface);
224     ASSERT( VA_STATUS_SUCCESS == va_status );
225     
226     win = XCreateSimpleWindow(dpy, RootWindow(dpy, 0), 0, 0,
227                               win_width,win_height, 0, 0, WhitePixel(dpy, 0));
228     XMapWindow(dpy, win);
229     XSync(dpy, False);
230
231 #if 0
232     va_status = vaPutSurface(va_dpy, vaSurface, win,
233                             0,0,surf_width,surf_height,
234                             0,0,win_width,win_height,
235                             NULL,0,0);
236 #endif
237     ASSERT( VA_STATUS_SUCCESS == va_status );
238
239     printf("press any key to exit\n");
240     getchar();
241     
242     vaDestroySurfaces(va_dpy,&vaSurface,1);
243     vaDestroyConfig(va_dpy,config_id);
244     vaDestroyContext(va_dpy,vaContext);
245 }
246
247 void post()
248 {
249     test_terminate();
250 }