[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: sageBlock.h |
---|
| 5 | * Author : Byungil Jeong |
---|
| 6 | * |
---|
| 7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 8 | * University of Illinois at Chicago |
---|
| 9 | * |
---|
| 10 | * All rights reserved. |
---|
| 11 | * |
---|
| 12 | * Redistribution and use in source and binary forms, with or without |
---|
| 13 | * modification, are permitted provided that the following conditions are met: |
---|
| 14 | * |
---|
| 15 | * * Redistributions of source code must retain the above copyright |
---|
| 16 | * notice, this list of conditions and the following disclaimer. |
---|
| 17 | * * Redistributions in binary form must reproduce the above |
---|
| 18 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 19 | * in the documentation and/or other materials provided with the distribution. |
---|
| 20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 21 | * the names of its contributors may be used to endorse or promote |
---|
| 22 | * products derived from this software without specific prior written permission. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 35 | * |
---|
| 36 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
| 37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 38 | * |
---|
| 39 | *****************************************************************************/ |
---|
| 40 | |
---|
| 41 | #ifndef _SAGE_BLOCK_H |
---|
| 42 | #define _SAGE_BLOCK_H |
---|
| 43 | |
---|
| 44 | #include "sageRect.h" |
---|
| 45 | |
---|
| 46 | #define BLOCK_HEADER_SIZE 128 |
---|
| 47 | |
---|
| 48 | #define SAGE_PIXEL_BLOCK 1 |
---|
| 49 | #define SAGE_UPDATE_BLOCK 2 |
---|
| 50 | |
---|
| 51 | //#define SAGE_BUFFER_BLOCK 2 |
---|
| 52 | //#define SAGE_IOVEC_FRAME 3 |
---|
| 53 | //#define SAGE_RLE_BLOCK 4 |
---|
| 54 | #define SAGE_AUDIO_BLOCK 5 |
---|
| 55 | |
---|
| 56 | #define SAGE_FRAME_BLOCK 100 |
---|
| 57 | #define SAGE_STOP_BLOCK 101 |
---|
| 58 | #define SAGE_TIME_BLOCK 102 |
---|
| 59 | #define SAGE_ACK_BLOCK 103 |
---|
| 60 | #define SAGE_SKIP_BLOCK 105 |
---|
| 61 | #define SAGE_CLEAR_BLOCK 106 |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * sageBLock |
---|
| 65 | */ |
---|
| 66 | class sageBlock { |
---|
| 67 | protected: |
---|
| 68 | char *buffer; |
---|
| 69 | int bufSize; |
---|
| 70 | int flag; // specify the function of block |
---|
| 71 | int rcnt; |
---|
| 72 | int blockID; |
---|
| 73 | |
---|
| 74 | public: |
---|
| 75 | sageBlock() : flag(SAGE_PIXEL_BLOCK), buffer(NULL), bufSize(0), rcnt(0) {} |
---|
| 76 | |
---|
| 77 | inline int getFlag() { return flag; } |
---|
| 78 | inline void setFlag(int f) { flag = f; } |
---|
| 79 | inline char *getBuffer() { return buffer; } |
---|
| 80 | inline int getBufSize() { return bufSize; } |
---|
| 81 | inline void setRefCnt(int cnt = 0) { rcnt = cnt; } |
---|
| 82 | inline int getRefCnt() { return rcnt; } |
---|
| 83 | inline int reference(int cnt = 1) { rcnt += cnt; return rcnt; } |
---|
| 84 | inline int dereference(int cnt = 1) { rcnt -= cnt; return rcnt; } |
---|
| 85 | inline void setID(int id) { blockID = id; } |
---|
| 86 | inline int getID() { return blockID; } |
---|
| 87 | |
---|
| 88 | virtual int updateBufferHeader() = 0; |
---|
| 89 | virtual bool updateBlockConfig() = 0; |
---|
| 90 | virtual int getFrameID() = 0; |
---|
| 91 | virtual ~sageBlock() {} |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * sagePixelData |
---|
| 96 | */ |
---|
| 97 | class sagePixelData : public sageRect, public sageBlock { |
---|
| 98 | protected: |
---|
| 99 | char *pixelData; // starting address of image buffer |
---|
| 100 | int frameID; // frame to which this block belongs |
---|
| 101 | sagePixFmt pixelType; // pixel format of block |
---|
| 102 | int bytesPerPixel; |
---|
| 103 | float compressX, compressY; |
---|
| 104 | |
---|
| 105 | int initBuffer(); |
---|
| 106 | int releaseBuffer(); |
---|
| 107 | int allocateBuffer(int size); |
---|
| 108 | |
---|
| 109 | public: |
---|
| 110 | sagePixelData() : pixelData(NULL), frameID(0), pixelType(PIXFMT_888), |
---|
| 111 | bytesPerPixel(3), compressX(1.0), compressY(1.0) {} |
---|
| 112 | |
---|
| 113 | virtual int getFrameID() { return frameID; } |
---|
| 114 | void operator=(sageRect &rect); |
---|
| 115 | inline void setFrameID(int id) { frameID = id; } |
---|
| 116 | inline sagePixFmt getPixelType() { return pixelType; } |
---|
| 117 | inline void setPixelType(sagePixFmt type) { pixelType = type; } |
---|
| 118 | inline int getBytesPerPixel() { return bytesPerPixel; } |
---|
| 119 | inline void setBytesPerPixel(int byte) { bytesPerPixel = byte; } |
---|
| 120 | inline char *getPixelBuffer() { return pixelData; } |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | class sageBlockGroup; |
---|
| 124 | |
---|
| 125 | /** |
---|
| 126 | * sagePixelBlock |
---|
| 127 | * |
---|
| 128 | * sageBlockGroup object has (grpSize/blockSize) of this sagePixelBlock object in its sageCircBufSingle |
---|
| 129 | */ |
---|
| 130 | class sagePixelBlock : public sagePixelData { |
---|
| 131 | protected: |
---|
| 132 | bool valid, dirty; |
---|
| 133 | sageBlockGroup *grp; |
---|
| 134 | int configID; |
---|
| 135 | int headerLen; |
---|
| 136 | |
---|
| 137 | public: |
---|
| 138 | sagePixelBlock() : valid(true), grp(NULL), dirty(false), headerLen(0) {} |
---|
| 139 | sagePixelBlock(int size); |
---|
| 140 | sagePixelBlock(sagePixelBlock& block); |
---|
| 141 | //sagePixelBlock(int w, int h, int bytes, float compX, float compY, |
---|
| 142 | // int frame, int confID); |
---|
| 143 | |
---|
| 144 | inline sageBlockGroup* getGroup() { return grp; } |
---|
| 145 | inline void setGroup(sageBlockGroup *parent) { grp = parent; } |
---|
| 146 | inline void setConfigID(int id) { configID = id; } |
---|
| 147 | inline int getConfigID() { return configID; } |
---|
| 148 | inline void clearHeader() { memset(buffer, 0, BLOCK_HEADER_SIZE); } |
---|
| 149 | inline void clearBuffer() { memset(buffer, 0, bufSize); } |
---|
| 150 | inline bool isDirty() { return dirty; } |
---|
| 151 | inline void setDirty() { dirty = true; } |
---|
| 152 | void clearPixelBlock(); |
---|
| 153 | int updateBufferHeader(); |
---|
| 154 | int updateHeader(int pid, int configID); |
---|
| 155 | bool updateBlockConfig(); |
---|
| 156 | |
---|
| 157 | inline int getHeaderLen(){ return headerLen; } |
---|
| 158 | inline bool isValid() { return valid; } |
---|
| 159 | inline void invalidate() { valid = false; } |
---|
| 160 | inline void validate() { valid = true; } |
---|
| 161 | |
---|
| 162 | //void recalcBufSize(); |
---|
| 163 | |
---|
| 164 | virtual ~sagePixelBlock(); |
---|
| 165 | }; |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * sageAudioBlock |
---|
| 169 | */ |
---|
| 170 | class sageAudioBlock : public sageBlock { |
---|
| 171 | protected: |
---|
| 172 | int frameID; // audio frame to which this block belongs |
---|
| 173 | int gframeID; // video frame to which this block belong |
---|
| 174 | |
---|
| 175 | sageSampleFmt sampleFmt; // sample format of block |
---|
| 176 | int bytesPerSample; |
---|
| 177 | int channels; |
---|
| 178 | int framePerBuffer; |
---|
| 179 | long sampleRate; |
---|
| 180 | char* audioData; |
---|
| 181 | |
---|
| 182 | char *extraInfo; |
---|
| 183 | int tileID; |
---|
| 184 | int nodeID; |
---|
| 185 | |
---|
| 186 | int releaseBuffer(); |
---|
| 187 | int allocateBuffer(int size); |
---|
| 188 | |
---|
| 189 | public: |
---|
| 190 | sageAudioBlock(); |
---|
| 191 | sageAudioBlock(int frame, sageSampleFmt type, int byte, int rate, int chan, int framesperbuffer); |
---|
| 192 | virtual ~sageAudioBlock(); |
---|
| 193 | |
---|
| 194 | int initBuffer(); |
---|
| 195 | int initBuffer(int size); |
---|
| 196 | |
---|
| 197 | public: |
---|
| 198 | int updateBufferHeader(); |
---|
| 199 | virtual bool updateBlockConfig(); |
---|
| 200 | virtual int getTileID() { return tileID; } |
---|
| 201 | |
---|
| 202 | inline void setTileID(int id) { tileID = id; } |
---|
| 203 | inline int getNodeID() { return nodeID; } |
---|
| 204 | inline void setNodeID(int id) { nodeID = id; } |
---|
| 205 | |
---|
| 206 | virtual int getFrameID() { return frameID; } |
---|
| 207 | void operator=(sageAudioBlock &rect); |
---|
| 208 | inline void setFrameID(int id) { frameID = id; } |
---|
| 209 | |
---|
| 210 | virtual int getgFrameID() { return gframeID; } |
---|
| 211 | inline void setgFrameID(int id) { gframeID = id; } |
---|
| 212 | |
---|
| 213 | inline sageSampleFmt getSampleFormat() { return sampleFmt; } |
---|
| 214 | inline void setSampleFormat(sageSampleFmt type) { sampleFmt = type; } |
---|
| 215 | |
---|
| 216 | inline int getBytesPerSample() { return bytesPerSample; } |
---|
| 217 | inline void setBytesPerSample(int byte) { bytesPerSample = byte; } |
---|
| 218 | |
---|
| 219 | inline int getChannel() { return channels; } |
---|
| 220 | inline void setChannel(int num) { channels = num; } |
---|
| 221 | |
---|
| 222 | inline int getFramePerBuffer() { return framePerBuffer; } |
---|
| 223 | inline void setFramePerBuffer(int num) { framePerBuffer = num; } |
---|
| 224 | |
---|
| 225 | inline int getSampleRate() { return sampleRate; } |
---|
| 226 | inline void setSampleRate(int rate) { sampleRate = rate; } |
---|
| 227 | |
---|
| 228 | char *getExtraInfo() { return extraInfo; } |
---|
| 229 | |
---|
| 230 | inline char *getAudioBuffer() { return audioData; } |
---|
| 231 | }; |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | /* |
---|
| 235 | class sageControlBlock : public sageBlock { |
---|
| 236 | protected: |
---|
| 237 | int frameID; |
---|
| 238 | char ctrlInfo[TOKEN_LEN]; |
---|
| 239 | |
---|
| 240 | public: |
---|
| 241 | sageControlBlock(int f, int frame, int size = 0); |
---|
| 242 | virtual ~sageControlBlock(); |
---|
| 243 | |
---|
| 244 | int updateBufferHeader(char *info); |
---|
| 245 | virtual int updateBlockConfig(); |
---|
| 246 | virtual int getFrameID() { return frameID; } |
---|
| 247 | char *getControlInfo() { return ctrlInfo; } |
---|
| 248 | }; |
---|
| 249 | */ |
---|
| 250 | |
---|
| 251 | #endif |
---|