OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2012 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, |
| 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 22 * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 */ |
| 24 |
| 25 //#define XT_DEBUG |
| 26 |
| 27 #include <cstdio> |
| 28 #include <getopt.h> |
| 29 #include <csignal> |
| 30 #include <cstring> |
| 31 #include <cstdarg> |
| 32 #include <X11/Xlib.h> |
| 33 #include <X11/Xutil.h> |
| 34 #include <cassert> |
| 35 #include <va/va_x11.h> |
| 36 #include <iostream> |
| 37 #include <cstdlib> |
| 38 |
| 39 #include "TCPSocketServer.h" |
| 40 using std::string; |
| 41 |
| 42 #define MYPROF VAProfileH264High |
| 43 |
| 44 int g_Debug = 0; |
| 45 int ip_port = 8888; |
| 46 TCPSocketServer *sock_ptr = NULL; |
| 47 #define SURFACE_NUM 7 |
| 48 static Display *win_display; |
| 49 static VADisplay va_dpy; |
| 50 Window win; |
| 51 int g_PX = 50; |
| 52 int g_PY = 0; |
| 53 bool g_LiveView = true; |
| 54 int pwm; |
| 55 int phm; |
| 56 VAContextID context_id; |
| 57 VASurfaceID surface_id[SURFACE_NUM]; |
| 58 int win_width = 0, win_height = 0; |
| 59 int surface_width = 0, surface_height = 0; |
| 60 static int time_to_quit = 0; |
| 61 |
| 62 static void SignalHandler(int a_Signal) |
| 63 { |
| 64 time_to_quit = 1; |
| 65 signal(SIGINT, SIG_DFL); |
| 66 } |
| 67 |
| 68 |
| 69 void InitSock() |
| 70 { |
| 71 try { |
| 72 sock_ptr = new TCPSocketServer(ip_port); |
| 73 } |
| 74 catch (const std::exception& e) |
| 75 { |
| 76 std::cerr << e.what() << '\n'; |
| 77 exit(1); |
| 78 } |
| 79 } |
| 80 |
| 81 |
| 82 |
| 83 |
| 84 /*currently, if XCheckWindowEvent was called in more than one thread, it would
cause |
| 85 * XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0" |
| 86 * after 87 requests (83 known processed) with 0 events remaining. |
| 87 * |
| 88 * X Error of failed request: BadGC (invalid GC parameter) |
| 89 * Major opcode of failed request: 60 (X_FreeGC) |
| 90 * Resource id in failed request: 0x600034 |
| 91 * Serial number of failed request: 398 |
| 92 * Current serial number in output stream: 399 |
| 93 * The root cause is unknown. */ |
| 94 |
| 95 VAStatus gva_status; |
| 96 VASurfaceStatus gsurface_status; |
| 97 #define CHECK_SURF(X) \ |
| 98 gva_status = vaQuerySurfaceStatus(va_dpy, X, &gsurface_status); \ |
| 99 if (gsurface_status != 4) printf("ss: %d\n", gsurface_status); |
| 100 |
| 101 |
| 102 |
| 103 #define CHECK_VASTATUS(va_status,func) \ |
| 104 if (va_status != VA_STATUS_SUCCESS) { \ |
| 105 fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \ |
| 106 exit(1); \ |
| 107 } else { \ |
| 108 /* fprintf(stderr,">> SUCCESS for: %s:%s (%d)\n", __func__, func, __LINE_
_); */ \ |
| 109 } |
| 110 |
| 111 void SetWindowTitle(const char* title, ...) |
| 112 { |
| 113 char buf[256]; |
| 114 va_list args; |
| 115 va_start(args, title); |
| 116 vsprintf(buf, title, args); |
| 117 va_end(args); |
| 118 XSetStandardProperties(win_display,win, buf, buf, None, NULL, 0, NULL); |
| 119 } |
| 120 |
| 121 |
| 122 #ifdef XT_DEBUG |
| 123 static inline void PrintFlagIfNotZero( |
| 124 const char *name, /* in */ |
| 125 unsigned int flag /* in */ |
| 126 ) |
| 127 { |
| 128 if (flag != 0) { |
| 129 printf("%s = %x\n", name, flag); |
| 130 } |
| 131 } |
| 132 |
| 133 void DumpVAPictureH264(VAPictureH264 *p, char *s) |
| 134 { |
| 135 printf("%s:\n", s); |
| 136 printf(" picture_id=0x%x\n", p->picture_id); |
| 137 printf(" frame_idx=%d\n", p->frame_idx); |
| 138 printf(" flags=%d\n", p->flags); |
| 139 printf(" TopFieldOrderCnt=%d\n", p->TopFieldOrderCnt); |
| 140 printf(" BottomFieldOrderCnt=%d\n", p->BottomFieldOrderCnt); |
| 141 } |
| 142 |
| 143 |
| 144 void DumpVAPictureParameterBufferH264(VAPictureParameterBufferH264 *p) |
| 145 { |
| 146 int i; |
| 147 printf("VAPictureParameterBufferH264\n"); |
| 148 printf("\tCurrPic.picture_id = 0x%08x\n", p->CurrPic.picture_id); |
| 149 printf("\tCurrPic.frame_idx = %d\n", p->CurrPic.frame_idx); |
| 150 printf("\tCurrPic.flags = %d\n", p->CurrPic.flags); |
| 151 printf("\tCurrPic.TopFieldOrderCnt = %d\n", p->CurrPic.TopFieldOrderCnt); |
| 152 printf("\tCurrPic.BottomFieldOrderCnt = %d\n", p->CurrPic.BottomFieldOrderCn
t); |
| 153 printf("\tReferenceFrames (TopFieldOrderCnt-BottomFieldOrderCnt-picture_id-f
rame_idx:\n"); |
| 154 for (i = 0; i < 16; i++) { |
| 155 if (p->ReferenceFrames[i].flags != VA_PICTURE_H264_INVALID) { |
| 156 printf("\t\t%d-%d-0x%08x-%d\n", |
| 157 p->ReferenceFrames[i].TopFieldOrderCnt, |
| 158 p->ReferenceFrames[i].BottomFieldOrderCnt, |
| 159 p->ReferenceFrames[i].picture_id, |
| 160 p->ReferenceFrames[i].frame_idx); |
| 161 } else { |
| 162 #ifdef EXTRA_LOGS |
| 163 printf("\t\tinv-inv-inv-inv\n"); |
| 164 #endif |
| 165 } |
| 166 } |
| 167 printf("\n"); |
| 168 printf("\tpicture_width_in_mbs_minus1 = %d\n", p->picture_width_in_mbs_minus
1); |
| 169 printf("\tpicture_height_in_mbs_minus1 = %d\n", p->picture_height_in_mbs_min
us1); |
| 170 printf("\tbit_depth_luma_minus8 = %d\n", p->bit_depth_luma_minus8); |
| 171 printf("\tbit_depth_chroma_minus8 = %d\n", p->bit_depth_chroma_minus8); |
| 172 printf("\tnum_ref_frames = %d\n", p->num_ref_frames); |
| 173 printf("\tseq fields = %d\n", p->seq_fields.value); |
| 174 printf("\tchroma_format_idc = %d\n", p->seq_fields.bits.chroma_format_idc); |
| 175 printf("\tresidual_colour_transform_flag = %d\n", p->seq_fields.bits.residua
l_colour_transform_flag); |
| 176 printf("\tframe_mbs_only_flag = %d\n", p->seq_fields.bits.frame_mbs_only_fla
g); |
| 177 printf("\tmb_adaptive_frame_field_flag = %d\n", p->seq_fields.bits.mb_adapti
ve_frame_field_flag); |
| 178 printf("\tdirect_8x8_inference_flag = %d\n", p->seq_fields.bits.direct_8x8_i
nference_flag); |
| 179 printf("\tMinLumaBiPredSize8x8 = %d\n", p->seq_fields.bits.MinLumaBiPredSize
8x8); |
| 180 printf("\tnum_slice_groups_minus1 = %d\n", p->num_slice_groups_minus1); |
| 181 printf("\tslice_group_map_type = %d\n", p->slice_group_map_type); |
| 182 printf("\tslice_group_change_rate_minus1 = %d\n", p->slice_group_change_rate
_minus1); |
| 183 printf("\tpic_init_qp_minus26 = %d\n", p->pic_init_qp_minus26); |
| 184 printf("\tpic_init_qs_minus26 = %d\n", p->pic_init_qs_minus26); |
| 185 printf("\tchroma_qp_index_offset = %d\n", p->chroma_qp_index_offset); |
| 186 printf("\tsecond_chroma_qp_index_offset = %d\n", p->second_chroma_qp_index_o
ffset); |
| 187 printf("\tpic_fields = 0x%03x\n", p->pic_fields.value); |
| 188 #ifdef EXTRA_LOGS |
| 189 PrintFlagIfNotZero("\t\tentropy_coding_mode_flag", p->pic_fields.bits.entrop
y_coding_mode_flag); |
| 190 PrintFlagIfNotZero("\t\tweighted_pred_flag", p->pic_fields.bits.weighted_pre
d_flag); |
| 191 PrintFlagIfNotZero("\t\tweighted_bipred_idc", p->pic_fields.bits.weighted_bi
pred_idc); |
| 192 PrintFlagIfNotZero("\t\ttransform_8x8_mode_flag", p->pic_fields.bits.transfo
rm_8x8_mode_flag); |
| 193 PrintFlagIfNotZero("\t\tfield_pic_flag", p->pic_fields.bits.field_pic_flag); |
| 194 PrintFlagIfNotZero("\t\tconstrained_intra_pred_flag", p->pic_fields.bits.con
strained_intra_pred_flag); |
| 195 PrintFlagIfNotZero("\t\tpic_order_present_flag", p->pic_fields.bits.pic_orde
r_present_flag); |
| 196 PrintFlagIfNotZero("\t\tdeblocking_filter_control_present_flag", p->pic_fiel
ds.bits.deblocking_filter_control_present_flag); |
| 197 PrintFlagIfNotZero("\t\tredundant_pic_cnt_present_flag", p->pic_fields.bits.
redundant_pic_cnt_present_flag); |
| 198 PrintFlagIfNotZero("\t\treference_pic_flag", p->pic_fields.bits.reference_pi
c_flag); |
| 199 #endif |
| 200 printf("\tframe_num = %d\n", p->frame_num); |
| 201 } |
| 202 #endif |
| 203 |
| 204 |
| 205 void SetVAPictureParameterBufferH264(VAPictureParameterBufferH264 *p) |
| 206 { |
| 207 int i; |
| 208 memset(p, 0, sizeof(VAPictureParameterBufferH264)); |
| 209 p->picture_width_in_mbs_minus1 = pwm; |
| 210 p->picture_height_in_mbs_minus1 = phm; |
| 211 p->num_ref_frames = 1; |
| 212 p->seq_fields.value = 145; |
| 213 /* |
| 214 p->seq_fields.bits.chroma_format_idc = 1; |
| 215 p->seq_fields.bits.frame_mbs_only_flag = 1; |
| 216 p->seq_fields.bits.MinLumaBiPredSize8x8 = 1; |
| 217 */ |
| 218 p->pic_fields.value = 0x501; |
| 219 for (i = 0; i < 16; i++) { |
| 220 p->ReferenceFrames[i].flags = VA_PICTURE_H264_INVALID; |
| 221 p->ReferenceFrames[i].picture_id = 0xffffffff; |
| 222 |
| 223 } |
| 224 } |
| 225 |
| 226 |
| 227 |
| 228 void SetVASliceParameterBufferH264(VASliceParameterBufferH264 *p) |
| 229 { |
| 230 int i; |
| 231 memset(p, 0, sizeof(VASliceParameterBufferH264)); |
| 232 p->slice_data_size = 0; |
| 233 p->slice_data_bit_offset = 64; |
| 234 p->slice_alpha_c0_offset_div2 = 2; |
| 235 p->slice_beta_offset_div2 = 2; |
| 236 p->chroma_weight_l0_flag = 1; |
| 237 p->chroma_weight_l0[0][0]=1; |
| 238 p->chroma_offset_l0[0][0]=0; |
| 239 p->chroma_weight_l0[0][1]=1; |
| 240 p->chroma_offset_l0[0][1]=0; |
| 241 p->luma_weight_l1_flag = 1; |
| 242 p->chroma_weight_l1_flag = 1; |
| 243 p->luma_weight_l0[0]=0x01; |
| 244 for (i = 0; i < 32; i++) { |
| 245 p->RefPicList0[i].flags = VA_PICTURE_H264_INVALID; |
| 246 p->RefPicList1[i].flags = VA_PICTURE_H264_INVALID; |
| 247 // p->ReferenceFrames[i].picture_id = 0xffffffff; |
| 248 } |
| 249 p->RefPicList1[0].picture_id = 0xffffffff; //0xaa0000bb; |
| 250 } |
| 251 |
| 252 |
| 253 |
| 254 void SetVASliceParameterBufferH264_T2(VASliceParameterBufferH264 *p, int first) |
| 255 { |
| 256 int i; |
| 257 memset(p, 0, sizeof(VASliceParameterBufferH264)); |
| 258 p->slice_data_size = 0; |
| 259 p->slice_data_bit_offset = 64; |
| 260 p->slice_alpha_c0_offset_div2 = 2; |
| 261 p->slice_beta_offset_div2 = 2; |
| 262 p->slice_type = 2; |
| 263 if (first) { |
| 264 p->luma_weight_l0_flag = 1; |
| 265 p->chroma_weight_l0_flag = 1; |
| 266 p->luma_weight_l1_flag = 1; |
| 267 p->chroma_weight_l1_flag = 1; |
| 268 } else { |
| 269 p->chroma_weight_l0_flag = 1; |
| 270 p->chroma_weight_l0[0][0]=1; |
| 271 p->chroma_offset_l0[0][0]=0; |
| 272 p->chroma_weight_l0[0][1]=1; |
| 273 p->chroma_offset_l0[0][1]=0; |
| 274 p->luma_weight_l1_flag = 1; |
| 275 p->chroma_weight_l1_flag = 1; |
| 276 p->luma_weight_l0[0]=0x01; |
| 277 } |
| 278 for (i = 0; i < 32; i++) { |
| 279 p->RefPicList0[i].flags = VA_PICTURE_H264_INVALID; |
| 280 p->RefPicList1[i].flags = VA_PICTURE_H264_INVALID; |
| 281 // p->ReferenceFrames[i].picture_id = 0xffffffff; |
| 282 } |
| 283 p->RefPicList1[0].picture_id = 0xffffffff; |
| 284 p->RefPicList0[0].picture_id = 0xffffffff; |
| 285 } |
| 286 |
| 287 |
| 288 unsigned char m_MatrixBufferH264[]= { |
| 289 //ScalingList4x4[6][16] |
| 290 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 291 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 292 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 293 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 294 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 295 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0
x10, |
| 296 //ScalingList8x8[2][64] |
| 297 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 298 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 299 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 300 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 301 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 302 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 303 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 304 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 305 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 306 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 307 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 308 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 309 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 310 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 311 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 312 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 |
| 313 }; |
| 314 |
| 315 #ifdef XT_DEBUG |
| 316 void DumpVASliceParameterBufferH264(VASliceParameterBufferH264 *p) |
| 317 { |
| 318 int i; |
| 319 printf("\telement[0] = VASliceParameterBufferH264\n"); |
| 320 printf("\tslice_data_size = %d\n", p->slice_data_size); |
| 321 printf("\tslice_data_offset = %d\n", p->slice_data_offset); |
| 322 printf("\tslice_data_flag = %d\n", p->slice_data_flag); |
| 323 printf("\tslice_data_bit_offset = %d\n", p->slice_data_bit_offset); |
| 324 printf("\tfirst_mb_in_slice = %d\n", p->first_mb_in_slice); |
| 325 printf("\tslice_type = %d\n", p->slice_type); |
| 326 printf("\tdirect_spatial_mv_pred_flag = %d\n", p->direct_spatial_mv_pred_fla
g); |
| 327 printf("\tnum_ref_idx_l0_active_minus1 = %d\n", p->num_ref_idx_l0_active_min
us1); |
| 328 printf("\tnum_ref_idx_l1_active_minus1 = %d\n", p->num_ref_idx_l1_active_min
us1); |
| 329 printf("\tcabac_init_idc = %d\n", p->cabac_init_idc); |
| 330 printf("\tslice_qp_delta = %d\n", p->slice_qp_delta); |
| 331 printf("\tdisable_deblocking_filter_idc = %d\n", p->disable_deblocking_filte
r_idc); |
| 332 printf("\tslice_alpha_c0_offset_div2 = %d\n", p->slice_alpha_c0_offset_div2)
; |
| 333 printf("\tslice_beta_offset_div2 = %d\n", p->slice_beta_offset_div2); |
| 334 if (p->slice_type == 0 || p->slice_type == 1) { |
| 335 printf("\tRefPicList0 ="); |
| 336 for (i = 0; i < p->num_ref_idx_l0_active_minus1 + 1; i++) { |
| 337 printf("%d-%d-0x%08x-%d\n", p->RefPicList0[i].TopFieldOrderCnt, p->RefPi
cList0[i].BottomFieldOrderCnt, p->RefPicList0[i].picture_id, p->RefPicList0[i].f
rame_idx); |
| 338 } |
| 339 if (p->slice_type == 1) { |
| 340 printf("\tRefPicList1 ="); |
| 341 for (i = 0; i < p->num_ref_idx_l1_active_minus1 + 1; i++) |
| 342 { |
| 343 printf("%d-%d-0x%08x-%d\n", p->RefPicList1[i].TopFieldOrderCnt, p->RefPi
cList1[i].BottomFieldOrderCnt, p->RefPicList1[i].picture_id, p->RefPicList1[i].f
rame_idx); |
| 344 } |
| 345 } |
| 346 } |
| 347 printf("\tluma_log2_weight_denom = %d\n", p->luma_log2_weight_denom); |
| 348 printf("\tchroma_log2_weight_denom = %d\n", p->chroma_log2_weight_denom); |
| 349 printf("\tluma_weight_l0_flag = %d\n", p->luma_weight_l0_flag); |
| 350 if (p->luma_weight_l0_flag) { |
| 351 for (i = 0; i <= p->num_ref_idx_l0_active_minus1; i++) { |
| 352 printf("\t%d ", p->luma_weight_l0[i]); |
| 353 printf("\t%d ", p->luma_offset_l0[i]); |
| 354 } |
| 355 printf("\n"); |
| 356 } |
| 357 printf("\tchroma_weight_l0_flag = %d\n", p->chroma_weight_l0_flag); |
| 358 if (p->chroma_weight_l0_flag) { |
| 359 for (i = 0; i <= p->num_ref_idx_l0_active_minus1; i++) { |
| 360 printf("\t\t%d ", p->chroma_weight_l0[i][0]); |
| 361 printf("\t\t%d ", p->chroma_offset_l0[i][0]); |
| 362 printf("\t\t%d ", p->chroma_weight_l0[i][1]); |
| 363 printf("\t\t%d ", p->chroma_offset_l0[i][1]); |
| 364 } |
| 365 printf("\n"); |
| 366 } |
| 367 printf("\tluma_weight_l1_flag = %d\n", p->luma_weight_l1_flag); |
| 368 if (p->luma_weight_l1_flag) { |
| 369 for (i = 0; i <= p->num_ref_idx_l1_active_minus1; i++) { |
| 370 printf("\t\t%d ", p->luma_weight_l1[i]); |
| 371 printf("\t\t%d ", p->luma_offset_l1[i]); |
| 372 } |
| 373 printf("\n"); |
| 374 } |
| 375 printf("\tchroma_weight_l1_flag = %d\n", p->chroma_weight_l1_flag); |
| 376 if (p->chroma_weight_l1_flag) { |
| 377 for (i = 0; i <= p->num_ref_idx_l1_active_minus1; i++) { |
| 378 printf("\t\t%d ", p->chroma_weight_l1[i][0]); |
| 379 printf("\t\t%d ", p->chroma_offset_l1[i][0]); |
| 380 printf("\t\t%d ", p->chroma_weight_l1[i][1]); |
| 381 printf("\t\t%d ", p->chroma_offset_l1[i][1]); |
| 382 } |
| 383 printf("\n"); |
| 384 } |
| 385 } |
| 386 #endif |
| 387 |
| 388 |
| 389 static void usage (FILE * fp, int argc, char ** argv) |
| 390 { |
| 391 fprintf (fp, |
| 392 "Usage: %s [options]\n" |
| 393 "\n" |
| 394 "Options:\n" |
| 395 "-?, --help Print this message\n" |
| 396 "-p, --port=PORT Listen port [%d]\n" |
| 397 "-l, --liveview-off Live View off\n" |
| 398 "-x, --posx=POS_X X position [WM handles placement]\n" |
| 399 "-y, --posy=POS_Y Y position [WM handles placement]\n" |
| 400 "-w, --width=WIDTH Window width [same as Surface]\n" |
| 401 "-h, --height=HEIGHT Window height [same as Surface]\n" |
| 402 "-d, --debug=LEVEL Debug level [%d]\n" |
| 403 "\n", |
| 404 argv[0], ip_port, g_Debug); |
| 405 } |
| 406 |
| 407 static const char short_options [] = "?p:lx:y:w:h:d:"; |
| 408 |
| 409 static const struct option |
| 410 long_options [] = { |
| 411 { "help", no_argument, NULL, '?' }, |
| 412 { "port", required_argument, NULL, 'p' }, |
| 413 { "liveview-off", no_argument, NULL, 'l' }, |
| 414 { "posx", required_argument, NULL, 'x' }, |
| 415 { "posy", required_argument, NULL, 'y' }, |
| 416 { "width", required_argument, NULL, 'w' }, |
| 417 { "height", required_argument, NULL, 'h' }, |
| 418 { "debug", required_argument, NULL, 'd' }, |
| 419 { 0, 0, 0, 0 } |
| 420 }; |
| 421 |
| 422 |
| 423 int main(int argc,char **argv) |
| 424 { |
| 425 int t2first = 1; |
| 426 int real_frame = 0; |
| 427 int slice_type = 2; |
| 428 int FieldOrderCnt = 0; |
| 429 int major_ver, minor_ver; |
| 430 int i; |
| 431 unsigned char frid = 0; |
| 432 int z; |
| 433 int sid = 0; |
| 434 int newsid = 0; |
| 435 unsigned int data_size = 0; |
| 436 unsigned int frame_count = 0; |
| 437 std::string remoteAddr; |
| 438 unsigned short remotePort; |
| 439 char *dh264 = NULL; |
| 440 int num_entrypoints,vld_entrypoint; |
| 441 VAStatus va_status; |
| 442 VAIQMatrixBufferH264 *mh264 = NULL; |
| 443 VAPictureParameterBufferH264 *ph264 = NULL; |
| 444 VASliceParameterBufferH264 *sh264 = NULL; |
| 445 VABufferID bufids[10]; |
| 446 VAEntrypoint entrypoints[5]; |
| 447 VAConfigAttrib attrib; |
| 448 VAConfigID config_id; |
| 449 VABufferID pic_param_buf_id[SURFACE_NUM]; |
| 450 VABufferID mat_param_buf_id[SURFACE_NUM]; |
| 451 VABufferID sp_param_buf_id[SURFACE_NUM]; |
| 452 VABufferID d_param_buf_id[SURFACE_NUM]; |
| 453 VAPictureH264 my_VAPictureH264; |
| 454 VAPictureH264 my_old_VAPictureH264; |
| 455 |
| 456 |
| 457 for (;;) { |
| 458 int index; |
| 459 int c; |
| 460 |
| 461 c = getopt_long (argc, argv, |
| 462 short_options, long_options, |
| 463 &index); |
| 464 |
| 465 if (-1 == c) |
| 466 break; |
| 467 |
| 468 switch (c) { |
| 469 case 0: /* getopt_long() flag */ |
| 470 break; |
| 471 |
| 472 case '?': |
| 473 usage (stdout, argc, argv); |
| 474 exit (EXIT_SUCCESS); |
| 475 case 'p': |
| 476 ip_port = atoi(optarg); |
| 477 break; |
| 478 case 'l': |
| 479 g_LiveView = false; |
| 480 break; |
| 481 case 'x': |
| 482 g_PX = atoi(optarg); |
| 483 break; |
| 484 case 'y': |
| 485 g_PY = atoi(optarg); |
| 486 break; |
| 487 case 'w': |
| 488 win_width = atoi(optarg); |
| 489 break; |
| 490 case 'h': |
| 491 win_height = atoi(optarg); |
| 492 break; |
| 493 case 'd': |
| 494 g_Debug = atoi(optarg); |
| 495 break; |
| 496 default: |
| 497 usage (stderr, argc, argv); |
| 498 exit (EXIT_FAILURE); |
| 499 } |
| 500 } |
| 501 |
| 502 InitSock(); |
| 503 |
| 504 printf("Accept - start\n"); |
| 505 sock_ptr->accept(remoteAddr, remotePort); |
| 506 printf("Accept - done (%s:%d)\n", remoteAddr.c_str(), remotePort); |
| 507 |
| 508 surface_width = sock_ptr->recv_uint32(); |
| 509 surface_height = sock_ptr->recv_uint32(); |
| 510 if (!win_width) { |
| 511 win_width = surface_width; |
| 512 } |
| 513 if (!win_height) { |
| 514 win_height = surface_height; |
| 515 } |
| 516 pwm = sock_ptr->recv_uint32(); |
| 517 phm = sock_ptr->recv_uint32(); |
| 518 |
| 519 win_display = (Display *)XOpenDisplay(":0.0"); |
| 520 if (win_display == NULL) { |
| 521 fprintf(stderr, "Can't open the connection of display!\n"); |
| 522 exit(-1); |
| 523 } |
| 524 if (g_LiveView) { |
| 525 win = XCreateSimpleWindow(win_display, RootWindow(win_display, 0), 0, 0, win
_width, win_height, 0, 0, WhitePixel(win_display, 0)); |
| 526 XMapWindow(win_display, win); |
| 527 SetWindowTitle("Decode H264 (%dx%d in %dx%d) TCP", surface_width,surface_hei
ght, win_width, win_height); |
| 528 if ((g_PX !=-1) && (g_PY !=-1)) { |
| 529 XMoveWindow(win_display, win, g_PX, g_PY); |
| 530 } |
| 531 XSync(win_display, False); |
| 532 } |
| 533 if(signal(SIGINT, SignalHandler) == SIG_ERR) { |
| 534 printf("signal() failed\n"); |
| 535 time_to_quit = 1; |
| 536 exit(-1); |
| 537 } |
| 538 va_dpy = vaGetDisplay(win_display); |
| 539 va_status = vaInitialize(va_dpy, &major_ver, &minor_ver); |
| 540 CHECK_VASTATUS(va_status, "vaInitialize"); |
| 541 |
| 542 va_status = vaQueryConfigEntrypoints(va_dpy, MYPROF, entrypoints, &num_entry
points); |
| 543 CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints"); |
| 544 for (vld_entrypoint = 0; vld_entrypoint < num_entrypoints; vld_entrypoint++)
{ |
| 545 if (entrypoints[vld_entrypoint] == VAEntrypointVLD) |
| 546 break; |
| 547 } |
| 548 if (vld_entrypoint == num_entrypoints) { |
| 549 /* not find VLD entry point */ |
| 550 assert(0); |
| 551 } |
| 552 /* Assuming finding VLD, find out the format for the render target */ |
| 553 attrib.type = VAConfigAttribRTFormat; |
| 554 vaGetConfigAttributes(va_dpy, MYPROF, VAEntrypointVLD, &attrib, 1); |
| 555 if ((attrib.value & VA_RT_FORMAT_YUV420) == 0) { |
| 556 /* not find desired YUV420 RT format */ |
| 557 assert(0); |
| 558 } |
| 559 CHECK_VASTATUS(va_status, "vaGetConfigAttributes"); |
| 560 va_status = vaCreateConfig(va_dpy, MYPROF, VAEntrypointVLD, &attrib, 1,&conf
ig_id); |
| 561 CHECK_VASTATUS(va_status, "vaCreateConfig"); |
| 562 va_status = vaCreateSurfaces(va_dpy,surface_width,surface_height,VA_RT_FORMA
T_YUV420, SURFACE_NUM, &surface_id[0]); |
| 563 CHECK_VASTATUS(va_status, "vaCreateSurfaces"); |
| 564 va_status = vaCreateContext(va_dpy, config_id, surface_width,surface_height,
0/*VA_PROGRESSIVE*/, &surface_id[0], SURFACE_NUM, &context_id); |
| 565 CHECK_VASTATUS(va_status, "vaCreateContext"); |
| 566 for(i=0; i<SURFACE_NUM; i++) { |
| 567 pic_param_buf_id[i] = VA_INVALID_ID; |
| 568 mat_param_buf_id[i] = VA_INVALID_ID; |
| 569 sp_param_buf_id[i] = VA_INVALID_ID; |
| 570 d_param_buf_id[i] = VA_INVALID_ID; |
| 571 } |
| 572 va_status = vaBeginPicture(va_dpy, context_id, surface_id[sid]); |
| 573 CHECK_VASTATUS(va_status, "vaBeginPicture"); |
| 574 if (g_Debug) { |
| 575 printf("--- Loop start here....\n"); |
| 576 } |
| 577 while(!time_to_quit) { |
| 578 frame_count = sock_ptr->recv_uint32(); |
| 579 slice_type = sock_ptr->recv_uint32(); |
| 580 switch(slice_type) { |
| 581 case 0: |
| 582 case 2: |
| 583 break; |
| 584 default: |
| 585 printf("Wrong type: %d\n", slice_type); |
| 586 exit(-1); |
| 587 break; |
| 588 } |
| 589 data_size = sock_ptr->recv_uint32(); |
| 590 if (g_Debug) { |
| 591 printf("T=%d S=%8d [%8d]\n", slice_type, data_size, frame_count); |
| 592 } |
| 593 my_VAPictureH264.picture_id = surface_id[sid]; |
| 594 my_VAPictureH264.frame_idx = frid; |
| 595 my_VAPictureH264.flags = 0; |
| 596 my_VAPictureH264.BottomFieldOrderCnt = FieldOrderCnt; |
| 597 my_VAPictureH264.TopFieldOrderCnt = FieldOrderCnt; |
| 598 if (pic_param_buf_id[sid] == VA_INVALID_ID) { |
| 599 va_status = vaCreateBuffer(va_dpy, context_id, VAPictureParameterBufferT
ype, sizeof(VAPictureParameterBufferH264), 1, NULL, &pic_param_buf_id[sid]); |
| 600 } |
| 601 CHECK_VASTATUS(va_status, "vaCreateBuffer"); |
| 602 CHECK_SURF(surface_id[sid]); |
| 603 va_status = vaMapBuffer(va_dpy,pic_param_buf_id[sid],(void **)&ph264); |
| 604 CHECK_VASTATUS(va_status, "vaMapBuffer"); |
| 605 SetVAPictureParameterBufferH264(ph264); |
| 606 memcpy(&ph264->CurrPic, &my_VAPictureH264, sizeof(VAPictureH264)); |
| 607 if (slice_type == 2) { |
| 608 } else { |
| 609 memcpy(&ph264->ReferenceFrames[0], &my_old_VAPictureH264, sizeof(VAPictu
reH264)); |
| 610 ph264->ReferenceFrames[0].flags = 0; |
| 611 } |
| 612 ph264->frame_num = frid; |
| 613 |
| 614 #ifdef XT_DEBUG |
| 615 DumpVAPictureParameterBufferH264(ph264); |
| 616 #endif |
| 617 va_status = vaUnmapBuffer(va_dpy,pic_param_buf_id[sid]); |
| 618 CHECK_VASTATUS(va_status, "vaUnmapBuffer"); |
| 619 |
| 620 if (mat_param_buf_id[sid] == VA_INVALID_ID) { |
| 621 va_status = vaCreateBuffer(va_dpy, context_id, VAIQMatrixBufferType, siz
eof(VAIQMatrixBufferH264), 1, NULL, &mat_param_buf_id[sid]); |
| 622 CHECK_VASTATUS(va_status, "vaCreateBuffer"); |
| 623 } |
| 624 CHECK_SURF(surface_id[sid]); |
| 625 va_status = vaMapBuffer(va_dpy, mat_param_buf_id[sid], (void **)&mh264); |
| 626 CHECK_VASTATUS(va_status, "vaMapBuffer"); |
| 627 memcpy(mh264, m_MatrixBufferH264, 224); |
| 628 va_status = vaUnmapBuffer(va_dpy, mat_param_buf_id[sid]); |
| 629 CHECK_VASTATUS(va_status, "vaUnmapBuffer"); |
| 630 bufids[0] = pic_param_buf_id[sid]; |
| 631 bufids[1] = mat_param_buf_id[sid]; |
| 632 CHECK_SURF(surface_id[sid]); |
| 633 va_status = vaRenderPicture(va_dpy, context_id, bufids, 2); |
| 634 CHECK_VASTATUS(va_status, "vaRenderPicture"); |
| 635 if (sp_param_buf_id[sid] == VA_INVALID_ID) { |
| 636 va_status = vaCreateBuffer(va_dpy, context_id, VASliceParameterBufferTyp
e, sizeof(VASliceParameterBufferH264), 1, NULL, &sp_param_buf_id[sid]); |
| 637 CHECK_VASTATUS(va_status, "vaCreateBuffer"); |
| 638 } |
| 639 CHECK_SURF(surface_id[sid]); |
| 640 va_status = vaMapBuffer(va_dpy, sp_param_buf_id[sid], (void **)&sh264); |
| 641 CHECK_VASTATUS(va_status, "vaMapBuffer"); |
| 642 if (slice_type == 2) { |
| 643 SetVASliceParameterBufferH264_T2(sh264, t2first); |
| 644 t2first = 0; |
| 645 } else { |
| 646 SetVASliceParameterBufferH264(sh264); |
| 647 memcpy(&sh264->RefPicList0[0], &my_old_VAPictureH264, sizeof(VAPictureH2
64)); |
| 648 sh264->RefPicList0[0].flags = 0; |
| 649 } |
| 650 sh264->slice_data_bit_offset = 0; |
| 651 sh264->slice_data_size = data_size; |
| 652 #ifdef XT_DEBUG |
| 653 DumpVASliceParameterBufferH264(sh264); |
| 654 #endif |
| 655 va_status = vaUnmapBuffer(va_dpy, sp_param_buf_id[sid]); |
| 656 CHECK_VASTATUS(va_status, "vaUnmapBuffer"); |
| 657 CHECK_SURF(surface_id[sid]); |
| 658 if (d_param_buf_id[sid] == VA_INVALID_ID) { |
| 659 va_status = vaCreateBuffer(va_dpy, context_id, VASliceDataBufferType, 41
77920, 1, NULL, &d_param_buf_id[sid]); // 1080p size |
| 660 CHECK_VASTATUS(va_status, "vaCreateBuffer"); |
| 661 } |
| 662 va_status = vaMapBuffer(va_dpy, d_param_buf_id[sid], (void **)&dh264); |
| 663 CHECK_VASTATUS(va_status, "vaMapBuffer"); |
| 664 sock_ptr->recv_data((unsigned char*)dh264, data_size); |
| 665 CHECK_SURF(surface_id[sid]); |
| 666 va_status = vaUnmapBuffer(va_dpy, d_param_buf_id[sid]); |
| 667 CHECK_VASTATUS(va_status, "vaUnmapBuffer"); |
| 668 bufids[0] = sp_param_buf_id[sid]; |
| 669 bufids[1] = d_param_buf_id[sid]; |
| 670 CHECK_SURF(surface_id[sid]); |
| 671 va_status = vaRenderPicture(va_dpy, context_id, bufids, 2); |
| 672 CHECK_VASTATUS(va_status, "vaRenderPicture"); |
| 673 va_status = vaEndPicture(va_dpy, context_id); |
| 674 CHECK_VASTATUS(va_status, "vaEndPicture"); |
| 675 newsid = sid+1; |
| 676 if (newsid==SURFACE_NUM) { |
| 677 newsid = 0; |
| 678 } |
| 679 va_status = vaBeginPicture(va_dpy, context_id, surface_id[newsid]); |
| 680 CHECK_VASTATUS(va_status, "vaBeginPicture"); |
| 681 va_status = vaSyncSurface(va_dpy, surface_id[sid]); |
| 682 CHECK_VASTATUS(va_status, "vaSyncSurface"); |
| 683 CHECK_SURF(surface_id[sid]); |
| 684 if (g_LiveView) { |
| 685 va_status = vaPutSurface(va_dpy, surface_id[sid], win, 0, 0, surface_wid
th, surface_height, 0, 0, win_width, win_height, NULL, 0, VA_FRAME_PICTURE); |
| 686 CHECK_VASTATUS(va_status, "vaPutSurface"); |
| 687 } |
| 688 sid = newsid; |
| 689 frid++; |
| 690 if (frid>15) frid = 0; |
| 691 FieldOrderCnt+=2; |
| 692 memcpy(&my_old_VAPictureH264, &my_VAPictureH264, sizeof(VAPictureH264)); |
| 693 real_frame ++; |
| 694 } |
| 695 if (g_Debug) { |
| 696 printf("Final !\n"); |
| 697 } |
| 698 vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM); |
| 699 vaTerminate(va_dpy); |
| 700 XCloseDisplay(win_display); |
| 701 delete sock_ptr; |
| 702 |
| 703 return 0; |
| 704 } |
OLD | NEW |