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
|
|
101 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
|
|
102 ctx->width, ctx->height);
|
|
103 if(!mpi){ // temporary!
|
|
104 printf("couldn't allocate image for cinepak codec\n");
|
|
105 return NULL;
|
|
106 }
|
|
107
|
|
108 mpi->planes[0]=lavc_picture.data[0];
|
|
109 mpi->planes[1]=lavc_picture.data[1];
|
|
110 mpi->planes[2]=lavc_picture.data[2];
|
|
111 mpi->stride[0]=lavc_picture.linesize[0];
|
|
112 mpi->stride[1]=lavc_picture.linesize[1];
|
|
113 mpi->stride[2]=lavc_picture.linesize[2];
|
|
114
|
|
115 if(ctx->pix_fmt==PIX_FMT_YUV422P){
|
|
116 mpi->stride[1]*=2;
|
|
117 mpi->stride[2]*=2;
|
|
118 }
|
|
119
|
|
120 return mpi;
|
|
121 }
|
|
122
|
|
123 #endif
|
|
124
|