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.

1549 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. int newmode = mod_table[*mode];
  354. if(newmode < 0) {
  355. av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
  356. *mode = 0;
  357. } else {
  358. *mode = newmode;
  359. }
  360. }
  361. /*****************************************************************************
  362. *
  363. * motion compensation
  364. *
  365. ****************************************************************************/
  366. static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
  367. int chroma_height,int delta,int list,uint8_t *dest_y,
  368. uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
  369. int src_y_offset,qpel_mc_func *qpix_op,
  370. h264_chroma_mc_func chroma_op,vector_t *mv){
  371. MpegEncContext * const s = &h->s;
  372. const int mx= mv->x + src_x_offset*8;
  373. const int my= mv->y + src_y_offset*8;
  374. const int luma_xy= (mx&3) + ((my&3)<<2);
  375. uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
  376. uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
  377. uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
  378. int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
  379. int extra_height= extra_width;
  380. int emu=0;
  381. const int full_mx= mx>>2;
  382. const int full_my= my>>2;
  383. const int pic_width = 16*h->mb_width;
  384. const int pic_height = 16*h->mb_height;
  385. if(!pic->data[0])
  386. return;
  387. if(mx&7) extra_width -= 3;
  388. if(my&7) extra_height -= 3;
  389. if( full_mx < 0-extra_width
  390. || full_my < 0-extra_height
  391. || full_mx + 16/*FIXME*/ > pic_width + extra_width
  392. || full_my + 16/*FIXME*/ > pic_height + extra_height){
  393. ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
  394. 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
  395. src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
  396. emu=1;
  397. }
  398. qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
  399. if(!square){
  400. qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
  401. }
  402. if(emu){
  403. ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
  404. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  405. src_cb= s->edge_emu_buffer;
  406. }
  407. chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
  408. if(emu){
  409. ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
  410. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  411. src_cr= s->edge_emu_buffer;
  412. }
  413. chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
  414. }
  415. static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
  416. uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
  417. int x_offset, int y_offset,qpel_mc_func *qpix_put,
  418. h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
  419. h264_chroma_mc_func chroma_avg, vector_t *mv){
  420. qpel_mc_func *qpix_op= qpix_put;
  421. h264_chroma_mc_func chroma_op= chroma_put;
  422. dest_y += 2*x_offset + 2*y_offset*h->l_stride;
  423. dest_cb += x_offset + y_offset*h->c_stride;
  424. dest_cr += x_offset + y_offset*h->c_stride;
  425. x_offset += 8*h->mbx;
  426. y_offset += 8*h->mby;
  427. if(mv->ref >= 0){
  428. Picture *ref= &h->DPB[mv->ref];
  429. mc_dir_part(h, ref, square, chroma_height, delta, 0,
  430. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  431. qpix_op, chroma_op, mv);
  432. qpix_op= qpix_avg;
  433. chroma_op= chroma_avg;
  434. }
  435. if((mv+MV_BWD_OFFS)->ref >= 0){
  436. Picture *ref= &h->DPB[0];
  437. mc_dir_part(h, ref, square, chroma_height, delta, 1,
  438. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  439. qpix_op, chroma_op, mv+MV_BWD_OFFS);
  440. }
  441. }
  442. static void inter_pred(AVSContext *h) {
  443. /* always do 8x8 blocks TODO: are larger blocks worth it? */
  444. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
  445. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  446. h->s.dsp.put_h264_chroma_pixels_tab[1],
  447. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  448. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
  449. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
  450. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  451. h->s.dsp.put_h264_chroma_pixels_tab[1],
  452. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  453. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
  454. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
  455. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  456. h->s.dsp.put_h264_chroma_pixels_tab[1],
  457. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  458. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
  459. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
  460. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  461. h->s.dsp.put_h264_chroma_pixels_tab[1],
  462. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  463. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
  464. /* set intra prediction modes to default values */
  465. h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
  466. h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
  467. }
  468. /*****************************************************************************
  469. *
  470. * motion vector prediction
  471. *
  472. ****************************************************************************/
  473. static inline void set_mvs(vector_t *mv, enum block_t size) {
  474. switch(size) {
  475. case BLK_16X16:
  476. mv[MV_STRIDE ] = mv[0];
  477. mv[MV_STRIDE+1] = mv[0];
  478. case BLK_16X8:
  479. mv[1] = mv[0];
  480. break;
  481. case BLK_8X16:
  482. mv[MV_STRIDE] = mv[0];
  483. break;
  484. }
  485. }
  486. static inline void store_mvs(AVSContext *h) {
  487. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0];
  488. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1];
  489. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2];
  490. h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3];
  491. }
  492. static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
  493. int den = h->scale_den[src->ref];
  494. *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
  495. *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
  496. }
  497. static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
  498. int ax, ay, bx, by, cx, cy;
  499. int len_ab, len_bc, len_ca, len_mid;
  500. /* scale candidates according to their temporal span */
  501. scale_mv(h, &ax, &ay, mvA, mvP->dist);
  502. scale_mv(h, &bx, &by, mvB, mvP->dist);
  503. scale_mv(h, &cx, &cy, mvC, mvP->dist);
  504. /* find the geometrical median of the three candidates */
  505. len_ab = abs(ax - bx) + abs(ay - by);
  506. len_bc = abs(bx - cx) + abs(by - cy);
  507. len_ca = abs(cx - ax) + abs(cy - ay);
  508. len_mid = mid_pred(len_ab, len_bc, len_ca);
  509. if(len_mid == len_ab) {
  510. mvP->x = cx;
  511. mvP->y = cy;
  512. } else if(len_mid == len_bc) {
  513. mvP->x = ax;
  514. mvP->y = ay;
  515. } else {
  516. mvP->x = bx;
  517. mvP->y = by;
  518. }
  519. }
  520. static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw,
  521. vector_t *col_mv) {
  522. vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS;
  523. int den = h->direct_den[col_mv->ref];
  524. int m = col_mv->x >> 31;
  525. pmv_fw->dist = h->dist[1];
  526. pmv_bw->dist = h->dist[0];
  527. pmv_fw->ref = 1;
  528. pmv_bw->ref = 0;
  529. /* scale the co-located motion vector according to its temporal span */
  530. pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m;
  531. pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m);
  532. m = col_mv->y >> 31;
  533. pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m;
  534. pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m);
  535. }
  536. static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) {
  537. vector_t *dst = src + MV_BWD_OFFS;
  538. /* backward mv is the scaled and negated forward mv */
  539. dst->x = -((src->x * h->sym_factor + 256) >> 9);
  540. dst->y = -((src->y * h->sym_factor + 256) >> 9);
  541. dst->ref = 0;
  542. dst->dist = h->dist[0];
  543. set_mvs(dst, size);
  544. }
  545. static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
  546. enum mv_pred_t mode, enum block_t size, int ref) {
  547. vector_t *mvP = &h->mv[nP];
  548. vector_t *mvA = &h->mv[nP-1];
  549. vector_t *mvB = &h->mv[nP-4];
  550. vector_t *mvC = &h->mv[nC];
  551. int mvAref = mvA->ref;
  552. int mvBref = mvB->ref;
  553. int mvCref;
  554. mvP->ref = ref;
  555. mvP->dist = h->dist[mvP->ref];
  556. if(mvC->ref == NOT_AVAIL)
  557. mvC = &h->mv[nP-5]; // set to top-left (mvD)
  558. mvCref = mvC->ref;
  559. if(mode == MV_PRED_PSKIP) {
  560. if((mvAref == NOT_AVAIL) || (mvBref == NOT_AVAIL) ||
  561. ((mvA->x | mvA->y | mvA->ref) == 0) ||
  562. ((mvB->x | mvB->y | mvB->ref) == 0) ) {
  563. mvP->x = mvP->y = 0;
  564. set_mvs(mvP,size);
  565. return;
  566. }
  567. }
  568. /* if there is only one suitable candidate, take it */
  569. if((mvAref >= 0) && (mvBref < 0) && (mvCref < 0)) {
  570. mvP->x = mvA->x;
  571. mvP->y = mvA->y;
  572. } else if((mvAref < 0) && (mvBref >= 0) && (mvCref < 0)) {
  573. mvP->x = mvB->x;
  574. mvP->y = mvB->y;
  575. } else if((mvAref < 0) && (mvBref < 0) && (mvCref >= 0)) {
  576. mvP->x = mvC->x;
  577. mvP->y = mvC->y;
  578. } else {
  579. switch(mode) {
  580. case MV_PRED_LEFT:
  581. if(mvAref == mvP->ref) {
  582. mvP->x = mvA->x;
  583. mvP->y = mvA->y;
  584. } else
  585. mv_pred_median(h, mvP, mvA, mvB, mvC);
  586. break;
  587. case MV_PRED_TOP:
  588. if(mvBref == mvP->ref) {
  589. mvP->x = mvB->x;
  590. mvP->y = mvB->y;
  591. } else
  592. mv_pred_median(h, mvP, mvA, mvB, mvC);
  593. break;
  594. case MV_PRED_TOPRIGHT:
  595. if(mvCref == mvP->ref) {
  596. mvP->x = mvC->x;
  597. mvP->y = mvC->y;
  598. } else
  599. mv_pred_median(h, mvP, mvA, mvB, mvC);
  600. break;
  601. default:
  602. mv_pred_median(h, mvP, mvA, mvB, mvC);
  603. break;
  604. }
  605. }
  606. if(mode < MV_PRED_PSKIP) {
  607. mvP->x += get_se_golomb(&h->s.gb);
  608. mvP->y += get_se_golomb(&h->s.gb);
  609. }
  610. set_mvs(mvP,size);
  611. }
  612. /*****************************************************************************
  613. *
  614. * residual data decoding
  615. *
  616. ****************************************************************************/
  617. /** kth-order exponential golomb code */
  618. static inline int get_ue_code(GetBitContext *gb, int order) {
  619. if(order) {
  620. int ret = get_ue_golomb(gb) << order;
  621. return ret + get_bits(gb,order);
  622. }
  623. return get_ue_golomb(gb);
  624. }
  625. /**
  626. * decode coefficients from one 8x8 block, dequantize, inverse transform
  627. * and add them to sample block
  628. * @param r pointer to 2D VLC table
  629. * @param esc_golomb_order escape codes are k-golomb with this order k
  630. * @param qp quantizer
  631. * @param dst location of sample block
  632. * @param stride line stride in frame buffer
  633. */
  634. static int decode_residual_block(AVSContext *h, GetBitContext *gb,
  635. const residual_vlc_t *r, int esc_golomb_order,
  636. int qp, uint8_t *dst, int stride) {
  637. int i,pos = -1;
  638. int level_code, esc_code, level, run, mask;
  639. int level_buf[64];
  640. int run_buf[64];
  641. int dqm = dequant_mul[qp];
  642. int dqs = dequant_shift[qp];
  643. int dqa = 1 << (dqs - 1);
  644. const uint8_t *scantab = ff_zigzag_direct;
  645. DCTELEM block[64];
  646. memset(block,0,64*sizeof(DCTELEM));
  647. for(i=0;i<65;i++) {
  648. level_code = get_ue_code(gb,r->golomb_order);
  649. if(level_code >= ESCAPE_CODE) {
  650. run = (level_code - ESCAPE_CODE) >> 1;
  651. esc_code = get_ue_code(gb,esc_golomb_order);
  652. level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
  653. while(level > r->inc_limit)
  654. r++;
  655. mask = -(level_code & 1);
  656. level = (level^mask) - mask;
  657. } else {
  658. if(level_code < 0)
  659. return -1;
  660. level = r->rltab[level_code][0];
  661. if(!level) //end of block signal
  662. break;
  663. run = r->rltab[level_code][1];
  664. r += r->rltab[level_code][2];
  665. }
  666. level_buf[i] = level;
  667. run_buf[i] = run;
  668. }
  669. /* inverse scan and dequantization */
  670. while(--i >= 0){
  671. pos += 1 + run_buf[i];
  672. if(pos > 63) {
  673. av_log(h->s.avctx, AV_LOG_ERROR,
  674. "position out of block bounds at pic %d MB(%d,%d)\n",
  675. h->picture.poc, h->mbx, h->mby);
  676. return -1;
  677. }
  678. block[scantab[pos]] = (level_buf[i]*dqm + dqa) >> dqs;
  679. }
  680. h->s.dsp.cavs_idct8_add(dst,block,stride);
  681. return 0;
  682. }
  683. static inline void decode_residual_chroma(AVSContext *h) {
  684. if(h->cbp & (1<<4))
  685. decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
  686. h->cu,h->c_stride);
  687. if(h->cbp & (1<<5))
  688. decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp],
  689. h->cv,h->c_stride);
  690. }
  691. static inline void decode_residual_inter(AVSContext *h) {
  692. int block;
  693. /* get coded block pattern */
  694. h->cbp = cbp_tab[get_ue_golomb(&h->s.gb)][1];
  695. /* get quantizer */
  696. if(h->cbp && !h->qp_fixed)
  697. h->qp += get_se_golomb(&h->s.gb);
  698. for(block=0;block<4;block++)
  699. if(h->cbp & (1<<block))
  700. decode_residual_block(h,&h->s.gb,inter_2dvlc,0,h->qp,
  701. h->cy + h->luma_scan[block], h->l_stride);
  702. decode_residual_chroma(h);
  703. }
  704. /*****************************************************************************
  705. *
  706. * macroblock level
  707. *
  708. ****************************************************************************/
  709. /**
  710. * initialise predictors for motion vectors and intra prediction
  711. */
  712. static inline void init_mb(AVSContext *h) {
  713. int i;
  714. /* copy predictors from top line (MB B and C) into cache */
  715. for(i=0;i<3;i++) {
  716. h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
  717. h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
  718. }
  719. h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
  720. h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
  721. /* clear top predictors if MB B is not available */
  722. if(!(h->flags & B_AVAIL)) {
  723. h->mv[MV_FWD_B2] = un_mv;
  724. h->mv[MV_FWD_B3] = un_mv;
  725. h->mv[MV_BWD_B2] = un_mv;
  726. h->mv[MV_BWD_B3] = un_mv;
  727. h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
  728. h->flags &= ~(C_AVAIL|D_AVAIL);
  729. } else if(h->mbx) {
  730. h->flags |= D_AVAIL;
  731. }
  732. if(h->mbx == h->mb_width-1) //MB C not available
  733. h->flags &= ~C_AVAIL;
  734. /* clear top-right predictors if MB C is not available */
  735. if(!(h->flags & C_AVAIL)) {
  736. h->mv[MV_FWD_C2] = un_mv;
  737. h->mv[MV_BWD_C2] = un_mv;
  738. }
  739. /* clear top-left predictors if MB D is not available */
  740. if(!(h->flags & D_AVAIL)) {
  741. h->mv[MV_FWD_D3] = un_mv;
  742. h->mv[MV_BWD_D3] = un_mv;
  743. }
  744. /* set pointer for co-located macroblock type */
  745. h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
  746. }
  747. static inline void check_for_slice(AVSContext *h);
  748. /**
  749. * save predictors for later macroblocks and increase
  750. * macroblock address
  751. * @returns 0 if end of frame is reached, 1 otherwise
  752. */
  753. static inline int next_mb(AVSContext *h) {
  754. int i;
  755. h->flags |= A_AVAIL;
  756. h->cy += 16;
  757. h->cu += 8;
  758. h->cv += 8;
  759. /* copy mvs as predictors to the left */
  760. for(i=0;i<=20;i+=4)
  761. h->mv[i] = h->mv[i+2];
  762. /* copy bottom mvs from cache to top line */
  763. h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
  764. h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
  765. h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
  766. h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
  767. /* next MB address */
  768. h->mbx++;
  769. if(h->mbx == h->mb_width) { //new mb line
  770. h->flags = B_AVAIL|C_AVAIL;
  771. /* clear left pred_modes */
  772. h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
  773. /* clear left mv predictors */
  774. for(i=0;i<=20;i+=4)
  775. h->mv[i] = un_mv;
  776. h->mbx = 0;
  777. h->mby++;
  778. /* re-calculate sample pointers */
  779. h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
  780. h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
  781. h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
  782. if(h->mby == h->mb_height) { //frame end
  783. return 0;
  784. } else {
  785. //check_for_slice(h);
  786. }
  787. }
  788. return 1;
  789. }
  790. static void decode_mb_i(AVSContext *h) {
  791. GetBitContext *gb = &h->s.gb;
  792. int block, pred_mode_uv;
  793. uint8_t top[18];
  794. uint8_t left[18];
  795. uint8_t *d;
  796. init_mb(h);
  797. /* get intra prediction modes from stream */
  798. for(block=0;block<4;block++) {
  799. int nA,nB,predpred;
  800. int pos = scan3x3[block];
  801. nA = h->pred_mode_Y[pos-1];
  802. nB = h->pred_mode_Y[pos-3];
  803. if((nA == NOT_AVAIL) || (nB == NOT_AVAIL))
  804. predpred = 2;
  805. else
  806. predpred = FFMIN(nA,nB);
  807. if(get_bits1(gb))
  808. h->pred_mode_Y[pos] = predpred;
  809. else {
  810. h->pred_mode_Y[pos] = get_bits(gb,2);
  811. if(h->pred_mode_Y[pos] >= predpred)
  812. h->pred_mode_Y[pos]++;
  813. }
  814. }
  815. pred_mode_uv = get_ue_golomb(gb);
  816. if(pred_mode_uv > 6) {
  817. av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
  818. pred_mode_uv = 0;
  819. }
  820. /* save pred modes before they get modified */
  821. h->pred_mode_Y[3] = h->pred_mode_Y[5];
  822. h->pred_mode_Y[6] = h->pred_mode_Y[8];
  823. h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
  824. h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
  825. /* modify pred modes according to availability of neighbour samples */
  826. if(!(h->flags & A_AVAIL)) {
  827. modify_pred(left_modifier_l, &h->pred_mode_Y[4] );
  828. modify_pred(left_modifier_l, &h->pred_mode_Y[7] );
  829. modify_pred(left_modifier_c, &pred_mode_uv );
  830. }
  831. if(!(h->flags & B_AVAIL)) {
  832. modify_pred(top_modifier_l, &h->pred_mode_Y[4] );
  833. modify_pred(top_modifier_l, &h->pred_mode_Y[5] );
  834. modify_pred(top_modifier_c, &pred_mode_uv );
  835. }
  836. /* get coded block pattern */
  837. if(h->pic_type == FF_I_TYPE)
  838. h->cbp = cbp_tab[get_ue_golomb(gb)][0];
  839. if(h->cbp && !h->qp_fixed)
  840. h->qp += get_se_golomb(gb); //qp_delta
  841. /* luma intra prediction interleaved with residual decode/transform/add */
  842. for(block=0;block<4;block++) {
  843. d = h->cy + h->luma_scan[block];
  844. load_intra_pred_luma(h, top, left, block);
  845. h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
  846. (d, top, left, h->l_stride);
  847. if(h->cbp & (1<<block))
  848. decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride);
  849. }
  850. /* chroma intra prediction */
  851. /* extend borders by one pixel */
  852. h->left_border_u[9] = h->left_border_u[8];
  853. h->left_border_v[9] = h->left_border_v[8];
  854. h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
  855. h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
  856. if(h->mbx && h->mby) {
  857. h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
  858. h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
  859. } else {
  860. h->left_border_u[0] = h->left_border_u[1];
  861. h->left_border_v[0] = h->left_border_v[1];
  862. h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
  863. h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
  864. }
  865. h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
  866. h->left_border_u, h->c_stride);
  867. h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
  868. h->left_border_v, h->c_stride);
  869. decode_residual_chroma(h);
  870. filter_mb(h,I_8X8);
  871. /* mark motion vectors as intra */
  872. h->mv[MV_FWD_X0] = intra_mv;
  873. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  874. h->mv[MV_BWD_X0] = intra_mv;
  875. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  876. if(h->pic_type != FF_B_TYPE)
  877. *h->col_type = I_8X8;
  878. }
  879. static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
  880. GetBitContext *gb = &h->s.gb;
  881. int ref[4];
  882. init_mb(h);
  883. switch(mb_type) {
  884. case P_SKIP:
  885. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
  886. break;
  887. case P_16X16:
  888. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  889. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]);
  890. break;
  891. case P_16X8:
  892. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  893. ref[2] = h->ref_flag ? 0 : get_bits1(gb);
  894. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
  895. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
  896. break;
  897. case P_8X16:
  898. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  899. ref[1] = h->ref_flag ? 0 : get_bits1(gb);
  900. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
  901. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]);
  902. break;
  903. case P_8X8:
  904. ref[0] = h->ref_flag ? 0 : get_bits1(gb);
  905. ref[1] = h->ref_flag ? 0 : get_bits1(gb);
  906. ref[2] = h->ref_flag ? 0 : get_bits1(gb);
  907. ref[3] = h->ref_flag ? 0 : get_bits1(gb);
  908. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
  909. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
  910. mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
  911. mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
  912. }
  913. inter_pred(h);
  914. store_mvs(h);
  915. if(mb_type != P_SKIP)
  916. decode_residual_inter(h);
  917. filter_mb(h,mb_type);
  918. *h->col_type = mb_type;
  919. }
  920. static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
  921. int block;
  922. enum sub_mb_t sub_type[4];
  923. int flags;
  924. init_mb(h);
  925. /* reset all MVs */
  926. h->mv[MV_FWD_X0] = dir_mv;
  927. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  928. h->mv[MV_BWD_X0] = dir_mv;
  929. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  930. switch(mb_type) {
  931. case B_SKIP:
  932. case B_DIRECT:
  933. if(!(*h->col_type)) {
  934. /* intra MB at co-location, do in-plane prediction */
  935. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
  936. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
  937. } else
  938. /* direct prediction from co-located P MB, block-wise */
  939. for(block=0;block<4;block++)
  940. mv_pred_direct(h,&h->mv[mv_scan[block]],
  941. &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
  942. break;
  943. case B_FWD_16X16:
  944. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
  945. break;
  946. case B_SYM_16X16:
  947. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
  948. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
  949. break;
  950. case B_BWD_16X16:
  951. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
  952. break;
  953. case B_8X8:
  954. for(block=0;block<4;block++)
  955. sub_type[block] = get_bits(&h->s.gb,2);
  956. for(block=0;block<4;block++) {
  957. switch(sub_type[block]) {
  958. case B_SUB_DIRECT:
  959. if(!(*h->col_type)) {
  960. /* intra MB at co-location, do in-plane prediction */
  961. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  962. MV_PRED_BSKIP, BLK_8X8, 1);
  963. mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
  964. mv_scan[block]-3+MV_BWD_OFFS,
  965. MV_PRED_BSKIP, BLK_8X8, 0);
  966. } else
  967. mv_pred_direct(h,&h->mv[mv_scan[block]],
  968. &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
  969. break;
  970. case B_SUB_FWD:
  971. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  972. MV_PRED_MEDIAN, BLK_8X8, 1);
  973. break;
  974. case B_SUB_SYM:
  975. mv_pred(h, mv_scan[block], mv_scan[block]-3,
  976. MV_PRED_MEDIAN, BLK_8X8, 1);
  977. mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
  978. break;
  979. }
  980. }
  981. for(block=0;block<4;block++) {
  982. if(sub_type[block] == B_SUB_BWD)
  983. mv_pred(h, mv_scan[block]+MV_BWD_OFFS,
  984. mv_scan[block]+MV_BWD_OFFS-3,
  985. MV_PRED_MEDIAN, BLK_8X8, 0);
  986. }
  987. break;
  988. default:
  989. assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
  990. flags = b_partition_flags[(mb_type-1)>>1];
  991. if(mb_type & 1) { /* 16x8 macroblock types */
  992. if(flags & FWD0)
  993. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
  994. if(flags & SYM0) {
  995. mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
  996. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
  997. }
  998. if(flags & FWD1)
  999. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
  1000. if(flags & SYM1) {
  1001. mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
  1002. mv_pred_sym(h, &h->mv[9], BLK_16X8);
  1003. }
  1004. if(flags & BWD0)
  1005. mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
  1006. if(flags & BWD1)
  1007. mv_pred(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
  1008. } else { /* 8x16 macroblock types */
  1009. if(flags & FWD0)
  1010. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
  1011. if(flags & SYM0) {
  1012. mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
  1013. mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
  1014. }
  1015. if(flags & FWD1)
  1016. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
  1017. if(flags & SYM1) {
  1018. mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1);
  1019. mv_pred_sym(h, &h->mv[6], BLK_8X16);
  1020. }
  1021. if(flags & BWD0)
  1022. mv_pred(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
  1023. if(flags & BWD1)
  1024. mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0);
  1025. }
  1026. }
  1027. inter_pred(h);
  1028. if(mb_type != B_SKIP)
  1029. decode_residual_inter(h);
  1030. filter_mb(h,mb_type);
  1031. }
  1032. /*****************************************************************************
  1033. *
  1034. * slice level
  1035. *
  1036. ****************************************************************************/
  1037. static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) {
  1038. if(h->stc > 0xAF)
  1039. av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
  1040. h->mby = h->stc;
  1041. if((h->mby == 0) && (!h->qp_fixed)){
  1042. h->qp_fixed = get_bits1(gb);
  1043. h->qp = get_bits(gb,6);
  1044. }
  1045. /* inter frame or second slice can have weighting params */
  1046. if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2))
  1047. if(get_bits1(gb)) { //slice_weighting_flag
  1048. av_log(h->s.avctx, AV_LOG_ERROR,
  1049. "weighted prediction not yet supported\n");
  1050. }
  1051. return 0;
  1052. }
  1053. static inline void check_for_slice(AVSContext *h) {
  1054. GetBitContext *gb = &h->s.gb;
  1055. int align;
  1056. align = (-get_bits_count(gb)) & 7;
  1057. if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
  1058. get_bits_long(gb,24+align);
  1059. h->stc = get_bits(gb,8);
  1060. decode_slice_header(h,gb);
  1061. }
  1062. }
  1063. /*****************************************************************************
  1064. *
  1065. * frame level
  1066. *
  1067. ****************************************************************************/
  1068. static void init_pic(AVSContext *h) {
  1069. int i;
  1070. /* clear some predictors */
  1071. for(i=0;i<=20;i+=4)
  1072. h->mv[i] = un_mv;
  1073. h->mv[MV_BWD_X0] = dir_mv;
  1074. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  1075. h->mv[MV_FWD_X0] = dir_mv;
  1076. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  1077. h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
  1078. h->cy = h->picture.data[0];
  1079. h->cu = h->picture.data[1];
  1080. h->cv = h->picture.data[2];
  1081. h->l_stride = h->picture.linesize[0];
  1082. h->c_stride = h->picture.linesize[1];
  1083. h->luma_scan[2] = 8*h->l_stride;
  1084. h->luma_scan[3] = 8*h->l_stride+8;
  1085. h->mbx = h->mby = 0;
  1086. h->flags = 0;
  1087. }
  1088. static int decode_pic(AVSContext *h) {
  1089. MpegEncContext *s = &h->s;
  1090. int skip_count;
  1091. enum mb_t mb_type;
  1092. if (!s->context_initialized) {
  1093. if (MPV_common_init(s) < 0)
  1094. return -1;
  1095. }
  1096. get_bits(&s->gb,16);//bbv_dwlay
  1097. if(h->stc == PIC_PB_START_CODE) {
  1098. h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE;
  1099. /* make sure we have the reference frames we need */
  1100. if(!h->DPB[0].data[0] ||
  1101. (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE))
  1102. return -1;
  1103. } else {
  1104. h->pic_type = FF_I_TYPE;
  1105. if(get_bits1(&s->gb))
  1106. get_bits(&s->gb,16);//time_code
  1107. }
  1108. /* release last B frame */
  1109. if(h->picture.data[0])
  1110. s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
  1111. s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
  1112. init_pic(h);
  1113. h->picture.poc = get_bits(&s->gb,8)*2;
  1114. /* get temporal distances and MV scaling factors */
  1115. if(h->pic_type != FF_B_TYPE) {
  1116. h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512;
  1117. } else {
  1118. h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512;
  1119. }
  1120. h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512;
  1121. h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
  1122. h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
  1123. if(h->pic_type == FF_B_TYPE) {
  1124. h->sym_factor = h->dist[0]*h->scale_den[1];
  1125. } else {
  1126. h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0;
  1127. h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0;
  1128. }
  1129. if(s->low_delay)
  1130. get_ue_golomb(&s->gb); //bbv_check_times
  1131. h->progressive = get_bits1(&s->gb);
  1132. if(h->progressive)
  1133. h->pic_structure = 1;
  1134. else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) )
  1135. get_bits1(&s->gb); //advanced_pred_mode_disable
  1136. skip_bits1(&s->gb); //top_field_first
  1137. skip_bits1(&s->gb); //repeat_first_field
  1138. h->qp_fixed = get_bits1(&s->gb);
  1139. h->qp = get_bits(&s->gb,6);
  1140. if(h->pic_type == FF_I_TYPE) {
  1141. if(!h->progressive && !h->pic_structure)
  1142. skip_bits1(&s->gb);//what is this?
  1143. skip_bits(&s->gb,4); //reserved bits
  1144. } else {
  1145. if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1))
  1146. h->ref_flag = get_bits1(&s->gb);
  1147. skip_bits(&s->gb,4); //reserved bits
  1148. h->skip_mode_flag = get_bits1(&s->gb);
  1149. }
  1150. h->loop_filter_disable = get_bits1(&s->gb);
  1151. if(!h->loop_filter_disable && get_bits1(&s->gb)) {
  1152. h->alpha_offset = get_se_golomb(&s->gb);
  1153. h->beta_offset = get_se_golomb(&s->gb);
  1154. } else {
  1155. h->alpha_offset = h->beta_offset = 0;
  1156. }
  1157. check_for_slice(h);
  1158. if(h->pic_type == FF_I_TYPE) {
  1159. do {
  1160. decode_mb_i(h);
  1161. } while(next_mb(h));
  1162. } else if(h->pic_type == FF_P_TYPE) {
  1163. do {
  1164. if(h->skip_mode_flag) {
  1165. skip_count = get_ue_golomb(&s->gb);
  1166. while(skip_count--) {
  1167. decode_mb_p(h,P_SKIP);
  1168. if(!next_mb(h))
  1169. goto done;
  1170. }
  1171. mb_type = get_ue_golomb(&s->gb) + P_16X16;
  1172. } else
  1173. mb_type = get_ue_golomb(&s->gb) + P_SKIP;
  1174. if(mb_type > P_8X8) {
  1175. h->cbp = cbp_tab[mb_type - P_8X8 - 1][0];
  1176. decode_mb_i(h);
  1177. } else
  1178. decode_mb_p(h,mb_type);
  1179. } while(next_mb(h));
  1180. } else { /* FF_B_TYPE */
  1181. do {
  1182. if(h->skip_mode_flag) {
  1183. skip_count = get_ue_golomb(&s->gb);
  1184. while(skip_count--) {
  1185. decode_mb_b(h,B_SKIP);
  1186. if(!next_mb(h))
  1187. goto done;
  1188. }
  1189. mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
  1190. } else
  1191. mb_type = get_ue_golomb(&s->gb) + B_SKIP;
  1192. init_mb(h);
  1193. if(mb_type > B_8X8) {
  1194. h->cbp = cbp_tab[mb_type - B_8X8 - 1][0];
  1195. decode_mb_i(h);
  1196. } else
  1197. decode_mb_b(h,mb_type);
  1198. } while(next_mb(h));
  1199. }
  1200. done:
  1201. if(h->pic_type != FF_B_TYPE) {
  1202. if(h->DPB[1].data[0])
  1203. s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
  1204. memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture));
  1205. memcpy(&h->DPB[0], &h->picture, sizeof(Picture));
  1206. memset(&h->picture,0,sizeof(Picture));
  1207. }
  1208. return 0;
  1209. }
  1210. /*****************************************************************************
  1211. *
  1212. * headers and interface
  1213. *
  1214. ****************************************************************************/
  1215. /**
  1216. * some predictions require data from the top-neighbouring macroblock.
  1217. * this data has to be stored for one complete row of macroblocks
  1218. * and this storage space is allocated here
  1219. */
  1220. static void init_top_lines(AVSContext *h) {
  1221. /* alloc top line of predictors */
  1222. h->top_qp = av_malloc( h->mb_width);
  1223. h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  1224. h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  1225. h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
  1226. h->top_border_y = av_malloc((h->mb_width+1)*16);
  1227. h->top_border_u = av_malloc((h->mb_width)*10);
  1228. h->top_border_v = av_malloc((h->mb_width)*10);
  1229. /* alloc space for co-located MVs and types */
  1230. h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
  1231. h->col_type_base = av_malloc(h->mb_width*h->mb_height);
  1232. }
  1233. static int decode_seq_header(AVSContext *h) {
  1234. MpegEncContext *s = &h->s;
  1235. extern const AVRational ff_frame_rate_tab[];
  1236. int frame_rate_code;
  1237. h->profile = get_bits(&s->gb,8);
  1238. h->level = get_bits(&s->gb,8);
  1239. skip_bits1(&s->gb); //progressive sequence
  1240. s->width = get_bits(&s->gb,14);
  1241. s->height = get_bits(&s->gb,14);
  1242. skip_bits(&s->gb,2); //chroma format
  1243. skip_bits(&s->gb,3); //sample_precision
  1244. h->aspect_ratio = get_bits(&s->gb,4);
  1245. frame_rate_code = get_bits(&s->gb,4);
  1246. skip_bits(&s->gb,18);//bit_rate_lower
  1247. skip_bits1(&s->gb); //marker_bit
  1248. skip_bits(&s->gb,12);//bit_rate_upper
  1249. s->low_delay = get_bits1(&s->gb);
  1250. h->mb_width = (s->width + 15) >> 4;
  1251. h->mb_height = (s->height + 15) >> 4;
  1252. h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num;
  1253. h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den;
  1254. h->s.avctx->width = s->width;
  1255. h->s.avctx->height = s->height;
  1256. if(!h->top_qp)
  1257. init_top_lines(h);
  1258. return 0;
  1259. }
  1260. /**
  1261. * finds the end of the current frame in the bitstream.
  1262. * @return the position of the first byte of the next frame, or -1
  1263. */
  1264. int ff_cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) {
  1265. int pic_found, i;
  1266. uint32_t state;
  1267. pic_found= pc->frame_start_found;
  1268. state= pc->state;
  1269. i=0;
  1270. if(!pic_found){
  1271. for(i=0; i<buf_size; i++){
  1272. state= (state<<8) | buf[i];
  1273. if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
  1274. i++;
  1275. pic_found=1;
  1276. break;
  1277. }
  1278. }
  1279. }
  1280. if(pic_found){
  1281. /* EOF considered as end of frame */
  1282. if (buf_size == 0)
  1283. return 0;
  1284. for(; i<buf_size; i++){
  1285. state= (state<<8) | buf[i];
  1286. if((state&0xFFFFFF00) == 0x100){
  1287. if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
  1288. pc->frame_start_found=0;
  1289. pc->state=-1;
  1290. return i-3;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. pc->frame_start_found= pic_found;
  1296. pc->state= state;
  1297. return END_NOT_FOUND;
  1298. }
  1299. void ff_cavs_flush(AVCodecContext * avctx) {
  1300. AVSContext *h = avctx->priv_data;
  1301. h->got_keyframe = 0;
  1302. }
  1303. static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
  1304. uint8_t * buf, int buf_size) {
  1305. AVSContext *h = avctx->priv_data;
  1306. MpegEncContext *s = &h->s;
  1307. int input_size;
  1308. const uint8_t *buf_end;
  1309. const uint8_t *buf_ptr;
  1310. AVFrame *picture = data;
  1311. uint32_t stc;
  1312. s->avctx = avctx;
  1313. if (buf_size == 0) {
  1314. if(!s->low_delay && h->DPB[0].data[0]) {
  1315. *data_size = sizeof(AVPicture);
  1316. *picture = *(AVFrame *) &h->DPB[0];
  1317. }
  1318. return 0;
  1319. }
  1320. buf_ptr = buf;
  1321. buf_end = buf + buf_size;
  1322. for(;;) {
  1323. buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);
  1324. if(stc & 0xFFFFFE00)
  1325. return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
  1326. input_size = (buf_end - buf_ptr)*8;
  1327. switch(stc) {
  1328. case SEQ_START_CODE:
  1329. init_get_bits(&s->gb, buf_ptr, input_size);
  1330. decode_seq_header(h);
  1331. break;
  1332. case PIC_I_START_CODE:
  1333. if(!h->got_keyframe) {
  1334. if(h->DPB[0].data[0])
  1335. avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
  1336. if(h->DPB[1].data[0])
  1337. avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
  1338. h->got_keyframe = 1;
  1339. }
  1340. case PIC_PB_START_CODE:
  1341. *data_size = 0;
  1342. if(!h->got_keyframe)
  1343. break;
  1344. init_get_bits(&s->gb, buf_ptr, input_size);
  1345. h->stc = stc;
  1346. if(decode_pic(h))
  1347. break;
  1348. *data_size = sizeof(AVPicture);
  1349. if(h->pic_type != FF_B_TYPE) {
  1350. if(h->DPB[1].data[0]) {
  1351. *picture = *(AVFrame *) &h->DPB[1];
  1352. } else {
  1353. *data_size = 0;
  1354. }
  1355. } else
  1356. *picture = *(AVFrame *) &h->picture;
  1357. break;
  1358. case EXT_START_CODE:
  1359. //mpeg_decode_extension(avctx,buf_ptr, input_size);
  1360. break;
  1361. case USER_START_CODE:
  1362. //mpeg_decode_user_data(avctx,buf_ptr, input_size);
  1363. break;
  1364. default:
  1365. if (stc >= SLICE_MIN_START_CODE &&
  1366. stc <= SLICE_MAX_START_CODE) {
  1367. init_get_bits(&s->gb, buf_ptr, input_size);
  1368. decode_slice_header(h, &s->gb);
  1369. }
  1370. break;
  1371. }
  1372. }
  1373. }
  1374. static int cavs_decode_init(AVCodecContext * avctx) {
  1375. AVSContext *h = avctx->priv_data;
  1376. MpegEncContext * const s = &h->s;
  1377. MPV_decode_defaults(s);
  1378. s->avctx = avctx;
  1379. avctx->pix_fmt= PIX_FMT_YUV420P;
  1380. h->luma_scan[0] = 0;
  1381. h->luma_scan[1] = 8;
  1382. h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
  1383. h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
  1384. h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
  1385. h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
  1386. h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
  1387. h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
  1388. h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
  1389. h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
  1390. h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
  1391. h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
  1392. h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
  1393. h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
  1394. h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
  1395. h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
  1396. h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
  1397. h->mv[ 7] = un_mv;
  1398. h->mv[19] = un_mv;
  1399. return 0;
  1400. }
  1401. static int cavs_decode_end(AVCodecContext * avctx) {
  1402. AVSContext *h = avctx->priv_data;
  1403. av_free(h->top_qp);
  1404. av_free(h->top_mv[0]);
  1405. av_free(h->top_mv[1]);
  1406. av_free(h->top_pred_Y);
  1407. av_free(h->top_border_y);
  1408. av_free(h->top_border_u);
  1409. av_free(h->top_border_v);
  1410. av_free(h->col_mv);
  1411. av_free(h->col_type_base);
  1412. return 0;
  1413. }
  1414. AVCodec cavs_decoder = {
  1415. "cavs",
  1416. CODEC_TYPE_VIDEO,
  1417. CODEC_ID_CAVS,
  1418. sizeof(AVSContext),
  1419. cavs_decode_init,
  1420. NULL,
  1421. cavs_decode_end,
  1422. cavs_decode_frame,
  1423. CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1424. .flush= ff_cavs_flush,
  1425. };