Mercurial > mplayer.hg
comparison libmpcodecs/ve_nuv.c @ 9520:2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
author | albeu |
---|---|
date | Mon, 03 Mar 2003 11:03:19 +0000 |
parents | |
children | cf2324339983 |
comparison
equal
deleted
inserted
replaced
9519:34b636d19268 | 9520:2860f7c9d9ca |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 #include "../config.h" | |
6 #include "../mp_msg.h" | |
7 | |
8 #include "m_option.h" | |
9 | |
10 #include "codec-cfg.h" | |
11 #include "stream.h" | |
12 #include "demuxer.h" | |
13 #include "stheader.h" | |
14 | |
15 #include "muxer.h" | |
16 | |
17 #include "img_format.h" | |
18 #include "mp_image.h" | |
19 #include "vf.h" | |
20 | |
21 #include "libmpdemux/nuppelvideo.h" | |
22 #include "native/minilzo.h" | |
23 #include "native/RTjpegN.h" | |
24 | |
25 #define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long)) | |
26 #define LZO_IN_LEN (1024*1024L) | |
27 #define LZO_OUT_LEN (LZO_IN_LEN + LZO_IN_LEN / 64 + 16 + 3) | |
28 | |
29 //===========================================================================// | |
30 | |
31 struct vf_priv_s { | |
32 int raw; // Do not use RTjpeg | |
33 int lzo; // Use lzo | |
34 unsigned int l,c,q; // Mjpeg param | |
35 muxer_stream_t* mux; | |
36 uint8_t* buffer; | |
37 | |
38 int buf_size; | |
39 int tbl_wrote; | |
40 lzo_byte *zbuffer; | |
41 long __LZO_MMODEL *zmem; | |
42 }; | |
43 #define mux_v (vf->priv->mux) | |
44 | |
45 struct vf_priv_s nuv_priv_dflt = { | |
46 0, // raw | |
47 1, // lzo | |
48 1,1, // l,c | |
49 255, // q | |
50 NULL, | |
51 NULL, | |
52 0,0, | |
53 NULL,NULL | |
54 }; | |
55 | |
56 m_option_t nuvopts_conf[]={ | |
57 {"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
58 {"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL}, | |
59 {"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
60 {"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL}, | |
61 {"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL}, | |
62 {"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, | |
63 {"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, | |
64 {NULL, NULL, 0, 0, 0, 0, NULL} | |
65 }; | |
66 | |
67 //===========================================================================// | |
68 | |
69 | |
70 static int config(struct vf_instance_s* vf, | |
71 int width, int height, int d_width, int d_height, | |
72 unsigned int flags, unsigned int outfmt){ | |
73 | |
74 // We need a buffer wich can holda header and a whole YV12 picture | |
75 // or a RTJpeg table | |
76 vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE; | |
77 if(vf->priv->buf_size < (int)(128*sizeof(long int) + FRAMEHEADERSIZE)) | |
78 vf->priv->buf_size = 128*sizeof(long int) + FRAMEHEADERSIZE; | |
79 | |
80 mux_v->bih->biWidth=width; | |
81 mux_v->bih->biHeight=height; | |
82 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
83 vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size); | |
84 vf->priv->tbl_wrote = 0; | |
85 | |
86 return 1; | |
87 } | |
88 | |
89 static int control(struct vf_instance_s* vf, int request, void* data){ | |
90 | |
91 return CONTROL_UNKNOWN; | |
92 } | |
93 | |
94 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
95 if(fmt==IMGFMT_I420) return 3; | |
96 return 0; | |
97 } | |
98 | |
99 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
100 struct rtframeheader* ench = (struct rtframeheader*)vf->priv->buffer; | |
101 uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE; | |
102 uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE; | |
103 int len = 0, zlen = 0,r; | |
104 | |
105 memset(vf->priv->buffer,0,FRAMEHEADERSIZE); // Reset the header | |
106 if(vf->priv->lzo) | |
107 memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE); | |
108 | |
109 // This has to be don here otherwise tv with sound doesn't work | |
110 if(!vf->priv->tbl_wrote) { | |
111 RTjpeg_init_compress((long int*)data,mpi->width,mpi->height,vf->priv->q); | |
112 RTjpeg_init_mcompress(); | |
113 | |
114 ench->frametype = 'D'; // compressor data | |
115 ench->comptype = 'R'; // compressor data for RTjpeg | |
116 ench->packetlength = 128*sizeof(long int); | |
117 | |
118 mux_v->buffer=vf->priv->buffer; | |
119 muxer_write_chunk(mux_v,FRAMEHEADERSIZE + 128*sizeof(long int), 0x10); | |
120 vf->priv->tbl_wrote = 1; | |
121 memset(ench,0,FRAMEHEADERSIZE); // Reset the header | |
122 } | |
123 | |
124 // Raw picture | |
125 if(vf->priv->raw) { | |
126 len = mpi->width*mpi->height*3/2; | |
127 // Try lzo ??? | |
128 if(vf->priv->lzo) { | |
129 r = lzo1x_1_compress(mpi->planes[0],mpi->width*mpi->height*3/2, | |
130 zdata,&zlen,vf->priv->zmem); | |
131 if(r != LZO_E_OK) { | |
132 mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); | |
133 zlen = 0; | |
134 } | |
135 } | |
136 | |
137 if(zlen <= 0 || zlen > len) { | |
138 memcpy(data,mpi->planes[0],len); | |
139 ench->comptype = '0'; | |
140 } else { // Use lzo only if it's littler | |
141 ench = (struct rtframeheader*)vf->priv->zbuffer; | |
142 ench->comptype = '3'; | |
143 len = zlen; | |
144 } | |
145 | |
146 } else { // RTjpeg compression | |
147 len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l, | |
148 vf->priv->c); | |
149 if(len <= 0) { | |
150 mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len); | |
151 return 0; | |
152 } | |
153 | |
154 if(vf->priv->lzo) { | |
155 r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem); | |
156 if(r != LZO_E_OK) { | |
157 mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); | |
158 zlen = 0; | |
159 } | |
160 } | |
161 | |
162 if(zlen <= 0 || zlen > len) | |
163 ench->comptype = '1'; | |
164 else { | |
165 ench = (struct rtframeheader*)vf->priv->zbuffer; | |
166 ench->comptype = '2'; | |
167 len = zlen; | |
168 } | |
169 | |
170 } | |
171 | |
172 ench->frametype = 'V'; // video frame | |
173 ench->packetlength = len; | |
174 mux_v->buffer=(void*)ench; | |
175 muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10); | |
176 return 1; | |
177 } | |
178 | |
179 //===========================================================================// | |
180 | |
181 static int vf_open(vf_instance_t *vf, char* args){ | |
182 vf->config=config; | |
183 vf->control=control; | |
184 vf->query_format=query_format; | |
185 vf->put_image=put_image; | |
186 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
187 memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s)); | |
188 //memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
189 vf->priv->mux=(muxer_stream_t*)args; | |
190 | |
191 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
192 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
193 mux_v->bih->biWidth=0; | |
194 mux_v->bih->biHeight=0; | |
195 mux_v->bih->biPlanes=1; | |
196 mux_v->bih->biBitCount=12; | |
197 mux_v->bih->biCompression = mmioFOURCC('N','U','V','1'); | |
198 | |
199 if(vf->priv->lzo) { | |
200 if(lzo_init() != LZO_E_OK) { | |
201 mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n"); | |
202 vf->priv->lzo = 0; | |
203 } | |
204 vf->priv->zbuffer = (lzo_bytep)malloc(FRAMEHEADERSIZE + LZO_OUT_LEN); | |
205 vf->priv->zmem = (long*)malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); | |
206 } | |
207 | |
208 return 1; | |
209 } | |
210 | |
211 vf_info_t ve_info_nuv = { | |
212 "nuv encoder", | |
213 "nuv", | |
214 "Albeu", | |
215 "for internal use by mencoder", | |
216 vf_open | |
217 }; | |
218 | |
219 //===========================================================================// |