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,2007 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_TIMESTAMPEDBUFFER__ |
---|
29 |
#define __FREEBOB_TIMESTAMPEDBUFFER__ |
---|
30 |
|
---|
31 |
#include "../debugmodule/debugmodule.h" |
---|
32 |
#include "libutil/ringbuffer.h" |
---|
33 |
|
---|
34 |
namespace FreebobUtil { |
---|
35 |
|
---|
36 |
class TimestampedBufferClient; |
---|
37 |
|
---|
38 |
class TimestampedBuffer { |
---|
39 |
|
---|
40 |
public: |
---|
41 |
|
---|
42 |
TimestampedBuffer(TimestampedBufferClient *); |
---|
43 |
virtual ~TimestampedBuffer(); |
---|
44 |
|
---|
45 |
bool writeFrames(unsigned int nbframes, char *data); |
---|
46 |
bool readFrames(unsigned int nbframes, char *data); |
---|
47 |
|
---|
48 |
bool blockProcessWriteFrames(unsigned int nbframes, int64_t ts); |
---|
49 |
bool blockProcessReadFrames(unsigned int nbframes); |
---|
50 |
|
---|
51 |
bool init(); |
---|
52 |
bool prepare(); |
---|
53 |
bool reset(); |
---|
54 |
|
---|
55 |
bool setEventSize(unsigned int s); |
---|
56 |
bool setEventsPerFrame(unsigned int s); |
---|
57 |
bool setBufferSize(unsigned int s); |
---|
58 |
|
---|
59 |
unsigned int getBufferFill(); |
---|
60 |
|
---|
61 |
// timestamp stuff |
---|
62 |
int getFrameCounter() {return m_framecounter;}; |
---|
63 |
|
---|
64 |
void decrementFrameCounter(int nbframes); |
---|
65 |
void incrementFrameCounter(int nbframes, uint64_t new_timestamp); |
---|
66 |
void resetFrameCounter(); |
---|
67 |
|
---|
68 |
void getBufferHeadTimestamp(uint64_t *ts, uint64_t *fc); |
---|
69 |
void getBufferTailTimestamp(uint64_t *ts, uint64_t *fc); |
---|
70 |
|
---|
71 |
void setBufferTailTimestamp(uint64_t new_timestamp); |
---|
72 |
|
---|
73 |
// dll stuff |
---|
74 |
void setNominalRate(double r) {m_nominal_rate=r;}; |
---|
75 |
double getRate() {return m_dll_e2;}; |
---|
76 |
|
---|
77 |
void setUpdatePeriod(unsigned int t) {m_update_period=t;}; |
---|
78 |
|
---|
79 |
// misc stuff |
---|
80 |
void dumpInfo(); |
---|
81 |
|
---|
82 |
|
---|
83 |
protected: |
---|
84 |
|
---|
85 |
freebob_ringbuffer_t * m_event_buffer; |
---|
86 |
char* m_cluster_buffer; |
---|
87 |
|
---|
88 |
unsigned int m_event_size; // the size of one event |
---|
89 |
unsigned int m_events_per_frame; // the number of events in a frame |
---|
90 |
unsigned int m_buffer_size; // the number of frames in the buffer |
---|
91 |
unsigned int m_bytes_per_frame; |
---|
92 |
unsigned int m_bytes_per_buffer; |
---|
93 |
|
---|
94 |
TimestampedBufferClient *m_Client; |
---|
95 |
|
---|
96 |
DECLARE_DEBUG_MODULE; |
---|
97 |
|
---|
98 |
private: |
---|
99 |
// the framecounter gives the number of frames in the buffer |
---|
100 |
signed int m_framecounter; |
---|
101 |
|
---|
102 |
// the buffer tail timestamp gives the timestamp of the last frame |
---|
103 |
// that was put into the buffer |
---|
104 |
uint64_t m_buffer_tail_timestamp; |
---|
105 |
uint64_t m_buffer_next_tail_timestamp; |
---|
106 |
|
---|
107 |
// the buffer head timestamp gives the timestamp of the first frame |
---|
108 |
// that was put into the buffer |
---|
109 |
// uint64_t m_buffer_head_timestamp; |
---|
110 |
// this mutex protects the access to the framecounter |
---|
111 |
// and the buffer head timestamp. |
---|
112 |
pthread_mutex_t m_framecounter_lock; |
---|
113 |
|
---|
114 |
// tracking DLL variables |
---|
115 |
double m_dll_e2; |
---|
116 |
double m_dll_b; |
---|
117 |
double m_dll_c; |
---|
118 |
|
---|
119 |
double m_nominal_rate; |
---|
120 |
unsigned int m_update_period; |
---|
121 |
}; |
---|
122 |
|
---|
123 |
class TimestampedBufferClient { |
---|
124 |
public: |
---|
125 |
TimestampedBufferClient() {}; |
---|
126 |
virtual ~TimestampedBufferClient() {}; |
---|
127 |
|
---|
128 |
virtual bool processReadBlock(char *data, unsigned int nevents, unsigned int offset)=0; |
---|
129 |
virtual bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset)=0; |
---|
130 |
|
---|
131 |
}; |
---|
132 |
|
---|
133 |
} // end of namespace FreebobUtil |
---|
134 |
|
---|
135 |
#endif /* __FREEBOB_TIMESTAMPEDBUFFER__ */ |
---|
136 |
|
---|
137 |
|
---|