Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 5482:cd97c8313300
libavcodec slices support
author | arpi |
---|---|
date | Wed, 03 Apr 2002 23:59:54 +0000 |
parents | f248c9e86423 |
children | 1c45b1484ffb |
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 | |
5280 | 34 typedef struct { |
35 AVCodecContext *avctx; | |
5482 | 36 int last_aspect; |
37 int do_slices; | |
38 int vo_inited; | |
5280 | 39 } vd_ffmpeg_ctx; |
40 | |
4952 | 41 //#ifdef FF_POSTPROCESS |
42 //unsigned int lavc_pp=0; | |
43 //#endif | |
44 | |
45 // to set/get/query special features/parameters | |
46 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
47 return CONTROL_UNKNOWN; | |
48 } | |
49 | |
50 // init driver | |
51 static int init(sh_video_t *sh){ | |
5280 | 52 AVCodecContext *avctx; |
53 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
|
54 AVCodec *lavc_codec; |
4952 | 55 |
56 if(!avcodec_inited){ | |
57 avcodec_init(); | |
58 avcodec_register_all(); | |
59 avcodec_inited=1; | |
60 } | |
5280 | 61 |
62 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
63 if (!ctx) | |
64 return(0); | |
65 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
4952 | 66 |
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
|
67 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
|
68 if(!lavc_codec){ |
4952 | 69 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
70 return 0; | |
71 } | |
5482 | 72 |
73 // currently buggy with B frames... | |
74 // if(vd_use_slices && lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) | |
75 // ctx->do_slices=1; | |
4952 | 76 |
5280 | 77 ctx->avctx = malloc(sizeof(AVCodecContext)); |
78 memset(ctx->avctx, 0, sizeof(AVCodecContext)); | |
79 avctx = ctx->avctx; | |
4952 | 80 |
5280 | 81 avctx->width = sh->disp_w; |
82 avctx->height= sh->disp_h; | |
83 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); | |
4952 | 84 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) |
5280 | 85 avctx->sub_id = 3; |
4952 | 86 /* 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
|
87 if (avcodec_open(avctx, lavc_codec) < 0) { |
4952 | 88 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
89 return 0; | |
90 } | |
91 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
5482 | 92 ctx->last_aspect=-3; |
93 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); | |
4952 | 94 } |
95 | |
96 // uninit driver | |
97 static void uninit(sh_video_t *sh){ | |
5280 | 98 vd_ffmpeg_ctx *ctx = sh->context; |
99 AVCodecContext *avctx = ctx->avctx; | |
100 | |
101 if (avcodec_close(avctx) < 0) | |
4952 | 102 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
5280 | 103 if (avctx) |
104 free(avctx); | |
105 if (ctx) | |
106 free(ctx); | |
4952 | 107 } |
108 | |
5482 | 109 #include "libvo/video_out.h" // FIXME!!! |
110 | |
111 static void draw_slice(struct AVCodecContext *s, | |
112 UINT8 **src, int linesize, | |
113 int y, int width, int height){ | |
114 vo_functions_t * output = s->opaque; | |
115 int stride[3]; | |
116 | |
117 stride[0]=linesize; | |
118 stride[1]=stride[2]=stride[0]/2; | |
119 | |
120 output->draw_slice (src, stride, width, height, 0, y); | |
121 | |
122 } | |
4952 | 123 |
124 // decode a frame | |
125 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
126 int got_picture=0; | |
127 int ret; | |
128 AVPicture lavc_picture; | |
5280 | 129 vd_ffmpeg_ctx *ctx = sh->context; |
130 AVCodecContext *avctx = ctx->avctx; | |
5482 | 131 mp_image_t* mpi=NULL; |
4952 | 132 |
133 if(len<=0) return NULL; // skipped frame | |
134 | |
5482 | 135 if(ctx->vo_inited){ |
136 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | | |
137 (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), | |
138 sh->disp_w, sh->disp_h); | |
139 if(mpi && mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ | |
140 // vd core likes slices! | |
141 avctx->draw_horiz_band=draw_slice; | |
142 avctx->opaque=sh->video_out; | |
143 } else | |
144 avctx->draw_horiz_band=NULL; | |
145 } | |
146 | |
5280 | 147 ret = avcodec_decode_video(avctx, &lavc_picture, |
4952 | 148 &got_picture, data, len); |
149 | |
150 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | |
151 if(!got_picture) return NULL; // skipped image | |
5280 | 152 |
5482 | 153 if (avctx->aspect_ratio_info != ctx->last_aspect || |
154 avctx->width != sh->disp_w || | |
155 avctx->height != sh->disp_h || | |
156 !ctx->vo_inited) | |
5280 | 157 { |
158 ctx->last_aspect = avctx->aspect_ratio_info; | |
159 switch(avctx->aspect_ratio_info) | |
160 { | |
161 case FF_ASPECT_4_3_625: | |
162 case FF_ASPECT_4_3_525: | |
163 sh->aspect = 4.0/3.0; | |
164 break; | |
165 case FF_ASPECT_16_9_625: | |
166 case FF_ASPECT_16_9_525: | |
167 sh->aspect = 16.0/9.0; | |
168 break; | |
169 case FF_ASPECT_SQUARE: | |
170 default: | |
171 sh->aspect = 0.0; | |
172 break; | |
173 } | |
5482 | 174 sh->disp_w = avctx->width; |
175 sh->disp_h = avctx->height; | |
176 ctx->vo_inited=1; | |
177 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
|
178 return NULL; |
5280 | 179 } |
4952 | 180 |
5482 | 181 if(!mpi) |
4952 | 182 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
5280 | 183 avctx->width, avctx->height); |
4952 | 184 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
|
185 printf("couldn't allocate image for codec\n"); |
4952 | 186 return NULL; |
187 } | |
188 | |
189 mpi->planes[0]=lavc_picture.data[0]; | |
190 mpi->planes[1]=lavc_picture.data[1]; | |
191 mpi->planes[2]=lavc_picture.data[2]; | |
192 mpi->stride[0]=lavc_picture.linesize[0]; | |
193 mpi->stride[1]=lavc_picture.linesize[1]; | |
194 mpi->stride[2]=lavc_picture.linesize[2]; | |
195 | |
5280 | 196 if(avctx->pix_fmt==PIX_FMT_YUV422P){ |
4952 | 197 mpi->stride[1]*=2; |
198 mpi->stride[2]*=2; | |
199 } | |
200 | |
201 return mpi; | |
202 } | |
203 | |
204 #endif | |
205 |