annotate cavs.c @ 3469:c9059c843d4c libavcodec

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