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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "contributors.h"
00046
00047 #include <time.h>
00048 #include <math.h>
00049
00050 #include "global.h"
00051 #include "cconv_yuv2rgb.h"
00052 #include "configfile.h"
00053 #include "context_ini.h"
00054 #include "explicit_gop.h"
00055 #include "explicit_seq.h"
00056 #include "filehandle.h"
00057 #include "image.h"
00058 #include "input.h"
00059 #include "img_io.h"
00060 #include "slice.h"
00061 #include "intrarefresh.h"
00062 #include "leaky_bucket.h"
00063 #include "mc_prediction.h"
00064 #include "memalloc.h"
00065 #include "me_epzs_common.h"
00066 #include "me_epzs_int.h"
00067 #include "me_umhex.h"
00068 #include "me_umhexsmp.h"
00069 #include "output.h"
00070 #include "parset.h"
00071 #include "q_matrix.h"
00072 #include "q_offsets.h"
00073 #include "ratectl.h"
00074 #include "report.h"
00075 #include "rdoq.h"
00076 #include "errdo.h"
00077 #include "rdopt.h"
00078 #include "wp_mcprec.h"
00079 #include "mv_search.h"
00080 #include "img_process.h"
00081 #include "q_offsets.h"
00082
00083 static const int mb_width_cr[4] = {0,8, 8,16};
00084 static const int mb_height_cr[4]= {0,8,16,16};
00085
00086 EncoderParams *p_Enc = NULL;
00087
00088 static void SetLevelIndices(ImageParameters *p_Img);
00089 static void chroma_mc_setup(ImageParameters *p_Img);
00090
00091 static int init_global_buffers (ImageParameters *p_Img, InputParameters *p_Inp);
00092 static void free_global_buffers (ImageParameters *p_Img, InputParameters *p_Inp);
00093 static void free_img (ImageParameters *p_Img, InputParameters *p_Inp);
00094 static void free_params (InputParameters *p_Inp);
00095
00096 static void init_img (ImageParameters *p_Img, InputParameters *p_Inp);
00097 static void init_poc (ImageParameters *p_Img, InputParameters *p_Inp);
00098 static void init_encoder (ImageParameters *p_Img, InputParameters *p_Inp);
00099 static void encode_sequence(ImageParameters *p_Img, InputParameters *p_Inp);
00100
00101 void init_stats (InputParameters *p_Inp, StatParameters *p_Stats)
00102 {
00103 memset(p_Stats, 0, sizeof(StatParameters));
00104 p_Stats->NumberBFrames = p_Inp->NumberBFrames;
00105 }
00106
00107 void init_dstats (DistortionParams *p_Dist)
00108 {
00109 p_Dist->frame_ctr = 0;
00110 memset(p_Dist->metric, 0, TOTAL_DIST_TYPES * sizeof(DistMetric));
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 static void init_frame_params(ImageParameters *p_Img, InputParameters *p_Inp)
00120 {
00121 int base_mul = 0;
00122
00123 if (p_Inp->idr_period)
00124 {
00125 if (!p_Inp->adaptive_idr_period && ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period == 0 )
00126 p_Img->nal_reference_idc = NALU_PRIORITY_HIGHEST;
00127
00128 if (p_Inp->adaptive_idr_period == 1 && ( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period == 0 )
00129 p_Img->nal_reference_idc = NALU_PRIORITY_HIGHEST;
00130 else
00131 p_Img->nal_reference_idc = (p_Inp->DisposableP) ? (p_Img->frm_number + 1) & 0x01 : NALU_PRIORITY_LOW;
00132
00133 }
00134 else
00135 p_Img->nal_reference_idc = (p_Img->frm_number && p_Inp->DisposableP) ? (p_Img->frm_number + 1) & 0x01 : NALU_PRIORITY_LOW;
00136
00137
00138
00139 if (p_Inp->idr_period)
00140 {
00141 if (!p_Inp->adaptive_idr_period)
00142 base_mul = ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period;
00143 else if (p_Inp->adaptive_idr_period == 1)
00144 base_mul = (( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period == 0) ? 0 : ( p_Img->frm_number - p_Img->lastIDRnumber );
00145 }
00146 else
00147 base_mul = ( p_Img->frm_number - p_Img->lastIDRnumber );
00148
00149 if ((p_Img->frm_number - p_Img->lastIDRnumber) <= p_Inp->intra_delay)
00150 {
00151 base_mul = -base_mul;
00152 }
00153 else
00154 {
00155 base_mul -= ( base_mul ? p_Inp->intra_delay : 0);
00156 }
00157
00158 p_Img->toppoc = base_mul * (2 * p_Img->base_dist);
00159
00160 if ((p_Inp->PicInterlace==FRAME_CODING) && (p_Inp->MbInterlace==FRAME_CODING))
00161 p_Img->bottompoc = p_Img->toppoc;
00162 else
00163 p_Img->bottompoc = p_Img->toppoc + 1;
00164
00165 p_Img->framepoc = imin (p_Img->toppoc, p_Img->bottompoc);
00166
00167
00168 p_Img->delta_pic_order_cnt[0] = 0;
00169
00170 if ((p_Inp->BRefPictures == 1) && (p_Img->frm_number))
00171 {
00172 p_Img->delta_pic_order_cnt[0] = 2 * p_Inp->NumberBFrames;
00173 }
00174
00175 if (p_Inp->NumberBFrames && p_Inp->last_frame && ((p_Img->gop_number) + 1) == p_Inp->no_frm_base)
00176 {
00177 int bi = (int)((float)p_Img->base_dist / (p_Img->initial_Bframes + 1.0) + 0.499999);
00178 int new_bframes = ((p_Inp->last_frame - (p_Img->frm_number - 1) * p_Img->base_dist) / bi) - 1;
00179
00180
00181 p_Img->delta_pic_order_cnt[0]= -2*(p_Img->initial_Bframes - new_bframes);
00182 p_Img->toppoc += p_Img->delta_pic_order_cnt[0];
00183 p_Img->bottompoc += p_Img->delta_pic_order_cnt[0];
00184 p_Img->framepoc = imin (p_Img->toppoc, p_Img->bottompoc);
00185 }
00186
00187
00188 if (p_Inp->idr_period && ((!p_Inp->adaptive_idr_period && ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period == 0)
00189 || (p_Inp->adaptive_idr_period == 1 && ( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period == 0)) )
00190 {
00191 p_Img->frame_num = 0;
00192 }
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 static void alloc_img( ImageParameters **p_Img)
00204 {
00205 if ((*p_Img = (ImageParameters *) calloc(1, sizeof(ImageParameters)))==NULL)
00206 no_mem_exit("alloc_img: p_Img");
00207 if ((((*p_Img)->p_Dist) = (DistortionParams *) calloc(1, sizeof(DistortionParams)))==NULL)
00208 no_mem_exit("alloc_img: p_Dist");
00209 if ((((*p_Img)->p_Stats) = (StatParameters *) calloc(1, sizeof(StatParameters)))==NULL)
00210 no_mem_exit("alloc_img: p_Stats");
00211 if (((*p_Img)->p_Dpb = (DecodedPictureBuffer *) calloc(1, sizeof(DecodedPictureBuffer)))==NULL)
00212 no_mem_exit("alloc_img: p_Dpb");
00213 if ((((*p_Img)->p_Quant) = (QuantParameters *) calloc(1, sizeof(QuantParameters)))==NULL)
00214 no_mem_exit("alloc_img: p_Quant");
00215 if ((((*p_Img)->p_QScale) = (ScaleParameters *) calloc(1, sizeof(ScaleParameters)))==NULL)
00216 no_mem_exit("alloc_img: p_QScale");
00217 if ((((*p_Img)->p_SEI) = (SEIParameters *) calloc(1, sizeof(SEIParameters)))==NULL)
00218 no_mem_exit("alloc_img: p_SEI");
00219
00220
00221 (*p_Img)->p_dec = -1;
00222 (*p_Img)->p_log = NULL;
00223 (*p_Img)->f_annexb = NULL;
00224
00225 (*p_Img)->f_rtp = NULL;
00226 (*p_Img)->CurrentRTPTimestamp = 0;
00227 (*p_Img)->CurrentRTPSequenceNumber = 0;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 static void alloc_params( InputParameters **p_Inp )
00239 {
00240 if ((*p_Inp = (InputParameters *) calloc(1, sizeof(InputParameters)))==NULL)
00241 no_mem_exit("alloc_params: p_Inp");
00242
00243 (*p_Inp)->top_left = NULL;
00244 (*p_Inp)->bottom_right = NULL;
00245 (*p_Inp)->slice_group_id = NULL;
00246 (*p_Inp)->run_length_minus1 = NULL;
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 static void alloc_encoder( EncoderParams **p_Enc)
00259 {
00260 if ((*p_Enc = (EncoderParams *) calloc(1, sizeof(EncoderParams)))==NULL)
00261 no_mem_exit("alloc_encoder: p_Enc");
00262
00263 alloc_img(&((*p_Enc)->p_Img));
00264 alloc_params(&((*p_Enc)->p_Inp));
00265 (*p_Enc)->p_trace = NULL;
00266 (*p_Enc)->bufferSize = 0;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 static void free_encoder (EncoderParams *p_Enc)
00276 {
00277 if ( p_Enc != NULL )
00278 {
00279 free( p_Enc );
00280 }
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 int main(int argc, char **argv)
00296 {
00297
00298 alloc_encoder(&p_Enc);
00299
00300 Configure (p_Enc->p_Img, p_Enc->p_Inp, argc, argv);
00301
00302
00303 init_encoder(p_Enc->p_Img, p_Enc->p_Inp);
00304
00305
00306 encode_sequence(p_Enc->p_Img, p_Enc->p_Inp);
00307
00308
00309 free_encoder_memory(p_Enc->p_Img, p_Enc->p_Inp);
00310
00311 free_params (p_Enc->p_Inp);
00312 free_encoder(p_Enc);
00313
00314 return 0;
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 static void init_encoder(ImageParameters *p_Img, InputParameters *p_Inp)
00326 {
00327 p_Img->giRDOpt_B8OnlyFlag = FALSE;
00328
00329 p_Img->p_log = NULL;
00330
00331 p_Img->cabac_encoding = 0;
00332
00333 p_Img->frame_statistic_start = 1;
00334
00335
00336 OpenFiles(&p_Inp->input_file1);
00337
00338
00339 Init_QMatrix(p_Img, p_Inp);
00340 Init_QOffsetMatrix(p_Img, p_Inp);
00341
00342 init_poc(p_Img, p_Inp);
00343 GenerateParameterSets(p_Img, p_Inp);
00344 SetLevelIndices(p_Img);
00345
00346 init_img (p_Img, p_Inp);
00347
00348 if (p_Inp->rdopt == 3)
00349 {
00350 init_error_conceal(p_Img,p_Inp->ErrorConcealment);
00351 }
00352
00353 #ifdef _LEAKYBUCKET_
00354 p_Img->initial_Bframes = 0;
00355 p_Img->Bit_Buffer = (long *)malloc((p_Inp->no_frames + 1) * sizeof(long));
00356 p_Img->total_frame_buffer = 0;
00357 #endif
00358
00359
00360
00361 if (p_Inp->HierarchicalCoding)
00362 {
00363 init_gop_structure(p_Img, p_Inp);
00364 if (p_Inp->NumberBFrames && p_Inp->HierarchicalCoding == 3)
00365 interpret_gop_structure(p_Img, p_Inp);
00366 else
00367 create_hierarchy(p_Img, p_Inp);
00368 }
00369
00370 p_Img->p_Dpb->init_done = 0;
00371
00372 init_dpb(p_Img, p_Inp, p_Img->p_Dpb);
00373 init_out_buffer(p_Img);
00374 init_stats (p_Inp, p_Img->p_Stats);
00375 init_dstats(p_Img->p_Dist);
00376
00377 p_Img->enc_picture = NULL;
00378
00379 init_global_buffers(p_Img, p_Inp);
00380
00381 if ( p_Inp->WPMCPrecision )
00382 {
00383 wpxInitWPXPasses(p_Img, p_Inp);
00384 }
00385
00386 Init_Motion_Search_Module (p_Img, p_Inp);
00387 information_init(p_Img, p_Inp, p_Img->p_Stats);
00388
00389 if(p_Inp->DistortionYUVtoRGB)
00390 init_YUVtoRGB(p_Img, p_Inp);
00391
00392
00393 if (p_Inp->RCEnable)
00394 rc_init_sequence(p_Img, p_Inp);
00395
00396 p_Img->last_valid_reference = 0;
00397 p_Img->tot_time = 0;
00398
00399 p_Img->initial_Bframes = p_Inp->NumberBFrames;
00400
00401 PatchInputNoFrames(p_Inp);
00402
00403 p_Img->type = I_SLICE;
00404
00405 p_Img->p_Stats->bit_ctr_filler_data = 0;
00406 p_Img->p_Stats->bit_ctr_filler_data_n = 0;
00407 p_Img->p_Stats->bit_ctr_parametersets = 0;
00408 p_Img->p_Stats->bit_slice = start_sequence(p_Img, p_Inp);
00409
00410 if (p_Inp->UseRDOQuant)
00411 precalculate_unary_exp_golomb_level(p_Img);
00412
00413 if (p_Inp->ExplicitSeqCoding)
00414 OpenExplicitSeqFile(p_Img, p_Inp);
00415
00416 if ( p_Inp->ChromaMCBuffer )
00417 p_Img->OneComponentChromaPrediction4x4 = OneComponentChromaPrediction4x4_retrieve;
00418 else
00419 p_Img->OneComponentChromaPrediction4x4 = OneComponentChromaPrediction4x4_regenerate;
00420
00421 p_Img->searchRange.min_x = -p_Inp->search_range << 2;
00422 p_Img->searchRange.max_x = p_Inp->search_range << 2;
00423 p_Img->searchRange.min_y = -p_Inp->search_range << 2;
00424 p_Img->searchRange.max_y = p_Inp->search_range << 2;
00425
00426 }
00427
00428
00429
00430
00431
00432
00433
00434 static int determine_coding_level(ImageParameters *p_Img, InputParameters *p_Inp, int curr_frame)
00435 {
00436 int coding_level = 0;
00437
00438 if (curr_frame - p_Img->last_idr_number == 0)
00439 return coding_level;
00440 else
00441 coding_level = (curr_frame - p_Img->last_idr_number - 1) % (1 + p_Inp->NumberBFrames);
00442
00443 return coding_level;
00444 }
00445
00446
00447
00448
00449
00450
00451
00452 static void SetImgType(ImageParameters *p_Img, InputParameters *p_Inp, int gop_frame_num)
00453 {
00454 if (gop_frame_num == 0)
00455 {
00456 int intra_refresh = (p_Inp->intra_period == 0) ? (p_Img->gop_number == 0) : (( ( p_Img->frm_number - p_Img->lastIntraNumber) % p_Inp->intra_period ) == 0);
00457 int idr_refresh;
00458
00459 if ( p_Inp->idr_period && !p_Inp->adaptive_idr_period )
00460 idr_refresh = (( ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period ) == 0);
00461 else if ( p_Inp->idr_period && p_Inp->adaptive_idr_period == 1 )
00462 idr_refresh = (( ( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period ) == 0);
00463 else
00464 idr_refresh = (p_Img->gop_number == 0);
00465
00466 if (intra_refresh || idr_refresh)
00467 {
00468 set_slice_type( p_Img, p_Inp, I_SLICE );
00469 }
00470 else
00471 {
00472 set_slice_type(p_Img, p_Inp, (p_Inp->sp_periodicity && ((p_Img->gop_number % p_Inp->sp_periodicity) == 0))
00473 ? SP_SLICE : ((p_Inp->BRefPictures == 2) ? B_SLICE : P_SLICE) );
00474 }
00475 }
00476 else
00477 {
00478 if (p_Inp->HierarchicalCoding)
00479 set_slice_type( p_Img, p_Inp, p_Img->gop_structure[gop_frame_num - 1].slice_type);
00480 else
00481 set_slice_type( p_Img, p_Inp, ( p_Inp->PReplaceBSlice ) ? P_SLICE : B_SLICE);
00482 }
00483 }
00484
00485 static void set_poc(ImageParameters *p_Img, InputParameters *p_Inp, double frame_to_code)
00486 {
00487 p_Img->toppoc = (int) (p_Img->frame_interval * frame_to_code);
00488 if (p_Img->gop_number && (p_Img->gop_number <= p_Inp->intra_delay))
00489 {
00490 if(p_Inp->idr_period && ((!p_Inp->adaptive_idr_period && ( p_Img->frm_number - p_Img->lastIDRnumber ) % p_Inp->idr_period == 0)
00491 || (p_Inp->adaptive_idr_period == 1 && ( p_Img->frm_number - imax(p_Img->lastIntraNumber, p_Img->lastIDRnumber) ) % p_Inp->idr_period == 0)) )
00492 p_Img->toppoc = p_Img->toppoc;
00493 else
00494 {
00495 p_Img->toppoc += (-p_Img->frm_number + p_Img->lastIDRnumber) * p_Img->base_dist;
00496 p_Img->toppoc *= 2;
00497 }
00498 }
00499 else
00500 {
00501 if(p_Inp->idr_period && !p_Inp->adaptive_idr_period)
00502 p_Img->toppoc += ((( p_Img->frm_number - p_Img->lastIDRnumber - p_Inp->intra_delay) % p_Inp->idr_period ) - 1) * p_Img->base_dist;
00503 else
00504 p_Img->toppoc += (( p_Img->frm_number - p_Img->lastIDRnumber - p_Inp->intra_delay - 1 ) * p_Img->base_dist);
00505 p_Img->toppoc *= 2;
00506 }
00507 }
00508
00509
00510
00511
00512
00513
00514
00515 static void prepare_first_layer(ImageParameters *p_Img, InputParameters *p_Inp, int curr_frame_to_code)
00516 {
00517 p_Img->number ++;
00518 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
00519 p_Img->frm_number = p_Img->number;
00520
00521 p_Img->frm_no_in_file = CalculateFrameNumber(p_Img, p_Inp);
00522
00523 if (p_Inp->last_frame != 0 && (p_Inp->last_frame == p_Img->frm_no_in_file) && p_Inp->HierarchicalCoding)
00524 {
00525 int numberBFrames = p_Inp->NumberBFrames;
00526 p_Inp->HierarchicalCoding = imin( 2, p_Inp->HierarchicalCoding);
00527 p_Inp->NumberBFrames = p_Inp->no_frames - curr_frame_to_code - 1;
00528
00529 clear_gop_structure(p_Img);
00530 init_gop_structure(p_Img, p_Inp);
00531 create_hierarchy(p_Img, p_Inp);
00532
00533 p_Inp->NumberBFrames = numberBFrames;
00534 }
00535 SetImgType(p_Img, p_Inp, 0);
00536
00537 init_frame_params(p_Img, p_Inp);
00538
00539
00540 if (p_Inp->RCEnable && p_Img->type == I_SLICE)
00541 rc_init_gop_params(p_Img, p_Inp);
00542
00543
00544 p_Img->layer = (p_Img->gop_number % (p_Inp->NumFramesInELSubSeq + 1)) ? 0 : 1;
00545 }
00546
00547
00548
00549
00550
00551
00552
00553 static void prepare_second_layer(ImageParameters *p_Img, InputParameters *p_Inp, int enh_frame_to_code)
00554 {
00555 p_Img->layer = (p_Inp->NumFramesInELSubSeq == 0) ? 0 : 1;
00556 SetImgType(p_Img, p_Inp, enh_frame_to_code);
00557
00558 if ((p_Img->gop_number > 0) && (p_Inp->EnableIDRGOP == 0 || p_Img->idr_gop_number))
00559 {
00560 if (p_Inp->HierarchicalCoding)
00561 {
00562 p_Img->nal_reference_idc = p_Img->gop_structure[enh_frame_to_code - 1].reference_idc;
00563 set_poc(p_Img, p_Inp, (double)(1 + p_Img->gop_structure[enh_frame_to_code - 1].display_no));
00564
00565 if (p_Img->gop_number && (p_Img->gop_number <= p_Inp->intra_delay))
00566 {
00567 if (enh_frame_to_code == 1)
00568 p_Img->delta_pic_order_cnt[0] = p_Img->toppoc - 2*(p_Img->start_tr_gop + (p_Inp->intra_delay - p_Img->gop_number)*(p_Img->base_dist));
00569 else
00570 p_Img->delta_pic_order_cnt[0] = p_Img->toppoc - 2*(p_Img->start_tr_gop + (p_Inp->intra_delay - p_Img->gop_number)*(p_Img->base_dist)
00571 + (int) (2.0 * p_Img->frame_interval * (double) (1 + p_Img->gop_structure[enh_frame_to_code - 2].display_no)));
00572 }
00573 else
00574 {
00575 if (enh_frame_to_code == 1)
00576 p_Img->delta_pic_order_cnt[0] = p_Img->toppoc - 2*(p_Img->start_tr_gop + (p_Img->frm_number - p_Img->lastIDRnumber)*(p_Img->base_dist));
00577 else
00578 p_Img->delta_pic_order_cnt[0] = p_Img->toppoc - 2*(p_Img->start_tr_gop + (p_Img->frm_number - p_Img->lastIDRnumber - 1)*(p_Img->base_dist)
00579 + (int) (2.0 * p_Img->frame_interval * (double) (1+ p_Img->gop_structure[enh_frame_to_code - 2].display_no)));
00580 }
00581 }
00582 else
00583 {
00584 p_Img->nal_reference_idc = (p_Inp->BRefPictures == 1 ) ? NALU_PRIORITY_LOW : NALU_PRIORITY_DISPOSABLE;
00585 set_poc(p_Img, p_Inp, (double)enh_frame_to_code);
00586
00587
00588 if (p_Inp->BRefPictures != 1)
00589 {
00590 p_Img->delta_pic_order_cnt[0]= 2 * (enh_frame_to_code - 1);
00591 }
00592 else
00593 {
00594 p_Img->delta_pic_order_cnt[0]= -2;
00595 }
00596 }
00597
00598 p_Img->delta_pic_order_cnt[1]= 0;
00599
00600 if ((p_Inp->PicInterlace==FRAME_CODING)&&(p_Inp->MbInterlace==FRAME_CODING))
00601 p_Img->bottompoc = p_Img->toppoc;
00602 else
00603 p_Img->bottompoc = p_Img->toppoc + 1;
00604
00605 p_Img->framepoc = imin (p_Img->toppoc, p_Img->bottompoc);
00606 p_Img->frm_no_in_file = CalculateFrameNumber(p_Img, p_Inp);
00607 }
00608 }
00609
00610
00611
00612
00613
00614
00615
00616 static void encode_sequence(ImageParameters *p_Img, InputParameters *p_Inp)
00617 {
00618 int HierarchicalCoding = p_Inp->HierarchicalCoding;
00619 int NumberBFrames = p_Inp->NumberBFrames;
00620 int jumpd = p_Inp->jumpd;
00621 int curr_frame_to_code = 0;
00622 int enh_frame_to_code = 0;
00623
00624 for (curr_frame_to_code = 0; curr_frame_to_code < p_Inp->no_frames; curr_frame_to_code++)
00625 {
00626
00627 if (p_Img->last_ref_idc == 1)
00628 {
00629 p_Img->frame_num++;
00630 p_Img->frame_num %= p_Img->max_frame_num;
00631 }
00632
00633
00634 if (p_Inp->ExplicitSeqCoding)
00635 {
00636 ExpFrameInfo *info = &p_Img->expSeq->info[curr_frame_to_code % p_Img->expSeq->no_frames];
00637 ReadExplicitSeqFile(p_Img->expSeq, p_Img->expSFile, curr_frame_to_code);
00638 ExplicitUpdateImgParams (info, p_Img, p_Inp);
00639 p_Img->b_frame_to_code = 0;
00640 }
00641 else
00642 {
00643 enh_frame_to_code = determine_coding_level(p_Img, p_Inp, curr_frame_to_code);
00644 p_Img->b_frame_to_code = enh_frame_to_code;
00645
00646 if (enh_frame_to_code == 0)
00647 prepare_first_layer(p_Img, p_Inp, curr_frame_to_code);
00648 else
00649 {
00650 prepare_second_layer(p_Img, p_Inp, enh_frame_to_code);
00651 }
00652 }
00653
00654
00655 if (p_Inp->redundant_pic_flag)
00656 {
00657 Init_redundant_frame(p_Img, p_Inp);
00658 Set_redundant_frame(p_Img, p_Inp);
00659 }
00660
00661 encode_one_frame(p_Img, p_Inp);
00662
00663 p_Img->last_ref_idc = p_Img->nal_reference_idc ? 1 : 0;
00664
00665
00666 if (p_Inp->redundant_pic_flag && p_Img->key_frame)
00667 {
00668 encode_one_redundant_frame(p_Img, p_Inp);
00669 }
00670
00671 if (p_Img->type == I_SLICE && p_Inp->EnableOpenGOP)
00672 p_Img->last_valid_reference = p_Img->ThisPOC;
00673
00674 if (p_Img->currentPicture->idr_flag)
00675 {
00676 p_Img->idr_gop_number = 0;
00677 }
00678 else
00679 p_Img->idr_gop_number ++;
00680
00681 if (p_Inp->ReportFrameStats)
00682 report_frame_statistic(p_Img, p_Inp);
00683
00684 }
00685
00686 p_Inp->HierarchicalCoding = HierarchicalCoding;
00687 p_Inp->NumberBFrames = NumberBFrames;
00688 p_Inp->jumpd = jumpd;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 void free_encoder_memory(ImageParameters *p_Img, InputParameters *p_Inp)
00700 {
00701 terminate_sequence(p_Img, p_Inp);
00702
00703 flush_dpb(p_Img, p_Inp, &p_Inp->output);
00704
00705 CloseFiles(&p_Inp->input_file1);
00706
00707 if (-1 != p_Img->p_dec)
00708 close(p_Img->p_dec);
00709 if (p_Enc->p_trace)
00710 fclose(p_Enc->p_trace);
00711
00712 Clear_Motion_Search_Module (p_Img, p_Inp);
00713
00714 RandomIntraUninit(p_Img);
00715 FmoUninit(p_Img);
00716
00717 if (p_Inp->HierarchicalCoding)
00718 clear_gop_structure (p_Img);
00719
00720 #ifdef _LEAKYBUCKET_
00721 calc_buffer(p_Img, p_Inp);
00722 #endif
00723
00724
00725 report(p_Img, p_Inp, p_Img->p_Stats);
00726
00727 #ifdef _LEAKYBUCKET_
00728 if (p_Img->Bit_Buffer != NULL)
00729 {
00730 free(p_Img->Bit_Buffer);
00731 p_Img->Bit_Buffer = NULL;
00732 }
00733 #endif
00734
00735 free_dpb(p_Img, p_Inp, p_Img->p_Dpb);
00736
00737 uninit_out_buffer(p_Img, p_Inp);
00738
00739 free_global_buffers(p_Img, p_Inp);
00740
00741 FreeParameterSets(p_Img);
00742
00743 if (p_Inp->ExplicitSeqCoding)
00744 CloseExplicitSeqFile(p_Img);
00745
00746
00747 free_img (p_Img, p_Inp);
00748 }
00749
00750
00751
00752
00753
00754
00755
00756
00757 static void init_poc(ImageParameters *p_Img, InputParameters *p_Inp)
00758 {
00759
00760
00761
00762 p_Img->pic_order_cnt_type=p_Inp->pic_order_cnt_type;
00763
00764 p_Img->delta_pic_order_always_zero_flag = FALSE;
00765 p_Img->num_ref_frames_in_pic_order_cnt_cycle= 1;
00766
00767 if (p_Inp->BRefPictures == 1)
00768 {
00769 p_Img->offset_for_non_ref_pic = 0;
00770 p_Img->offset_for_ref_frame[0] = 2;
00771 }
00772 else
00773 {
00774 p_Img->offset_for_non_ref_pic = -2*(p_Inp->NumberBFrames);
00775 p_Img->offset_for_ref_frame[0] = 2*(p_Inp->NumberBFrames + 1);
00776 }
00777
00778 if ((p_Inp->PicInterlace==FRAME_CODING) && (p_Inp->MbInterlace==FRAME_CODING))
00779 {
00780 p_Img->offset_for_top_to_bottom_field = 0;
00781 p_Img->bottom_field_pic_order_in_frame_present_flag = FALSE;
00782 p_Img->delta_pic_order_cnt_bottom = 0;
00783 }
00784 else
00785 {
00786 p_Img->offset_for_top_to_bottom_field = 1;
00787 p_Img->bottom_field_pic_order_in_frame_present_flag = TRUE;
00788 p_Img->delta_pic_order_cnt_bottom = 1;
00789 }
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803 static void init_img( ImageParameters *p_Img, InputParameters *p_Inp)
00804 {
00805 int i, j;
00806 int imgpel_abs_range;
00807
00808 p_Img->number = -1;
00809 p_Img->start_frame_no = 0;
00810 p_Img->gop_number = (p_Img->number - p_Img->start_frame_no);
00811 p_Img->start_tr_gop = 0;
00812
00813 p_Img->last_idr_number = 0;
00814
00815 p_Img->yuv_format = p_Inp->output.yuv_format;
00816 p_Img->P444_joined = (p_Img->yuv_format == YUV444 && !IS_INDEPENDENT(p_Inp));
00817
00818
00819 p_Img->bitdepth_luma = (short) p_Inp->output.bit_depth[0];
00820 p_Img->bitdepth_scale[0] = 1 << (p_Img->bitdepth_luma - 8);
00821 p_Img->bitdepth_lambda_scale = 2 * (p_Img->bitdepth_luma - 8);
00822 p_Img->bitdepth_luma_qp_scale = 3 * p_Img->bitdepth_lambda_scale;
00823 p_Img->dc_pred_value_comp[0] = (imgpel) (1<<(p_Img->bitdepth_luma - 1));
00824 p_Img->max_pel_value_comp[0] = (1<<p_Img->bitdepth_luma) - 1;
00825 p_Img->max_imgpel_value_comp_sq[0] = p_Img->max_pel_value_comp[0] * p_Img->max_pel_value_comp[0];
00826
00827 p_Img->dc_pred_value = p_Img->dc_pred_value_comp[0];
00828 p_Img->max_imgpel_value = (short) p_Img->max_pel_value_comp[0];
00829 p_Img->mb_size[0][0] = p_Img->mb_size[0][1] = MB_BLOCK_SIZE;
00830
00831
00832 p_Img->RCMinQP = p_Inp->RCMinQP[P_SLICE];
00833 p_Img->RCMaxQP = p_Inp->RCMaxQP[P_SLICE];
00834
00835 p_Img->WalkAround = 0;
00836 p_Img->NumberOfMBs = 0;
00837
00838
00839
00840 if (p_Img->active_sps->profile_idc == BASELINE || p_Img->active_sps->profile_idc == MAIN || p_Img->active_sps->profile_idc == EXTENDED)
00841 p_Img->min_IPCM_value = 1;
00842 else
00843 p_Img->min_IPCM_value = 0;
00844
00845 if (p_Img->yuv_format != YUV400)
00846 {
00847 p_Img->bitdepth_chroma = (short) p_Inp->output.bit_depth[1];
00848 p_Img->bitdepth_scale[1] = 1 << (p_Img->bitdepth_chroma - 8);
00849 p_Img->dc_pred_value_comp[1] = (imgpel) (1<<(p_Img->bitdepth_chroma - 1));
00850 p_Img->dc_pred_value_comp[2] = p_Img->dc_pred_value_comp[1];
00851 p_Img->max_pel_value_comp[1] = (1<<p_Img->bitdepth_chroma) - 1;
00852 p_Img->max_pel_value_comp[2] = p_Img->max_pel_value_comp[1];
00853 p_Img->max_imgpel_value_comp_sq[1] = p_Img->max_pel_value_comp[1] * p_Img->max_pel_value_comp[1];
00854 p_Img->max_imgpel_value_comp_sq[2] = p_Img->max_pel_value_comp[2] * p_Img->max_pel_value_comp[2];
00855 p_Img->num_blk8x8_uv = (1<<p_Img->yuv_format)&(~(0x1));
00856 p_Img->num_cdc_coeff = p_Img->num_blk8x8_uv << 1;
00857
00858 p_Img->mb_size[1][0] = p_Img->mb_size[2][0] = p_Img->mb_cr_size_x = (p_Img->yuv_format == YUV420 || p_Img->yuv_format == YUV422) ? 8 : 16;
00859 p_Img->mb_size[1][1] = p_Img->mb_size[2][1] = p_Img->mb_cr_size_y = (p_Img->yuv_format == YUV444 || p_Img->yuv_format == YUV422) ? 16 : 8;
00860
00861 p_Img->bitdepth_chroma_qp_scale = 6*(p_Img->bitdepth_chroma - 8);
00862
00863 p_Img->chroma_qp_offset[0] = p_Img->active_pps->cb_qp_index_offset;
00864 p_Img->chroma_qp_offset[1] = p_Img->active_pps->cr_qp_index_offset;
00865 }
00866 else
00867 {
00868 p_Img->bitdepth_chroma = 0;
00869 p_Img->bitdepth_scale[1] = 0;
00870 p_Img->max_pel_value_comp[1] = 0;
00871 p_Img->max_pel_value_comp[2] = p_Img->max_pel_value_comp[1];
00872 p_Img->max_imgpel_value_comp_sq[1] = p_Img->max_pel_value_comp[1] * p_Img->max_pel_value_comp[1];
00873 p_Img->max_imgpel_value_comp_sq[2] = p_Img->max_pel_value_comp[2] * p_Img->max_pel_value_comp[2];
00874 p_Img->num_blk8x8_uv = 0;
00875 p_Img->num_cdc_coeff = 0;
00876 p_Img->mb_size[1][0] = p_Img->mb_size[2][0] = p_Img->mb_cr_size_x = 0;
00877 p_Img->mb_size[1][1] = p_Img->mb_size[2][1] = p_Img->mb_cr_size_y = 0;
00878
00879 p_Img->bitdepth_chroma_qp_scale = 0;
00880 p_Img->bitdepth_chroma_qp_scale = 0;
00881
00882 p_Img->chroma_qp_offset[0] = 0;
00883 p_Img->chroma_qp_offset[1] = 0;
00884 }
00885
00886 p_Img->max_bitCount = 128 + 256 * p_Img->bitdepth_luma + 2 * p_Img->mb_cr_size_y * p_Img->mb_cr_size_x * p_Img->bitdepth_chroma;
00887
00888
00889 p_Img->max_qp_delta = (25 + (p_Img->bitdepth_luma_qp_scale>>1));
00890 p_Img->min_qp_delta = p_Img->max_qp_delta + 1;
00891
00892 p_Img->num_ref_frames = p_Img->active_sps->num_ref_frames;
00893 p_Img->max_num_references = p_Img->active_sps->frame_mbs_only_flag ? p_Img->active_sps->num_ref_frames : 2 * p_Img->active_sps->num_ref_frames;
00894
00895 p_Img->buf_cycle = p_Inp->num_ref_frames;
00896 p_Img->base_dist = p_Inp->jumpd + 1;
00897
00898
00899 p_Img->lastIntraNumber = 0;
00900 p_Img->lastINTRA = 0;
00901 p_Img->lastIDRnumber = 0;
00902 p_Img->last_ref_idc = 0;
00903 p_Img->idr_refresh = 0;
00904 p_Img->idr_gop_number = 0;
00905 p_Img->rewind_frame = 0;
00906
00907 p_Img->DeblockCall = 0;
00908 p_Img->framerate = (float) p_Inp->output.frame_rate;
00909
00910 if (p_Inp->AdaptiveRounding)
00911 {
00912 if (p_Img->yuv_format != 0)
00913 {
00914 get_mem4Dint(&(p_Img->ARCofAdj4x4), 3, MAXMODE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00915 get_mem4Dint(&(p_Img->ARCofAdj8x8), p_Img->P444_joined ? 3 : 1, MAXMODE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00916 }
00917 else
00918 {
00919 get_mem4Dint(&(p_Img->ARCofAdj4x4), 1, MAXMODE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00920 get_mem4Dint(&(p_Img->ARCofAdj8x8), 1, MAXMODE, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
00921 }
00922 }
00923
00924 imgpel_abs_range = (imax(p_Img->max_pel_value_comp[0], p_Img->max_pel_value_comp[1]) + 1) * 2;
00925
00926 p_Img->width = (p_Inp->output.width + p_Img->auto_crop_right);
00927 p_Img->height = (p_Inp->output.height + p_Img->auto_crop_bottom);
00928 p_Img->width_blk = p_Img->width / BLOCK_SIZE;
00929 p_Img->height_blk = p_Img->height / BLOCK_SIZE;
00930 p_Img->width_padded = p_Img->width + 2 * IMG_PAD_SIZE;
00931 p_Img->height_padded = p_Img->height + 2 * IMG_PAD_SIZE;
00932
00933 if (p_Img->yuv_format != YUV400)
00934 {
00935 p_Img->width_cr = p_Img->width * mb_width_cr [p_Img->yuv_format] / 16;
00936 p_Img->height_cr= p_Img->height * mb_height_cr[p_Img->yuv_format] / 16;
00937 }
00938 else
00939 {
00940 p_Img->width_cr = 0;
00941 p_Img->height_cr= 0;
00942 }
00943
00944 p_Img->height_cr_frame = p_Img->height_cr;
00945
00946 p_Img->size = p_Img->width * p_Img->height;
00947 p_Img->size_cr = p_Img->width_cr * p_Img->height_cr;
00948
00949 p_Img->PicWidthInMbs = p_Img->width / MB_BLOCK_SIZE;
00950 p_Img->FrameHeightInMbs = p_Img->height / MB_BLOCK_SIZE;
00951 p_Img->FrameSizeInMbs = p_Img->PicWidthInMbs * p_Img->FrameHeightInMbs;
00952
00953 p_Img->PicHeightInMapUnits = ( p_Img->active_sps->frame_mbs_only_flag ? p_Img->FrameHeightInMbs : p_Img->FrameHeightInMbs >> 1 );
00954
00955 if ((p_Img->b8x8info = (Block8x8Info *) calloc(1, sizeof(Block8x8Info))) == NULL)
00956 no_mem_exit("init_img: p_Img->block8x8info");
00957
00958 if( IS_INDEPENDENT(p_Inp) )
00959 {
00960 for( i = 0; i < MAX_PLANE; i++ ){
00961 if ((p_Img->mb_data_JV[i] = (Macroblock *) calloc(p_Img->FrameSizeInMbs,sizeof(Macroblock))) == NULL)
00962 no_mem_exit("init_img: p_Img->mb_data_JV");
00963 }
00964 p_Img->mb_data = NULL;
00965 }
00966 else
00967 {
00968 if ((p_Img->mb_data = (Macroblock *) calloc(p_Img->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
00969 no_mem_exit("init_img: p_Img->mb_data");
00970 }
00971
00972 if (p_Inp->UseConstrainedIntraPred)
00973 {
00974 if ((p_Img->intra_block = (int*)calloc(p_Img->FrameSizeInMbs, sizeof(int))) == NULL)
00975 no_mem_exit("init_img: p_Img->intra_block");
00976 }
00977
00978 if (p_Inp->CtxAdptLagrangeMult == 1)
00979 {
00980 if ((p_Img->mb16x16_cost_frame = (double*)calloc(p_Img->FrameSizeInMbs, sizeof(double))) == NULL)
00981 {
00982 no_mem_exit("init p_Img->mb16x16_cost_frame");
00983 }
00984 }
00985 get_mem2D((byte***)&(p_Img->ipredmode), p_Img->height_blk, p_Img->width_blk);
00986 get_mem2D((byte***)&(p_Img->ipredmode8x8), p_Img->height_blk, p_Img->width_blk);
00987 memset(&(p_Img->ipredmode[0][0]) , -1, p_Img->height_blk * p_Img->width_blk *sizeof(char));
00988 memset(&(p_Img->ipredmode8x8[0][0]), -1, p_Img->height_blk * p_Img->width_blk *sizeof(char));
00989
00990
00991
00992 get_mem3Dint(&(p_Img->nz_coeff), p_Img->FrameSizeInMbs, 4, 4+p_Img->num_blk8x8_uv);
00993
00994 get_mem2Dolm (&(p_Img->lambda) , 10, 52 + p_Img->bitdepth_luma_qp_scale, p_Img->bitdepth_luma_qp_scale);
00995 get_mem2Dodouble (&(p_Img->lambda_md), 10, 52 + p_Img->bitdepth_luma_qp_scale, p_Img->bitdepth_luma_qp_scale);
00996 get_mem3Dodouble (&(p_Img->lambda_me), 10, 52 + p_Img->bitdepth_luma_qp_scale, 3, p_Img->bitdepth_luma_qp_scale);
00997 get_mem3Doint (&(p_Img->lambda_mf), 10, 52 + p_Img->bitdepth_luma_qp_scale, 3, p_Img->bitdepth_luma_qp_scale);
00998
00999 if (p_Inp->CtxAdptLagrangeMult == 1)
01000 {
01001 get_mem2Dodouble(&(p_Img->lambda_mf_factor), 10, 52 + p_Img->bitdepth_luma_qp_scale, p_Img->bitdepth_luma_qp_scale);
01002 }
01003
01004 p_Img->b_frame_to_code = 0;
01005 p_Img->GopLevels = (p_Inp->NumberBFrames) ? 1 : 0;
01006 p_Img->mb_y_upd = 0;
01007
01008 RandomIntraInit (p_Img, p_Img->PicWidthInMbs, p_Img->FrameHeightInMbs, p_Inp->RandomIntraMBRefresh);
01009
01010 InitSEIMessages(p_Img, p_Inp);
01011
01012 initInput(p_Img, &p_Inp->source, &p_Inp->output);
01013
01014
01015 AllocateFrameMemory(p_Img, p_Inp, &p_Inp->source);
01016
01017
01018
01019
01020 if (p_Inp->DFSendParameters)
01021 {
01022 for (j = 0; j < 2; j++)
01023 {
01024 for (i = 0; i < NUM_SLICE_TYPES; i++)
01025 {
01026 p_Inp->DFAlpha[j][i] <<= 1;
01027 p_Inp->DFBeta [j][i] <<= 1;
01028 }
01029 }
01030 }
01031 else
01032 {
01033 for (j = 0; j < 2; j++)
01034 {
01035 for (i = 0; i < NUM_SLICE_TYPES; i++)
01036 {
01037 p_Inp->DFDisableIdc[j][i] = 0;
01038 p_Inp->DFAlpha [j][i] = 0;
01039 p_Inp->DFBeta [j][i] = 0;
01040 }
01041 }
01042 }
01043
01044 p_Img->ChromaArrayType = p_Inp->separate_colour_plane_flag ? 0 : p_Inp->output.yuv_format;
01045 p_Img->colour_plane_id = 0;
01046
01047 if (p_Inp->RDPictureDecision)
01048 p_Img->frm_iter = 3;
01049 else
01050 p_Img->frm_iter = 1;
01051
01052 p_Img->frame_interval = (double) (p_Inp->frame_skip + 1);
01053
01054 p_Img->max_frame_num = 1 << (p_Img->log2_max_frame_num_minus4 + 4);
01055 p_Img->max_pic_order_cnt_lsb = 1 << (p_Img->log2_max_pic_order_cnt_lsb_minus4 + 4);
01056
01057 create_context_memory (p_Img, p_Inp);
01058 }
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 static void free_img (ImageParameters *p_Img, InputParameters *p_Inp)
01070 {
01071
01072 DeleteFrameMemory(p_Img);
01073
01074 CloseSEIMessages(p_Img, p_Inp);
01075
01076 free_context_memory (p_Img);
01077
01078 if (p_Inp->AdaptiveRounding)
01079 {
01080 free_mem4Dint(p_Img->ARCofAdj4x4);
01081 free_mem4Dint(p_Img->ARCofAdj8x8);
01082 }
01083
01084
01085 free (p_Img->p_SEI);
01086 free (p_Img->p_QScale);
01087 free (p_Img->p_Quant);
01088 free (p_Img->p_Dpb);
01089 free (p_Img->p_Stats);
01090 free (p_Img->p_Dist);
01091 free (p_Img);
01092 }
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103 static void free_params (InputParameters *p_Inp)
01104 {
01105 if ( p_Inp != NULL )
01106 {
01107 if ( p_Inp->top_left != NULL )
01108 free( p_Inp->top_left );
01109 if ( p_Inp->bottom_right != NULL )
01110 free( p_Inp->bottom_right );
01111 if ( p_Inp->slice_group_id != NULL )
01112 free( p_Inp->slice_group_id );
01113 if ( p_Inp->run_length_minus1 != NULL )
01114 free( p_Inp->run_length_minus1 );
01115 free( p_Inp );
01116 }
01117 }
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 Picture *malloc_picture()
01130 {
01131 Picture *pic;
01132 if ((pic = calloc (1, sizeof (Picture))) == NULL) no_mem_exit ("malloc_picture: Picture structure");
01133
01134 return pic;
01135 }
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145 void free_picture(Picture *pic)
01146 {
01147 if (pic != NULL)
01148 {
01149 free_slice_list(pic);
01150 free (pic);
01151 }
01152 }
01153
01154
01155
01156
01157
01158
01159
01160
01161 int init_orig_buffers(ImageParameters *p_Img, InputParameters *p_Inp, ImageData *imgData)
01162 {
01163 int memory_size = 0;
01164 int nplane;
01165
01166
01167 imgData->format = p_Inp->output;
01168 imgData->format.width = p_Img->width;
01169 imgData->format.height = p_Img->height;
01170 imgData->format.width_cr = p_Img->width_cr;
01171 imgData->format.height_cr = p_Img->height_cr;
01172 imgData->format.yuv_format = p_Img->yuv_format;
01173 imgData->format.auto_crop_bottom = p_Img->auto_crop_bottom;
01174 imgData->format.auto_crop_right = p_Img->auto_crop_right;
01175 imgData->format.auto_crop_bottom_cr = (p_Img->auto_crop_bottom * mb_height_cr [p_Img->yuv_format]) / MB_BLOCK_SIZE;
01176 imgData->format.auto_crop_right_cr = (p_Img->auto_crop_right * mb_width_cr [p_Img->yuv_format]) / MB_BLOCK_SIZE;
01177
01178 if( IS_INDEPENDENT(p_Inp) )
01179 {
01180
01181 for( nplane=0; nplane<MAX_PLANE; nplane++ )
01182 {
01183 memory_size += get_mem2Dpel(&(imgData->frm_data[nplane]), p_Img->height, p_Img->width);
01184 }
01185 }
01186 else
01187 {
01188
01189
01190 memory_size += get_mem2Dpel(&(imgData->frm_data[0]), p_Img->height, p_Img->width);
01191
01192 if (p_Img->yuv_format != YUV400)
01193 {
01194 int i, j, k;
01195 memory_size += get_mem2Dpel(&(imgData->frm_data[1]), p_Img->height_cr, p_Img->width_cr);
01196 memory_size += get_mem2Dpel(&(imgData->frm_data[2]), p_Img->height_cr, p_Img->width_cr);
01197
01198 if (sizeof(imgpel) == sizeof(unsigned char))
01199 {
01200 for (k = 1; k < 3; k++)
01201 memset(&(imgData->frm_data[k][0][0]), 128, p_Img->height_cr * p_Img->width_cr * sizeof(imgpel));
01202 }
01203 else
01204 {
01205 for (k = 1; k < 3; k++)
01206 for (j = 0; j < p_Img->height_cr; j++)
01207 for (i = 0; i < p_Img->width_cr; i++)
01208 imgData->frm_data[k][j][i] = 128;
01209 }
01210 }
01211 }
01212
01213 if (!p_Img->active_sps->frame_mbs_only_flag)
01214 {
01215
01216 memory_size += init_top_bot_planes(imgData->frm_data[0], p_Img->height, &(imgData->top_data[0]), &(imgData->bot_data[0]));
01217
01218 if (p_Img->yuv_format != YUV400)
01219 {
01220
01221 memory_size += 4*(sizeof(imgpel**));
01222
01223 memory_size += init_top_bot_planes(imgData->frm_data[1], p_Img->height_cr, &(imgData->top_data[1]), &(imgData->bot_data[1]));
01224 memory_size += init_top_bot_planes(imgData->frm_data[2], p_Img->height_cr, &(imgData->top_data[2]), &(imgData->bot_data[2]));
01225 }
01226 }
01227 return memory_size;
01228 }
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242 static int init_global_buffers(ImageParameters *p_Img, InputParameters *p_Inp)
01243 {
01244 int j, memory_size=0;
01245
01246 if ((p_Img->enc_frame_picture = (StorablePicture**)malloc(6 * sizeof(StorablePicture*))) == NULL)
01247 no_mem_exit("init_global_buffers: *p_Img->enc_frame_picture");
01248
01249 for (j = 0; j < 6; j++)
01250 p_Img->enc_frame_picture[j] = NULL;
01251
01252 if ((p_Img->enc_field_picture = (StorablePicture**)malloc(2 * sizeof(StorablePicture*))) == NULL)
01253 no_mem_exit("init_global_buffers: *p_Img->enc_field_picture");
01254
01255 for (j = 0; j < 2; j++)
01256 p_Img->enc_field_picture[j] = NULL;
01257
01258 if ((p_Img->frame_pic = (Picture**)malloc(p_Img->frm_iter * sizeof(Picture*))) == NULL)
01259 no_mem_exit("init_global_buffers: *p_Img->frame_pic");
01260
01261 for (j = 0; j < p_Img->frm_iter; j++)
01262 p_Img->frame_pic[j] = malloc_picture();
01263
01264 if (p_Inp->si_frame_indicator || p_Inp->sp_periodicity)
01265 {
01266 p_Img->si_frame_indicator = FALSE;
01267 p_Img->number_sp2_frames=0;
01268
01269 p_Img->frame_pic_si = malloc_picture();
01270
01271 get_mem2Dint (&p_Img->lrec, p_Img->height, p_Img->width);
01272 get_mem3Dint (&p_Img->lrec_uv, 2, p_Img->height, p_Img->width);
01273 }
01274
01275
01276 if (p_Inp->PicInterlace != FRAME_CODING)
01277 {
01278 if ((p_Img->field_pic = (Picture**)malloc(2 * sizeof(Picture*))) == NULL)
01279 no_mem_exit("init_global_buffers: *p_Img->field_pic");
01280
01281 for (j = 0; j < 2; j++)
01282 p_Img->field_pic[j] = malloc_picture();
01283 }
01284
01285
01286 memory_size += init_orig_buffers(p_Img, p_Inp, &p_Img->imgData);
01287 memory_size += init_orig_buffers(p_Img, p_Inp, &p_Img->imgData0);
01288
01289 memory_size += get_mem2Dshort(&PicPos, p_Img->FrameSizeInMbs + 1, 2);
01290
01291 for (j = 0; j < (int) p_Img->FrameSizeInMbs + 1; j++)
01292 {
01293 PicPos[j][0] = (short) (j % p_Img->PicWidthInMbs);
01294 PicPos[j][1] = (short) (j / p_Img->PicWidthInMbs);
01295 }
01296
01297
01298 if (p_Inp->rdopt == 3)
01299 {
01300 memory_size += allocate_errdo_mem(p_Img, p_Inp);
01301 }
01302
01303 if (p_Inp->RestrictRef)
01304 {
01305 memory_size += get_mem2D(&p_Img->pixel_map, p_Img->height, p_Img->width);
01306 memory_size += get_mem2D(&p_Img->refresh_map, p_Img->height >> 3, p_Img->width >> 3);
01307 }
01308
01309 if (!p_Img->active_sps->frame_mbs_only_flag)
01310 {
01311 memory_size += get_mem2Dpel(&p_Img->imgY_com, p_Img->height, p_Img->width);
01312
01313 if (p_Img->yuv_format != YUV400)
01314 {
01315 memory_size += get_mem3Dpel(&p_Img->imgUV_com, 2, p_Img->height_cr, p_Img->width_cr);
01316 }
01317 }
01318
01319
01320 if (!p_Inp->IntraProfile)
01321 {
01322 if (p_Inp->SearchMode == UM_HEX)
01323 {
01324 if ((p_Img->p_UMHex = (UMHexStruct*)calloc(1, sizeof(UMHexStruct))) == NULL)
01325 no_mem_exit("init_mv_block: p_Img->p_UMHex");
01326 memory_size += UMHEX_get_mem(p_Img, p_Inp);
01327 }
01328 else if (p_Inp->SearchMode == UM_HEX_SIMPLE)
01329 {
01330 if ((p_Img->p_UMHexSMP = (UMHexSMPStruct*)calloc(1, sizeof(UMHexSMPStruct))) == NULL)
01331 no_mem_exit("init_mv_block: p_Img->p_UMHexSMP");
01332
01333 smpUMHEX_init(p_Img);
01334 memory_size += smpUMHEX_get_mem(p_Img);
01335 }
01336 else if (p_Inp->SearchMode == EPZS)
01337 {
01338 memory_size += EPZSInit(p_Img);
01339 }
01340
01341 }
01342
01343 if (p_Inp->RCEnable)
01344 rc_allocate_memory(p_Img, p_Inp);
01345
01346 if (p_Inp->redundant_pic_flag)
01347 {
01348 memory_size += get_mem2Dpel(&p_Img->imgY_tmp, p_Img->height, p_Img->width);
01349 memory_size += get_mem2Dpel(&p_Img->imgUV_tmp[0], p_Img->height_cr, p_Img->width_cr);
01350 memory_size += get_mem2Dpel(&p_Img->imgUV_tmp[1], p_Img->height_cr, p_Img->width_cr);
01351 }
01352
01353 memory_size += get_mem2Dint (&p_Img->imgY_sub_tmp, p_Img->height_padded, p_Img->width_padded);
01354
01355 if ( p_Inp->ChromaMCBuffer )
01356 chroma_mc_setup(p_Img);
01357
01358 p_Img->padded_size_x = (p_Img->width + 2 * IMG_PAD_SIZE);
01359 p_Img->padded_size_x_m8x8 = (p_Img->padded_size_x - BLOCK_SIZE_8x8);
01360 p_Img->padded_size_x_m4x4 = (p_Img->padded_size_x - BLOCK_SIZE);
01361 p_Img->cr_padded_size_x = (p_Img->width_cr + 2 * p_Img->pad_size_uv_x);
01362 p_Img->cr_padded_size_x2 = (p_Img->cr_padded_size_x << 1);
01363 p_Img->cr_padded_size_x4 = (p_Img->cr_padded_size_x << 2);
01364 p_Img->cr_padded_size_x_m8 = (p_Img->cr_padded_size_x - 8);
01365
01366
01367
01368
01369 if(p_Inp->DistortionYUVtoRGB)
01370 {
01371 memory_size += create_RGB_memory(p_Img);
01372 }
01373
01374 p_Img->pWPX = NULL;
01375 if ( p_Inp->WPMCPrecision )
01376 {
01377 wpxInitWPXObject(p_Img);
01378 }
01379
01380 memory_size += InitProcessImage( p_Img, p_Inp );
01381
01382 return memory_size;
01383 }
01384
01385
01386
01387
01388
01389
01390
01391
01392 void free_orig_planes(ImageParameters *p_Img, InputParameters *p_Inp, ImageData *imgData)
01393 {
01394 if( IS_INDEPENDENT(p_Inp) )
01395 {
01396 int nplane;
01397 for( nplane=0; nplane<MAX_PLANE; nplane++ )
01398 {
01399 free_mem2Dpel(imgData->frm_data[nplane]);
01400 }
01401 }
01402 else
01403 {
01404 free_mem2Dpel(imgData->frm_data[0]);
01405
01406 if (imgData->format.yuv_format != YUV400)
01407 {
01408 free_mem2Dpel(imgData->frm_data[1]);
01409 free_mem2Dpel(imgData->frm_data[2]);
01410 }
01411 }
01412
01413 if (!p_Img->active_sps->frame_mbs_only_flag)
01414 {
01415 free_top_bot_planes(imgData->top_data[0], imgData->bot_data[0]);
01416
01417 if (imgData->format.yuv_format != YUV400)
01418 {
01419 free_top_bot_planes(imgData->top_data[1], imgData->bot_data[1]);
01420 free_top_bot_planes(imgData->top_data[2], imgData->bot_data[2]);
01421 }
01422 }
01423 }
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439 static void free_global_buffers(ImageParameters *p_Img, InputParameters *p_Inp)
01440 {
01441 int i,j;
01442
01443 if (p_Img->enc_frame_picture)
01444 free (p_Img->enc_frame_picture);
01445 if (p_Img->frame_pic)
01446 {
01447 for (j = 0; j < p_Img->frm_iter; j++)
01448 {
01449 if (p_Img->frame_pic[j])
01450 free_picture (p_Img->frame_pic[j]);
01451 }
01452 free (p_Img->frame_pic);
01453 }
01454
01455 if (p_Img->enc_field_picture)
01456 free (p_Img->enc_field_picture);
01457 if (p_Img->field_pic)
01458 {
01459 for (j = 0; j < 2; j++)
01460 {
01461 if (p_Img->field_pic[j])
01462 free_picture (p_Img->field_pic[j]);
01463 }
01464 free (p_Img->field_pic);
01465 }
01466
01467
01468 if (p_Inp->si_frame_indicator || p_Inp->sp_periodicity)
01469 {
01470 free_picture (p_Img->frame_pic_si);
01471
01472 free_mem2Dint (p_Img->lrec);
01473 free_mem3Dint (p_Img->lrec_uv);
01474 }
01475
01476 free_orig_planes(p_Img, p_Inp, &p_Img->imgData);
01477 free_orig_planes(p_Img, p_Inp, &p_Img->imgData0);
01478
01479
01480 free_mem2Dshort(PicPos);
01481
01482 free_QMatrix(p_Img->p_Quant);
01483 free_QOffsets(p_Img->p_Quant, p_Inp);
01484
01485
01486 if ( p_Inp->WPMCPrecision )
01487 {
01488 wpxFreeWPXObject(p_Img);
01489 }
01490
01491 if (p_Img->imgY_sub_tmp)
01492 {
01493 free_mem2Dint (p_Img->imgY_sub_tmp);
01494 p_Img->imgY_sub_tmp = NULL;
01495 }
01496
01497
01498
01499 free_mem2D((byte**)p_Img->ipredmode);
01500 free_mem2D((byte**)p_Img->ipredmode8x8);
01501 free(p_Img->b8x8info);
01502 if( IS_INDEPENDENT(p_Inp) )
01503 {
01504 for( i=0; i<MAX_PLANE; i++ ){
01505 free(p_Img->mb_data_JV[i]);
01506 }
01507 }
01508 else
01509 {
01510 free(p_Img->mb_data);
01511 }
01512
01513 if(p_Inp->UseConstrainedIntraPred)
01514 {
01515 free (p_Img->intra_block);
01516 }
01517
01518 if (p_Inp->CtxAdptLagrangeMult == 1)
01519 {
01520 free(p_Img->mb16x16_cost_frame);
01521 }
01522
01523 if (p_Inp->rdopt == 3)
01524 {
01525 free_errdo_mem(p_Img);
01526 }
01527
01528 if (p_Inp->RestrictRef)
01529 {
01530 free(p_Img->pixel_map[0]);
01531 free(p_Img->pixel_map);
01532 free(p_Img->refresh_map[0]);
01533 free(p_Img->refresh_map);
01534 }
01535
01536 if (!p_Img->active_sps->frame_mbs_only_flag)
01537 {
01538 free_mem2Dpel(p_Img->imgY_com);
01539
01540 if (p_Img->yuv_format != YUV400)
01541 {
01542 free_mem3Dpel(p_Img->imgUV_com);
01543 }
01544 }
01545
01546 free_mem3Dint(p_Img->nz_coeff);
01547
01548 free_mem2Dolm (p_Img->lambda, p_Img->bitdepth_luma_qp_scale);
01549 free_mem2Dodouble (p_Img->lambda_md, p_Img->bitdepth_luma_qp_scale);
01550 free_mem3Dodouble (p_Img->lambda_me, 10, 52 + p_Img->bitdepth_luma_qp_scale, p_Img->bitdepth_luma_qp_scale);
01551 free_mem3Doint (p_Img->lambda_mf, 10, 52 + p_Img->bitdepth_luma_qp_scale, p_Img->bitdepth_luma_qp_scale);
01552
01553 if (p_Inp->CtxAdptLagrangeMult == 1)
01554 {
01555 free_mem2Dodouble(p_Img->lambda_mf_factor, p_Img->bitdepth_luma_qp_scale);
01556 }
01557
01558 if (!p_Inp->IntraProfile)
01559 {
01560 if (p_Inp->SearchMode == UM_HEX)
01561 {
01562 UMHEX_free_mem(p_Img, p_Inp);
01563 }
01564 else if (p_Inp->SearchMode == UM_HEX_SIMPLE)
01565 {
01566 smpUMHEX_free_mem(p_Img);
01567 }
01568 else if (p_Inp->SearchMode == EPZS)
01569 {
01570 EPZSDelete(p_Img);
01571 }
01572 }
01573
01574 if (p_Inp->RCEnable)
01575 rc_free_memory(p_Img, p_Inp);
01576
01577 if (p_Inp->redundant_pic_flag)
01578 {
01579 free_mem2Dpel(p_Img->imgY_tmp);
01580 free_mem2Dpel(p_Img->imgUV_tmp[0]);
01581 free_mem2Dpel(p_Img->imgUV_tmp[1]);
01582 }
01583
01584
01585
01586 if(p_Inp->DistortionYUVtoRGB)
01587 {
01588 delete_RGB_memory(p_Img);
01589 }
01590
01591 ClearProcessImage( p_Img, p_Inp );
01592 }
01593
01594
01595
01596
01597
01598
01599
01600
01601 int get_mem_ACcoeff (ImageParameters *p_Img, int***** cofAC)
01602 {
01603 int num_blk8x8 = BLOCK_SIZE + p_Img->num_blk8x8_uv;
01604
01605 get_mem4Dint(cofAC, num_blk8x8, BLOCK_SIZE, 2, 65);
01606
01607 return num_blk8x8 * BLOCK_SIZE * 2 * 65 * sizeof(int);
01608 }
01609
01610
01611
01612
01613
01614
01615
01616 int get_mem_ACcoeff_new (int****** cofAC, int chroma)
01617 {
01618 get_mem5Dint(cofAC, BLOCK_SIZE, chroma, BLOCK_SIZE, 2, 65);
01619 return chroma * BLOCK_SIZE * BLOCK_SIZE * 2 * 65 * sizeof(int);
01620 }
01621
01622
01623
01624
01625
01626
01627
01628 int get_mem_DCcoeff (int**** cofDC)
01629 {
01630 get_mem3Dint(cofDC, 3, 2, 18);
01631 return 3 * 2 * 18 * sizeof(int);
01632 }
01633
01634
01635
01636
01637
01638
01639
01640
01641 void free_mem_ACcoeff (int**** cofAC)
01642 {
01643 free_mem4Dint(cofAC);
01644 }
01645
01646
01647
01648
01649
01650
01651
01652 void free_mem_ACcoeff_new (int***** cofAC)
01653 {
01654 free_mem5Dint(cofAC);
01655 }
01656
01657
01658
01659
01660
01661
01662
01663 void free_mem_DCcoeff (int*** cofDC)
01664 {
01665 free_mem3Dint(cofDC);
01666 }
01667
01668
01669
01670
01671
01672
01673
01674
01675 static void SetLevelIndices(ImageParameters *p_Img)
01676 {
01677 switch(p_Img->active_sps->level_idc)
01678 {
01679 case 9:
01680 p_Img->LevelIndex=1;
01681 break;
01682 case 10:
01683 p_Img->LevelIndex=0;
01684 break;
01685 case 11:
01686 if (!IS_FREXT_PROFILE(p_Img->active_sps->profile_idc) && (p_Img->active_sps->constrained_set3_flag == 0))
01687 p_Img->LevelIndex=2;
01688 else
01689 p_Img->LevelIndex=1;
01690 break;
01691 case 12:
01692 p_Img->LevelIndex=3;
01693 break;
01694 case 13:
01695 p_Img->LevelIndex=4;
01696 break;
01697 case 20:
01698 p_Img->LevelIndex=5;
01699 break;
01700 case 21:
01701 p_Img->LevelIndex=6;
01702 break;
01703 case 22:
01704 p_Img->LevelIndex=7;
01705 break;
01706 case 30:
01707 p_Img->LevelIndex=8;
01708 break;
01709 case 31:
01710 p_Img->LevelIndex=9;
01711 break;
01712 case 32:
01713 p_Img->LevelIndex=10;
01714 break;
01715 case 40:
01716 p_Img->LevelIndex=11;
01717 break;
01718 case 41:
01719 p_Img->LevelIndex=12;
01720 break;
01721 case 42:
01722 if (!IS_FREXT_PROFILE(p_Img->active_sps->profile_idc))
01723 p_Img->LevelIndex=13;
01724 else
01725 p_Img->LevelIndex=14;
01726 break;
01727 case 50:
01728 p_Img->LevelIndex=15;
01729 break;
01730 case 51:
01731 p_Img->LevelIndex=16;
01732 break;
01733 default:
01734 fprintf ( stderr, "Warning: unknown LevelIDC, using maximum level 5.1 \n" );
01735 p_Img->LevelIndex=16;
01736 break;
01737 }
01738 }
01739
01740
01741
01742
01743
01744
01745
01746 void Init_redundant_frame(ImageParameters *p_Img, InputParameters *p_Inp)
01747 {
01748 if (p_Inp->redundant_pic_flag)
01749 {
01750 if (p_Inp->NumberBFrames)
01751 {
01752 error("B frame not supported when redundant picture used!", 100);
01753 }
01754
01755 if (p_Inp->PicInterlace)
01756 {
01757 error("Interlace not supported when redundant picture used!", 100);
01758 }
01759
01760 if (p_Inp->num_ref_frames < p_Inp->PrimaryGOPLength)
01761 {
01762 error("NumberReferenceFrames must be no less than PrimaryGOPLength", 100);
01763 }
01764
01765 if ((1<<p_Inp->NumRedundantHierarchy) > p_Inp->PrimaryGOPLength)
01766 {
01767 error("PrimaryGOPLength must be greater than 2^NumRedundantHeirarchy", 100);
01768 }
01769
01770 if (p_Inp->Verbose != 1)
01771 {
01772 error("Redundant slices not supported when Verbose != 1", 100);
01773 }
01774 }
01775
01776 p_Img->key_frame = 0;
01777 p_Img->redundant_coding = 0;
01778 p_Img->redundant_pic_cnt = 0;
01779 p_Img->frameNuminGOP = p_Img->frm_number % p_Inp->PrimaryGOPLength;
01780 if (p_Img->frm_number == 0)
01781 {
01782 p_Img->frameNuminGOP = -1;
01783 }
01784 }
01785
01786
01787
01788
01789
01790
01791
01792 void Set_redundant_frame(ImageParameters *p_Img, InputParameters *p_Inp)
01793 {
01794 int GOPlength = p_Inp->PrimaryGOPLength;
01795
01796
01797 if (p_Img->frameNuminGOP == 0)
01798 {
01799 p_Img->redundant_coding = 0;
01800 p_Img->key_frame = 1;
01801 p_Img->redundant_ref_idx = GOPlength;
01802 }
01803
01804
01805 if (p_Inp->NumRedundantHierarchy > 0)
01806 {
01807 if (p_Img->frameNuminGOP == GOPlength >> 1)
01808 {
01809 p_Img->redundant_coding = 0;
01810 p_Img->key_frame = 1;
01811 p_Img->redundant_ref_idx = GOPlength >> 1;
01812 }
01813 }
01814
01815
01816 if (p_Inp->NumRedundantHierarchy > 1)
01817 {
01818 if (p_Img->frameNuminGOP == (GOPlength >> 2) || p_Img->frameNuminGOP == ((GOPlength*3) >> 2))
01819 {
01820 p_Img->redundant_coding = 0;
01821 p_Img->key_frame = 1;
01822 p_Img->redundant_ref_idx = GOPlength >> 2;
01823 }
01824 }
01825
01826
01827 if (p_Inp->NumRedundantHierarchy > 2)
01828 {
01829 if (p_Img->frameNuminGOP == GOPlength >> 3 || p_Img->frameNuminGOP == ((GOPlength*3) >> 3)
01830 || p_Img->frameNuminGOP == ((GOPlength*5) >> 3) || p_Img->frameNuminGOP == ((GOPlength*7) & 0x03))
01831 {
01832 p_Img->redundant_coding = 0;
01833 p_Img->key_frame = 1;
01834 p_Img->redundant_ref_idx = GOPlength >> 3;
01835 }
01836 }
01837
01838
01839 if (p_Inp->NumRedundantHierarchy > 3)
01840 {
01841 if (p_Img->frameNuminGOP == (GOPlength >> 4) || p_Img->frameNuminGOP == ((GOPlength*3) >> 4)
01842 || p_Img->frameNuminGOP == ((GOPlength*5) >> 4) || p_Img->frameNuminGOP == ((GOPlength*7) >> 4)
01843 || p_Img->frameNuminGOP == ((GOPlength*9) >> 4) || p_Img->frameNuminGOP == ((GOPlength*11) >> 4)
01844 || p_Img->frameNuminGOP == ((GOPlength*13) >> 4))
01845 {
01846 p_Img->redundant_coding = 0;
01847 p_Img->key_frame = 1;
01848 p_Img->redundant_ref_idx = GOPlength >> 4;
01849 }
01850 }
01851 }
01852
01853
01854
01855
01856
01857
01858
01859 void encode_one_redundant_frame(ImageParameters *p_Img, InputParameters *p_Inp)
01860 {
01861 p_Img->key_frame = 0;
01862 p_Img->redundant_coding = 1;
01863 p_Img->redundant_pic_cnt = 1;
01864
01865 if (!p_Img->currentPicture->idr_flag)
01866 {
01867 if (p_Img->type == I_SLICE)
01868 {
01869 set_slice_type( p_Img, p_Inp, P_SLICE );
01870 }
01871 }
01872
01873 encode_one_frame(p_Img, p_Inp);
01874 }
01875
01876
01877
01878
01879
01880
01881
01882 static void chroma_mc_setup(ImageParameters *p_Img)
01883 {
01884
01885 if ( p_Img->yuv_format == YUV420 )
01886 {
01887 p_Img->pad_size_uv_x = IMG_PAD_SIZE >> 1;
01888 p_Img->pad_size_uv_y = IMG_PAD_SIZE >> 1;
01889 p_Img->chroma_mask_mv_y = 7;
01890 p_Img->chroma_mask_mv_x = 7;
01891 p_Img->chroma_shift_x = 3;
01892 p_Img->chroma_shift_y = 3;
01893 }
01894 else if ( p_Img->yuv_format == YUV422 )
01895 {
01896 p_Img->pad_size_uv_x = IMG_PAD_SIZE >> 1;
01897 p_Img->pad_size_uv_y = IMG_PAD_SIZE;
01898 p_Img->chroma_mask_mv_y = 3;
01899 p_Img->chroma_mask_mv_x = 7;
01900 p_Img->chroma_shift_y = 2;
01901 p_Img->chroma_shift_x = 3;
01902 }
01903 else
01904 {
01905 p_Img->pad_size_uv_x = IMG_PAD_SIZE;
01906 p_Img->pad_size_uv_y = IMG_PAD_SIZE;
01907 p_Img->chroma_mask_mv_y = 3;
01908 p_Img->chroma_mask_mv_x = 3;
01909 p_Img->chroma_shift_y = 2;
01910 p_Img->chroma_shift_x = 2;
01911 }
01912 p_Img->shift_cr_y = p_Img->chroma_shift_y - 2;
01913 p_Img->shift_cr_x = p_Img->chroma_shift_x - 2;
01914 }
01915