ldecod.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*!
  2. ***********************************************************************
  3. * \mainpage
  4. * This is the H.264/AVC decoder reference software. For detailed documentation
  5. * see the comments in each file.
  6. *
  7. * The JM software web site is located at:
  8. * http://iphome.hhi.de/suehring/tml
  9. *
  10. * For bug reporting and known issues see:
  11. * https://ipbt.hhi.de
  12. *
  13. * \author
  14. * The main contributors are listed in contributors.h
  15. *
  16. * \version
  17. * JM 16.1 (FRExt)
  18. *
  19. * \note
  20. * tags are used for document system "doxygen"
  21. * available at http://www.doxygen.org
  22. */
  23. /*!
  24. * \file
  25. * ldecod.c
  26. * \brief
  27. * H.264/AVC reference decoder project main()
  28. * \author
  29. * Main contributors (see contributors.h for copyright, address and affiliation details)
  30. * - Inge Lille-Langøy <[email protected]>
  31. * - Rickard Sjoberg <[email protected]>
  32. * - Stephan Wenger <[email protected]>
  33. * - Jani Lainema <[email protected]>
  34. * - Sebastian Purreiter <[email protected]>
  35. * - Byeong-Moon Jeon <[email protected]>
  36. * - Gabi Blaettermann
  37. * - Ye-Kui Wang <[email protected]>
  38. * - Valeri George <[email protected]>
  39. * - Karsten Suehring <[email protected]>
  40. *
  41. ***********************************************************************
  42. */
  43. #include "contributors.h"
  44. #include <sys/stat.h>
  45. #include "global.h"
  46. #include "image.h"
  47. #include "memalloc.h"
  48. #include "mc_prediction.h"
  49. #include "mbuffer.h"
  50. #include "leaky_bucket.h"
  51. #include "fmo.h"
  52. #include "output.h"
  53. #include "cabac.h"
  54. #include "parset.h"
  55. #include "sei.h"
  56. #include "erc_api.h"
  57. #include "quant.h"
  58. #include "block.h"
  59. #include "nalu.h"
  60. #include "meminput.h"
  61. #define LOGFILE "log.dec"
  62. #define DATADECFILE "dataDec.txt"
  63. #define TRACEFILE "trace_dec.txt"
  64. // Decoder definition. This should be the only global variable in the entire
  65. // software. Global variables should be avoided.
  66. char errortext[ET_SIZE]; //!< buffer for error message for exit with error()
  67. #ifdef TRACE
  68. FILE *p_trace=0;
  69. int bitcounter=0;
  70. #endif
  71. // Prototypes of static functions
  72. void init (VideoParameters *p_Vid);
  73. void malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid);
  74. void free_slice (Slice *currSlice);
  75. void init_frext(VideoParameters *p_Vid);
  76. /*!
  77. ************************************************************************
  78. * \brief
  79. * Error handling procedure. Print error message to stderr and exit
  80. * with supplied code.
  81. * \param text
  82. * Error message
  83. * \param code
  84. * Exit code
  85. ************************************************************************
  86. */
  87. void error(char *text, int code)
  88. {
  89. RaiseException(code, 0, 1, (ULONG_PTR *)text);
  90. //fprintf(stderr, "%s\n", text);
  91. //flush_dpb(p_Dec->p_Vid);
  92. //exit(code);
  93. }
  94. /*static */void Configure(VideoParameters *p_Vid, InputParameters *p_Inp)
  95. {
  96. p_Vid->p_Inp = p_Inp;
  97. p_Inp->intra_profile_deblocking = 0;
  98. #ifdef _LEAKYBUCKET_
  99. p_Inp->R_decoder=500000; //! Decoder rate
  100. p_Inp->B_decoder=104000; //! Decoder buffer size
  101. p_Inp->F_decoder=73000; //! Decoder initial delay
  102. strcpy(p_Inp->LeakyBucketParamFile,"leakybucketparam.cfg"); // file where Leaky Bucket parameters (computed by encoder) are stored
  103. #endif
  104. }
  105. /*!
  106. ***********************************************************************
  107. * \brief
  108. * Allocate the Image structure
  109. * \par Output:
  110. * Image Parameters VideoParameters *p_Vid
  111. ***********************************************************************
  112. */
  113. static void alloc_img( VideoParameters **p_Vid)
  114. {
  115. if ((*p_Vid = (VideoParameters *) calloc(1, sizeof(VideoParameters)))==NULL)
  116. no_mem_exit("alloc_img: p_Vid");
  117. if (((*p_Vid)->old_slice = (OldSliceParams *) calloc(1, sizeof(OldSliceParams)))==NULL)
  118. no_mem_exit("alloc_img: p_Vid->old_slice");
  119. if (((*p_Vid)->p_Dpb = (DecodedPictureBuffer*)calloc(1, sizeof(DecodedPictureBuffer)))==NULL)
  120. no_mem_exit("alloc_img: p_Vid->p_Dpb");
  121. (*p_Vid)->p_Dpb->init_done = 0;
  122. (*p_Vid)->global_init_done = 0;
  123. #if (ENABLE_OUTPUT_TONEMAPPING)
  124. if (((*p_Vid)->seiToneMapping = (ToneMappingSEI*)calloc(1, sizeof(ToneMappingSEI)))==NULL)
  125. no_mem_exit("alloc_img: (*p_Vid)->seiToneMapping");
  126. #endif
  127. }
  128. /*!
  129. ***********************************************************************
  130. * \brief
  131. * Allocate the Input structure
  132. * \par Output:
  133. * Input Parameters InputParameters *p_Vid
  134. ***********************************************************************
  135. */
  136. static void alloc_params( InputParameters **p_Inp )
  137. {
  138. if ((*p_Inp = (InputParameters *) calloc(1, sizeof(InputParameters)))==NULL)
  139. no_mem_exit("alloc_params: p_Inp");
  140. }
  141. /*!
  142. ***********************************************************************
  143. * \brief
  144. * Allocate the Decoder Structure
  145. * \par Output:
  146. * Decoder Parameters
  147. ***********************************************************************
  148. */
  149. DecoderParams *alloc_decoder()
  150. {
  151. DecoderParams *decoder = (DecoderParams *) calloc(1, sizeof(DecoderParams));
  152. if (decoder)
  153. {
  154. alloc_img(&(decoder->p_Vid));
  155. alloc_params(&(decoder->p_Inp));
  156. #ifdef TRACE
  157. p_trace = 0;
  158. bitcounter = 0;
  159. #endif
  160. }
  161. return decoder;
  162. }
  163. /*!
  164. ***********************************************************************
  165. * \brief
  166. * Free the Image structure
  167. * \par Input:
  168. * Image Parameters VideoParameters *p_Vid
  169. ***********************************************************************
  170. */
  171. void free_img( VideoParameters *p_Vid)
  172. {
  173. if (p_Vid != NULL)
  174. {
  175. free_mem_input(p_Vid);
  176. #if (ENABLE_OUTPUT_TONEMAPPING)
  177. if (p_Vid->seiToneMapping != NULL)
  178. {
  179. free (p_Vid->seiToneMapping);
  180. p_Vid->seiToneMapping = NULL;
  181. }
  182. #endif
  183. if (p_Vid->p_Dpb != NULL)
  184. {
  185. free (p_Vid->p_Dpb);
  186. p_Vid->p_Dpb = NULL;
  187. }
  188. if (p_Vid->old_slice != NULL)
  189. {
  190. free (p_Vid->old_slice);
  191. p_Vid->old_slice = NULL;
  192. }
  193. free (p_Vid);
  194. p_Vid = NULL;
  195. }
  196. }
  197. /*!
  198. ***********************************************************************
  199. * \brief
  200. * main function for TML decoder
  201. ***********************************************************************
  202. */
  203. #if 0
  204. int main(int argc, char **argv)
  205. {
  206. DecoderParams *p_Dec = alloc_decoder();
  207. if (!p_Dec)
  208. return 1;
  209. Configure(p_Dec->p_Vid, p_Dec->p_Inp, argc, argv);
  210. initBitsFile(p_Dec->p_Vid, p_Dec->p_Inp->FileFormat);
  211. p_Dec->p_Vid->bitsfile->OpenBitsFile(p_Dec->p_Vid, p_Dec->p_Inp->infile);
  212. // Allocate Slice data struct
  213. malloc_slice(p_Dec->p_Inp, p_Dec->p_Vid);
  214. init_old_slice(p_Dec->p_Vid->old_slice);
  215. init(p_Dec->p_Vid);
  216. init_out_buffer(p_Dec->p_Vid);
  217. while (decode_one_frame(p_Dec->p_Vid) != EOS)
  218. ;
  219. free_slice(p_Dec->p_Vid->currentSlice);
  220. FmoFinit(p_Dec->p_Vid);
  221. free_global_buffers(p_Dec->p_Vid);
  222. flush_dpb(p_Dec->p_Vid);
  223. #if (PAIR_FIELDS_IN_OUTPUT)
  224. flush_pending_output(p_Dec->p_Vid, p_Dec->p_Vid->p_out);
  225. #endif
  226. p_Dec->p_Vid->bitsfile->CloseBitsFile(p_Dec->p_Vid);
  227. close(p_Dec->p_Vid->p_out);
  228. if (p_Dec->p_Vid->p_ref != -1)
  229. close(p_Dec->p_Vid->p_ref);
  230. #if TRACE
  231. fclose(p_trace);
  232. #endif
  233. ercClose(p_Dec->p_Vid, p_Dec->p_Vid->erc_errorVar);
  234. CleanUpPPS(p_Dec->p_Vid);
  235. free_dpb(p_Dec->p_Vid);
  236. uninit_out_buffer(p_Dec->p_Vid);
  237. free (p_Dec->p_Inp);
  238. free_img (p_Dec->p_Vid);
  239. free(p_Dec);
  240. return 0;
  241. }
  242. #endif
  243. /*!
  244. ***********************************************************************
  245. * \brief
  246. * Initilize some arrays
  247. ***********************************************************************
  248. */
  249. void init(VideoParameters *p_Vid) //!< image parameters
  250. {
  251. int i;
  252. InputParameters *p_Inp = p_Vid->p_Inp;
  253. p_Vid->oldFrameSizeInMbs = -1;
  254. p_Vid->recovery_point = 0;
  255. p_Vid->recovery_point_found = 0;
  256. p_Vid->recovery_poc = 0x7fffffff; /* set to a max value */
  257. p_Vid->number = 0;
  258. p_Vid->type = I_SLICE;
  259. p_Vid->dec_ref_pic_marking_buffer = NULL;
  260. p_Vid->dec_picture = NULL;
  261. // reference flag initialization
  262. for(i=0;i<17;++i)
  263. {
  264. p_Vid->ref_flag[i] = 1;
  265. }
  266. p_Vid->MbToSliceGroupMap = NULL;
  267. p_Vid->MapUnitToSliceGroupMap = NULL;
  268. p_Vid->LastAccessUnitExists = 0;
  269. p_Vid->NALUCount = 0;
  270. p_Vid->out_buffer = NULL;
  271. p_Vid->pending_output = NULL;
  272. p_Vid->pending_output_state = FRAME;
  273. p_Vid->recovery_flag = 0;
  274. #if (ENABLE_OUTPUT_TONEMAPPING)
  275. init_tone_mapping_sei(p_Vid->seiToneMapping);
  276. #endif
  277. }
  278. /*!
  279. ***********************************************************************
  280. * \brief
  281. * Initialize FREXT variables
  282. ***********************************************************************
  283. */
  284. void init_frext(VideoParameters *p_Vid) //!< image parameters
  285. {
  286. //pel bitdepth init
  287. p_Vid->bitdepth_luma_qp_scale = 6 * (p_Vid->bitdepth_luma - 8);
  288. p_Vid->dc_pred_value_comp[0] = 1<<(p_Vid->bitdepth_luma - 1);
  289. p_Vid->max_pel_value_comp[0] = (1<<p_Vid->bitdepth_luma) - 1;
  290. p_Vid->mb_size[IS_LUMA][0] = p_Vid->mb_size[IS_LUMA][1] = MB_BLOCK_SIZE;
  291. if (p_Vid->active_sps->chroma_format_idc != YUV400)
  292. {
  293. //for chrominance part
  294. p_Vid->bitdepth_chroma_qp_scale = 6 * (p_Vid->bitdepth_chroma - 8);
  295. p_Vid->dc_pred_value_comp[1] = (1 << (p_Vid->bitdepth_chroma - 1));
  296. p_Vid->dc_pred_value_comp[2] = p_Vid->dc_pred_value_comp[1];
  297. p_Vid->max_pel_value_comp[1] = (1 << p_Vid->bitdepth_chroma) - 1;
  298. p_Vid->max_pel_value_comp[2] = (1 << p_Vid->bitdepth_chroma) - 1;
  299. p_Vid->num_blk8x8_uv = (1 << p_Vid->active_sps->chroma_format_idc) & (~(0x1));
  300. p_Vid->num_uv_blocks = (p_Vid->num_blk8x8_uv >> 1);
  301. p_Vid->num_cdc_coeff = (p_Vid->num_blk8x8_uv << 1);
  302. p_Vid->mb_size[IS_CHROMA][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = (p_Vid->active_sps->chroma_format_idc==YUV420 || p_Vid->active_sps->chroma_format_idc==YUV422)? 8 : 16;
  303. p_Vid->mb_size[IS_CHROMA][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = (p_Vid->active_sps->chroma_format_idc==YUV444 || p_Vid->active_sps->chroma_format_idc==YUV422)? 16 : 8;
  304. p_Vid->subpel_x = p_Vid->mb_cr_size_x == 8 ? 7 : 3;
  305. p_Vid->subpel_y = p_Vid->mb_cr_size_y == 8 ? 7 : 3;
  306. p_Vid->shiftpel_x = p_Vid->mb_cr_size_x == 8 ? 3 : 2;
  307. p_Vid->shiftpel_y = p_Vid->mb_cr_size_y == 8 ? 3 : 2;
  308. }
  309. else
  310. {
  311. p_Vid->bitdepth_chroma_qp_scale = 0;
  312. p_Vid->max_pel_value_comp[1] = 0;
  313. p_Vid->max_pel_value_comp[2] = 0;
  314. p_Vid->num_blk8x8_uv = 0;
  315. p_Vid->num_uv_blocks = 0;
  316. p_Vid->num_cdc_coeff = 0;
  317. p_Vid->mb_size[IS_CHROMA][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = 0;
  318. p_Vid->mb_size[IS_CHROMA][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = 0;
  319. p_Vid->subpel_x = 0;
  320. p_Vid->subpel_y = 0;
  321. p_Vid->shiftpel_x = 0;
  322. p_Vid->shiftpel_y = 0;
  323. }
  324. p_Vid->mb_size_blk[0][0] = p_Vid->mb_size_blk[0][1] = p_Vid->mb_size[0][0] >> 2;
  325. p_Vid->mb_size_blk[1][0] = p_Vid->mb_size_blk[2][0] = p_Vid->mb_size[1][0] >> 2;
  326. p_Vid->mb_size_blk[1][1] = p_Vid->mb_size_blk[2][1] = p_Vid->mb_size[1][1] >> 2;
  327. p_Vid->mb_size_shift[0][0] = p_Vid->mb_size_shift[0][1] = CeilLog2_sf (p_Vid->mb_size[0][0]);
  328. p_Vid->mb_size_shift[1][0] = p_Vid->mb_size_shift[2][0] = CeilLog2_sf (p_Vid->mb_size[1][0]);
  329. p_Vid->mb_size_shift[1][1] = p_Vid->mb_size_shift[2][1] = CeilLog2_sf (p_Vid->mb_size[1][1]);
  330. }
  331. /*!
  332. ************************************************************************
  333. * \brief
  334. * Allocates a stand-alone partition structure. Structure should
  335. * be freed by FreePartition();
  336. * data structures
  337. *
  338. * \par Input:
  339. * n: number of partitions in the array
  340. * \par return
  341. * pointer to DataPartition Structure, zero-initialized
  342. ************************************************************************
  343. */
  344. DataPartition *AllocPartition(int n)
  345. {
  346. DataPartition *partArr, *dataPart;
  347. int i;
  348. partArr = (DataPartition *) calloc(n, sizeof(DataPartition));
  349. if (partArr == NULL)
  350. {
  351. snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Data Partition failed");
  352. error(errortext, 100);
  353. }
  354. for (i=0; i<n; ++i) // loop over all data partitions
  355. {
  356. dataPart = &(partArr[i]);
  357. dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
  358. if (dataPart->bitstream == NULL)
  359. {
  360. snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Bitstream failed");
  361. error(errortext, 100);
  362. }
  363. dataPart->bitstream->streamBuffer = 0;
  364. }
  365. return partArr;
  366. }
  367. /*!
  368. ************************************************************************
  369. * \brief
  370. * Frees a partition structure (array).
  371. *
  372. * \par Input:
  373. * Partition to be freed, size of partition Array (Number of Partitions)
  374. *
  375. * \par return
  376. * None
  377. *
  378. * \note
  379. * n must be the same as for the corresponding call of AllocPartition
  380. ************************************************************************
  381. */
  382. void FreePartition (DataPartition *dp, int n)
  383. {
  384. int i;
  385. assert (dp != NULL);
  386. assert (dp->bitstream != NULL);
  387. //assert (dp->bitstream->streamBuffer != NULL);
  388. for (i=0; i<n; ++i)
  389. {
  390. //free (dp[i].bitstream->streamBuffer);
  391. free (dp[i].bitstream);
  392. }
  393. free (dp);
  394. }
  395. /*!
  396. ************************************************************************
  397. * \brief
  398. * Allocates the slice structure along with its dependent
  399. * data structures
  400. *
  401. * \par Input:
  402. * Input Parameters InputParameters *p_Inp, VideoParameters *p_Vid
  403. ************************************************************************
  404. */
  405. void malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid)
  406. {
  407. int memory_size = 0;
  408. Slice *currSlice;
  409. p_Vid->currentSlice = (Slice *) _aligned_malloc(sizeof(Slice), 32);
  410. if ( (currSlice = p_Vid->currentSlice) == NULL)
  411. {
  412. error("Memory allocation for Slice datastruct failed",100);
  413. }
  414. memset(p_Vid->currentSlice, 0, sizeof(Slice));
  415. // p_Vid->currentSlice->rmpni_buffer=NULL;
  416. //! you don't know whether we do CABAC here, hence initialize CABAC anyway
  417. // if (p_Inp->symbol_mode == CABAC)
  418. // create all context models
  419. currSlice->mot_ctx = create_contexts_MotionInfo();
  420. currSlice->tex_ctx = create_contexts_TextureInfo();
  421. currSlice->max_part_nr = 3; //! assume data partitioning (worst case) for the following mallocs()
  422. currSlice->partArr = AllocPartition(currSlice->max_part_nr);
  423. currSlice->p_colocated = NULL;
  424. currSlice->coeff_ctr = -1;
  425. currSlice->pos = 0;
  426. }
  427. /*!
  428. ************************************************************************
  429. * \brief
  430. * Memory frees of the Slice structure and of its dependent
  431. * data structures
  432. *
  433. * \par Input:
  434. * Input Parameters InputParameters *p_Inp, VideoParameters *p_Vid
  435. ************************************************************************
  436. */
  437. void free_slice(Slice *currSlice)
  438. {
  439. FreePartition (currSlice->partArr, 3);
  440. if (1)
  441. {
  442. // delete all context models
  443. delete_contexts_MotionInfo(currSlice->mot_ctx);
  444. delete_contexts_TextureInfo(currSlice->tex_ctx);
  445. }
  446. _aligned_free(currSlice);
  447. currSlice = NULL;
  448. }
  449. /*!
  450. ************************************************************************
  451. * \brief
  452. * Dynamic memory allocation of frame size related global buffers
  453. * buffers are defined in global.h, allocated memory must be freed in
  454. * void free_global_buffers()
  455. *
  456. * \par Input:
  457. * Input Parameters InputParameters *p_Inp, Image Parameters VideoParameters *p_Vid
  458. *
  459. * \par Output:
  460. * Number of allocated bytes
  461. ***********************************************************************
  462. */
  463. int init_global_buffers(VideoParameters *p_Vid)
  464. {
  465. int memory_size=0;
  466. int i;
  467. if (p_Vid->global_init_done)
  468. {
  469. free_global_buffers(p_Vid);
  470. }
  471. // allocate memory in structure p_Vid
  472. if( IS_INDEPENDENT(p_Vid) )
  473. {
  474. for( i=0; i<MAX_PLANE; ++i )
  475. {
  476. if(((p_Vid->mb_data_JV[i]) = (Macroblock *) calloc(p_Vid->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
  477. no_mem_exit("init_global_buffers: p_Vid->mb_data");
  478. }
  479. p_Vid->mb_data = NULL;
  480. }
  481. else
  482. {
  483. if(((p_Vid->mb_data) = (Macroblock *) calloc(p_Vid->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
  484. no_mem_exit("init_global_buffers: p_Vid->mb_data");
  485. }
  486. if(((p_Vid->intra_block) = (int*)calloc(p_Vid->FrameSizeInMbs, sizeof(int))) == NULL)
  487. no_mem_exit("init_global_buffers: p_Vid->intra_block");
  488. p_Vid->PicPos = (h264_pic_position *)calloc(p_Vid->FrameSizeInMbs + 1, sizeof(h264_pic_position)); //! Helper array to access macroblock positions. We add 1 to also consider last MB.
  489. for (i = 0; i < (int) p_Vid->FrameSizeInMbs + 1;++i)
  490. {
  491. p_Vid->PicPos[i][0] = (i % p_Vid->PicWidthInMbs);
  492. p_Vid->PicPos[i][1] = (i / p_Vid->PicWidthInMbs);
  493. }
  494. memory_size += get_mem2D(&(p_Vid->ipredmode), 4*p_Vid->FrameHeightInMbs, 4*p_Vid->PicWidthInMbs);
  495. // CAVLC mem
  496. p_Vid->nz_coeff = (h264_nz_coefficient *)_aligned_malloc(p_Vid->FrameSizeInMbs*sizeof(h264_nz_coefficient), 32);
  497. memset(p_Vid->nz_coeff, 0, p_Vid->FrameSizeInMbs*sizeof(h264_nz_coefficient));
  498. //memory_size += get_mem4D(&(p_Vid->nz_coeff), p_Vid->FrameSizeInMbs, 3, BLOCK_SIZE, BLOCK_SIZE);
  499. memory_size += get_mem2Dint(&(p_Vid->siblock), p_Vid->FrameHeightInMbs, p_Vid->PicWidthInMbs);
  500. init_qp_process(p_Vid);
  501. p_Vid->global_init_done = 1;
  502. p_Vid->oldFrameSizeInMbs = p_Vid->FrameSizeInMbs;
  503. return (memory_size);
  504. }
  505. /*!
  506. ************************************************************************
  507. * \brief
  508. * Free allocated memory of frame size related global buffers
  509. * buffers are defined in global.h, allocated memory is allocated in
  510. * int init_global_buffers()
  511. *
  512. * \par Input:
  513. * Input Parameters InputParameters *p_Inp, Image Parameters VideoParameters *p_Vid
  514. *
  515. * \par Output:
  516. * none
  517. *
  518. ************************************************************************
  519. */
  520. void free_global_buffers(VideoParameters *p_Vid)
  521. {
  522. // CAVLC free mem
  523. _aligned_free(p_Vid->nz_coeff);
  524. free_mem2Dint(p_Vid->siblock);
  525. // free mem, allocated for structure p_Vid
  526. if (p_Vid->mb_data != NULL)
  527. free(p_Vid->mb_data);
  528. free(p_Vid->PicPos);
  529. free (p_Vid->intra_block);
  530. free_mem2D(p_Vid->ipredmode);
  531. free_qp_matrices(p_Vid);
  532. p_Vid->global_init_done = 0;
  533. }