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