Lines Matching refs:ctx

280 sps_rbsp(struct mpeg2enc_context *ctx,  in sps_rbsp()  argument
286 if (ctx->new_sequence) { in sps_rbsp()
318 if (ctx->new_gop_header) { in sps_rbsp()
402 build_packed_seq_buffer(struct mpeg2enc_context *ctx, in build_packed_seq_buffer() argument
409 sps_rbsp(ctx, seq_param, &bs); in build_packed_seq_buffer()
434 struct mpeg2enc_context *ctx = data; in upload_yuv_to_surface() local
440 int y_size = ctx->width * ctx->height; in upload_yuv_to_surface()
441 int u_size = (ctx->width >> 1) * (ctx->height >> 1); in upload_yuv_to_surface()
446 n_items = fread(ctx->frame_data_buffer, ctx->frame_size, 1, ctx->ifp); in upload_yuv_to_surface()
449 … va_status = vaDeriveImage(ctx->va_dpy, surface_ids[ctx->current_upload_surface], &surface_image); in upload_yuv_to_surface()
452 vaMapBuffer(ctx->va_dpy, surface_image.buf, &surface_p); in upload_yuv_to_surface()
455 y_src = ctx->frame_data_buffer; in upload_yuv_to_surface()
456 u_src = ctx->frame_data_buffer + y_size; /* UV offset for NV12 */ in upload_yuv_to_surface()
457 v_src = ctx->frame_data_buffer + y_size + u_size; in upload_yuv_to_surface()
467 y_src += ctx->width; in upload_yuv_to_surface()
478 u_src += (ctx->width / 2); in upload_yuv_to_surface()
479 v_src += (ctx->width / 2); in upload_yuv_to_surface()
490 u_src += (ctx->width / 2); in upload_yuv_to_surface()
491 v_src += (ctx->width / 2); in upload_yuv_to_surface()
495 vaUnmapBuffer(ctx->va_dpy, surface_image.buf); in upload_yuv_to_surface()
496 vaDestroyImage(ctx->va_dpy, surface_image.image_id); in upload_yuv_to_surface()
502 mpeg2enc_exit(struct mpeg2enc_context *ctx, int exit_code) in mpeg2enc_exit() argument
504 if (ctx->frame_data_buffer) { in mpeg2enc_exit()
505 free(ctx->frame_data_buffer); in mpeg2enc_exit()
506 ctx->frame_data_buffer = NULL; in mpeg2enc_exit()
509 if (ctx->ifp) { in mpeg2enc_exit()
510 fclose(ctx->ifp); in mpeg2enc_exit()
511 ctx->ifp = NULL; in mpeg2enc_exit()
514 if (ctx->ofp) { in mpeg2enc_exit()
515 fclose(ctx->ofp); in mpeg2enc_exit()
516 ctx->ofp = NULL; in mpeg2enc_exit()
541 mpeg2_profile_level(struct mpeg2enc_context *ctx, in mpeg2_profile_level() argument
549 if (ctx->width <= mpeg2_upper_samplings[p][l].samplers_per_line && in mpeg2_profile_level()
550 ctx->height <= mpeg2_upper_samplings[p][l].line_per_frame && in mpeg2_profile_level()
551 ctx->fps <= mpeg2_upper_samplings[p][l].frame_per_sec) { in mpeg2_profile_level()
566 ctx->profile = mpeg2_va_profiles[p]; in mpeg2_profile_level()
567 ctx->level = l; in mpeg2_profile_level()
571 parse_args(struct mpeg2enc_context *ctx, int argc, char **argv) in parse_args() argument
592 ctx->width = atoi(argv[1]); in parse_args()
593 ctx->height = atoi(argv[2]); in parse_args()
595 if (ctx->width <= 0 || ctx->height <= 0) { in parse_args()
600 ctx->ifp = fopen(argv[3], "rb"); in parse_args()
602 if (ctx->ifp == NULL) { in parse_args()
607 fseek(ctx->ifp, 0l, SEEK_END); in parse_args()
608 file_size = ftell(ctx->ifp); in parse_args()
609 ctx->frame_size = ctx->width * ctx->height * 3 / 2; in parse_args()
611 if ((file_size < ctx->frame_size) || in parse_args()
612 (file_size % ctx->frame_size)) { in parse_args()
613 …rr, "The input file size %ld isn't a multiple of the frame size %d\n", file_size, ctx->frame_size); in parse_args()
617 ctx->num_pictures = file_size / ctx->frame_size; in parse_args()
618 fseek(ctx->ifp, 0l, SEEK_SET); in parse_args()
620 ctx->ofp = fopen(argv[4], "wb"); in parse_args()
622 if (ctx->ofp == NULL) { in parse_args()
628 ctx->fps = 30; in parse_args()
629 ctx->qp = 8; in parse_args()
630 ctx->rate_control_mode = VA_RC_CQP; in parse_args()
631 ctx->mode = MPEG2_MODE_IP; in parse_args()
632 ctx->profile = VAProfileMPEG2Main; in parse_args()
633 ctx->level = MPEG2_LEVEL_MAIN; in parse_args()
656 ctx->qp = tmp & 0xFE; in parse_args()
657 ctx->rate_control_mode = VA_RC_CQP; in parse_args()
667 ctx->fps = tmp; in parse_args()
669 ctx->rate_control_mode = VA_RC_CBR; in parse_args()
679 ctx->mode = tmp; in parse_args()
711 mpeg2_profile_level(ctx, profile, level); in parse_args()
718 mpeg2enc_exit(ctx, 1); in parse_args()
725 mpeg2enc_init_sequence_parameter(struct mpeg2enc_context *ctx, in mpeg2enc_init_sequence_parameter() argument
730 switch (ctx->profile) { in mpeg2enc_init_sequence_parameter()
744 switch (ctx->level) { in mpeg2enc_init_sequence_parameter()
762 seq_param->intra_period = ctx->intra_period; in mpeg2enc_init_sequence_parameter()
763 seq_param->ip_period = ctx->ip_period; /* FIXME: ??? */ in mpeg2enc_init_sequence_parameter()
764 seq_param->picture_width = ctx->width; in mpeg2enc_init_sequence_parameter()
765 seq_param->picture_height = ctx->height; in mpeg2enc_init_sequence_parameter()
767 if (ctx->bit_rate > 0) in mpeg2enc_init_sequence_parameter()
768 seq_param->bits_per_second = 1024 * ctx->bit_rate; /* use kbps as input */ in mpeg2enc_init_sequence_parameter()
772 seq_param->frame_rate = ctx->fps; in mpeg2enc_init_sequence_parameter()
789 mpeg2enc_init_picture_parameter(struct mpeg2enc_context *ctx, in mpeg2enc_init_picture_parameter() argument
818 mpeg2enc_alloc_va_resources(struct mpeg2enc_context *ctx) in mpeg2enc_alloc_va_resources() argument
826 ctx->va_dpy = va_open_display(); in mpeg2enc_alloc_va_resources()
827 va_status = vaInitialize(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
832 max_entrypoints = vaMaxNumEntrypoints(ctx->va_dpy); in mpeg2enc_alloc_va_resources()
834 vaQueryConfigEntrypoints(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
835 ctx->profile, in mpeg2enc_alloc_va_resources()
854 vaGetConfigAttributes(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
855 ctx->profile, in mpeg2enc_alloc_va_resources()
865 if ((attrib_list[1].value & ctx->rate_control_mode) == 0) { in mpeg2enc_alloc_va_resources()
867 fprintf(stderr, "RC mode %d isn't found, exit\n", ctx->rate_control_mode); in mpeg2enc_alloc_va_resources()
872 attrib_list[1].value = ctx->rate_control_mode; /* set to desired RC mode */ in mpeg2enc_alloc_va_resources()
874 va_status = vaCreateConfig(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
875 ctx->profile, in mpeg2enc_alloc_va_resources()
879 &ctx->config_id); in mpeg2enc_alloc_va_resources()
883 va_status = vaCreateContext(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
884 ctx->config_id, in mpeg2enc_alloc_va_resources()
885 ctx->width, in mpeg2enc_alloc_va_resources()
886 ctx->height, in mpeg2enc_alloc_va_resources()
890 &ctx->context_id); in mpeg2enc_alloc_va_resources()
893 va_status = vaCreateSurfaces(ctx->va_dpy, in mpeg2enc_alloc_va_resources()
895 ctx->width, in mpeg2enc_alloc_va_resources()
896 ctx->height, in mpeg2enc_alloc_va_resources()
905 mpeg2enc_init(struct mpeg2enc_context *ctx) in mpeg2enc_init() argument
909 ctx->frame_data_buffer = (unsigned char *)malloc(ctx->frame_size); in mpeg2enc_init()
910 ctx->seq_param_buf_id = VA_INVALID_ID; in mpeg2enc_init()
911 ctx->pic_param_buf_id = VA_INVALID_ID; in mpeg2enc_init()
912 ctx->packed_seq_header_param_buf_id = VA_INVALID_ID; in mpeg2enc_init()
913 ctx->packed_seq_buf_id = VA_INVALID_ID; in mpeg2enc_init()
914 ctx->packed_pic_header_param_buf_id = VA_INVALID_ID; in mpeg2enc_init()
915 ctx->packed_pic_buf_id = VA_INVALID_ID; in mpeg2enc_init()
916 ctx->codedbuf_buf_id = VA_INVALID_ID; in mpeg2enc_init()
917 ctx->codedbuf_i_size = ctx->frame_size; in mpeg2enc_init()
918 ctx->codedbuf_pb_size = 0; in mpeg2enc_init()
919 ctx->next_display_order = 0; in mpeg2enc_init()
920 ctx->next_type = VAEncPictureTypeIntra; in mpeg2enc_init()
922 if (ctx->mode == MPEG2_MODE_I) { in mpeg2enc_init()
923 ctx->intra_period = 1; in mpeg2enc_init()
924 ctx->ip_period = 0; in mpeg2enc_init()
925 } else if (ctx->mode == MPEG2_MODE_IP) { in mpeg2enc_init()
926 ctx->intra_period = 16; in mpeg2enc_init()
927 ctx->ip_period = 0; in mpeg2enc_init()
929 ctx->intra_period = 16; in mpeg2enc_init()
930 ctx->ip_period = 2; in mpeg2enc_init()
933 ctx->next_bframes = ctx->ip_period; in mpeg2enc_init()
935 ctx->new_sequence = 1; in mpeg2enc_init()
936 ctx->new_gop_header = 1; in mpeg2enc_init()
937 ctx->gop_header_in_display_order = 0; in mpeg2enc_init()
939 ctx->bit_rate = -1; in mpeg2enc_init()
942 ctx->slice_param_buf_id[i] = VA_INVALID_ID; in mpeg2enc_init()
945 mpeg2enc_init_sequence_parameter(ctx, &ctx->seq_param); in mpeg2enc_init()
946 mpeg2enc_init_picture_parameter(ctx, &ctx->pic_param); in mpeg2enc_init()
947 mpeg2enc_alloc_va_resources(ctx); in mpeg2enc_init()
950 ctx->current_input_surface = SID_INPUT_PICTURE_0; in mpeg2enc_init()
951 ctx->current_upload_surface = SID_INPUT_PICTURE_1; in mpeg2enc_init()
952 ctx->upload_thread_value = pthread_create(&ctx->upload_thread_id, in mpeg2enc_init()
955 ctx); in mpeg2enc_init()
995 mpeg2enc_update_sequence_parameter(struct mpeg2enc_context *ctx, in mpeg2enc_update_sequence_parameter() argument
1000 VAEncSequenceParameterBufferMPEG2 *seq_param = &ctx->seq_param; in mpeg2enc_update_sequence_parameter()
1003 if (ctx->new_gop_header) { in mpeg2enc_update_sequence_parameter()
1009 mpeg2enc_update_picture_parameter(struct mpeg2enc_context *ctx, in mpeg2enc_update_picture_parameter() argument
1014 VAEncPictureParameterBufferMPEG2 *pic_param = &ctx->pic_param; in mpeg2enc_update_picture_parameter()
1017 pic_param->temporal_reference = (display_order - ctx->gop_header_in_display_order) & 0x3FF; in mpeg2enc_update_picture_parameter()
1050 mpeg2enc_update_picture_parameter_buffer(struct mpeg2enc_context *ctx, in mpeg2enc_update_picture_parameter_buffer() argument
1055 VAEncPictureParameterBufferMPEG2 *pic_param = &ctx->pic_param; in mpeg2enc_update_picture_parameter_buffer()
1059 pic_param->coded_buf = ctx->codedbuf_buf_id; in mpeg2enc_update_picture_parameter_buffer()
1060 va_status = vaCreateBuffer(ctx->va_dpy, in mpeg2enc_update_picture_parameter_buffer()
1061 ctx->context_id, in mpeg2enc_update_picture_parameter_buffer()
1066 &ctx->pic_param_buf_id); in mpeg2enc_update_picture_parameter_buffer()
1071 mpeg2enc_update_slice_parameter(struct mpeg2enc_context *ctx, VAEncPictureType picture_type) in mpeg2enc_update_slice_parameter() argument
1079 pic_param = &ctx->pic_param; in mpeg2enc_update_slice_parameter()
1082 seq_param = &ctx->seq_param; in mpeg2enc_update_slice_parameter()
1085 ctx->num_slice_groups = 1; in mpeg2enc_update_slice_parameter()
1088 slice_param = &ctx->slice_param[i]; in mpeg2enc_update_slice_parameter()
1092 slice_param->quantiser_scale_code = ctx->qp / 2; in mpeg2enc_update_slice_parameter()
1095 va_status = vaCreateBuffer(ctx->va_dpy, in mpeg2enc_update_slice_parameter()
1096 ctx->context_id, in mpeg2enc_update_slice_parameter()
1100 ctx->slice_param, in mpeg2enc_update_slice_parameter()
1101 ctx->slice_param_buf_id); in mpeg2enc_update_slice_parameter()
1106 begin_picture(struct mpeg2enc_context *ctx, in begin_picture() argument
1117 if (ctx->upload_thread_value != 0) { in begin_picture()
1122 pthread_join(ctx->upload_thread_id, NULL); in begin_picture()
1124 ctx->upload_thread_value = -1; in begin_picture()
1125 tmp = ctx->current_input_surface; in begin_picture()
1126 ctx->current_input_surface = ctx->current_upload_surface; in begin_picture()
1127 ctx->current_upload_surface = tmp; in begin_picture()
1129 mpeg2enc_update_sequence_parameter(ctx, picture_type, coded_order, display_order); in begin_picture()
1130 mpeg2enc_update_picture_parameter(ctx, picture_type, coded_order, display_order); in begin_picture()
1132 if (ctx->new_sequence || ctx->new_gop_header) { in begin_picture()
1134 length_in_bits = build_packed_seq_buffer(ctx, &ctx->seq_param, &packed_seq_buffer); in begin_picture()
1138 va_status = vaCreateBuffer(ctx->va_dpy, in begin_picture()
1139 ctx->context_id, in begin_picture()
1142 &ctx->packed_seq_header_param_buf_id); in begin_picture()
1145 va_status = vaCreateBuffer(ctx->va_dpy, in begin_picture()
1146 ctx->context_id, in begin_picture()
1149 &ctx->packed_seq_buf_id); in begin_picture()
1155 length_in_bits = build_packed_pic_buffer(&ctx->seq_param, &ctx->pic_param, &packed_pic_buffer); in begin_picture()
1160 va_status = vaCreateBuffer(ctx->va_dpy, in begin_picture()
1161 ctx->context_id, in begin_picture()
1164 &ctx->packed_pic_header_param_buf_id); in begin_picture()
1167 va_status = vaCreateBuffer(ctx->va_dpy, in begin_picture()
1168 ctx->context_id, in begin_picture()
1171 &ctx->packed_pic_buf_id); in begin_picture()
1177 VAEncSequenceParameterBufferMPEG2 *seq_param = &ctx->seq_param; in begin_picture()
1178 va_status = vaCreateBuffer(ctx->va_dpy, in begin_picture()
1179 ctx->context_id, in begin_picture()
1184 &ctx->seq_param_buf_id); in begin_picture()
1188 mpeg2enc_update_slice_parameter(ctx, picture_type); in begin_picture()
1194 mpeg2enc_render_picture(struct mpeg2enc_context *ctx) in mpeg2enc_render_picture() argument
1200 va_buffers[num_va_buffers++] = ctx->seq_param_buf_id; in mpeg2enc_render_picture()
1201 va_buffers[num_va_buffers++] = ctx->pic_param_buf_id; in mpeg2enc_render_picture()
1203 if (ctx->packed_seq_header_param_buf_id != VA_INVALID_ID) in mpeg2enc_render_picture()
1204 va_buffers[num_va_buffers++] = ctx->packed_seq_header_param_buf_id; in mpeg2enc_render_picture()
1206 if (ctx->packed_seq_buf_id != VA_INVALID_ID) in mpeg2enc_render_picture()
1207 va_buffers[num_va_buffers++] = ctx->packed_seq_buf_id; in mpeg2enc_render_picture()
1209 if (ctx->packed_pic_header_param_buf_id != VA_INVALID_ID) in mpeg2enc_render_picture()
1210 va_buffers[num_va_buffers++] = ctx->packed_pic_header_param_buf_id; in mpeg2enc_render_picture()
1212 if (ctx->packed_pic_buf_id != VA_INVALID_ID) in mpeg2enc_render_picture()
1213 va_buffers[num_va_buffers++] = ctx->packed_pic_buf_id; in mpeg2enc_render_picture()
1215 va_status = vaBeginPicture(ctx->va_dpy, in mpeg2enc_render_picture()
1216 ctx->context_id, in mpeg2enc_render_picture()
1217 surface_ids[ctx->current_input_surface]); in mpeg2enc_render_picture()
1220 va_status = vaRenderPicture(ctx->va_dpy, in mpeg2enc_render_picture()
1221 ctx->context_id, in mpeg2enc_render_picture()
1226 va_status = vaRenderPicture(ctx->va_dpy, in mpeg2enc_render_picture()
1227 ctx->context_id, in mpeg2enc_render_picture()
1228 &ctx->slice_param_buf_id[0], in mpeg2enc_render_picture()
1229 ctx->num_slice_groups); in mpeg2enc_render_picture()
1232 va_status = vaEndPicture(ctx->va_dpy, ctx->context_id); in mpeg2enc_render_picture()
1239 mpeg2enc_destroy_buffers(struct mpeg2enc_context *ctx, VABufferID *va_buffers, unsigned int num_va_… in mpeg2enc_destroy_buffers() argument
1246 va_status = vaDestroyBuffer(ctx->va_dpy, va_buffers[i]); in mpeg2enc_destroy_buffers()
1256 end_picture(struct mpeg2enc_context *ctx, VAEncPictureType picture_type, int next_is_bpic) in end_picture() argument
1279 mpeg2enc_destroy_buffers(ctx, &ctx->seq_param_buf_id, 1); in end_picture()
1280 mpeg2enc_destroy_buffers(ctx, &ctx->pic_param_buf_id, 1); in end_picture()
1281 mpeg2enc_destroy_buffers(ctx, &ctx->packed_seq_header_param_buf_id, 1); in end_picture()
1282 mpeg2enc_destroy_buffers(ctx, &ctx->packed_seq_buf_id, 1); in end_picture()
1283 mpeg2enc_destroy_buffers(ctx, &ctx->packed_pic_header_param_buf_id, 1); in end_picture()
1284 mpeg2enc_destroy_buffers(ctx, &ctx->packed_pic_buf_id, 1); in end_picture()
1285 mpeg2enc_destroy_buffers(ctx, &ctx->slice_param_buf_id[0], ctx->num_slice_groups); in end_picture()
1286 mpeg2enc_destroy_buffers(ctx, &ctx->codedbuf_buf_id, 1); in end_picture()
1287 memset(ctx->slice_param, 0, sizeof(ctx->slice_param)); in end_picture()
1288 ctx->num_slice_groups = 0; in end_picture()
1292 store_coded_buffer(struct mpeg2enc_context *ctx, VAEncPictureType picture_type) in store_coded_buffer() argument
1301 va_status = vaSyncSurface(ctx->va_dpy, surface_ids[ctx->current_input_surface]); in store_coded_buffer()
1305 …va_status = vaQuerySurfaceStatus(ctx->va_dpy, surface_ids[ctx->current_input_surface], &surface_st… in store_coded_buffer()
1308 va_status = vaMapBuffer(ctx->va_dpy, ctx->codedbuf_buf_id, (void **)(&coded_buffer_segment)); in store_coded_buffer()
1314 ctx->codedbuf_i_size *= 2; in store_coded_buffer()
1316 ctx->codedbuf_pb_size *= 2; in store_coded_buffer()
1318 vaUnmapBuffer(ctx->va_dpy, ctx->codedbuf_buf_id); in store_coded_buffer()
1325 w_items = fwrite(coded_mem, slice_data_length, 1, ctx->ofp); in store_coded_buffer()
1329 if (ctx->codedbuf_i_size > slice_data_length * 3 / 2) { in store_coded_buffer()
1330 ctx->codedbuf_i_size = slice_data_length * 3 / 2; in store_coded_buffer()
1333 if (ctx->codedbuf_pb_size < slice_data_length) { in store_coded_buffer()
1334 ctx->codedbuf_pb_size = slice_data_length; in store_coded_buffer()
1337 if (ctx->codedbuf_pb_size > slice_data_length * 3 / 2) { in store_coded_buffer()
1338 ctx->codedbuf_pb_size = slice_data_length * 3 / 2; in store_coded_buffer()
1342 vaUnmapBuffer(ctx->va_dpy, ctx->codedbuf_buf_id); in store_coded_buffer()
1348 encode_picture(struct mpeg2enc_context *ctx, in encode_picture() argument
1358 begin_picture(ctx, coded_order, display_order, picture_type); in encode_picture()
1362 if (next_display_order >= ctx->num_pictures) in encode_picture()
1363 next_display_order = ctx->num_pictures - 1; in encode_picture()
1365 fseek(ctx->ifp, ctx->frame_size * next_display_order, SEEK_SET); in encode_picture()
1366 ctx->upload_thread_value = pthread_create(&ctx->upload_thread_id, in encode_picture()
1369 ctx); in encode_picture()
1373 mpeg2enc_destroy_buffers(ctx, &ctx->codedbuf_buf_id, 1); in encode_picture()
1374 mpeg2enc_destroy_buffers(ctx, &ctx->pic_param_buf_id, 1); in encode_picture()
1378 codedbuf_size = ctx->codedbuf_i_size; in encode_picture()
1380 codedbuf_size = ctx->codedbuf_pb_size; in encode_picture()
1384 va_status = vaCreateBuffer(ctx->va_dpy, in encode_picture()
1385 ctx->context_id, in encode_picture()
1388 &ctx->codedbuf_buf_id); in encode_picture()
1392 mpeg2enc_update_picture_parameter_buffer(ctx, picture_type, coded_order, display_order); in encode_picture()
1394 mpeg2enc_render_picture(ctx); in encode_picture()
1396 ret = store_coded_buffer(ctx, picture_type); in encode_picture()
1399 end_picture(ctx, picture_type, next_is_bpic); in encode_picture()
1403 update_next_frame_info(struct mpeg2enc_context *ctx, in update_next_frame_info() argument
1408 if (((curr_coded_order + 1) % ctx->intra_period) == 0) { in update_next_frame_info()
1409 ctx->next_type = VAEncPictureTypeIntra; in update_next_frame_info()
1410 ctx->next_display_order = curr_coded_order + 1; in update_next_frame_info()
1417 ctx->next_type = VAEncPictureTypePredictive; in update_next_frame_info()
1418 ctx->next_bframes = ctx->ip_period; in update_next_frame_info()
1419 ctx->next_display_order = curr_display_order + ctx->next_bframes + 1; in update_next_frame_info()
1421 if (ctx->ip_period == 0) { in update_next_frame_info()
1423 ctx->next_type = VAEncPictureTypePredictive; in update_next_frame_info()
1424 ctx->next_display_order = curr_display_order + 1; in update_next_frame_info()
1426 ctx->next_type = VAEncPictureTypeBidirectional; in update_next_frame_info()
1427 ctx->next_display_order = curr_display_order - ctx->next_bframes; in update_next_frame_info()
1428 ctx->next_bframes--; in update_next_frame_info()
1431 if (ctx->next_bframes == 0) { in update_next_frame_info()
1432 ctx->next_type = VAEncPictureTypePredictive; in update_next_frame_info()
1433 ctx->next_bframes = ctx->ip_period; in update_next_frame_info()
1434 ctx->next_display_order = curr_display_order + ctx->next_bframes + 2; in update_next_frame_info()
1436 ctx->next_type = VAEncPictureTypeBidirectional; in update_next_frame_info()
1437 ctx->next_display_order = curr_display_order + 1; in update_next_frame_info()
1438 ctx->next_bframes--; in update_next_frame_info()
1442 if (ctx->next_display_order >= ctx->num_pictures) { in update_next_frame_info()
1443 int rtmp = ctx->next_display_order - (ctx->num_pictures - 1); in update_next_frame_info()
1444 ctx->next_display_order = ctx->num_pictures - 1; in update_next_frame_info()
1445 ctx->next_bframes -= rtmp; in update_next_frame_info()
1450 mpeg2enc_run(struct mpeg2enc_context *ctx) in mpeg2enc_run() argument
1455 ctx->new_sequence = 1; in mpeg2enc_run()
1456 ctx->new_gop_header = 1; in mpeg2enc_run()
1457 ctx->gop_header_in_display_order = display_order; in mpeg2enc_run()
1459 while (coded_order < ctx->num_pictures) { in mpeg2enc_run()
1460 type = ctx->next_type; in mpeg2enc_run()
1461 display_order = ctx->next_display_order; in mpeg2enc_run()
1463 update_next_frame_info(ctx, type, coded_order, display_order); in mpeg2enc_run()
1464 encode_picture(ctx, in mpeg2enc_run()
1468 ctx->next_type == VAEncPictureTypeBidirectional, in mpeg2enc_run()
1469 ctx->next_display_order); in mpeg2enc_run()
1472 ctx->new_sequence = 0; in mpeg2enc_run()
1473 ctx->new_gop_header = ctx->next_type == VAEncPictureTypeIntra; in mpeg2enc_run()
1475 if (ctx->new_gop_header) in mpeg2enc_run()
1476 ctx->gop_header_in_display_order += ctx->intra_period; in mpeg2enc_run()
1480 fprintf(stderr, "\r %d/%d ...", coded_order, ctx->num_pictures); in mpeg2enc_run()
1489 mpeg2enc_release_va_resources(struct mpeg2enc_context *ctx) in mpeg2enc_release_va_resources() argument
1491 vaDestroySurfaces(ctx->va_dpy, surface_ids, SID_NUMBER); in mpeg2enc_release_va_resources()
1492 vaDestroyContext(ctx->va_dpy, ctx->context_id); in mpeg2enc_release_va_resources()
1493 vaDestroyConfig(ctx->va_dpy, ctx->config_id); in mpeg2enc_release_va_resources()
1494 vaTerminate(ctx->va_dpy); in mpeg2enc_release_va_resources()
1495 va_close_display(ctx->va_dpy); in mpeg2enc_release_va_resources()
1499 mpeg2enc_end(struct mpeg2enc_context *ctx) in mpeg2enc_end() argument
1501 pthread_join(ctx->upload_thread_id, NULL); in mpeg2enc_end()
1502 mpeg2enc_release_va_resources(ctx); in mpeg2enc_end()
1508 struct mpeg2enc_context ctx; in main() local
1514 memset(&ctx, 0, sizeof(ctx)); in main()
1515 parse_args(&ctx, argc, argv); in main()
1516 mpeg2enc_init(&ctx); in main()
1517 mpeg2enc_run(&ctx); in main()
1518 mpeg2enc_end(&ctx); in main()
1524 …tf(stderr, "encode %d frames in %f secondes, FPS is %.1f\n", ctx.num_pictures, timeuse, ctx.num_pi… in main()
1526 mpeg2enc_exit(&ctx, 0); in main()