comparison libmpcodecs/vd_ffmpeg.c @ 4952:ffeba1050226

vd_ffmpeg added
author arpi
date Wed, 06 Mar 2002 20:54:43 +0000
parents
children eb57973314ae
comparison
equal deleted inserted replaced
4951:e5bd91881646 4952:ffeba1050226
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 "codec-cfg.h"
14 #include "../libvo/img_format.h"
15
16 #include "stream.h"
17 #include "demuxer.h"
18 #include "stheader.h"
19
20 #include "vd.h"
21 #include "vd_internal.h"
22
23 static vd_info_t info = {
24 "FFmpeg's libavcodec codec family",
25 "ffmpeg",
26 VFM_FFMPEG,
27 "A'rpi",
28 "http://ffmpeg.sf.net",
29 "native codecs"
30 };
31
32 LIBVD_EXTERN(ffmpeg)
33
34 #ifdef USE_LIBAVCODEC_SO
35 #include <libffmpeg/avcodec.h>
36 #else
37 #include "libavcodec/avcodec.h"
38 #endif
39
40 int avcodec_inited=0;
41
42 //#ifdef FF_POSTPROCESS
43 //unsigned int lavc_pp=0;
44 //#endif
45
46 // to set/get/query special features/parameters
47 static int control(sh_video_t *sh,int cmd,void* arg,...){
48 return CONTROL_UNKNOWN;
49 }
50
51 // init driver
52 static int init(sh_video_t *sh){
53 AVCodec *lavc_codec;
54 AVCodecContext *ctx;
55
56 if(!avcodec_inited){
57 avcodec_init();
58 avcodec_register_all();
59 avcodec_inited=1;
60 }
61
62 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll);
63 if(!lavc_codec){
64 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll);
65 return 0;
66 }
67
68 ctx = sh->context = malloc(sizeof(AVCodecContext));
69 memset(ctx, 0, sizeof(AVCodecContext));
70
71 ctx->width = sh->disp_w;
72 ctx->height= sh->disp_h;
73 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",ctx->width,ctx->height);
74 if (sh->format == mmioFOURCC('R', 'V', '1', '3'))
75 ctx->sub_id = 3;
76 /* open it */
77 if (avcodec_open(ctx, lavc_codec) < 0) {
78 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec);
79 return 0;
80 }
81 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n");
82 mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
83 return 1;
84 }
85
86 // uninit driver
87 static void uninit(sh_video_t *sh){
88 if (avcodec_close(sh->context) < 0)
89 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
90 }
91
92 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
93
94 // decode a frame
95 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
96 int got_picture=0;
97 int ret;
98 AVPicture lavc_picture;
99 AVCodecContext *ctx = sh->context;
100 mp_image_t* mpi;
101
102 if(len<=0) return NULL; // skipped frame
103
104 ret = avcodec_decode_video(sh->context, &lavc_picture,
105 &got_picture, data, len);
106
107 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
108 if(!got_picture) return NULL; // skipped image
109
110 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
111 ctx->width, ctx->height);
112 if(!mpi){ // temporary!
113 printf("couldn't allocate image for cinepak codec\n");
114 return NULL;
115 }
116
117 mpi->planes[0]=lavc_picture.data[0];
118 mpi->planes[1]=lavc_picture.data[1];
119 mpi->planes[2]=lavc_picture.data[2];
120 mpi->stride[0]=lavc_picture.linesize[0];
121 mpi->stride[1]=lavc_picture.linesize[1];
122 mpi->stride[2]=lavc_picture.linesize[2];
123
124 if(ctx->pix_fmt==PIX_FMT_YUV422P){
125 mpi->stride[1]*=2;
126 mpi->stride[2]*=2;
127 }
128
129 return mpi;
130 }
131
132 #endif
133