JackEngineControl.h

00001 /*
00002 Copyright (C) 2003 Paul Davis
00003 Copyright (C) 2004-2008 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifndef __JackEngineControl__
00022 #define __JackEngineControl__
00023 
00024 #include "JackShmMem.h"
00025 #include "JackFrameTimer.h"
00026 #include "JackTransportEngine.h"
00027 #include "types.h"
00028 
00029 namespace Jack
00030 {
00031 
00032 class JackClientInterface;
00033 class JackGraphManager;
00034 
00035 #define TIME_POINTS 1000
00036 #define JACK_ENGINE_ROLLING_COUNT 32
00037 #define JACK_ENGINE_ROLLING_INTERVAL 1024
00038 
00043 struct JackTimingMeasureClient
00044 {
00045         int fRefNum;
00046     jack_time_t fSignaledAt;
00047     jack_time_t fAwakeAt;
00048     jack_time_t fFinishedAt;
00049     jack_client_state_t fStatus;
00050 };
00051 
00056 struct JackTimingMeasure
00057 {
00058         unsigned int fAudioCycle;
00059     jack_time_t fEngineTime;
00060     JackTimingMeasureClient fClientTable[CLIENT_NUM];
00061 };
00062 
00067 struct JackEngineControl : public JackShmMem
00068 {
00069         // Shared state
00070     jack_nframes_t fBufferSize;
00071     jack_nframes_t fSampleRate;
00072         bool fSyncMode;
00073         bool fTemporary;
00074     jack_time_t fPeriodUsecs;
00075     jack_time_t fTimeOutUsecs;
00076         bool fTimeOut;
00077         bool fRealTime;
00078         int fPriority;
00079         char fServerName[64];
00080     JackTransportEngine fTransport;
00081     bool fVerbose;
00082         
00083         // Timing
00084         JackTimingMeasure fMeasure[TIME_POINTS];
00085         jack_time_t fLastTime;
00086         jack_time_t fCurTime;
00087         jack_time_t fProcessTime;
00088         jack_time_t fLastProcessTime;
00089         jack_time_t fSpareUsecs;
00090         jack_time_t fMaxUsecs;
00091         unsigned int fAudioCycle;
00092         jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
00093         int     fRollingClientUsecsCnt;
00094         int     fRollingClientUsecsIndex;
00095         int     fRollingInterval;
00096         float fCPULoad;
00097         
00098         // Fos OSX thread
00099     UInt64 fPeriod;
00100     UInt64 fComputation;
00101     UInt64 fConstraint;
00102         
00103         // Timer
00104         JackFrameTimer fFrameTimer;
00105 
00106         JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
00107         {
00108                 fSyncMode = sync;
00109                 fTemporary = temporary;
00110                 fTimeOut = (timeout > 0);
00111                 fTimeOutUsecs = timeout * 1000;
00112                 fRealTime = rt;
00113                 fPriority = priority;
00114                 fVerbose = verbose;
00115                 fLastTime = 0;
00116                 fCurTime = 0;
00117                 fProcessTime = 0;
00118                 fLastProcessTime = 0;
00119                 fSpareUsecs = 0;
00120                 fMaxUsecs = 0;
00121                 fAudioCycle = 0;
00122                 ClearTimeMeasures();
00123                 ResetRollingUsecs();
00124                 snprintf(fServerName, sizeof(fServerName), server_name);
00125         }
00126         ~JackEngineControl()
00127         {}
00128         
00129         // Cycle
00130         void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
00131         void CycleEnd(JackClientInterface** table);
00132         
00133         // Timer
00134         void InitFrameTime();
00135         void ResetFrameTime(jack_time_t callback_usecs);
00136         void ReadFrameTime(JackTimer* timer);
00137 
00138         // Private
00139         void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager);
00140         void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
00141         void ClearTimeMeasures();
00142         void ResetRollingUsecs();
00143         
00144 };
00145 
00146 } // end of namespace
00147 
00148 #endif

Generated on Thu Feb 14 11:16:01 2008 for Jackdmp by  doxygen 1.5.1