1
0

global.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /*!
  2. ************************************************************************
  3. * \file
  4. * global.h
  5. * \brief
  6. * global definitions for H.264 decoder.
  7. * \author
  8. * Copyright (C) 1999 Telenor Satellite Services,Norway
  9. * Ericsson Radio Systems, Sweden
  10. *
  11. * Inge Lille-Langoy <[email protected]>
  12. *
  13. * Telenor Satellite Services
  14. * Keysers gt.13 tel.: +47 23 13 86 98
  15. * N-0130 Oslo,Norway fax.: +47 22 77 79 80
  16. *
  17. * Rickard Sjoberg <[email protected]>
  18. *
  19. * Ericsson Radio Systems
  20. * KI/ERA/T/VV
  21. * 164 80 Stockholm, Sweden
  22. *
  23. ************************************************************************
  24. */
  25. #ifndef _GLOBAL_H_
  26. #define _GLOBAL_H_
  27. #include <stdlib.h>
  28. #include <stdarg.h>
  29. #include <string.h>
  30. #include <assert.h>
  31. #include <time.h>
  32. #include <sys/timeb.h>
  33. #include <bfc/platform/types.h>
  34. #include "win32.h"
  35. #include "defines.h"
  36. #include "ifunctions.h"
  37. #include "parsetcommon.h"
  38. #include "types.h"
  39. #include "frame.h"
  40. #include "nalucommon.h"
  41. #include "memcache.h"
  42. #include <mmintrin.h>
  43. #ifdef H264_IPP
  44. //#include "../tools/staticlib/ipp_px.h"
  45. #include "ippdefs.h"
  46. #include "ippcore.h"
  47. #include "ipps.h"
  48. #include "ippi.h"
  49. #include "ippvc.h"
  50. #endif
  51. /* benski> not the best place for this but it works for now */
  52. #ifdef _M_IX86
  53. // must be a multiple of 16
  54. #pragma warning(disable: 4799)
  55. static inline void memzero_cache32(void *dst, unsigned long i)
  56. {
  57. __asm {
  58. pxor mm0, mm0
  59. mov edi, dst
  60. loopwrite:
  61. movq 0[edi], mm0
  62. movq 8[edi], mm0
  63. movq 16[edi], mm0
  64. movq 24[edi], mm0
  65. lea edi, [edi+32]
  66. sub i, 32
  67. jg loopwrite
  68. }
  69. }
  70. static inline void memzero_fast32(void *dst, unsigned long i)
  71. {
  72. __asm {
  73. pxor mm0, mm0
  74. mov edi, dst
  75. loopwrite:
  76. movntq 0[edi], mm0
  77. movntq 8[edi], mm0
  78. movntq 16[edi], mm0
  79. movntq 24[edi], mm0
  80. lea edi, [edi+32]
  81. sub i, 32
  82. jg loopwrite
  83. }
  84. }
  85. static inline void memzero64(void *dst)
  86. {
  87. __asm {
  88. pxor mm0, mm0
  89. mov edi, dst
  90. movq 0[edi], mm0
  91. movq 8[edi], mm0
  92. movq 16[edi], mm0
  93. movq 24[edi], mm0
  94. movq 32[edi], mm0
  95. movq 40[edi], mm0
  96. movq 48[edi], mm0
  97. movq 56[edi], mm0
  98. }
  99. }
  100. static inline void memzero128(void *dst)
  101. {
  102. __asm {
  103. pxor mm0, mm0
  104. mov edi, dst
  105. movq 0[edi], mm0
  106. movq 8[edi], mm0
  107. movq 16[edi], mm0
  108. movq 24[edi], mm0
  109. movq 32[edi], mm0
  110. movq 40[edi], mm0
  111. movq 48[edi], mm0
  112. movq 56[edi], mm0
  113. movq 64[edi], mm0
  114. movq 72[edi], mm0
  115. movq 80[edi], mm0
  116. movq 88[edi], mm0
  117. movq 96[edi], mm0
  118. movq 104[edi], mm0
  119. movq 112[edi], mm0
  120. movq 120[edi], mm0
  121. }
  122. }
  123. static inline void memzero24(void *dst)
  124. {
  125. __asm {
  126. pxor mm0, mm0
  127. mov edi, dst
  128. movq 0[edi], mm0
  129. movq 8[edi], mm0
  130. movq 16[edi], mm0
  131. }
  132. }
  133. static inline void memzero48(void *dst)
  134. {
  135. __asm {
  136. pxor mm0, mm0
  137. mov edi, dst
  138. movq 0[edi], mm0
  139. movq 8[edi], mm0
  140. movq 16[edi], mm0
  141. movq 24[edi], mm0
  142. movq 32[edi], mm0
  143. movq 40[edi], mm0
  144. }
  145. }
  146. static inline void memzero16(void *dst)
  147. {
  148. __asm {
  149. pxor mm0, mm0
  150. mov edi, dst
  151. movq 0[edi], mm0
  152. movq 8[edi], mm0
  153. }
  154. }
  155. static inline void memzero8(void *dst)
  156. {
  157. __asm {
  158. pxor mm0, mm0
  159. mov edi, dst
  160. movq 0[edi], mm0
  161. }
  162. }
  163. static inline void memset_fast_end()
  164. {
  165. _mm_empty();
  166. }
  167. // Very optimized memcpy() routine for all AMD Athlon and Duron family.
  168. // This code uses any of FOUR different basic copy methods, depending
  169. // on the transfer size.
  170. // NOTE: Since this code uses MOVNTQ (also known as "Non-Temporal MOV" or
  171. // "Streaming Store"), and also uses the software prefetchnta instructions,
  172. // be sure youre running on Athlon/Duron or other recent CPU before calling!
  173. #define TINY_BLOCK_COPY 64 // upper limit for movsd type copy
  174. // The smallest copy uses the X86 "movsd" instruction, in an optimized
  175. // form which is an "unrolled loop".
  176. #define IN_CACHE_COPY 64 * 1024 // upper limit for movq/movq copy w/SW prefetch
  177. // Next is a copy that uses the MMX registers to copy 8 bytes at a time,
  178. // also using the "unrolled loop" optimization. This code uses
  179. // the software prefetch instruction to get the data into the cache.
  180. #define UNCACHED_COPY 197 * 1024 // upper limit for movq/movntq w/SW prefetch
  181. // For larger blocks, which will spill beyond the cache, its faster to
  182. // use the Streaming Store instruction MOVNTQ. This write instruction
  183. // bypasses the cache and writes straight to main memory. This code also
  184. // uses the software prefetch instruction to pre-read the data.
  185. // USE 64 * 1024 FOR THIS VALUE IF YOURE ALWAYS FILLING A "CLEAN CACHE"
  186. #define BLOCK_PREFETCH_COPY infinity // no limit for movq/movntq w/block prefetch
  187. #define CACHEBLOCK 80h // number of 64-byte blocks (cache lines) for block prefetch
  188. // For the largest size blocks, a special technique called Block Prefetch
  189. // can be used to accelerate the read operations. Block Prefetch reads
  190. // one address per cache line, for a series of cache lines, in a short loop.
  191. // This is faster than using software prefetch. The technique is great for
  192. // getting maximum read bandwidth, especially in DDR memory systems.
  193. // Inline assembly syntax for use with Visual C++
  194. static void * memcpy_amd(void *dest, const void *src, size_t n)
  195. {
  196. __asm {
  197. mov ecx, [n] // number of bytes to copy
  198. mov edi, [dest] // destination
  199. mov esi, [src] // source
  200. mov ebx, ecx // keep a copy of count
  201. cld
  202. cmp ecx, TINY_BLOCK_COPY
  203. jb $memcpy_ic_3 // tiny? skip mmx copy
  204. cmp ecx, 32*1024 // dont align between 32k-64k because
  205. jbe $memcpy_do_align // it appears to be slower
  206. cmp ecx, 64*1024
  207. jbe $memcpy_align_done
  208. $memcpy_do_align:
  209. mov ecx, 8 // a trick thats faster than rep movsb...
  210. sub ecx, edi // align destination to qword
  211. and ecx, 111b // get the low bits
  212. sub ebx, ecx // update copy count
  213. neg ecx // set up to jump into the array
  214. add ecx, offset $memcpy_align_done
  215. jmp ecx // jump to array of movsbs
  216. align 4
  217. movsb
  218. movsb
  219. movsb
  220. movsb
  221. movsb
  222. movsb
  223. movsb
  224. movsb
  225. $memcpy_align_done: // destination is dword aligned
  226. mov ecx, ebx // number of bytes left to copy
  227. shr ecx, 6 // get 64-byte block count
  228. jz $memcpy_ic_2 // finish the last few bytes
  229. cmp ecx, IN_CACHE_COPY/64 // too big 4 cache? use uncached copy
  230. jae $memcpy_uc_test
  231. // This is small block copy that uses the MMX registers to copy 8 bytes
  232. // at a time. It uses the "unrolled loop" optimization, and also uses
  233. // the software prefetch instruction to get the data into the cache.
  234. align 16
  235. $memcpy_ic_1: // 64-byte block copies, in-cache copy
  236. prefetchnta [esi + (200*64/34+192)] // start reading ahead
  237. movq mm0, [esi+0] // read 64 bits
  238. movq mm1, [esi+8]
  239. movq [edi+0], mm0 // write 64 bits
  240. movq [edi+8], mm1 // note: the normal movq writes the
  241. movq mm2, [esi+16] // data to cache// a cache line will be
  242. movq mm3, [esi+24] // allocated as needed, to store the data
  243. movq [edi+16], mm2
  244. movq [edi+24], mm3
  245. movq mm0, [esi+32]
  246. movq mm1, [esi+40]
  247. movq [edi+32], mm0
  248. movq [edi+40], mm1
  249. movq mm2, [esi+48]
  250. movq mm3, [esi+56]
  251. movq [edi+48], mm2
  252. movq [edi+56], mm3
  253. add esi, 64 // update source pointer
  254. add edi, 64 // update destination pointer
  255. dec ecx // count down
  256. jnz $memcpy_ic_1 // last 64-byte block?
  257. $memcpy_ic_2:
  258. mov ecx, ebx // has valid low 6 bits of the byte count
  259. $memcpy_ic_3:
  260. shr ecx, 2 // dword count
  261. and ecx, 1111b // only look at the "remainder" bits
  262. neg ecx // set up to jump into the array
  263. add ecx, offset $memcpy_last_few
  264. jmp ecx // jump to array of movsds
  265. $memcpy_uc_test:
  266. cmp ecx, UNCACHED_COPY/64 // big enough? use block prefetch copy
  267. jae $memcpy_bp_1
  268. $memcpy_64_test:
  269. or ecx, ecx // _tail end of block prefetch will jump here
  270. jz $memcpy_ic_2 // no more 64-byte blocks left
  271. // For larger blocks, which will spill beyond the cache, its faster to
  272. // use the Streaming Store instruction MOVNTQ. This write instruction
  273. // bypasses the cache and writes straight to main memory. This code also
  274. // uses the software prefetch instruction to pre-read the data.
  275. align 16
  276. $memcpy_uc_1: // 64-byte blocks, uncached copy
  277. prefetchnta [esi + (200*64/34+192)] // start reading ahead
  278. movq mm0,[esi+0] // read 64 bits
  279. add edi,64 // update destination pointer
  280. movq mm1,[esi+8]
  281. add esi,64 // update source pointer
  282. movq mm2,[esi-48]
  283. movntq [edi-64], mm0 // write 64 bits, bypassing the cache
  284. movq mm0,[esi-40] // note: movntq also prevents the CPU
  285. movntq [edi-56], mm1 // from READING the destination address
  286. movq mm1,[esi-32] // into the cache, only to be over-written
  287. movntq [edi-48], mm2 // so that also helps performance
  288. movq mm2,[esi-24]
  289. movntq [edi-40], mm0
  290. movq mm0,[esi-16]
  291. movntq [edi-32], mm1
  292. movq mm1,[esi-8]
  293. movntq [edi-24], mm2
  294. movntq [edi-16], mm0
  295. dec ecx
  296. movntq [edi-8], mm1
  297. jnz $memcpy_uc_1 // last 64-byte block?
  298. jmp $memcpy_ic_2 // almost done
  299. // For the largest size blocks, a special technique called Block Prefetch
  300. // can be used to accelerate the read operations. Block Prefetch reads
  301. // one address per cache line, for a series of cache lines, in a short loop.
  302. // This is faster than using software prefetch, in this case.
  303. // The technique is great for getting maximum read bandwidth,
  304. // especially in DDR memory systems.
  305. $memcpy_bp_1: // large blocks, block prefetch copy
  306. cmp ecx, CACHEBLOCK // big enough to run another prefetch loop?
  307. jl $memcpy_64_test // no, back to regular uncached copy
  308. mov eax, CACHEBLOCK / 2 // block prefetch loop, unrolled 2X
  309. add esi, CACHEBLOCK * 64 // move to the top of the block
  310. align 16
  311. $memcpy_bp_2:
  312. mov edx, [esi-64] // grab one address per cache line
  313. mov edx, [esi-128] // grab one address per cache line
  314. sub esi, 128 // go reverse order
  315. dec eax // count down the cache lines
  316. jnz $memcpy_bp_2 // keep grabbing more lines into cache
  317. mov eax, CACHEBLOCK // now that its in cache, do the copy
  318. align 16
  319. $memcpy_bp_3:
  320. movq mm0, [esi ] // read 64 bits
  321. movq mm1, [esi+ 8]
  322. movq mm2, [esi+16]
  323. movq mm3, [esi+24]
  324. movq mm4, [esi+32]
  325. movq mm5, [esi+40]
  326. movq mm6, [esi+48]
  327. movq mm7, [esi+56]
  328. add esi, 64 // update source pointer
  329. movntq [edi ], mm0 // write 64 bits, bypassing cache
  330. movntq [edi+ 8], mm1 // note: movntq also prevents the CPU
  331. movntq [edi+16], mm2 // from READING the destination address
  332. movntq [edi+24], mm3 // into the cache, only to be over-written,
  333. movntq [edi+32], mm4 // so that also helps performance
  334. movntq [edi+40], mm5
  335. movntq [edi+48], mm6
  336. movntq [edi+56], mm7
  337. add edi, 64 // update dest pointer
  338. dec eax // count down
  339. jnz $memcpy_bp_3 // keep copying
  340. sub ecx, CACHEBLOCK // update the 64-byte block count
  341. jmp $memcpy_bp_1 // keep processing chunks
  342. // The smallest copy uses the X86 "movsd" instruction, in an optimized
  343. // form which is an "unrolled loop". Then it handles the last few bytes.
  344. align 4
  345. movsd
  346. movsd // perform last 1-15 dword copies
  347. movsd
  348. movsd
  349. movsd
  350. movsd
  351. movsd
  352. movsd
  353. movsd
  354. movsd // perform last 1-7 dword copies
  355. movsd
  356. movsd
  357. movsd
  358. movsd
  359. movsd
  360. movsd
  361. $memcpy_last_few: // dword aligned from before movsds
  362. mov ecx, ebx // has valid low 2 bits of the byte count
  363. and ecx, 11b // the last few cows must come home
  364. jz $memcpy_final // no more, lets leave
  365. rep movsb // the last 1, 2, or 3 bytes
  366. $memcpy_final:
  367. // emms // clean up the MMX state
  368. sfence // flush the write buffer
  369. mov eax, [dest] // ret value = destination pointer
  370. }
  371. }
  372. #elif defined(_M_X64)
  373. static inline void memzero24(void *dst)
  374. {
  375. int32_t j;
  376. int32_t *d = (int32_t *)dst;
  377. for (j=0;j<24;j+=4)
  378. {
  379. d[j] = 0;
  380. }
  381. }
  382. static inline void memset_fast_end() {}
  383. #else
  384. static inline void memzero_fast16(void *dst, unsigned long i)
  385. {
  386. int32_t j;
  387. int32_t *d = (int32_t *)dst;
  388. for (j=0;j<i;j+=4)
  389. {
  390. d[j] = 0;
  391. }
  392. }
  393. static inline void memzero24(void *dst)
  394. {
  395. int32_t j;
  396. int32_t *d = (int32_t *)dst;
  397. for (j=0;j<24;j+=4)
  398. {
  399. d[j] = 0;
  400. }
  401. }
  402. static inline void memset_fast_end() {}
  403. #endif
  404. #define UNDEFINED_REFERENCE ((int)0x80000000)
  405. typedef int32_t h264_ref_t;
  406. #define ET_SIZE 300 //!< size of error text buffer
  407. extern char errortext[ET_SIZE]; //!< buffer for error message for exit with error()
  408. extern int sse2_flag, mmx_flag, sse_flag, sse3_flag, sse4_1_flag;
  409. /***********************************************************************
  410. * T y p e d e f i n i t i o n s f o r J M
  411. ***********************************************************************
  412. */
  413. typedef enum
  414. {
  415. LumaComp = 0,
  416. CrComp = 1,
  417. CbComp = 2
  418. } Color_Component;
  419. /***********************************************************************
  420. * D a t a t y p e s f o r C A B A C
  421. ***********************************************************************
  422. */
  423. typedef struct pix_pos
  424. {
  425. int available;
  426. int mb_addr;
  427. short x;
  428. short y;
  429. short pos_x;
  430. short pos_y;
  431. } PixelPos;
  432. //! struct to characterize the state of the arithmetic coding engine
  433. typedef struct
  434. {
  435. unsigned int Drange;
  436. unsigned int Dvalue;
  437. int DbitsLeft;
  438. byte *Dcodestrm;
  439. int *Dcodestrm_len;
  440. } DecodingEnvironment;
  441. typedef DecodingEnvironment *DecodingEnvironmentPtr;
  442. typedef short MotionVector[2];
  443. //! definition of motion parameters
  444. typedef struct pic_motion
  445. {
  446. h264_ref_t ref_pic_id;
  447. h264_ref_t ref_id;
  448. MotionVector mv;
  449. char ref_idx;
  450. } PicMotion;
  451. // TODO: benski> might be more efficient to make a [list][subblock_y][subblock_x] array of these values instead of parallel arrays
  452. typedef struct motion_params
  453. {
  454. PicMotion **motion[2];
  455. byte ** moving_block;
  456. } MotionParams;
  457. //! struct for context management
  458. typedef struct
  459. {
  460. uint16_t state; // index into state-table CP
  461. unsigned char MPS; // Least Probable Symbol 0/1 CP
  462. unsigned char dummy; // for alignment
  463. } BiContextType;
  464. typedef BiContextType *BiContextTypePtr;
  465. /**********************************************************************
  466. * C O N T E X T S F O R T M L S Y N T A X E L E M E N T S
  467. **********************************************************************
  468. */
  469. #define NUM_MB_TYPE_CTX 11
  470. #define NUM_B8_TYPE_CTX 9
  471. #define NUM_MV_RES_CTX 10
  472. #define NUM_REF_NO_CTX 6
  473. #define NUM_DELTA_QP_CTX 4
  474. #define NUM_MB_AFF_CTX 4
  475. #define NUM_TRANSFORM_SIZE_CTX 3
  476. // structures that will be declared somewhere else
  477. struct storable_picture;
  478. struct datapartition;
  479. struct syntaxelement;
  480. typedef struct
  481. {
  482. BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX];
  483. BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
  484. BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
  485. BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
  486. BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX];
  487. BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
  488. } MotionInfoContexts;
  489. #define NUM_IPR_CTX 2
  490. #define NUM_CIPR_CTX 4
  491. #define NUM_CBP_CTX 4
  492. #define NUM_BCBP_CTX 4
  493. #define NUM_MAP_CTX 15
  494. #define NUM_LAST_CTX 15
  495. #define NUM_ONE_CTX 5
  496. #define NUM_ABS_CTX 5
  497. typedef struct
  498. {
  499. BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
  500. BiContextType ipr_contexts [NUM_IPR_CTX];
  501. BiContextType cipr_contexts[NUM_CIPR_CTX];
  502. BiContextType cbp_contexts [3][NUM_CBP_CTX];
  503. BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
  504. BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX+1]; // +1 for better alignment
  505. BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX+1]; // +1 for better alignment
  506. BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
  507. BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
  508. } TextureInfoContexts;
  509. //*********************** end of data type definition for CABAC *******************
  510. /***********************************************************************
  511. * N e w D a t a t y p e s f o r T M L
  512. ***********************************************************************
  513. */
  514. /*! Buffer structure for decoded reference picture marking commands */
  515. typedef struct DecRefPicMarking_s
  516. {
  517. int memory_management_control_operation;
  518. int difference_of_pic_nums_minus1;
  519. int long_term_pic_num;
  520. int long_term_frame_idx;
  521. int max_long_term_frame_idx_plus1;
  522. struct DecRefPicMarking_s *Next;
  523. } DecRefPicMarking_t;
  524. //! definition of pic motion parameters
  525. typedef struct pic_motion_params2
  526. {
  527. h264_ref_t ref_pic_id; //!< reference picture identifier [list][subblock_y][subblock_x]
  528. h264_ref_t ref_id; //!< reference picture identifier [list][subblock_y][subblock_x]
  529. short mv[2]; //!< motion vector [list][subblock_x][subblock_y][component]
  530. char ref_idx; //!< reference picture [list][subblock_y][subblock_x]
  531. byte mb_field; //!< field macroblock indicator
  532. byte field_frame; //!< indicates if co_located is field or frame.
  533. } PicMotionParams2;
  534. //! Macroblock
  535. typedef struct macroblock
  536. {
  537. struct slice *p_Slice; //!< pointer to the current slice
  538. struct img_par *p_Vid; //!< pointer to VideoParameters
  539. struct inp_par *p_Inp;
  540. int mbAddrX; //!< current MB address
  541. int mb_x;
  542. int mb_y;
  543. int block_x;
  544. int block_y;
  545. int block_y_aff;
  546. int pix_x;
  547. int pix_y;
  548. int pix_c_x;
  549. int pix_c_y;
  550. int subblock_x;
  551. int subblock_y;
  552. int qp; //!< QP luma
  553. int qpc[2]; //!< QP chroma
  554. int qp_scaled[MAX_PLANE]; //!< QP scaled for all comps.
  555. Boolean is_lossless;
  556. Boolean is_intra_block;
  557. Boolean is_v_block;
  558. short slice_nr;
  559. short delta_quant; //!< for rate control
  560. struct macroblock *mb_up; //!< pointer to neighboring MB (CABAC)
  561. struct macroblock *mb_left; //!< pointer to neighboring MB (CABAC)
  562. // some storage of macroblock syntax elements for global access
  563. int mb_type;
  564. short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2]; //!< indices correspond to [forw,backw][block_y][block_x][x,y]
  565. int cbp;
  566. int64 cbp_blk [3];
  567. int64 cbp_bits [3];
  568. int64 cbp_bits_8x8[3];
  569. int i16mode;
  570. char b8mode[4];
  571. char b8pdir[4];
  572. char ei_flag; //!< error indicator flag that enables concealment
  573. char dpl_flag; //!< error indicator flag that signals a missing data partition
  574. char ipmode_DPCM;
  575. short DFDisableIdc;
  576. short DFAlphaC0Offset;
  577. short DFBetaOffset;
  578. char c_ipred_mode; //!< chroma intra prediction mode
  579. Boolean mb_field;
  580. int skip_flag;
  581. int mb_addr_left, mb_addr_up, mb_addr_upper_right, mb_addr_upper_left;
  582. Boolean mb_avail_left, mb_avail_up, mb_avail_upper_right, mb_avail_upper_left;
  583. Boolean luma_transform_size_8x8_flag;
  584. Boolean NoMbPartLessThan8x8Flag;
  585. void (*itrans_8x8)(struct macroblock *currMB, ColorPlane pl, int ioff, int joff);
  586. void (*GetMVPredictor) (struct macroblock *currMB, PixelPos *block,
  587. short pmv[2], short ref_frame, struct pic_motion **motion, int mb_x, int mb_y, int blockshape_x, int blockshape_y);
  588. int (*read_and_store_CBP_block_bit) (struct macroblock *currMB, DecodingEnvironmentPtr dep_dp, int type);
  589. char (*readRefPictureIdx) (struct syntaxelement *currSE, struct datapartition *dP, int list);
  590. } Macroblock;
  591. //! Syntaxelement
  592. typedef struct syntaxelement
  593. {
  594. int value1; //!< numerical value of syntax element
  595. int value2; //!< for blocked symbols, e.g. run/level
  596. int len; //!< length of code
  597. //int inf; //!< info part of CAVLC code
  598. #if TRACE
  599. #define TRACESTRING_SIZE 100 //!< size of trace string
  600. char tracestring[TRACESTRING_SIZE]; //!< trace string
  601. #endif
  602. //! for mapping of CAVLC to syntaxElement
  603. void (*mapping)(int len, int info, int *value1, int *value2);
  604. } SyntaxElement;
  605. //! Bitstream
  606. typedef struct
  607. {
  608. // CABAC Decoding
  609. int read_len; //!< actual position in the codebuffer, CABAC only
  610. int code_len; //!< overall codebuffer length, CABAC only
  611. // CAVLC Decoding
  612. int frame_bitoffset; //!< actual position in the codebuffer, bit-oriented, CAVLC only
  613. int bitstream_length; //!< over codebuffer lnegth, byte oriented, CAVLC only
  614. byte *streamBuffer; //!< actual codebuffer for read bytes
  615. } Bitstream;
  616. /* === 4x4 block typedefs === */
  617. // 32 bit precision
  618. typedef int h264_int_block_row_t[BLOCK_SIZE];
  619. typedef h264_int_block_row_t h264_int_block_t[BLOCK_SIZE];
  620. // 16 bit precision
  621. typedef int16_t h264_short_block_row_t[BLOCK_SIZE];
  622. typedef h264_short_block_row_t h264_short_block_t[BLOCK_SIZE];
  623. // 8 bit precision
  624. /* === 8x8 block typedefs === */
  625. // 32 bit precision
  626. typedef int h264_int_8x8block_row_t[BLOCK_SIZE_8x8];
  627. typedef h264_int_8x8block_row_t h264_int_8x8block_t[BLOCK_SIZE_8x8];
  628. // 16 bit precision
  629. typedef int16_t h264_short_8x8block_row_t[BLOCK_SIZE_8x8];
  630. typedef h264_short_8x8block_row_t h264_short_8x8block_t[BLOCK_SIZE_8x8];
  631. // 8 bit precision
  632. typedef imgpel h264_imgpel_8x8block_row_t[BLOCK_SIZE_8x8];
  633. typedef h264_imgpel_8x8block_row_t h264_imgpel_8x8block_t[BLOCK_SIZE_8x8];
  634. /* === 16x16 block typedefs === */
  635. // 32 bit precision
  636. typedef int h264_int_macroblock_row_t[MB_BLOCK_SIZE];
  637. typedef h264_int_macroblock_row_t h264_int_macroblock_t[MB_BLOCK_SIZE];
  638. // 16 bit precision
  639. typedef int16_t h264_short_macroblock_row_t[MB_BLOCK_SIZE];
  640. typedef h264_short_macroblock_row_t h264_short_macroblock_t[MB_BLOCK_SIZE];
  641. // 8 bit precision
  642. typedef imgpel h264_imgpel_macroblock_row_t[MB_BLOCK_SIZE];
  643. typedef h264_imgpel_macroblock_row_t h264_imgpel_macroblock_t[MB_BLOCK_SIZE];
  644. typedef int h264_pic_position[2];
  645. typedef byte h264_4x4_byte[BLOCK_SIZE][BLOCK_SIZE];
  646. typedef h264_4x4_byte h264_nz_coefficient[3];
  647. //! DataPartition
  648. typedef struct datapartition
  649. {
  650. Bitstream *bitstream;
  651. DecodingEnvironment de_cabac;
  652. } DataPartition;
  653. //! Slice
  654. typedef struct slice
  655. {
  656. struct img_par *p_Vid;
  657. struct inp_par *p_Inp;
  658. pic_parameter_set_rbsp_t *active_pps;
  659. seq_parameter_set_rbsp_t *active_sps;
  660. struct colocated_params *p_colocated;
  661. struct colocated_params *Co_located_JV[MAX_PLANE]; //!< p_colocated to be used during 4:4:4 independent mode decoding
  662. int mb_aff_frame_flag;
  663. int direct_spatial_mv_pred_flag; //!< Indicator for direct mode type (1 for Spatial, 0 for Temporal)
  664. int num_ref_idx_l0_active; //!< number of available list 0 references
  665. int num_ref_idx_l1_active; //!< number of available list 1 references
  666. int qp;
  667. int slice_qp_delta;
  668. int qs;
  669. int slice_qs_delta;
  670. int slice_type; //!< slice type
  671. int model_number; //!< cabac model number
  672. PictureStructure structure; //!< Identify picture structure type
  673. int start_mb_nr; //!< MUST be set by NAL even in case of ei_flag == 1
  674. int max_part_nr;
  675. int dp_mode; //!< data partitioning mode
  676. int last_dquant;
  677. // int last_mb_nr; //!< only valid when entropy coding == CABAC
  678. DataPartition *partArr; //!< array of partitions
  679. MotionInfoContexts *mot_ctx; //!< pointer to struct of context models for use in CABAC
  680. TextureInfoContexts *tex_ctx; //!< pointer to struct of context models for use in CABAC
  681. int mvscale[6][MAX_REFERENCE_PICTURES];
  682. int ref_pic_list_reordering_flag_l0;
  683. int *reordering_of_pic_nums_idc_l0;
  684. int *abs_diff_pic_num_minus1_l0;
  685. int *long_term_pic_idx_l0;
  686. int ref_pic_list_reordering_flag_l1;
  687. int *reordering_of_pic_nums_idc_l1;
  688. int *abs_diff_pic_num_minus1_l1;
  689. int *long_term_pic_idx_l1;
  690. short DFDisableIdc; //!< Disable deblocking filter on slice
  691. short DFAlphaC0Offset; //!< Alpha and C0 offset for filtering slice
  692. short DFBetaOffset; //!< Beta offset for filtering slice
  693. int pic_parameter_set_id; //!<the ID of the picture parameter set the slice is reffering to
  694. int dpB_NotPresent; //!< non-zero, if data partition B is lost
  695. int dpC_NotPresent; //!< non-zero, if data partition C is lost
  696. __declspec(align(32)) h264_imgpel_macroblock_t mb_pred[MAX_PLANE];
  697. __declspec(align(32)) h264_imgpel_macroblock_t mb_rec[MAX_PLANE];
  698. __declspec(align(32)) union
  699. {
  700. __declspec(align(32)) h264_short_8x8block_t mb_rres8[MAX_PLANE][4];
  701. __declspec(align(32)) h264_short_macroblock_t cof[MAX_PLANE];
  702. __declspec(align(32)) h264_short_block_t cof4[MAX_PLANE][16]; // TODO: get this to work, one of these days
  703. __declspec(align(32)) h264_short_macroblock_t ipcm[MAX_PLANE];
  704. };
  705. int cofu[16];
  706. // Scaling matrix info
  707. int InvLevelScale4x4_Intra[3][6][4][4];
  708. int InvLevelScale4x4_Inter[3][6][4][4];
  709. int InvLevelScale8x8_Intra[3][6][64];
  710. int InvLevelScale8x8_Inter[3][6][64];
  711. int *qmatrix[12];
  712. // Cabac
  713. // TODO: we could optimize coefficient reading by storing the levels/runs instead of coefficients
  714. int16_t coeff[64]; // one more for EOB
  715. int coeff_ctr;
  716. int pos;
  717. //weighted prediction
  718. unsigned int apply_weights;
  719. unsigned int luma_log2_weight_denom;
  720. unsigned int chroma_log2_weight_denom;
  721. int wp_weight[2][MAX_REFERENCE_PICTURES][3]; // weight in [list][index][component] order
  722. int wp_offset[6][MAX_REFERENCE_PICTURES][3]; // offset in [list][index][component] order
  723. int wbp_weight[6][MAX_REFERENCE_PICTURES][MAX_REFERENCE_PICTURES][3]; //weight in [list][fw_index][bw_index][component] order
  724. int wp_round_luma;
  725. int wp_round_chroma;
  726. void (*read_CBP_and_coeffs_from_NAL) (Macroblock *currMB);
  727. int (*decode_one_component ) (Macroblock *currMB, ColorPlane curr_plane, struct video_image *image, struct storable_picture *dec_picture);
  728. int (*readSlice ) (struct img_par *, struct inp_par *);
  729. int (*nal_startcode_follows ) (struct slice*, int );
  730. void (*read_motion_info_from_NAL) (Macroblock *currMB);
  731. void (*read_one_macroblock ) (Macroblock *currMB);
  732. void (*interpret_mb_mode ) (Macroblock *currMB);
  733. void (*compute_colocated ) (struct slice *currSlice, struct colocated_params *p, struct storable_picture **listX[6]);
  734. void (*linfo_cbp_intra) (int len,int info,int *cbp, int *dummy);
  735. void (*linfo_cbp_inter) (int len,int info,int *cbp, int *dummy);
  736. } Slice;
  737. //****************************** ~DM ***********************************
  738. // image parameters
  739. typedef struct img_par
  740. {
  741. struct inp_par *p_Inp;
  742. pic_parameter_set_rbsp_t *active_pps;
  743. seq_parameter_set_rbsp_t *active_sps;
  744. seq_parameter_set_rbsp_t SeqParSet[MAXSPS];
  745. pic_parameter_set_rbsp_t PicParSet[MAXPPS];
  746. struct sei_params *p_SEI;
  747. struct old_slice_par *old_slice;
  748. int number; //!< frame number
  749. unsigned int current_mb_nr; // bitstream order
  750. unsigned int num_dec_mb;
  751. short current_slice_nr;
  752. int *intra_block;
  753. int qp; //!< quant for the current frame
  754. int sp_switch; //!< 1 for switching sp, 0 for normal sp
  755. int type; //!< image type INTER/INTRA
  756. int width;
  757. int height;
  758. int width_cr; //!< width chroma
  759. int height_cr; //!< height chroma
  760. int mb_x;
  761. int mb_y;
  762. int block_x;
  763. int block_y;
  764. int pix_c_x;
  765. int pix_c_y;
  766. int allrefzero;
  767. byte **ipredmode; //!< prediction type [90][74]
  768. h264_nz_coefficient *nz_coeff;
  769. int **siblock;
  770. int cod_counter; //!< Current count of number of skipped macroblocks in a row
  771. int structure; //!< Identify picture structure type
  772. Slice *currentSlice; //!< pointer to current Slice data struct
  773. Macroblock *mb_data; //!< array containing all MBs of a whole frame
  774. Macroblock *mb_data_JV[MAX_PLANE]; //!< mb_data to be used for 4:4:4 independent mode
  775. int colour_plane_id; //!< colour_plane_id of the current coded slice
  776. int ChromaArrayType;
  777. // For MB level frame/field coding
  778. int mb_aff_frame_flag;
  779. // for signalling to the neighbour logic that this is a deblocker call
  780. int DeblockCall;
  781. byte mixedModeEdgeFlag;
  782. // picture error concealment
  783. // concealment_head points to first node in list, concealment_end points to
  784. // last node in list. Initialize both to NULL, meaning no nodes in list yet
  785. struct concealment_node *concealment_head;
  786. struct concealment_node *concealment_end;
  787. DecRefPicMarking_t *dec_ref_pic_marking_buffer; //!< stores the memory management control operations
  788. int num_ref_idx_l0_active; //!< number of forward reference
  789. int num_ref_idx_l1_active; //!< number of backward reference
  790. int slice_group_change_cycle;
  791. int redundant_pic_cnt;
  792. unsigned int pre_frame_num; //!< store the frame_num in the last decoded slice. For detecting gap in frame_num.
  793. int non_conforming_stream;
  794. // End JVT-D101
  795. // POC200301: from unsigned int to int
  796. int toppoc; //poc for this top field // POC200301
  797. int bottompoc; //poc of bottom field of frame
  798. int framepoc; //poc of this frame // POC200301
  799. unsigned int frame_num; //frame_num for this frame
  800. unsigned int field_pic_flag;
  801. byte bottom_field_flag;
  802. //the following is for slice header syntax elements of poc
  803. // for poc mode 0.
  804. unsigned int pic_order_cnt_lsb;
  805. int delta_pic_order_cnt_bottom;
  806. // for poc mode 1.
  807. int delta_pic_order_cnt[3];
  808. // ////////////////////////
  809. // for POC mode 0:
  810. signed int PrevPicOrderCntMsb;
  811. unsigned int PrevPicOrderCntLsb;
  812. signed int PicOrderCntMsb;
  813. // for POC mode 1:
  814. unsigned int AbsFrameNum;
  815. signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle;
  816. unsigned int PreviousFrameNum, FrameNumOffset;
  817. int ExpectedDeltaPerPicOrderCntCycle;
  818. int PreviousPOC, ThisPOC;
  819. int PreviousFrameNumOffset;
  820. // /////////////////////////
  821. int idr_flag;
  822. int nal_reference_idc; //!< nal_reference_idc from NAL unit
  823. int idr_pic_id;
  824. int MaxFrameNum;
  825. unsigned int PicWidthInMbs;
  826. unsigned int PicHeightInMapUnits;
  827. unsigned int FrameHeightInMbs;
  828. unsigned int PicHeightInMbs;
  829. unsigned int PicSizeInMbs;
  830. unsigned int FrameSizeInMbs;
  831. unsigned int oldFrameSizeInMbs;
  832. int no_output_of_prior_pics_flag;
  833. int long_term_reference_flag;
  834. int adaptive_ref_pic_buffering_flag;
  835. int last_has_mmco_5;
  836. int last_pic_bottom_field;
  837. // Fidelity Range Extensions Stuff
  838. short bitdepth_luma;
  839. short bitdepth_chroma;
  840. int bitdepth_scale[2];
  841. int bitdepth_luma_qp_scale;
  842. int bitdepth_chroma_qp_scale;
  843. unsigned int dc_pred_value_comp[MAX_PLANE]; //!< component value for DC prediction (depends on component pel bit depth)
  844. int max_pel_value_comp[MAX_PLANE]; //!< max value that one picture element (pixel) can take (depends on pic_unit_bitdepth)
  845. int Transform8x8Mode;
  846. int profile_idc;
  847. int yuv_format;
  848. int lossless_qpprime_flag;
  849. int num_blk8x8_uv;
  850. int num_uv_blocks;
  851. int num_cdc_coeff;
  852. int mb_cr_size_x;
  853. int mb_cr_size_y;
  854. int mb_cr_size_x_blk;
  855. int mb_cr_size_y_blk;
  856. int mb_size[3][2]; //!< component macroblock dimensions
  857. int mb_size_blk[3][2]; //!< component macroblock dimensions
  858. int mb_size_shift[3][2];
  859. int subpel_x;
  860. int subpel_y;
  861. int shiftpel_x;
  862. int shiftpel_y;
  863. int max_vmv_r; //!< maximum vertical motion vector range in luma quarter frame pixel units for the current level_idc
  864. int max_mb_vmv_r; //!< maximum vertical motion vector range in luma quarter pixel units for the current level_idc
  865. // picture error concealment
  866. int last_ref_pic_poc;
  867. int ref_poc_gap;
  868. int poc_gap;
  869. int earlier_missing_poc;
  870. unsigned int frame_to_conceal;
  871. int IDR_concealment_flag;
  872. int conceal_slice_type;
  873. // random access point decoding
  874. int recovery_point;
  875. int recovery_point_found;
  876. int recovery_frame_cnt;
  877. int recovery_frame_num;
  878. int recovery_poc;
  879. int separate_colour_plane_flag;
  880. int frame_number;
  881. int init_bl_done;
  882. // Redundant slices. Should be moved to another structure and allocated only if extended profile
  883. unsigned int previous_frame_num; //!< frame number of previous slice
  884. int ref_flag[17]; //!< 0: i-th previous frame is incorrect
  885. //!< non-zero: i-th previous frame is correct
  886. int Is_primary_correct; //!< if primary frame is correct, 0: incorrect
  887. int Is_redundant_correct; //!< if redundant frame is correct, 0:incorrect
  888. int redundant_slice_ref_idx; //!< reference index of redundant slice
  889. //FILE *p_log; //!< SNR file
  890. int LastAccessUnitExists;
  891. int NALUCount;
  892. Boolean global_init_done;
  893. int *qp_per_matrix;
  894. int *qp_rem_matrix;
  895. struct frame_store *last_out_fs;
  896. int pocs_in_dpb[100];
  897. struct storable_picture *dec_picture;
  898. struct storable_picture *dec_picture_JV[MAX_PLANE]; //!< dec_picture to be used during 4:4:4 independent mode decoding
  899. struct storable_picture *no_reference_picture; //!< dummy storable picture for recovery point
  900. struct storable_picture **listX[6];
  901. // Error parameters
  902. struct object_buffer *erc_object_list;
  903. struct ercVariables_s *erc_errorVar;
  904. int erc_mvperMB;
  905. struct img_par *erc_img;
  906. int ec_flag[SE_MAX_ELEMENTS]; //!< array to set errorconcealment
  907. struct memory_input_struct *mem_input;
  908. struct frame_store *out_buffer;
  909. struct storable_picture *pending_output;
  910. int pending_output_state;
  911. int recovery_flag;
  912. // dpb
  913. struct decoded_picture_buffer *p_Dpb;
  914. char listXsize[6];
  915. // report
  916. char cslice_type[9];
  917. // FMO
  918. int *MbToSliceGroupMap;
  919. int *MapUnitToSliceGroupMap;
  920. int NumberOfSliceGroups; // the number of slice groups -1 (0 == scan order, 7 == maximum)
  921. #if (ENABLE_OUTPUT_TONEMAPPING)
  922. struct tone_mapping_struct_s *seiToneMapping;
  923. #endif
  924. // benski> buffer of storablge pictures ready for output.
  925. // might be able to optimize a tad by making a ringbuffer, but i doubt it matters
  926. struct storable_picture **out_pictures;
  927. size_t size_out_pictures;
  928. size_t num_out_pictures;
  929. ImageCache image_cache[2]; // [0] is luma [1] is chroma (shared for both planes)
  930. MotionCache motion_cache;
  931. h264_pic_position *PicPos; //! Helper array to access macroblock positions.
  932. NALU_t *nalu; // a cache so we don't re-alloc every time
  933. void (*getNeighbour) (const Macroblock *currMB, int xN, int yN, const int mb_size[2], PixelPos *pix);
  934. void (*getNeighbourPX_NoPos)(const Macroblock *currMB, int xN, int yN, const int mb_size[2], PixelPos *pix);
  935. void (*getNeighbourXP_NoPos)(const Macroblock *currMB, int xN, int yN, const int mb_size[2], PixelPos *pix);
  936. void (*getNeighbourLuma) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  937. void (*getNeighbourPXLuma) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  938. void (*getNeighbourXPLuma) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  939. void (*getNeighbourLeftLuma)(const Macroblock *currMB, PixelPos *pix);
  940. void (*getNeighbourNXLuma) (const Macroblock *currMB, int yN, PixelPos *pix); // xN<0, yN full range
  941. void (*getNeighbourLeft) (const Macroblock *currMB, const int mb_size[2], PixelPos *pix); // xN<0, yN=0
  942. void (*getNeighbourUp) (const Macroblock *currMB, const int mb_size[2], PixelPos *pix); // xN=0, yN<0
  943. void (*getNeighbourNX) (const Macroblock *currMB, int yN, const int mb_size[2], PixelPos *pix); // xN<0, yN full range
  944. void (*getNeighbourNP) (const Macroblock *currMB, int yN, const int mb_size[2], PixelPos *pix); // xN<0, yN>=0
  945. void (*getNeighbourNPChromaNB)(const Macroblock *currMB, int yN, const int mb_size[2], PixelPos *pix); // xN<0, yN>=0
  946. void (*getNeighbour0X) (const Macroblock *currMB, int yN, const int mb_size[2], PixelPos *pix); // xN=0, yN full range
  947. void (*getNeighbour0XLuma) (const Macroblock *currMB, int yN, PixelPos *pix); // xN=0, yN full range
  948. void (*getNeighbourX0) (const Macroblock *currMB, int xN, const int mb_size[2], PixelPos *pix); // xN full range, yN = 0
  949. void (*getNeighbourUpLuma) (const Macroblock *currMB, PixelPos *pix); // xN=0, yN<0
  950. void (*getNeighbourNPLumaNB)(const Macroblock *currMB, int yN, PixelPos *pix);
  951. void (*getNeighbourPXLumaNB) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  952. void (*getNeighbourPXLumaNB_NoPos)(const Macroblock *currMB, int yN, PixelPos *pix);
  953. void (*getNeighbourPPLumaNB) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  954. void (*getNeighbourXPLumaNB) (const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  955. void (*getNeighbourXPLumaNB_NoPos)(const Macroblock *currMB, int xN, int yN, PixelPos *pix);
  956. void (*get_mb_block_pos) (const h264_pic_position *PicPos, int mb_addr, short *x, short *y);
  957. void (*GetStrength) (byte Strength[16], Macroblock *MbQ, int dir,int edge, int mvlimit, struct storable_picture *p);
  958. void (*EdgeLoopLuma) (ColorPlane pl, struct video_image *image, const byte Strength[16], Macroblock *MbQ, int dir, int edge, struct storable_picture *p);
  959. void (*EdgeLoopChroma) (struct video_image *image, byte Strength[16], Macroblock *MbQ, int dir, int edge, int uv, struct storable_picture *p);
  960. } VideoParameters;
  961. // input parameters from configuration file
  962. typedef struct inp_par
  963. {
  964. int intra_profile_deblocking; //!< Loop filter usage determined by flags and parameters in bitstream
  965. // Output sequence format related variables
  966. FrameFormat output; //!< output related information
  967. #ifdef _LEAKYBUCKET_
  968. unsigned long R_decoder; //!< Decoder Rate in HRD Model
  969. unsigned long B_decoder; //!< Decoder Buffer size in HRD model
  970. unsigned long F_decoder; //!< Decoder Initial buffer fullness in HRD model
  971. char LeakyBucketParamFile[FILE_NAME_SIZE]; //!< LeakyBucketParamFile
  972. #endif
  973. // picture error concealment
  974. int ref_poc_gap;
  975. int poc_gap;
  976. } InputParameters;
  977. typedef struct old_slice_par
  978. {
  979. unsigned field_pic_flag;
  980. unsigned frame_num;
  981. int nal_ref_idc;
  982. unsigned pic_oder_cnt_lsb;
  983. int delta_pic_oder_cnt_bottom;
  984. int delta_pic_order_cnt[2];
  985. byte bottom_field_flag;
  986. byte idr_flag;
  987. int idr_pic_id;
  988. int pps_id;
  989. } OldSliceParams;
  990. typedef struct decoder_params
  991. {
  992. InputParameters *p_Inp; //!< Input Parameters
  993. VideoParameters *p_Vid; //!< Image Parameters
  994. } DecoderParams;
  995. #ifdef TRACE
  996. extern FILE *p_trace; //!< Trace file
  997. extern int bitcounter;
  998. #endif
  999. // prototypes
  1000. extern void error(char *text, int code);
  1001. // dynamic mem allocation
  1002. extern int init_global_buffers(VideoParameters *p_Vid);
  1003. extern void free_global_buffers(VideoParameters *p_Vid);
  1004. extern int RBSPtoSODB(byte *streamBuffer, int last_byte_pos);
  1005. extern int EBSPtoRBSP(byte *streamBuffer, int end_bytepos);
  1006. void FreePartition (DataPartition *dp, int n);
  1007. DataPartition *AllocPartition(int n);
  1008. void tracebits(const char *trace_str, int len, int info,int value1);
  1009. void tracebits2(const char *trace_str, int len, int info);
  1010. unsigned CeilLog2 ( unsigned uiVal);
  1011. unsigned CeilLog2_sf( unsigned uiVal);
  1012. // For 4:4:4 independent mode
  1013. extern void change_plane_JV( VideoParameters *p_Vid, int nplane );
  1014. extern void make_frame_picture_JV(VideoParameters *p_Vid);
  1015. #endif