1 |
/* $Id$ */ |
---|
2 |
|
---|
3 |
/* |
---|
4 |
* FreeBob Streaming API |
---|
5 |
* FreeBob = Firewire (pro-)audio for linux |
---|
6 |
* |
---|
7 |
* http://freebob.sf.net |
---|
8 |
* |
---|
9 |
* Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net> |
---|
10 |
* |
---|
11 |
* This program is free software {} you can redistribute it and/or modify |
---|
12 |
* it under the terms of the GNU General Public License as published by |
---|
13 |
* the Free Software Foundation {} either version 2 of the License, or |
---|
14 |
* (at your option) any later version. |
---|
15 |
* |
---|
16 |
* This program is distributed in the hope that it will be useful, |
---|
17 |
* but WITHOUT ANY WARRANTY {} without even the implied warranty of |
---|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
* GNU General Public License for more details. |
---|
20 |
* |
---|
21 |
* You should have received a copy of the GNU General Public License |
---|
22 |
* along with this program {} if not, write to the Free Software |
---|
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 |
* |
---|
25 |
* |
---|
26 |
* |
---|
27 |
*/ |
---|
28 |
#ifndef __FREEBOB_TIMESOURCE__ |
---|
29 |
#define __FREEBOB_TIMESOURCE__ |
---|
30 |
|
---|
31 |
#include "../debugmodule/debugmodule.h" |
---|
32 |
|
---|
33 |
#include <vector> |
---|
34 |
|
---|
35 |
typedef uint64_t freebob_microsecs_t; |
---|
36 |
|
---|
37 |
namespace Util { |
---|
38 |
|
---|
39 |
class TimeSource; |
---|
40 |
typedef std::vector<TimeSource *> TimeSourceVector; |
---|
41 |
typedef std::vector<TimeSource *>::iterator TimeSourceVectorIterator; |
---|
42 |
|
---|
43 |
/*! |
---|
44 |
\brief The base class for all TimeSource's. |
---|
45 |
|
---|
46 |
Any object that can act as a source of timing |
---|
47 |
information should subclass this class and implement |
---|
48 |
its virtual functions. |
---|
49 |
|
---|
50 |
A TimeSource can be slaved to another TimeSource, allowing |
---|
51 |
the mapping of the master's time to the slave's time. |
---|
52 |
*/ |
---|
53 |
class TimeSource { |
---|
54 |
|
---|
55 |
public: |
---|
56 |
|
---|
57 |
TimeSource(); |
---|
58 |
virtual ~TimeSource(); |
---|
59 |
|
---|
60 |
virtual freebob_microsecs_t getCurrentTime()=0; |
---|
61 |
virtual freebob_microsecs_t getCurrentTimeAsUsecs()=0; |
---|
62 |
virtual freebob_microsecs_t unWrapTime(freebob_microsecs_t t)=0; |
---|
63 |
virtual freebob_microsecs_t wrapTime(freebob_microsecs_t t)=0; |
---|
64 |
|
---|
65 |
freebob_microsecs_t mapMasterTime(freebob_microsecs_t t); |
---|
66 |
|
---|
67 |
bool updateTimeSource(); |
---|
68 |
|
---|
69 |
bool registerSlave(TimeSource *ts); |
---|
70 |
bool unregisterSlave(TimeSource *ts); |
---|
71 |
|
---|
72 |
virtual void setVerboseLevel(int l); |
---|
73 |
|
---|
74 |
virtual void printTimeSourceInfo(); |
---|
75 |
|
---|
76 |
protected: |
---|
77 |
|
---|
78 |
private: |
---|
79 |
bool setMaster(TimeSource *ts); |
---|
80 |
void clearMaster(); |
---|
81 |
|
---|
82 |
void initSlaveTimeSource(); |
---|
83 |
|
---|
84 |
TimeSource * m_Master; |
---|
85 |
TimeSourceVector m_Slaves; |
---|
86 |
|
---|
87 |
freebob_microsecs_t m_last_master_time; |
---|
88 |
freebob_microsecs_t m_last_time; |
---|
89 |
|
---|
90 |
double m_slave_rate; |
---|
91 |
int64_t m_slave_offset; |
---|
92 |
double m_last_err; |
---|
93 |
|
---|
94 |
DECLARE_DEBUG_MODULE; |
---|
95 |
|
---|
96 |
}; |
---|
97 |
|
---|
98 |
} // end of namespace Util |
---|
99 |
|
---|
100 |
#endif /* __FREEBOB_TIMESOURCE__ */ |
---|
101 |
|
---|
102 |
|
---|