[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: sageAudioSync.h |
---|
| 5 | * Author : Hyejung Hur, |
---|
| 6 | * Description : This file contains the class which provides the syncing |
---|
| 7 | * mechanism. |
---|
| 8 | * |
---|
| 9 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 10 | * University of Illinois at Chicago |
---|
| 11 | * |
---|
| 12 | * All rights reserved. |
---|
| 13 | * |
---|
| 14 | * Redistribution and use in source and binary forms, with or without |
---|
| 15 | * modification, are permitted provided that the following conditions are met: |
---|
| 16 | * |
---|
| 17 | * * Redistributions of source code must retain the above copyright |
---|
| 18 | * notice, this list of conditions and the following disclaimer. |
---|
| 19 | * * Redistributions in binary form must reproduce the above |
---|
| 20 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 21 | * in the documentation and/or other materials provided with the distribution. |
---|
| 22 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 23 | * the names of its contributors may be used to endorse or promote |
---|
| 24 | * products derived from this software without specific prior written permission. |
---|
| 25 | * |
---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 37 | * |
---|
| 38 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
| 39 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 40 | * |
---|
| 41 | *****************************************************************************/ |
---|
| 42 | |
---|
| 43 | #ifndef _SAGE_AUDIO_SYNC_H |
---|
| 44 | #define _SAGE_AUDIO_SYNC_H |
---|
| 45 | |
---|
| 46 | #include <vector> |
---|
| 47 | |
---|
| 48 | #include "sageBase.h" |
---|
| 49 | #include "streamProtocol.h" |
---|
| 50 | |
---|
| 51 | class sageSyncInfo { |
---|
| 52 | public: |
---|
| 53 | int m_sourceId; |
---|
| 54 | int m_bufferId; |
---|
| 55 | int m_keyframeNum; |
---|
| 56 | sageAudioSyncType m_syncType; |
---|
| 57 | bool m_updateFlag; |
---|
| 58 | int m_clientSockFd; |
---|
| 59 | int m_passNum; |
---|
| 60 | bool m_lockFlag; |
---|
| 61 | sageSyncInfo() : m_sourceId(-1), m_bufferId(-1), m_keyframeNum(30), m_syncType(SAGE_SYNC_NONE), |
---|
| 62 | m_updateFlag(false), m_clientSockFd(-1), m_passNum(0), m_lockFlag(false) {}; |
---|
| 63 | ~sageSyncInfo() {}; |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | class sageAudioSync { |
---|
| 67 | public: |
---|
| 68 | sageAudioSync(bool audioRecv=false); |
---|
| 69 | ~sageAudioSync(); |
---|
| 70 | |
---|
| 71 | public: |
---|
| 72 | int init(int port); |
---|
| 73 | int connect(char* ip); |
---|
| 74 | |
---|
| 75 | /** register to buffer information for contol |
---|
| 76 | */ |
---|
| 77 | void registerBuffer(sageAudioSyncType type, int sourceId, int bufferId, int keyframeNum); |
---|
| 78 | |
---|
| 79 | /** remove buffer from the contorl list. |
---|
| 80 | */ |
---|
| 81 | int removeBuffer(int bufferId); |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /** check current frame number is keyframe |
---|
| 85 | */ |
---|
| 86 | bool checkKeyFrame(int bufferId, int frameNum); |
---|
| 87 | |
---|
| 88 | /** check signal |
---|
| 89 | */ |
---|
| 90 | bool checkSignal(int bufferId); |
---|
| 91 | |
---|
| 92 | int sendSignal(int bufferId); |
---|
| 93 | |
---|
| 94 | int checkConnections(); |
---|
| 95 | |
---|
| 96 | protected: |
---|
| 97 | int initListener(int port); |
---|
| 98 | int initSender(char* ip, int port); |
---|
| 99 | |
---|
| 100 | bool recvSignal(int socketFd, char* msg, int bufferId); |
---|
| 101 | int closeAll(); |
---|
| 102 | |
---|
| 103 | int sendSignal(sageSyncInfo* info); |
---|
| 104 | |
---|
| 105 | void doKeyFrameAction(sageSyncInfo* info); |
---|
| 106 | |
---|
| 107 | protected: |
---|
| 108 | /** buffer list |
---|
| 109 | */ |
---|
| 110 | std::vector<sageSyncInfo*> m_syncInfoList; |
---|
| 111 | |
---|
| 112 | int m_serverSockFd; |
---|
| 113 | int m_clientSockFd; |
---|
| 114 | std::vector<int> m_clientSockList; |
---|
| 115 | |
---|
| 116 | sockaddr_in m_localAddr; |
---|
| 117 | sockaddr_in m_serverAddr; |
---|
| 118 | |
---|
| 119 | int m_recvPort; |
---|
| 120 | int m_sendPort; |
---|
| 121 | |
---|
| 122 | // for identify receivers. : if it's aStreamRcv, true |
---|
| 123 | bool m_audioReceiver; |
---|
| 124 | |
---|
| 125 | bool m_connectedDone; |
---|
| 126 | // timer.... |
---|
| 127 | |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | #endif |
---|