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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4952
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
1 #include <stdio.h>
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
2 #include <stdlib.h>
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
3 #include <assert.h>
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
4
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
5 #include "config.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
6 #include "mp_msg.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
7 #include "help_mp.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
8
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
9 #ifdef USE_LIBAVCODEC
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
10
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
11 #include "bswap.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
12
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
13 #include "vd_internal.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
14
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
15 static vd_info_t info = {
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
16 "FFmpeg's libavcodec codec family",
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
17 "ffmpeg",
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
18 VFM_FFMPEG,
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
19 "A'rpi",
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
20 "http://ffmpeg.sf.net",
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
21 "native codecs"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
22 };
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
23
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
24 LIBVD_EXTERN(ffmpeg)
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
25
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
26 #ifdef USE_LIBAVCODEC_SO
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
27 #include <libffmpeg/avcodec.h>
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
28 #else
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
29 #include "libavcodec/avcodec.h"
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
30 #endif
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
31
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
32 int avcodec_inited=0;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
33
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
34 //#ifdef FF_POSTPROCESS
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
35 //unsigned int lavc_pp=0;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
36 //#endif
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
37
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
38 // to set/get/query special features/parameters
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
39 static int control(sh_video_t *sh,int cmd,void* arg,...){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
40 return CONTROL_UNKNOWN;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
41 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
42
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
43 // init driver
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
44 static int init(sh_video_t *sh){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
45 AVCodec *lavc_codec;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
46 AVCodecContext *ctx;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
47
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
48 if(!avcodec_inited){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
49 avcodec_init();
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
50 avcodec_register_all();
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
51 avcodec_inited=1;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
52 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
53
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
54 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
55 if(!lavc_codec){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
56 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
57 return 0;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
58 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
59
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
60 ctx = sh->context = malloc(sizeof(AVCodecContext));
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
61 memset(ctx, 0, sizeof(AVCodecContext));
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
62
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
63 ctx->width = sh->disp_w;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
64 ctx->height= sh->disp_h;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
65 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",ctx->width,ctx->height);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
66 if (sh->format == mmioFOURCC('R', 'V', '1', '3'))
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
67 ctx->sub_id = 3;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
68 /* open it */
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
69 if (avcodec_open(ctx, lavc_codec) < 0) {
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
70 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
71 return 0;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
72 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
73 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n");
5124
3dcbf67c0de0 handle error from mpcodecs_config_vo()
arpi
parents: 4986
diff changeset
74 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
4952
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
75 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
76
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
77 // uninit driver
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
78 static void uninit(sh_video_t *sh){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
79 if (avcodec_close(sh->context) < 0)
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
80 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
81 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
82
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
83 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
84
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
85 // decode a frame
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
86 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
87 int got_picture=0;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
88 int ret;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
89 AVPicture lavc_picture;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
90 AVCodecContext *ctx = sh->context;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
91 mp_image_t* mpi;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
92
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
93 if(len<=0) return NULL; // skipped frame
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
94
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
95 ret = avcodec_decode_video(sh->context, &lavc_picture,
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
96 &got_picture, data, len);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
97
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
98 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
99 if(!got_picture) return NULL; // skipped image
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
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
alex
parents: 5207
diff changeset
104 /* and what about the sh->bih (BitmapInfoHeader) width/height values? */
alex
parents: 5207
diff changeset
105 sh->disp_w = ctx->width;
alex
parents: 5207
diff changeset
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
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
111 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
112 ctx->width, ctx->height);
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
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
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
115 return NULL;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
116 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
117
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
118 mpi->planes[0]=lavc_picture.data[0];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
119 mpi->planes[1]=lavc_picture.data[1];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
120 mpi->planes[2]=lavc_picture.data[2];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
121 mpi->stride[0]=lavc_picture.linesize[0];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
122 mpi->stride[1]=lavc_picture.linesize[1];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
123 mpi->stride[2]=lavc_picture.linesize[2];
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
124
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
125 if(ctx->pix_fmt==PIX_FMT_YUV422P){
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
126 mpi->stride[1]*=2;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
127 mpi->stride[2]*=2;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
128 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
129
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
130 return mpi;
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
131 }
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
132
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
133 #endif
ffeba1050226 vd_ffmpeg added
arpi
parents:
diff changeset
134