vc1.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /*
  2. * VC-1 and WMV3 decoder common code
  3. * Copyright (c) 2006-2007 Konstantin Shishkov
  4. * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * VC-1 and WMV3 decoder common code
  25. *
  26. */
  27. #include "internal.h"
  28. #include "dsputil.h"
  29. #include "avcodec.h"
  30. #include "mpegvideo.h"
  31. #include "vc1.h"
  32. #include "vc1data.h"
  33. #include "msmpeg4data.h"
  34. #include "unary.h"
  35. #include "simple_idct.h"
  36. #undef NDEBUG
  37. #include <assert.h>
  38. /***********************************************************************/
  39. /**
  40. * @name VC-1 Bitplane decoding
  41. * @see 8.7, p56
  42. * @{
  43. */
  44. /**
  45. * Imode types
  46. * @{
  47. */
  48. enum Imode {
  49. IMODE_RAW,
  50. IMODE_NORM2,
  51. IMODE_DIFF2,
  52. IMODE_NORM6,
  53. IMODE_DIFF6,
  54. IMODE_ROWSKIP,
  55. IMODE_COLSKIP
  56. };
  57. /** @} */ //imode defines
  58. /** Decode rows by checking if they are skipped
  59. * @param plane Buffer to store decoded bits
  60. * @param[in] width Width of this buffer
  61. * @param[in] height Height of this buffer
  62. * @param[in] stride of this buffer
  63. */
  64. static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
  65. int x, y;
  66. for (y=0; y<height; y++){
  67. if (!get_bits1(gb)) //rowskip
  68. memset(plane, 0, width);
  69. else
  70. for (x=0; x<width; x++)
  71. plane[x] = get_bits1(gb);
  72. plane += stride;
  73. }
  74. }
  75. /** Decode columns by checking if they are skipped
  76. * @param plane Buffer to store decoded bits
  77. * @param[in] width Width of this buffer
  78. * @param[in] height Height of this buffer
  79. * @param[in] stride of this buffer
  80. * @todo FIXME: Optimize
  81. */
  82. static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
  83. int x, y;
  84. for (x=0; x<width; x++){
  85. if (!get_bits1(gb)) //colskip
  86. for (y=0; y<height; y++)
  87. plane[y*stride] = 0;
  88. else
  89. for (y=0; y<height; y++)
  90. plane[y*stride] = get_bits1(gb);
  91. plane ++;
  92. }
  93. }
  94. /** Decode a bitplane's bits
  95. * @param data bitplane where to store the decode bits
  96. * @param[out] raw_flag pointer to the flag indicating that this bitplane is not coded explicitly
  97. * @param v VC-1 context for bit reading and logging
  98. * @return Status
  99. * @todo FIXME: Optimize
  100. */
  101. static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
  102. {
  103. GetBitContext *gb = &v->s.gb;
  104. int imode, x, y, code, offset;
  105. uint8_t invert, *planep = data;
  106. int width, height, stride;
  107. width = v->s.mb_width;
  108. height = v->s.mb_height;
  109. stride = v->s.mb_stride;
  110. invert = get_bits1(gb);
  111. imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
  112. *raw_flag = 0;
  113. switch (imode)
  114. {
  115. case IMODE_RAW:
  116. //Data is actually read in the MB layer (same for all tests == "raw")
  117. *raw_flag = 1; //invert ignored
  118. return invert;
  119. case IMODE_DIFF2:
  120. case IMODE_NORM2:
  121. if ((height * width) & 1)
  122. {
  123. *planep++ = get_bits1(gb);
  124. offset = 1;
  125. }
  126. else offset = 0;
  127. // decode bitplane as one long line
  128. for (y = offset; y < height * width; y += 2) {
  129. code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
  130. *planep++ = code & 1;
  131. offset++;
  132. if(offset == width) {
  133. offset = 0;
  134. planep += stride - width;
  135. }
  136. *planep++ = code >> 1;
  137. offset++;
  138. if(offset == width) {
  139. offset = 0;
  140. planep += stride - width;
  141. }
  142. }
  143. break;
  144. case IMODE_DIFF6:
  145. case IMODE_NORM6:
  146. if(!(height % 3) && (width % 3)) { // use 2x3 decoding
  147. for(y = 0; y < height; y+= 3) {
  148. for(x = width & 1; x < width; x += 2) {
  149. code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
  150. if(code < 0){
  151. av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
  152. return -1;
  153. }
  154. planep[x + 0] = (code >> 0) & 1;
  155. planep[x + 1] = (code >> 1) & 1;
  156. planep[x + 0 + stride] = (code >> 2) & 1;
  157. planep[x + 1 + stride] = (code >> 3) & 1;
  158. planep[x + 0 + stride * 2] = (code >> 4) & 1;
  159. planep[x + 1 + stride * 2] = (code >> 5) & 1;
  160. }
  161. planep += stride * 3;
  162. }
  163. if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
  164. } else { // 3x2
  165. planep += (height & 1) * stride;
  166. for(y = height & 1; y < height; y += 2) {
  167. for(x = width % 3; x < width; x += 3) {
  168. code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
  169. if(code < 0){
  170. av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
  171. return -1;
  172. }
  173. planep[x + 0] = (code >> 0) & 1;
  174. planep[x + 1] = (code >> 1) & 1;
  175. planep[x + 2] = (code >> 2) & 1;
  176. planep[x + 0 + stride] = (code >> 3) & 1;
  177. planep[x + 1 + stride] = (code >> 4) & 1;
  178. planep[x + 2 + stride] = (code >> 5) & 1;
  179. }
  180. planep += stride * 2;
  181. }
  182. x = width % 3;
  183. if(x) decode_colskip(data , x, height , stride, &v->s.gb);
  184. if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
  185. }
  186. break;
  187. case IMODE_ROWSKIP:
  188. decode_rowskip(data, width, height, stride, &v->s.gb);
  189. break;
  190. case IMODE_COLSKIP:
  191. decode_colskip(data, width, height, stride, &v->s.gb);
  192. break;
  193. default: break;
  194. }
  195. /* Applying diff operator */
  196. if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
  197. {
  198. planep = data;
  199. planep[0] ^= invert;
  200. for (x=1; x<width; x++)
  201. planep[x] ^= planep[x-1];
  202. for (y=1; y<height; y++)
  203. {
  204. planep += stride;
  205. planep[0] ^= planep[-stride];
  206. for (x=1; x<width; x++)
  207. {
  208. if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
  209. else planep[x] ^= planep[x-1];
  210. }
  211. }
  212. }
  213. else if (invert)
  214. {
  215. planep = data;
  216. for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
  217. }
  218. return (imode<<1) + invert;
  219. }
  220. /** @} */ //Bitplane group
  221. /***********************************************************************/
  222. /** VOP Dquant decoding
  223. * @param v VC-1 Context
  224. */
  225. static int vop_dquant_decoding(VC1Context *v)
  226. {
  227. GetBitContext *gb = &v->s.gb;
  228. int pqdiff;
  229. //variable size
  230. if (v->dquant == 2)
  231. {
  232. pqdiff = get_bits(gb, 3);
  233. if (pqdiff == 7) v->altpq = get_bits(gb, 5);
  234. else v->altpq = v->pq + pqdiff + 1;
  235. }
  236. else
  237. {
  238. v->dquantfrm = get_bits1(gb);
  239. if ( v->dquantfrm )
  240. {
  241. v->dqprofile = get_bits(gb, 2);
  242. switch (v->dqprofile)
  243. {
  244. case DQPROFILE_SINGLE_EDGE:
  245. case DQPROFILE_DOUBLE_EDGES:
  246. v->dqsbedge = get_bits(gb, 2);
  247. break;
  248. case DQPROFILE_ALL_MBS:
  249. v->dqbilevel = get_bits1(gb);
  250. if(!v->dqbilevel)
  251. v->halfpq = 0;
  252. default: break; //Forbidden ?
  253. }
  254. if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
  255. {
  256. pqdiff = get_bits(gb, 3);
  257. if (pqdiff == 7) v->altpq = get_bits(gb, 5);
  258. else v->altpq = v->pq + pqdiff + 1;
  259. }
  260. }
  261. }
  262. return 0;
  263. }
  264. static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
  265. /**
  266. * Decode Simple/Main Profiles sequence header
  267. * @see Figure 7-8, p16-17
  268. * @param avctx Codec context
  269. * @param gb GetBit context initialized from Codec context extra_data
  270. * @return Status
  271. */
  272. int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
  273. {
  274. av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
  275. v->profile = get_bits(gb, 2);
  276. if (v->profile == PROFILE_COMPLEX)
  277. {
  278. av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
  279. }
  280. if (v->profile == PROFILE_ADVANCED)
  281. {
  282. v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
  283. v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
  284. return decode_sequence_header_adv(v, gb);
  285. }
  286. else
  287. {
  288. v->zz_8x4 = wmv2_scantableA;
  289. v->zz_4x8 = wmv2_scantableB;
  290. v->res_y411 = get_bits1(gb);
  291. v->res_sprite = get_bits1(gb);
  292. if (v->res_y411)
  293. {
  294. av_log(avctx, AV_LOG_ERROR,
  295. "Old interlaced mode is not supported\n");
  296. return -1;
  297. }
  298. if (v->res_sprite) {
  299. av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n");
  300. }
  301. }
  302. // (fps-2)/4 (->30)
  303. v->frmrtq_postproc = get_bits(gb, 3); //common
  304. // (bitrate-32kbps)/64kbps
  305. v->bitrtq_postproc = get_bits(gb, 5); //common
  306. v->s.loop_filter = get_bits1(gb); //common
  307. if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
  308. {
  309. av_log(avctx, AV_LOG_ERROR,
  310. "LOOPFILTER shall not be enabled in Simple Profile\n");
  311. }
  312. if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
  313. v->s.loop_filter = 0;
  314. v->res_x8 = get_bits1(gb); //reserved
  315. v->multires = get_bits1(gb);
  316. v->res_fasttx = get_bits1(gb);
  317. if (!v->res_fasttx)
  318. {
  319. v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_8;
  320. v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
  321. v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
  322. v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
  323. v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_8;
  324. v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
  325. v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
  326. v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
  327. }
  328. v->fastuvmc = get_bits1(gb); //common
  329. if (!v->profile && !v->fastuvmc)
  330. {
  331. av_log(avctx, AV_LOG_ERROR,
  332. "FASTUVMC unavailable in Simple Profile\n");
  333. return -1;
  334. }
  335. v->extended_mv = get_bits1(gb); //common
  336. if (!v->profile && v->extended_mv)
  337. {
  338. av_log(avctx, AV_LOG_ERROR,
  339. "Extended MVs unavailable in Simple Profile\n");
  340. return -1;
  341. }
  342. v->dquant = get_bits(gb, 2); //common
  343. v->vstransform = get_bits1(gb); //common
  344. v->res_transtab = get_bits1(gb);
  345. if (v->res_transtab)
  346. {
  347. av_log(avctx, AV_LOG_ERROR,
  348. "1 for reserved RES_TRANSTAB is forbidden\n");
  349. return -1;
  350. }
  351. v->overlap = get_bits1(gb); //common
  352. v->s.resync_marker = get_bits1(gb);
  353. v->rangered = get_bits1(gb);
  354. if (v->rangered && v->profile == PROFILE_SIMPLE)
  355. {
  356. av_log(avctx, AV_LOG_INFO,
  357. "RANGERED should be set to 0 in Simple Profile\n");
  358. }
  359. v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
  360. v->quantizer_mode = get_bits(gb, 2); //common
  361. v->finterpflag = get_bits1(gb); //common
  362. if (v->res_sprite) {
  363. int w = get_bits(gb, 11);
  364. int h = get_bits(gb, 11);
  365. avcodec_set_dimensions(v->s.avctx, w, h);
  366. skip_bits(gb, 5); //frame rate
  367. v->res_x8 = get_bits1(gb);
  368. if (get_bits1(gb)) { // something to do with DC VLC selection
  369. av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
  370. return -1;
  371. }
  372. skip_bits(gb, 3); //slice code
  373. v->res_rtm_flag = 0;
  374. } else {
  375. v->res_rtm_flag = get_bits1(gb); //reserved
  376. }
  377. if (!v->res_rtm_flag)
  378. {
  379. // av_log(avctx, AV_LOG_ERROR,
  380. // "0 for reserved RES_RTM_FLAG is forbidden\n");
  381. av_log(avctx, AV_LOG_ERROR,
  382. "Old WMV3 version detected, some frames may be decoded incorrectly\n");
  383. //return -1;
  384. }
  385. //TODO: figure out what they mean (always 0x402F)
  386. if(!v->res_fasttx) skip_bits(gb, 16);
  387. av_log(avctx, AV_LOG_DEBUG,
  388. "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
  389. "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
  390. "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
  391. "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
  392. v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
  393. v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
  394. v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
  395. v->dquant, v->quantizer_mode, avctx->max_b_frames
  396. );
  397. return 0;
  398. }
  399. static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
  400. {
  401. int w, h;
  402. v->res_rtm_flag = 1;
  403. v->level = get_bits(gb, 3);
  404. if(v->level >= 5)
  405. {
  406. av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
  407. }
  408. v->chromaformat = get_bits(gb, 2);
  409. if (v->chromaformat != 1)
  410. {
  411. av_log(v->s.avctx, AV_LOG_ERROR,
  412. "Only 4:2:0 chroma format supported\n");
  413. return -1;
  414. }
  415. // (fps-2)/4 (->30)
  416. v->frmrtq_postproc = get_bits(gb, 3); //common
  417. // (bitrate-32kbps)/64kbps
  418. v->bitrtq_postproc = get_bits(gb, 5); //common
  419. v->postprocflag = get_bits1(gb); //common
  420. w = (get_bits(gb, 12) + 1) << 1;
  421. h = (get_bits(gb, 12) + 1) << 1;
  422. avcodec_set_dimensions(v->s.avctx, w, h);
  423. v->broadcast = get_bits1(gb);
  424. v->interlace = get_bits1(gb);
  425. v->tfcntrflag = get_bits1(gb);
  426. v->finterpflag = get_bits1(gb);
  427. skip_bits1(gb); // reserved
  428. v->s.h_edge_pos = w;
  429. v->s.v_edge_pos = h;
  430. av_log(v->s.avctx, AV_LOG_DEBUG,
  431. "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
  432. "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
  433. "TFCTRflag=%i, FINTERPflag=%i\n",
  434. v->level, v->frmrtq_postproc, v->bitrtq_postproc,
  435. v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
  436. v->tfcntrflag, v->finterpflag
  437. );
  438. v->psf = get_bits1(gb);
  439. if(v->psf) { //PsF, 6.1.13
  440. av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
  441. return -1;
  442. }
  443. v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
  444. if(get_bits1(gb)) { //Display Info - decoding is not affected by it
  445. int dw, dh, ar = 0;
  446. av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
  447. dw = get_bits(gb, 14) + 1;
  448. dh = get_bits(gb, 14) + 1;
  449. v->s.avctx->sample_aspect_ratio = av_div_q((AVRational){dw, dh}, (AVRational){w, h});
  450. av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", dw, dh);
  451. if(get_bits1(gb))
  452. ar = get_bits(gb, 4);
  453. if(ar && ar < 14){
  454. v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
  455. }else if(ar == 15){
  456. w = get_bits(gb, 8) + 1;
  457. h = get_bits(gb, 8) + 1;
  458. v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
  459. }
  460. av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den);
  461. if(get_bits1(gb)){ //framerate stuff
  462. if(get_bits1(gb)) {
  463. v->s.avctx->time_base.num = 32;
  464. v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
  465. } else {
  466. int nr, dr;
  467. nr = get_bits(gb, 8);
  468. dr = get_bits(gb, 4);
  469. if(nr && nr < 8 && dr && dr < 3){
  470. v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1];
  471. v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000;
  472. }
  473. }
  474. }
  475. if(get_bits1(gb)){
  476. v->color_prim = get_bits(gb, 8);
  477. v->transfer_char = get_bits(gb, 8);
  478. v->matrix_coef = get_bits(gb, 8);
  479. }
  480. }
  481. v->hrd_param_flag = get_bits1(gb);
  482. if(v->hrd_param_flag) {
  483. int i;
  484. v->hrd_num_leaky_buckets = get_bits(gb, 5);
  485. skip_bits(gb, 4); //bitrate exponent
  486. skip_bits(gb, 4); //buffer size exponent
  487. for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
  488. skip_bits(gb, 16); //hrd_rate[n]
  489. skip_bits(gb, 16); //hrd_buffer[n]
  490. }
  491. }
  492. return 0;
  493. }
  494. int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
  495. {
  496. int i;
  497. av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
  498. v->broken_link = get_bits1(gb);
  499. v->closed_entry = get_bits1(gb);
  500. v->panscanflag = get_bits1(gb);
  501. v->refdist_flag = get_bits1(gb);
  502. v->s.loop_filter = get_bits1(gb);
  503. v->fastuvmc = get_bits1(gb);
  504. v->extended_mv = get_bits1(gb);
  505. v->dquant = get_bits(gb, 2);
  506. v->vstransform = get_bits1(gb);
  507. v->overlap = get_bits1(gb);
  508. v->quantizer_mode = get_bits(gb, 2);
  509. if(v->hrd_param_flag){
  510. for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
  511. skip_bits(gb, 8); //hrd_full[n]
  512. }
  513. }
  514. if(get_bits1(gb)){
  515. int w = (get_bits(gb, 12)+1)<<1;
  516. int h = (get_bits(gb, 12)+1)<<1;
  517. avcodec_set_dimensions(avctx, w, h);
  518. }
  519. if(v->extended_mv)
  520. v->extended_dmv = get_bits1(gb);
  521. if((v->range_mapy_flag = get_bits1(gb))) {
  522. av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
  523. v->range_mapy = get_bits(gb, 3);
  524. }
  525. if((v->range_mapuv_flag = get_bits1(gb))) {
  526. av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
  527. v->range_mapuv = get_bits(gb, 3);
  528. }
  529. av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
  530. "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
  531. "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
  532. "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
  533. v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
  534. v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
  535. return 0;
  536. }
  537. int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
  538. {
  539. int pqindex, lowquant, status;
  540. if(v->finterpflag) v->interpfrm = get_bits1(gb);
  541. skip_bits(gb, 2); //framecnt unused
  542. v->rangeredfrm = 0;
  543. if (v->rangered) v->rangeredfrm = get_bits1(gb);
  544. v->s.pict_type = get_bits1(gb);
  545. if (v->s.avctx->max_b_frames) {
  546. if (!v->s.pict_type) {
  547. if (get_bits1(gb)) v->s.pict_type = AV_PICTURE_TYPE_I;
  548. else v->s.pict_type = AV_PICTURE_TYPE_B;
  549. } else v->s.pict_type = AV_PICTURE_TYPE_P;
  550. } else v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
  551. v->bi_type = 0;
  552. if(v->s.pict_type == AV_PICTURE_TYPE_B) {
  553. v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
  554. v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
  555. if(v->bfraction == 0) {
  556. v->s.pict_type = AV_PICTURE_TYPE_BI;
  557. }
  558. }
  559. if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
  560. skip_bits(gb, 7); // skip buffer fullness
  561. if(v->parse_only)
  562. return 0;
  563. /* calculate RND */
  564. if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
  565. v->rnd = 1;
  566. if(v->s.pict_type == AV_PICTURE_TYPE_P)
  567. v->rnd ^= 1;
  568. /* Quantizer stuff */
  569. pqindex = get_bits(gb, 5);
  570. if(!pqindex) return -1;
  571. if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
  572. v->pq = ff_vc1_pquant_table[0][pqindex];
  573. else
  574. v->pq = ff_vc1_pquant_table[1][pqindex];
  575. v->pquantizer = 1;
  576. if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
  577. v->pquantizer = pqindex < 9;
  578. if (v->quantizer_mode == QUANT_NON_UNIFORM)
  579. v->pquantizer = 0;
  580. v->pqindex = pqindex;
  581. if (pqindex < 9) v->halfpq = get_bits1(gb);
  582. else v->halfpq = 0;
  583. if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
  584. v->pquantizer = get_bits1(gb);
  585. v->dquantfrm = 0;
  586. if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3);
  587. v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
  588. v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
  589. v->range_x = 1 << (v->k_x - 1);
  590. v->range_y = 1 << (v->k_y - 1);
  591. if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B) v->respic = get_bits(gb, 2);
  592. if(v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)){
  593. v->x8_type = get_bits1(gb);
  594. }else v->x8_type = 0;
  595. //av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
  596. // (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
  597. if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) v->use_ic = 0;
  598. switch(v->s.pict_type) {
  599. case AV_PICTURE_TYPE_P:
  600. if (v->pq < 5) v->tt_index = 0;
  601. else if(v->pq < 13) v->tt_index = 1;
  602. else v->tt_index = 2;
  603. lowquant = (v->pq > 12) ? 0 : 1;
  604. v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
  605. if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
  606. {
  607. int scale, shift, i;
  608. v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
  609. v->lumscale = get_bits(gb, 6);
  610. v->lumshift = get_bits(gb, 6);
  611. v->use_ic = 1;
  612. /* fill lookup tables for intensity compensation */
  613. if(!v->lumscale) {
  614. scale = -64;
  615. shift = (255 - v->lumshift * 2) << 6;
  616. if(v->lumshift > 31)
  617. shift += 128 << 6;
  618. } else {
  619. scale = v->lumscale + 32;
  620. if(v->lumshift > 31)
  621. shift = (v->lumshift - 64) << 6;
  622. else
  623. shift = v->lumshift << 6;
  624. }
  625. for(i = 0; i < 256; i++) {
  626. v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
  627. v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
  628. }
  629. }
  630. if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
  631. v->s.quarter_sample = 0;
  632. else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
  633. if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
  634. v->s.quarter_sample = 0;
  635. else
  636. v->s.quarter_sample = 1;
  637. } else
  638. v->s.quarter_sample = 1;
  639. v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
  640. if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
  641. v->mv_mode2 == MV_PMODE_MIXED_MV)
  642. || v->mv_mode == MV_PMODE_MIXED_MV)
  643. {
  644. status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
  645. if (status < 0) return -1;
  646. av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
  647. "Imode: %i, Invert: %i\n", status>>1, status&1);
  648. } else {
  649. v->mv_type_is_raw = 0;
  650. memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
  651. }
  652. status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
  653. if (status < 0) return -1;
  654. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
  655. "Imode: %i, Invert: %i\n", status>>1, status&1);
  656. /* Hopefully this is correct for P frames */
  657. v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
  658. v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
  659. if (v->dquant)
  660. {
  661. av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
  662. vop_dquant_decoding(v);
  663. }
  664. v->ttfrm = 0; //FIXME Is that so ?
  665. if (v->vstransform)
  666. {
  667. v->ttmbf = get_bits1(gb);
  668. if (v->ttmbf)
  669. {
  670. v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
  671. }
  672. } else {
  673. v->ttmbf = 1;
  674. v->ttfrm = TT_8X8;
  675. }
  676. break;
  677. case AV_PICTURE_TYPE_B:
  678. if (v->pq < 5) v->tt_index = 0;
  679. else if(v->pq < 13) v->tt_index = 1;
  680. else v->tt_index = 2;
  681. v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
  682. v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
  683. v->s.mspel = v->s.quarter_sample;
  684. status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
  685. if (status < 0) return -1;
  686. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
  687. "Imode: %i, Invert: %i\n", status>>1, status&1);
  688. status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
  689. if (status < 0) return -1;
  690. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
  691. "Imode: %i, Invert: %i\n", status>>1, status&1);
  692. v->s.mv_table_index = get_bits(gb, 2);
  693. v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
  694. if (v->dquant)
  695. {
  696. av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
  697. vop_dquant_decoding(v);
  698. }
  699. v->ttfrm = 0;
  700. if (v->vstransform)
  701. {
  702. v->ttmbf = get_bits1(gb);
  703. if (v->ttmbf)
  704. {
  705. v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
  706. }
  707. } else {
  708. v->ttmbf = 1;
  709. v->ttfrm = TT_8X8;
  710. }
  711. break;
  712. }
  713. if(!v->x8_type)
  714. {
  715. /* AC Syntax */
  716. v->c_ac_table_index = decode012(gb);
  717. if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
  718. {
  719. v->y_ac_table_index = decode012(gb);
  720. }
  721. /* DC Syntax */
  722. v->s.dc_table_index = get_bits1(gb);
  723. }
  724. if(v->s.pict_type == AV_PICTURE_TYPE_BI) {
  725. v->s.pict_type = AV_PICTURE_TYPE_B;
  726. v->bi_type = 1;
  727. }
  728. return 0;
  729. }
  730. int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
  731. {
  732. int pqindex, lowquant;
  733. int status;
  734. v->p_frame_skipped = 0;
  735. if(v->interlace){
  736. v->fcm = decode012(gb);
  737. if(v->fcm){
  738. if(!v->warn_interlaced++)
  739. av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is not implemented\n");
  740. return -1;
  741. }
  742. }
  743. switch(get_unary(gb, 0, 4)) {
  744. case 0:
  745. v->s.pict_type = AV_PICTURE_TYPE_P;
  746. break;
  747. case 1:
  748. v->s.pict_type = AV_PICTURE_TYPE_B;
  749. break;
  750. case 2:
  751. v->s.pict_type = AV_PICTURE_TYPE_I;
  752. break;
  753. case 3:
  754. v->s.pict_type = AV_PICTURE_TYPE_BI;
  755. break;
  756. case 4:
  757. v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
  758. v->p_frame_skipped = 1;
  759. return 0;
  760. }
  761. if(v->tfcntrflag)
  762. skip_bits(gb, 8);
  763. if(v->broadcast) {
  764. if(!v->interlace || v->psf) {
  765. v->rptfrm = get_bits(gb, 2);
  766. } else {
  767. v->tff = get_bits1(gb);
  768. v->rff = get_bits1(gb);
  769. }
  770. }
  771. if(v->panscanflag) {
  772. av_log_missing_feature(v->s.avctx, "Pan-scan", 0);
  773. //...
  774. }
  775. v->rnd = get_bits1(gb);
  776. if(v->interlace)
  777. v->uvsamp = get_bits1(gb);
  778. if(v->finterpflag) v->interpfrm = get_bits1(gb);
  779. if(v->s.pict_type == AV_PICTURE_TYPE_B) {
  780. v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
  781. v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
  782. if(v->bfraction == 0) {
  783. v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
  784. }
  785. }
  786. pqindex = get_bits(gb, 5);
  787. if(!pqindex) return -1;
  788. v->pqindex = pqindex;
  789. if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
  790. v->pq = ff_vc1_pquant_table[0][pqindex];
  791. else
  792. v->pq = ff_vc1_pquant_table[1][pqindex];
  793. v->pquantizer = 1;
  794. if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
  795. v->pquantizer = pqindex < 9;
  796. if (v->quantizer_mode == QUANT_NON_UNIFORM)
  797. v->pquantizer = 0;
  798. v->pqindex = pqindex;
  799. if (pqindex < 9) v->halfpq = get_bits1(gb);
  800. else v->halfpq = 0;
  801. if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
  802. v->pquantizer = get_bits1(gb);
  803. if(v->postprocflag)
  804. v->postproc = get_bits(gb, 2);
  805. if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) v->use_ic = 0;
  806. if(v->parse_only)
  807. return 0;
  808. switch(v->s.pict_type) {
  809. case AV_PICTURE_TYPE_I:
  810. case AV_PICTURE_TYPE_BI:
  811. status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
  812. if (status < 0) return -1;
  813. av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
  814. "Imode: %i, Invert: %i\n", status>>1, status&1);
  815. v->condover = CONDOVER_NONE;
  816. if(v->overlap && v->pq <= 8) {
  817. v->condover = decode012(gb);
  818. if(v->condover == CONDOVER_SELECT) {
  819. status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
  820. if (status < 0) return -1;
  821. av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
  822. "Imode: %i, Invert: %i\n", status>>1, status&1);
  823. }
  824. }
  825. break;
  826. case AV_PICTURE_TYPE_P:
  827. if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
  828. else v->mvrange = 0;
  829. v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
  830. v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
  831. v->range_x = 1 << (v->k_x - 1);
  832. v->range_y = 1 << (v->k_y - 1);
  833. if (v->pq < 5) v->tt_index = 0;
  834. else if(v->pq < 13) v->tt_index = 1;
  835. else v->tt_index = 2;
  836. lowquant = (v->pq > 12) ? 0 : 1;
  837. v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
  838. if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
  839. {
  840. int scale, shift, i;
  841. v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
  842. v->lumscale = get_bits(gb, 6);
  843. v->lumshift = get_bits(gb, 6);
  844. /* fill lookup tables for intensity compensation */
  845. if(!v->lumscale) {
  846. scale = -64;
  847. shift = (255 - v->lumshift * 2) << 6;
  848. if(v->lumshift > 31)
  849. shift += 128 << 6;
  850. } else {
  851. scale = v->lumscale + 32;
  852. if(v->lumshift > 31)
  853. shift = (v->lumshift - 64) << 6;
  854. else
  855. shift = v->lumshift << 6;
  856. }
  857. for(i = 0; i < 256; i++) {
  858. v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
  859. v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
  860. }
  861. v->use_ic = 1;
  862. }
  863. if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
  864. v->s.quarter_sample = 0;
  865. else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
  866. if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
  867. v->s.quarter_sample = 0;
  868. else
  869. v->s.quarter_sample = 1;
  870. } else
  871. v->s.quarter_sample = 1;
  872. v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
  873. if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
  874. v->mv_mode2 == MV_PMODE_MIXED_MV)
  875. || v->mv_mode == MV_PMODE_MIXED_MV)
  876. {
  877. status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
  878. if (status < 0) return -1;
  879. av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
  880. "Imode: %i, Invert: %i\n", status>>1, status&1);
  881. } else {
  882. v->mv_type_is_raw = 0;
  883. memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
  884. }
  885. status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
  886. if (status < 0) return -1;
  887. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
  888. "Imode: %i, Invert: %i\n", status>>1, status&1);
  889. /* Hopefully this is correct for P frames */
  890. v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
  891. v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
  892. if (v->dquant)
  893. {
  894. av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
  895. vop_dquant_decoding(v);
  896. }
  897. v->ttfrm = 0; //FIXME Is that so ?
  898. if (v->vstransform)
  899. {
  900. v->ttmbf = get_bits1(gb);
  901. if (v->ttmbf)
  902. {
  903. v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
  904. }
  905. } else {
  906. v->ttmbf = 1;
  907. v->ttfrm = TT_8X8;
  908. }
  909. break;
  910. case AV_PICTURE_TYPE_B:
  911. if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
  912. else v->mvrange = 0;
  913. v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
  914. v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
  915. v->range_x = 1 << (v->k_x - 1);
  916. v->range_y = 1 << (v->k_y - 1);
  917. if (v->pq < 5) v->tt_index = 0;
  918. else if(v->pq < 13) v->tt_index = 1;
  919. else v->tt_index = 2;
  920. v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
  921. v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
  922. v->s.mspel = v->s.quarter_sample;
  923. status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
  924. if (status < 0) return -1;
  925. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
  926. "Imode: %i, Invert: %i\n", status>>1, status&1);
  927. status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
  928. if (status < 0) return -1;
  929. av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
  930. "Imode: %i, Invert: %i\n", status>>1, status&1);
  931. v->s.mv_table_index = get_bits(gb, 2);
  932. v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
  933. if (v->dquant)
  934. {
  935. av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
  936. vop_dquant_decoding(v);
  937. }
  938. v->ttfrm = 0;
  939. if (v->vstransform)
  940. {
  941. v->ttmbf = get_bits1(gb);
  942. if (v->ttmbf)
  943. {
  944. v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
  945. }
  946. } else {
  947. v->ttmbf = 1;
  948. v->ttfrm = TT_8X8;
  949. }
  950. break;
  951. }
  952. /* AC Syntax */
  953. v->c_ac_table_index = decode012(gb);
  954. if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
  955. {
  956. v->y_ac_table_index = decode012(gb);
  957. }
  958. /* DC Syntax */
  959. v->s.dc_table_index = get_bits1(gb);
  960. if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) && v->dquant) {
  961. av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
  962. vop_dquant_decoding(v);
  963. }
  964. v->bi_type = 0;
  965. if(v->s.pict_type == AV_PICTURE_TYPE_BI) {
  966. v->s.pict_type = AV_PICTURE_TYPE_B;
  967. v->bi_type = 1;
  968. }
  969. return 0;
  970. }