Mercurial > mplayer.hg
annotate libmpcodecs/ve_nuv.c @ 35883:804c3926503b
Fix a potential integer overflow.
author | reimar |
---|---|
date | Sat, 16 Mar 2013 10:32:42 +0000 |
parents | 8fa2f43cb760 |
children |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
18 |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
19 #include <stdio.h> |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
20 #include <stdlib.h> |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
21 #include <string.h> |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
22 |
17012 | 23 #include "config.h" |
24 #include "mp_msg.h" | |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
25 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
26 #include "m_option.h" |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
27 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
28 #include "codec-cfg.h" |
22600
3c2b4a866c6a
Add explicit location for headers from the stream/ directory.
diego
parents:
22240
diff
changeset
|
29 #include "stream/stream.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
30 #include "libmpdemux/demuxer.h" |
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
31 #include "libmpdemux/stheader.h" |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
32 |
22600
3c2b4a866c6a
Add explicit location for headers from the stream/ directory.
diego
parents:
22240
diff
changeset
|
33 #include "stream/stream.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
34 #include "libmpdemux/muxer.h" |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
35 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
36 #include "img_format.h" |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
37 #include "mp_image.h" |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
38 #include "vf.h" |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
39 |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
40 #include "libavutil/intreadwrite.h" |
22240
43d03ab870b6
Use liblzo2 instead of liblzo1, it's not bigger but faster.
diego
parents:
22239
diff
changeset
|
41 #include <lzo/lzo1x.h> |
26304
5f526e8e3988
Rename RTJPEG files so that filenames consist of lowercase name only.
diego
parents:
22601
diff
changeset
|
42 #include "native/rtjpegn.h" |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
43 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
44 #define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long)) |
28875
8cfb1d6272fe
Allocate buffer for lzo compression correctly also for large frame sizes.
reimar
parents:
28874
diff
changeset
|
45 #define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3) |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
46 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
47 //===========================================================================// |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
48 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
49 struct vf_priv_s { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
50 int raw; // Do not use RTjpeg |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
51 int lzo; // Use lzo |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
52 unsigned int l,c,q; // Mjpeg param |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
53 muxer_stream_t* mux; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
54 uint8_t* buffer; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
55 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
56 int buf_size; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
57 int tbl_wrote; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
58 lzo_byte *zbuffer; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
59 long __LZO_MMODEL *zmem; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
60 }; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
61 #define mux_v (vf->priv->mux) |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
62 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
63 struct vf_priv_s nuv_priv_dflt = { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
64 0, // raw |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
65 1, // lzo |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
66 1,1, // l,c |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
67 255, // q |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
68 NULL, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
69 NULL, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
70 0,0, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
71 NULL,NULL |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
72 }; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
73 |
30955
4e59a7aebadb
Mark encoder-related m_option_t struct arrays as const.
diego
parents:
30642
diff
changeset
|
74 const m_option_t nuvopts_conf[] = { |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
75 {"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
76 {"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
77 {"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
78 {"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
79 {"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
80 {"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
81 {"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
82 {NULL, NULL, 0, 0, 0, 0, NULL} |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
83 }; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
84 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
85 //===========================================================================// |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
86 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
87 |
28874
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
88 #define COMPDATASIZE (128*4) |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
89 #define FRAMEHEADERSIZE 12 |
28874
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
90 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30421
diff
changeset
|
91 static int config(struct vf_instance *vf, |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
92 int width, int height, int d_width, int d_height, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
93 unsigned int flags, unsigned int outfmt){ |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
94 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
95 // We need a buffer wich can holda header and a whole YV12 picture |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
96 // or a RTJpeg table |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
97 vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE; |
28874
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
98 if(vf->priv->buf_size < COMPDATASIZE + FRAMEHEADERSIZE) |
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
99 vf->priv->buf_size = COMPDATASIZE + FRAMEHEADERSIZE; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
100 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
101 mux_v->bih->biWidth=width; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
102 mux_v->bih->biHeight=height; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
103 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); |
12061 | 104 mux_v->aspect = (float)d_width/d_height; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
105 vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size); |
28875
8cfb1d6272fe
Allocate buffer for lzo compression correctly also for large frame sizes.
reimar
parents:
28874
diff
changeset
|
106 if (vf->priv->lzo) |
8cfb1d6272fe
Allocate buffer for lzo compression correctly also for large frame sizes.
reimar
parents:
28874
diff
changeset
|
107 vf->priv->zbuffer = realloc(vf->priv->zbuffer, FRAMEHEADERSIZE + LZO_OUT_LEN(vf->priv->buf_size)); |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
108 vf->priv->tbl_wrote = 0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
109 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
110 return 1; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
111 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
112 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30421
diff
changeset
|
113 static int control(struct vf_instance *vf, int request, void* data){ |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
114 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
115 return CONTROL_UNKNOWN; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
116 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
117 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30421
diff
changeset
|
118 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14896
diff
changeset
|
119 if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
120 return 0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
121 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
122 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30421
diff
changeset
|
123 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
124 uint8_t *header = vf->priv->buffer; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
125 uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
126 uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE; |
28877
aed9da3c6d0f
Fix type of zlen, fixes crashes on 64 bit systems.
reimar
parents:
28876
diff
changeset
|
127 int len = 0, r; |
aed9da3c6d0f
Fix type of zlen, fixes crashes on 64 bit systems.
reimar
parents:
28876
diff
changeset
|
128 size_t zlen = 0; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
129 |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
130 memset(header, 0, FRAMEHEADERSIZE); // Reset the header |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
131 if(vf->priv->lzo) |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
132 memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
133 |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
134 // This has to be don here otherwise tv with sound doesn't work |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
135 if(!vf->priv->tbl_wrote) { |
28874
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
136 RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q); |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
137 RTjpeg_init_mcompress(); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
138 |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
139 header[0] = 'D'; // frametype: compressor data |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
140 header[1] = 'R'; // comptype: compressor data for RTjpeg |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
141 AV_WL32(header + 8, COMPDATASIZE); // packetlength |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
142 |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
143 mux_v->buffer=vf->priv->buffer; |
28874
3420ff87048e
nuv encoder 64 bit fix: avoid using long/sizeof(long)
reimar
parents:
26304
diff
changeset
|
144 muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE); |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
145 vf->priv->tbl_wrote = 1; |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
146 memset(header, 0, FRAMEHEADERSIZE); // Reset the header |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
147 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
148 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
149 // Raw picture |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
150 if(vf->priv->raw) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
151 len = mpi->width*mpi->height*3/2; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
152 // Try lzo ??? |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
153 if(vf->priv->lzo) { |
28876 | 154 r = lzo1x_1_compress(mpi->planes[0],len, |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
155 zdata,&zlen,vf->priv->zmem); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
156 if(r != LZO_E_OK) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
157 mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
158 zlen = 0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
159 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
160 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
161 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
162 if(zlen <= 0 || zlen > len) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
163 memcpy(data,mpi->planes[0],len); |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
164 header[1] = '0'; // comptype: uncompressed |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
165 } else { // Use lzo only if it's littler |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
166 header = vf->priv->zbuffer; |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
167 header[1] = '3'; //comptype: lzo |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
168 len = zlen; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
169 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
170 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
171 } else { // RTjpeg compression |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
172 len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l, |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
173 vf->priv->c); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
174 if(len <= 0) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
175 mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
176 return 0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
177 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
178 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
179 if(vf->priv->lzo) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
180 r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
181 if(r != LZO_E_OK) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
182 mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
183 zlen = 0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
184 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
185 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
186 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
187 if(zlen <= 0 || zlen > len) |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
188 header[1] = '1'; // comptype: RTjpeg |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
189 else { |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
190 header = vf->priv->zbuffer; |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
191 header[1] = '2'; // comptype: RTjpeg + LZO |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
192 len = zlen; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
193 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
194 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
195 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
196 |
28879
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
197 header[0] = 'V'; // frametype: video frame |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
198 AV_WL32(header + 8, len); // packetlength |
fad277267be5
Get rid of nuppelvideo.h and its ugly packed struct and instead write the
reimar
parents:
28877
diff
changeset
|
199 mux_v->buffer = header; |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17487
diff
changeset
|
200 muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts); |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
201 return 1; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
202 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
203 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30421
diff
changeset
|
204 static void uninit(struct vf_instance *vf) { |
9522 | 205 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32123
diff
changeset
|
206 free(vf->priv->buffer); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32123
diff
changeset
|
207 free(vf->priv->zbuffer); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32123
diff
changeset
|
208 free(vf->priv->zmem); |
9522 | 209 |
210 } | |
211 | |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
212 //===========================================================================// |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
213 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
214 static int vf_open(vf_instance_t *vf, char* args){ |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
215 vf->config=config; |
14878 | 216 vf->default_caps=VFCAP_CONSTANT; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
217 vf->control=control; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
218 vf->query_format=query_format; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
219 vf->put_image=put_image; |
9522 | 220 vf->uninit = uninit; |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
221 vf->priv=malloc(sizeof(struct vf_priv_s)); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
222 memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s)); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
223 vf->priv->mux=(muxer_stream_t*)args; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28879
diff
changeset
|
224 |
32123 | 225 mux_v->bih=calloc(1, sizeof(*mux_v->bih)); |
226 mux_v->bih->biSize=sizeof(*mux_v->bih); | |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
227 mux_v->bih->biWidth=0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
228 mux_v->bih->biHeight=0; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
229 mux_v->bih->biPlanes=1; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
230 mux_v->bih->biBitCount=12; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
231 mux_v->bih->biCompression = mmioFOURCC('N','U','V','1'); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
232 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
233 if(vf->priv->lzo) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
234 if(lzo_init() != LZO_E_OK) { |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
235 mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n"); |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
236 vf->priv->lzo = 0; |
28875
8cfb1d6272fe
Allocate buffer for lzo compression correctly also for large frame sizes.
reimar
parents:
28874
diff
changeset
|
237 } else |
18879 | 238 vf->priv->zmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
239 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
240 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
241 return 1; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
242 } |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
243 |
32033 | 244 const vf_info_t ve_info_nuv = { |
9520
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
245 "nuv encoder", |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
246 "nuv", |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
247 "Albeu", |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
248 "for internal use by mencoder", |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
249 vf_open |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
250 }; |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
251 |
2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
albeu
parents:
diff
changeset
|
252 //===========================================================================// |