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
|
/*-
* 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.
*/
#ifndef vic_grabber_h
#define vic_grabber_h
#include "config.h"
#include "timer.h"
#include "media-timer.h"
#include "Tcl.h"
class Module;
class Transmitter;
/*
* Number of horizontal lines to pad at the top and bottom of the
* framer buffers that are handed to the Encoder encode method.
* Some encoders can operate more efficiently with this scratch
* space (i.e., the bvc coder).
*/
#define GRABBER_VPAD 1
class Grabber : public TclObject, public Timer, public MediaTimer {
protected:
Grabber();
public:
virtual ~Grabber();
virtual int command(int argc, const char*const* argv);
virtual void fps(int);
inline int fps() const { return (fps_); }
virtual void bps(int);
inline int bps() const { return (bps_); }
inline void fillrate(int v) { idle_high_ = v; }
double tick(int n);
virtual void start();
virtual void stop();
inline int status() const { return (status_); }
virtual int grab();
virtual void timeout();
int background() const;
protected:
/* hooks for conditional replenishment algorithm */
void suppress(const u_char* devbuf);
void saveblks(u_char* lum);
void crinit(int w, int h);
void age_blocks();
double advance();
void set_size_422(int w, int h);
void set_size_411(int w, int h);
void set_size_cif(int w, int h);
void allocref();
int vstart_;
int vstop_;
int hstart_;
int hstop_;
int threshold_ ; // when a block is changed ? (was constant 48)
u_int framesize_;
u_char* framebase_;
u_char* frame_;
u_char* crvec_;
u_char* ref_;/*XXX*/
int inw_;
int inh_;
int outw_;
int outh_;
int blkw_;
int blkh_;
Module* target_;
Transmitter* tx_;
int scan_;
int nblk_;
int rover_;
int idle_low_;
int idle_high_;
double frametime_; /* 1 / fps */
double frameclock_; /* logical clock for pumping out frames */
int fps_; /* desired frames per second */
int bps_; /* desired bits per second */
int running_; /* true when grabber active */
int status_; /* true if grabber okay */
double delta_; /* most recent inter-frame time */
/* brightness/contrast controls */
void contrast(double c);
u_int ymin_;
u_int ymax_;
double contrast_;
u_char ynorm_[256];
};
#define REPLENISH(devbuf, refbuf, ds, bpp, hstart, hstop, vstart, vstop) \
{ \
/* \
* First age the blocks from the previous frame. \
*/ \
age_blocks(); \
\
register int _ds = ds; \
register int _rs = outw_; \
const u_char* rb = &(refbuf)[scan_ * _rs]; \
const u_char* db = &(devbuf)[scan_ * _ds]; \
int w = blkw_; \
u_char* crv = crvec_; \
\
crv += (vstart) * w; \
for (int y = vstart; y < vstop; ++y) { \
const u_char* ndb = db; \
const u_char* nrb = rb; \
u_char* ncrv = crv; \
crv += hstart; \
for (int x = hstart; x < hstop; x++) { \
int left = 0; \
int right = 0; \
int top = 0; \
int bottom = 0; \
DIFFLINE(db, rb, left, top, right); \
db += _ds << 3; \
rb += _rs << 3; \
DIFFLINE(db, rb, left, bottom, right); \
db -= _ds << 3; \
rb -= _rs << 3; \
\
int center = 0; \
if (left >= threshold_ && x > 0) { \
crv[-1] = CR_MOTION|CR_SEND; \
center = 1; \
} \
if (right >= threshold_ && x < w - 1) { \
crv[1] = CR_MOTION|CR_SEND; \
center = 1; \
} \
if (bottom >= threshold_ && y < blkh_ - 1) { \
crv[w] = CR_MOTION|CR_SEND; \
center = 1; \
} \
if (top >= threshold_ && y > 0) { \
crv[-w] = CR_MOTION|CR_SEND; \
center = 1; \
} \
if (center) \
crv[0] = CR_MOTION|CR_SEND; \
\
db += 16 * (bpp); \
rb += 16; \
++crv; \
} \
db = ndb + (_ds << 4); \
rb = nrb + (_rs << 4); \
crv = ncrv + w; \
} \
}
#endif
|