Lines 68-78
Link Here
|
68 |
} |
68 |
} |
69 |
} |
69 |
} |
70 |
|
70 |
|
|
|
71 |
#ifdef HAVE_XVMC_VLD |
72 |
static XvMCSurface* findPastSurface(MpegEncContext *s, |
73 |
xvmc_render_state_t *render) |
74 |
{ |
75 |
Picture *lastp = s->last_picture_ptr; |
76 |
xvmc_render_state_t *last = NULL; |
77 |
|
78 |
if (NULL!=lastp) { |
79 |
last = (xvmc_render_state_t*)(lastp->data[2]); |
80 |
if (B_TYPE==last->pict_type) |
81 |
av_log(s->avctx,AV_LOG_DEBUG, "Past frame is a B frame in findPastSurface, this is bad.\n"); |
82 |
//assert(B_TYPE!=last->pict_type); |
83 |
} |
84 |
|
85 |
if (NULL==last) |
86 |
if (!s->first_field) |
87 |
last = render; // predict second field from the first |
88 |
else |
89 |
return 0; |
90 |
|
91 |
if (last->magic != MP_XVMC_RENDER_MAGIC) |
92 |
return 0; |
93 |
|
94 |
return (last->state & MP_XVMC_STATE_PREDICTION) ? last->p_surface : 0; |
95 |
} |
96 |
|
97 |
static XvMCSurface* findFutureSurface(MpegEncContext *s) |
98 |
{ |
99 |
Picture *nextp = s->next_picture_ptr; |
100 |
xvmc_render_state_t *next = NULL; |
101 |
|
102 |
if (NULL!=nextp) { |
103 |
next = (xvmc_render_state_t*)(nextp->data[2]); |
104 |
if (B_TYPE==next->pict_type) |
105 |
av_log(s->avctx,AV_LOG_DEBUG, "Next frame is a B frame in findFutureSurface, thisis bad.\n"); |
106 |
//assert(B_TYPE!=next->pict_type); |
107 |
} |
108 |
|
109 |
assert(NULL!=next); |
110 |
|
111 |
if (next->magic != MP_XVMC_RENDER_MAGIC) |
112 |
return 0; |
113 |
|
114 |
return (next->state & MP_XVMC_STATE_PREDICTION) ? next->p_surface : 0; |
115 |
} |
116 |
#endif //HAVE_XVMC_VLD |
117 |
|
71 |
//these functions should be called on every new field or/and frame |
118 |
//these functions should be called on every new field or/and frame |
72 |
//They should be safe if they are called few times for same field! |
119 |
//They should be safe if they are called few times for same field! |
73 |
int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){ |
120 |
int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){ |
74 |
xvmc_render_state_t * render,* last, * next; |
121 |
xvmc_render_state_t * render,* last, * next; |
75 |
|
122 |
|
|
|
123 |
#ifdef HAVE_XVMC_VLD |
124 |
XvMCMpegControl binfo; |
125 |
XvMCQMatrix qmatrix; |
126 |
int i; |
127 |
Status status; |
128 |
|
129 |
memset(&binfo, 0, sizeof(binfo)); |
130 |
memset(&qmatrix, 0, sizeof(qmatrix)); |
131 |
#endif |
132 |
|
76 |
assert(avctx != NULL); |
133 |
assert(avctx != NULL); |
77 |
|
134 |
|
78 |
render = (xvmc_render_state_t*)s->current_picture.data[2]; |
135 |
render = (xvmc_render_state_t*)s->current_picture.data[2]; |
Lines 83-94
Link Here
|
83 |
render->picture_structure = s->picture_structure; |
140 |
render->picture_structure = s->picture_structure; |
84 |
render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD; |
141 |
render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD; |
85 |
|
142 |
|
|
|
143 |
#ifdef HAVE_XVMC_VLD |
144 |
if (s->avctx->xvmc_acceleration == 4) |
145 |
{ |
146 |
if (render->picture_structure == PICT_FRAME) |
147 |
render->flags |= XVMC_FRAME_PICTURE; |
148 |
else if (render->picture_structure == PICT_TOP_FIELD) |
149 |
render->flags |= XVMC_TOP_FIELD; |
150 |
else if (render->picture_structure == PICT_BOTTOM_FIELD) |
151 |
render->flags |= XVMC_BOTTOM_FIELD; |
152 |
} |
153 |
else |
154 |
#endif |
155 |
{ |
86 |
//make sure that all data is drawn by XVMC_end_frame |
156 |
//make sure that all data is drawn by XVMC_end_frame |
87 |
assert(render->filled_mv_blocks_num==0); |
157 |
assert(render->filled_mv_blocks_num==0); |
|
|
158 |
} |
88 |
|
159 |
|
89 |
render->p_future_surface = NULL; |
160 |
render->p_future_surface = NULL; |
90 |
render->p_past_surface = NULL; |
161 |
render->p_past_surface = NULL; |
91 |
|
162 |
|
|
|
163 |
render->pict_type = s->pict_type; // for later frame dropping use |
164 |
|
165 |
#ifdef HAVE_XVMC_VLD |
166 |
if (s->avctx->xvmc_acceleration == 4) |
167 |
{ |
168 |
switch(s->pict_type){ |
169 |
case I_TYPE: |
170 |
break; |
171 |
case B_TYPE: |
172 |
render->p_past_surface = findPastSurface(s, render); |
173 |
render->p_future_surface = findFutureSurface(s); |
174 |
if (!render->p_past_surface) |
175 |
av_log(avctx, AV_LOG_ERROR, "error: decoding B frame and past frame is null!"); |
176 |
else if (!render->p_future_surface) |
177 |
av_log(avctx, AV_LOG_ERROR, "error: decoding B frame and future frame is null!"); |
178 |
break; |
179 |
|
180 |
case P_TYPE: |
181 |
render->p_past_surface = findPastSurface(s, render); |
182 |
render->p_future_surface = render->p_surface; |
183 |
if (!render->p_past_surface) |
184 |
av_log(avctx, AV_LOG_ERROR, "error: decoding P frame and past frame is null!"); |
185 |
break; |
186 |
} |
187 |
} else |
188 |
#endif |
189 |
{ |
92 |
switch(s->pict_type){ |
190 |
switch(s->pict_type){ |
93 |
case I_TYPE: |
191 |
case I_TYPE: |
94 |
return 0;// no prediction from other frames |
192 |
return 0;// no prediction from other frames |
Lines 109-114
Link Here
|
109 |
render->p_past_surface = last->p_surface; |
207 |
render->p_past_surface = last->p_surface; |
110 |
return 0; |
208 |
return 0; |
111 |
} |
209 |
} |
|
|
210 |
} |
211 |
|
212 |
#ifdef HAVE_XVMC_VLD |
213 |
if (s->avctx->xvmc_acceleration == 4) |
214 |
{ |
215 |
for (i = 0; i < 64; i++){ |
216 |
qmatrix.intra_quantiser_matrix[i] = s->intra_matrix[s->dsp.idct_permutation[i]]; |
217 |
qmatrix.non_intra_quantiser_matrix[i] = s->inter_matrix[s->dsp.idct_permutation[i]]; |
218 |
qmatrix.chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[s->dsp.idct_permutation[i]]; |
219 |
qmatrix.chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[s->dsp.idct_permutation[i]]; |
220 |
} |
221 |
|
222 |
qmatrix.load_intra_quantiser_matrix = 1; |
223 |
qmatrix.load_non_intra_quantiser_matrix = 1; |
224 |
qmatrix.load_chroma_intra_quantiser_matrix = 1; |
225 |
qmatrix.load_chroma_non_intra_quantiser_matrix = 1; |
226 |
|
227 |
|
228 |
binfo.flags = 0; |
229 |
if (s->alternate_scan) |
230 |
binfo.flags |= XVMC_ALTERNATE_SCAN; |
231 |
if (s->top_field_first) |
232 |
binfo.flags |= XVMC_TOP_FIELD_FIRST; |
233 |
if (s->frame_pred_frame_dct) |
234 |
binfo.flags |= XVMC_PRED_DCT_FRAME; |
235 |
else |
236 |
binfo.flags |= XVMC_PRED_DCT_FIELD; |
237 |
|
238 |
if (s->intra_vlc_format) |
239 |
binfo.flags |= XVMC_INTRA_VLC_FORMAT; |
240 |
if (!s->first_field && !s->progressive_sequence) |
241 |
binfo.flags |= XVMC_SECOND_FIELD; |
242 |
if (s->q_scale_type) |
243 |
binfo.flags |= XVMC_Q_SCALE_TYPE; |
244 |
if (s->concealment_motion_vectors) |
245 |
binfo.flags |= XVMC_CONCEALMENT_MOTION_VECTORS; |
246 |
if (s->progressive_sequence) |
247 |
binfo.flags |= XVMC_PROGRESSIVE_SEQUENCE; |
248 |
|
249 |
binfo.picture_structure = s->picture_structure; |
250 |
switch (s->pict_type) |
251 |
{ |
252 |
case I_TYPE: binfo.picture_coding_type = XVMC_I_PICTURE; break; |
253 |
case P_TYPE: binfo.picture_coding_type = XVMC_P_PICTURE; break; |
254 |
case B_TYPE: binfo.picture_coding_type = XVMC_B_PICTURE; break; |
255 |
default: av_log(avctx, AV_LOG_ERROR, "%s: Unknown picture coding type: %d\n", __FUNCTION__, s->pict_type); |
256 |
} |
257 |
|
258 |
binfo.intra_dc_precision = s->intra_dc_precision;; |
259 |
|
260 |
if (s->codec_id == CODEC_ID_MPEG2VIDEO) |
261 |
binfo.mpeg_coding = 2; |
262 |
else |
263 |
binfo.mpeg_coding = 1; |
264 |
|
265 |
s->mb_width = (s->width + 15) / 16; |
266 |
s->mb_height = (s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) ? |
267 |
2 * ((s->height + 31) / 32) : (s->height + 15) / 16; |
268 |
|
269 |
if (s->codec_id == CODEC_ID_MPEG2VIDEO) |
270 |
{ |
271 |
binfo.FVMV_range = (s->mpeg_f_code[0][1] - 1); |
272 |
binfo.FHMV_range = (s->mpeg_f_code[0][0] - 1); |
273 |
binfo.BVMV_range = (s->mpeg_f_code[1][1] - 1); |
274 |
binfo.BHMV_range = (s->mpeg_f_code[1][0] - 1); |
275 |
} |
276 |
else |
277 |
{ |
278 |
binfo.FVMV_range = (s->mpeg_f_code[0][0] - 1); |
279 |
binfo.FHMV_range = (s->mpeg_f_code[0][0] - 1); |
280 |
binfo.BVMV_range = (s->mpeg_f_code[1][1] - 1); |
281 |
binfo.BHMV_range = (s->mpeg_f_code[1][1] - 1); |
282 |
} |
283 |
|
284 |
status = XvMCLoadQMatrix(render->disp, render->ctx, &qmatrix); |
285 |
if (status) |
286 |
av_log(avctx,AV_LOG_ERROR, "XvMCLoadQMatrix: Error: %d\n", status); |
287 |
|
288 |
status = XvMCBeginSurface(render->disp, render->ctx, render->p_surface, |
289 |
render->p_past_surface, render->p_future_surface, |
290 |
&binfo); |
291 |
if (status) |
292 |
av_log(avctx,AV_LOG_ERROR, "XvMCBeginSurface: Error: %d\n", status); |
293 |
|
294 |
if (!status) |
295 |
return 0; |
296 |
} |
297 |
#endif |
112 |
|
298 |
|
113 |
return -1; |
299 |
return -1; |
114 |
} |
300 |
} |
Lines 118-128
Link Here
|
118 |
render = (xvmc_render_state_t*)s->current_picture.data[2]; |
304 |
render = (xvmc_render_state_t*)s->current_picture.data[2]; |
119 |
assert(render != NULL); |
305 |
assert(render != NULL); |
120 |
|
306 |
|
|
|
307 |
#ifdef HAVE_XVMC_VLD |
308 |
if (s->avctx->xvmc_acceleration == 4) |
309 |
{ |
310 |
XvMCFlushSurface(render->disp, render->p_surface); |
311 |
XvMCSyncSurface(render->disp, render->p_surface); |
312 |
|
313 |
s->error_count = 0; |
314 |
} |
315 |
else |
316 |
#endif |
317 |
{ |
121 |
if(render->filled_mv_blocks_num > 0){ |
318 |
if(render->filled_mv_blocks_num > 0){ |
122 |
// printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num ); |
319 |
// printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num ); |
123 |
ff_draw_horiz_band(s,0,0); |
320 |
ff_draw_horiz_band(s,0,0); |
124 |
} |
321 |
} |
125 |
} |
322 |
} |
|
|
323 |
} |
126 |
|
324 |
|
127 |
void XVMC_decode_mb(MpegEncContext *s){ |
325 |
void XVMC_decode_mb(MpegEncContext *s){ |
128 |
XvMCMacroBlock * mv_block; |
326 |
XvMCMacroBlock * mv_block; |
Lines 311-314
Link Here
|
311 |
|
509 |
|
312 |
} |
510 |
} |
313 |
|
511 |
|
|
|
512 |
#ifdef HAVE_XVMC_VLD |
513 |
static int length_to_next_start(uint8_t* pbuf_ptr, int buf_size) |
514 |
{ |
515 |
uint8_t* buf_ptr; |
516 |
unsigned int state = 0xFFFFFFFF, v; |
517 |
|
518 |
buf_ptr = pbuf_ptr; |
519 |
while (buf_ptr < pbuf_ptr + buf_size) |
520 |
{ |
521 |
v = *buf_ptr++; |
522 |
if (state == 0x000001) { |
523 |
return buf_ptr - pbuf_ptr - 4; |
524 |
} |
525 |
state = ((state << 8) | v) & 0xffffff; |
526 |
} |
527 |
return -1; |
528 |
} |
529 |
|
530 |
#define SLICE_MIN_START_CODE 0x00000101 |
531 |
#define SLICE_MAX_START_CODE 0x000001af |
532 |
|
533 |
void XVMC_decode_slice(MpegEncContext *s, int mb_y, uint8_t* buffer, int buf_size) |
534 |
{ |
535 |
int slicelen = length_to_next_start(buffer, buf_size); |
536 |
xvmc_render_state_t* render; |
537 |
|
538 |
if (slicelen < 0) |
539 |
{ |
540 |
if ((mb_y == s->mb_height - 1) || |
541 |
(!s->progressive_sequence && mb_y == (s->mb_height >> 1) -1) || |
542 |
(s->codec_id != CODEC_ID_MPEG2VIDEO)) |
543 |
slicelen = buf_size; |
544 |
else |
545 |
return; |
546 |
} |
547 |
|
548 |
render = (xvmc_render_state_t*)s->current_picture.data[2]; |
549 |
render->slice_code = SLICE_MIN_START_CODE + mb_y; |
550 |
render->slice_data = buffer; |
551 |
render->slice_datalen = slicelen; |
552 |
|
553 |
ff_draw_horiz_band(s, 0, 0); |
554 |
} |
555 |
#endif |
556 |
|
314 |
#endif |
557 |
#endif |
|
|
558 |
|