Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 5233:07165a7dbed0
allow LPSTR typedef
author | arpi |
---|---|
date | Wed, 20 Mar 2002 22:31:52 +0000 |
parents | 9a2e8b32db2a |
children | ea8f3e8f39c1 |
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 | |
34 //#ifdef FF_POSTPROCESS | |
35 //unsigned int lavc_pp=0; | |
36 //#endif | |
37 | |
38 // to set/get/query special features/parameters | |
39 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
40 return CONTROL_UNKNOWN; | |
41 } | |
42 | |
43 // init driver | |
44 static int init(sh_video_t *sh){ | |
45 AVCodec *lavc_codec; | |
46 AVCodecContext *ctx; | |
47 | |
48 if(!avcodec_inited){ | |
49 avcodec_init(); | |
50 avcodec_register_all(); | |
51 avcodec_inited=1; | |
52 } | |
53 | |
54 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); | |
55 if(!lavc_codec){ | |
56 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); | |
57 return 0; | |
58 } | |
59 | |
60 ctx = sh->context = malloc(sizeof(AVCodecContext)); | |
61 memset(ctx, 0, sizeof(AVCodecContext)); | |
62 | |
63 ctx->width = sh->disp_w; | |
64 ctx->height= sh->disp_h; | |
65 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",ctx->width,ctx->height); | |
66 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) | |
67 ctx->sub_id = 3; | |
68 /* open it */ | |
69 if (avcodec_open(ctx, lavc_codec) < 0) { | |
70 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); | |
71 return 0; | |
72 } | |
73 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
5124 | 74 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
4952 | 75 } |
76 | |
77 // uninit driver | |
78 static void uninit(sh_video_t *sh){ | |
79 if (avcodec_close(sh->context) < 0) | |
80 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); | |
81 } | |
82 | |
83 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
84 | |
85 // decode a frame | |
86 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
87 int got_picture=0; | |
88 int ret; | |
89 AVPicture lavc_picture; | |
90 AVCodecContext *ctx = sh->context; | |
91 mp_image_t* mpi; | |
92 | |
93 if(len<=0) return NULL; // skipped frame | |
94 | |
95 ret = avcodec_decode_video(sh->context, &lavc_picture, | |
96 &got_picture, data, len); | |
97 | |
98 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | |
99 if(!got_picture) return NULL; // skipped image | |
100 | |
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
101 if ((ctx->width != sh->disp_w) || |
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
102 (ctx->height != sh->disp_h)) |
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
103 { |
5219 | 104 /* and what about the sh->bih (BitmapInfoHeader) width/height values? */ |
105 sh->disp_w = ctx->width; | |
106 sh->disp_h = ctx->height; | |
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
107 if (mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) |
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
108 return NULL; |
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
109 } |
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
110 |
4952 | 111 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
112 ctx->width, ctx->height); | |
113 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
|
114 printf("couldn't allocate image for codec\n"); |
4952 | 115 return NULL; |
116 } | |
117 | |
118 mpi->planes[0]=lavc_picture.data[0]; | |
119 mpi->planes[1]=lavc_picture.data[1]; | |
120 mpi->planes[2]=lavc_picture.data[2]; | |
121 mpi->stride[0]=lavc_picture.linesize[0]; | |
122 mpi->stride[1]=lavc_picture.linesize[1]; | |
123 mpi->stride[2]=lavc_picture.linesize[2]; | |
124 | |
125 if(ctx->pix_fmt==PIX_FMT_YUV422P){ | |
126 mpi->stride[1]*=2; | |
127 mpi->stride[2]*=2; | |
128 } | |
129 | |
130 return mpi; | |
131 } | |
132 | |
133 #endif | |
134 |