00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "contributors.h"
00028
00029 #include <math.h>
00030 #include <time.h>
00031
00032 #include "global.h"
00033
00034 #include "filehandle.h"
00035 #include "mbuffer.h"
00036 #include "img_luma.h"
00037 #include "img_chroma.h"
00038 #include "img_distortion.h"
00039 #include "intrarefresh.h"
00040 #include "slice.h"
00041 #include "fmo.h"
00042 #include "sei.h"
00043 #include "memalloc.h"
00044 #include "nalu.h"
00045 #include "ratectl.h"
00046 #include "mb_access.h"
00047 #include "context_ini.h"
00048 #include "biariencode.h"
00049 #include "enc_statistics.h"
00050 #include "conformance.h"
00051 #include "report.h"
00052
00053 #include "q_matrix.h"
00054 #include "q_offsets.h"
00055 #include "wp.h"
00056 #include "input.h"
00057 #include "image.h"
00058 #include "errdo.h"
00059 #include "img_process.h"
00060 #include "rdopt.h"
00061 #include "sei.h"
00062
00063 extern void DeblockFrame (ImageParameters *p_Img, imgpel **, imgpel ***);
00064
00065 static void code_a_picture (ImageParameters *p_Img, InputParameters *p_Inp, Picture *pic);
00066 static void field_picture (ImageParameters *p_Img, InputParameters *p_Inp, Picture *top, Picture *bottom);
00067 static void prepare_enc_frame_picture (ImageParameters *p_Img, InputParameters *p_Inp, StorablePicture **stored_pic);
00068 static void writeout_picture (ImageParameters *p_Img, Picture *pic);
00069 static byte picture_structure_decision(ImageParameters *p_Img, Picture *frame, Picture *top, Picture *bot);
00070 static void distortion_fld (ImageParameters *p_Img, InputParameters *p_Inp, Picture *field_pic, ImageData *imgData);
00071
00072
00073 static void field_mode_buffer (ImageParameters *p_Img);
00074 static void frame_mode_buffer (ImageParameters *p_Img, InputParameters *p_Inp);
00075 static void init_frame (ImageParameters *p_Img, InputParameters *p_Inp);
00076 static void init_field (ImageParameters *p_Img, InputParameters *p_Inp);
00077 static void put_buffer_frame (ImageParameters *p_Img);
00078 static void put_buffer_top (ImageParameters *p_Img);
00079 static void put_buffer_bot (ImageParameters *p_Img);
00080
00081 static void ReportFirstframe (ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time);
00082 static void ReportI (ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time);
00083 static void ReportP (ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time);
00084 static void ReportB (ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time);
00085 static void ReportNALNonVLCBits(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time);
00086
00087 extern void rd_picture_coding(ImageParameters *p_Img, InputParameters *p_Inp);
00088
00089 void MbAffPostProc(ImageParameters *p_Img)
00090 {
00091 imgpel temp[32][16];
00092
00093 StorablePicture *p_Enc_Pic = p_Img->enc_picture;
00094 imgpel ** imgY = p_Enc_Pic->imgY;
00095 imgpel ***imgUV = p_Enc_Pic->imgUV;
00096 short i, y, x0, y0, uv;
00097
00098 if (p_Img->yuv_format != YUV400)
00099 {
00100 for (i=0; i<(int)p_Img->PicSizeInMbs; i+=2)
00101 {
00102 if (p_Enc_Pic->motion.mb_field[i])
00103 {
00104 get_mb_pos(p_Img, i, p_Img->mb_size[IS_LUMA], &x0, &y0);
00105 for (y=0; y<(2*MB_BLOCK_SIZE);y++)
00106 memcpy(&temp[y],&imgY[y0+y][x0], MB_BLOCK_SIZE * sizeof(imgpel));
00107
00108 for (y=0; y<MB_BLOCK_SIZE;y++)
00109 {
00110 memcpy(&imgY[y0+(2*y)][x0],temp[y], MB_BLOCK_SIZE * sizeof(imgpel));
00111 memcpy(&imgY[y0+(2*y + 1)][x0],temp[y+ MB_BLOCK_SIZE], MB_BLOCK_SIZE * sizeof(imgpel));
00112 }
00113
00114 x0 = x0 / (16/p_Img->mb_cr_size_x);
00115 y0 = y0 / (16/p_Img->mb_cr_size_y);
00116
00117 for (uv=0; uv<2; uv++)
00118 {
00119 for (y=0; y < (2 * p_Img->mb_cr_size_y); y++)
00120 memcpy(&temp[y],&imgUV[uv][y0+y][x0], p_Img->mb_cr_size_x * sizeof(imgpel));
00121
00122 for (y=0; y<p_Img->mb_cr_size_y;y++)
00123 {
00124 memcpy(&imgUV[uv][y0+(2*y)][x0],temp[y], p_Img->mb_cr_size_x * sizeof(imgpel));
00125 memcpy(&imgUV[uv][y0+(2*y + 1)][x0],temp[y+ p_Img->mb_cr_size_y], p_Img->mb_cr_size_x * sizeof(imgpel));
00126 }
00127 }
00128 }
00129 }
00130 }
00131 else
00132 {
00133 for (i=0; i<(int)p_Img->PicSizeInMbs; i+=2)
00134 {
00135 if (p_Enc_Pic->motion.mb_field[i])
00136 {
00137 get_mb_pos(p_Img, i, p_Img->mb_size[IS_LUMA], &x0, &y0);
00138 for (y=0; y<(2*MB_BLOCK_SIZE);y++)
00139 memcpy(&temp[y],&imgY[y0+y][x0], MB_BLOCK_SIZE * sizeof(imgpel));
00140
00141 for (y=0; y<MB_BLOCK_SIZE;y++)
00142 {
00143 memcpy(&imgY[y0+(2*y)][x0],temp[y], MB_BLOCK_SIZE * sizeof(imgpel));
00144 memcpy(&imgY[y0+(2*y + 1)][x0],temp[y+ MB_BLOCK_SIZE], MB_BLOCK_SIZE * sizeof(imgpel));
00145 }
00146 }
00147 }
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158 void set_slice_type(ImageParameters *p_Img, InputParameters *p_Inp, int slice_type)
00159 {
00160 p_Img->type = (short) slice_type;
00161 p_Img->RCMinQP = p_Inp->RCMinQP[p_Img->type];
00162 p_Img->RCMaxQP = p_Inp->RCMaxQP[p_Img->type];
00163 }
00164
00165 static void code_a_plane(ImageParameters *p_Img, InputParameters *p_Inp)
00166 {
00167 unsigned int NumberOfCodedMBs = 0;
00168 int SliceGroup = 0;
00169
00170
00171 p_Img->slice_group_change_cycle=1;
00172 FmoInit(p_Img, p_Img->active_pps, p_Img->active_sps);
00173 FmoStartPicture (p_Img);
00174
00175 CalculateQuant4x4Param (p_Img);
00176 CalculateOffset4x4Param(p_Img, p_Inp);
00177
00178 if(p_Inp->Transform8x8Mode)
00179 {
00180 CalculateQuant8x8Param (p_Img);
00181 CalculateOffset8x8Param(p_Img, p_Inp);
00182 }
00183
00184 reset_pic_bin_count(p_Img);
00185 p_Img->bytes_in_picture = 0;
00186
00187 while (NumberOfCodedMBs < p_Img->PicSizeInMbs)
00188 {
00189
00190 while (!FmoSliceGroupCompletelyCoded (p_Img, SliceGroup))
00191 {
00192
00193 if (!p_Img->MbaffFrameFlag)
00194 NumberOfCodedMBs += encode_one_slice (p_Img, p_Inp, SliceGroup, NumberOfCodedMBs);
00195 else
00196 NumberOfCodedMBs += encode_one_slice_MBAFF (p_Img, p_Inp, SliceGroup, NumberOfCodedMBs);
00197
00198 FmoSetLastMacroblockInSlice (p_Img, p_Img->current_mb_nr);
00199
00200 p_Img->current_slice_nr++;
00201 p_Img->p_Stats->bit_slice = 0;
00202 }
00203
00204 SliceGroup++;
00205 }
00206 FmoEndPicture ();
00207
00208 if ((p_Inp->SkipDeBlockNonRef == 0) || (p_Img->nal_reference_idc != 0))
00209 DeblockFrame (p_Img, p_Img->enc_picture->imgY, p_Img->enc_picture->imgUV);
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 static void code_a_picture(ImageParameters *p_Img, InputParameters *p_Inp, Picture *pic)
00223 {
00224 int pl;
00225
00226 p_Img->currentPicture = pic;
00227 p_Img->currentPicture->idr_flag = get_idr_flag(p_Img, p_Inp);
00228
00229 if (p_Img->currentPicture->idr_flag && p_Inp->EnableIDRGOP && p_Img->frm_number)
00230 {
00231 p_Img->last_idr_number = p_Img->frm_no_in_file;
00232 }
00233
00234 pic->no_slices = 0;
00235
00236 RandomIntraNewPicture (p_Img);
00237
00238 if( IS_INDEPENDENT( p_Inp ) )
00239 {
00240 for( pl=0; pl<MAX_PLANE; pl++ )
00241 {
00242 p_Img->current_mb_nr = 0;
00243 p_Img->current_slice_nr = 0;
00244 p_Img->SumFrameQP = 0;
00245 p_Img->num_ref_idx_l0_active = 0;
00246 p_Img->num_ref_idx_l1_active = 0;
00247
00248 p_Img->colour_plane_id = (char) pl;
00249
00250 code_a_plane(p_Img, p_Inp);
00251 }
00252 }
00253 else
00254 {
00255 code_a_plane(p_Img, p_Inp);
00256 }
00257
00258 if (p_Img->MbaffFrameFlag)
00259 MbAffPostProc(p_Img);
00260 }
00261
00262
00263
00264
00265
00266
00267
00268 byte get_idr_flag( ImageParameters *p_Img, InputParameters *p_Inp)
00269 {
00270 int idr_flag;
00271 int idr_refresh;
00272
00273
00274 if ( p_Inp->idr_period && !p_Inp->adaptive_idr_period )
00275 {
00276 idr_refresh = (( ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period ) == 0);
00277 }
00278 else if ( p_Inp->idr_period && p_Inp->adaptive_idr_period == 1 )
00279 {
00280 idr_refresh = (( ( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period ) == 0);
00281 }
00282 else
00283 {
00284 idr_refresh = (p_Img->frm_number == 0);
00285 }
00286
00287 idr_flag = ((!p_Img->gop_number) && (!(p_Img->structure==BOTTOM_FIELD)))
00288 || (idr_refresh && (p_Img->type == I_SLICE || p_Img->type==SI_SLICE)&& (!(p_Img->structure==BOTTOM_FIELD)));
00289
00290 return (byte) idr_flag;
00291 }
00292
00293
00294
00295
00296
00297
00298
00299 void update_global_stats(InputParameters *p_Inp, StatParameters *gl_stats, StatParameters *cur_stats)
00300 {
00301 int i, j, k;
00302
00303 if (p_Inp->skip_gl_stats == 0)
00304 {
00305 for (i = 0; i < 4; i++)
00306 {
00307 gl_stats->intra_chroma_mode[i] += cur_stats->intra_chroma_mode[i];
00308 }
00309
00310 for (i = 0; i < 5; i++)
00311 {
00312 gl_stats->quant[i] += cur_stats->quant[i];
00313 gl_stats->num_macroblocks[i] += cur_stats->num_macroblocks[i];
00314 gl_stats->bit_use_mb_type [i] += cur_stats->bit_use_mb_type[i];
00315 gl_stats->bit_use_header [i] += cur_stats->bit_use_header[i];
00316 gl_stats->tmp_bit_use_cbp [i] += cur_stats->tmp_bit_use_cbp[i];
00317 gl_stats->bit_use_coeffC [i] += cur_stats->bit_use_coeffC[i];
00318 gl_stats->bit_use_coeff[0][i] += cur_stats->bit_use_coeff[0][i];
00319 gl_stats->bit_use_coeff[1][i] += cur_stats->bit_use_coeff[1][i];
00320 gl_stats->bit_use_coeff[2][i] += cur_stats->bit_use_coeff[2][i];
00321 gl_stats->bit_use_delta_quant[i] += cur_stats->bit_use_delta_quant[i];
00322 gl_stats->bit_use_stuffingBits[i] += cur_stats->bit_use_stuffingBits[i];
00323
00324 for (k = 0; k < 2; k++)
00325 gl_stats->b8_mode_0_use[i][k] += cur_stats->b8_mode_0_use[i][k];
00326
00327 for (j = 0; j < 15; j++)
00328 {
00329 gl_stats->mode_use[i][j] += cur_stats->mode_use[i][j];
00330 gl_stats->bit_use_mode[i][j] += cur_stats->bit_use_mode[i][j];
00331 for (k = 0; k < 2; k++)
00332 gl_stats->mode_use_transform[i][j][k] += cur_stats->mode_use_transform[i][j][k];
00333 }
00334 }
00335 }
00336 }
00337
00338 static void storeRedundantFrame(ImageParameters *p_Img)
00339 {
00340 int j, k;
00341 if(p_Img->key_frame)
00342 {
00343 for(j=0; j<p_Img->height; j++)
00344 {
00345 memcpy(p_Img->imgY_tmp[j], p_Img->enc_frame_picture[0]->imgY[j], p_Img->width * sizeof(imgpel));
00346 }
00347
00348 for (k = 0; k < 2; k++)
00349 {
00350 for(j=0; j<p_Img->height_cr; j++)
00351 {
00352 memcpy(p_Img->imgUV_tmp[k][j], p_Img->enc_frame_picture[0]->imgUV[k][j], p_Img->width_cr * sizeof(imgpel));
00353 }
00354 }
00355 }
00356
00357 if(p_Img->redundant_coding)
00358 {
00359 for(j=0; j<p_Img->height; j++)
00360 {
00361 memcpy(p_Img->enc_frame_picture[0]->imgY[j], p_Img->imgY_tmp[j], p_Img->width * sizeof(imgpel));
00362 }
00363 for (k = 0; k < 2; k++)
00364 {
00365 for(j=0; j<p_Img->height_cr; j++)
00366 {
00367 memcpy(p_Img->enc_frame_picture[0]->imgUV[k][j], p_Img->imgUV_tmp[k][j], p_Img->width_cr * sizeof(imgpel));
00368 }
00369 }
00370 }
00371 }
00372
00373
00374
00375
00376
00377
00378 void free_pictures(ImageParameters *p_Img, InputParameters *p_Inp, int stored_pic)
00379 {
00380 int i;
00381 for (i = 0; i < 6; i++)
00382 {
00383 if (i != stored_pic)
00384 free_storable_picture(p_Img, p_Inp, p_Img->enc_frame_picture[i]);
00385 }
00386 }
00387
00388
00389
00390
00391
00392
00393
00394 int encode_one_frame (ImageParameters *p_Img, InputParameters *p_Inp)
00395 {
00396 int prev_frame_no = 0;
00397 int consecutive_non_reference_pictures = 0;
00398 int i;
00399 int nplane;
00400
00401
00402 int bits = 0;
00403
00404 TIME_T start_time;
00405 TIME_T end_time;
00406 int64 tmp_time;
00407
00408 p_Img->me_time = 0;
00409 p_Img->rd_pass = 0;
00410
00411 if( IS_INDEPENDENT(p_Inp) )
00412 {
00413 for( nplane=0; nplane<MAX_PLANE; nplane++ ){
00414 p_Img->enc_frame_picture_JV[nplane] = NULL;
00415 }
00416 }
00417
00418 for (i = 0; i < 6; i++)
00419 p_Img->enc_frame_picture[i] = NULL;
00420
00421 gettime(&start_time);
00422
00423
00424 p_Img->write_macroblock = FALSE;
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 put_buffer_frame (p_Img);
00439
00440 init_frame (p_Img, p_Inp);
00441
00442 ReadOneFrame (p_Img, p_Inp, &p_Inp->input_file1, p_Img->frm_no_in_file, p_Inp->infile_header, &p_Inp->source, &p_Inp->output, p_Img->imgData0.frm_data);
00443 PaddAutoCropBorders (p_Inp->output, p_Img->width, p_Img->height, p_Img->width_cr, p_Img->height_cr, p_Img->imgData0.frm_data);
00444
00445
00446 ProcessImage(p_Img, p_Inp);
00447 PaddAutoCropBorders (p_Inp->output, p_Img->width, p_Img->height, p_Img->width_cr, p_Img->height_cr, p_Img->imgData.frm_data);
00448
00449
00450
00451
00452
00453
00454
00455 p_Img->p_Dist->frame_ctr++;
00456
00457 if(p_Img->type == SP_SLICE)
00458 {
00459 if(p_Inp->sp2_frame_indicator)
00460 {
00461 p_Img->sp2_frame_indicator = TRUE;
00462 read_SP_coefficients(p_Img, p_Inp);
00463 }
00464 }
00465 else
00466 {
00467 p_Img->sp2_frame_indicator = FALSE;
00468 }
00469 if ( p_Inp->WPMCPrecision )
00470 {
00471 wpxInitWPXPasses(p_Img, p_Inp);
00472 p_Img->pWPX->curr_wp_rd_pass = p_Img->pWPX->wp_rd_passes;
00473 p_Img->pWPX->curr_wp_rd_pass->algorithm = WP_REGULAR;
00474 }
00475
00476 if (p_Inp->PicInterlace == FIELD_CODING)
00477 {
00478
00479 if ( p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE )
00480 p_Img->p_rc_gen->FieldControl = 1;
00481
00482 p_Img->field_picture = 1;
00483 field_picture (p_Img, p_Inp, p_Img->field_pic[0], p_Img->field_pic[1]);
00484 p_Img->fld_flag = TRUE;
00485 }
00486 else
00487 {
00488 int tmpFrameQP;
00489 int num_ref_idx_l0;
00490 int num_ref_idx_l1;
00491
00492
00493 if ( p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE )
00494 p_Img->p_rc_gen->FieldControl = 0;
00495
00496 p_Img->field_picture = 0;
00497
00498
00499 if(p_Inp->RCEnable)
00500 rc_init_frame(p_Img, p_Inp);
00501
00502 if (p_Inp->GenerateMultiplePPS)
00503 p_Img->active_pps = p_Img->PicParSet[0];
00504
00505 frame_picture (p_Img, p_Inp, p_Img->frame_pic[0], &p_Img->imgData, 0);
00506
00507 if(p_Inp->WPIterMC)
00508 p_Img->frameOffsetAvail = 1;
00509
00510 if ((p_Inp->RDPictureIntra || p_Img->type!=I_SLICE) && p_Inp->RDPictureDecision)
00511 {
00512 rd_picture_coding(p_Img, p_Inp);
00513 }
00514
00515 tmpFrameQP = p_Img->SumFrameQP;
00516 num_ref_idx_l0 = p_Img->num_ref_idx_l0_active;
00517 num_ref_idx_l1 = p_Img->num_ref_idx_l1_active;
00518
00519
00520
00521 if ((p_Img->type==SP_SLICE) && (p_Img->si_frame_indicator == FALSE) && (p_Inp->si_frame_indicator))
00522 {
00523
00524 p_Img->si_frame_indicator = TRUE;
00525 frame_picture (p_Img, p_Inp, p_Img->frame_pic_si, &p_Img->imgData, 0);
00526 }
00527
00528 if ((p_Img->type == SP_SLICE) && (p_Inp->sp_output_indicator))
00529 {
00530
00531 output_SP_coefficients(p_Img, p_Inp);
00532 }
00533
00534 if (p_Inp->PicInterlace == ADAPTIVE_CODING)
00535 {
00536
00537 if ( p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE )
00538 p_Img->p_rc_gen->FieldControl=1;
00539 p_Img->write_macroblock = FALSE;
00540 p_Img->bot_MB = FALSE;
00541
00542 p_Img->field_picture = 1;
00543 field_picture (p_Img, p_Inp, p_Img->field_pic[0], p_Img->field_pic[1]);
00544
00545 if(p_Img->rd_pass == 0)
00546 p_Img->fld_flag = picture_structure_decision (p_Img, p_Img->frame_pic[0], p_Img->field_pic[0], p_Img->field_pic[1]);
00547 else if(p_Img->rd_pass == 1)
00548 p_Img->fld_flag = picture_structure_decision (p_Img, p_Img->frame_pic[1], p_Img->field_pic[0], p_Img->field_pic[1]);
00549 else
00550 p_Img->fld_flag = picture_structure_decision (p_Img, p_Img->frame_pic[2], p_Img->field_pic[0], p_Img->field_pic[1]);
00551
00552 if ( p_Img->fld_flag )
00553 {
00554 tmpFrameQP = p_Img->SumFrameQP;
00555 num_ref_idx_l0 = p_Img->num_ref_idx_l0_active;
00556 num_ref_idx_l1 = p_Img->num_ref_idx_l1_active;
00557 }
00558
00559 update_field_frame_contexts (p_Img, p_Img->fld_flag);
00560
00561
00562 if ( p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE )
00563 p_Img->p_rc_gen->FieldFrame = !(p_Img->fld_flag) ? 1 : 0;
00564 }
00565 else
00566 p_Img->fld_flag = FALSE;
00567
00568 p_Img->SumFrameQP = tmpFrameQP;
00569 p_Img->num_ref_idx_l0_active = num_ref_idx_l0;
00570 p_Img->num_ref_idx_l1_active = num_ref_idx_l1;
00571 }
00572
00573 p_Img->p_Stats->frame_counter++;
00574 p_Img->p_Stats->frame_ctr[p_Img->type]++;
00575
00576
00577
00578
00579
00580 if (p_Img->fld_flag)
00581 {
00582 field_mode_buffer (p_Img);
00583 write_non_vcl_nalu(p_Img, p_Inp);
00584 writeout_picture (p_Img, p_Img->field_pic[0]);
00585 writeout_picture (p_Img, p_Img->field_pic[1]);
00586 }
00587 else
00588 {
00589 frame_mode_buffer (p_Img, p_Inp);
00590
00591 if (p_Img->type==SP_SLICE && p_Img->si_frame_indicator == 1)
00592 {
00593 write_non_vcl_nalu(p_Img, p_Inp);
00594 writeout_picture (p_Img, p_Img->frame_pic_si);
00595 p_Img->si_frame_indicator = FALSE;
00596 }
00597 else
00598 {
00599 write_non_vcl_nalu(p_Img, p_Inp);
00600 writeout_picture (p_Img, p_Img->frame_pic[p_Img->rd_pass]);
00601 }
00602 }
00603
00604 if (p_Img->frame_pic_si)
00605 {
00606 free_slice_list(p_Img->frame_pic_si);
00607 }
00608
00609 for (i = 0; i < p_Img->frm_iter; i++)
00610 {
00611 if (p_Img->frame_pic[i])
00612 {
00613 free_slice_list(p_Img->frame_pic[i]);
00614 }
00615 }
00616
00617 if (p_Img->field_pic)
00618 {
00619 for (i = 0; i < 2; i++)
00620 {
00621 if (p_Img->field_pic[i])
00622 free_slice_list(p_Img->field_pic[i]);
00623 }
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 if ( p_Inp->RCEnable )
00637 {
00638
00639 bits = (int)( p_Img->p_Stats->bit_ctr - p_Img->p_Stats->bit_ctr_n )
00640 + (int)( p_Img->p_Stats->bit_ctr_filler_data - p_Img->p_Stats->bit_ctr_filler_data_n );
00641
00642 if ( p_Inp->RCUpdateMode <= MAX_RC_MODE )
00643 p_Img->rc_update_pict_frame_ptr(p_Img, p_Inp, p_Img->p_rc_quad, p_Img->p_rc_gen, bits);
00644 }
00645
00646 if (p_Inp->PicInterlace == FRAME_CODING)
00647 {
00648 if ((p_Inp->rdopt == 3) && (p_Img->nal_reference_idc != 0))
00649 {
00650 UpdateDecoders (p_Img, p_Inp, p_Img->enc_picture);
00651 }
00652
00653 if (p_Inp->RestrictRef)
00654 UpdatePixelMap (p_Img, p_Inp);
00655 }
00656
00657 compute_distortion(p_Img, p_Inp, &p_Img->imgData);
00658
00659
00660 if(p_Inp->redundant_pic_flag)
00661 {
00662 storeRedundantFrame(p_Img);
00663 }
00664
00665 if (p_Inp->PicInterlace == ADAPTIVE_CODING)
00666 {
00667 if (p_Img->fld_flag)
00668 {
00669 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_field_picture[0]->stats);
00670 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_field_picture[1]->stats);
00671
00672 store_picture_in_dpb (p_Img, p_Inp, p_Img->enc_field_picture[1], &p_Inp->output);
00673 free_storable_picture(p_Img, p_Inp, p_Img->enc_frame_picture[0]);
00674 free_storable_picture(p_Img, p_Inp, p_Img->enc_frame_picture[1]);
00675 free_storable_picture(p_Img, p_Inp, p_Img->enc_frame_picture[2]);
00676 }
00677 else
00678 {
00679 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_frame_picture[p_Img->rd_pass]->stats);
00680
00681 if (p_Img->rd_pass==2)
00682 {
00683 replace_top_pic_with_frame(p_Img, p_Inp, p_Img->enc_frame_picture[2], &p_Inp->output);
00684 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[0]);
00685 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[1]);
00686 }
00687 else if (p_Img->rd_pass==1)
00688 {
00689 replace_top_pic_with_frame(p_Img, p_Inp, p_Img->enc_frame_picture[1], &p_Inp->output);
00690 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[0]);
00691 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[2]);
00692 }
00693 else
00694 {
00695 if(p_Inp->redundant_pic_flag==0 || (p_Img->key_frame==0))
00696 {
00697 replace_top_pic_with_frame(p_Img, p_Inp, p_Img->enc_frame_picture[0], &p_Inp->output);
00698 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[1]);
00699 free_storable_picture (p_Img, p_Inp, p_Img->enc_frame_picture[2]);
00700 }
00701 }
00702 free_storable_picture(p_Img, p_Inp, p_Img->enc_field_picture[1]);
00703 }
00704 }
00705 else
00706 {
00707 if (p_Img->fld_flag)
00708 {
00709 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_field_picture[0]->stats);
00710 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_field_picture[1]->stats);
00711 store_picture_in_dpb(p_Img, p_Inp, p_Img->enc_field_picture[1], &p_Inp->output);
00712 }
00713 else
00714 {
00715 if ((p_Inp->redundant_pic_flag != 1) || (p_Img->key_frame == 0))
00716 {
00717 update_global_stats(p_Inp, p_Img->p_Stats, &p_Img->enc_frame_picture[p_Img->rd_pass]->stats);
00718 store_picture_in_dpb (p_Img, p_Inp, p_Img->enc_frame_picture[p_Img->rd_pass], &p_Inp->output);
00719 free_pictures(p_Img, p_Inp, p_Img->rd_pass);
00720 }
00721 }
00722 }
00723
00724 p_Img->AverageFrameQP = isign(p_Img->SumFrameQP) * ((iabs(p_Img->SumFrameQP) + (int) (p_Img->FrameSizeInMbs >> 1))/ (int) p_Img->FrameSizeInMbs);
00725
00726 if ( p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE && p_Img->type != B_SLICE && p_Inp->basicunit < p_Img->FrameSizeInMbs )
00727 p_Img->p_rc_quad->CurrLastQP = p_Img->AverageFrameQP + p_Img->p_rc_quad->bitdepth_qp_scale;
00728
00729 #ifdef _LEAKYBUCKET_
00730
00731 if (!p_Img->redundant_coding)
00732 {
00733 p_Img->Bit_Buffer[p_Img->total_frame_buffer++] = (long) (p_Img->p_Stats->bit_ctr - p_Img->p_Stats->bit_ctr_n)
00734 + (long)( p_Img->p_Stats->bit_ctr_filler_data - p_Img->p_Stats->bit_ctr_filler_data_n );
00735 }
00736 #endif
00737
00738
00739
00740 if (p_Img->pic_order_cnt_type == 2)
00741 {
00742 if (!p_Img->nal_reference_idc) consecutive_non_reference_pictures++;
00743 else consecutive_non_reference_pictures = 0;
00744
00745 if (p_Img->frame_no < prev_frame_no || consecutive_non_reference_pictures>1)
00746 error("POC type 2 cannot be applied for the coding pattern where the encoding /decoding order of pictures are different from the output order.\n", -1);
00747 prev_frame_no = p_Img->frame_no;
00748 }
00749
00750 gettime(&end_time);
00751 tmp_time = timediff(&start_time, &end_time);
00752 p_Img->tot_time += tmp_time;
00753 tmp_time = timenorm(tmp_time);
00754 p_Img->me_time = timenorm(p_Img->me_time);
00755
00756 if (p_Img->p_Stats->bit_ctr_parametersets_n!=0 && p_Inp->Verbose != 3)
00757 ReportNALNonVLCBits(p_Img, p_Inp, p_Img->p_Stats, tmp_time);
00758
00759 if (p_Img->frm_number == 0)
00760 ReportFirstframe(p_Img, p_Inp, p_Img->p_Stats, tmp_time);
00761 else
00762 {
00763
00764 if(p_Inp->RCEnable)
00765 {
00766 if ((!p_Inp->PicInterlace) && (!p_Inp->MbInterlace))
00767 {
00768 bits = (int) (p_Img->p_Stats->bit_ctr - p_Img->p_Stats->bit_ctr_n)
00769 + (int)( p_Img->p_Stats->bit_ctr_filler_data - p_Img->p_Stats->bit_ctr_filler_data_n );
00770 }
00771 else if ( p_Inp->RCUpdateMode <= MAX_RC_MODE )
00772 {
00773 bits = (int)(p_Img->p_Stats->bit_ctr - (p_Img->p_rc_quad->Pprev_bits))
00774 + (int)( p_Img->p_Stats->bit_ctr_filler_data - p_Img->p_Stats->bit_ctr_filler_data_n );
00775 p_Img->p_rc_quad->Pprev_bits = p_Img->p_Stats->bit_ctr + p_Img->p_Stats->bit_ctr_filler_data;
00776 }
00777 }
00778
00779 p_Img->p_Stats->bit_counter[p_Img->type] += p_Img->p_Stats->bit_ctr - p_Img->p_Stats->bit_ctr_n;
00780
00781 switch (p_Img->type)
00782 {
00783 case I_SLICE:
00784 case SI_SLICE:
00785 ReportI(p_Img, p_Inp, p_Img->p_Stats, tmp_time);
00786 break;
00787 case B_SLICE:
00788 ReportB(p_Img, p_Inp, p_Img->p_Stats, tmp_time);
00789 break;
00790 default:
00791 ReportP(p_Img, p_Inp, p_Img->p_Stats, tmp_time);
00792 }
00793 }
00794
00795 if (p_Inp->Verbose == 0)
00796 {
00797
00798
00799
00800 printf("Completed Encoding Frame %05d.\r", p_Img->frame_no);
00801 }
00802
00803 fflush(stdout);
00804
00805
00806 if(p_Inp->RCEnable)
00807 p_Img->rc_update_picture_ptr( p_Img, p_Inp, bits );
00808
00809
00810 p_Img->p_Stats->bit_ctr_n = p_Img->p_Stats->bit_ctr;
00811 p_Img->p_Stats->bit_ctr_parametersets_n = 0;
00812 p_Img->p_Stats->bit_ctr_filler_data_n = p_Img->p_Stats->bit_ctr_filler_data;
00813
00814 if ( p_Img->type == I_SLICE && p_Img->nal_reference_idc)
00815 {
00816
00817
00818 if ( !(p_Img->b_frame_to_code) )
00819 {
00820 p_Img->lastINTRA = imax(p_Img->lastINTRA, p_Img->frame_no);
00821 p_Img->lastIntraNumber = p_Img->frm_number;
00822 }
00823 if ( p_Img->currentPicture->idr_flag )
00824 {
00825 p_Img->lastIDRnumber = p_Img->frm_number;
00826 }
00827 }
00828
00829 return ((p_Img->gop_number == 0)? 0 : 1);
00830 }
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843 static void writeout_picture(ImageParameters *p_Img, Picture *pic)
00844 {
00845 int partition, slice;
00846 Slice *currSlice;
00847
00848 p_Img->currentPicture = pic;
00849
00850
00851 for (slice=0; slice < pic->no_slices; slice++)
00852 {
00853 currSlice = pic->slices[slice];
00854
00855
00856 for (partition=0; partition < currSlice->max_part_nr; partition++)
00857 {
00858
00859 if (currSlice->partArr[partition].bitstream->write_flag )
00860 {
00861 p_Img->p_Stats->bit_ctr += p_Img->WriteNALU (p_Img, currSlice->partArr[partition].nal_unit);
00862 }
00863 }
00864 }
00865 }
00866
00867
00868 void copy_params(ImageParameters *p_Img, StorablePicture *enc_picture, seq_parameter_set_rbsp_t *active_sps)
00869 {
00870 enc_picture->frame_mbs_only_flag = active_sps->frame_mbs_only_flag;
00871 enc_picture->frame_cropping_flag = active_sps->frame_cropping_flag;
00872 enc_picture->chroma_format_idc = active_sps->chroma_format_idc;
00873 enc_picture->chroma_mask_mv_x = p_Img->chroma_mask_mv_x;
00874 enc_picture->chroma_mask_mv_y = p_Img->chroma_mask_mv_y;
00875 enc_picture->chroma_shift_y = p_Img->chroma_shift_y;
00876 enc_picture->chroma_shift_x = p_Img->chroma_shift_x;
00877
00878
00879 if (active_sps->frame_cropping_flag)
00880 {
00881 enc_picture->frame_cropping_rect_left_offset = active_sps->frame_cropping_rect_left_offset;
00882 enc_picture->frame_cropping_rect_right_offset = active_sps->frame_cropping_rect_right_offset;
00883 enc_picture->frame_cropping_rect_top_offset = active_sps->frame_cropping_rect_top_offset;
00884 enc_picture->frame_cropping_rect_bottom_offset = active_sps->frame_cropping_rect_bottom_offset;
00885 }
00886 else
00887 {
00888 enc_picture->frame_cropping_rect_left_offset = 0;
00889 enc_picture->frame_cropping_rect_right_offset = 0;
00890 enc_picture->frame_cropping_rect_top_offset = 0;
00891 enc_picture->frame_cropping_rect_bottom_offset = 0;
00892 }
00893 }
00894
00895
00896
00897
00898
00899
00900
00901 static void prepare_enc_frame_picture (ImageParameters *p_Img, InputParameters *p_Inp, StorablePicture **stored_pic)
00902 {
00903 (*stored_pic) = alloc_storable_picture (p_Img, p_Inp, (PictureStructure) p_Img->structure, p_Img->width, p_Img->height, p_Img->width_cr, p_Img->height_cr);
00904
00905 p_Img->ThisPOC = p_Img->framepoc;
00906 (*stored_pic)->poc = p_Img->framepoc;
00907 (*stored_pic)->top_poc = p_Img->toppoc;
00908 (*stored_pic)->bottom_poc = p_Img->bottompoc;
00909 (*stored_pic)->frame_poc = p_Img->framepoc;
00910 (*stored_pic)->pic_num = p_Img->frame_num;
00911 (*stored_pic)->frame_num = p_Img->frame_num;
00912 (*stored_pic)->coded_frame = 1;
00913 (*stored_pic)->MbaffFrameFlag = p_Img->MbaffFrameFlag = (Boolean) (p_Inp->MbInterlace != FRAME_CODING);
00914
00915 p_Img->get_mb_block_pos = p_Img->MbaffFrameFlag ? get_mb_block_pos_mbaff : get_mb_block_pos_normal;
00916 p_Img->getNeighbour = p_Img->MbaffFrameFlag ? getAffNeighbour : getNonAffNeighbour;
00917 p_Img->enc_picture = *stored_pic;
00918
00919 copy_params(p_Img, p_Img->enc_picture, p_Img->active_sps);
00920 }
00921
00922 static void calc_picture_bits(Picture *frame)
00923 {
00924 int i, j;
00925 Slice *thisSlice = NULL;
00926
00927 frame->bits_per_picture = 0;
00928
00929 for ( i = 0; i < frame->no_slices; i++ )
00930 {
00931 thisSlice = frame->slices[i];
00932
00933 for ( j = 0; j < thisSlice->max_part_nr; j++ )
00934 frame->bits_per_picture += 8 * ((thisSlice->partArr[j]).bitstream)->byte_pos;
00935 }
00936 }
00937
00938
00939
00940
00941
00942
00943 void frame_picture (ImageParameters *p_Img, InputParameters *p_Inp, Picture *frame, ImageData *imgData, int rd_pass)
00944 {
00945 int nplane;
00946 p_Img->SumFrameQP = 0;
00947 p_Img->num_ref_idx_l0_active = 0;
00948 p_Img->num_ref_idx_l1_active = 0;
00949 p_Img->structure = FRAME;
00950 p_Img->PicSizeInMbs = p_Img->FrameSizeInMbs;
00951
00952 update_mv_limits(p_Img, p_Inp, FALSE);
00953
00954
00955 if( IS_INDEPENDENT(p_Inp) )
00956 {
00957 for( nplane=0; nplane<MAX_PLANE; nplane++ )
00958 {
00959 prepare_enc_frame_picture( p_Img, p_Inp, &p_Img->enc_frame_picture_JV[nplane] );
00960 }
00961 }
00962 else
00963 {
00964 prepare_enc_frame_picture( p_Img, p_Inp, &p_Img->enc_frame_picture[rd_pass] );
00965 }
00966
00967
00968 p_Img->fld_flag = FALSE;
00969 code_a_picture(p_Img, p_Inp, frame);
00970
00971 if( IS_INDEPENDENT(p_Inp) )
00972 {
00973 make_frame_picture_JV(p_Img, p_Inp);
00974 }
00975
00976 calc_picture_bits(frame);
00977
00978 if (p_Img->structure==FRAME)
00979 {
00980 find_distortion (p_Img, p_Inp, imgData);
00981 frame->distortion = p_Img->p_Dist->metric[SSE];
00982 }
00983 }
00984
00985
00986
00987
00988
00989
00990
00991
00992 static void field_picture (ImageParameters *p_Img, InputParameters *p_Inp, Picture *top, Picture *bottom)
00993 {
00994
00995 int old_pic_type;
00996 int TopFieldBits;
00997 p_Img->SumFrameQP = 0;
00998 p_Img->num_ref_idx_l0_active = 0;
00999 p_Img->num_ref_idx_l1_active = 0;
01000
01001
01002 update_mv_limits(p_Img, p_Inp, TRUE);
01003
01004
01005 old_pic_type = p_Img->type;
01006
01007 p_Img->number *= 2;
01008 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01009 p_Img->buf_cycle *= 2;
01010 p_Img->height = (p_Inp->output.height + p_Img->auto_crop_bottom) >> 1;
01011 p_Img->height_cr = p_Img->height_cr_frame >> 1;
01012 p_Img->fld_flag = TRUE;
01013 p_Img->PicSizeInMbs = p_Img->FrameSizeInMbs >> 1;
01014
01015
01016 p_Img->enc_field_picture[0] = alloc_storable_picture (p_Img, p_Inp, (PictureStructure) p_Img->structure, p_Img->width, p_Img->height, p_Img->width_cr, p_Img->height_cr);
01017 p_Img->enc_field_picture[0]->poc = p_Img->toppoc;
01018 p_Img->enc_field_picture[0]->frame_poc = p_Img->toppoc;
01019 p_Img->enc_field_picture[0]->pic_num = p_Img->frame_num;
01020 p_Img->enc_field_picture[0]->frame_num = p_Img->frame_num;
01021 p_Img->enc_field_picture[0]->coded_frame = 0;
01022 p_Img->enc_field_picture[0]->MbaffFrameFlag = p_Img->MbaffFrameFlag = FALSE;
01023 p_Img->get_mb_block_pos = get_mb_block_pos_normal;
01024 p_Img->getNeighbour = getNonAffNeighbour;
01025 p_Img->ThisPOC = p_Img->toppoc;
01026
01027 p_Img->structure = TOP_FIELD;
01028 p_Img->enc_picture = p_Img->enc_field_picture[0];
01029 copy_params(p_Img, p_Img->enc_picture, p_Img->active_sps);
01030
01031 put_buffer_top (p_Img);
01032 init_field (p_Img, p_Inp);
01033
01034 p_Img->fld_flag = TRUE;
01035
01036
01037 if(p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE)
01038 rc_init_top_field(p_Img, p_Inp);
01039
01040 code_a_picture(p_Img, p_Inp, p_Img->field_pic[0]);
01041 p_Img->enc_picture->structure = TOP_FIELD;
01042
01043 store_picture_in_dpb(p_Img, p_Inp, p_Img->enc_field_picture[0], &p_Inp->output);
01044
01045 calc_picture_bits(top);
01046
01047
01048 TopFieldBits=top->bits_per_picture;
01049
01050
01051 p_Img->enc_field_picture[1] = alloc_storable_picture (p_Img, p_Inp, (PictureStructure) p_Img->structure, p_Img->width, p_Img->height, p_Img->width_cr, p_Img->height_cr);
01052 p_Img->enc_field_picture[1]->poc=p_Img->bottompoc;
01053 p_Img->enc_field_picture[1]->frame_poc = p_Img->bottompoc;
01054 p_Img->enc_field_picture[1]->pic_num = p_Img->frame_num;
01055 p_Img->enc_field_picture[1]->frame_num = p_Img->frame_num;
01056 p_Img->enc_field_picture[1]->coded_frame = 0;
01057 p_Img->enc_field_picture[1]->MbaffFrameFlag = p_Img->MbaffFrameFlag = FALSE;
01058 p_Img->get_mb_block_pos = get_mb_block_pos_normal;
01059 p_Img->getNeighbour = getNonAffNeighbour;
01060
01061 p_Img->ThisPOC = p_Img->bottompoc;
01062 p_Img->structure = BOTTOM_FIELD;
01063 p_Img->enc_picture = p_Img->enc_field_picture[1];
01064 copy_params(p_Img, p_Img->enc_picture, p_Img->active_sps);
01065 put_buffer_bot (p_Img);
01066 p_Img->number++;
01067 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01068
01069 init_field (p_Img, p_Inp);
01070
01071 if (p_Img->type == I_SLICE && p_Inp->IntraBottom!=1)
01072 set_slice_type(p_Img, p_Inp, (p_Inp->BRefPictures == 2) ? B_SLICE : P_SLICE);
01073
01074 p_Img->fld_flag = TRUE;
01075
01076
01077 if(p_Inp->RCEnable && p_Inp->RCUpdateMode <= MAX_RC_MODE)
01078 rc_init_bottom_field( p_Img, p_Inp, TopFieldBits );
01079
01080 p_Img->enc_picture->structure = BOTTOM_FIELD;
01081 code_a_picture(p_Img, p_Inp, p_Img->field_pic[1]);
01082
01083 calc_picture_bits(bottom);
01084
01085
01086
01087 distortion_fld (p_Img, p_Inp, top, &p_Img->imgData);
01088 }
01089
01090
01091
01092
01093
01094
01095
01096 static void combine_field(ImageParameters *p_Img)
01097 {
01098 int i, k;
01099
01100 for (i = 0; i < (p_Img->height >> 1); i++)
01101 {
01102 memcpy(p_Img->imgY_com[i*2], p_Img->enc_field_picture[0]->imgY[i], p_Img->width*sizeof(imgpel));
01103 memcpy(p_Img->imgY_com[i*2 + 1], p_Img->enc_field_picture[1]->imgY[i], p_Img->width*sizeof(imgpel));
01104 }
01105
01106 if (p_Img->yuv_format != YUV400)
01107 {
01108 for (k = 0; k < 2; k++)
01109 {
01110 for (i = 0; i < (p_Img->height_cr >> 1); i++)
01111 {
01112 memcpy(p_Img->imgUV_com[k][i*2], p_Img->enc_field_picture[0]->imgUV[k][i], p_Img->width_cr*sizeof(imgpel));
01113 memcpy(p_Img->imgUV_com[k][i*2 + 1], p_Img->enc_field_picture[1]->imgUV[k][i], p_Img->width_cr*sizeof(imgpel));
01114 }
01115 }
01116 }
01117 }
01118
01119
01120
01121
01122
01123
01124
01125 static void distortion_fld (ImageParameters *p_Img, InputParameters *p_Inp, Picture *field_pic, ImageData *imgData)
01126 {
01127
01128 p_Img->number /= 2;
01129 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01130 p_Img->buf_cycle /= 2;
01131 p_Img->height = (p_Inp->output.height + p_Img->auto_crop_bottom);
01132 p_Img->height_cr = p_Img->height_cr_frame;
01133
01134 combine_field (p_Img);
01135
01136 p_Img->pCurImg = imgData->frm_data[0];
01137 p_Img->pImgOrg[0] = imgData->frm_data[0];
01138
01139 if (p_Inp->output.yuv_format != YUV400)
01140 {
01141 p_Img->pImgOrg[1] = imgData->frm_data[1];
01142 p_Img->pImgOrg[2] = imgData->frm_data[2];
01143 }
01144
01145 find_distortion (p_Img, p_Inp, imgData);
01146 field_pic->distortion = p_Img->p_Dist->metric[SSE];
01147 }
01148
01149
01150
01151
01152
01153
01154
01155
01156 static byte decide_fld_frame(float snr_frame_Y, float snr_field_Y, int bit_field, int bit_frame, double lambda_picture)
01157 {
01158 double cost_frame, cost_field;
01159
01160 cost_frame = bit_frame * lambda_picture + snr_frame_Y;
01161 cost_field = bit_field * lambda_picture + snr_field_Y;
01162
01163 if (cost_field > cost_frame)
01164 return FALSE;
01165 else
01166 return TRUE;
01167 }
01168
01169
01170
01171
01172
01173
01174
01175 static byte picture_structure_decision (ImageParameters *p_Img, Picture *frame, Picture *top, Picture *bot)
01176 {
01177 double lambda_picture;
01178 float sse_frame, sse_field;
01179 int bit_frame, bit_field;
01180
01181 lambda_picture = 0.68 * pow (2, p_Img->bitdepth_lambda_scale + ((p_Img->qp - SHIFT_QP) / 3.0)) * ((p_Img->type == B_SLICE) ? 1 : 1);
01182
01183 sse_frame = frame->distortion.value[0] + frame->distortion.value[1] + frame->distortion.value[2];
01184
01185 sse_field = top->distortion.value[0] + top->distortion.value[1] + top->distortion.value[2];
01186
01187 bit_field = top->bits_per_picture + bot->bits_per_picture;
01188 bit_frame = frame->bits_per_picture;
01189 return decide_fld_frame (sse_frame, sse_field, bit_field, bit_frame, lambda_picture);
01190 }
01191
01192
01193
01194
01195
01196
01197
01198
01199 static void field_mode_buffer (ImageParameters *p_Img)
01200 {
01201 put_buffer_frame (p_Img);
01202 }
01203
01204
01205
01206
01207
01208
01209
01210
01211 static void frame_mode_buffer (ImageParameters *p_Img, InputParameters *p_Inp)
01212 {
01213 put_buffer_frame (p_Img);
01214
01215 if ((p_Inp->PicInterlace != FRAME_CODING)||(p_Inp->MbInterlace != FRAME_CODING))
01216 {
01217 p_Img->height = p_Img->height / 2;
01218 p_Img->height_cr = p_Img->height_cr / 2;
01219 p_Img->number *= 2;
01220 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01221
01222 put_buffer_top (p_Img);
01223
01224 p_Img->number++;
01225 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01226 put_buffer_bot (p_Img);
01227
01228 p_Img->number /= 2;
01229 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01230 p_Img->height = (p_Inp->output.height + p_Img->auto_crop_bottom);
01231 p_Img->height_cr = p_Img->height_cr_frame;
01232
01233 put_buffer_frame (p_Img);
01234 }
01235 }
01236
01237
01238
01239
01240
01241
01242
01243
01244 static void init_dec_ref_pic_marking_buffer(ImageParameters *p_Img)
01245 {
01246 p_Img->dec_ref_pic_marking_buffer=NULL;
01247 }
01248
01249
01250
01251
01252
01253
01254
01255
01256 static void init_frame (ImageParameters *p_Img, InputParameters *p_Inp)
01257 {
01258 int i, j;
01259
01260 p_Img->current_mb_nr = 0;
01261 p_Img->current_slice_nr = 0;
01262 p_Img->p_Stats->bit_slice = 0;
01263
01264
01265
01266
01267 if( IS_INDEPENDENT(p_Inp) )
01268 {
01269 for( j=0; j<MAX_PLANE; j++ ){
01270 for(i=0;i< ((int) (p_Img->FrameSizeInMbs));i++)
01271 p_Img->mb_data_JV[j][i].slice_nr=-1;
01272 }
01273 }
01274 else
01275 {
01276 for(i = 0; i < ((int) (p_Img->FrameSizeInMbs)); i++)
01277 p_Img->mb_data[i].slice_nr = -1;
01278 }
01279
01280 if (p_Img->b_frame_to_code == 0)
01281 {
01282
01283 if(!p_Inp->RCEnable)
01284 {
01285 if (p_Img->type == I_SLICE)
01286 {
01287
01288 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01289 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01290 p_Img->qp = p_Inp->qp[1][I_SLICE];
01291 else
01292 p_Img->qp = p_Inp->qp[0][I_SLICE];
01293
01294 if (p_Img->redundant_coding)
01295 {
01296
01297 p_Img->qp = imin(p_Img->qp + 5, 51);
01298 }
01299 }
01300 else
01301 {
01302
01303 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01304 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01305 p_Img->qp = p_Inp->qp[1][P_SLICE] + (p_Img->nal_reference_idc ? 0 : p_Inp->DispPQPOffset);
01306 else
01307 p_Img->qp = p_Inp->qp[0][P_SLICE] + (p_Img->nal_reference_idc ? 0 : p_Inp->DispPQPOffset);
01308
01309 if (p_Img->type == SP_SLICE)
01310 {
01311 if ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ))
01312 {
01313 p_Img->qp = p_Inp->qp[1][SP_SLICE];
01314 p_Img->qpsp = p_Inp->qpsp[1];
01315 }
01316 else
01317 {
01318 p_Img->qp = p_Inp->qp[0][SP_SLICE];
01319 p_Img->qpsp = p_Inp->qpsp[0];
01320 }
01321 }
01322 }
01323 }
01324
01325 p_Img->mb_y_intra = p_Img->mb_y_upd;
01326
01327 if (p_Inp->intra_upd > 0)
01328 {
01329 p_Img->mb_y_upd = (p_Img->frm_number / p_Inp->intra_upd) % (p_Img->height / MB_BLOCK_SIZE);
01330 }
01331 }
01332 else
01333 {
01334
01335 if(!p_Inp->RCEnable && p_Inp->HierarchicalCoding == 0)
01336 {
01337
01338 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01339 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01340 {
01341 p_Img->qp = p_Inp->qp[1][B_SLICE];
01342 }
01343 else
01344 {
01345 p_Img->qp = p_Inp->qp[0][B_SLICE];
01346 }
01347
01348 if (p_Img->nal_reference_idc)
01349 {
01350
01351 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01352 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01353 {
01354 p_Img->qp = iClip3(-p_Img->bitdepth_luma_qp_scale,51,p_Inp->qp[1][B_SLICE] + p_Inp->qpBRSOffset[1]);
01355 }
01356 else
01357 {
01358 p_Img->qp = iClip3(-p_Img->bitdepth_luma_qp_scale, 51, p_Inp->qp[0][B_SLICE] + p_Inp->qpBRSOffset[0]);
01359 }
01360 }
01361 }
01362 else if (!p_Inp->RCEnable && p_Inp->HierarchicalCoding !=0)
01363 {
01364
01365 p_Img->qp = p_Img->gop_structure[p_Img->b_frame_to_code - 1].slice_qp;
01366
01367 }
01368 }
01369
01370 p_Img->no_output_of_prior_pics_flag = 0;
01371 p_Img->long_term_reference_flag = FALSE;
01372
01373 init_dec_ref_pic_marking_buffer(p_Img);
01374
01375 if(p_Inp->WPIterMC)
01376 p_Img->frameOffsetAvail = 0;
01377
01378
01379
01380 p_Img->direct_spatial_mv_pred_flag = (char) p_Inp->direct_spatial_mv_pred_flag;
01381 p_Img->DFDisableIdc = (char) p_Inp->DFDisableIdc[p_Img->nal_reference_idc > 0][p_Img->type];
01382 p_Img->DFAlphaC0Offset = (char) p_Inp->DFAlpha [p_Img->nal_reference_idc > 0][p_Img->type];
01383 p_Img->DFBetaOffset = (char) p_Inp->DFBeta [p_Img->nal_reference_idc > 0][p_Img->type];
01384
01385 p_Img->AdaptiveRounding = p_Inp->AdaptiveRounding;
01386 }
01387
01388
01389
01390
01391
01392
01393
01394 static void init_field (ImageParameters *p_Img, InputParameters *p_Inp)
01395 {
01396 p_Img->current_mb_nr = 0;
01397 p_Img->current_slice_nr = 0;
01398 p_Img->p_Stats->bit_slice = 0;
01399
01400 p_Inp->jumpd *= 2;
01401 p_Inp->NumberBFrames *= 2;
01402 p_Img->number /= 2;
01403 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01404 p_Img->buf_cycle /= 2;
01405
01406 if (!p_Img->b_frame_to_code)
01407 {
01408
01409 if(!p_Inp->RCEnable)
01410 {
01411 if (p_Img->type == I_SLICE)
01412 {
01413
01414 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01415 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01416 p_Img->qp = p_Inp->qp[1][I_SLICE];
01417 else
01418 p_Img->qp = p_Inp->qp[0][I_SLICE];
01419 }
01420 else
01421 {
01422
01423 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01424 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01425 p_Img->qp = p_Inp->qp[1][P_SLICE] + (p_Img->nal_reference_idc ? 0 : p_Inp->DispPQPOffset);
01426 else
01427 p_Img->qp = p_Inp->qp[0][P_SLICE] + (p_Img->nal_reference_idc ? 0 : p_Inp->DispPQPOffset);
01428
01429 if (p_Img->type == SP_SLICE)
01430 {
01431 if ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ))
01432 {
01433 p_Img->qp = p_Inp->qp[1][SP_SLICE];
01434 p_Img->qpsp = p_Inp->qpsp[1];
01435 }
01436 else
01437 {
01438 p_Img->qp = p_Inp->qp[0][SP_SLICE];
01439 p_Img->qpsp = p_Inp->qpsp[0];
01440 }
01441 }
01442 }
01443 }
01444 p_Img->mb_y_intra = p_Img->mb_y_upd;
01445
01446 if (p_Inp->intra_upd > 0)
01447 {
01448 p_Img->mb_y_upd =
01449 (p_Img->number / p_Inp->intra_upd) % (p_Img->width / MB_BLOCK_SIZE);
01450 }
01451 }
01452 else
01453 {
01454
01455 if(!p_Inp->RCEnable && p_Inp->HierarchicalCoding == 0)
01456 {
01457
01458 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01459 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01460 {
01461 p_Img->qp = p_Inp->qp[1][B_SLICE];
01462 }
01463 else
01464 p_Img->qp = p_Inp->qp[0][B_SLICE];
01465 if (p_Img->nal_reference_idc)
01466 {
01467
01468 if ((p_Inp->qp2start > 0 && p_Img->frame_no >= p_Inp->qp2start && p_Inp->sp2_frame_indicator==0)||
01469 ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ) && (p_Inp->sp2_frame_indicator==1)))
01470 {
01471 p_Img->qp = iClip3(-p_Img->bitdepth_luma_qp_scale,51,p_Inp->qp[1][B_SLICE] + p_Inp->qpBRSOffset[1]);
01472 }
01473 else
01474 p_Img->qp = iClip3(-p_Img->bitdepth_luma_qp_scale,51,p_Inp->qp[0][B_SLICE] + p_Inp->qpBRSOffset[0]);
01475
01476 }
01477 }
01478 else if (!p_Inp->RCEnable && p_Inp->HierarchicalCoding != 0)
01479 {
01480 p_Img->qp = p_Img->gop_structure[p_Img->b_frame_to_code - 1].slice_qp;
01481 }
01482 }
01483 p_Inp->jumpd /= 2;
01484 p_Inp->NumberBFrames /= 2;
01485 p_Img->buf_cycle *= 2;
01486 p_Img->number = 2 * p_Img->number + p_Img->fld_type;
01487 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01488 }
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502 void UnifiedOneForthPix ( ImageParameters *p_Img, InputParameters *p_Inp, StorablePicture *s)
01503 {
01504 int ypadded_size = s->size_y_padded;
01505 int xpadded_size = s->size_x_padded;
01506
01507
01508 if (s->imgY_sub)
01509 return;
01510
01511 get_mem4Dpel (&(s->imgY_sub), 4, 4, ypadded_size, xpadded_size);
01512 if (NULL == s->imgY_sub)
01513 no_mem_exit("alloc_storable_picture: s->imgY_sub");
01514 s->p_img_sub[0] = s->imgY_sub;
01515 s->p_curr_img_sub = s->imgY_sub;
01516 s->p_curr_img = s->imgY;
01517
01518 if ( p_Inp->ChromaMCBuffer || p_Img->P444_joined)
01519 {
01520
01521 if ( p_Img->yuv_format != YUV400 )
01522 {
01523 if ( p_Img->yuv_format == YUV420 )
01524 {
01525 get_mem5Dpel (&(s->imgUV_sub), 2, 8, 8, ypadded_size>>1, xpadded_size>>1);
01526 }
01527 else if ( p_Img->yuv_format == YUV422 )
01528 {
01529 get_mem5Dpel (&(s->imgUV_sub), 2, 4, 8, ypadded_size, xpadded_size>>1);
01530 }
01531 else
01532 {
01533 get_mem5Dpel (&(s->imgUV_sub), 2, 4, 4, ypadded_size, xpadded_size);
01534 }
01535 s->p_img_sub[1] = s->imgUV_sub[0];
01536 s->p_img_sub[2] = s->imgUV_sub[1];
01537 }
01538 else
01539 {
01540 s->p_img_sub[1] = NULL;
01541 s->p_img_sub[2] = NULL;
01542 }
01543 }
01544 else
01545 {
01546 s->p_img_sub[1] = NULL;
01547 s->p_img_sub[2] = NULL;
01548 }
01549
01550
01551
01552
01553 {
01554 getSubImagesLuma ( p_Img, p_Inp, s );
01555
01556
01557 if ( (p_Img->yuv_format != YUV400) && (p_Inp->ChromaMCBuffer) )
01558 {
01559 if (p_Img->P444_joined)
01560 {
01561
01562 select_plane(p_Img, PLANE_U);
01563 getSubImagesLuma (p_Img, p_Inp, s);
01564
01565 select_plane(p_Img, PLANE_V);
01566 getSubImagesLuma (p_Img, p_Inp, s);
01567
01568 select_plane(p_Img, PLANE_Y);
01569 }
01570 else
01571 getSubImagesChroma( p_Img, p_Inp, s );
01572 }
01573 }
01574 }
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586 void UnifiedOneForthPix_JV (ImageParameters *p_Img, InputParameters *p_Inp, int nplane, StorablePicture *s)
01587 {
01588 int ypadded_size = s->size_y_padded;
01589 int xpadded_size = s->size_x_padded;
01590
01591 if( nplane == 0 )
01592 {
01593
01594 if (s->imgY_sub)
01595 return;
01596
01597 get_mem4Dpel (&(s->imgY_sub), 4, 4, ypadded_size, xpadded_size);
01598 if (NULL == s->imgY_sub)
01599 no_mem_exit("UnifiedOneForthPix_JV: s->imgY_sub");
01600
01601
01602 if (s->imgUV_sub)
01603 return;
01604
01605 get_mem5Dpel (&(s->imgUV_sub), 2, 4, 4, ypadded_size, xpadded_size);
01606 if (NULL == s->imgUV_sub)
01607 no_mem_exit("UnifiedOneForthPix_JV: s->imgUV_sub");
01608
01609 s->p_img[0] = s->imgY;
01610 s->p_img[1] = s->imgUV[0];
01611 s->p_img[2] = s->imgUV[1];
01612
01613 s->p_img_sub[0] = s->imgY_sub;
01614 s->p_img_sub[1] = s->imgUV_sub[0];
01615 s->p_img_sub[2] = s->imgUV_sub[1];
01616 }
01617
01618
01619 s->colour_plane_id = nplane;
01620 s->p_curr_img = s->p_img[nplane];
01621 s->p_curr_img_sub = s->p_img_sub[nplane];
01622
01623 getSubImagesLuma ( p_Img, p_Inp, s );
01624 }
01625
01626
01627
01628
01629
01630
01631
01632 Boolean dummy_slice_too_big (int bits_slice)
01633 {
01634 return FALSE;
01635 }
01636
01637
01638 static void ReportSimple(ImageParameters *p_Img, char *pic_type, int cur_bits, DistMetric *metric, int tmp_time)
01639 {
01640 printf ("%05d(%3s)%8d %2d %7.3f %7.3f %7.3f %9d %7d %3s %d\n",
01641 p_Img->frame_no, pic_type, cur_bits,
01642 p_Img->AverageFrameQP,
01643 metric->value[0], metric->value[1], metric->value[2],
01644 tmp_time, (int) p_Img->me_time,
01645 p_Img->fld_flag ? "FLD" : "FRM",
01646 p_Img->nal_reference_idc);
01647 }
01648
01649 static void ReportVerbose(ImageParameters *p_Img, char *pic_type, int cur_bits, int wp_method, int lambda, DistMetric *mPSNR, int tmp_time, int direct_mode)
01650 {
01651 printf ("%05d(%3s)%8d %1d %2d %2d %7.3f %7.3f %7.3f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01652 p_Img->frame_no, pic_type, cur_bits, wp_method,
01653 p_Img->AverageFrameQP, lambda,
01654 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01655 tmp_time, (int) p_Img->me_time,
01656 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01657 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active, p_Img->rd_pass, p_Img->nal_reference_idc);
01658 }
01659
01660 static void ReportVerboseNVB(ImageParameters *p_Img, char *pic_type, int cur_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, int tmp_time, int direct_mode)
01661 {
01662 printf ("%05d(%3s)%8d %3d %1d %2d %2d %7.3f %7.3f %7.3f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01663 p_Img->frame_no, pic_type, cur_bits, nvb_bits, wp_method,
01664 p_Img->AverageFrameQP, lambda,
01665 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01666 tmp_time, (int) p_Img->me_time,
01667 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01668 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active, p_Img->rd_pass, p_Img->nal_reference_idc);
01669 }
01670
01671 static void ReportVerboseFDN(ImageParameters *p_Img, char *pic_type, int cur_bits, int fdn_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, int tmp_time, int direct_mode)
01672 {
01673 printf ("%05d(%3s)%8d %8d %3d %1d %2d %2d %7.3f %7.3f %7.3f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01674 p_Img->frame_no, pic_type, cur_bits, fdn_bits, nvb_bits, wp_method,
01675 p_Img->AverageFrameQP, lambda,
01676 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01677 tmp_time, (int) p_Img->me_time,
01678 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01679 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active, p_Img->rd_pass, p_Img->nal_reference_idc);
01680 }
01681
01682 static void ReportVerboseSSIM(ImageParameters *p_Img, char *pic_type, int cur_bits, int wp_method, int lambda, DistMetric *mPSNR, DistMetric *mSSIM,int tmp_time, int direct_mode)
01683 {
01684 printf ("%05d(%3s)%8d %1d %2d %2d %7.3f %7.3f %7.3f %7.4f %7.4f %7.4f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01685 p_Img->frame_no, pic_type, cur_bits, wp_method,
01686 p_Img->AverageFrameQP, lambda,
01687 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01688 mSSIM->value[0], mSSIM->value[1], mSSIM->value[2],
01689 tmp_time, (int) p_Img->me_time,
01690 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01691 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active,p_Img->rd_pass, p_Img->nal_reference_idc);
01692 }
01693
01694 static void ReportVerboseNVBSSIM(ImageParameters *p_Img, char *pic_type, int cur_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, DistMetric *mSSIM,int tmp_time, int direct_mode)
01695 {
01696 printf ("%05d(%3s)%8d %3d %1d %2d %2d %7.3f %7.3f %7.3f %7.4f %7.4f %7.4f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01697 p_Img->frame_no, pic_type, cur_bits, nvb_bits, wp_method,
01698 p_Img->AverageFrameQP, lambda,
01699 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01700 mSSIM->value[0], mSSIM->value[1], mSSIM->value[2],
01701 tmp_time, (int) p_Img->me_time,
01702 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01703 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active, p_Img->rd_pass, p_Img->nal_reference_idc);
01704 }
01705
01706 static void ReportVerboseFDNSSIM(ImageParameters *p_Img, char *pic_type, int cur_bits, int fdn_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, DistMetric *mSSIM,int tmp_time, int direct_mode)
01707 {
01708 printf ("%05d(%3s)%8d %8d %3d %1d %2d %2d %7.3f %7.3f %7.3f %7.4f %7.4f %7.4f %9d %7d %3s %5d %1d %2d %2d %d %d\n",
01709 p_Img->frame_no, pic_type, cur_bits, fdn_bits, nvb_bits, wp_method,
01710 p_Img->AverageFrameQP, lambda,
01711 mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],
01712 mSSIM->value[0], mSSIM->value[1], mSSIM->value[2],
01713 tmp_time, (int) p_Img->me_time,
01714 p_Img->fld_flag ? "FLD" : "FRM", p_Img->intras, direct_mode,
01715 p_Img->num_ref_idx_l0_active, p_Img->num_ref_idx_l1_active, p_Img->rd_pass, p_Img->nal_reference_idc);
01716 }
01717
01718
01719 static void ReportNALNonVLCBits(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *p_Stats, int64 tmp_time)
01720 {
01721
01722 if (p_Inp->Verbose != 0)
01723 printf ("%05d(NVB)%8d \n", p_Img->frame_no, p_Stats->bit_ctr_parametersets_n);
01724 }
01725
01726 static void ReportFirstframe(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *stats, int64 tmp_time)
01727 {
01728 int cur_bits = (int)(stats->bit_ctr - stats->bit_ctr_n)
01729 + (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n);
01730
01731 if (p_Inp->Verbose == 1)
01732 {
01733 ReportSimple(p_Img, "IDR", cur_bits, &p_Img->p_Dist->metric[PSNR], (int) tmp_time);
01734 }
01735 else if (p_Inp->Verbose == 2)
01736 {
01737 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01738 if (p_Inp->Distortion[SSIM] == 1)
01739 ReportVerboseSSIM(p_Img, "IDR", cur_bits, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01740 else
01741 ReportVerbose(p_Img, "IDR", cur_bits, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01742 }
01743 else if (p_Inp->Verbose == 3)
01744 {
01745 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01746 if (p_Inp->Distortion[SSIM] == 1)
01747 ReportVerboseNVBSSIM(p_Img, "IDR", cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01748 else
01749 ReportVerboseNVB(p_Img, "IDR", cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01750 }
01751 else if (p_Inp->Verbose == 4)
01752 {
01753 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01754 if (p_Inp->Distortion[SSIM] == 1)
01755 ReportVerboseFDNSSIM(p_Img, "IDR", cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01756 else
01757 ReportVerboseFDN(p_Img, "IDR", cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01758 }
01759
01760 stats->bit_counter[I_SLICE] = stats->bit_ctr;
01761 stats->bit_ctr = 0;
01762 }
01763
01764 static void ReportI(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *stats, int64 tmp_time)
01765 {
01766 char pic_type[4];
01767 int cur_bits = (int)(stats->bit_ctr - stats->bit_ctr_n)
01768 + (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n);
01769
01770 if ((p_Inp->redundant_pic_flag == 0) || !p_Img->redundant_coding )
01771 {
01772 if (p_Img->currentPicture->idr_flag == TRUE)
01773 strcpy(pic_type,"IDR");
01774 else
01775 strcpy(pic_type," I ");
01776 }
01777 else
01778 strcpy(pic_type,"R");
01779
01780 if (p_Inp->Verbose == 1)
01781 {
01782 ReportSimple(p_Img, pic_type, cur_bits, &p_Img->p_Dist->metric[PSNR], (int) tmp_time);
01783 }
01784 else if (p_Inp->Verbose == 2)
01785 {
01786 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01787 if (p_Inp->Distortion[SSIM] == 1)
01788 {
01789 ReportVerboseSSIM(p_Img, pic_type, cur_bits, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01790 }
01791 else
01792 {
01793 ReportVerbose(p_Img, pic_type, cur_bits, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01794 }
01795 }
01796 else if (p_Inp->Verbose == 3)
01797 {
01798 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01799 if (p_Inp->Distortion[SSIM] == 1)
01800 {
01801 ReportVerboseNVBSSIM(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01802 }
01803 else
01804 {
01805 ReportVerboseNVB(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01806 }
01807 }
01808 else if (p_Inp->Verbose == 4)
01809 {
01810 int lambda = (int) p_Img->lambda_me[I_SLICE][p_Img->AverageFrameQP][0];
01811 if (p_Inp->Distortion[SSIM] == 1)
01812 {
01813 ReportVerboseFDNSSIM(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01814 }
01815 else
01816 {
01817 ReportVerboseFDN(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, 0, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01818 }
01819 }
01820 }
01821
01822 static void ReportB(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *stats, int64 tmp_time)
01823 {
01824 int cur_bits = (int)(stats->bit_ctr - stats->bit_ctr_n)
01825 + (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n);
01826
01827 if (p_Inp->Verbose == 1)
01828 {
01829 ReportSimple(p_Img, " B ", cur_bits, &p_Img->p_Dist->metric[PSNR], (int) tmp_time);
01830 }
01831 else if (p_Inp->Verbose == 2)
01832 {
01833 int lambda = (int) p_Img->lambda_me[p_Img->nal_reference_idc ? 5 : B_SLICE][p_Img->AverageFrameQP][0];
01834 if (p_Inp->Distortion[SSIM] == 1)
01835 ReportVerboseSSIM(p_Img, " B ", cur_bits, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01836 else
01837 ReportVerbose(p_Img, " B ", cur_bits, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01838 }
01839 else if (p_Inp->Verbose == 3)
01840 {
01841 int lambda = (int) p_Img->lambda_me[p_Img->nal_reference_idc ? 5 : B_SLICE][p_Img->AverageFrameQP][0];
01842 if (p_Inp->Distortion[SSIM] == 1)
01843 ReportVerboseNVBSSIM(p_Img, " B ", cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01844 else
01845 ReportVerboseNVB(p_Img, " B ", cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01846 }
01847 else if (p_Inp->Verbose == 4)
01848 {
01849 int lambda = (int) p_Img->lambda_me[p_Img->nal_reference_idc ? 5 : B_SLICE][p_Img->AverageFrameQP][0];
01850 if (p_Inp->Distortion[SSIM] == 1)
01851 ReportVerboseFDNSSIM(p_Img, " B ", cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01852 else
01853 ReportVerboseFDN(p_Img, " B ", cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_bipred_idc, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, p_Img->direct_spatial_mv_pred_flag);
01854 }
01855 }
01856
01857 static void ReportP(ImageParameters *p_Img, InputParameters *p_Inp, StatParameters *stats, int64 tmp_time)
01858 {
01859 char pic_type[4];
01860 int cur_bits = (int)(stats->bit_ctr - stats->bit_ctr_n)
01861 + (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n);
01862
01863 if (p_Img->type == SP_SLICE)
01864 strcpy(pic_type,"SP ");
01865 else if ((p_Inp->redundant_pic_flag == 0) || !p_Img->redundant_coding )
01866 strcpy(pic_type," P ");
01867 else
01868 strcpy(pic_type," R ");
01869
01870 if (p_Inp->Verbose == 1)
01871 {
01872 ReportSimple(p_Img, pic_type, cur_bits, &p_Img->p_Dist->metric[PSNR], (int) tmp_time);
01873 }
01874 else if (p_Inp->Verbose == 2)
01875 {
01876 int lambda = (int) p_Img->lambda_me[P_SLICE][p_Img->AverageFrameQP][0];
01877 if (p_Inp->Distortion[SSIM] == 1)
01878 ReportVerboseSSIM(p_Img, pic_type, cur_bits, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01879 else
01880 ReportVerbose(p_Img, pic_type, cur_bits, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01881 }
01882 else if (p_Inp->Verbose == 3)
01883 {
01884 int lambda = (int) p_Img->lambda_me[P_SLICE][p_Img->AverageFrameQP][0];
01885 if (p_Inp->Distortion[SSIM] == 1)
01886 ReportVerboseNVBSSIM(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01887 else
01888 ReportVerboseNVB(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01889 }
01890 else if (p_Inp->Verbose == 4)
01891 {
01892 int lambda = (int) p_Img->lambda_me[P_SLICE][p_Img->AverageFrameQP][0];
01893 if (p_Inp->Distortion[SSIM] == 1)
01894 ReportVerboseFDNSSIM(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], &p_Img->p_Dist->metric[SSIM], (int) tmp_time, 0);
01895 else
01896 ReportVerboseFDN(p_Img, pic_type, cur_bits + stats->bit_ctr_parametersets_n, (int)(stats->bit_ctr_filler_data - stats->bit_ctr_filler_data_n), stats->bit_ctr_parametersets_n, p_Img->active_pps->weighted_pred_flag, lambda, &p_Img->p_Dist->metric[PSNR], (int) tmp_time, 0);
01897 }
01898 }
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911 int CalculateFrameNumber(ImageParameters *p_Img, InputParameters *p_Inp)
01912 {
01913 int frm_sign = (p_Img->gop_number && (p_Img->gop_number <= p_Inp->intra_delay)) ? -1 : 1;
01914 int delay = (p_Img->gop_number <= p_Inp->intra_delay) ? p_Inp->intra_delay : 0;
01915
01916 if (p_Img->b_frame_to_code)
01917 {
01918 if ((p_Img->gop_number && (p_Img->gop_number <= p_Inp->intra_delay)))
01919 {
01920 if (p_Inp->HierarchicalCoding)
01921 p_Img->frame_no = p_Img->start_tr_gop + (p_Inp->intra_delay - p_Img->gop_number) * p_Img->base_dist
01922 + (int) (p_Img->frame_interval * (double) (1 + p_Img->gop_structure[p_Img->b_frame_to_code - 1].display_no));
01923 else
01924 p_Img->frame_no = p_Img->start_tr_gop + (p_Inp->intra_delay - p_Img->gop_number) * p_Img->base_dist
01925 + (int) (p_Img->frame_interval * (double) p_Img->b_frame_to_code);
01926 }
01927 else
01928 {
01929 if (p_Inp->HierarchicalCoding)
01930 p_Img->frame_no = p_Img->start_tr_gop + (p_Img->gop_number - 1) * p_Img->base_dist
01931 + (int) (p_Img->frame_interval * (double) (1 + p_Img->gop_structure[p_Img->b_frame_to_code - 1].display_no));
01932 else
01933 p_Img->frame_no = p_Img->start_tr_gop + (p_Img->gop_number - 1) * p_Img->base_dist
01934 + (int) (p_Img->frame_interval * (double) p_Img->b_frame_to_code);
01935 }
01936
01937 }
01938 else
01939 {
01940 if (p_Inp->idr_period && p_Inp->EnableIDRGOP && p_Img->frm_number &&
01941 ((!p_Inp->adaptive_idr_period && (p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period == 0)
01942 || (p_Inp->adaptive_idr_period == 1 && (p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period == 0)) )
01943 {
01944 delay = p_Inp->intra_delay;
01945 p_Img->rewind_frame += p_Inp->NumberBFrames;
01946 p_Img->start_frame_no = p_Img->frm_number;
01947 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
01948 p_Img->start_tr_gop = (p_Img->frm_number) * p_Img->base_dist - p_Img->rewind_frame;
01949 }
01950
01951 p_Img->frame_no = p_Img->start_tr_gop + (frm_sign * p_Img->gop_number + delay) * p_Img->base_dist;
01952
01953 if (p_Img->frame_no > p_Inp->last_frame)
01954 p_Img->frame_no = imin(p_Img->frame_no, (p_Inp->no_frames - 1) * (p_Inp->frame_skip + 1));
01955
01956 }
01957
01958 return p_Img->frame_no;
01959 }
01960
01961
01962
01963
01964
01965
01966
01967 static void put_buffer_frame(ImageParameters *p_Img)
01968 {
01969 p_Img->pCurImg = p_Img->imgData.frm_data[0];
01970 p_Img->pImgOrg[0] = p_Img->imgData.frm_data[0];
01971
01972 if (p_Img->yuv_format != YUV400)
01973 {
01974 p_Img->pImgOrg[1] = p_Img->imgData.frm_data[1];
01975 p_Img->pImgOrg[2] = p_Img->imgData.frm_data[2];
01976 }
01977 }
01978
01979
01980
01981
01982
01983
01984
01985 static void put_buffer_top(ImageParameters *p_Img)
01986 {
01987 p_Img->fld_type = 0;
01988
01989 p_Img->pCurImg = p_Img->imgData.top_data[0];
01990 p_Img->pImgOrg[0] = p_Img->imgData.top_data[0];
01991
01992 if (p_Img->yuv_format != YUV400)
01993 {
01994 p_Img->pImgOrg[1] = p_Img->imgData.top_data[1];
01995 p_Img->pImgOrg[2] = p_Img->imgData.top_data[2];
01996 }
01997 }
01998
01999
02000
02001
02002
02003
02004
02005 static void put_buffer_bot(ImageParameters *p_Img)
02006 {
02007 p_Img->fld_type = 1;
02008
02009 p_Img->pCurImg = p_Img->imgData.bot_data[0];
02010 p_Img->pImgOrg[0] = p_Img->imgData.bot_data[0];
02011
02012 if (p_Img->yuv_format != YUV400)
02013 {
02014 p_Img->pImgOrg[1] = p_Img->imgData.bot_data[1];
02015 p_Img->pImgOrg[2] = p_Img->imgData.bot_data[2];
02016 }
02017 }
02018
02019
02020
02021
02022
02023
02024
02025 void output_SP_coefficients(ImageParameters *p_Img, InputParameters *p_Inp)
02026 {
02027 int i,k;
02028 FILE *SP_coeff_file;
02029 int ret;
02030 if(p_Img->number_sp2_frames==0)
02031 {
02032 if ((SP_coeff_file = fopen(p_Inp->sp_output_filename,"wb")) == NULL)
02033 {
02034 printf ("Fatal: cannot open SP output file '%s', exit (-1)\n", p_Inp->sp_output_filename);
02035 exit (-1);
02036 }
02037 p_Img->number_sp2_frames++;
02038 }
02039 else
02040 {
02041 if ((SP_coeff_file = fopen(p_Inp->sp_output_filename,"ab")) == NULL)
02042 {
02043 printf ("Fatal: cannot open SP output file '%s', exit (-1)\n", p_Inp->sp_output_filename);
02044 exit (-1);
02045 }
02046 }
02047
02048 for(i=0;i<p_Img->height;i++)
02049 {
02050 ret = fwrite(p_Img->lrec[i],sizeof(int),p_Img->width,SP_coeff_file);
02051 if (ret != p_Img->width)
02052 {
02053 error ("cannot write to SP output file", -1);
02054 }
02055 }
02056
02057 for(k=0;k<2;k++)
02058 {
02059 for(i=0;i<p_Img->height_cr;i++)
02060 {
02061 ret = fwrite(p_Img->lrec_uv[k][i],sizeof(int),p_Img->width_cr,SP_coeff_file);
02062 if (ret != p_Img->width_cr)
02063 {
02064 error ("cannot write to SP output file", -1);
02065 }
02066 }
02067 }
02068 fclose(SP_coeff_file);
02069 }
02070
02071
02072
02073
02074
02075
02076
02077 void read_SP_coefficients(ImageParameters *p_Img, InputParameters *p_Inp)
02078 {
02079 int i,k;
02080 FILE *SP_coeff_file;
02081
02082 if ( (p_Inp->qp2start > 0) && ( ( (p_Img->frame_no ) % (2*p_Inp->qp2start) ) >=p_Inp->qp2start ))
02083 {
02084 if ((SP_coeff_file = fopen(p_Inp->sp2_input_filename1,"rb")) == NULL)
02085 {
02086 printf ("Fatal: cannot open SP input file '%s', exit (-1)\n", p_Inp->sp2_input_filename2);
02087 exit (-1);
02088 }
02089 }
02090 else
02091 {
02092 if ((SP_coeff_file = fopen(p_Inp->sp2_input_filename2,"rb")) == NULL)
02093 {
02094 printf ("Fatal: cannot open SP input file '%s', exit (-1)\n", p_Inp->sp2_input_filename1);
02095 exit (-1);
02096 }
02097 }
02098
02099 if (0 != fseek (SP_coeff_file, p_Img->size * 3/2*p_Img->number_sp2_frames*sizeof(int), SEEK_SET))
02100 {
02101 printf ("Fatal: cannot seek in SP input file, exit (-1)\n");
02102 exit (-1);
02103 }
02104 p_Img->number_sp2_frames++;
02105
02106 for(i=0;i<p_Img->height;i++)
02107 {
02108 if(p_Img->width!=(int)fread(p_Img->lrec[i],sizeof(int),p_Img->width,SP_coeff_file))
02109 {
02110 printf ("Fatal: cannot read in SP input file, exit (-1)\n");
02111 exit (-1);
02112 }
02113 }
02114
02115 for(k=0;k<2;k++)
02116 {
02117 for(i=0;i<p_Img->height_cr;i++)
02118 {
02119 if(p_Img->width_cr!=(int)fread(p_Img->lrec_uv[k][i],sizeof(int),p_Img->width_cr,SP_coeff_file))
02120 {
02121 printf ("Fatal: cannot read in SP input file, exit (-1)\n");
02122 exit (-1);
02123 }
02124 }
02125 }
02126 fclose(SP_coeff_file);
02127 }
02128
02129
02130
02131
02132
02133
02134
02135
02136 void select_plane(ImageParameters *p_Img, ColorPlane color_plane)
02137 {
02138 p_Img->pCurImg = p_Img->pImgOrg[color_plane];
02139 p_Img->enc_picture->p_curr_img = p_Img->enc_picture->p_img[color_plane];
02140 p_Img->enc_picture->p_curr_img_sub = p_Img->enc_picture->p_img_sub[color_plane];
02141 p_Img->max_imgpel_value = (short) p_Img->max_pel_value_comp[color_plane];
02142 p_Img->dc_pred_value = p_Img->dc_pred_value_comp[color_plane];
02143 }
02144
02145
02146
02147
02148
02149
02150
02151 static int is_gop_first_unit(ImageParameters *p_Img, InputParameters *p_Inp)
02152 {
02153 return ( get_idr_flag(p_Img, p_Inp) || ( p_Img->type == I_SLICE && p_Inp->EnableOpenGOP ) );
02154 }
02155
02156
02157
02158
02159
02160
02161
02162 void write_non_vcl_nalu( ImageParameters *p_Img, InputParameters *p_Inp )
02163 {
02164
02165 if (p_Inp->ResendSPS == 3 && is_gop_first_unit(p_Img, p_Inp) && p_Img->number)
02166 {
02167 p_Img->p_Stats->bit_slice = rewrite_paramsets(p_Img, p_Inp);
02168 }
02169
02170 if (p_Inp->ResendSPS == 2 && get_idr_flag(p_Img, p_Inp) && p_Img->number)
02171 {
02172 p_Img->p_Stats->bit_slice = rewrite_paramsets(p_Img, p_Inp);
02173 }
02174 if (p_Inp->ResendSPS == 1 && p_Img->type == I_SLICE && p_Img->frm_number != 0)
02175 {
02176 p_Img->p_Stats->bit_slice = rewrite_paramsets(p_Img, p_Inp);
02177 }
02178
02179 if ( p_Inp->ResendPPS && p_Img->frm_number != 0
02180 && (p_Img->type != I_SLICE || p_Inp->ResendSPS != 1)
02181 && (!(p_Inp->ResendSPS == 2 && get_idr_flag(p_Img, p_Inp)))
02182 && (!(p_Inp->ResendSPS == 3 && is_gop_first_unit(p_Img, p_Inp))) )
02183 {
02184
02185 if ( p_Inp->SendAUD )
02186 {
02187 p_Img->p_Stats->bit_ctr_parametersets_n = Write_AUD_NALU(p_Img);
02188 p_Img->p_Stats->bit_ctr_parametersets_n += write_PPS(p_Img, p_Inp, 0, 0);
02189 }
02190 else
02191 {
02192 p_Img->p_Stats->bit_ctr_parametersets_n = write_PPS(p_Img, p_Inp, 0, 0);
02193 }
02194 }
02195
02196 if ( p_Inp->SendAUD
02197 && (!(p_Inp->ResendPPS && p_Img->frm_number != 0))
02198 && (p_Img->type != I_SLICE || p_Inp->ResendSPS != 1)
02199 && (!(p_Inp->ResendSPS == 2 && get_idr_flag(p_Img, p_Inp)))
02200 && (!(p_Inp->ResendSPS == 3 && is_gop_first_unit(p_Img, p_Inp))) )
02201 {
02202 p_Img->p_Stats->bit_ctr_parametersets_n += Write_AUD_NALU(p_Img);
02203 }
02204
02205 UpdateSubseqInfo (p_Img, p_Inp, p_Img->layer);
02206 UpdateSceneInformation (p_Img->p_SEI, FALSE, 0, 0, -1);
02207
02208
02209
02210
02211
02212 if (p_Inp->ToneMappingSEIPresentFlag)
02213 {
02214 UpdateToneMapping(p_Img->p_SEI);
02215 }
02216
02217 PrepareAggregationSEIMessage(p_Img);
02218
02219 p_Img->p_Stats->bit_ctr_parametersets_n += Write_SEI_NALU(p_Img, 0);
02220
02221 p_Img->p_Stats->bit_ctr_parametersets += p_Img->p_Stats->bit_ctr_parametersets_n;
02222 }
02223
02224