5536
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7 #include "../mp_msg.h"
|
|
8
|
|
9 //#ifdef USE_LIBFAME
|
|
10
|
|
11 // 100=best >=80 very good >=50 fast
|
|
12 #define QUALITY 90
|
|
13
|
5607
|
14 #include "img_format.h"
|
|
15 #include "mp_image.h"
|
5536
|
16 #include "vf.h"
|
|
17
|
|
18 //#include "../libvo/fastmemcpy.h"
|
|
19 #include "../libfame/fame.h"
|
|
20
|
|
21 struct vf_priv_s {
|
|
22 unsigned char* outbuf;
|
|
23 int outbuf_size;
|
|
24 fame_parameters_t params;
|
|
25 fame_context_t *ctx;
|
|
26 vo_mpegpes_t pes;
|
|
27 };
|
|
28
|
|
29 //===========================================================================//
|
|
30
|
|
31 static int config(struct vf_instance_s* vf,
|
|
32 int width, int height, int d_width, int d_height,
|
|
33 unsigned int flags, unsigned int outfmt){
|
|
34 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0;
|
|
35
|
|
36 vf->priv->params.width=width;
|
|
37 vf->priv->params.height=height;
|
|
38
|
|
39 vf->priv->outbuf_size=10000+width*height; // must be enough!
|
|
40 if(vf->priv->outbuf) free(vf->priv->outbuf);
|
|
41 vf->priv->outbuf = malloc(vf->priv->outbuf_size);
|
|
42
|
|
43 fame_init(vf->priv->ctx,&vf->priv->params,vf->priv->outbuf,vf->priv->outbuf_size);
|
|
44
|
|
45 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES);
|
|
46 }
|
|
47
|
|
48 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
|
49 fame_yuv_t yuv;
|
|
50 mp_image_t *dmpi;
|
|
51 int out_size;
|
|
52
|
|
53 yuv.w=mpi->width;
|
|
54 yuv.h=mpi->height;
|
|
55 yuv.y=mpi->planes[0];
|
|
56 yuv.u=mpi->planes[1];
|
|
57 yuv.v=mpi->planes[2];
|
|
58
|
|
59 out_size = fame_encode_frame(vf->priv->ctx, &yuv, NULL);
|
|
60
|
|
61 if(out_size<=0) return;
|
|
62
|
|
63 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES,
|
|
64 MP_IMGTYPE_EXPORT, 0,
|
|
65 mpi->w, mpi->h);
|
|
66
|
|
67 vf->priv->pes.data=vf->priv->outbuf;
|
|
68 vf->priv->pes.size=out_size;
|
|
69 vf->priv->pes.id=0x1E0;
|
|
70 vf->priv->pes.timestamp=-1; // dunno
|
|
71
|
|
72 dmpi->planes[0]=&vf->priv->pes;
|
|
73
|
|
74 vf_next_put_image(vf,dmpi);
|
|
75 }
|
|
76
|
|
77 //===========================================================================//
|
|
78
|
|
79 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|
80 switch(fmt){
|
|
81 case IMGFMT_YV12:
|
|
82 case IMGFMT_I420:
|
|
83 case IMGFMT_IYUV:
|
5876
|
84 return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE)));
|
5536
|
85 }
|
|
86 return 0;
|
|
87 }
|
|
88
|
|
89 static int open(vf_instance_t *vf, char* args){
|
|
90 vf->config=config;
|
|
91 vf->put_image=put_image;
|
|
92 vf->query_format=query_format;
|
|
93 vf->priv=malloc(sizeof(struct vf_priv_s));
|
5876
|
94 vf->default_caps=0;
|
5536
|
95 memset(vf->priv,0,sizeof(struct vf_priv_s));
|
|
96
|
|
97 vf->priv->ctx=fame_open();
|
|
98 if(!vf->priv->ctx){
|
|
99 printf("FATAL: cannot open libFAME!\n");
|
|
100 return 0;
|
|
101 }
|
|
102
|
|
103 // TODO: parse args ->
|
|
104 vf->priv->params.coding="I";
|
|
105 vf->priv->params.quality=QUALITY;
|
|
106 vf->priv->params.bitrate=0;
|
|
107 vf->priv->params.slices_per_frame=1;
|
|
108 vf->priv->params.frames_per_sequence=25; //0xffffffff;
|
|
109 vf->priv->params.frame_rate_num=25;
|
|
110 vf->priv->params.frame_rate_den=1;
|
|
111 vf->priv->params.shape_quality=100;
|
|
112 vf->priv->params.search_range=8; // for "IPPP" only
|
|
113 vf->priv->params.verbose=0;
|
|
114 vf->priv->params.profile=NULL; // TODO
|
|
115
|
|
116 return 1;
|
|
117 }
|
|
118
|
|
119 vf_info_t vf_info_fame = {
|
|
120 "realtime mpeg1 encoding with libFAME",
|
|
121 "fame",
|
|
122 "A'rpi",
|
|
123 "",
|
|
124 open
|
|
125 };
|
|
126
|
|
127 //===========================================================================//
|
|
128 //#endif
|