diff --git a/encode/av1encode.c b/encode/av1encode.c index 4b1ab1e..03e3c33 100644 --- a/encode/av1encode.c +++ b/encode/av1encode.c @@ -806,7 +806,8 @@ static void process_cmdline(int argc, char *argv[]) else { struct stat tmp; - fstat(fileno(srcyuv_fp), &tmp); + va_status = fstat(fileno(srcyuv_fp), &tmp); + CHECK_VASTATUS(va_status, "fstat"); srcyuv_frames = tmp.st_size / (ips.width * ips.height * 1.5); printf("Source YUV file %s with %llu frames\n", ips.srcyuv, srcyuv_frames); @@ -1856,12 +1857,6 @@ pack_render_size(bitstream* bs) uint32_t render_and_frame_size_different = 0; put_ui(bs, render_and_frame_size_different, 1);//render_and_frame_size_different - - if (render_and_frame_size_different == 1) - { - put_ui(bs, fh.RenderWidth - 1, 16);//render_width_minus_1 - put_ui(bs, fh.RenderHeight - 1, 16);//render_height_minus_1 - } } static void @@ -2560,19 +2555,23 @@ static int save_codeddata(unsigned long long display_order, unsigned long long e { //first frame unsigned int ivf_size = coded_size - 32 - 12; - fseek(coded_fp, frame_start + 32, SEEK_SET); + va_status = fseek(coded_fp, frame_start + 32, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); fwrite(&ivf_size, 4, 1, coded_fp); fwrite(&display_order, 8, 1, coded_fp); - fseek(coded_fp, frame_end, SEEK_SET); + va_status = fseek(coded_fp, frame_end, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); } else { //other frames unsigned int ivf_size = coded_size - 12; - fseek(coded_fp, frame_start, SEEK_SET); + va_status = fseek(coded_fp, frame_start, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); fwrite(&ivf_size, 4, 1, coded_fp); fwrite(&display_order, 8, 1, coded_fp); - fseek(coded_fp, frame_end, SEEK_SET); + va_status = fseek(coded_fp, frame_end, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); } printf("\n "); /* return back to startpoint */ @@ -2899,6 +2898,8 @@ static int calc_PSNR(double *psnr) srcyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(srcyuv_fp), i); recyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(recyuv_fp), i); if ((srcyuv_ptr == MAP_FAILED) || (recyuv_ptr == MAP_FAILED)) { + free(srcyuv_ptr); + free(recyuv_ptr); printf("Failed to mmap YUV files\n"); return 1; } diff --git a/encode/avcenc.c b/encode/avcenc.c index 3eecd20..4b09057 100644 --- a/encode/avcenc.c +++ b/encode/avcenc.c @@ -848,7 +848,7 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice /* hrd parameter */ VAEncMiscParameterBuffer *misc_param; VAEncMiscParameterHRD *misc_hrd_param; - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, avcenc_context.context_id, VAEncMiscParameterBufferType, sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl), @@ -878,13 +878,14 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice VAEncMiscParameterBufferROI *misc_roi_param; int roi_num = 1; - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, avcenc_context.context_id, VAEncMiscParameterBufferType, sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterBufferROI) + roi_num * sizeof(VAEncROI), 1, NULL, &avcenc_context.misc_parameter_roi_buf_id); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); vaMapBuffer(va_dpy, avcenc_context.misc_parameter_roi_buf_id, (void **)&misc_param); @@ -1792,7 +1793,8 @@ encode_picture(FILE *yuv_fp, FILE *avc_fp, index = SID_INPUT_PICTURE_0; if (next_display_num >= frame_number) next_display_num = frame_number - 1; - fseeko(yuv_fp, (off_t)frame_size * next_display_num, SEEK_SET); + va_status = fseeko(yuv_fp, (off_t)frame_size * next_display_num, SEEK_SET); + CHECK_VASTATUS(va_status, "fseeko"); avcenc_context.upload_thread_param.yuv_fp = yuv_fp; avcenc_context.upload_thread_param.surface_id = surface_ids[index]; @@ -2108,7 +2110,7 @@ int main(int argc, char *argv[]) file_size = ftello(yuv_fp); frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ; - if ((file_size < frame_size) || (file_size % frame_size)) { + if ((file_size < frame_size) || (frame_size != 0 && file_size % frame_size)) { fclose(yuv_fp); printf("The YUV file's size is not correct\n"); return -1; diff --git a/encode/hevcencode.c b/encode/hevcencode.c index 7d9786b..0e28bcb 100644 --- a/encode/hevcencode.c +++ b/encode/hevcencode.c @@ -1280,8 +1280,6 @@ static void sliceHeader_rbsp( { uint8_t nal_unit_type = NALU_TRAIL_R; int gop_ref_distance = ip_period; - int incomplete_mini_gop = 0; - int p_slice_flag = 1; int i = 0; put_ui(bs, slice_header->first_slice_segment_in_pic_flag, 1); @@ -1337,51 +1335,21 @@ static void sliceHeader_rbsp( if (1 == gop_ref_distance) { put_ue(bs, 0 /*delta_poc_s0_minus1*/); } else { - if (incomplete_mini_gop) { - if (frame_cnt_in_gop % gop_ref_distance > i) { - put_ue(bs, 0 /*delta_poc_s0_minus1*/); - } else { - int DeltaPoc = -(int)(gop_ref_distance); - put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); - } + // For Non-BPyramid GOP i.e B0 type + if (num_active_ref_p > 1) { + // DeltaPOC Equals NumB + int DeltaPoc = -(int)(gop_ref_distance); + put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); } else { - // For Non-BPyramid GOP i.e B0 type - if (num_active_ref_p > 1) { - // MultiRef Case - if (p_slice_flag) { - // DeltaPOC Equals NumB - int DeltaPoc = -(int)(gop_ref_distance); - put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); - } else { - // for normal B - if (frame_cnt_in_gop < gop_ref_distance) { - if (0 == i) { - int DeltaPoc = -(int)(frame_cnt_in_gop); - put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); - } - } else if (frame_cnt_in_gop > gop_ref_distance) { - if (0 == i) { - //Need % to wraparound the delta poc, to avoid corruption caused on POC=5 with GOP (29,2) and 4 refs - int DeltaPoc = -(int)((frame_cnt_in_gop - gop_ref_distance) % gop_ref_distance); - put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); - } else if (1 <= i) { - int DeltaPoc = -(int)(gop_ref_distance); - put_ue(bs, prev - DeltaPoc - 1 /*delta_poc_s0_minus1*/); - } - } - } - } else { - // the big 'if' wraps here is - - // if (!slice_header->short_term_ref_pic_set_sps_flag) - // From the Teddi logic, the short_term_ref_pic_set_sps_flag only can be '0' - // either for B-Prymid or first several frames in a GOP in multi-ref cases - // when there are not enough backward refs. - // So though there are really some codes under this 'else'in Teddi, don't - // want to introduce them in MEA to avoid confusion, and put an assert - // here to guard that there is new case we need handle in the future. - assert(0); - - } + // the big 'if' wraps here is - + // if (!slice_header->short_term_ref_pic_set_sps_flag) + // From the Teddi logic, the short_term_ref_pic_set_sps_flag only can be '0' + // either for B-Prymid or first several frames in a GOP in multi-ref cases + // when there are not enough backward refs. + // So though there are really some codes under this 'else'in Teddi, don't + // want to introduce them in MEA to avoid confusion, and put an assert + // here to guard that there is new case we need handle in the future. + assert(0); } } put_ui(bs, 1 /*used_by_curr_pic_s0_flag*/, 1); @@ -1528,11 +1496,6 @@ static void sliceHeader_rbsp( int slice_header_extension_length = 0; put_ue(bs, slice_header_extension_length); - - for (i = 0; i < slice_header_extension_length; i++) { - int slice_header_extension_data_byte = 0; - put_ui(bs, slice_header_extension_data_byte, 8); - } } } @@ -1844,6 +1807,7 @@ static int process_cmdline(int argc, char *argv[]) frame_rate = atoi(optarg); break; case 'o': + free(coded_fn); coded_fn = strdup(optarg); break; case 0: @@ -1875,9 +1839,11 @@ static int process_cmdline(int argc, char *argv[]) } break; case 9: + free(srcyuv_fn); srcyuv_fn = strdup(optarg); break; case 10: + free(recyuv_fn); recyuv_fn = strdup(optarg); break; case 11: diff --git a/encode/jpegenc.c b/encode/jpegenc.c index ae97a49..d685866 100644 --- a/encode/jpegenc.c +++ b/encode/jpegenc.c @@ -976,7 +976,7 @@ int main(int argc, char *argv[]) fseeko(yuv_fp, (off_t)0, SEEK_END); file_size = ftello(yuv_fp); - if ((file_size < frame_size) || (file_size % frame_size)) { + if ((file_size < frame_size) || (frame_size != 0 && file_size % frame_size)) { fclose(yuv_fp); printf("The YUV file's size is not correct: file_size=%zd, frame_size=%d\n", file_size, frame_size); return -1; diff --git a/encode/mpeg2vaenc.c b/encode/mpeg2vaenc.c index b1d4494..d85a516 100644 --- a/encode/mpeg2vaenc.c +++ b/encode/mpeg2vaenc.c @@ -1382,7 +1382,8 @@ encode_picture(struct mpeg2enc_context *ctx, if (next_display_order >= ctx->num_pictures) next_display_order = ctx->num_pictures - 1; - fseek(ctx->ifp, ctx->frame_size * next_display_order, SEEK_SET); + va_status = fseek(ctx->ifp, ctx->frame_size * next_display_order, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); ctx->upload_thread_value = pthread_create(&ctx->upload_thread_id, NULL, upload_yuv_to_surface, diff --git a/encode/svctenc.c b/encode/svctenc.c index fda193a..f6e668a 100644 --- a/encode/svctenc.c +++ b/encode/svctenc.c @@ -1159,7 +1159,8 @@ upload_task(struct svcenc_context *ctx, unsigned int display_order, int surface) int y_size = ctx->width * ctx->height; int u_size = (ctx->width >> 1) * (ctx->height >> 1); - fseek(ctx->ifp, ctx->frame_size * display_order, SEEK_SET); + va_status = fseek(ctx->ifp, ctx->frame_size * display_order, SEEK_SET); + CHECK_VASTATUS(va_status, "fseek"); do { n_items = fread(ctx->frame_data_buffer, ctx->frame_size, 1, ctx->ifp); diff --git a/encode/vp8enc.c b/encode/vp8enc.c index 5f4cd19..aa3fa62 100644 --- a/encode/vp8enc.c +++ b/encode/vp8enc.c @@ -673,7 +673,6 @@ void vp8enc_create_EncoderPipe() VAEntrypoint entrypoints[5]; int num_entrypoints; int i; - bool entrypoint_found; VAConfigAttrib conf_attrib[2]; VASurfaceAttrib surface_attrib; int major_ver, minor_ver; @@ -686,17 +685,6 @@ void vp8enc_create_EncoderPipe() vaQueryConfigEntrypoints(vaapi_context.display, vaapi_context.profile, entrypoints, &num_entrypoints); - entrypoint_found = true; - for (i = 0; i < num_entrypoints; i++) { - if (entrypoints[i] == settings.vaapi_entry_point) - entrypoint_found = true; - } - - if (entrypoint_found == false) { - fprintf(stderr, "Error: VAEntrypoint not found!\n"); - assert(0); - } - /* find out the format for the render target, and rate control mode */ conf_attrib[0].type = VAConfigAttribRTFormat; conf_attrib[1].type = VAConfigAttribRateControl; @@ -835,7 +823,8 @@ vp8enc_store_coded_buffer(FILE *vp8_fp, uint64_t timestamp) size_t vp8enc_get_FileSize(FILE *fp) { struct stat st; - fstat(fileno(fp), &st); + va_status = fstat(fileno(fp), &st); + CHECK_VASTATUS(va_status, "fstat"); return st.st_size; } @@ -882,7 +871,7 @@ int vp8enc_prepare_buffers(int frame_type) /* hrd parameter */ - vaCreateBuffer(vaapi_context.display, + va_status = vaCreateBuffer(vaapi_context.display, vaapi_context.context_id, VAEncMiscParameterBufferType, sizeof(vaapi_context.hrd_param), 1, &vaapi_context.hrd_param, @@ -905,7 +894,7 @@ int vp8enc_prepare_buffers(int frame_type) num_buffers++; /* Create the Misc FR/RC buffer under non-CQP mode */ if (settings.rc_mode != VA_RC_CQP && frame_type == KEY_FRAME) { - vaCreateBuffer(vaapi_context.display, + va_status = vaCreateBuffer(vaapi_context.display, vaapi_context.context_id, VAEncMiscParameterBufferType, sizeof(vaapi_context.frame_rate_param), 1, &vaapi_context.frame_rate_param, @@ -915,7 +904,7 @@ int vp8enc_prepare_buffers(int frame_type) va_buffers ++; num_buffers++; - vaCreateBuffer(vaapi_context.display, + va_status = vaCreateBuffer(vaapi_context.display, vaapi_context.context_id, VAEncMiscParameterBufferType, sizeof(vaapi_context.rate_control_param), 1, &vaapi_context.rate_control_param, diff --git a/encode/vp9enc.c b/encode/vp9enc.c index 1d1283f..c08dbaf 100644 --- a/encode/vp9enc.c +++ b/encode/vp9enc.c @@ -896,7 +896,7 @@ vp9enc_begin_picture(FILE *yuv_fp, int frame_num, int frame_type) /* hrd parameter */ VAEncMiscParameterBuffer *misc_param; VAEncMiscParameterHRD *misc_hrd_param; - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, vp9enc_context.context_id, VAEncMiscParameterBufferType, sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl), @@ -938,7 +938,7 @@ vp9enc_begin_picture(FILE *yuv_fp, int frame_num, int frame_type) VAEncMiscParameterFrameRate *misc_fr; VAEncMiscParameterRateControl *misc_rc; - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, vp9enc_context.context_id, VAEncMiscParameterBufferType, sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterFrameRate), @@ -955,7 +955,7 @@ vp9enc_begin_picture(FILE *yuv_fp, int frame_num, int frame_type) misc_fr->framerate = frame_rate; vaUnmapBuffer(va_dpy, vp9enc_context.misc_fr_buf_id); - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, vp9enc_context.context_id, VAEncMiscParameterBufferType, sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl), @@ -1182,7 +1182,8 @@ vp9enc_encode_picture(FILE *yuv_fp, FILE *vp9_fp, else index = SID_INPUT_PICTURE_0; - fseeko(yuv_fp, (off_t)frame_size * next_enc_frame, SEEK_SET); + va_status = fseeko(yuv_fp, (off_t)frame_size * next_enc_frame, SEEK_SET); + CHECK_VASTATUS(va_status, "fseeko"); vp9enc_context.upload_thread_param.yuv_fp = yuv_fp; vp9enc_context.upload_thread_param.surface_id = surface_ids[index]; @@ -1227,17 +1228,19 @@ vp9enc_encode_picture(FILE *yuv_fp, FILE *vp9_fp, packed_header_param_buffer.bit_length = raw_data_length * 8; packed_header_param_buffer.has_emulation_bytes = 0; - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, vp9enc_context.context_id, VAEncPackedHeaderParameterBufferType, sizeof(packed_header_param_buffer), 1, &packed_header_param_buffer, &vp9enc_context.raw_data_header_buf_id); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); - vaCreateBuffer(va_dpy, + va_status = vaCreateBuffer(va_dpy, vp9enc_context.context_id, VAEncPackedHeaderDataBufferType, raw_data_length, 1, raw_data, &vp9enc_context.raw_data_buf_id); + CHECK_VASTATUS(va_status, "vaCreateBuffer"); } vp9enc_create_picture_parameter_buf(); @@ -1531,7 +1534,7 @@ main(int argc, char *argv[]) file_size = ftello(yuv_fp); frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ; - if ((file_size < frame_size) || (file_size % frame_size)) { + if ((file_size < frame_size) || (frame_size != 0 && file_size % frame_size)) { fclose(yuv_fp); printf("The YUV file's size is not correct\n"); return -1;