2003-03-03 11:03:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
#include "m_option.h"
|
|
|
|
|
|
|
|
#include "codec-cfg.h"
|
2007-03-15 17:30:55 +00:00
|
|
|
#include "stream/stream.h"
|
2007-03-15 17:51:32 +00:00
|
|
|
#include "libmpdemux/demuxer.h"
|
|
|
|
#include "libmpdemux/stheader.h"
|
2003-03-03 11:03:19 +00:00
|
|
|
|
2007-03-15 17:30:55 +00:00
|
|
|
#include "stream/stream.h"
|
2007-03-15 17:51:32 +00:00
|
|
|
#include "libmpdemux/muxer.h"
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
|
2009-03-09 15:01:12 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2007-02-18 14:54:50 +00:00
|
|
|
#include <lzo/lzo1x.h>
|
2008-04-06 18:17:59 +00:00
|
|
|
#include "native/rtjpegn.h"
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
#define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long))
|
2009-03-09 14:30:41 +00:00
|
|
|
#define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3)
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
int raw; // Do not use RTjpeg
|
|
|
|
int lzo; // Use lzo
|
|
|
|
unsigned int l,c,q; // Mjpeg param
|
|
|
|
muxer_stream_t* mux;
|
|
|
|
uint8_t* buffer;
|
|
|
|
|
|
|
|
int buf_size;
|
|
|
|
int tbl_wrote;
|
|
|
|
lzo_byte *zbuffer;
|
|
|
|
long __LZO_MMODEL *zmem;
|
|
|
|
};
|
|
|
|
#define mux_v (vf->priv->mux)
|
|
|
|
|
|
|
|
struct vf_priv_s nuv_priv_dflt = {
|
|
|
|
0, // raw
|
|
|
|
1, // lzo
|
|
|
|
1,1, // l,c
|
|
|
|
255, // q
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,0,
|
|
|
|
NULL,NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
m_option_t nuvopts_conf[]={
|
|
|
|
{"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
|
|
|
{"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL},
|
|
|
|
{"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
|
|
|
{"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL},
|
|
|
|
{"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL},
|
|
|
|
{"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
|
|
|
|
{"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
2009-05-13 02:58:57 +00:00
|
|
|
};
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
|
2009-03-09 13:37:55 +00:00
|
|
|
#define COMPDATASIZE (128*4)
|
2009-03-09 15:01:12 +00:00
|
|
|
#define FRAMEHEADERSIZE 12
|
2009-03-09 13:37:55 +00:00
|
|
|
|
2003-03-03 11:03:19 +00:00
|
|
|
static int config(struct vf_instance_s* vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
|
|
|
|
|
|
|
// We need a buffer wich can holda header and a whole YV12 picture
|
|
|
|
// or a RTJpeg table
|
|
|
|
vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE;
|
2009-03-09 13:37:55 +00:00
|
|
|
if(vf->priv->buf_size < COMPDATASIZE + FRAMEHEADERSIZE)
|
|
|
|
vf->priv->buf_size = COMPDATASIZE + FRAMEHEADERSIZE;
|
2003-03-03 11:03:19 +00:00
|
|
|
|
|
|
|
mux_v->bih->biWidth=width;
|
|
|
|
mux_v->bih->biHeight=height;
|
|
|
|
mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
|
2004-03-24 15:16:36 +00:00
|
|
|
mux_v->aspect = (float)d_width/d_height;
|
2003-03-03 11:03:19 +00:00
|
|
|
vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size);
|
2009-03-09 14:30:41 +00:00
|
|
|
if (vf->priv->lzo)
|
|
|
|
vf->priv->zbuffer = realloc(vf->priv->zbuffer, FRAMEHEADERSIZE + LZO_OUT_LEN(vf->priv->buf_size));
|
2003-03-03 11:03:19 +00:00
|
|
|
vf->priv->tbl_wrote = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vf_instance_s* vf, int request, void* data){
|
|
|
|
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
2005-04-18 15:52:38 +00:00
|
|
|
if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
2003-03-03 11:03:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-21 21:26:42 +00:00
|
|
|
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
|
2009-03-09 15:01:12 +00:00
|
|
|
uint8_t *header = vf->priv->buffer;
|
2003-03-03 11:03:19 +00:00
|
|
|
uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE;
|
|
|
|
uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE;
|
2009-03-09 14:40:55 +00:00
|
|
|
int len = 0, r;
|
|
|
|
size_t zlen = 0;
|
2003-03-03 11:03:19 +00:00
|
|
|
|
2009-03-09 15:01:12 +00:00
|
|
|
memset(header, 0, FRAMEHEADERSIZE); // Reset the header
|
2003-03-03 11:03:19 +00:00
|
|
|
if(vf->priv->lzo)
|
|
|
|
memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-03-03 11:03:19 +00:00
|
|
|
// This has to be don here otherwise tv with sound doesn't work
|
2009-05-13 02:58:57 +00:00
|
|
|
if(!vf->priv->tbl_wrote) {
|
2009-03-09 13:37:55 +00:00
|
|
|
RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q);
|
2003-03-03 11:03:19 +00:00
|
|
|
RTjpeg_init_mcompress();
|
|
|
|
|
2009-03-09 15:01:12 +00:00
|
|
|
header[0] = 'D'; // frametype: compressor data
|
|
|
|
header[1] = 'R'; // comptype: compressor data for RTjpeg
|
|
|
|
AV_WL32(header + 8, COMPDATASIZE); // packetlength
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-03-03 11:03:19 +00:00
|
|
|
mux_v->buffer=vf->priv->buffer;
|
2009-03-09 13:37:55 +00:00
|
|
|
muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
|
2003-03-03 11:03:19 +00:00
|
|
|
vf->priv->tbl_wrote = 1;
|
2009-03-09 15:01:12 +00:00
|
|
|
memset(header, 0, FRAMEHEADERSIZE); // Reset the header
|
2003-03-03 11:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Raw picture
|
|
|
|
if(vf->priv->raw) {
|
|
|
|
len = mpi->width*mpi->height*3/2;
|
|
|
|
// Try lzo ???
|
|
|
|
if(vf->priv->lzo) {
|
2009-03-09 14:32:19 +00:00
|
|
|
r = lzo1x_1_compress(mpi->planes[0],len,
|
2003-03-03 11:03:19 +00:00
|
|
|
zdata,&zlen,vf->priv->zmem);
|
|
|
|
if(r != LZO_E_OK) {
|
|
|
|
mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
|
|
|
|
zlen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(zlen <= 0 || zlen > len) {
|
|
|
|
memcpy(data,mpi->planes[0],len);
|
2009-03-09 15:01:12 +00:00
|
|
|
header[1] = '0'; // comptype: uncompressed
|
2003-03-03 11:03:19 +00:00
|
|
|
} else { // Use lzo only if it's littler
|
2009-03-09 15:01:12 +00:00
|
|
|
header = vf->priv->zbuffer;
|
|
|
|
header[1] = '3'; //comptype: lzo
|
2003-03-03 11:03:19 +00:00
|
|
|
len = zlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // RTjpeg compression
|
|
|
|
len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l,
|
|
|
|
vf->priv->c);
|
|
|
|
if(len <= 0) {
|
|
|
|
mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vf->priv->lzo) {
|
|
|
|
r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem);
|
|
|
|
if(r != LZO_E_OK) {
|
|
|
|
mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
|
|
|
|
zlen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(zlen <= 0 || zlen > len)
|
2009-03-09 15:01:12 +00:00
|
|
|
header[1] = '1'; // comptype: RTjpeg
|
2003-03-03 11:03:19 +00:00
|
|
|
else {
|
2009-03-09 15:01:12 +00:00
|
|
|
header = vf->priv->zbuffer;
|
|
|
|
header[1] = '2'; // comptype: RTjpeg + LZO
|
2003-03-03 11:03:19 +00:00
|
|
|
len = zlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2009-03-09 15:01:12 +00:00
|
|
|
header[0] = 'V'; // frametype: video frame
|
|
|
|
AV_WL32(header + 8, len); // packetlength
|
|
|
|
mux_v->buffer = header;
|
2006-03-21 21:26:42 +00:00
|
|
|
muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts);
|
2003-03-03 11:03:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-03-04 13:26:09 +00:00
|
|
|
static void uninit(struct vf_instance_s* vf) {
|
|
|
|
|
|
|
|
if(vf->priv->buffer)
|
|
|
|
free(vf->priv->buffer);
|
|
|
|
if(vf->priv->zbuffer)
|
|
|
|
free(vf->priv->zbuffer);
|
|
|
|
if(vf->priv->zmem)
|
|
|
|
free(vf->priv->zmem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-03-03 11:03:19 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int vf_open(vf_instance_t *vf, char* args){
|
|
|
|
vf->config=config;
|
2005-03-01 20:21:58 +00:00
|
|
|
vf->default_caps=VFCAP_CONSTANT;
|
2003-03-03 11:03:19 +00:00
|
|
|
vf->control=control;
|
|
|
|
vf->query_format=query_format;
|
|
|
|
vf->put_image=put_image;
|
2003-03-04 13:26:09 +00:00
|
|
|
vf->uninit = uninit;
|
2003-03-03 11:03:19 +00:00
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
|
|
memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s));
|
|
|
|
vf->priv->mux=(muxer_stream_t*)args;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-01-20 22:53:37 +00:00
|
|
|
mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER));
|
2003-03-03 11:03:19 +00:00
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
|
|
|
|
mux_v->bih->biWidth=0;
|
|
|
|
mux_v->bih->biHeight=0;
|
|
|
|
mux_v->bih->biPlanes=1;
|
|
|
|
mux_v->bih->biBitCount=12;
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('N','U','V','1');
|
|
|
|
|
|
|
|
if(vf->priv->lzo) {
|
|
|
|
if(lzo_init() != LZO_E_OK) {
|
|
|
|
mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n");
|
|
|
|
vf->priv->lzo = 0;
|
2009-03-09 14:30:41 +00:00
|
|
|
} else
|
2006-07-02 08:17:07 +00:00
|
|
|
vf->priv->zmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS));
|
2003-03-03 11:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t ve_info_nuv = {
|
|
|
|
"nuv encoder",
|
|
|
|
"nuv",
|
|
|
|
"Albeu",
|
|
|
|
"for internal use by mencoder",
|
|
|
|
vf_open
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|