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");
|
|
74 mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
|
|
75 return 1;
|
|
76 }
|
|
77
|
|
78 // uninit driver
|
|
79 static void uninit(sh_video_t *sh){
|
|
80 if (avcodec_close(sh->context) < 0)
|
|
81 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
|
|
82 }
|
|
83
|
|
84 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
|
|
85
|
|
86 // decode a frame
|
|
87 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|
88 int got_picture=0;
|
|
89 int ret;
|
|
90 AVPicture lavc_picture;
|
|
91 AVCodecContext *ctx = sh->context;
|
|
92 mp_image_t* mpi;
|
|
93
|
|
94 if(len<=0) return NULL; // skipped frame
|
|
95
|
|
96 ret = avcodec_decode_video(sh->context, &lavc_picture,
|
|
97 &got_picture, data, len);
|
|
98
|
|
99 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n");
|
|
100 if(!got_picture) return NULL; // skipped image
|
|
101
|
|
102 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
|
|
103 ctx->width, ctx->height);
|
|
104 if(!mpi){ // temporary!
|
|
105 printf("couldn't allocate image for cinepak codec\n");
|
|
106 return NULL;
|
|
107 }
|
|
108
|
|
109 mpi->planes[0]=lavc_picture.data[0];
|
|
110 mpi->planes[1]=lavc_picture.data[1];
|
|
111 mpi->planes[2]=lavc_picture.data[2];
|
|
112 mpi->stride[0]=lavc_picture.linesize[0];
|
|
113 mpi->stride[1]=lavc_picture.linesize[1];
|
|
114 mpi->stride[2]=lavc_picture.linesize[2];
|
|
115
|
|
116 if(ctx->pix_fmt==PIX_FMT_YUV422P){
|
|
117 mpi->stride[1]*=2;
|
|
118 mpi->stride[2]*=2;
|
|
119 }
|
|
120
|
|
121 return mpi;
|
|
122 }
|
|
123
|
|
124 #endif
|
|
125
|