Mercurial > mplayer.hg
comparison libmpcodecs/vd_ffmpeg.c @ 19073:8b52dad54b1d
Remove #if LIBAVCODEC_BUILD >= XXX and #if LIBAVFORMAT_BUILD >= XXX jungle.
It served no apparent purpose anymore.
author | diego |
---|---|
date | Thu, 13 Jul 2006 23:02:03 +0000 |
parents | d9a75b26da6c |
children | 3f910f7b0e53 |
comparison
equal
deleted
inserted
replaced
19072:e6f5f7c26166 | 19073:8b52dad54b1d |
---|---|
23 | 23 |
24 #ifdef USE_LIBAVCODEC_SO | 24 #ifdef USE_LIBAVCODEC_SO |
25 #include <ffmpeg/avcodec.h> | 25 #include <ffmpeg/avcodec.h> |
26 #else | 26 #else |
27 #include "libavcodec/avcodec.h" | 27 #include "libavcodec/avcodec.h" |
28 #endif | |
29 | |
30 #if LIBAVCODEC_BUILD < 4641 | |
31 #error we do not support libavcodec prior to build 4641, get the latest libavcodec CVS | |
32 #endif | |
33 | |
34 #if LIBAVCODEC_BUILD < 4645 | |
35 #warning your version of libavcodec is old, u might want to get a newer one | |
36 #endif | |
37 | |
38 #if LIBAVCODEC_BUILD < 4645 | |
39 #define AVFrame AVVideoFrame | |
40 #define coded_frame coded_picture | |
41 #endif | |
42 | |
43 #if LIBAVCODEC_BUILD < 4654 | |
44 #define PIX_FMT_RGB24 PIX_FMT_BGR24 | |
45 #define PIX_FMT_RGBA32 PIX_FMT_BGRA32 | |
46 #endif | |
47 | |
48 #if LIBAVCODEC_BUILD < 4672 | |
49 #undef HAVE_XVMC | |
50 #endif | 28 #endif |
51 | 29 |
52 #ifdef HAVE_XVMC | 30 #ifdef HAVE_XVMC |
53 #include "xvmc_render.h" | 31 #include "xvmc_render.h" |
54 #endif | 32 #endif |
103 static int lavc_param_skip_top=0; | 81 static int lavc_param_skip_top=0; |
104 static int lavc_param_skip_bottom=0; | 82 static int lavc_param_skip_bottom=0; |
105 static int lavc_param_fast=0; | 83 static int lavc_param_fast=0; |
106 static int lavc_param_lowres=0; | 84 static int lavc_param_lowres=0; |
107 static char *lavc_param_lowres_str=NULL; | 85 static char *lavc_param_lowres_str=NULL; |
108 #if LIBAVCODEC_BUILD >= 4758 | |
109 static char *lavc_param_skip_loop_filter_str = NULL; | 86 static char *lavc_param_skip_loop_filter_str = NULL; |
110 static char *lavc_param_skip_idct_str = NULL; | 87 static char *lavc_param_skip_idct_str = NULL; |
111 static char *lavc_param_skip_frame_str = NULL; | 88 static char *lavc_param_skip_frame_str = NULL; |
112 #endif | |
113 static int lavc_param_threads=1; | 89 static int lavc_param_threads=1; |
114 static int lavc_param_bitexact=0; | 90 static int lavc_param_bitexact=0; |
115 | 91 |
116 m_option_t lavc_decode_opts_conf[]={ | 92 m_option_t lavc_decode_opts_conf[]={ |
117 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL}, | 93 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL}, |
126 {"sb", &lavc_param_skip_bottom, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, | 102 {"sb", &lavc_param_skip_bottom, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, |
127 #ifdef CODEC_FLAG2_FAST | 103 #ifdef CODEC_FLAG2_FAST |
128 {"fast", &lavc_param_fast, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG2_FAST, NULL}, | 104 {"fast", &lavc_param_fast, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG2_FAST, NULL}, |
129 #endif | 105 #endif |
130 {"lowres", &lavc_param_lowres_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | 106 {"lowres", &lavc_param_lowres_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
131 #if LIBAVCODEC_BUILD >= 4758 | |
132 {"skiploopfilter", &lavc_param_skip_loop_filter_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | 107 {"skiploopfilter", &lavc_param_skip_loop_filter_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
133 {"skipidct", &lavc_param_skip_idct_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | 108 {"skipidct", &lavc_param_skip_idct_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
134 {"skipframe", &lavc_param_skip_frame_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | 109 {"skipframe", &lavc_param_skip_frame_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
135 #endif | |
136 {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, | 110 {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, |
137 {"bitexact", &lavc_param_bitexact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL}, | 111 {"bitexact", &lavc_param_bitexact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL}, |
138 {NULL, NULL, 0, 0, 0, 0, NULL} | 112 {NULL, NULL, 0, 0, 0, 0, NULL} |
139 }; | 113 }; |
140 | 114 |
141 #if LIBAVCODEC_BUILD >= 4758 | |
142 static enum AVDiscard str2AVDiscard(char *str) { | 115 static enum AVDiscard str2AVDiscard(char *str) { |
143 if (!str) | 116 if (!str) |
144 return AVDISCARD_DEFAULT; | 117 return AVDISCARD_DEFAULT; |
145 if (strcasecmp(str, "none") == 0) | 118 if (strcasecmp(str, "none") == 0) |
146 return AVDISCARD_NONE; | 119 return AVDISCARD_NONE; |
155 if (strcasecmp(str, "all") == 0) | 128 if (strcasecmp(str, "all") == 0) |
156 return AVDISCARD_ALL; | 129 return AVDISCARD_ALL; |
157 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unknown discard value %s\n", str); | 130 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unknown discard value %s\n", str); |
158 return AVDISCARD_DEFAULT; | 131 return AVDISCARD_DEFAULT; |
159 } | 132 } |
160 #endif | |
161 | 133 |
162 // to set/get/query special features/parameters | 134 // to set/get/query special features/parameters |
163 static int control(sh_video_t *sh,int cmd,void* arg,...){ | 135 static int control(sh_video_t *sh,int cmd,void* arg,...){ |
164 vd_ffmpeg_ctx *ctx = sh->context; | 136 vd_ffmpeg_ctx *ctx = sh->context; |
165 AVCodecContext *avctx = ctx->avctx; | 137 AVCodecContext *avctx = ctx->avctx; |
198 // init driver | 170 // init driver |
199 static int init(sh_video_t *sh){ | 171 static int init(sh_video_t *sh){ |
200 AVCodecContext *avctx; | 172 AVCodecContext *avctx; |
201 vd_ffmpeg_ctx *ctx; | 173 vd_ffmpeg_ctx *ctx; |
202 AVCodec *lavc_codec; | 174 AVCodec *lavc_codec; |
203 #if LIBAVCODEC_BUILD >= 4722 | |
204 int lowres_w=0; | 175 int lowres_w=0; |
205 #endif | |
206 int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); | 176 int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); |
207 | 177 |
208 if(!avcodec_inited){ | 178 if(!avcodec_inited){ |
209 avcodec_init(); | 179 avcodec_init(); |
210 avcodec_register_all(); | 180 avcodec_register_all(); |
228 if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264) | 198 if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264) |
229 ctx->do_dr1=1; | 199 ctx->do_dr1=1; |
230 ctx->b_age= ctx->ip_age[0]= ctx->ip_age[1]= 256*256*256*64; | 200 ctx->b_age= ctx->ip_age[0]= ctx->ip_age[1]= 256*256*256*64; |
231 ctx->ip_count= ctx->b_count= 0; | 201 ctx->ip_count= ctx->b_count= 0; |
232 | 202 |
233 #if LIBAVCODEC_BUILD >= 4645 | |
234 ctx->pic = avcodec_alloc_frame(); | 203 ctx->pic = avcodec_alloc_frame(); |
235 #else | |
236 ctx->pic = avcodec_alloc_picture(); | |
237 #endif | |
238 ctx->avctx = avcodec_alloc_context(); | 204 ctx->avctx = avcodec_alloc_context(); |
239 avctx = ctx->avctx; | 205 avctx = ctx->avctx; |
240 | |
241 #if LIBAVCODEC_BUILD >= 4691 && LIBAVCODEC_BUILD <= 4692 | |
242 if(lavc_codec->capabilities&CODEC_CAP_CR) | |
243 avctx->cr_available = 1; | |
244 #endif | |
245 | 206 |
246 #ifdef HAVE_XVMC | 207 #ifdef HAVE_XVMC |
247 | 208 |
248 #ifdef CODEC_CAP_HWACCEL | 209 #ifdef CODEC_CAP_HWACCEL |
249 if(lavc_codec->capabilities & CODEC_CAP_HWACCEL){ | 210 if(lavc_codec->capabilities & CODEC_CAP_HWACCEL){ |
263 #endif | 224 #endif |
264 if(ctx->do_dr1){ | 225 if(ctx->do_dr1){ |
265 avctx->flags|= CODEC_FLAG_EMU_EDGE; | 226 avctx->flags|= CODEC_FLAG_EMU_EDGE; |
266 avctx->get_buffer= get_buffer; | 227 avctx->get_buffer= get_buffer; |
267 avctx->release_buffer= release_buffer; | 228 avctx->release_buffer= release_buffer; |
268 #if LIBAVCODEC_BUILD >= 4693 | |
269 avctx->reget_buffer= get_buffer; | 229 avctx->reget_buffer= get_buffer; |
270 #endif | |
271 } | 230 } |
272 | 231 |
273 #ifdef CODEC_FLAG_NOT_TRUNCATED | 232 #ifdef CODEC_FLAG_NOT_TRUNCATED |
274 avctx->flags|= CODEC_FLAG_NOT_TRUNCATED; | 233 avctx->flags|= CODEC_FLAG_NOT_TRUNCATED; |
275 #endif | 234 #endif |
282 if(lavc_param_gray) avctx->flags|= CODEC_FLAG_GRAY; | 241 if(lavc_param_gray) avctx->flags|= CODEC_FLAG_GRAY; |
283 #ifdef CODEC_FLAG2_FAST | 242 #ifdef CODEC_FLAG2_FAST |
284 avctx->flags2|= lavc_param_fast; | 243 avctx->flags2|= lavc_param_fast; |
285 #endif | 244 #endif |
286 avctx->codec_tag= sh->format; | 245 avctx->codec_tag= sh->format; |
287 #if LIBAVCODEC_BUILD >= 4679 | |
288 avctx->stream_codec_tag= sh->video.fccHandler; | 246 avctx->stream_codec_tag= sh->video.fccHandler; |
289 #endif | |
290 avctx->idct_algo= lavc_param_idct_algo; | 247 avctx->idct_algo= lavc_param_idct_algo; |
291 avctx->error_concealment= lavc_param_error_concealment; | 248 avctx->error_concealment= lavc_param_error_concealment; |
292 #if LIBAVCODEC_BUILD >= 4642 | |
293 avctx->debug= lavc_param_debug; | 249 avctx->debug= lavc_param_debug; |
294 if (lavc_param_debug) | 250 if (lavc_param_debug) |
295 av_log_set_level(AV_LOG_DEBUG); | 251 av_log_set_level(AV_LOG_DEBUG); |
296 #endif | |
297 #if LIBAVCODEC_BUILD >= 4698 | |
298 avctx->debug_mv= lavc_param_vismv; | 252 avctx->debug_mv= lavc_param_vismv; |
299 #endif | |
300 #if LIBAVCODEC_BUILD >= 4717 | |
301 avctx->skip_top = lavc_param_skip_top; | 253 avctx->skip_top = lavc_param_skip_top; |
302 avctx->skip_bottom= lavc_param_skip_bottom; | 254 avctx->skip_bottom= lavc_param_skip_bottom; |
303 #endif | |
304 #if LIBAVCODEC_BUILD >= 4722 | |
305 if(lavc_param_lowres_str != NULL) | 255 if(lavc_param_lowres_str != NULL) |
306 { | 256 { |
307 sscanf(lavc_param_lowres_str, "%d,%d", &lavc_param_lowres, &lowres_w); | 257 sscanf(lavc_param_lowres_str, "%d,%d", &lavc_param_lowres, &lowres_w); |
308 if(lavc_param_lowres < 1 || lavc_param_lowres > 16 || (lowres_w > 0 && avctx->width < lowres_w)) | 258 if(lavc_param_lowres < 1 || lavc_param_lowres > 16 || (lowres_w > 0 && avctx->width < lowres_w)) |
309 lavc_param_lowres = 0; | 259 lavc_param_lowres = 0; |
310 avctx->lowres = lavc_param_lowres; | 260 avctx->lowres = lavc_param_lowres; |
311 } | 261 } |
312 #endif | |
313 #if LIBAVCODEC_BUILD >= 4758 | |
314 avctx->skip_loop_filter = str2AVDiscard(lavc_param_skip_loop_filter_str); | 262 avctx->skip_loop_filter = str2AVDiscard(lavc_param_skip_loop_filter_str); |
315 avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str); | 263 avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str); |
316 avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str); | 264 avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str); |
317 #endif | |
318 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); | 265 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); |
319 switch (sh->format) { | 266 switch (sh->format) { |
320 case mmioFOURCC('A','V','R','n'): | 267 case mmioFOURCC('A','V','R','n'): |
321 case mmioFOURCC('M','J','P','G'): | 268 case mmioFOURCC('M','J','P','G'): |
322 /* AVRn stores huffman table in AVI header */ | 269 /* AVRn stores huffman table in AVI header */ |
381 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); | 328 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
382 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); | 329 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); |
383 break; | 330 break; |
384 } | 331 } |
385 /* Pass palette to codec */ | 332 /* Pass palette to codec */ |
386 #if LIBAVCODEC_BUILD >= 4689 | |
387 if (sh->bih && (sh->bih->biBitCount <= 8)) { | 333 if (sh->bih && (sh->bih->biBitCount <= 8)) { |
388 avctx->palctrl = calloc(1,sizeof(AVPaletteControl)); | 334 avctx->palctrl = calloc(1,sizeof(AVPaletteControl)); |
389 avctx->palctrl->palette_changed = 1; | 335 avctx->palctrl->palette_changed = 1; |
390 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER)) | 336 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER)) |
391 /* Palette size in biSize */ | 337 /* Palette size in biSize */ |
394 else | 340 else |
395 /* Palette size in biClrUsed */ | 341 /* Palette size in biClrUsed */ |
396 memcpy(avctx->palctrl->palette, sh->bih+1, | 342 memcpy(avctx->palctrl->palette, sh->bih+1, |
397 min(sh->bih->biClrUsed * 4, AVPALETTE_SIZE)); | 343 min(sh->bih->biClrUsed * 4, AVPALETTE_SIZE)); |
398 } | 344 } |
399 #endif | 345 |
400 | |
401 if(sh->bih) | 346 if(sh->bih) |
402 avctx->bits_per_sample= sh->bih->biBitCount; | 347 avctx->bits_per_sample= sh->bih->biBitCount; |
403 | 348 |
404 #if LIBAVCODEC_BUILD >= 4716 | |
405 if(lavc_param_threads > 1) | 349 if(lavc_param_threads > 1) |
406 avcodec_thread_init(avctx, lavc_param_threads); | 350 avcodec_thread_init(avctx, lavc_param_threads); |
407 #endif | |
408 /* open it */ | 351 /* open it */ |
409 if (avcodec_open(avctx, lavc_codec) < 0) { | 352 if (avcodec_open(avctx, lavc_codec) < 0) { |
410 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); | 353 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
411 return 0; | 354 return 0; |
412 } | 355 } |
433 | 376 |
434 if (avcodec_close(avctx) < 0) | 377 if (avcodec_close(avctx) < 0) |
435 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); | 378 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
436 | 379 |
437 av_freep(&avctx->extradata); | 380 av_freep(&avctx->extradata); |
438 #if LIBAVCODEC_BUILD >= 4689 | |
439 av_freep(&avctx->palctrl); | 381 av_freep(&avctx->palctrl); |
440 #endif | |
441 av_freep(&avctx->slice_offset); | 382 av_freep(&avctx->slice_offset); |
442 | 383 |
443 av_freep(&avctx); | 384 av_freep(&avctx); |
444 av_freep(&ctx->pic); | 385 av_freep(&ctx->pic); |
445 if (ctx) | 386 if (ctx) |
446 free(ctx); | 387 free(ctx); |
447 } | 388 } |
448 | 389 |
449 static void draw_slice(struct AVCodecContext *s, | 390 static void draw_slice(struct AVCodecContext *s, |
450 #if LIBAVCODEC_BUILD >= 4670 | |
451 AVFrame *src, int offset[4], | 391 AVFrame *src, int offset[4], |
452 #else | |
453 uint8_t **src, int linesize, | |
454 #endif | |
455 int y, int type, int height){ | 392 int y, int type, int height){ |
456 sh_video_t * sh = s->opaque; | 393 sh_video_t * sh = s->opaque; |
457 int start=0, i; | 394 int start=0, i; |
458 int width= s->width; | 395 int width= s->width; |
459 int skip_stride= ((width<<lavc_param_lowres)+15)>>4; | 396 int skip_stride= ((width<<lavc_param_lowres)+15)>>4; |
460 uint8_t *skip= &s->coded_frame->mbskip_table[(y>>4)*skip_stride]; | 397 uint8_t *skip= &s->coded_frame->mbskip_table[(y>>4)*skip_stride]; |
461 int threshold= s->coded_frame->age; | 398 int threshold= s->coded_frame->age; |
462 #if LIBAVCODEC_BUILD >= 4670 | |
463 uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]}; | 399 uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]}; |
464 #else | |
465 int stride[3]; | |
466 | |
467 stride[0]=linesize; | |
468 if(s->coded_frame->linesize[1]){ | |
469 stride[1]= s->coded_frame->linesize[1]; | |
470 stride[2]= s->coded_frame->linesize[2]; | |
471 }else | |
472 stride[1]=stride[2]=stride[0]/2; | |
473 #endif | |
474 #if 0 | 400 #if 0 |
475 if(s->pict_type!=B_TYPE){ | 401 if(s->pict_type!=B_TYPE){ |
476 for(i=0; i*16<width+16; i++){ | 402 for(i=0; i*16<width+16; i++){ |
477 if(i*16>=width || skip[i]>=threshold){ | 403 if(i*16>=width || skip[i]>=threshold){ |
478 if(start==i) start++; | 404 if(start==i) start++; |
487 } | 413 } |
488 } | 414 } |
489 }else | 415 }else |
490 #endif | 416 #endif |
491 if (y < sh->disp_h) { | 417 if (y < sh->disp_h) { |
492 #if LIBAVCODEC_BUILD >= 4670 | |
493 mpcodecs_draw_slice (sh, source, src->linesize, sh->disp_w, (y+height)<=sh->disp_h?height:sh->disp_h-y, 0, y); | 418 mpcodecs_draw_slice (sh, source, src->linesize, sh->disp_w, (y+height)<=sh->disp_h?height:sh->disp_h-y, 0, y); |
494 #else | |
495 mpcodecs_draw_slice (sh,src, stride, sh->disp_w, (y+height)<=sh->disp_h?height:sh->disp_h-y, 0, y); | |
496 #endif | |
497 } | 419 } |
498 } | 420 } |
499 | 421 |
500 | 422 |
501 static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ | 423 static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ |
502 vd_ffmpeg_ctx *ctx = sh->context; | 424 vd_ffmpeg_ctx *ctx = sh->context; |
503 AVCodecContext *avctx = ctx->avctx; | 425 AVCodecContext *avctx = ctx->avctx; |
504 #if LIBAVCODEC_BUILD >= 4687 | |
505 float aspect= av_q2d(avctx->sample_aspect_ratio) * avctx->width / avctx->height; | 426 float aspect= av_q2d(avctx->sample_aspect_ratio) * avctx->width / avctx->height; |
506 #else | |
507 float aspect= avctx->aspect_ratio; | |
508 #endif | |
509 int width, height; | 427 int width, height; |
510 | 428 |
511 width = avctx->width; | 429 width = avctx->width; |
512 height = avctx->height; | 430 height = avctx->height; |
513 | 431 |
580 int align=15; | 498 int align=15; |
581 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); | 499 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); |
582 if(avctx->pix_fmt == PIX_FMT_YUV410P) | 500 if(avctx->pix_fmt == PIX_FMT_YUV410P) |
583 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) | 501 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) |
584 | 502 |
585 #if LIBAVCODEC_BUILD >= 4691 | |
586 if (pic->buffer_hints) { | 503 if (pic->buffer_hints) { |
587 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints); | 504 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints); |
588 type = MP_IMGTYPE_TEMP; | 505 type = MP_IMGTYPE_TEMP; |
589 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE) | 506 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE) |
590 flags |= MP_IMGFLAG_READABLE; | 507 flags |= MP_IMGFLAG_READABLE; |
598 } | 515 } |
599 flags|=(!avctx->hurry_up && ctx->do_slices) ? | 516 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
600 MP_IMGFLAG_DRAW_CALLBACK:0; | 517 MP_IMGFLAG_DRAW_CALLBACK:0; |
601 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n"); | 518 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n"); |
602 } else { | 519 } else { |
603 #endif | |
604 if(!pic->reference){ | 520 if(!pic->reference){ |
605 ctx->b_count++; | 521 ctx->b_count++; |
606 flags|=(!avctx->hurry_up && ctx->do_slices) ? | 522 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
607 MP_IMGFLAG_DRAW_CALLBACK:0; | 523 MP_IMGFLAG_DRAW_CALLBACK:0; |
608 }else{ | 524 }else{ |
609 ctx->ip_count++; | 525 ctx->ip_count++; |
610 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE | 526 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE |
611 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0); | 527 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0); |
612 } | 528 } |
613 #if LIBAVCODEC_BUILD >= 4691 | |
614 } | 529 } |
615 #endif | |
616 | 530 |
617 if(init_vo(sh,avctx->pix_fmt) < 0){ | 531 if(init_vo(sh,avctx->pix_fmt) < 0){ |
618 avctx->release_buffer= avcodec_default_release_buffer; | 532 avctx->release_buffer= avcodec_default_release_buffer; |
619 avctx->get_buffer= avcodec_default_get_buffer; | 533 avctx->get_buffer= avcodec_default_get_buffer; |
620 return avctx->get_buffer(avctx, pic); | 534 return avctx->get_buffer(avctx, pic); |
621 } | 535 } |
622 | 536 |
623 #if LIBAVCODEC_BUILD >= 4691 | |
624 if (!pic->buffer_hints) { | 537 if (!pic->buffer_hints) { |
625 #endif | |
626 if(ctx->b_count>1 || ctx->ip_count>2){ | 538 if(ctx->b_count>1 || ctx->ip_count>2){ |
627 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_DRIFailure); | 539 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_DRIFailure); |
628 | 540 |
629 ctx->do_dr1=0; //FIXME | 541 ctx->do_dr1=0; //FIXME |
630 avctx->get_buffer= avcodec_default_get_buffer; | 542 avctx->get_buffer= avcodec_default_get_buffer; |
635 type= MP_IMGTYPE_IPB; | 547 type= MP_IMGTYPE_IPB; |
636 }else{ | 548 }else{ |
637 type= MP_IMGTYPE_IP; | 549 type= MP_IMGTYPE_IP; |
638 } | 550 } |
639 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); | 551 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); |
640 #if LIBAVCODEC_BUILD >= 4691 | |
641 } | 552 } |
642 #endif | |
643 | 553 |
644 mpi= mpcodecs_get_image(sh,type, flags, | 554 mpi= mpcodecs_get_image(sh,type, flags, |
645 (width+align)&(~align), (height+align)&(~align)); | 555 (width+align)&(~align), (height+align)&(~align)); |
646 | 556 |
647 // ok, let's see what did we get: | 557 // ok, let's see what did we get: |
650 // nice, filter/vo likes draw_callback :) | 560 // nice, filter/vo likes draw_callback :) |
651 avctx->draw_horiz_band= draw_slice; | 561 avctx->draw_horiz_band= draw_slice; |
652 } else | 562 } else |
653 avctx->draw_horiz_band= NULL; | 563 avctx->draw_horiz_band= NULL; |
654 | 564 |
655 #if LIBAVCODEC_BUILD >= 4689 | |
656 // Palette support: libavcodec copies palette to *data[1] | 565 // Palette support: libavcodec copies palette to *data[1] |
657 if (mpi->bpp == 8) | 566 if (mpi->bpp == 8) |
658 mpi->planes[1] = av_malloc(AVPALETTE_SIZE); | 567 mpi->planes[1] = av_malloc(AVPALETTE_SIZE); |
659 #endif | |
660 | 568 |
661 pic->data[0]= mpi->planes[0]; | 569 pic->data[0]= mpi->planes[0]; |
662 pic->data[1]= mpi->planes[1]; | 570 pic->data[1]= mpi->planes[1]; |
663 pic->data[2]= mpi->planes[2]; | 571 pic->data[2]= mpi->planes[2]; |
664 | 572 |
707 | 615 |
708 ctx->ip_age[0]++; | 616 ctx->ip_age[0]++; |
709 ctx->ip_age[1]++; | 617 ctx->ip_age[1]++; |
710 ctx->b_age=1; | 618 ctx->b_age=1; |
711 } | 619 } |
712 #if LIBAVCODEC_BUILD >= 4644 | |
713 pic->type= FF_BUFFER_TYPE_USER; | 620 pic->type= FF_BUFFER_TYPE_USER; |
714 #endif | |
715 return 0; | 621 return 0; |
716 } | 622 } |
717 | 623 |
718 static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ | 624 static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ |
719 mp_image_t* mpi= pic->opaque; | 625 mp_image_t* mpi= pic->opaque; |
732 | 638 |
733 // Palette support: free palette buffer allocated in get_buffer | 639 // Palette support: free palette buffer allocated in get_buffer |
734 if ( mpi && (mpi->bpp == 8)) | 640 if ( mpi && (mpi->bpp == 8)) |
735 av_freep(&mpi->planes[1]); | 641 av_freep(&mpi->planes[1]); |
736 | 642 |
737 #if LIBAVCODEC_BUILD >= 4644 | |
738 if(pic->type!=FF_BUFFER_TYPE_USER){ | 643 if(pic->type!=FF_BUFFER_TYPE_USER){ |
739 avcodec_default_release_buffer(avctx, pic); | 644 avcodec_default_release_buffer(avctx, pic); |
740 return; | 645 return; |
741 } | 646 } |
742 #endif | |
743 | 647 |
744 for(i=0; i<4; i++){ | 648 for(i=0; i<4; i++){ |
745 pic->data[i]= NULL; | 649 pic->data[i]= NULL; |
746 } | 650 } |
747 //printf("R%X %X\n", pic->linesize[0], pic->data[0]); | 651 //printf("R%X %X\n", pic->linesize[0], pic->data[0]); |
768 int dr1= ctx->do_dr1; | 672 int dr1= ctx->do_dr1; |
769 unsigned char *buf = NULL; | 673 unsigned char *buf = NULL; |
770 | 674 |
771 if(len<=0) return NULL; // skipped frame | 675 if(len<=0) return NULL; // skipped frame |
772 | 676 |
773 #if LIBAVCODEC_BUILD < 4707 | |
774 | |
775 #ifdef HAVE_XVMC | |
776 if( !avctx->xvmc_acceleration ) | |
777 #endif | |
778 | |
779 #else | |
780 //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices | 677 //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices |
781 if (!dr1) | 678 if (!dr1) |
782 #endif | |
783 avctx->draw_horiz_band=NULL; | 679 avctx->draw_horiz_band=NULL; |
784 avctx->opaque=sh; | 680 avctx->opaque=sh; |
785 if(ctx->vo_inited && !(flags&3) && !dr1){ | 681 if(ctx->vo_inited && !(flags&3) && !dr1){ |
786 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | | 682 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | |
787 (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), | 683 (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), |
823 | 719 |
824 dr1= ctx->do_dr1; | 720 dr1= ctx->do_dr1; |
825 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | 721 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); |
826 //printf("repeat: %d\n", pic->repeat_pict); | 722 //printf("repeat: %d\n", pic->repeat_pict); |
827 //-- vstats generation | 723 //-- vstats generation |
828 #if LIBAVCODEC_BUILD >= 4643 | |
829 while(lavc_param_vstats){ // always one time loop | 724 while(lavc_param_vstats){ // always one time loop |
830 static FILE *fvstats=NULL; | 725 static FILE *fvstats=NULL; |
831 char filename[20]; | 726 char filename[20]; |
832 static long long int all_len=0; | 727 static long long int all_len=0; |
833 static int frame_number=0; | 728 static int frame_number=0; |
894 ctx->qp_sum += quality; | 789 ctx->qp_sum += quality; |
895 ctx->inv_qp_sum += 1.0/(double)quality; | 790 ctx->inv_qp_sum += 1.0/(double)quality; |
896 | 791 |
897 break; | 792 break; |
898 } | 793 } |
899 #endif | |
900 //-- | 794 //-- |
901 | 795 |
902 if(!got_picture) return NULL; // skipped image | 796 if(!got_picture) return NULL; // skipped image |
903 | 797 |
904 if(init_vo(sh,avctx->pix_fmt) < 0) return NULL; | 798 if(init_vo(sh,avctx->pix_fmt) < 0) return NULL; |
935 | 829 |
936 /* to comfirm with newer lavc style */ | 830 /* to comfirm with newer lavc style */ |
937 mpi->qscale =pic->qscale_table; | 831 mpi->qscale =pic->qscale_table; |
938 mpi->qstride=pic->qstride; | 832 mpi->qstride=pic->qstride; |
939 mpi->pict_type=pic->pict_type; | 833 mpi->pict_type=pic->pict_type; |
940 #if LIBAVCODEC_BUILD >= 4664 | |
941 mpi->qscale_type= pic->qscale_type; | 834 mpi->qscale_type= pic->qscale_type; |
942 #endif | |
943 #if LIBAVCODEC_BUILD >= 4697 | |
944 mpi->fields = MP_IMGFIELD_ORDERED; | 835 mpi->fields = MP_IMGFIELD_ORDERED; |
945 if(pic->interlaced_frame) mpi->fields |= MP_IMGFIELD_INTERLACED; | 836 if(pic->interlaced_frame) mpi->fields |= MP_IMGFIELD_INTERLACED; |
946 if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST; | 837 if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST; |
947 if(pic->repeat_pict == 1) mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; | 838 if(pic->repeat_pict == 1) mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; |
948 #endif | 839 |
949 | |
950 return mpi; | 840 return mpi; |
951 } | 841 } |
952 | 842 |
953 static enum PixelFormat get_format(struct AVCodecContext * avctx, | 843 static enum PixelFormat get_format(struct AVCodecContext * avctx, |
954 const enum PixelFormat * fmt){ | 844 const enum PixelFormat * fmt){ |