Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 6735:847781af99a4
dont depend upon vo_directrendering
author | michael |
---|---|
date | Sun, 14 Jul 2002 21:57:03 +0000 |
parents | e614de962b6e |
children | eccd31a0584f |
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 |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
60 static int lavc_param_workaround_bugs=0; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
61 static int lavc_param_error_resilience=0; |
6355 | 62 static int lavc_param_gray=0; |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
63 |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
64 struct config lavc_decode_opts_conf[]={ |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
65 #if LIBAVCODEC_BUILD >= 4611 |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
66 {"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
|
67 {"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
|
68 #endif |
6355 | 69 #if LIBAVCODEC_BUILD >= 4614 |
70 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, | |
71 #endif | |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
72 {NULL, NULL, 0, 0, 0, 0, NULL} |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
73 }; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
74 |
4952 | 75 // to set/get/query special features/parameters |
76 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
|
77 vd_ffmpeg_ctx *ctx = sh->context; |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
78 switch(cmd){ |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
79 case VDCTRL_QUERY_FORMAT: |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
80 if( (*((int*)arg)) == IMGFMT_YV12 ) return CONTROL_TRUE; |
5707 | 81 if( (*((int*)arg)) == IMGFMT_IYUV ) return CONTROL_TRUE; |
82 if( (*((int*)arg)) == IMGFMT_I420 ) return CONTROL_TRUE; | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
83 if( (*((int*)arg)) == IMGFMT_YUY2 && ctx->yuy2_support ) return CONTROL_TRUE; |
6681 | 84 #if LIBAVCODEC_BUILD >= 4615 |
85 if( (*((int*)arg)) == IMGFMT_YVU9 && ctx->yvu9_support ) return CONTROL_TRUE; | |
86 #endif | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
87 return CONTROL_FALSE; |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
88 } |
4952 | 89 return CONTROL_UNKNOWN; |
90 } | |
91 | |
92 // init driver | |
93 static int init(sh_video_t *sh){ | |
5280 | 94 AVCodecContext *avctx; |
95 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
|
96 AVCodec *lavc_codec; |
4952 | 97 |
98 if(!avcodec_inited){ | |
99 avcodec_init(); | |
100 avcodec_register_all(); | |
101 avcodec_inited=1; | |
102 } | |
5280 | 103 |
104 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
105 if (!ctx) | |
106 return(0); | |
107 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
4952 | 108 |
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
|
109 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
|
110 if(!lavc_codec){ |
4952 | 111 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
112 return 0; | |
113 } | |
5482 | 114 |
5494
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
115 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
|
116 ctx->do_slices=1; |
6734 | 117 |
6735 | 118 if(lavc_codec->capabilities&CODEC_CAP_DR1) |
6734 | 119 ctx->do_dr1=1; |
4952 | 120 |
5280 | 121 ctx->avctx = malloc(sizeof(AVCodecContext)); |
122 memset(ctx->avctx, 0, sizeof(AVCodecContext)); | |
123 avctx = ctx->avctx; | |
4952 | 124 |
5280 | 125 avctx->width = sh->disp_w; |
126 avctx->height= sh->disp_h; | |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
127 #if LIBAVCODEC_BUILD >= 4611 |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
128 avctx->workaround_bugs= lavc_param_workaround_bugs; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
129 avctx->error_resilience= lavc_param_error_resilience; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
130 #endif |
6355 | 131 #if LIBAVCODEC_BUILD >= 4614 |
132 if(lavc_param_gray) avctx->flags|= CODEC_FLAG_GRAY; | |
133 #endif | |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
134 |
5280 | 135 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); |
4952 | 136 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) |
5280 | 137 avctx->sub_id = 3; |
5939 | 138 #if LIBAVCODEC_BUILD >= 4605 |
139 /* AVRn stores huffman table in AVI header */ | |
140 /* Pegasus MJPEG stores it also in AVI header, but it uses the common | |
141 MJPG fourcc :( */ | |
5940 | 142 if (sh->bih && (sh->bih->biSize != sizeof(BITMAPINFOHEADER)) && |
5939 | 143 (sh->format == mmioFOURCC('A','V','R','n') || |
144 sh->format == mmioFOURCC('M','J','P','G'))) | |
145 { | |
146 avctx->flags |= CODEC_FLAG_EXTERN_HUFF; | |
147 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); | |
148 avctx->extradata = malloc(avctx->extradata_size); | |
149 memcpy(avctx->extradata, sh->bih+sizeof(BITMAPINFOHEADER), | |
150 avctx->extradata_size); | |
151 | |
152 #if 0 | |
153 { | |
154 int x; | |
155 uint8_t *p = avctx->extradata; | |
156 | |
157 for (x=0; x<avctx->extradata_size; x++) | |
158 printf("[%x] ", p[x]); | |
159 printf("\n"); | |
160 } | |
161 #endif | |
162 } | |
163 #endif | |
4952 | 164 /* 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
|
165 if (avcodec_open(avctx, lavc_codec) < 0) { |
4952 | 166 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
167 return 0; | |
168 } | |
169 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
5482 | 170 ctx->last_aspect=-3; |
5510 | 171 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
4952 | 172 } |
173 | |
174 // uninit driver | |
175 static void uninit(sh_video_t *sh){ | |
5280 | 176 vd_ffmpeg_ctx *ctx = sh->context; |
177 AVCodecContext *avctx = ctx->avctx; | |
178 | |
179 if (avcodec_close(avctx) < 0) | |
4952 | 180 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
5939 | 181 |
182 #if LIBAVCODEC_BUILD >= 4605 | |
183 if (avctx->extradata_size) | |
184 free(avctx->extradata); | |
185 #endif | |
186 | |
5280 | 187 if (avctx) |
188 free(avctx); | |
189 if (ctx) | |
190 free(ctx); | |
4952 | 191 } |
192 | |
5482 | 193 static void draw_slice(struct AVCodecContext *s, |
194 UINT8 **src, int linesize, | |
195 int y, int width, int height){ | |
6710 | 196 sh_video_t * sh = s->opaque; |
5482 | 197 int stride[3]; |
198 | |
199 stride[0]=linesize; | |
200 stride[1]=stride[2]=stride[0]/2; | |
201 | |
6710 | 202 mpcodecs_draw_slice (sh,src, stride, width, height, 0, y); |
5482 | 203 } |
4952 | 204 |
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
|
205 static int init_vo(sh_video_t *sh){ |
5280 | 206 vd_ffmpeg_ctx *ctx = sh->context; |
207 AVCodecContext *avctx = ctx->avctx; | |
4952 | 208 |
5482 | 209 if (avctx->aspect_ratio_info != ctx->last_aspect || |
210 avctx->width != sh->disp_w || | |
211 avctx->height != sh->disp_h || | |
212 !ctx->vo_inited) | |
5280 | 213 { |
214 ctx->last_aspect = avctx->aspect_ratio_info; | |
215 switch(avctx->aspect_ratio_info) | |
216 { | |
217 case FF_ASPECT_4_3_625: | |
218 case FF_ASPECT_4_3_525: | |
219 sh->aspect = 4.0/3.0; | |
220 break; | |
221 case FF_ASPECT_16_9_625: | |
222 case FF_ASPECT_16_9_525: | |
223 sh->aspect = 16.0/9.0; | |
224 break; | |
225 case FF_ASPECT_SQUARE: | |
226 sh->aspect = 0.0; | |
227 break; | |
228 } | |
5482 | 229 sh->disp_w = avctx->width; |
230 sh->disp_h = avctx->height; | |
231 ctx->vo_inited=1; | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
232 ctx->yuy2_support=(avctx->pix_fmt==PIX_FMT_YUV422P); |
6681 | 233 #if LIBAVCODEC_BUILD >= 4615 |
234 ctx->yvu9_support=(avctx->pix_fmt==PIX_FMT_YUV410P); | |
235 #endif | |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
236 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
|
237 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
|
238 return -1; |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
239 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
|
240 } |
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
|
241 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
|
242 } |
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
|
243 |
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
|
244 #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
|
245 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
|
246 sh_video_t * sh = avctx->opaque; |
6734 | 247 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
|
248 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
|
249 // 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
|
250 int flags= MP_IMGFLAG_ACCEPT_STRIDE; |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
251 |
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
|
252 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
|
253 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
|
254 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
|
255 } |
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
|
256 |
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
|
257 if(pict_type==B_TYPE) |
6734 | 258 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
259 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
|
260 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
|
261 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
|
262 |
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 mpi= mpcodecs_get_image(sh,MP_IMGTYPE_IPB, 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
|
264 // MN: arpi, is the next line ok? (i doubt it), its needed for height%16!=0 files |
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 (width+15)&(~15), (height+15)&(~15)); |
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 |
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 // 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
|
268 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
|
269 !(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
|
270 // 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
|
271 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
|
272 } 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
|
273 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
|
274 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
|
275 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
|
276 avctx->dr_buffer[2]= mpi->planes[2]; |
6734 | 277 |
278 if(avctx->dr_stride && avctx->dr_stride !=mpi->stride[0]){ | |
279 mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: stride changed\n"); | |
280 } | |
281 | |
282 avctx->dr_stride = mpi->stride[0]; | |
283 | |
284 if(mpi->stride[0]>>1 != mpi->stride[1] | |
285 ||mpi->stride[0]>>1 != mpi->stride[2]){ | |
286 mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Error: chroma stride != luma stride >>1\n"); | |
287 } | |
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 avctx->dr_opaque_frame = mpi; |
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 #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
|
292 |
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 // 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 mp_image_t* mpi=NULL; |
6734 | 301 int dr1= ctx->do_dr1=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
|
302 |
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 if(len<=0) return NULL; // skipped frame |
6734 | 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 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
|
306 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
|
307 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
|
308 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
|
309 (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
|
310 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
|
311 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
|
312 // 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
|
313 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
|
314 } |
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 } |
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
|
316 |
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
|
317 #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
|
318 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
|
319 avctx->flags|= CODEC_FLAG_EMU_EDGE | CODEC_FLAG_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
|
320 avctx->get_buffer_callback= get_buffer; |
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 #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
|
325 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
|
326 #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
|
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 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
|
329 &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
|
330 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
|
331 if(!got_picture) return NULL; // skipped image |
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 |
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 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
|
334 |
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 #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
|
336 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
|
337 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
|
338 } |
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 #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
|
340 |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
341 if(!mpi && ctx->convert){ |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
342 // do yuv422p -> yuy2 conversion: |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
343 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
|
344 avctx->width, avctx->height); |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
345 if(!mpi) return NULL; |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
346 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
|
347 mpi->planes[0],avctx->width,avctx->height, |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
348 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
|
349 return mpi; |
5280 | 350 } |
4952 | 351 |
5482 | 352 if(!mpi) |
4952 | 353 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
5280 | 354 avctx->width, avctx->height); |
4952 | 355 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
|
356 printf("couldn't allocate image for codec\n"); |
4952 | 357 return NULL; |
358 } | |
359 | |
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 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 } |
4952 | 368 |
5280 | 369 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
|
370 // we have 422p but user wants yv12 (420p) |
4952 | 371 mpi->stride[1]*=2; |
372 mpi->stride[2]*=2; | |
373 } | |
374 | |
6665 | 375 /* to comfirm with newer lavc style */ |
376 #if !defined(FF_POSTPROCESS) && (LIBAVCODEC_BUILD > 4612) | |
377 mpi->qscale=avctx->quant_store; | |
378 #if LIBAVCODEC_BUILD > 4613 | |
379 mpi->qstride=avctx->qstride; | |
380 #else | |
381 mpi->qstride=MBC+1; | |
382 #endif | |
383 #else ifdef FF_POSTPROCESS | |
5517 | 384 mpi->qscale=&quant_store[0][0]; |
385 mpi->qstride=MBC+1; | |
386 #endif | |
387 | |
4952 | 388 return mpi; |
389 } | |
390 | |
391 #endif | |
392 |