You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1556 lines
53KB

  1. /*
  2. * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
  3. * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * @file cavs.c
  21. * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
  22. * @author Stefan Gehrer <stefan.gehrer@gmx.de>
  23. */
  24. #include "avcodec.h"
  25. #include "bitstream.h"
  26. #include "golomb.h"
  27. #include "mpegvideo.h"
  28. #include "cavsdata.h"
  29. typedef struct {
  30. MpegEncContext s;
  31. Picture picture; ///< currently decoded frame
  32. Picture DPB[2]; ///< reference frames
  33. int dist[2]; ///< temporal distances from current frame to ref frames
  34. int profile, level;
  35. int aspect_ratio;
  36. int mb_width, mb_height;
  37. int pic_type;
  38. int progressive;
  39. int pic_structure;
  40. int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
  41. int loop_filter_disable;
  42. int alpha_offset, beta_offset;
  43. int ref_flag;
  44. int mbx, mby; ///< macroblock coordinates
  45. int flags; ///< availability flags of neighbouring macroblocks
  46. int stc; ///< last start code
  47. uint8_t *cy, *cu, *cv; ///< current MB sample pointers
  48. int left_qp;
  49. uint8_t *top_qp;
  50. /** mv motion vector cache
  51. 0: D3 B2 B3 C2
  52. 4: A1 X0 X1 -
  53. 8: A3 X2 X3 -
  54. X are the vectors in the current macroblock (5,6,9,10)
  55. A is the macroblock to the left (4,8)
  56. B is the macroblock to the top (1,2)
  57. C is the macroblock to the top-right (3)
  58. D is the macroblock to the top-left (0)
  59. the same is repeated for backward motion vectors */
  60. vector_t mv[2*4*3];
  61. vector_t *top_mv[2];
  62. vector_t *col_mv;
  63. /** luma pred mode cache
  64. 0: -- B2 B3
  65. 3: A1 X0 X1
  66. 6: A3 X2 X3 */
  67. int pred_mode_Y[3*3];
  68. int *top_pred_Y;
  69. int l_stride, c_stride;
  70. int luma_scan[4];
  71. int qp;
  72. int qp_fixed;
  73. int cbp;
  74. /** intra prediction is done with un-deblocked samples
  75. they are saved here before deblocking the MB */
  76. uint8_t *top_border_y, *top_border_u, *top_border_v;
  77. uint8_t left_border_y[16], left_border_u[10], left_border_v[10];
  78. uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
  79. void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
  80. void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
  81. uint8_t *col_type_base;
  82. uint8_t *col_type;
  83. /* scaling factors for MV prediction */
  84. int sym_factor; ///< for scaling in symmetrical B block
  85. int direct_den[2]; ///< for scaling in direct B block
  86. int scale_den[2]; ///< for scaling neighbouring MVs
  87. int got_keyframe;
  88. } AVSContext;
  89. /*****************************************************************************
  90. *
  91. * in-loop deblocking filter
  92. *
  93. ****************************************************************************/
  94. static inline int get_bs_p(vector_t *mvP, vector_t *mvQ) {
  95. if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
  96. return 2;
  97. if(mvP->ref != mvQ->ref)
  98. return 1;
  99. if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
  100. return 1;
  101. return 0;
  102. }
  103. static inline int get_bs_b(vector_t *mvP, vector_t *mvQ) {
  104. if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA)) {
  105. return 2;
  106. } else {
  107. vector_t *mvPbw = mvP + MV_BWD_OFFS;
  108. vector_t *mvQbw = mvQ + MV_BWD_OFFS;
  109. if( (abs( mvP->x - mvQ->x) >= 4) ||
  110. (abs( mvP->y - mvQ->y) >= 4) ||
  111. (abs(mvPbw->x - mvQbw->x) >= 4) ||
  112. (abs(mvPbw->y - mvQbw->y) >= 4) )
  113. return 1;
  114. }
  115. return 0;
  116. }
  117. #define SET_PARAMS \
  118. alpha = alpha_tab[clip(qp_avg + h->alpha_offset,0,63)]; \
  119. beta = beta_tab[clip(qp_avg + h->beta_offset, 0,63)]; \
  120. tc = tc_tab[clip(qp_avg + h->alpha_offset,0,63)];
  121. /**
  122. * in-loop deblocking filter for a single macroblock
  123. *
  124. * boundary strength (bs) mapping:
  125. *
  126. * --4---5--
  127. * 0 2 |
  128. * | 6 | 7 |
  129. * 1 3 |
  130. * ---------
  131. *
  132. */
  133. static void filter_mb(AVSContext *h, enum mb_t mb_type) {
  134. DECLARE_ALIGNED_8(uint8_t, bs[8]);
  135. int qp_avg, alpha, beta, tc;
  136. int i;
  137. /* save un-deblocked lines */
  138. h->topleft_border_y = h->top_border_y[h->mbx*16+15];
  139. h->topleft_border_u = h->top_border_u[h->mbx*10+8];
  140. h->topleft_border_v = h->top_border_v[h->mbx*10+8];
  141. memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
  142. memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
  143. memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
  144. for(i=0;i<8;i++) {
  145. h->left_border_y[i*2+0] = *(h->cy + 15 + (i*2+0)*h->l_stride);
  146. h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+1)*h->l_stride);
  147. h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
  148. h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
  149. }
  150. if(!h->loop_filter_disable) {
  151. /* clear bs */
  152. *((uint64_t *)bs) = 0;
  153. /* determine bs */
  154. switch(mb_type) {
  155. case I_8X8:
  156. *((uint64_t *)bs) = 0x0202020202020202ULL;
  157. break;
  158. case P_8X8:
  159. case P_8X16:
  160. bs[2] = get_bs_p(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1]);
  161. bs[3] = get_bs_p(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3]);
  162. case P_16X8:
  163. bs[6] = get_bs_p(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2]);
  164. bs[7] = get_bs_p(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3]);
  165. case P_16X16:
  166. case P_SKIP:
  167. bs[0] = get_bs_p(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0]);
  168. bs[1] = get_bs_p(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2]);
  169. bs[4] = get_bs_p(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0]);
  170. bs[5] = get_bs_p(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1]);
  171. break;
  172. case B_SKIP:
  173. case B_DIRECT:
  174. case B_8X8:
  175. bs[2] = get_bs_b(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1]);
  176. bs[3] = get_bs_b(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3]);
  177. bs[6] = get_bs_b(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2]);
  178. bs[7] = get_bs_b(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3]);
  179. case B_FWD_16X16:
  180. case B_BWD_16X16:
  181. case B_SYM_16X16:
  182. bs[0] = get_bs_b(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0]);
  183. bs[1] = get_bs_b(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2]);
  184. bs[4] = get_bs_b(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0]);
  185. bs[5] = get_bs_b(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1]);
  186. break;
  187. default:
  188. if(mb_type & 1) { //16X8
  189. bs[6] = bs[7] = get_bs_b(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2]);
  190. } else { //8X16
  191. bs[2] = bs[3] = get_bs_b(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1]);
  192. }
  193. bs[0] = get_bs_b(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0]);
  194. bs[1] = get_bs_b(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2]);
  195. bs[4] = get_bs_b(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0]);
  196. bs[5] = get_bs_b(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1]);
  197. }
  198. if( *((uint64_t *)bs) ) {
  199. if(h->flags & A_AVAIL) {
  200. qp_avg = (h->qp + h->left_qp + 1) >> 1;
  201. SET_PARAMS;
  202. h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
  203. h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
  204. h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
  205. }
  206. qp_avg = h->qp;
  207. SET_PARAMS;
  208. h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
  209. h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
  210. bs[6],bs[7]);
  211. if(h->flags & B_AVAIL) {
  212. qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
  213. SET_PARAMS;
  214. h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
  215. h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
  216. h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
  217. }
  218. }
  219. }
  220. h->left_qp = h->qp;
  221. h->top_qp[h->mbx] = h->qp;
  222. }
  223. #undef SET_PARAMS
  224. /*****************************************************************************
  225. *
  226. * spatial intra prediction
  227. *
  228. ****************************************************************************/
  229. static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top,
  230. uint8_t *left, int block) {
  231. int i;
  232. switch(block) {
  233. case 0:
  234. memcpy(&left[1],h->left_border_y,16);
  235. left[0] = left[1];
  236. left[17] = left[16];
  237. memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
  238. top[17] = top[16];
  239. top[0] = top[1];
  240. if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
  241. left[0] = top[0] = h->topleft_border_y;
  242. break;
  243. case 1:
  244. for(i=0;i<8;i++)
  245. left[i+1] = *(h->cy + 7 + i*h->l_stride);
  246. memset(&left[9],left[8],9);
  247. left[0] = left[1];
  248. memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
  249. if(h->flags & C_AVAIL)
  250. memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
  251. else
  252. memset(&top[9],top[8],9);
  253. top[17] = top[16];
  254. top[0] = top[1];
  255. if(h->flags & B_AVAIL)
  256. left[0] = top[0] = h->top_border_y[h->mbx*16+7];
  257. break;
  258. case 2:
  259. memcpy(&left[1],&h->left_border_y[8],8);
  260. memset(&left[9],left[8],9);
  261. memcpy(&top[1],h->cy + 7*h->l_stride,16);
  262. top[17] = top[16];
  263. left[0] = h->left_border_y[7];
  264. top[0] = top[1];
  265. if(h->flags & A_AVAIL)
  266. top[0] = left[0];
  267. break;
  268. case 3:
  269. for(i=0;i<9;i++)
  270. left[i] = *(h->cy + 7 + (i+7)*h->l_stride);
  271. memset(&left[9],left[8],9);
  272. memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
  273. memset(&top[9],top[8],9);
  274. break;
  275. }
  276. }
  277. static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  278. int y;
  279. uint64_t a = *((uint64_t *)(&top[1]));
  280. for(y=0;y<8;y++) {
  281. *((uint64_t *)(d+y*stride)) = a;
  282. }
  283. }
  284. static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  285. int y;
  286. uint64_t a;
  287. for(y=0;y<8;y++) {
  288. a = left[y+1] * 0x0101010101010101ULL;
  289. *((uint64_t *)(d+y*stride)) = a;
  290. }
  291. }
  292. static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  293. int y;
  294. uint64_t a = 0x8080808080808080ULL;
  295. for(y=0;y<8;y++)
  296. *((uint64_t *)(d+y*stride)) = a;
  297. }
  298. static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  299. int x,y,ia;
  300. int ih = 0;
  301. int iv = 0;
  302. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  303. for(x=0; x<4; x++) {
  304. ih += (x+1)*(top[5+x]-top[3-x]);
  305. iv += (x+1)*(left[5+x]-left[3-x]);
  306. }
  307. ia = (top[8]+left[8])<<4;
  308. ih = (17*ih+16)>>5;
  309. iv = (17*iv+16)>>5;
  310. for(y=0; y<8; y++)
  311. for(x=0; x<8; x++)
  312. d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
  313. }
  314. #define LOWPASS(ARRAY,INDEX) \
  315. (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
  316. static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  317. int x,y;
  318. for(y=0; y<8; y++)
  319. for(x=0; x<8; x++)
  320. d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
  321. }
  322. static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  323. int x,y;
  324. for(y=0; y<8; y++)
  325. for(x=0; x<8; x++)
  326. d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
  327. }
  328. static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  329. int x,y;
  330. for(y=0; y<8; y++)
  331. for(x=0; x<8; x++)
  332. if(x==y)
  333. d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
  334. else if(x>y)
  335. d[y*stride+x] = LOWPASS(top,x-y);
  336. else
  337. d[y*stride+x] = LOWPASS(left,y-x);
  338. }
  339. static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  340. int x,y;
  341. for(y=0; y<8; y++)
  342. for(x=0; x<8; x++)
  343. d[y*stride+x] = LOWPASS(left,y+1);
  344. }
  345. static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  346. int x,y;
  347. for(y=0; y<8; y++)
  348. for(x=0; x<8; x++)
  349. d[y*stride+x] = LOWPASS(top,x+1);
  350. }
  351. #undef LOWPASS
  352. static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
  353. *mode = mod_table[*mode];
  354. if(*mode < 0) {
  355. av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
  356. *mode = 0;
  357. }
  358. }
  359. /*****************************************************************************
  360. *
  361. * motion compensation
  362. *
  363. ****************************************************************************/
  364. static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
  365. int chroma_height,int delta,int list,uint8_t *dest_y,
  366. uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
  367. int src_y_offset,qpel_mc_func *qpix_op,
  368. h264_chroma_mc_func chroma_op,vector_t *mv){
  369. MpegEncContext * const s = &h->s;
  370. const int mx= mv->x + src_x_offset*8;
  371. const int my= mv->y + src_y_offset*8;
  372. const int luma_xy= (mx&3) + ((my&3)<<2);
  373. uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
  374. uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
  375. uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
  376. int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
  377. int extra_height= extra_width;
  378. int emu=0;
  379. const int full_mx= mx>>2;
  380. const int full_my= my>>2;
  381. const int pic_width = 16*h->mb_width;
  382. const int pic_height = 16*h->mb_height;
  383. if(!pic->data[0])
  384. return;
  385. if(mx&7) extra_width -= 3;
  386. if(my&7) extra_height -= 3;
  387. if( full_mx < 0-extra_width
  388. || full_my < 0-extra_height
  389. || full_mx + 16/*FIXME*/ > pic_width + extra_width
  390. || full_my + 16/*FIXME*/ > pic_height + extra_height){
  391. ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
  392. 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
  393. src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
  394. emu=1;
  395. }
  396. qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
  397. if(!square){
  398. qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
  399. }
  400. if(emu){
  401. ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
  402. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  403. src_cb= s->edge_emu_buffer;
  404. }
  405. chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
  406. if(emu){
  407. ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
  408. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  409. src_cr= s->edge_emu_buffer;
  410. }
  411. chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
  412. }
  413. static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
  414. uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
  415. int x_offset, int y_offset,qpel_mc_func *qpix_put,
  416. h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
  417. h264_chroma_mc_func chroma_avg, vector_t *mv){
  418. qpel_mc_func *qpix_op= qpix_put;
  419. h264_chroma_mc_func chroma_op= chroma_put;
  420. dest_y += 2*x_offset + 2*y_offset*h->l_stride;
  421. dest_cb += x_offset + y_offset*h->c_stride;
  422. dest_cr += x_offset + y_offset*h->c_stride;
  423. x_offset += 8*h->mbx;
  424. y_offset += 8*h->mby;
  425. if(mv->ref >= 0){
  426. Picture *ref= &h->DPB[mv->ref];
  427. mc_dir_part(h, ref, square, chroma_height, delta, 0,
  428. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  429. qpix_op, chroma_op, mv);
  430. qpix_op= qpix_avg;
  431. chroma_op= chroma_avg;
  432. }
  433. if((mv+MV_BWD_OFFS)->ref >= 0){
  434. Picture *ref= &h->DPB[0];
  435. mc_dir_part(h, ref, square, chroma_height, delta, 1,
  436. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  437. qpix_op, chroma_op, mv+MV_BWD_OFFS);
  438. }
  439. }
  440. static void inter_pred(AVSContext *h) {
  441. /* always do 8x8 blocks TODO: are larger blocks worth it? */
  442. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
  443. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  444. h->s.dsp.put_h264_chroma_pixels_tab[1],
  445. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  446. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
  447. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
  448. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  449. h->s.dsp.put_h264_chroma_pixels_tab[1],
  450. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  451. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
  452. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
  453. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  454. h->s.dsp.put_h264_chroma_pixels_tab[1],
  455. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  456. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
  457. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
  458. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  459. h->s.dsp.put_h264_chroma_pixels_tab[1],
  460. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  461. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
  462. /* set intra prediction modes to default values */
  463. h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
  464. h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
  465. }
  466. /*****************************************************************************
  467. *
  468. * motion vector prediction
  469. *
  470. ****************************************************************************/
  471. static inline void set_mvs(vector_t *mv, enum block_t size) {
  472. switch(size) {
  473. case BLK_16X16:
  474. mv[MV_STRIDE ] = mv[0];
  475. mv[MV_STRIDE+1] = mv[0];
  476. case BLK_16X8:
  477. mv[1] = mv[0];
  478. break;
  479. case BLK_8X16:
  480. mv[MV_STRIDE] = mv[0];
  481. break;
  482. }
  483. }
  484. static inline void store_mvs(AVSContext *h) {
  485. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0];
  486. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1];
  487. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2];
  488. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
  489. }
  490. static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
  491. int den = h->scale_den[src->ref];
  492. *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
  493. *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
  494. }
  495. static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
  496. int ax, ay, bx, by, cx, cy;
  497. int len_ab, len_bc, len_ca, len_mid;
  498. /* scale candidates according to their temporal span */
  499. scale_mv(h, &ax, &ay, mvA, mvP->dist);
  500. scale_mv(h, &bx, &by, mvB, mvP->dist);
  501. scale_mv(h, &cx, &cy, mvC, mvP->dist);
  502. /* find the geometrical median of the three candidates */
  503. len_ab = abs(ax - bx) + abs(ay - by);
  504. len_bc = abs(bx - cx) + abs(by - cy);
  505. len_ca = abs(cx - ax) + abs(cy - ay);
  506. len_mid = mid_pred(len_ab, len_bc, len_ca);
  507. if(len_mid == len_ab) {
  508. mvP->x = cx;
  509. mvP->y = cy;
  510. } else if(len_mid == len_bc) {
  511. mvP->x = ax;
  512. mvP->y = ay;
  513. } else {
  514. mvP->x = bx;
  515. mvP->y = by;
  516. }
  517. }
  518. static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
  519. vector_t *col_mv) {
  520. vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS;
  521. int den = h->direct_den[col_mv->ref];
  522. int m = col_mv->x >> 31;
  523. pmv_fw->dist = h->dist[1];
  524. pmv_bw->dist = h->dist[0];
  525. pmv_fw->ref = 1;
  526. pmv_bw->ref = 0;
  527. /* scale the co-located motion vector according to its temporal span */
  528. pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m;
  529. pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m);
  530. m = col_mv->y >> 31;
  531. pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m;
  532. pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m);
  533. }
  534. static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) {
  535. vector_t *dst = src + MV_BWD_OFFS;
  536. /* backward mv is the scaled and negated forward mv */
  537. dst->x = -((src->x * h->sym_factor + 256) >> 9);
  538. dst->y = -((src->y * h->sym_factor + 256) >> 9);
  539. dst->ref = 0;
  540. dst->dist = h->dist[0];
  541. set_mvs(dst, size);
  542. }
  543. static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
  544. enum mv_pred_t mode, enum block_t size, int ref) {
  545. vector_t *mvP = &h->mv[nP];
  546. vector_t *mvA = &h->mv[nP-1];
  547. vector_t *mvB = &h->mv[nP-4];
  548. vector_t *mvC = &h->mv[nC];
  549. int mvAref = mvA->ref;
  550. int mvBref = mvB->ref;
  551. int mvCref;
  552. mvP->ref = ref;
  553. mvP->dist = h->dist[mvP->ref];
  554. if(mvC->ref == NOT_AVAIL)
  555. mvC = &h->mv[nP-5]; // set to top-left (mvD)
  556. mvCref = mvC->ref;
  557. if(mode == MV_PRED_PSKIP) {
  558. if((mvAref == NOT_AVAIL) || (mvBref == NOT_AVAIL) ||
  559. ((mvA->x | mvA->y | mvA->ref) == 0) ||
  560. ((mvB->x | mvB->y | mvB->ref) == 0) ) {
  561. mvP->x = mvP->y = 0;
  562. set_mvs(mvP,size);
  563. return;
  564. }
  565. }
  566. /* if there is only one suitable candidate, take it */
  567. if((mvAref >= 0) && (mvBref < 0) && (mvCref < 0)) {
  568. mvP->x = mvA->x;
  569. mvP->y = mvA->y;
  570. } else if((mvAref < 0) && (mvBref >= 0) && (mvCref < 0)) {
  571. mvP->x = mvB->x;
  572. mvP->y = mvB->y;
  573. } else if((mvAref < 0) && (mvBref < 0) && (mvCref >= 0)) {
  574. mvP->x = mvC->x;
  575. mvP->y = mvC->y;
  576. } else {
  577. switch(mode) {
  578. case MV_PRED_LEFT:
  579. if(mvAref == mvP->ref) {
  580. mvP->x = mvA->x;
  581. mvP->y = mvA->y;
  582. } else
  583. mv_pred_median(h, mvP, mvA, mvB, mvC);
  584. break;
  585. case MV_PRED_TOP:
  586. if(mvBref == mvP->ref) {
  587. mvP->x = mvB->x;
  588. mvP->y = mvB->y;
  589. } else
  590. mv_pred_median(h, mvP, mvA, mvB, mvC);
  591. break;
  592. case MV_PRED_TOPRIGHT:
  593. if(mvCref == mvP->ref) {
  594. mvP->x = mvC->x;
  595. mvP->y = mvC->y;
  596. } else
  597. mv_pred_median(h, mvP, mvA, mvB, mvC);
  598. break;
  599. default:
  600. mv_pred_median(h, mvP, mvA, mvB, mvC);
  601. break;
  602. }
  603. }
  604. if(mode < MV_PRED_PSKIP) {
  605. mvP->x += get_se_golomb(&h->s.gb);
  606. mvP->y += get_se_golomb(&h->s.gb);
  607. }
  608. set_mvs(mvP,size);
  609. }
  610. /*****************************************************************************
  611. *
  612. * residual data decoding
  613. *
  614. ****************************************************************************/
  615. /** kth-order exponential golomb code */
  616. static inline int get_ue_code(GetBitContext *gb, int order) {
  617. if(order) {
  618. int ret = get_ue_golomb(gb) << order;
  619. return ret + get_bits(gb,order);
  620. }
  621. return get_ue_golomb(gb);
  622. }
  623. /**
  624. * decode coefficients from one 8x8 block, dequantize, inverse transform
  625. * and add them to sample block
  626. * @param r pointer to 2D VLC table
  627. * @param esc_golomb_order escape codes are k-golomb with this order k
  628. * @param qp quantizer
  629. * @param dst location of sample block
  630. * @param stride line stride in frame buffer
  631. */
  632. static int decode_residual_block(AVSContext *h, GetBitContext *gb,
  633. const residual_vlc_t *r, int esc_golomb_order,
  634. int qp, uint8_t *dst, int stride) {
  635. int i,pos = -1;
  636. int level_code, esc_code, level, run, mask;
  637. int level_buf[64];
  638. int run_buf[64];
  639. int dqm = dequant_mul[qp];
  640. int dqs = dequant_shift[qp];
  641. int dqa = 1 << (dqs - 1);
  642. const uint8_t *scantab = ff_zigzag_direct;
  643. DCTELEM block[64];
  644. memset(block,0,64*sizeof(DCTELEM));
  645. for(i=0;i<65;i++) {
  646. level_code = get_ue_code(gb,r->golomb_order);
  647. if(level_code >= ESCAPE_CODE) {
  648. run = (level_code - ESCAPE_CODE) >> 1;
  649. esc_code = get_ue_code(gb,esc_golomb_order);
  650. level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
  651. while(level > r->inc_limit)
  652. r++;
  653. mask = -(level_code & 1);
  654. level = (level^mask) - mask;
  655. } else {
  656. if(level_code < 0)
  657. return -1;
  658. level = r->rltab[level_code][0];
  659. if(!level) //end of block signal
  660. break;
  661. run = r->rltab[level_code][1];
  662. r += r->rltab[level_code][2];
  663. }
  664. level_buf[i] = level;
  665. run_buf[i] = run;
  666. }
  667. /* inverse scan and dequantization */
  668. while(--i >= 0){
  669. pos += 1 + run_buf[i];
  670. if(pos > 63) {
  671. av_log(h->s.avctx, AV_LOG_ERROR,
  672. "position out of block bounds at pic %d MB(%d,%d)\n",
  673. h->picture.poc, h->mbx, h->mby);
  674. return -1;
  675. }
  676. block[scantab[pos]] = (level_buf[i]*dqm + dqa) >> dqs;
  677. }
  678. h->s.dsp.cavs_idct8_add(dst,block,stride);
  679. return 0;
  680. }
  681. static inline void decode_residual_chroma(AVSContext *h) {
  682. if(h->cbp & (1<<4))
  683. decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
  684. h->cu,h->c_stride);
  685. if(h->cbp & (1<<5))
  686. decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
  687. h->cv,h->c_stride);
  688. }
  689. static inline int decode_residual_inter(AVSContext *h) {
  690. int block;
  691. /* get coded block pattern */
  692. int cbp= get_ue_golomb(&h->s.gb);
  693. if(cbp > 63){
  694. av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
  695. return -1;
  696. }
  697. h->cbp = cbp_tab[cbp][1];
  698. /* get quantizer */
  699. if(h->cbp && !h->qp_fixed)
  700. h->qp += get_se_golomb(&h->s.gb);
  701. for(block=0;block<4;block++)
  702. if(h->cbp & (1<<block))
  703. decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
  704. h->cy + h->luma_scan[block], h->l_stride);
  705. decode_residual_chroma(h);
  706. return 0;
  707. }
  708. /*****************************************************************************
  709. *
  710. * macroblock level
  711. *
  712. ****************************************************************************/
  713. /**
  714. * initialise predictors for motion vectors and intra prediction
  715. */
  716. static inline void init_mb(AVSContext *h) {
  717. int i;
  718. /* copy predictors from top line (MB B and C) into cache */
  719. for(i=0;i<3;i++) {
  720. h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
  721. h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
  722. }
  723. h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
  724. h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
  725. /* clear top predictors if MB B is not available */
  726. if(!(h->flags & B_AVAIL)) {
  727. h->mv[MV_FWD_B2] = un_mv;
  728. h->mv[MV_FWD_B3] = un_mv;
  729. h->mv[MV_BWD_B2] = un_mv;
  730. h->mv[MV_BWD_B3] = un_mv;
  731. h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
  732. h->flags &= ~(C_AVAIL|D_AVAIL);
  733. } else if(h->mbx) {
  734. h->flags |= D_AVAIL;
  735. }
  736. if(h->mbx == h->mb_width-1) //MB C not available
  737. h->flags &= ~C_AVAIL;
  738. /* clear top-right predictors if MB C is not available */
  739. if(!(h->flags & C_AVAIL)) {
  740. h->mv[MV_FWD_C2] = un_mv;
  741. h->mv[MV_BWD_C2] = un_mv;
  742. }
  743. /* clear top-left predictors if MB D is not available */
  744. if(!(h->flags & D_AVAIL)) {
  745. h->mv[MV_FWD_D3] = un_mv;
  746. h->mv[MV_BWD_D3] = un_mv;
  747. }
  748. /* set pointer for co-located macroblock type */
  749. h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
  750. }
  751. static inline void check_for_slice(AVSContext *h);
  752. /**
  753. * save predictors for later macroblocks and increase
  754. * macroblock address
  755. * @returns 0 if end of frame is reached, 1 otherwise
  756. */
  757. static inline int next_mb(AVSContext *h) {
  758. int i;
  759. h->flags |= A_AVAIL;
  760. h->cy += 16;
  761. h->cu += 8;
  762. h->cv += 8;
  763. /* copy mvs as predictors to the left */
  764. for(i=0;i<=20;i+=4)
  765. h->mv[i] = h->mv[i+2];
  766. /* copy bottom mvs from cache to top line */
  767. h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
  768. h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
  769. h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
  770. h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
  771. /* next MB address */
  772. h->mbx++;
  773. if(h->mbx == h->mb_width) { //new mb line
  774. h->flags = B_AVAIL|C_AVAIL;
  775. /* clear left pred_modes */
  776. h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
  777. /* clear left mv predictors */
  778. for(i=0;i<=20;i+=4)
  779. h->mv[i] = un_mv;
  780. h->mbx = 0;
  781. h->mby++;
  782. /* re-calculate sample pointers */
  783. h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
  784. h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
  785. h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
  786. if(h->mby == h->mb_height) { //frame end
  787. return 0;
  788. } else {
  789. //check_for_slice(h);
  790. }
  791. }
  792. return 1;
  793. }
  794. static int decode_mb_i(AVSContext *h, int cbp_code) {
  795. GetBitContext *gb = &h->s.gb;
  796. int block, pred_mode_uv;
  797. uint8_t top[18];
  798. uint8_t left[18];
  799. uint8_t *d;
  800. init_mb(h);
  801. /* get intra prediction modes from stream */
  802. for(block=0;block<4;block++) {
  803. int nA,nB,predpred;
  804. int pos = scan3x3[block];
  805. nA = h->pred_mode_Y[pos-1];
  806. nB = h->pred_mode_Y[pos-3];
  807. predpred = FFMIN(nA,nB);
  808. if(predpred == NOT_AVAIL) // if either is not available
  809. predpred = INTRA_L_LP;
  810. if(!get_bits1(gb)){
  811. int rem_mode= get_bits(gb, 2);
  812. predpred = rem_mode + (rem_mode >= predpred);
  813. }
  814. h->pred_mode_Y[pos] = predpred;
  815. }
  816. pred_mode_uv = get_ue_golomb(gb);
  817. if(pred_mode_uv > 6) {
  818. av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
  819. return -1;
  820. }
  821. /* save pred modes before they get modified */
  822. h->pred_mode_Y[3] = h->pred_mode_Y[5];
  823. h->pred_mode_Y[6] = h->pred_mode_Y[8];
  824. h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
  825. h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
  826. /* modify pred modes according to availability of neighbour samples */
  827. if(!(h->flags & A_AVAIL)) {
  828. modify_pred(left_modifier_l, &h->pred_mode_Y[4] );
  829. modify_pred(left_modifier_l, &h->pred_mode_Y[7] );
  830. modify_pred(left_modifier_c, &pred_mode_uv );
  831. }
  832. if(!(h->flags & B_AVAIL)) {
  833. modify_pred(top_modifier_l, &h->pred_mode_Y[4] );
  834. modify_pred(top_modifier_l, &h->pred_mode_Y[5] );
  835. modify_pred(top_modifier_c, &pred_mode_uv );
  836. }
  837. /* get coded block pattern */
  838. if(h->pic_type == FF_I_TYPE)
  839. cbp_code = get_ue_golomb(gb);
  840. if(cbp_code > 63){
  841. av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
  842. return -1;
  843. }
  844. h->cbp = cbp_tab[cbp_code][0];
  845. if(h->cbp && !h->qp_fixed)
  846. h->qp += get_se_golomb(gb); //qp_delta
  847. /* luma intra prediction interleaved with residual decode/transform/add */
  848. for(block=0;block<4;block++) {
  849. d = h->cy + h->luma_scan[block];
  850. load_intra_pred_luma(h, top, left, block);
  851. h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
  852. (d, top, left, h->l_stride);
  853. if(h->cbp & (1<<block))
  854. decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride);
  855. }
  856. /* chroma intra prediction */
  857. /* extend borders by one pixel */
  858. h->left_border_u[9] = h->left_border_u[8];
  859. h->left_border_v[9] = h->left_border_v[8];
  860. h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
  861. h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
  862. if(h->mbx && h->mby) {
  863. h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
  864. h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
  865. } else {
  866. h->left_border_u[0] = h->left_border_u[1];
  867. h->left_border_v[0] = h->left_border_v[1];
  868. h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
  869. h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
  870. }
  871. h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
  872. h->left_border_u, h->c_stride);
  873. h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
  874. h->left_border_v, h->c_stride);
  875. decode_residual_chroma(h);
  876. filter_mb(h,I_8X8);
  877. /* mark motion vectors as intra */
  878. h->mv[MV_FWD_X0] = intra_mv;
  879. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  880. h->mv[MV_BWD_X0] = intra_mv;
  881. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  882. if(h->pic_type != FF_B_TYPE)
  883. *h->col_type = I_8X8;
  884. return 0;
  885. }
  886. static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
  887. GetBitContext *gb = &h->s.gb;
  888. int ref[4];
  889. init_mb(h);
  890. switch(mb_type) {
  891. case P_SKIP:
  892. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
  893. break;
  894. case P_16X16:
  895. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  896. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]);
  897. break;
  898. case P_16X8:
  899. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  900. ref[2] = h->ref_flag ? 0 : get_bits1(gb);
  901. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
  902. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
  903. break;
  904. case P_8X16:
  905. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  906. ref[1] = h->ref_flag ? 0 : get_bits1(gb);
  907. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
  908. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]);
  909. break;
  910. case P_8X8:
  911. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  912. ref[1] = h->ref_flag ? 0 : get_bits1(gb);
  913. ref[2] = h->ref_flag ? 0 : get_bits1(gb);
  914. ref[3] = h->ref_flag ? 0 : get_bits1(gb);
  915. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
  916. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
  917. mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
  918. mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
  919. }
  920. inter_pred(h);
  921. store_mvs(h);
  922. if(mb_type != P_SKIP)
  923. decode_residual_inter(h);
  924. filter_mb(h,mb_type);
  925. *h->col_type = mb_type;
  926. }
  927. static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
  928. int block;
  929. enum sub_mb_t sub_type[4];
  930. int flags;
  931. init_mb(h);
  932. /* reset all MVs */
  933. h->mv[MV_FWD_X0] = dir_mv;
  934. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  935. h->mv[MV_BWD_X0] = dir_mv;
  936. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  937. switch(mb_type) {
  938. case B_SKIP:
  939. case B_DIRECT:
  940. if(!(*h->col_type)) {
  941. /* intra MB at co-location, do in-plane prediction */
  942. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
  943. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
  944. } else
  945. /* direct prediction from co-located P MB, block-wise */
  946. for(block=0;block<4;block++)
  947. mv_pred_direct(h,&h->mv[mv_scan[block]],
  948. &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
  949. break;
  950. case B_FWD_16X16:
  951. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
  952. break;
  953. case B_SYM_16X16:
  954. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
  955. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
  956. break;
  957. case B_BWD_16X16:
  958. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
  959. break;
  960. case B_8X8:
  961. for(block=0;block<4;block++)
  962. sub_type[block] = get_bits(&h->s.gb,2);
  963. for(block=0;block<4;block++) {
  964. switch(sub_type[block]) {
  965. case B_SUB_DIRECT:
  966. if(!(*h->col_type)) {
  967. /* intra MB at co-location, do in-plane prediction */
  968. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  969. MV_PRED_BSKIP, BLK_8X8, 1);
  970. mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
  971. mv_scan[block]-3+MV_BWD_OFFS,
  972. MV_PRED_BSKIP, BLK_8X8, 0);
  973. } else
  974. mv_pred_direct(h,&h->mv[mv_scan[block]],
  975. &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
  976. break;
  977. case B_SUB_FWD:
  978. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  979. MV_PRED_MEDIAN, BLK_8X8, 1);
  980. break;
  981. case B_SUB_SYM:
  982. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  983. MV_PRED_MEDIAN, BLK_8X8, 1);
  984. mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
  985. break;
  986. }
  987. }
  988. for(block=0;block<4;block++) {
  989. if(sub_type[block] == B_SUB_BWD)
  990. mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
  991. mv_scan[block]+MV_BWD_OFFS-3,
  992. MV_PRED_MEDIAN, BLK_8X8, 0);
  993. }
  994. break;
  995. default:
  996. assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
  997. flags = b_partition_flags[(mb_type-1)>>1];
  998. if(mb_type & 1) { /* 16x8 macroblock types */
  999. if(flags & FWD0)
  1000. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
  1001. if(flags & SYM0) {
  1002. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
  1003. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
  1004. }
  1005. if(flags & FWD1)
  1006. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
  1007. if(flags & SYM1) {
  1008. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
  1009. mv_pred_sym(h, &h->mv[9], BLK_16X8);
  1010. }
  1011. if(flags & BWD0)
  1012. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
  1013. if(flags & BWD1)
  1014. mv_pred(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
  1015. } else { /* 8x16 macroblock types */
  1016. if(flags & FWD0)
  1017. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
  1018. if(flags & SYM0) {
  1019. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
  1020. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
  1021. }
  1022. if(flags & FWD1)
  1023. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
  1024. if(flags & SYM1) {
  1025. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
  1026. mv_pred_sym(h, &h->mv[6], BLK_8X16);
  1027. }
  1028. if(flags & BWD0)
  1029. mv_pred(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
  1030. if(flags & BWD1)
  1031. mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0);
  1032. }
  1033. }
  1034. inter_pred(h);
  1035. if(mb_type != B_SKIP)
  1036. decode_residual_inter(h);
  1037. filter_mb(h,mb_type);
  1038. }
  1039. /*****************************************************************************
  1040. *
  1041. * slice level
  1042. *
  1043. ****************************************************************************/
  1044. static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) {
  1045. if(h->stc > 0xAF)
  1046. av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
  1047. h->mby = h->stc;
  1048. if((h->mby == 0) && (!h->qp_fixed)){
  1049. h->qp_fixed = get_bits1(gb);
  1050. h->qp = get_bits(gb,6);
  1051. }
  1052. /* inter frame or second slice can have weighting params */
  1053. if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2))
  1054. if(get_bits1(gb)) { //slice_weighting_flag
  1055. av_log(h->s.avctx, AV_LOG_ERROR,
  1056. "weighted prediction not yet supported\n");
  1057. }
  1058. return 0;
  1059. }
  1060. static inline void check_for_slice(AVSContext *h) {
  1061. GetBitContext *gb = &h->s.gb;
  1062. int align;
  1063. align = (-get_bits_count(gb)) & 7;
  1064. if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
  1065. get_bits_long(gb,24+align);
  1066. h->stc = get_bits(gb,8);
  1067. decode_slice_header(h,gb);
  1068. }
  1069. }
  1070. /*****************************************************************************
  1071. *
  1072. * frame level
  1073. *
  1074. ****************************************************************************/
  1075. static void init_pic(AVSContext *h) {
  1076. int i;
  1077. /* clear some predictors */
  1078. for(i=0;i<=20;i+=4)
  1079. h->mv[i] = un_mv;
  1080. h->mv[MV_BWD_X0] = dir_mv;
  1081. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  1082. h->mv[MV_FWD_X0] = dir_mv;
  1083. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  1084. h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
  1085. h->cy = h->picture.data[0];
  1086. h->cu = h->picture.data[1];
  1087. h->cv = h->picture.data[2];
  1088. h->l_stride = h->picture.linesize[0];
  1089. h->c_stride = h->picture.linesize[1];
  1090. h->luma_scan[2] = 8*h->l_stride;
  1091. h->luma_scan[3] = 8*h->l_stride+8;
  1092. h->mbx = h->mby = 0;
  1093. h->flags = 0;
  1094. }
  1095. static int decode_pic(AVSContext *h) {
  1096. MpegEncContext *s = &h->s;
  1097. int skip_count;
  1098. enum mb_t mb_type;
  1099. if (!s->context_initialized) {
  1100. if (MPV_common_init(s) < 0)
  1101. return -1;
  1102. }
  1103. get_bits(&s->gb,16);//bbv_dwlay
  1104. if(h->stc == PIC_PB_START_CODE) {
  1105. h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE;
  1106. /* make sure we have the reference frames we need */
  1107. if(!h->DPB[0].data[0] ||
  1108. (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE))
  1109. return -1;
  1110. } else {
  1111. h->pic_type = FF_I_TYPE;
  1112. if(get_bits1(&s->gb))
  1113. get_bits(&s->gb,16);//time_code
  1114. }
  1115. /* release last B frame */
  1116. if(h->picture.data[0])
  1117. s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
  1118. s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
  1119. init_pic(h);
  1120. h->picture.poc = get_bits(&s->gb,8)*2;
  1121. /* get temporal distances and MV scaling factors */
  1122. if(h->pic_type != FF_B_TYPE) {
  1123. h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512;
  1124. } else {
  1125. h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512;
  1126. }
  1127. h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512;
  1128. h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
  1129. h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
  1130. if(h->pic_type == FF_B_TYPE) {
  1131. h->sym_factor = h->dist[0]*h->scale_den[1];
  1132. } else {
  1133. h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0;
  1134. h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0;
  1135. }
  1136. if(s->low_delay)
  1137. get_ue_golomb(&s->gb); //bbv_check_times
  1138. h->progressive = get_bits1(&s->gb);
  1139. if(h->progressive)
  1140. h->pic_structure = 1;
  1141. else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) )
  1142. get_bits1(&s->gb); //advanced_pred_mode_disable
  1143. skip_bits1(&s->gb); //top_field_first
  1144. skip_bits1(&s->gb); //repeat_first_field
  1145. h->qp_fixed = get_bits1(&s->gb);
  1146. h->qp = get_bits(&s->gb,6);
  1147. if(h->pic_type == FF_I_TYPE) {
  1148. if(!h->progressive && !h->pic_structure)
  1149. skip_bits1(&s->gb);//what is this?
  1150. skip_bits(&s->gb,4); //reserved bits
  1151. } else {
  1152. if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1))
  1153. h->ref_flag = get_bits1(&s->gb);
  1154. skip_bits(&s->gb,4); //reserved bits
  1155. h->skip_mode_flag = get_bits1(&s->gb);
  1156. }
  1157. h->loop_filter_disable = get_bits1(&s->gb);
  1158. if(!h->loop_filter_disable && get_bits1(&s->gb)) {
  1159. h->alpha_offset = get_se_golomb(&s->gb);
  1160. h->beta_offset = get_se_golomb(&s->gb);
  1161. } else {
  1162. h->alpha_offset = h->beta_offset = 0;
  1163. }
  1164. check_for_slice(h);
  1165. if(h->pic_type == FF_I_TYPE) {
  1166. do {
  1167. decode_mb_i(h, 0);
  1168. } while(next_mb(h));
  1169. } else if(h->pic_type == FF_P_TYPE) {
  1170. do {
  1171. if(h->skip_mode_flag) {
  1172. skip_count = get_ue_golomb(&s->gb);
  1173. while(skip_count--) {
  1174. decode_mb_p(h,P_SKIP);
  1175. if(!next_mb(h))
  1176. goto done;
  1177. }
  1178. mb_type = get_ue_golomb(&s->gb) + P_16X16;
  1179. } else
  1180. mb_type = get_ue_golomb(&s->gb) + P_SKIP;
  1181. if(mb_type > P_8X8) {
  1182. decode_mb_i(h, mb_type - P_8X8 - 1);
  1183. } else
  1184. decode_mb_p(h,mb_type);
  1185. } while(next_mb(h));
  1186. } else { /* FF_B_TYPE */
  1187. do {
  1188. if(h->skip_mode_flag) {
  1189. skip_count = get_ue_golomb(&s->gb);
  1190. while(skip_count--) {
  1191. decode_mb_b(h,B_SKIP);
  1192. if(!next_mb(h))
  1193. goto done;
  1194. }
  1195. mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
  1196. } else
  1197. mb_type = get_ue_golomb(&s->gb) + B_SKIP;
  1198. if(mb_type > B_8X8) {
  1199. decode_mb_i(h, mb_type - B_8X8 - 1);
  1200. } else
  1201. decode_mb_b(h,mb_type);
  1202. } while(next_mb(h));
  1203. }
  1204. done:
  1205. if(h->pic_type != FF_B_TYPE) {
  1206. if(h->DPB[1].data[0])
  1207. s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
  1208. memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture));
  1209. memcpy(&h->DPB[0], &h->picture, sizeof(Picture));
  1210. memset(&h->picture,0,sizeof(Picture));
  1211. }
  1212. return 0;
  1213. }
  1214. /*****************************************************************************
  1215. *
  1216. * headers and interface
  1217. *
  1218. ****************************************************************************/
  1219. /**
  1220. * some predictions require data from the top-neighbouring macroblock.
  1221. * this data has to be stored for one complete row of macroblocks
  1222. * and this storage space is allocated here
  1223. */
  1224. static void init_top_lines(AVSContext *h) {
  1225. /* alloc top line of predictors */
  1226. h->top_qp = av_malloc( h->mb_width);
  1227. h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  1228. h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  1229. h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
  1230. h->top_border_y = av_malloc((h->mb_width+1)*16);
  1231. h->top_border_u = av_malloc((h->mb_width)*10);
  1232. h->top_border_v = av_malloc((h->mb_width)*10);
  1233. /* alloc space for co-located MVs and types */
  1234. h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
  1235. h->col_type_base = av_malloc(h->mb_width*h->mb_height);
  1236. }
  1237. static int decode_seq_header(AVSContext *h) {
  1238. MpegEncContext *s = &h->s;
  1239. extern const AVRational ff_frame_rate_tab[];
  1240. int frame_rate_code;
  1241. h->profile = get_bits(&s->gb,8);
  1242. h->level = get_bits(&s->gb,8);
  1243. skip_bits1(&s->gb); //progressive sequence
  1244. s->width = get_bits(&s->gb,14);
  1245. s->height = get_bits(&s->gb,14);
  1246. skip_bits(&s->gb,2); //chroma format
  1247. skip_bits(&s->gb,3); //sample_precision
  1248. h->aspect_ratio = get_bits(&s->gb,4);
  1249. frame_rate_code = get_bits(&s->gb,4);
  1250. skip_bits(&s->gb,18);//bit_rate_lower
  1251. skip_bits1(&s->gb); //marker_bit
  1252. skip_bits(&s->gb,12);//bit_rate_upper
  1253. s->low_delay = get_bits1(&s->gb);
  1254. h->mb_width = (s->width + 15) >> 4;
  1255. h->mb_height = (s->height + 15) >> 4;
  1256. h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num;
  1257. h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den;
  1258. h->s.avctx->width = s->width;
  1259. h->s.avctx->height = s->height;
  1260. if(!h->top_qp)
  1261. init_top_lines(h);
  1262. return 0;
  1263. }
  1264. /**
  1265. * finds the end of the current frame in the bitstream.
  1266. * @return the position of the first byte of the next frame, or -1
  1267. */
  1268. int ff_cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) {
  1269. int pic_found, i;
  1270. uint32_t state;
  1271. pic_found= pc->frame_start_found;
  1272. state= pc->state;
  1273. i=0;
  1274. if(!pic_found){
  1275. for(i=0; i<buf_size; i++){
  1276. state= (state<<8) | buf[i];
  1277. if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
  1278. i++;
  1279. pic_found=1;
  1280. break;
  1281. }
  1282. }
  1283. }
  1284. if(pic_found){
  1285. /* EOF considered as end of frame */
  1286. if (buf_size == 0)
  1287. return 0;
  1288. for(; i<buf_size; i++){
  1289. state= (state<<8) | buf[i];
  1290. if((state&0xFFFFFF00) == 0x100){
  1291. if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
  1292. pc->frame_start_found=0;
  1293. pc->state=-1;
  1294. return i-3;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. pc->frame_start_found= pic_found;
  1300. pc->state= state;
  1301. return END_NOT_FOUND;
  1302. }
  1303. void ff_cavs_flush(AVCodecContext * avctx) {
  1304. AVSContext *h = avctx->priv_data;
  1305. h->got_keyframe = 0;
  1306. }
  1307. static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
  1308. uint8_t * buf, int buf_size) {
  1309. AVSContext *h = avctx->priv_data;
  1310. MpegEncContext *s = &h->s;
  1311. int input_size;
  1312. const uint8_t *buf_end;
  1313. const uint8_t *buf_ptr;
  1314. AVFrame *picture = data;
  1315. uint32_t stc;
  1316. s->avctx = avctx;
  1317. if (buf_size == 0) {
  1318. if(!s->low_delay && h->DPB[0].data[0]) {
  1319. *data_size = sizeof(AVPicture);
  1320. *picture = *(AVFrame *) &h->DPB[0];
  1321. }
  1322. return 0;
  1323. }
  1324. buf_ptr = buf;
  1325. buf_end = buf + buf_size;
  1326. for(;;) {
  1327. buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);
  1328. if(stc & 0xFFFFFE00)
  1329. return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
  1330. input_size = (buf_end - buf_ptr)*8;
  1331. switch(stc) {
  1332. case SEQ_START_CODE:
  1333. init_get_bits(&s->gb, buf_ptr, input_size);
  1334. decode_seq_header(h);
  1335. break;
  1336. case PIC_I_START_CODE:
  1337. if(!h->got_keyframe) {
  1338. if(h->DPB[0].data[0])
  1339. avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
  1340. if(h->DPB[1].data[0])
  1341. avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
  1342. h->got_keyframe = 1;
  1343. }
  1344. case PIC_PB_START_CODE:
  1345. *data_size = 0;
  1346. if(!h->got_keyframe)
  1347. break;
  1348. init_get_bits(&s->gb, buf_ptr, input_size);
  1349. h->stc = stc;
  1350. if(decode_pic(h))
  1351. break;
  1352. *data_size = sizeof(AVPicture);
  1353. if(h->pic_type != FF_B_TYPE) {
  1354. if(h->DPB[1].data[0]) {
  1355. *picture = *(AVFrame *) &h->DPB[1];
  1356. } else {
  1357. *data_size = 0;
  1358. }
  1359. } else
  1360. *picture = *(AVFrame *) &h->picture;
  1361. break;
  1362. case EXT_START_CODE:
  1363. //mpeg_decode_extension(avctx,buf_ptr, input_size);
  1364. break;
  1365. case USER_START_CODE:
  1366. //mpeg_decode_user_data(avctx,buf_ptr, input_size);
  1367. break;
  1368. default:
  1369. if (stc >= SLICE_MIN_START_CODE &&
  1370. stc <= SLICE_MAX_START_CODE) {
  1371. init_get_bits(&s->gb, buf_ptr, input_size);
  1372. decode_slice_header(h, &s->gb);
  1373. }
  1374. break;
  1375. }
  1376. }
  1377. }
  1378. static int cavs_decode_init(AVCodecContext * avctx) {
  1379. AVSContext *h = avctx->priv_data;
  1380. MpegEncContext * const s = &h->s;
  1381. MPV_decode_defaults(s);
  1382. s->avctx = avctx;
  1383. avctx->pix_fmt= PIX_FMT_YUV420P;
  1384. h->luma_scan[0] = 0;
  1385. h->luma_scan[1] = 8;
  1386. h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
  1387. h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
  1388. h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
  1389. h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
  1390. h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
  1391. h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
  1392. h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
  1393. h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
  1394. h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
  1395. h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
  1396. h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
  1397. h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
  1398. h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
  1399. h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
  1400. h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
  1401. h->mv[ 7] = un_mv;
  1402. h->mv[19] = un_mv;
  1403. return 0;
  1404. }
  1405. static int cavs_decode_end(AVCodecContext * avctx) {
  1406. AVSContext *h = avctx->priv_data;
  1407. av_free(h->top_qp);
  1408. av_free(h->top_mv[0]);
  1409. av_free(h->top_mv[1]);
  1410. av_free(h->top_pred_Y);
  1411. av_free(h->top_border_y);
  1412. av_free(h->top_border_u);
  1413. av_free(h->top_border_v);
  1414. av_free(h->col_mv);
  1415. av_free(h->col_type_base);
  1416. return 0;
  1417. }
  1418. AVCodec cavs_decoder = {
  1419. "cavs",
  1420. CODEC_TYPE_VIDEO,
  1421. CODEC_ID_CAVS,
  1422. sizeof(AVSContext),
  1423. cavs_decode_init,
  1424. NULL,
  1425. cavs_decode_end,
  1426. cavs_decode_frame,
  1427. CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1428. .flush= ff_cavs_flush,
  1429. };