[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: sail.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 SAIL_H_ |
---|
| 42 | #define SAIL_H_ |
---|
| 43 | |
---|
| 44 | #include "sageConfig.h" |
---|
| 45 | |
---|
| 46 | #ifndef GL_ABGR_EXT |
---|
| 47 | # define GL_ABGR_EXT 0x8000 |
---|
| 48 | #endif |
---|
| 49 | #ifndef GL_BGR |
---|
| 50 | # define GL_BGR 0x80E0 |
---|
| 51 | #endif |
---|
| 52 | #ifndef GL_BGRA |
---|
| 53 | # define GL_BGRA 0x80E1 |
---|
| 54 | #endif |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | #ifndef GL_UNSIGNED_SHORT_5_6_5 |
---|
| 58 | # define GL_UNSIGNED_SHORT_5_6_5 0x8363 |
---|
| 59 | #endif |
---|
| 60 | |
---|
| 61 | // awf: more (similar) defines for win32... |
---|
| 62 | #ifndef GL_UNSIGNED_SHORT_5_5_5_1 |
---|
| 63 | # define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 |
---|
| 64 | #endif |
---|
| 65 | #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV |
---|
| 66 | # define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8066 |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | #include "sagePixelType.h" |
---|
| 70 | |
---|
| 71 | class envInterface; |
---|
| 72 | class sageStreamer; |
---|
| 73 | class streamProtocol; |
---|
| 74 | class sageSyncServer; |
---|
| 75 | class sageSyncClient; |
---|
| 76 | class sageDoubleBuf; |
---|
| 77 | class syncGroup; |
---|
| 78 | #ifdef SAGE_AUDIO |
---|
| 79 | class sageAudioCircBuf; |
---|
| 80 | class sageAudioModule; |
---|
| 81 | class sageAppAudio; |
---|
| 82 | #endif |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * \brief SAGE applicatoins communicate with the FSManager and stream pixels to SAGE receivers through SAIL |
---|
| 86 | */ |
---|
| 87 | class sail { |
---|
| 88 | private: |
---|
| 89 | envInterface *envIntf; |
---|
| 90 | sageStreamer *pixelStreamer; /**< pixel streamer */ |
---|
| 91 | sageStreamer *audioStreamer; /**< audio streamer */ |
---|
| 92 | sailConfig config; |
---|
| 93 | sagePixelType pInfo; |
---|
| 94 | |
---|
| 95 | bool sailOn; |
---|
| 96 | bool audioOn; // audio on/off flag |
---|
| 97 | |
---|
| 98 | int bufSize; |
---|
| 99 | int winID; |
---|
| 100 | |
---|
| 101 | std::deque<sageMessage> appMsgQueue; |
---|
| 102 | |
---|
| 103 | int bufID; |
---|
| 104 | sageDoubleBuf *doubleBuf; |
---|
| 105 | |
---|
| 106 | #ifdef SAGE_AUDIO |
---|
| 107 | sageAudioCircBuf* audioBuffer; |
---|
| 108 | sageAudioModule* audioModule; |
---|
| 109 | sageAppAudio* audioAppDataHander; |
---|
| 110 | #endif |
---|
| 111 | |
---|
| 112 | int waitNodes; |
---|
| 113 | int connectedNode; |
---|
| 114 | bool connectionDone; |
---|
| 115 | |
---|
| 116 | int reconfigStep; |
---|
| 117 | |
---|
| 118 | //double reportTime; |
---|
| 119 | sageTimer perfTimer; |
---|
| 120 | double frameRate; |
---|
| 121 | double bandWidth; |
---|
| 122 | double totalBand; |
---|
| 123 | int perfWait; |
---|
| 124 | int reportRate; |
---|
| 125 | double frameInterval; |
---|
| 126 | |
---|
| 127 | pthread_mutex_t *msgMutex; |
---|
| 128 | pthread_cond_t *notEmpty; |
---|
| 129 | sageSyncServer *syncServerObj; /**< sageSyncServer object for master node */ |
---|
| 130 | syncGroup *sGroup; |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * invoked by init() member function |
---|
| 134 | * |
---|
| 135 | * keeps calling readMessage(), sendPerformanceInfo(), and |
---|
| 136 | * if config.master then also calling envIntf->checkClient(), |
---|
| 137 | * and for each client, calls readClientMsg() followed by parseMessage() |
---|
| 138 | * |
---|
| 139 | */ |
---|
| 140 | |
---|
| 141 | pthread_t msgThreadID; |
---|
| 142 | static void* msgThread(void *args); |
---|
| 143 | |
---|
| 144 | int checkSyncServer(); |
---|
| 145 | int generateSageBlocks(); |
---|
| 146 | |
---|
| 147 | public: |
---|
| 148 | sail(); |
---|
| 149 | ~sail(); |
---|
| 150 | |
---|
| 151 | /** |
---|
| 152 | * accepts sailConfig object and sets necessary parameters |
---|
| 153 | * ready audioBuffer if SAGE_AUDIO |
---|
| 154 | * creates pthreads mutex and condition variable. |
---|
| 155 | * if it runs on the master node then creates sageSyncServer object. |
---|
| 156 | * followed by sync related code |
---|
| 157 | * followed by creation of sageBlockStreamer object |
---|
| 158 | * followed by SAGE_AUDIO part |
---|
| 159 | * finally pthread_create 'msgThread' |
---|
| 160 | * |
---|
| 161 | * @return 0 on success, -1 otherwise |
---|
| 162 | */ |
---|
| 163 | int init(sailConfig &conf); |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | * getting message through envInf |
---|
| 167 | */ |
---|
| 168 | int readMessage(); |
---|
| 169 | int sendMessage(sageMessage &msg); |
---|
| 170 | int sendMessage(int code); |
---|
| 171 | int sendMessage(int code, int data); |
---|
| 172 | int sendMessage(int code, char *data); |
---|
| 173 | int parseMessage(sageMessage &msg); |
---|
| 174 | int swapBuffer(int mode = SAGE_BLOCKING); |
---|
| 175 | #ifdef SAGE_AUDIO |
---|
| 176 | /** |
---|
| 177 | * calls audioAppDataHander->swapBuffer(size, buf); |
---|
| 178 | */ |
---|
| 179 | int pushAudioData(int size, void *buf); |
---|
| 180 | #endif |
---|
| 181 | |
---|
| 182 | void* getBuffer(); |
---|
| 183 | int initPixelBlocks(); |
---|
| 184 | int streamPixelBlocks(int blockFrame); |
---|
| 185 | int streamFBO(); |
---|
| 186 | |
---|
| 187 | //int resizeBuffer(int x, int y, int depth); |
---|
| 188 | int getRowOrder() { return config.rowOrd; } |
---|
| 189 | int getBufSize() { return bufSize; } |
---|
| 190 | int checkMsg(sageMessage &msg, bool blocking); |
---|
| 191 | int requestNewFrame(); |
---|
| 192 | int shutdown(); |
---|
| 193 | int sendPerformanceInfo(); |
---|
| 194 | |
---|
| 195 | int initFrameBufferObject(); // initailize FBO of SAIL |
---|
| 196 | int bindFrameBufferObject(); // bind the FBO of SAIL |
---|
| 197 | int releaseFrameBufferObject(); // back to regular frame buffer |
---|
| 198 | int transferFBO(); // transfer pixels written into FBO to SAGE |
---|
| 199 | |
---|
| 200 | inline bool isSailOn() { return sailOn; } |
---|
| 201 | |
---|
| 202 | friend class envInterface; |
---|
| 203 | }; |
---|
| 204 | |
---|
| 205 | #endif |
---|