typo fixes
[mplayer/greg.git] / libmpcodecs / vf_fame.c
blob6eeb29530da8445ca26c82e8336868b501486cf4
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
8 #include "help_mp.h"
10 //#ifdef USE_LIBFAME
12 // 100=best >=80 very good >=50 fast
13 #define QUALITY 90
15 #include "img_format.h"
16 #include "mp_image.h"
17 #include "vf.h"
19 //#include "libvo/fastmemcpy.h"
20 #include <fame.h>
22 struct vf_priv_s {
23 unsigned char* outbuf;
24 int outbuf_size;
25 fame_parameters_t params;
26 fame_context_t *ctx;
27 vo_mpegpes_t pes;
30 //===========================================================================//
32 static int config(struct vf_instance_s* vf,
33 int width, int height, int d_width, int d_height,
34 unsigned int flags, unsigned int outfmt){
35 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0;
37 vf->priv->params.width=width;
38 vf->priv->params.height=height;
40 vf->priv->outbuf_size=10000+width*height; // must be enough!
41 if(vf->priv->outbuf) free(vf->priv->outbuf);
42 vf->priv->outbuf = malloc(vf->priv->outbuf_size);
44 fame_init(vf->priv->ctx,&vf->priv->params,vf->priv->outbuf,vf->priv->outbuf_size);
46 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES);
49 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
50 fame_yuv_t yuv;
51 mp_image_t *dmpi;
52 int out_size;
54 yuv.w=mpi->width;
55 yuv.h=mpi->height;
56 yuv.p=mpi->stride[0];
57 yuv.y=mpi->planes[0];
58 yuv.u=mpi->planes[1];
59 yuv.v=mpi->planes[2];
61 // out_size = fame_encode_frame(vf->priv->ctx, &yuv, NULL);
62 fame_start_frame(vf->priv->ctx, &yuv, NULL);
63 out_size = fame_encode_slice(vf->priv->ctx);
64 fame_end_frame(vf->priv->ctx, NULL);
66 if(out_size<=0) return 1;
68 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES,
69 MP_IMGTYPE_EXPORT, 0,
70 mpi->w, mpi->h);
72 vf->priv->pes.data=vf->priv->outbuf;
73 vf->priv->pes.size=out_size;
74 vf->priv->pes.id=0x1E0;
75 vf->priv->pes.timestamp=-1; // dunno
77 dmpi->planes[0]=(void*) &vf->priv->pes;
79 return vf_next_put_image(vf,dmpi, MP_NOPTS_VALUE);
82 //===========================================================================//
84 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
85 switch(fmt){
86 case IMGFMT_YV12:
87 case IMGFMT_I420:
88 case IMGFMT_IYUV:
89 // return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE)));
90 return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW)));
92 return 0;
95 static int open(vf_instance_t *vf, char* args){
96 int p_quality=0;
97 float p_fps=0;
99 vf->config=config;
100 vf->put_image=put_image;
101 vf->query_format=query_format;
102 vf->priv=malloc(sizeof(struct vf_priv_s));
103 memset(vf->priv,0,sizeof(struct vf_priv_s));
105 vf->priv->ctx=fame_open();
106 if(!vf->priv->ctx){
107 mp_msg(MSGT_VFILTER, MSGL_ERR, MSGTR_MPCODECS_FatalCantOpenlibFAME);
108 return 0;
111 // TODO: parse args ->
112 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps);
114 if(p_quality<=100){
115 // fixed quality
116 vf->priv->params.quality=p_quality?p_quality:QUALITY;
117 vf->priv->params.bitrate=0;
118 } else {
119 // fixed bitrate (in kbits)
120 vf->priv->params.quality=QUALITY;
121 vf->priv->params.bitrate=1000*p_quality;
124 if(p_fps<1) p_fps=25.0;
125 if(p_fps == ((int)p_fps)){
126 vf->priv->params.frame_rate_num=p_fps;
127 vf->priv->params.frame_rate_den=1;
128 } else {
129 vf->priv->params.frame_rate_num=p_fps*1001;
130 vf->priv->params.frame_rate_den=1001;
133 vf->priv->params.coding="I";
134 vf->priv->params.slices_per_frame=1;
135 vf->priv->params.frames_per_sequence=(int)p_fps;
136 vf->priv->params.shape_quality=100;
137 vf->priv->params.search_range=8; // for "IPPP" only
138 vf->priv->params.verbose=0;
139 vf->priv->params.profile="mpeg1"; // TODO
141 return 1;
144 vf_info_t vf_info_fame = {
145 "realtime mpeg1 encoding with libFAME",
146 "fame",
147 "A'rpi",
149 open,
150 NULL
153 //===========================================================================//
154 //#endif