Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 6740:913736867009
10l y422p -> y420p
use uvstride in draw_slices
dr2 support (disabled as mplayer doesnt like slices with width!=picture width sometimes)
| author | michael |
|---|---|
| date | Tue, 16 Jul 2002 12:04:30 +0000 |
| parents | 8a680d5f3a17 |
| children | 93bce3460e2a |
| rev | line source |
|---|---|
| 4952 | 1 #include <stdio.h> |
| 2 #include <stdlib.h> | |
| 3 #include <assert.h> | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "mp_msg.h" | |
| 7 #include "help_mp.h" | |
| 8 | |
| 9 #ifdef USE_LIBAVCODEC | |
| 10 | |
| 11 #include "bswap.h" | |
| 12 | |
| 13 #include "vd_internal.h" | |
| 14 | |
| 15 static vd_info_t info = { | |
| 16 "FFmpeg's libavcodec codec family", | |
| 17 "ffmpeg", | |
| 18 VFM_FFMPEG, | |
| 19 "A'rpi", | |
| 20 "http://ffmpeg.sf.net", | |
| 21 "native codecs" | |
| 22 }; | |
| 23 | |
| 24 LIBVD_EXTERN(ffmpeg) | |
| 25 | |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
26 #include "../postproc/rgb2rgb.h" |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
27 |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
28 |
| 4952 | 29 #ifdef USE_LIBAVCODEC_SO |
| 30 #include <libffmpeg/avcodec.h> | |
| 31 #else | |
| 32 #include "libavcodec/avcodec.h" | |
| 33 #endif | |
| 34 | |
| 35 int avcodec_inited=0; | |
| 36 | |
| 5517 | 37 #ifdef FF_POSTPROCESS |
| 38 int quant_store[MBR+1][MBC+1]; | |
| 39 #endif | |
| 40 | |
| 5280 | 41 typedef struct { |
| 42 AVCodecContext *avctx; | |
| 5482 | 43 int last_aspect; |
| 44 int do_slices; | |
| 6734 | 45 int do_dr1; |
| 5482 | 46 int vo_inited; |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
47 int convert; |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
48 int yuy2_support; |
| 6681 | 49 #if LIBAVCODEC_BUILD >= 4615 |
| 50 int yvu9_support; | |
| 51 #endif | |
| 5280 | 52 } vd_ffmpeg_ctx; |
| 53 | |
| 4952 | 54 //#ifdef FF_POSTPROCESS |
| 55 //unsigned int lavc_pp=0; | |
| 56 //#endif | |
| 57 | |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
58 #include "cfgparser.h" |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
59 |
| 6739 | 60 static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type); |
| 61 | |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
62 static int lavc_param_workaround_bugs=0; |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
63 static int lavc_param_error_resilience=0; |
| 6355 | 64 static int lavc_param_gray=0; |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
65 |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
66 struct config lavc_decode_opts_conf[]={ |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
67 #if LIBAVCODEC_BUILD >= 4611 |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
68 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
69 {"ver", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, -1, 99, NULL}, |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
70 #endif |
| 6355 | 71 #if LIBAVCODEC_BUILD >= 4614 |
| 72 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, | |
| 73 #endif | |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
74 {NULL, NULL, 0, 0, 0, 0, NULL} |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
75 }; |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
76 |
| 4952 | 77 // to set/get/query special features/parameters |
| 78 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
79 vd_ffmpeg_ctx *ctx = sh->context; |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
80 switch(cmd){ |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
81 case VDCTRL_QUERY_FORMAT: |
| 6739 | 82 switch(*((int*)arg)){ |
| 83 case IMGFMT_YV12: | |
| 84 case IMGFMT_IYUV: | |
| 85 case IMGFMT_I420: | |
| 6740 | 86 if(ctx->yvu9_support) return CONTROL_FALSE; |
| 87 else return CONTROL_TRUE; | |
| 6739 | 88 case IMGFMT_YUY2: |
| 89 if(ctx->yuy2_support) return CONTROL_TRUE; | |
| 90 return CONTROL_FALSE; | |
| 6681 | 91 #if LIBAVCODEC_BUILD >= 4615 |
| 6739 | 92 case IMGFMT_YVU9: |
| 93 if(ctx->yvu9_support) return CONTROL_TRUE; | |
| 94 return CONTROL_FALSE; | |
| 6681 | 95 #endif |
| 6739 | 96 default: |
| 97 return CONTROL_FALSE; | |
| 98 | |
| 99 } | |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
100 } |
| 4952 | 101 return CONTROL_UNKNOWN; |
| 102 } | |
| 103 | |
| 104 // init driver | |
| 105 static int init(sh_video_t *sh){ | |
| 5280 | 106 AVCodecContext *avctx; |
| 107 vd_ffmpeg_ctx *ctx; | |
|
5457
f248c9e86423
config vo only if aspect really changed and width&&height isn't changed (if w||h changes, we set it later)
alex
parents:
5331
diff
changeset
|
108 AVCodec *lavc_codec; |
| 4952 | 109 |
| 110 if(!avcodec_inited){ | |
| 111 avcodec_init(); | |
| 112 avcodec_register_all(); | |
| 113 avcodec_inited=1; | |
| 114 } | |
| 5280 | 115 |
| 116 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
| 117 if (!ctx) | |
| 118 return(0); | |
| 119 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
| 4952 | 120 |
|
5457
f248c9e86423
config vo only if aspect really changed and width&&height isn't changed (if w||h changes, we set it later)
alex
parents:
5331
diff
changeset
|
121 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); |
|
f248c9e86423
config vo only if aspect really changed and width&&height isn't changed (if w||h changes, we set it later)
alex
parents:
5331
diff
changeset
|
122 if(!lavc_codec){ |
| 4952 | 123 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
| 124 return 0; | |
| 125 } | |
| 5482 | 126 |
|
5494
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
127 if(vd_use_slices && lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) |
|
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
128 ctx->do_slices=1; |
| 6734 | 129 |
| 6736 | 130 #if LIBAVCODEC_BUILD > 4615 |
| 6735 | 131 if(lavc_codec->capabilities&CODEC_CAP_DR1) |
| 6734 | 132 ctx->do_dr1=1; |
| 6736 | 133 #endif |
| 134 | |
| 5280 | 135 ctx->avctx = malloc(sizeof(AVCodecContext)); |
| 136 memset(ctx->avctx, 0, sizeof(AVCodecContext)); | |
| 137 avctx = ctx->avctx; | |
| 6739 | 138 |
| 139 #if LIBAVCODEC_BUILD > 4615 | |
| 140 if(ctx->do_dr1){ | |
| 141 avctx->flags|= CODEC_FLAG_EMU_EDGE | CODEC_FLAG_DR1; | |
| 142 avctx->get_buffer_callback= get_buffer; | |
| 143 } | |
| 144 #endif | |
| 4952 | 145 |
| 5280 | 146 avctx->width = sh->disp_w; |
| 147 avctx->height= sh->disp_h; | |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
148 #if LIBAVCODEC_BUILD >= 4611 |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
149 avctx->workaround_bugs= lavc_param_workaround_bugs; |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
150 avctx->error_resilience= lavc_param_error_resilience; |
|
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
151 #endif |
| 6355 | 152 #if LIBAVCODEC_BUILD >= 4614 |
| 153 if(lavc_param_gray) avctx->flags|= CODEC_FLAG_GRAY; | |
| 154 #endif | |
|
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
155 |
| 5280 | 156 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); |
| 4952 | 157 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) |
| 5280 | 158 avctx->sub_id = 3; |
| 5939 | 159 #if LIBAVCODEC_BUILD >= 4605 |
| 160 /* AVRn stores huffman table in AVI header */ | |
| 161 /* Pegasus MJPEG stores it also in AVI header, but it uses the common | |
| 162 MJPG fourcc :( */ | |
| 5940 | 163 if (sh->bih && (sh->bih->biSize != sizeof(BITMAPINFOHEADER)) && |
| 5939 | 164 (sh->format == mmioFOURCC('A','V','R','n') || |
| 165 sh->format == mmioFOURCC('M','J','P','G'))) | |
| 166 { | |
| 167 avctx->flags |= CODEC_FLAG_EXTERN_HUFF; | |
| 168 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); | |
| 169 avctx->extradata = malloc(avctx->extradata_size); | |
| 170 memcpy(avctx->extradata, sh->bih+sizeof(BITMAPINFOHEADER), | |
| 171 avctx->extradata_size); | |
| 172 | |
| 173 #if 0 | |
| 174 { | |
| 175 int x; | |
| 176 uint8_t *p = avctx->extradata; | |
| 177 | |
| 178 for (x=0; x<avctx->extradata_size; x++) | |
| 179 printf("[%x] ", p[x]); | |
| 180 printf("\n"); | |
| 181 } | |
| 182 #endif | |
| 183 } | |
| 184 #endif | |
| 4952 | 185 /* open it */ |
|
5457
f248c9e86423
config vo only if aspect really changed and width&&height isn't changed (if w||h changes, we set it later)
alex
parents:
5331
diff
changeset
|
186 if (avcodec_open(avctx, lavc_codec) < 0) { |
| 4952 | 187 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
| 188 return 0; | |
| 189 } | |
| 190 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
| 5482 | 191 ctx->last_aspect=-3; |
| 5510 | 192 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
| 4952 | 193 } |
| 194 | |
| 195 // uninit driver | |
| 196 static void uninit(sh_video_t *sh){ | |
| 5280 | 197 vd_ffmpeg_ctx *ctx = sh->context; |
| 198 AVCodecContext *avctx = ctx->avctx; | |
| 199 | |
| 200 if (avcodec_close(avctx) < 0) | |
| 4952 | 201 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
| 5939 | 202 |
| 203 #if LIBAVCODEC_BUILD >= 4605 | |
| 204 if (avctx->extradata_size) | |
| 205 free(avctx->extradata); | |
| 206 #endif | |
| 207 | |
| 5280 | 208 if (avctx) |
| 209 free(avctx); | |
| 210 if (ctx) | |
| 211 free(ctx); | |
| 4952 | 212 } |
| 213 | |
| 5482 | 214 static void draw_slice(struct AVCodecContext *s, |
| 215 UINT8 **src, int linesize, | |
| 216 int y, int width, int height){ | |
| 6710 | 217 sh_video_t * sh = s->opaque; |
| 5482 | 218 int stride[3]; |
| 6740 | 219 int start=0, i; |
| 220 int skip_stride= (s->width+15)>>4; | |
| 221 UINT8 *skip= &s->mbskip_table[(y>>4)*skip_stride]; | |
| 222 #if LIBAVCODEC_BUILD > 4615 | |
| 223 int threshold= s->pict_type==B_TYPE ? -99 : s->dr_ip_buffer_count; | |
| 224 #endif | |
| 5482 | 225 |
| 226 stride[0]=linesize; | |
| 6740 | 227 #if LIBAVCODEC_BUILD > 4615 |
| 228 if(s->dr_uvstride) | |
| 229 stride[1]=stride[2]= s->dr_uvstride; | |
| 230 else | |
| 231 #endif | |
| 232 stride[1]=stride[2]=stride[0]/2; | |
| 233 #if 0 | |
| 234 if(s->pict_type!=B_TYPE){ | |
| 235 for(i=0; i*16<width+16; i++){ | |
| 236 if(i*16>=width || skip[i]>=threshold){ | |
| 237 if(start==i) start++; | |
| 238 else{ | |
| 239 UINT8 *src2[3]= {src[0] + start*16, | |
| 240 src[1] + start*8, | |
| 241 src[2] + start*8}; | |
| 242 //printf("%2d-%2d x %d\n", start, i, y); | |
| 243 mpcodecs_draw_slice (sh,src2, stride, (i-start)*16, height, start*16, y); | |
| 244 start= i+1; | |
| 245 } | |
| 246 } | |
| 247 } | |
| 248 }else | |
| 249 #endif | |
| 250 mpcodecs_draw_slice (sh,src, stride, width, height, 0, y); | |
| 5482 | 251 } |
| 4952 | 252 |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
253 static int init_vo(sh_video_t *sh){ |
| 5280 | 254 vd_ffmpeg_ctx *ctx = sh->context; |
| 255 AVCodecContext *avctx = ctx->avctx; | |
| 4952 | 256 |
| 5482 | 257 if (avctx->aspect_ratio_info != ctx->last_aspect || |
| 258 avctx->width != sh->disp_w || | |
| 259 avctx->height != sh->disp_h || | |
| 260 !ctx->vo_inited) | |
| 5280 | 261 { |
| 262 ctx->last_aspect = avctx->aspect_ratio_info; | |
| 263 switch(avctx->aspect_ratio_info) | |
| 264 { | |
| 265 case FF_ASPECT_4_3_625: | |
| 266 case FF_ASPECT_4_3_525: | |
| 267 sh->aspect = 4.0/3.0; | |
| 268 break; | |
| 269 case FF_ASPECT_16_9_625: | |
| 270 case FF_ASPECT_16_9_525: | |
| 271 sh->aspect = 16.0/9.0; | |
| 272 break; | |
| 273 case FF_ASPECT_SQUARE: | |
| 274 sh->aspect = 0.0; | |
| 275 break; | |
| 276 } | |
| 5482 | 277 sh->disp_w = avctx->width; |
| 278 sh->disp_h = avctx->height; | |
| 279 ctx->vo_inited=1; | |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
280 ctx->yuy2_support=(avctx->pix_fmt==PIX_FMT_YUV422P); |
| 6681 | 281 #if LIBAVCODEC_BUILD >= 4615 |
| 282 ctx->yvu9_support=(avctx->pix_fmt==PIX_FMT_YUV410P); | |
| 283 #endif | |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
284 if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
285 ctx->yuy2_support ? IMGFMT_YUY2 : IMGFMT_YV12)) |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
286 return -1; |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
287 ctx->convert=(sh->codec->outfmt[sh->outfmtidx]==IMGFMT_YUY2); |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
288 } |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
289 return 0; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
290 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
291 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
292 #if LIBAVCODEC_BUILD > 4615 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
293 static void get_buffer(struct AVCodecContext *avctx, int width, int height, int pict_type){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
294 sh_video_t * sh = avctx->opaque; |
| 6734 | 295 vd_ffmpeg_ctx *ctx = sh->context; |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
296 mp_image_t* mpi=NULL; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
297 // int flags= MP_IMGFLAG_ALIGNED_STRIDE; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
298 int flags= MP_IMGFLAG_ACCEPT_STRIDE; |
| 6737 | 299 int type= MP_IMGTYPE_IPB; |
| 6738 | 300 int align=15; |
| 301 | |
| 302 if(avctx->pix_fmt == PIX_FMT_YUV410P) | |
| 303 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) | |
| 304 | |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
305 if(init_vo(sh)<0){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
306 printf("init_vo failed\n"); |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
307 return; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
308 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
309 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
310 if(pict_type==B_TYPE) |
| 6734 | 311 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
| 312 MP_IMGFLAG_DRAW_CALLBACK:0; | |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
313 else |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
314 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
315 |
| 6737 | 316 #if LIBAVCODEC_BUILD > 4616 |
| 317 if(avctx->has_b_frames){ | |
| 318 type= MP_IMGTYPE_IPB; | |
| 319 }else{ | |
| 320 type= MP_IMGTYPE_IP; | |
| 321 } | |
| 322 #endif | |
| 323 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); | |
| 324 | |
| 325 mpi= mpcodecs_get_image(sh,type, flags, | |
| 6738 | 326 (width+align)&(~align), (height+align)&(~align)); |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
327 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
328 // ok, lets see what did we get: |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
329 if( mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
330 !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
331 // nice, filter/vo likes draw_callback :) |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
332 avctx->draw_horiz_band= draw_slice; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
333 } else |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
334 avctx->draw_horiz_band= NULL; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
335 avctx->dr_buffer[0]= mpi->planes[0]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
336 avctx->dr_buffer[1]= mpi->planes[1]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
337 avctx->dr_buffer[2]= mpi->planes[2]; |
| 6734 | 338 |
| 339 if(avctx->dr_stride && avctx->dr_stride !=mpi->stride[0]){ | |
| 340 mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: stride changed\n"); | |
| 341 } | |
| 342 | |
| 343 avctx->dr_stride = mpi->stride[0]; | |
| 6737 | 344 avctx->dr_uvstride = mpi->stride[1]; |
| 6734 | 345 |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
346 avctx->dr_opaque_frame = mpi; |
| 6737 | 347 avctx->dr_ip_buffer_count=2; //FIXME |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
348 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
349 #endif |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
350 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
351 // decode a frame |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
352 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
353 int got_picture=0; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
354 int ret; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
355 AVPicture lavc_picture; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
356 vd_ffmpeg_ctx *ctx = sh->context; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
357 AVCodecContext *avctx = ctx->avctx; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
358 mp_image_t* mpi=NULL; |
| 6737 | 359 int dr1= ctx->do_dr1; |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
360 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
361 if(len<=0) return NULL; // skipped frame |
| 6734 | 362 |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
363 avctx->draw_horiz_band=NULL; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
364 avctx->opaque=sh; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
365 if(ctx->vo_inited && !ctx->convert && !(flags&3) && !dr1){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
366 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
367 (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
368 sh->disp_w, sh->disp_h); |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
369 if(mpi && mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
370 // vd core likes slices! |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
371 avctx->draw_horiz_band=draw_slice; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
372 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
373 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
374 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
375 #if LIBAVCODEC_BUILD > 4603 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
376 avctx->hurry_up=(flags&3)?((flags&2)?2:1):0; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
377 #endif |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
378 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
379 ret = avcodec_decode_video(avctx, &lavc_picture, |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
380 &got_picture, data, len); |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
381 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
382 if(!got_picture) return NULL; // skipped image |
| 6738 | 383 |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
384 if(init_vo(sh)<0) return NULL; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
385 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
386 #if LIBAVCODEC_BUILD > 4615 |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
387 if(dr1 && avctx->dr_opaque_frame){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
388 mpi= (mp_image_t*)avctx->dr_opaque_frame; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
389 } |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
390 #endif |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
391 |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
392 if(!mpi && ctx->convert){ |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
393 // do yuv422p -> yuy2 conversion: |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
394 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
395 avctx->width, avctx->height); |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
396 if(!mpi) return NULL; |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
397 yuv422ptoyuy2(lavc_picture.data[0],lavc_picture.data[1],lavc_picture.data[2], |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
398 mpi->planes[0],avctx->width,avctx->height, |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
399 lavc_picture.linesize[0],lavc_picture.linesize[1],mpi->stride[0]); |
|
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
400 return mpi; |
| 5280 | 401 } |
| 4952 | 402 |
| 5482 | 403 if(!mpi) |
| 4952 | 404 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
| 5280 | 405 avctx->width, avctx->height); |
| 4952 | 406 if(!mpi){ // temporary! |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
407 printf("couldn't allocate image for codec\n"); |
| 4952 | 408 return NULL; |
| 409 } | |
| 410 | |
|
6733
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
411 if(!dr1){ |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
412 mpi->planes[0]=lavc_picture.data[0]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
413 mpi->planes[1]=lavc_picture.data[1]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
414 mpi->planes[2]=lavc_picture.data[2]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
415 mpi->stride[0]=lavc_picture.linesize[0]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
416 mpi->stride[1]=lavc_picture.linesize[1]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
417 mpi->stride[2]=lavc_picture.linesize[2]; |
|
3b1f37fc0693
direct rendering method 1 (disabled currently as its not bugfree / finished yet, just set dr1=1 if u want to try it)
michael
parents:
6710
diff
changeset
|
418 } |
| 4952 | 419 |
| 5280 | 420 if(avctx->pix_fmt==PIX_FMT_YUV422P){ |
|
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
421 // we have 422p but user wants yv12 (420p) |
| 4952 | 422 mpi->stride[1]*=2; |
| 423 mpi->stride[2]*=2; | |
| 424 } | |
| 425 | |
| 6665 | 426 /* to comfirm with newer lavc style */ |
| 427 #if !defined(FF_POSTPROCESS) && (LIBAVCODEC_BUILD > 4612) | |
| 428 mpi->qscale=avctx->quant_store; | |
| 429 #if LIBAVCODEC_BUILD > 4613 | |
| 430 mpi->qstride=avctx->qstride; | |
| 431 #else | |
| 432 mpi->qstride=MBC+1; | |
| 433 #endif | |
| 434 #else ifdef FF_POSTPROCESS | |
| 5517 | 435 mpi->qscale=&quant_store[0][0]; |
| 436 mpi->qstride=MBC+1; | |
| 437 #endif | |
| 438 | |
| 4952 | 439 return mpi; |
| 440 } | |
| 441 | |
| 442 #endif | |
| 443 |
