Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 19033:9fd34039e6df
Remove useless variable.
author | diego |
---|---|
date | Wed, 12 Jul 2006 17:15:58 +0000 |
parents | d9a75b26da6c |
children | 8b52dad54b1d |
rev | line source |
---|---|
4952 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <assert.h> | |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
4 #include <time.h> |
4952 | 5 |
6 #include "config.h" | |
7 #include "mp_msg.h" | |
8 #include "help_mp.h" | |
9 | |
10 #include "bswap.h" | |
11 | |
12 #include "vd_internal.h" | |
13 | |
14 static vd_info_t info = { | |
15 "FFmpeg's libavcodec codec family", | |
16 "ffmpeg", | |
17 "A'rpi", | |
7388 | 18 "A'rpi, Michael, Alex", |
19 "native codecs (http://ffmpeg.sf.net/)" | |
4952 | 20 }; |
21 | |
22 LIBVD_EXTERN(ffmpeg) | |
23 | |
24 #ifdef USE_LIBAVCODEC_SO | |
7004 | 25 #include <ffmpeg/avcodec.h> |
4952 | 26 #else |
27 #include "libavcodec/avcodec.h" | |
28 #endif | |
29 | |
8339 | 30 #if LIBAVCODEC_BUILD < 4641 |
11000 | 31 #error we do not support libavcodec prior to build 4641, get the latest libavcodec CVS |
8339 | 32 #endif |
33 | |
8413 | 34 #if LIBAVCODEC_BUILD < 4645 |
35 #warning your version of libavcodec is old, u might want to get a newer one | |
36 #endif | |
37 | |
38 #if LIBAVCODEC_BUILD < 4645 | |
39 #define AVFrame AVVideoFrame | |
40 #define coded_frame coded_picture | |
41 #endif | |
42 | |
8885
33fb8b6b8547
I hope this works as expected with old lavc versions. At least it compiles now.
rfelker
parents:
8595
diff
changeset
|
43 #if LIBAVCODEC_BUILD < 4654 |
33fb8b6b8547
I hope this works as expected with old lavc versions. At least it compiles now.
rfelker
parents:
8595
diff
changeset
|
44 #define PIX_FMT_RGB24 PIX_FMT_BGR24 |
33fb8b6b8547
I hope this works as expected with old lavc versions. At least it compiles now.
rfelker
parents:
8595
diff
changeset
|
45 #define PIX_FMT_RGBA32 PIX_FMT_BGRA32 |
33fb8b6b8547
I hope this works as expected with old lavc versions. At least it compiles now.
rfelker
parents:
8595
diff
changeset
|
46 #endif |
33fb8b6b8547
I hope this works as expected with old lavc versions. At least it compiles now.
rfelker
parents:
8595
diff
changeset
|
47 |
10471 | 48 #if LIBAVCODEC_BUILD < 4672 |
10362 | 49 #undef HAVE_XVMC |
50 #endif | |
51 | |
52 #ifdef HAVE_XVMC | |
53 #include "xvmc_render.h" | |
54 #endif | |
55 | |
4952 | 56 int avcodec_inited=0; |
57 | |
5280 | 58 typedef struct { |
59 AVCodecContext *avctx; | |
8413 | 60 AVFrame *pic; |
17973 | 61 enum PixelFormat pix_fmt; |
8237 | 62 float last_aspect; |
5482 | 63 int do_slices; |
6734 | 64 int do_dr1; |
5482 | 65 int vo_inited; |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
66 int best_csp; |
8339 | 67 int b_age; |
68 int ip_age[2]; | |
8411 | 69 int qp_stat[32]; |
70 double qp_sum; | |
71 double inv_qp_sum; | |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
72 int ip_count; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
73 int b_count; |
5280 | 74 } vd_ffmpeg_ctx; |
75 | |
17463 | 76 //#ifdef USE_LIBPOSTPROC |
4952 | 77 //unsigned int lavc_pp=0; |
78 //#endif | |
79 | |
10594
57bdcdb061d7
Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents:
10471
diff
changeset
|
80 #include "m_option.h" |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
81 |
8413 | 82 static int get_buffer(AVCodecContext *avctx, AVFrame *pic); |
83 static void release_buffer(AVCodecContext *avctx, AVFrame *pic); | |
12006 | 84 static enum PixelFormat get_format(struct AVCodecContext * avctx, |
85 const enum PixelFormat * pix_fmt); | |
6739 | 86 |
10362 | 87 #ifdef HAVE_XVMC |
88 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic); | |
89 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic); | |
90 static void mc_render_slice(struct AVCodecContext *s, | |
10452 | 91 AVFrame *src, int offset[4], |
92 int y, int type, int height); | |
10362 | 93 #endif |
94 | |
7722 | 95 static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT; |
96 static int lavc_param_error_resilience=2; | |
97 static int lavc_param_error_concealment=3; | |
6355 | 98 static int lavc_param_gray=0; |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
99 static int lavc_param_vstats=0; |
7564 | 100 static int lavc_param_idct_algo=0; |
8341 | 101 static int lavc_param_debug=0; |
11702 | 102 static int lavc_param_vismv=0; |
12670 | 103 static int lavc_param_skip_top=0; |
104 static int lavc_param_skip_bottom=0; | |
13230 | 105 static int lavc_param_fast=0; |
13473 | 106 static int lavc_param_lowres=0; |
14169
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
107 static char *lavc_param_lowres_str=NULL; |
15986 | 108 #if LIBAVCODEC_BUILD >= 4758 |
109 static char *lavc_param_skip_loop_filter_str = NULL; | |
110 static char *lavc_param_skip_idct_str = NULL; | |
111 static char *lavc_param_skip_frame_str = NULL; | |
112 #endif | |
17080 | 113 static int lavc_param_threads=1; |
17217 | 114 static int lavc_param_bitexact=0; |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
115 |
10594
57bdcdb061d7
Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents:
10471
diff
changeset
|
116 m_option_t lavc_decode_opts_conf[]={ |
9547 | 117 {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL}, |
7722 | 118 {"er", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, |
6355 | 119 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, |
7564 | 120 {"idct", &lavc_param_idct_algo, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, |
7722 | 121 {"ec", &lavc_param_error_concealment, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, |
6869 | 122 {"vstats", &lavc_param_vstats, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8341 | 123 {"debug", &lavc_param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 9999999, NULL}, |
11702 | 124 {"vismv", &lavc_param_vismv, CONF_TYPE_INT, CONF_RANGE, 0, 9999999, NULL}, |
12670 | 125 {"st", &lavc_param_skip_top, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, |
126 {"sb", &lavc_param_skip_bottom, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, | |
13230 | 127 #ifdef CODEC_FLAG2_FAST |
128 {"fast", &lavc_param_fast, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG2_FAST, NULL}, | |
129 #endif | |
14169
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
130 {"lowres", &lavc_param_lowres_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
15986 | 131 #if LIBAVCODEC_BUILD >= 4758 |
132 {"skiploopfilter", &lavc_param_skip_loop_filter_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
133 {"skipidct", &lavc_param_skip_idct_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
134 {"skipframe", &lavc_param_skip_frame_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
135 #endif | |
17080 | 136 {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, |
17217 | 137 {"bitexact", &lavc_param_bitexact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL}, |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
138 {NULL, NULL, 0, 0, 0, 0, NULL} |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
139 }; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
140 |
15986 | 141 #if LIBAVCODEC_BUILD >= 4758 |
142 static enum AVDiscard str2AVDiscard(char *str) { | |
143 if (!str) | |
144 return AVDISCARD_DEFAULT; | |
145 if (strcasecmp(str, "none") == 0) | |
146 return AVDISCARD_NONE; | |
147 if (strcasecmp(str, "default") == 0) | |
148 return AVDISCARD_DEFAULT; | |
149 if (strcasecmp(str, "nonref") == 0) | |
150 return AVDISCARD_NONREF; | |
151 if (strcasecmp(str, "bidir") == 0) | |
152 return AVDISCARD_BIDIR; | |
153 if (strcasecmp(str, "nonkey") == 0) | |
154 return AVDISCARD_NONKEY; | |
155 if (strcasecmp(str, "all") == 0) | |
156 return AVDISCARD_ALL; | |
157 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unknown discard value %s\n", str); | |
158 return AVDISCARD_DEFAULT; | |
159 } | |
160 #endif | |
161 | |
4952 | 162 // to set/get/query special features/parameters |
163 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
|
164 vd_ffmpeg_ctx *ctx = sh->context; |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
165 AVCodecContext *avctx = ctx->avctx; |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
166 switch(cmd){ |
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
167 case VDCTRL_QUERY_FORMAT: |
10362 | 168 { |
169 int format =(*((int*)arg)); | |
170 if( format == ctx->best_csp ) return CONTROL_TRUE;//supported | |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
171 // possible conversions: |
10362 | 172 switch( format ){ |
6739 | 173 case IMGFMT_YV12: |
174 case IMGFMT_IYUV: | |
175 case IMGFMT_I420: | |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
176 // "converted" using pointer/stride modification |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
177 if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap |
11064 | 178 if(avctx->pix_fmt==PIX_FMT_YUV422P && !ctx->do_dr1) return CONTROL_TRUE;// half stride |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
179 break; |
10452 | 180 #ifdef HAVE_XVMC |
181 case IMGFMT_XVMC_IDCT_MPEG2: | |
182 case IMGFMT_XVMC_MOCO_MPEG2: | |
10471 | 183 if(avctx->pix_fmt==PIX_FMT_XVMC_MPEG2_IDCT) return CONTROL_TRUE; |
10452 | 184 #endif |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
185 } |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
186 return CONTROL_FALSE; |
11977
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
11955
diff
changeset
|
187 } |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
11955
diff
changeset
|
188 break; |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
11955
diff
changeset
|
189 case VDCTRL_RESYNC_STREAM: |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
11955
diff
changeset
|
190 avcodec_flush_buffers(avctx); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18879
diff
changeset
|
191 return CONTROL_TRUE; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18879
diff
changeset
|
192 case VDCTRL_QUERY_UNSEEN_FRAMES: |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18879
diff
changeset
|
193 return avctx->has_b_frames + 10; |
10362 | 194 } |
4952 | 195 return CONTROL_UNKNOWN; |
196 } | |
197 | |
198 // init driver | |
199 static int init(sh_video_t *sh){ | |
5280 | 200 AVCodecContext *avctx; |
201 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
|
202 AVCodec *lavc_codec; |
14169
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
203 #if LIBAVCODEC_BUILD >= 4722 |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
204 int lowres_w=0; |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
205 #endif |
11712
5905aae865c7
disable dr1&slices for the other vissualizations too
michael
parents:
11711
diff
changeset
|
206 int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); |
4952 | 207 |
208 if(!avcodec_inited){ | |
209 avcodec_init(); | |
210 avcodec_register_all(); | |
211 avcodec_inited=1; | |
212 } | |
5280 | 213 |
214 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
215 if (!ctx) | |
216 return(0); | |
217 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
4952 | 218 |
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
|
219 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
|
220 if(!lavc_codec){ |
4952 | 221 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
222 return 0; | |
223 } | |
5482 | 224 |
11712
5905aae865c7
disable dr1&slices for the other vissualizations too
michael
parents:
11711
diff
changeset
|
225 if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) |
5494
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
226 ctx->do_slices=1; |
6734 | 227 |
13275 | 228 if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264) |
6734 | 229 ctx->do_dr1=1; |
8339 | 230 ctx->b_age= ctx->ip_age[0]= ctx->ip_age[1]= 256*256*256*64; |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
231 ctx->ip_count= ctx->b_count= 0; |
7444 | 232 |
8413 | 233 #if LIBAVCODEC_BUILD >= 4645 |
234 ctx->pic = avcodec_alloc_frame(); | |
235 #else | |
8339 | 236 ctx->pic = avcodec_alloc_picture(); |
8413 | 237 #endif |
7444 | 238 ctx->avctx = avcodec_alloc_context(); |
5280 | 239 avctx = ctx->avctx; |
6739 | 240 |
11526 | 241 #if LIBAVCODEC_BUILD >= 4691 && LIBAVCODEC_BUILD <= 4692 |
11420 | 242 if(lavc_codec->capabilities&CODEC_CAP_CR) |
243 avctx->cr_available = 1; | |
244 #endif | |
245 | |
10362 | 246 #ifdef HAVE_XVMC |
12033
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
247 |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
248 #ifdef CODEC_CAP_HWACCEL |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
249 if(lavc_codec->capabilities & CODEC_CAP_HWACCEL){ |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
250 #else |
10362 | 251 if(lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC){ |
12033
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
252 #endif |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
253 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedCodec); |
10362 | 254 assert(ctx->do_dr1);//these are must to! |
255 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails | |
256 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!! | |
12006 | 257 avctx->get_format= get_format;//for now only this decoder will use it |
10362 | 258 avctx->get_buffer= mc_get_buffer; |
259 avctx->release_buffer= mc_release_buffer; | |
10471 | 260 avctx->draw_horiz_band = mc_render_slice; |
261 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD; | |
10362 | 262 }else |
263 #endif | |
6739 | 264 if(ctx->do_dr1){ |
8339 | 265 avctx->flags|= CODEC_FLAG_EMU_EDGE; |
266 avctx->get_buffer= get_buffer; | |
267 avctx->release_buffer= release_buffer; | |
11526 | 268 #if LIBAVCODEC_BUILD >= 4693 |
269 avctx->reget_buffer= get_buffer; | |
270 #endif | |
6739 | 271 } |
7303 | 272 |
273 #ifdef CODEC_FLAG_NOT_TRUNCATED | |
274 avctx->flags|= CODEC_FLAG_NOT_TRUNCATED; | |
275 #endif | |
17217 | 276 avctx->flags|= lavc_param_bitexact; |
4952 | 277 |
5280 | 278 avctx->width = sh->disp_w; |
279 avctx->height= sh->disp_h; | |
6265
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
280 avctx->workaround_bugs= lavc_param_workaround_bugs; |
f49ec39ab0c6
workaround bugs & error resilience ffmpeg decoder options
michael
parents:
5940
diff
changeset
|
281 avctx->error_resilience= lavc_param_error_resilience; |
6355 | 282 if(lavc_param_gray) avctx->flags|= CODEC_FLAG_GRAY; |
13230 | 283 #ifdef CODEC_FLAG2_FAST |
284 avctx->flags2|= lavc_param_fast; | |
285 #endif | |
9547 | 286 avctx->codec_tag= sh->format; |
10847 | 287 #if LIBAVCODEC_BUILD >= 4679 |
288 avctx->stream_codec_tag= sh->video.fccHandler; | |
289 #endif | |
7564 | 290 avctx->idct_algo= lavc_param_idct_algo; |
7722 | 291 avctx->error_concealment= lavc_param_error_concealment; |
8341 | 292 #if LIBAVCODEC_BUILD >= 4642 |
293 avctx->debug= lavc_param_debug; | |
17073
177c02c3785f
make -lavdopts debug work again, patch by Jason Tackaberry ( tack AH sault POIS org )
gpoirier
parents:
16963
diff
changeset
|
294 if (lavc_param_debug) |
177c02c3785f
make -lavdopts debug work again, patch by Jason Tackaberry ( tack AH sault POIS org )
gpoirier
parents:
16963
diff
changeset
|
295 av_log_set_level(AV_LOG_DEBUG); |
8341 | 296 #endif |
11702 | 297 #if LIBAVCODEC_BUILD >= 4698 |
298 avctx->debug_mv= lavc_param_vismv; | |
299 #endif | |
12670 | 300 #if LIBAVCODEC_BUILD >= 4717 |
301 avctx->skip_top = lavc_param_skip_top; | |
302 avctx->skip_bottom= lavc_param_skip_bottom; | |
303 #endif | |
13473 | 304 #if LIBAVCODEC_BUILD >= 4722 |
14169
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
305 if(lavc_param_lowres_str != NULL) |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
306 { |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
307 sscanf(lavc_param_lowres_str, "%d,%d", &lavc_param_lowres, &lowres_w); |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
308 if(lavc_param_lowres < 1 || lavc_param_lowres > 16 || (lowres_w > 0 && avctx->width < lowres_w)) |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
309 lavc_param_lowres = 0; |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
310 avctx->lowres = lavc_param_lowres; |
95dd81b8b9de
conditional lowres: activate lowres if frame width >= threshold
nicodvb
parents:
14118
diff
changeset
|
311 } |
13473 | 312 #endif |
15986 | 313 #if LIBAVCODEC_BUILD >= 4758 |
314 avctx->skip_loop_filter = str2AVDiscard(lavc_param_skip_loop_filter_str); | |
315 avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str); | |
316 avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str); | |
317 #endif | |
5280 | 318 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); |
18023
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
319 switch (sh->format) { |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
320 case mmioFOURCC('A','V','R','n'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
321 case mmioFOURCC('M','J','P','G'): |
5939 | 322 /* AVRn stores huffman table in AVI header */ |
323 /* Pegasus MJPEG stores it also in AVI header, but it uses the common | |
324 MJPG fourcc :( */ | |
18023
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
325 if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
326 break; |
5939 | 327 avctx->flags |= CODEC_FLAG_EXTERN_HUFF; |
328 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); | |
17226
255b14c0bc36
malloc padding to avoid access beyond allocated memory
henry
parents:
17217
diff
changeset
|
329 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
5939 | 330 memcpy(avctx->extradata, sh->bih+sizeof(BITMAPINFOHEADER), |
331 avctx->extradata_size); | |
332 | |
333 #if 0 | |
334 { | |
335 int x; | |
336 uint8_t *p = avctx->extradata; | |
337 | |
338 for (x=0; x<avctx->extradata_size; x++) | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
339 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"[%x] ", p[x]); |
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
340 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"\n"); |
5939 | 341 } |
342 #endif | |
18023
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
343 break; |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
344 |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
345 case mmioFOURCC('R', 'V', '1', '0'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
346 case mmioFOURCC('R', 'V', '1', '3'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
347 case mmioFOURCC('R', 'V', '2', '0'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
348 case mmioFOURCC('R', 'V', '3', '0'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
349 case mmioFOURCC('R', 'V', '4', '0'): |
7126 | 350 avctx->extradata_size= 8; |
17226
255b14c0bc36
malloc padding to avoid access beyond allocated memory
henry
parents:
17217
diff
changeset
|
351 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
7574
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
352 if(sh->bih->biSize!=sizeof(*sh->bih)+8){ |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
353 /* only 1 packet per frame & sub_id from fourcc */ |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
354 ((uint32_t*)avctx->extradata)[0] = 0; |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
355 avctx->sub_id= |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
356 ((uint32_t*)avctx->extradata)[1] = |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
357 (sh->format == mmioFOURCC('R', 'V', '1', '3')) ? 0x10003001 : 0x10000000; |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
358 } else { |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
359 /* has extra slice header (demux_rm or rm->avi streamcopy) */ |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
360 unsigned int* extrahdr=(unsigned int*)(sh->bih+1); |
14118 | 361 ((uint32_t*)avctx->extradata)[0] = be2me_32(extrahdr[0]); |
362 avctx->sub_id= extrahdr[1]; | |
363 ((uint32_t*)avctx->extradata)[1] = be2me_32(extrahdr[1]); | |
7574
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
364 } |
7573 | 365 |
7126 | 366 // printf("%X %X %d %d\n", extrahdr[0], extrahdr[1]); |
18023
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
367 break; |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
368 |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
369 case mmioFOURCC('S','V','Q','3'): |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
370 if (!sh->ImageDesc) |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
371 break; |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
372 avctx->extradata_size = (*(int*)sh->ImageDesc) - sizeof(int); |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
373 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
374 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
375 break; |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
376 |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
377 default: |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
378 if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) |
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
379 break; |
7736
b81b0ab0aa40
put M4S2 & MP4S headers in avctx->extradata (in the unlikely case that they arent missing completly)
michael
parents:
7722
diff
changeset
|
380 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); |
17226
255b14c0bc36
malloc padding to avoid access beyond allocated memory
henry
parents:
17217
diff
changeset
|
381 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
7736
b81b0ab0aa40
put M4S2 & MP4S headers in avctx->extradata (in the unlikely case that they arent missing completly)
michael
parents:
7722
diff
changeset
|
382 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); |
18023
4ca6b585aa58
simplify extradata handling and make passing extradata on the default.
reimar
parents:
18004
diff
changeset
|
383 break; |
7736
b81b0ab0aa40
put M4S2 & MP4S headers in avctx->extradata (in the unlikely case that they arent missing completly)
michael
parents:
7722
diff
changeset
|
384 } |
11420 | 385 /* Pass palette to codec */ |
386 #if LIBAVCODEC_BUILD >= 4689 | |
387 if (sh->bih && (sh->bih->biBitCount <= 8)) { | |
18879 | 388 avctx->palctrl = calloc(1,sizeof(AVPaletteControl)); |
11420 | 389 avctx->palctrl->palette_changed = 1; |
390 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER)) | |
391 /* Palette size in biSize */ | |
392 memcpy(avctx->palctrl->palette, sh->bih+1, | |
393 min(sh->bih->biSize-sizeof(BITMAPINFOHEADER), AVPALETTE_SIZE)); | |
394 else | |
395 /* Palette size in biClrUsed */ | |
396 memcpy(avctx->palctrl->palette, sh->bih+1, | |
397 min(sh->bih->biClrUsed * 4, AVPALETTE_SIZE)); | |
398 } | |
399 #endif | |
8190 | 400 |
8264 | 401 if(sh->bih) |
402 avctx->bits_per_sample= sh->bih->biBitCount; | |
7126 | 403 |
17080 | 404 #if LIBAVCODEC_BUILD >= 4716 |
405 if(lavc_param_threads > 1) | |
406 avcodec_thread_init(avctx, lavc_param_threads); | |
407 #endif | |
4952 | 408 /* 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
|
409 if (avcodec_open(avctx, lavc_codec) < 0) { |
4952 | 410 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
411 return 0; | |
412 } | |
413 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
5482 | 414 ctx->last_aspect=-3; |
5510 | 415 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
4952 | 416 } |
417 | |
418 // uninit driver | |
419 static void uninit(sh_video_t *sh){ | |
5280 | 420 vd_ffmpeg_ctx *ctx = sh->context; |
421 AVCodecContext *avctx = ctx->avctx; | |
8411 | 422 |
423 if(lavc_param_vstats){ | |
424 int i; | |
425 for(i=1; i<32; i++){ | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
426 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"QP: %d, count: %d\n", i, ctx->qp_stat[i]); |
8411 | 427 } |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
428 mp_msg(MSGT_DECVIDEO, MSGL_INFO,MSGTR_MPCODECS_ArithmeticMeanOfQP, |
8413 | 429 ctx->qp_sum / avctx->coded_frame->coded_picture_number, |
430 1.0/(ctx->inv_qp_sum / avctx->coded_frame->coded_picture_number) | |
8411 | 431 ); |
432 } | |
5280 | 433 |
434 if (avcodec_close(avctx) < 0) | |
4952 | 435 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
5939 | 436 |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
437 av_freep(&avctx->extradata); |
11422 | 438 #if LIBAVCODEC_BUILD >= 4689 |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
439 av_freep(&avctx->palctrl); |
11422 | 440 #endif |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
441 av_freep(&avctx->slice_offset); |
5939 | 442 |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
443 av_freep(&avctx); |
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
444 av_freep(&ctx->pic); |
5280 | 445 if (ctx) |
446 free(ctx); | |
4952 | 447 } |
448 | |
5482 | 449 static void draw_slice(struct AVCodecContext *s, |
10436 | 450 #if LIBAVCODEC_BUILD >= 4670 |
451 AVFrame *src, int offset[4], | |
452 #else | |
453 uint8_t **src, int linesize, | |
454 #endif | |
10449 | 455 int y, int type, int height){ |
6710 | 456 sh_video_t * sh = s->opaque; |
6740 | 457 int start=0, i; |
10449 | 458 int width= s->width; |
13489
912c906db2ed
compensate for width/height being picture width/height instead of bitstream width/height
michael
parents:
13473
diff
changeset
|
459 int skip_stride= ((width<<lavc_param_lowres)+15)>>4; |
9400 | 460 uint8_t *skip= &s->coded_frame->mbskip_table[(y>>4)*skip_stride]; |
8413 | 461 int threshold= s->coded_frame->age; |
10436 | 462 #if LIBAVCODEC_BUILD >= 4670 |
463 uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]}; | |
464 #else | |
465 int stride[3]; | |
10449 | 466 |
5482 | 467 stride[0]=linesize; |
8413 | 468 if(s->coded_frame->linesize[1]){ |
469 stride[1]= s->coded_frame->linesize[1]; | |
470 stride[2]= s->coded_frame->linesize[2]; | |
8339 | 471 }else |
6740 | 472 stride[1]=stride[2]=stride[0]/2; |
10436 | 473 #endif |
6740 | 474 #if 0 |
475 if(s->pict_type!=B_TYPE){ | |
476 for(i=0; i*16<width+16; i++){ | |
477 if(i*16>=width || skip[i]>=threshold){ | |
478 if(start==i) start++; | |
479 else{ | |
9400 | 480 uint8_t *src2[3]= {src[0] + start*16, |
6740 | 481 src[1] + start*8, |
482 src[2] + start*8}; | |
483 //printf("%2d-%2d x %d\n", start, i, y); | |
484 mpcodecs_draw_slice (sh,src2, stride, (i-start)*16, height, start*16, y); | |
485 start= i+1; | |
486 } | |
487 } | |
488 } | |
489 }else | |
490 #endif | |
15683 | 491 if (y < sh->disp_h) { |
10436 | 492 #if LIBAVCODEC_BUILD >= 4670 |
15694 | 493 mpcodecs_draw_slice (sh, source, src->linesize, sh->disp_w, (y+height)<=sh->disp_h?height:sh->disp_h-y, 0, y); |
10436 | 494 #else |
15694 | 495 mpcodecs_draw_slice (sh,src, stride, sh->disp_w, (y+height)<=sh->disp_h?height:sh->disp_h-y, 0, y); |
10436 | 496 #endif |
15683 | 497 } |
5482 | 498 } |
4952 | 499 |
10436 | 500 |
12006 | 501 static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ |
5280 | 502 vd_ffmpeg_ctx *ctx = sh->context; |
503 AVCodecContext *avctx = ctx->avctx; | |
11194 | 504 #if LIBAVCODEC_BUILD >= 4687 |
505 float aspect= av_q2d(avctx->sample_aspect_ratio) * avctx->width / avctx->height; | |
506 #else | |
507 float aspect= avctx->aspect_ratio; | |
508 #endif | |
15567
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
509 int width, height; |
4952 | 510 |
15567
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
511 width = avctx->width; |
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
512 height = avctx->height; |
15569 | 513 |
514 // HACK! | |
515 // if sh->ImageDesc is non-NULL, it means we decode QuickTime(tm) video. | |
516 // use dimensions from BIH to avoid black borders at the right and bottom. | |
517 if (sh->bih && sh->ImageDesc) { | |
518 width = sh->bih->biWidth>>lavc_param_lowres; | |
519 height = sh->bih->biHeight>>lavc_param_lowres; | |
15567
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
520 } |
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
521 |
11414 | 522 // it is possible another vo buffers to be used after vo config() |
523 // lavc reset its buffers on width/heigh change but not on aspect change!!! | |
524 if (// aspect != ctx->last_aspect || | |
15567
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
525 width != sh->disp_w || |
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
526 height != sh->disp_h || |
17973 | 527 pix_fmt != ctx->pix_fmt || |
5482 | 528 !ctx->vo_inited) |
5280 | 529 { |
11194 | 530 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] aspect_ratio: %f\n", aspect); |
531 ctx->last_aspect = aspect; | |
8510 | 532 // if(ctx->last_aspect>=0.01 && ctx->last_aspect<100) |
10080
312eb2923169
Made the decoder honor the aspect ratio set by the container (if it was set at all).
mosu
parents:
9991
diff
changeset
|
533 if(sh->aspect==0.0) |
8510 | 534 sh->aspect = ctx->last_aspect; |
15567
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
535 sh->disp_w = width; |
c8ef0513f470
prefer width&height from bitmapinfoheader for h263 streams
henry
parents:
15064
diff
changeset
|
536 sh->disp_h = height; |
17973 | 537 ctx->pix_fmt = pix_fmt; |
12006 | 538 switch(pix_fmt){ |
14597
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
539 // YUVJ are YUV formats that use the full Y range and not just |
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
540 // 16 - 235 (see colorspaces.txt). |
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
541 // Currently they are all treated the same way. |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
542 case PIX_FMT_YUV410P: ctx->best_csp=IMGFMT_YVU9;break; //svq1 |
14597
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
543 case PIX_FMT_YUVJ420P: |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
544 case PIX_FMT_YUV420P: ctx->best_csp=IMGFMT_YV12;break; //mpegs |
14597
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
545 case PIX_FMT_YUVJ422P: |
8190 | 546 case PIX_FMT_YUV422P: ctx->best_csp=IMGFMT_422P;break; //mjpeg / huffyuv |
14597
9bc220e867ed
"support" YUVJ colorspaces added to libavcodec, makes mjpeg decoding work again
reimar
parents:
14576
diff
changeset
|
547 case PIX_FMT_YUVJ444P: |
8510 | 548 case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg |
7662 | 549 case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc |
8190 | 550 case PIX_FMT_YUV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future |
11955 | 551 case PIX_FMT_RGB24 : ctx->best_csp=IMGFMT_RGB24;break; //qtrle |
10436 | 552 case PIX_FMT_RGBA32: ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg |
11420 | 553 case PIX_FMT_BGR24 : ctx->best_csp=IMGFMT_BGR24;break; //8bps |
554 case PIX_FMT_RGB555: ctx->best_csp=IMGFMT_BGR15;break; //rpza,cram | |
12171 | 555 case PIX_FMT_RGB565: ctx->best_csp=IMGFMT_BGR16;break; //4xm |
17561 | 556 case PIX_FMT_GRAY8: ctx->best_csp=IMGFMT_Y800;break; // gray jpeg |
11420 | 557 case PIX_FMT_PAL8: ctx->best_csp=IMGFMT_BGR8;break; //8bps,mrle,cram |
10362 | 558 #ifdef HAVE_XVMC |
10471 | 559 case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break; |
560 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break; | |
10362 | 561 #endif |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
562 default: |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
563 ctx->best_csp=0; |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
564 } |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
565 if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp)) |
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
|
566 return -1; |
16963
4aa0f65686a6
do not set ctx->vo_inited when init fails. This caused a crash when a
reimar
parents:
16497
diff
changeset
|
567 ctx->vo_inited = 1; |
5592
b545d56314d2
yuy2 support, fixed bug of dropping frame after config_vo calls
arpi
parents:
5517
diff
changeset
|
568 } |
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
|
569 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
|
570 } |
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
|
571 |
8413 | 572 static int get_buffer(AVCodecContext *avctx, AVFrame *pic){ |
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
|
573 sh_video_t * sh = avctx->opaque; |
6734 | 574 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
|
575 mp_image_t* mpi=NULL; |
6875 | 576 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE; |
6737 | 577 int type= MP_IMGTYPE_IPB; |
8339 | 578 int width= avctx->width; |
579 int height= avctx->height; | |
6738 | 580 int align=15; |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
581 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); |
6738 | 582 if(avctx->pix_fmt == PIX_FMT_YUV410P) |
583 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) | |
584 | |
11420 | 585 #if LIBAVCODEC_BUILD >= 4691 |
586 if (pic->buffer_hints) { | |
587 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints); | |
588 type = MP_IMGTYPE_TEMP; | |
589 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE) | |
590 flags |= MP_IMGFLAG_READABLE; | |
591 if (pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) { | |
592 type = MP_IMGTYPE_STATIC; | |
593 flags |= MP_IMGFLAG_PRESERVE; | |
594 } | |
595 if (pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) { | |
596 type = MP_IMGTYPE_STATIC; | |
597 flags |= MP_IMGFLAG_PRESERVE; | |
598 } | |
599 flags|=(!avctx->hurry_up && ctx->do_slices) ? | |
600 MP_IMGFLAG_DRAW_CALLBACK:0; | |
601 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n"); | |
602 } else { | |
603 #endif | |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
604 if(!pic->reference){ |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
605 ctx->b_count++; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
606 flags|=(!avctx->hurry_up && ctx->do_slices) ? |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
607 MP_IMGFLAG_DRAW_CALLBACK:0; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
608 }else{ |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
609 ctx->ip_count++; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
610 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
611 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0); |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
612 } |
11420 | 613 #if LIBAVCODEC_BUILD >= 4691 |
614 } | |
615 #endif | |
8339 | 616 |
12006 | 617 if(init_vo(sh,avctx->pix_fmt) < 0){ |
9991 | 618 avctx->release_buffer= avcodec_default_release_buffer; |
619 avctx->get_buffer= avcodec_default_get_buffer; | |
620 return avctx->get_buffer(avctx, pic); | |
621 } | |
622 | |
11420 | 623 #if LIBAVCODEC_BUILD >= 4691 |
624 if (!pic->buffer_hints) { | |
625 #endif | |
9991 | 626 if(ctx->b_count>1 || ctx->ip_count>2){ |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
627 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_DRIFailure); |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
628 |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
629 ctx->do_dr1=0; //FIXME |
8339 | 630 avctx->get_buffer= avcodec_default_get_buffer; |
631 return avctx->get_buffer(avctx, pic); | |
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
|
632 } |
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
|
633 |
6737 | 634 if(avctx->has_b_frames){ |
635 type= MP_IMGTYPE_IPB; | |
636 }else{ | |
637 type= MP_IMGTYPE_IP; | |
638 } | |
639 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); | |
11420 | 640 #if LIBAVCODEC_BUILD >= 4691 |
641 } | |
642 #endif | |
6737 | 643 |
644 mpi= mpcodecs_get_image(sh,type, flags, | |
6738 | 645 (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
|
646 |
11000 | 647 // ok, let's see what did we get: |
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
|
648 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
|
649 !(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
|
650 // 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
|
651 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
|
652 } 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
|
653 avctx->draw_horiz_band= NULL; |
11420 | 654 |
11431
bf80540aeae5
1l, another version check missing, noted by rgselk
rtognimp
parents:
11422
diff
changeset
|
655 #if LIBAVCODEC_BUILD >= 4689 |
11420 | 656 // Palette support: libavcodec copies palette to *data[1] |
657 if (mpi->bpp == 8) | |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
658 mpi->planes[1] = av_malloc(AVPALETTE_SIZE); |
11431
bf80540aeae5
1l, another version check missing, noted by rgselk
rtognimp
parents:
11422
diff
changeset
|
659 #endif |
11420 | 660 |
8339 | 661 pic->data[0]= mpi->planes[0]; |
662 pic->data[1]= mpi->planes[1]; | |
663 pic->data[2]= mpi->planes[2]; | |
8595 | 664 |
665 #if 0 | |
666 assert(mpi->width >= ((width +align)&(~align))); | |
667 assert(mpi->height >= ((height+align)&(~align))); | |
668 assert(mpi->stride[0] >= mpi->width); | |
7051
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
669 if(mpi->imgfmt==IMGFMT_I420 || mpi->imgfmt==IMGFMT_YV12 || mpi->imgfmt==IMGFMT_IYUV){ |
8586
88f2362f1291
5l - fixed asserts... mpi->width is allocated width, not the effective one
arpi
parents:
8510
diff
changeset
|
670 const int y_size= mpi->stride[0] * (mpi->h-1) + mpi->w; |
88f2362f1291
5l - fixed asserts... mpi->width is allocated width, not the effective one
arpi
parents:
8510
diff
changeset
|
671 const int c_size= mpi->stride[1] * ((mpi->h>>1)-1) + (mpi->w>>1); |
7051
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
672 |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
673 assert(mpi->planes[0] > mpi->planes[1] || mpi->planes[0] + y_size <= mpi->planes[1]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
674 assert(mpi->planes[0] > mpi->planes[2] || mpi->planes[0] + y_size <= mpi->planes[2]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
675 assert(mpi->planes[1] > mpi->planes[0] || mpi->planes[1] + c_size <= mpi->planes[0]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
676 assert(mpi->planes[1] > mpi->planes[2] || mpi->planes[1] + c_size <= mpi->planes[2]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
677 assert(mpi->planes[2] > mpi->planes[0] || mpi->planes[2] + c_size <= mpi->planes[0]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
678 assert(mpi->planes[2] > mpi->planes[1] || mpi->planes[2] + c_size <= mpi->planes[1]); |
d03fad6123a3
asserts to check buffer size and non overlapingness
michael
parents:
7004
diff
changeset
|
679 } |
8595 | 680 #endif |
6734 | 681 |
8339 | 682 /* Note, some (many) codecs in libavcodec must have stride1==stride2 && no changes between frames |
683 * lavc will check that and die with an error message, if its not true | |
684 */ | |
685 pic->linesize[0]= mpi->stride[0]; | |
686 pic->linesize[1]= mpi->stride[1]; | |
687 pic->linesize[2]= mpi->stride[2]; | |
6734 | 688 |
8339 | 689 pic->opaque = mpi; |
6742
93bce3460e2a
fallback to slices, if dr1 fails (bug found by kabi)
michael
parents:
6740
diff
changeset
|
690 //printf("%X\n", (int)mpi->planes[0]); |
6869 | 691 #if 0 |
692 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
693 printf("D"); | |
694 else if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK) | |
695 printf("S"); | |
696 else | |
697 printf("."); | |
698 #endif | |
8339 | 699 if(pic->reference){ |
700 pic->age= ctx->ip_age[0]; | |
701 | |
702 ctx->ip_age[0]= ctx->ip_age[1]+1; | |
703 ctx->ip_age[1]= 1; | |
704 ctx->b_age++; | |
705 }else{ | |
706 pic->age= ctx->b_age; | |
707 | |
708 ctx->ip_age[0]++; | |
709 ctx->ip_age[1]++; | |
710 ctx->b_age=1; | |
711 } | |
8411 | 712 #if LIBAVCODEC_BUILD >= 4644 |
713 pic->type= FF_BUFFER_TYPE_USER; | |
714 #endif | |
7928 | 715 return 0; |
8339 | 716 } |
717 | |
8413 | 718 static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
719 mp_image_t* mpi= pic->opaque; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
720 sh_video_t * sh = avctx->opaque; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
721 vd_ffmpeg_ctx *ctx = sh->context; |
8339 | 722 int i; |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
723 |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
724 //printf("release buffer %d %d %d\n", mpi ? mpi->flags&MP_IMGFLAG_PRESERVE : -99, ctx->ip_count, ctx->b_count); |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
725 |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
726 if(ctx->ip_count <= 2 && ctx->b_count<=1){ |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
727 if(mpi->flags&MP_IMGFLAG_PRESERVE) |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
728 ctx->ip_count--; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
729 else |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
730 ctx->b_count--; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
731 } |
11420 | 732 |
733 // Palette support: free palette buffer allocated in get_buffer | |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
734 if ( mpi && (mpi->bpp == 8)) |
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
735 av_freep(&mpi->planes[1]); |
11420 | 736 |
8411 | 737 #if LIBAVCODEC_BUILD >= 4644 |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
738 if(pic->type!=FF_BUFFER_TYPE_USER){ |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
739 avcodec_default_release_buffer(avctx, pic); |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
740 return; |
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
741 } |
8411 | 742 #endif |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
743 |
8339 | 744 for(i=0; i<4; i++){ |
745 pic->data[i]= NULL; | |
746 } | |
747 //printf("R%X %X\n", pic->linesize[0], pic->data[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
|
748 } |
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
|
749 |
7573 | 750 // copypaste from demux_real.c - it should match to get it working! |
751 //FIXME put into some header | |
752 typedef struct dp_hdr_s { | |
753 uint32_t chunks; // number of chunks | |
754 uint32_t timestamp; // timestamp from packet header | |
755 uint32_t len; // length of actual data | |
756 uint32_t chunktab; // offset to chunk offset array | |
757 } dp_hdr_t; | |
758 | |
13190 | 759 |
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
|
760 // 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
|
761 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
|
762 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
|
763 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
|
764 vd_ffmpeg_ctx *ctx = sh->context; |
8413 | 765 AVFrame *pic= ctx->pic; |
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
|
766 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
|
767 mp_image_t* mpi=NULL; |
6737 | 768 int dr1= ctx->do_dr1; |
13190 | 769 unsigned char *buf = NULL; |
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
|
770 |
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
|
771 if(len<=0) return NULL; // skipped frame |
6734 | 772 |
12033
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
773 #if LIBAVCODEC_BUILD < 4707 |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
774 |
10362 | 775 #ifdef HAVE_XVMC |
12033
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
776 if( !avctx->xvmc_acceleration ) |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
777 #endif |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
778 |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
779 #else |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
780 //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices |
3dd75c52bf38
use flag for XvMC codec recognition and enable dr1 for fixed version of lavc
iive
parents:
12006
diff
changeset
|
781 if (!dr1) |
10362 | 782 #endif |
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
|
783 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
|
784 avctx->opaque=sh; |
10161
a339c588ddcd
removed obsolete (and currently non-working) scaling functions, after that it works correctly with YV12,422P and 444P mjpegs
alex
parents:
10131
diff
changeset
|
785 if(ctx->vo_inited && !(flags&3) && !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
|
786 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
|
787 (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
|
788 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
|
789 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
|
790 // 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
|
791 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
|
792 } |
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
|
793 } |
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
|
794 |
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
|
795 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
|
796 |
7574
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
797 // if(sh->ds->demuxer->type == DEMUXER_TYPE_REAL){ |
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
798 if( sh->format == mmioFOURCC('R', 'V', '1', '0') |
11541 | 799 || sh->format == mmioFOURCC('R', 'V', '1', '3') |
11669
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
800 || sh->format == mmioFOURCC('R', 'V', '2', '0') |
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
801 || sh->format == mmioFOURCC('R', 'V', '3', '0') |
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
802 || sh->format == mmioFOURCC('R', 'V', '4', '0')) |
7574
87f57e23e301
fixing RV10 streamcopy - detect packet format (simple single frame vs. slices
arpi
parents:
7573
diff
changeset
|
803 if(sh->bih->biSize==sizeof(*sh->bih)+8){ |
7573 | 804 int i; |
805 dp_hdr_t *hdr= (dp_hdr_t*)data; | |
806 | |
807 if(avctx->slice_offset==NULL) | |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
14169
diff
changeset
|
808 avctx->slice_offset= av_malloc(sizeof(int)*1000); |
7573 | 809 |
810 // for(i=0; i<25; i++) printf("%02X ", ((uint8_t*)data)[i]); | |
811 | |
812 avctx->slice_count= hdr->chunks+1; | |
813 for(i=0; i<avctx->slice_count; i++) | |
814 avctx->slice_offset[i]= ((uint32_t*)(data+hdr->chunktab))[2*i+1]; | |
7578 | 815 len=hdr->len; |
7573 | 816 data+= sizeof(dp_hdr_t); |
817 } | |
818 | |
16497
182794778785
print the first 16 bytes of frame data with -v -v, helps detect when
reimar
parents:
15986
diff
changeset
|
819 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "vd_ffmpeg data: %04x, %04x, %04x, %04x\n", |
182794778785
print the first 16 bytes of frame data with -v -v, helps detect when
reimar
parents:
15986
diff
changeset
|
820 ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], ((int *)data)[3]); |
8339 | 821 ret = avcodec_decode_video(avctx, pic, |
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
|
822 &got_picture, data, len); |
13190 | 823 |
9982
cd76f332bdee
fallback to non-dr1 if the codec wants more than 1+2 buffers
michael
parents:
9931
diff
changeset
|
824 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
|
825 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); |
9547 | 826 //printf("repeat: %d\n", pic->repeat_pict); |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
827 //-- vstats generation |
8347 | 828 #if LIBAVCODEC_BUILD >= 4643 |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
829 while(lavc_param_vstats){ // always one time loop |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
830 static FILE *fvstats=NULL; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
831 char filename[20]; |
6834
2d7dfcc79651
Fix overall frametime overflow, hopefully long long int is portable. (untested, will test tomorrow)
atmos4
parents:
6833
diff
changeset
|
832 static long long int all_len=0; |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
833 static int frame_number=0; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
834 static double all_frametime=0.0; |
8413 | 835 AVFrame *pic= avctx->coded_frame; |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
836 double quality=0.0; |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
837 |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
838 if(!fvstats) { |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
839 time_t today2; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
840 struct tm *today; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
841 today2 = time(NULL); |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
842 today = localtime(&today2); |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
843 sprintf(filename, "vstats_%02d%02d%02d.log", today->tm_hour, |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
844 today->tm_min, today->tm_sec); |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
845 fvstats = fopen(filename,"w"); |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
846 if(!fvstats) { |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
847 perror("fopen"); |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
848 lavc_param_vstats=0; // disable block |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
849 break; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
850 /*exit(1);*/ |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
851 } |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
852 } |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
853 |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
854 // average MB quantizer |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
855 { |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
856 int x, y; |
13489
912c906db2ed
compensate for width/height being picture width/height instead of bitstream width/height
michael
parents:
13473
diff
changeset
|
857 int w = ((avctx->width << lavc_param_lowres)+15) >> 4; |
912c906db2ed
compensate for width/height being picture width/height instead of bitstream width/height
michael
parents:
13473
diff
changeset
|
858 int h = ((avctx->height << lavc_param_lowres)+15) >> 4; |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
859 int8_t *q = pic->qscale_table; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
860 for( y = 0; y < h; y++ ) { |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
861 for( x = 0; x < w; x++ ) |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
862 quality += (double)*(q+x); |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
863 q += pic->qstride; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
864 } |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
865 quality /= w * h; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
866 } |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
867 |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
868 all_len+=len; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
869 all_frametime+=sh->frametime; |
8411 | 870 fprintf(fvstats, "frame= %5d q= %2.2f f_size= %6d s_size= %8.0fkB ", |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
871 ++frame_number, quality, len, (double)all_len/1024); |
6833
a709a7662cd1
Add type= and fix a minor typing difference from ffmpeg
atmos4
parents:
6828
diff
changeset
|
872 fprintf(fvstats, "time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
873 all_frametime, (double)(len*8)/sh->frametime/1000.0, |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
874 (double)(all_len*8)/all_frametime/1000.0); |
8339 | 875 switch(pic->pict_type){ |
8347 | 876 case FF_I_TYPE: |
8065
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
877 fprintf(fvstats, "type= I\n"); |
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
878 break; |
8347 | 879 case FF_P_TYPE: |
8065
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
880 fprintf(fvstats, "type= P\n"); |
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
881 break; |
8347 | 882 case FF_S_TYPE: |
8065
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
883 fprintf(fvstats, "type= S\n"); |
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
884 break; |
8347 | 885 case FF_B_TYPE: |
8065
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
886 fprintf(fvstats, "type= B\n"); |
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
887 break; |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
888 default: |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
889 fprintf(fvstats, "type= ? (%d)\n", pic->pict_type); |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
890 break; |
8065
a3e7c0e16d5b
fixing vstats so B frames are shown as B and not P
michael
parents:
7984
diff
changeset
|
891 } |
8411 | 892 |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
893 ctx->qp_stat[(int)(quality+0.5)]++; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
894 ctx->qp_sum += quality; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9547
diff
changeset
|
895 ctx->inv_qp_sum += 1.0/(double)quality; |
8411 | 896 |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
897 break; |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
898 } |
8347 | 899 #endif |
6828
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
900 //-- |
010be15e48ad
Generate ffmpeg compatible vstats_<time>.log, when -lavdopts vstats is specified.
atmos4
parents:
6771
diff
changeset
|
901 |
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
|
902 if(!got_picture) return NULL; // skipped image |
6738 | 903 |
12006 | 904 if(init_vo(sh,avctx->pix_fmt) < 0) return NULL; |
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
|
905 |
8339 | 906 if(dr1 && pic->opaque){ |
907 mpi= (mp_image_t*)pic->opaque; | |
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
|
908 } |
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
|
909 |
5482 | 910 if(!mpi) |
4952 | 911 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
5280 | 912 avctx->width, avctx->height); |
4952 | 913 if(!mpi){ // temporary! |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
914 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_CouldntAllocateImageForCodec); |
4952 | 915 return NULL; |
916 } | |
917 | |
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
|
918 if(!dr1){ |
8339 | 919 mpi->planes[0]=pic->data[0]; |
920 mpi->planes[1]=pic->data[1]; | |
921 mpi->planes[2]=pic->data[2]; | |
922 mpi->stride[0]=pic->linesize[0]; | |
923 mpi->stride[1]=pic->linesize[1]; | |
924 mpi->stride[2]=pic->linesize[2]; | |
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
|
925 } |
11372
3761aff4722e
If alex is too lazy to apply a patch, then i'll do it :)
attila
parents:
11194
diff
changeset
|
926 |
3761aff4722e
If alex is too lazy to apply a patch, then i'll do it :)
attila
parents:
11194
diff
changeset
|
927 if (!mpi->planes[0]) |
3761aff4722e
If alex is too lazy to apply a patch, then i'll do it :)
attila
parents:
11194
diff
changeset
|
928 return NULL; |
4952 | 929 |
6873
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
930 if(avctx->pix_fmt==PIX_FMT_YUV422P && mpi->chroma_y_shift==1){ |
1206fa765697
colorspace part cleanup and support for IMGFMT_422P, _444P
arpi
parents:
6869
diff
changeset
|
931 // we have 422p but user wants 420p |
4952 | 932 mpi->stride[1]*=2; |
933 mpi->stride[2]*=2; | |
934 } | |
935 | |
6665 | 936 /* to comfirm with newer lavc style */ |
8339 | 937 mpi->qscale =pic->qscale_table; |
938 mpi->qstride=pic->qstride; | |
939 mpi->pict_type=pic->pict_type; | |
9931 | 940 #if LIBAVCODEC_BUILD >= 4664 |
9925
420640a0f6d0
passing qscale_type around so the pp code can fix the mpeg2 <<1 thing
michael
parents:
9865
diff
changeset
|
941 mpi->qscale_type= pic->qscale_type; |
9931 | 942 #endif |
11669
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
943 #if LIBAVCODEC_BUILD >= 4697 |
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
944 mpi->fields = MP_IMGFIELD_ORDERED; |
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
945 if(pic->interlaced_frame) mpi->fields |= MP_IMGFIELD_INTERLACED; |
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
946 if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST; |
11992
d8890a065727
vd_ffmpeg to set repeat-first-field patch by (Zoltan Hidvegi <mplayer at hzoli do 2y dot net>)
michael
parents:
11977
diff
changeset
|
947 if(pic->repeat_pict == 1) mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; |
11669
bcf9862f61b2
set top_field first for lavc decoding and add MP_IMGFIELD_INTERLACED
michael
parents:
11541
diff
changeset
|
948 #endif |
5517 | 949 |
4952 | 950 return mpi; |
951 } | |
952 | |
12006 | 953 static enum PixelFormat get_format(struct AVCodecContext * avctx, |
954 const enum PixelFormat * fmt){ | |
955 sh_video_t * sh = avctx->opaque; | |
956 vd_ffmpeg_ctx *ctx = sh->context; | |
957 int i; | |
958 | |
959 #ifdef HAVE_XVMC | |
960 if(avctx->xvmc_acceleration){ | |
961 avctx->get_buffer= mc_get_buffer; | |
962 avctx->release_buffer= mc_release_buffer; | |
963 avctx->draw_horiz_band = mc_render_slice; | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
964 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedMPEG2); |
12006 | 965 assert(ctx->do_dr1);//these are must to! |
966 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails | |
967 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!! | |
968 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD; | |
969 } | |
970 #endif | |
971 for(i=0;fmt[i]!=-1;i++){ | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
972 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_TryingPixfmt,i); |
12006 | 973 if( init_vo(sh,fmt[i]) >= 0) |
974 return fmt[i]; | |
975 } | |
976 return fmt[0]; | |
977 } | |
978 | |
10362 | 979 #ifdef HAVE_XVMC |
980 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ | |
981 sh_video_t * sh = avctx->opaque; | |
982 vd_ffmpeg_ctx *ctx = sh->context; | |
983 mp_image_t* mpi=NULL; | |
984 xvmc_render_state_t * render; | |
985 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE| | |
986 MP_IMGFLAG_DRAW_CALLBACK; | |
987 | |
988 // printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); | |
10452 | 989 if(!avctx->xvmc_acceleration){ |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
990 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC); |
10362 | 991 assert(0); |
992 exit(1); | |
10452 | 993 // return -1;//!!fixme check error conditions |
10362 | 994 } |
995 assert(avctx->draw_horiz_band == mc_render_slice); | |
996 assert(avctx->release_buffer == mc_release_buffer); | |
17932 | 997 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
998 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer\n"); |
10452 | 999 |
12006 | 1000 if(init_vo(sh,avctx->pix_fmt) < 0){ |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
1001 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_UnexpectedInitVoError); |
10362 | 1002 exit(1); |
10452 | 1003 // return -1;//!!fixme check error conditions |
10362 | 1004 } |
1005 | |
1006 | |
1007 | |
1008 if(!pic->reference){ | |
1009 ctx->b_count++; | |
1010 }else{ | |
1011 ctx->ip_count++; | |
1012 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE; | |
1013 } | |
1014 | |
1015 mpi= mpcodecs_get_image(sh, MP_IMGTYPE_IPB,flags , | |
1016 avctx->width, avctx->height); | |
1017 if(mpi==NULL){ | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
1018 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken); |
10362 | 1019 assert(0); |
1020 exit(1); | |
10452 | 1021 // return -1;//!!fixme check error conditions in ffmpeg |
10362 | 1022 }; |
1023 | |
1024 if( (mpi->flags & MP_IMGFLAG_DIRECT) == 0){ | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
1025 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed); |
10362 | 1026 assert(0); |
1027 exit(1); | |
10452 | 1028 // return -1;//!!fixme check error conditions in ffmpeg |
10362 | 1029 } |
1030 | |
1031 pic->data[0]= mpi->planes[0]; | |
1032 pic->data[1]= mpi->planes[1]; | |
1033 pic->data[2]= mpi->planes[2]; | |
1034 | |
1035 | |
1036 /* Note, some (many) codecs in libavcodec must have stride1==stride2 && no changes between frames | |
1037 * lavc will check that and die with an error message, if its not true | |
1038 */ | |
1039 pic->linesize[0]= mpi->stride[0]; | |
1040 pic->linesize[1]= mpi->stride[1]; | |
1041 pic->linesize[2]= mpi->stride[2]; | |
1042 | |
1043 pic->opaque = mpi; | |
1044 | |
1045 if(pic->reference){ | |
1046 //I or P frame | |
1047 pic->age= ctx->ip_age[0]; | |
1048 | |
1049 ctx->ip_age[0]= ctx->ip_age[1]+1; | |
1050 ctx->ip_age[1]= 1; | |
1051 ctx->b_age++; | |
1052 }else{ | |
1053 //B frame | |
1054 pic->age= ctx->b_age; | |
1055 | |
1056 ctx->ip_age[0]++; | |
1057 ctx->ip_age[1]++; | |
1058 ctx->b_age=1; | |
1059 } | |
10452 | 1060 |
10362 | 1061 pic->type= FF_BUFFER_TYPE_USER; |
10452 | 1062 |
10362 | 1063 render=(xvmc_render_state_t*)mpi->priv;//same as data[2] |
17932 | 1064 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
1065 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer (render=%p)\n",render); |
10362 | 1066 assert(render != 0); |
1067 assert(render->magic == MP_XVMC_RENDER_MAGIC); | |
1068 render->state |= MP_XVMC_STATE_PREDICTION; | |
1069 return 0; | |
1070 } | |
1071 | |
1072 | |
1073 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic){ | |
1074 mp_image_t* mpi= pic->opaque; | |
1075 sh_video_t * sh = avctx->opaque; | |
1076 vd_ffmpeg_ctx *ctx = sh->context; | |
1077 xvmc_render_state_t * render; | |
1078 int i; | |
1079 | |
1080 | |
1081 if(ctx->ip_count <= 2 && ctx->b_count<=1){ | |
1082 if(mpi->flags&MP_IMGFLAG_PRESERVE) | |
1083 ctx->ip_count--; | |
1084 else | |
1085 ctx->b_count--; | |
1086 } | |
1087 | |
1088 //printf("R%X %X\n", pic->linesize[0], pic->data[0]); | |
1089 //mark the surface as not requared for prediction | |
1090 render=(xvmc_render_state_t*)pic->data[2];//same as mpi->priv | |
17932 | 1091 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17973
diff
changeset
|
1092 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_release_buffer (render=%p)\n",render); |
10362 | 1093 assert(render!=NULL); |
1094 assert(render->magic==MP_XVMC_RENDER_MAGIC); | |
1095 render->state&=~MP_XVMC_STATE_PREDICTION; | |
1096 for(i=0; i<4; i++){ | |
1097 pic->data[i]= NULL; | |
1098 } | |
1099 } | |
1100 | |
1101 static void mc_render_slice(struct AVCodecContext *s, | |
10452 | 1102 AVFrame *src, int offset[4], |
1103 int y, int type, int height){ | |
1104 int width= s->width; | |
1105 sh_video_t * sh = s->opaque; | |
1106 uint8_t *source[3]= {src->data[0], src->data[1], src->data[2]}; | |
10362 | 1107 |
10452 | 1108 assert(src->linesize[0]==0 && src->linesize[1]==0 && src->linesize[2]==0); |
1109 assert(offset[0]==0 && offset[1]==0 && offset[2]==0); | |
1110 | |
1111 mpcodecs_draw_slice (sh, source, src->linesize, width, height, 0, y); | |
10362 | 1112 |
1113 } | |
1114 | |
1115 #endif // HAVE_XVMC |