annotate libmpcodecs/vf_fame.c @ 5887:f684e461f141

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