1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
/*
* Copyright (c) 1993-1994 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and the Network Research Group at
* Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* This code was originally derived from a cellb reference decoder from
* Sun Microsystems with the following copyright:
*
* Copyright (c) Sun Microsystems, Inc. 1992, 1993. All rights reserved.
*
* License is granted to copy, to use, and to make and to use derivative
* works for research and evaluation purposes, provided that Sun Microsystems is
* acknowledged in all documentation pertaining to any such copy or derivative
* work. Sun Microsystems grants no other licenses expressed or implied. The
* Sun Microsystems trade name should not be used in any advertising without
* its written permission.
*
* SUN MICROSYSTEMS MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF
* THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is provided "as is"
* without express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this software.
*/
static const char rcsid[] =
"@(#) $Header: /cs/research/mice/starship/src/local/CVS_repository/vic/decoder-cellb.cc,v 1.1.1.1 1998/02/18 18:03:23 ucacsva Exp $ (LBL)";
#include <stdio.h>
#include <string.h>
#include "inet.h"
#include "rtp.h"
#include "decoder.h"
#include "bsd-endian.h"
class CellbDecoder : public PlaneDecoder {
public:
CellbDecoder();
protected:
virtual void recv(const struct rtphdr*, const u_char* data, int len);
void decode(const u_char*, int cc, int x, int y, int w, int h);
};
static class CellbDecoderMatcher : public Matcher {
public:
CellbDecoderMatcher() : Matcher("decoder") {}
TclObject* match(const char* id) {
if (strcasecmp(id, "cellb") == 0)
return (new CellbDecoder());
else
return (0);
}
} dm_cellb;
#define STAT_BAD_GEOM 0
#define STAT_BAD_COORD 1
CellbDecoder::CellbDecoder() : PlaneDecoder(sizeof(cellbhdr))
{
stat_[STAT_BAD_GEOM].name = "Cellb-Bad-Geom";
stat_[STAT_BAD_COORD].name = "Cellb-Bad-Coord";
nstat_ = 2;
color_ = 1;
inw_ = 0;
inh_ = 0;
}
/*
* Inverse VQ tables.
*/
extern "C" u_short cellb_yytable[256], cellb_uvtable[256];
void CellbDecoder::decode(const u_char* p, int cc, int cellx, int celly,
int width, int height)
{
/* Convert width to count in cells */
width >>= 2;
height >>= 2;
while (cc >= 4) {
int mask = *p;
if (mask & 0x80) {
cellx += mask - 127;
while (cellx >= width) {
cellx -= width;
++celly;
}
++p;
--cc;
} else {
mask <<= 8;
mask |= p[1];
/*XXX yytable is backward so flip mask bits*/
mask ^= 0xffff;
int yy = cellb_yytable[p[3]];
if (celly >= height) {
/*XXX*/
fprintf(stderr, "vic: bad cellb packet\n");
return;
}
int k = 4 * (celly * 4 * width + cellx);
u_int* yp = (u_int*)&frm_[k];
#if BYTE_ORDER == LITTLE_ENDIAN
#define MSET(y, yy, mask, pos) \
{ \
int t = (((mask) >> (pos)) & 1) << 3; \
y >>= 8; \
y |= ((yy) >> t) << 24; \
}
#else
#define MSET(y, yy, mask, pos) \
{ \
int t = (((mask) >> (pos)) & 1) << 3; \
y <<= 8; \
y |= ((yy) >> t) & 0xff; \
}
#endif
/* First bit of mask is clear. */
#if BYTE_ORDER == LITTLE_ENDIAN
u_int y = (yy >> 8) << 24;
#else
u_int y = yy >> 8;
#endif
MSET(y, yy, mask, 14);
MSET(y, yy, mask, 13);
MSET(y, yy, mask, 12);
*yp = y;
yp += width;
MSET(y, yy, mask, 11);
MSET(y, yy, mask, 10);
MSET(y, yy, mask, 9);
MSET(y, yy, mask, 8);
*yp = y;
yp += width;
MSET(y, yy, mask, 7);
MSET(y, yy, mask, 6);
MSET(y, yy, mask, 5);
MSET(y, yy, mask, 4);
*yp = y;
yp += width;
MSET(y, yy, mask, 3);
MSET(y, yy, mask, 2);
MSET(y, yy, mask, 1);
MSET(y, yy, mask, 0);
*yp = y;
#undef MSET
int s = (width << 2) * (height << 2);/*XXX*/
u_char* up = frm_ + s + k / 2;
u_char* vp = up + (s >> 1);
k = p[2];
int uv = cellb_uvtable[k];
int t = uv >> 8;
t |= t << 8;
*(u_short*)up = t; up += width << 1;
*(u_short*)up = t; up += width << 1;
*(u_short*)up = t; up += width << 1;
*(u_short*)up = t;
t = uv & 0xff;
t |= t << 8;
*(u_short*)vp = t; vp += width << 1;
*(u_short*)vp = t; vp += width << 1;
*(u_short*)vp = t; vp += width << 1;
*(u_short*)vp = t;
/* mark block as changed */
/*XXX should maintain offset using loop */
int o = (cellx >> 1) + (celly >> 1) * (width >> 1);
rvts_[o] = now_;
if (++cellx >= width) {
cellx -= width;
++celly;
}
p += 4;
cc -= 4;
}
ndblk_++;
}
}
void CellbDecoder::recv(const rtphdr* rh, const u_char* bp, int cc)
{
cellbhdr* ph = (cellbhdr*)(rh + 1);
int w = ntohs(ph->width) & 0x7fff;
int h = ntohs(ph->height);
if (w != inw_ || h != inh_) {
if ((unsigned)w > 1000 || (unsigned)h > 1000) {
/*XXX*/
w = 320;
h = 240;
count(STAT_BAD_GEOM);
}
resize(w, h);
}
decode(bp, cc, ntohs(ph->x), ntohs(ph->y), w, h);
if (ntohs(rh->rh_flags) & RTP_M) {
render_frame(frm_);
resetndblk();
}
}
|