comparison libmpcodecs/ve_nuv.c @ 28879:fad277267be5

Get rid of nuppelvideo.h and its ugly packed struct and instead write the frame header directly in nuv encoder.
author reimar
date Mon, 09 Mar 2009 15:01:12 +0000
parents aed9da3c6d0f
children 0f1b5b68af32
comparison
equal deleted inserted replaced
28878:2f71bc5f5f12 28879:fad277267be5
17 17
18 #include "img_format.h" 18 #include "img_format.h"
19 #include "mp_image.h" 19 #include "mp_image.h"
20 #include "vf.h" 20 #include "vf.h"
21 21
22 #include "libmpdemux/nuppelvideo.h" 22 #include "libavutil/intreadwrite.h"
23 #include <lzo/lzo1x.h> 23 #include <lzo/lzo1x.h>
24 #include "native/rtjpegn.h" 24 #include "native/rtjpegn.h"
25 25
26 #define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long)) 26 #define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long))
27 #define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3) 27 #define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3)
66 66
67 //===========================================================================// 67 //===========================================================================//
68 68
69 69
70 #define COMPDATASIZE (128*4) 70 #define COMPDATASIZE (128*4)
71 #define FRAMEHEADERSIZE 12
71 72
72 static int config(struct vf_instance_s* vf, 73 static int config(struct vf_instance_s* vf,
73 int width, int height, int d_width, int d_height, 74 int width, int height, int d_width, int d_height,
74 unsigned int flags, unsigned int outfmt){ 75 unsigned int flags, unsigned int outfmt){
75 76
100 if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; 101 if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
101 return 0; 102 return 0;
102 } 103 }
103 104
104 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ 105 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
105 struct rtframeheader* ench = (struct rtframeheader*)vf->priv->buffer; 106 uint8_t *header = vf->priv->buffer;
106 uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE; 107 uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE;
107 uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE; 108 uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE;
108 int len = 0, r; 109 int len = 0, r;
109 size_t zlen = 0; 110 size_t zlen = 0;
110 111
111 memset(vf->priv->buffer,0,FRAMEHEADERSIZE); // Reset the header 112 memset(header, 0, FRAMEHEADERSIZE); // Reset the header
112 if(vf->priv->lzo) 113 if(vf->priv->lzo)
113 memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE); 114 memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE);
114 115
115 // This has to be don here otherwise tv with sound doesn't work 116 // This has to be don here otherwise tv with sound doesn't work
116 if(!vf->priv->tbl_wrote) { 117 if(!vf->priv->tbl_wrote) {
117 RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q); 118 RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q);
118 RTjpeg_init_mcompress(); 119 RTjpeg_init_mcompress();
119 120
120 ench->frametype = 'D'; // compressor data 121 header[0] = 'D'; // frametype: compressor data
121 ench->comptype = 'R'; // compressor data for RTjpeg 122 header[1] = 'R'; // comptype: compressor data for RTjpeg
122 ench->packetlength = COMPDATASIZE; 123 AV_WL32(header + 8, COMPDATASIZE); // packetlength
123 124
124 le2me_rtframeheader(ench);
125 mux_v->buffer=vf->priv->buffer; 125 mux_v->buffer=vf->priv->buffer;
126 muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE); 126 muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
127 vf->priv->tbl_wrote = 1; 127 vf->priv->tbl_wrote = 1;
128 memset(ench,0,FRAMEHEADERSIZE); // Reset the header 128 memset(header, 0, FRAMEHEADERSIZE); // Reset the header
129 } 129 }
130 130
131 // Raw picture 131 // Raw picture
132 if(vf->priv->raw) { 132 if(vf->priv->raw) {
133 len = mpi->width*mpi->height*3/2; 133 len = mpi->width*mpi->height*3/2;
141 } 141 }
142 } 142 }
143 143
144 if(zlen <= 0 || zlen > len) { 144 if(zlen <= 0 || zlen > len) {
145 memcpy(data,mpi->planes[0],len); 145 memcpy(data,mpi->planes[0],len);
146 ench->comptype = '0'; 146 header[1] = '0'; // comptype: uncompressed
147 } else { // Use lzo only if it's littler 147 } else { // Use lzo only if it's littler
148 ench = (struct rtframeheader*)vf->priv->zbuffer; 148 header = vf->priv->zbuffer;
149 ench->comptype = '3'; 149 header[1] = '3'; //comptype: lzo
150 len = zlen; 150 len = zlen;
151 } 151 }
152 152
153 } else { // RTjpeg compression 153 } else { // RTjpeg compression
154 len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l, 154 len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l,
165 zlen = 0; 165 zlen = 0;
166 } 166 }
167 } 167 }
168 168
169 if(zlen <= 0 || zlen > len) 169 if(zlen <= 0 || zlen > len)
170 ench->comptype = '1'; 170 header[1] = '1'; // comptype: RTjpeg
171 else { 171 else {
172 ench = (struct rtframeheader*)vf->priv->zbuffer; 172 header = vf->priv->zbuffer;
173 ench->comptype = '2'; 173 header[1] = '2'; // comptype: RTjpeg + LZO
174 len = zlen; 174 len = zlen;
175 } 175 }
176 176
177 } 177 }
178 178
179 ench->frametype = 'V'; // video frame 179 header[0] = 'V'; // frametype: video frame
180 ench->packetlength = len; 180 AV_WL32(header + 8, len); // packetlength
181 le2me_rtframeheader(ench); 181 mux_v->buffer = header;
182 mux_v->buffer=(void*)ench;
183 muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts); 182 muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts);
184 return 1; 183 return 1;
185 } 184 }
186 185
187 static void uninit(struct vf_instance_s* vf) { 186 static void uninit(struct vf_instance_s* vf) {