Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 6739:8a680d5f3a17
10l (init flags after init ...)
author | michael |
---|---|
date | Tue, 16 Jul 2002 00:56:12 +0000 |
parents | 77f2713ae7fd |
children | 913736867009 |
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: | |
86 if(ctx->yuy2_support || ctx->yvu9_support) return CONTROL_FALSE; | |
87 else return CONTROL_TRUE; | |
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]; |
219 | |
220 stride[0]=linesize; | |
221 stride[1]=stride[2]=stride[0]/2; | |
222 | |
6710 | 223 mpcodecs_draw_slice (sh,src, stride, width, height, 0, y); |
5482 | 224 } |
4952 | 225 |
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
|
226 static int init_vo(sh_video_t *sh){ |
5280 | 227 vd_ffmpeg_ctx *ctx = sh->context; |
228 AVCodecContext *avctx = ctx->avctx; | |
4952 | 229 |
5482 | 230 if (avctx->aspect_ratio_info != ctx->last_aspect || |
231 avctx->width != sh->disp_w || | |
232 avctx->height != sh->disp_h || | |
233 !ctx->vo_inited) | |
5280 | 234 { |
235 ctx->last_aspect = avctx->aspect_ratio_info; | |
236 switch(avctx->aspect_ratio_info) | |
237 { | |
238 case FF_ASPECT_4_3_625: | |
239 case FF_ASPECT_4_3_525: | |
240 sh->aspect = 4.0/3.0; | |
241 break; | |
242 case FF_ASPECT_16_9_625: | |
243 case FF_ASPECT_16_9_525: | |
244 sh->aspect = 16.0/9.0; | |
245 break; | |
246 case FF_ASPECT_SQUARE: | |
247 sh->aspect = 0.0; | |
248 break; | |
249 } | |
5482 | 250 sh->disp_w = avctx->width; |
251 sh->disp_h = avctx->height; | |
252 ctx->vo_inited=1; | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
253 ctx->yuy2_support=(avctx->pix_fmt==PIX_FMT_YUV422P); |
6681 | 254 #if LIBAVCODEC_BUILD >= 4615 |
255 ctx->yvu9_support=(avctx->pix_fmt==PIX_FMT_YUV410P); | |
256 #endif | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
257 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
|
258 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
|
259 return -1; |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
260 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
|
261 } |
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
|
262 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
|
263 } |
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
|
264 |
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
|
265 #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
|
266 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
|
267 sh_video_t * sh = avctx->opaque; |
6734 | 268 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
|
269 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
|
270 // 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
|
271 int flags= MP_IMGFLAG_ACCEPT_STRIDE; |
6737 | 272 int type= MP_IMGTYPE_IPB; |
6738 | 273 int align=15; |
274 | |
275 if(avctx->pix_fmt == PIX_FMT_YUV410P) | |
276 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) | |
277 | |
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
|
278 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
|
279 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
|
280 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
|
281 } |
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
|
282 |
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
|
283 if(pict_type==B_TYPE) |
6734 | 284 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
285 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
|
286 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
|
287 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
|
288 |
6737 | 289 #if LIBAVCODEC_BUILD > 4616 |
290 if(avctx->has_b_frames){ | |
291 type= MP_IMGTYPE_IPB; | |
292 }else{ | |
293 type= MP_IMGTYPE_IP; | |
294 } | |
295 #endif | |
296 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); | |
297 | |
298 mpi= mpcodecs_get_image(sh,type, flags, | |
6738 | 299 (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
|
300 |
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
|
301 // 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
|
302 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
|
303 !(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
|
304 // 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
|
305 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
|
306 } 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
|
307 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
|
308 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
|
309 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
|
310 avctx->dr_buffer[2]= mpi->planes[2]; |
6734 | 311 |
312 if(avctx->dr_stride && avctx->dr_stride !=mpi->stride[0]){ | |
313 mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: stride changed\n"); | |
314 } | |
315 | |
316 avctx->dr_stride = mpi->stride[0]; | |
6737 | 317 avctx->dr_uvstride = mpi->stride[1]; |
6734 | 318 |
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
|
319 avctx->dr_opaque_frame = mpi; |
6737 | 320 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
|
321 } |
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
|
322 #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
|
323 |
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
|
324 // 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 mp_image_t* mpi=NULL; |
6737 | 332 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
|
333 |
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 if(len<=0) return NULL; // skipped frame |
6734 | 335 |
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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 (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
|
341 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
|
342 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
|
343 // 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
|
344 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
|
345 } |
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 } |
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
|
347 |
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 #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
|
349 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
|
350 #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
|
351 |
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 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
|
353 &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
|
354 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
|
355 if(!got_picture) return NULL; // skipped image |
6738 | 356 |
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
|
357 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
|
358 |
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
|
359 #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
|
360 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
|
361 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
|
362 } |
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 #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
|
364 |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
365 if(!mpi && ctx->convert){ |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
366 // do yuv422p -> yuy2 conversion: |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
367 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
|
368 avctx->width, avctx->height); |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
369 if(!mpi) return NULL; |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
370 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
|
371 mpi->planes[0],avctx->width,avctx->height, |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
372 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
|
373 return mpi; |
5280 | 374 } |
4952 | 375 |
5482 | 376 if(!mpi) |
4952 | 377 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
5280 | 378 avctx->width, avctx->height); |
4952 | 379 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
|
380 printf("couldn't allocate image for codec\n"); |
4952 | 381 return NULL; |
382 } | |
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(!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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 } |
4952 | 392 |
5280 | 393 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
|
394 // we have 422p but user wants yv12 (420p) |
4952 | 395 mpi->stride[1]*=2; |
396 mpi->stride[2]*=2; | |
397 } | |
398 | |
6665 | 399 /* to comfirm with newer lavc style */ |
400 #if !defined(FF_POSTPROCESS) && (LIBAVCODEC_BUILD > 4612) | |
401 mpi->qscale=avctx->quant_store; | |
402 #if LIBAVCODEC_BUILD > 4613 | |
403 mpi->qstride=avctx->qstride; | |
404 #else | |
405 mpi->qstride=MBC+1; | |
406 #endif | |
407 #else ifdef FF_POSTPROCESS | |
5517 | 408 mpi->qscale=&quant_store[0][0]; |
409 mpi->qstride=MBC+1; | |
410 #endif | |
411 | |
4952 | 412 return mpi; |
413 } | |
414 | |
415 #endif | |
416 |