Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 5526:30679378f814
free old context, really use query_format
author | arpi |
---|---|
date | Sun, 07 Apr 2002 23:30:59 +0000 |
parents | a3337d7b853f |
children | b545d56314d2 |
rev | line source |
---|---|
4952 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <assert.h> | |
4 | |
5 #include "config.h" | |
6 #include "mp_msg.h" | |
7 #include "help_mp.h" | |
8 | |
9 #ifdef USE_LIBAVCODEC | |
10 | |
11 #include "bswap.h" | |
12 | |
13 #include "vd_internal.h" | |
14 | |
15 static vd_info_t info = { | |
16 "FFmpeg's libavcodec codec family", | |
17 "ffmpeg", | |
18 VFM_FFMPEG, | |
19 "A'rpi", | |
20 "http://ffmpeg.sf.net", | |
21 "native codecs" | |
22 }; | |
23 | |
24 LIBVD_EXTERN(ffmpeg) | |
25 | |
26 #ifdef USE_LIBAVCODEC_SO | |
27 #include <libffmpeg/avcodec.h> | |
28 #else | |
29 #include "libavcodec/avcodec.h" | |
30 #endif | |
31 | |
32 int avcodec_inited=0; | |
33 | |
5517 | 34 #ifdef FF_POSTPROCESS |
35 int quant_store[MBR+1][MBC+1]; | |
36 #endif | |
37 | |
5280 | 38 typedef struct { |
39 AVCodecContext *avctx; | |
5482 | 40 int last_aspect; |
41 int do_slices; | |
42 int vo_inited; | |
5280 | 43 } vd_ffmpeg_ctx; |
44 | |
4952 | 45 //#ifdef FF_POSTPROCESS |
46 //unsigned int lavc_pp=0; | |
47 //#endif | |
48 | |
49 // to set/get/query special features/parameters | |
50 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
51 return CONTROL_UNKNOWN; | |
52 } | |
53 | |
54 // init driver | |
55 static int init(sh_video_t *sh){ | |
5280 | 56 AVCodecContext *avctx; |
57 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
|
58 AVCodec *lavc_codec; |
4952 | 59 |
60 if(!avcodec_inited){ | |
61 avcodec_init(); | |
62 avcodec_register_all(); | |
63 avcodec_inited=1; | |
64 } | |
5280 | 65 |
66 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
67 if (!ctx) | |
68 return(0); | |
69 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
4952 | 70 |
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
|
71 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
|
72 if(!lavc_codec){ |
4952 | 73 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
74 return 0; | |
75 } | |
5482 | 76 |
5494
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
77 if(vd_use_slices && lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) |
1c45b1484ffb
i just fixed b-frames & slices in libavcodec :) ... iam too tired for benchmarks now ...
michael
parents:
5482
diff
changeset
|
78 ctx->do_slices=1; |
4952 | 79 |
5280 | 80 ctx->avctx = malloc(sizeof(AVCodecContext)); |
81 memset(ctx->avctx, 0, sizeof(AVCodecContext)); | |
82 avctx = ctx->avctx; | |
4952 | 83 |
5280 | 84 avctx->width = sh->disp_w; |
85 avctx->height= sh->disp_h; | |
86 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); | |
4952 | 87 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) |
5280 | 88 avctx->sub_id = 3; |
4952 | 89 /* 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
|
90 if (avcodec_open(avctx, lavc_codec) < 0) { |
4952 | 91 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
92 return 0; | |
93 } | |
94 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
5482 | 95 ctx->last_aspect=-3; |
5510 | 96 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
4952 | 97 } |
98 | |
99 // uninit driver | |
100 static void uninit(sh_video_t *sh){ | |
5280 | 101 vd_ffmpeg_ctx *ctx = sh->context; |
102 AVCodecContext *avctx = ctx->avctx; | |
103 | |
104 if (avcodec_close(avctx) < 0) | |
4952 | 105 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
5280 | 106 if (avctx) |
107 free(avctx); | |
108 if (ctx) | |
109 free(ctx); | |
4952 | 110 } |
111 | |
5482 | 112 #include "libvo/video_out.h" // FIXME!!! |
113 | |
114 static void draw_slice(struct AVCodecContext *s, | |
115 UINT8 **src, int linesize, | |
116 int y, int width, int height){ | |
117 vo_functions_t * output = s->opaque; | |
118 int stride[3]; | |
119 | |
120 stride[0]=linesize; | |
121 stride[1]=stride[2]=stride[0]/2; | |
122 | |
123 output->draw_slice (src, stride, width, height, 0, y); | |
124 | |
125 } | |
4952 | 126 |
127 // decode a frame | |
128 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
129 int got_picture=0; | |
130 int ret; | |
131 AVPicture lavc_picture; | |
5280 | 132 vd_ffmpeg_ctx *ctx = sh->context; |
133 AVCodecContext *avctx = ctx->avctx; | |
5482 | 134 mp_image_t* mpi=NULL; |
4952 | 135 |
136 if(len<=0) return NULL; // skipped frame | |
137 | |
5482 | 138 if(ctx->vo_inited){ |
139 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | | |
140 (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), | |
141 sh->disp_w, sh->disp_h); | |
142 if(mpi && mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ | |
143 // vd core likes slices! | |
144 avctx->draw_horiz_band=draw_slice; | |
145 avctx->opaque=sh->video_out; | |
146 } else | |
147 avctx->draw_horiz_band=NULL; | |
148 } | |
149 | |
5280 | 150 ret = avcodec_decode_video(avctx, &lavc_picture, |
4952 | 151 &got_picture, data, len); |
152 | |
153 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | |
154 if(!got_picture) return NULL; // skipped image | |
5280 | 155 |
5482 | 156 if (avctx->aspect_ratio_info != ctx->last_aspect || |
157 avctx->width != sh->disp_w || | |
158 avctx->height != sh->disp_h || | |
159 !ctx->vo_inited) | |
5280 | 160 { |
161 ctx->last_aspect = avctx->aspect_ratio_info; | |
162 switch(avctx->aspect_ratio_info) | |
163 { | |
164 case FF_ASPECT_4_3_625: | |
165 case FF_ASPECT_4_3_525: | |
166 sh->aspect = 4.0/3.0; | |
167 break; | |
168 case FF_ASPECT_16_9_625: | |
169 case FF_ASPECT_16_9_525: | |
170 sh->aspect = 16.0/9.0; | |
171 break; | |
172 case FF_ASPECT_SQUARE: | |
173 default: | |
174 sh->aspect = 0.0; | |
175 break; | |
176 } | |
5482 | 177 sh->disp_w = avctx->width; |
178 sh->disp_h = avctx->height; | |
179 ctx->vo_inited=1; | |
180 if (mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) | |
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
|
181 return NULL; |
5280 | 182 } |
4952 | 183 |
5482 | 184 if(!mpi) |
4952 | 185 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
5280 | 186 avctx->width, avctx->height); |
4952 | 187 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
|
188 printf("couldn't allocate image for codec\n"); |
4952 | 189 return NULL; |
190 } | |
191 | |
192 mpi->planes[0]=lavc_picture.data[0]; | |
193 mpi->planes[1]=lavc_picture.data[1]; | |
194 mpi->planes[2]=lavc_picture.data[2]; | |
195 mpi->stride[0]=lavc_picture.linesize[0]; | |
196 mpi->stride[1]=lavc_picture.linesize[1]; | |
197 mpi->stride[2]=lavc_picture.linesize[2]; | |
198 | |
5280 | 199 if(avctx->pix_fmt==PIX_FMT_YUV422P){ |
4952 | 200 mpi->stride[1]*=2; |
201 mpi->stride[2]*=2; | |
202 } | |
203 | |
5517 | 204 #ifdef FF_POSTPROCESS |
205 mpi->qscale=&quant_store[0][0]; | |
206 mpi->qstride=MBC+1; | |
207 #endif | |
208 | |
4952 | 209 return mpi; |
210 } | |
211 | |
212 #endif | |
213 |