~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/crdef.cc

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * crdef.cc --
  3  *
  4  *      Conditional Replenisher object source code
  5  *
  6  * Copyright (c) 1997-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  */
 33 
 34 #ifndef lint
 35 static const char rcsid[] =
 36     "@(#) $Header: /usr/mash/src/repository/mash/mash-1/codec/crdef.cc,v 1.11 2002/02/03 03:13:32 lim Exp $";
 37 #endif
 38 
 39 #include "crdef.h"
 40 
 41 ConditionalReplenisher::ConditionalReplenisher()
 42         :frmno_(0), crvec_(0), rover_(0)
 43 {
 44         /*FIXME*/
 45         idle_low_ = 2;
 46         idle_high_ = 2;
 47 }
 48 
 49 ConditionalReplenisher::~ConditionalReplenisher()
 50 {
 51         delete[] crvec_;
 52 }
 53 
 54 #define NLEVEL 4
 55 int levelMap[] = { 0, 2, 1, 2}; /*FIXME needs to be parameterizable from tcl*/
 56 
 57 int ConditionalReplenisher::get_level()
 58 {
 59         /*FIXME this needs to be parameterizable from tcl*/
 60         return (frmno_ & (NLEVEL - 1));
 61 }
 62 
 63 void ConditionalReplenisher::crinit(int w, int h)
 64 {
 65         blkw_ = w >> 4;
 66         blkh_ = h >> 4;
 67         scan_ = 0;
 68         nblk_ = blkw_ * blkh_;
 69         delete[] crvec_;
 70         crvec_ = new u_char[nblk_];
 71         send_all();
 72 }
 73 
 74 
 75 void ConditionalReplenisher::mark_all_send()
 76 {
 77         if (crvec_ != 0) {
 78                 for (int i = 0; i < nblk_; ++i)
 79                         crvec_[i] = CR_SEND;
 80         }
 81 }
 82 
 83 
 84 void ConditionalReplenisher::send_all()
 85 {
 86         if (crvec_ != 0) {
 87                 for (int i = 0; i < nblk_; ++i)
 88                         crvec_[i] = CR_MOTION_BIT|CR_LQ;
 89         }
 90 }
 91 
 92 int ConditionalReplenisher::age_blocks()
 93 {
 94         ++frmno_;
 95         int level = get_level();
 96         int hlev = levelMap[level];
 97 
 98         for (int i = 0; i < nblk_; ++i) {
 99                 int s = crvec_[i] & 0x3f;
100                 /*
101                  * Age this block.
102                  * Once we hit the age threshold, we
103                  * set CR_SEND as a hint to send a
104                  * higher-quality version of the block.
105                  * After this the block will stop aging,
106                  * until there is motion.  In the meantime,
107                  * we might send it as background fill
108                  * using the highest quality.
109                  */
110                 if (s & CR_AGE_BIT) {
111                         int age = s & 0x1f;
112                         age += 1;
113                         if (age >= CR_AGETHRESH)
114                                 s = CR_MQ;
115                         else
116                                 s = CR_AGE_BIT | age;
117                 } else if (s & CR_MOTION_BIT) {
118                         int slev = s & 0xf;
119                         if (hlev == 0) {
120                                 s = CR_AGE_BIT;
121                                 if (slev > 0)
122                                         s |= CR_LQ;
123                         } else if (hlev < slev)
124                                 s = CR_LQ|CR_MOTION_BIT | hlev;
125                 }
126                 crvec_[i] = s;
127         }
128         /*
129          * Bump the CR scan pointer.  This variable controls which
130          * scan line of a block we use to make the replenishment
131          * decision.  We skip 3 lines at a time to quickly precess
132          * over the block.  Since 3 and 8 are coprime, we will
133          * sweep out every line.
134          */
135         scan_ = (scan_ + 3) & 7;
136 
137         /*
138          * Now go through and look for some idle blocks to send
139          * as background fill.  But only do background fill
140          * on the base layer.
141          */
142         if (hlev != 0)
143                 return (hlev);
144 
145         int blkno = rover_;
146 #ifdef notdef
147         int n = (delta_ * 2. < frametime_)? idle_high_ : idle_low_;
148 #endif
149         /* FIXME */
150         int n = 2;
151         while (n > 0) {
152                 int s = crvec_[blkno];
153                 /*
154                  * If this block isn't being sent because of
155                  * motion, send it as a high-quality background
156                  * block.  We used to check also that the block
157                  * was not aging, but removed this constraint since
158                  * at low bandwidth it takes too long to cycle
159                  * through the whole image...
160                  */
161                 if ((s & CR_MOTION_BIT) == 0) {
162                         crvec_[blkno] = CR_HQ;
163                         --n;
164                 }
165                 if (++blkno >= nblk_) {
166                         blkno = 0;
167                         /* one way to guarantee loop termination */
168                         break;
169                 }
170         }
171         rover_ = blkno;
172 
173         return (hlev);
174 }
175 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.