| 131 | // frame counter & sync stuff |
---|
| 132 | public: |
---|
| 133 | /** |
---|
| 134 | * @brief Can this StreamProcessor handle a nframes of frames? |
---|
| 135 | * |
---|
| 136 | * this function indicates if the streamprocessor can handle nframes |
---|
| 137 | * of frames. It is used to detect underruns-to-be. |
---|
| 138 | * |
---|
| 139 | * @param nframes number of frames |
---|
| 140 | * @return true if the StreamProcessor can handle this amount of frames |
---|
| 141 | * false if it can't |
---|
| 142 | */ |
---|
| 143 | virtual bool canClientTransferFrames(unsigned int nframes) {return true;}; |
---|
| 144 | |
---|
| 145 | int getFrameCounter() {return m_framecounter;}; |
---|
| 146 | |
---|
| 147 | void decrementFrameCounter(int nbframes, uint64_t new_timestamp); |
---|
| 148 | void incrementFrameCounter(int nbframes, uint64_t new_timestamp); |
---|
| 149 | void setFrameCounter(int new_framecounter, uint64_t new_timestamp); |
---|
| 150 | void resetFrameCounter(); |
---|
| 151 | |
---|
| 152 | void setBufferTailTimestamp(uint64_t new_timestamp); |
---|
| 153 | void setBufferHeadTimestamp(uint64_t new_timestamp); |
---|
| 154 | void setBufferTimestamps(uint64_t new_head, uint64_t new_tail); |
---|
| 155 | /** |
---|
| 156 | * \brief return the time until the next period boundary (in microseconds) |
---|
| 157 | * |
---|
| 158 | * Return the time until the next period boundary. If this StreamProcessor |
---|
| 159 | * is the current synchronization source, this function is called to |
---|
| 160 | * determine when a buffer transfer can be made. When this value is |
---|
| 161 | * smaller than 0, a period boundary is assumed to be crossed, hence a |
---|
| 162 | * transfer can be made. |
---|
| 163 | * |
---|
| 164 | * \return the time in usecs |
---|
| 165 | */ |
---|
| 166 | virtual int64_t getTimeUntilNextPeriodUsecs() = 0; |
---|
| 167 | /** |
---|
| 168 | * \brief return the time of the next period boundary (in microseconds) |
---|
| 169 | * |
---|
| 170 | * Returns the time of the next period boundary, in microseconds. The |
---|
| 171 | * goal of this function is to determine the exact point of the period |
---|
| 172 | * boundary. This is assumed to be the point at which the buffer transfer should |
---|
| 173 | * take place, meaning that it can be used as a reference timestamp for transmitting |
---|
| 174 | * StreamProcessors |
---|
| 175 | * |
---|
| 176 | * \return the time in usecs |
---|
| 177 | */ |
---|
| 178 | virtual uint64_t getTimeAtPeriodUsecs() = 0; |
---|
| 179 | |
---|
| 180 | /** |
---|
| 181 | * \brief return the time of the next period boundary (in internal units) |
---|
| 182 | * |
---|
| 183 | * The same as getTimeUntilNextPeriodUsecs() but in internal units. |
---|
| 184 | * |
---|
| 185 | * @return the time in internal units |
---|
| 186 | */ |
---|
| 187 | virtual uint64_t getTimeAtPeriod() = 0; |
---|
| 188 | |
---|
| 189 | void getBufferHeadTimestamp(uint64_t *ts, uint64_t *fc); |
---|
| 190 | void getBufferTailTimestamp(uint64_t *ts, uint64_t *fc); |
---|
| 191 | |
---|
| 192 | bool setSyncSource(StreamProcessor *s); |
---|
| 193 | float getTicksPerFrame() {return m_ticks_per_frame;}; |
---|
| 194 | |
---|
| 195 | protected: |
---|
| 196 | // the framecounter gives the number of frames in the buffer |
---|
| 197 | signed int m_framecounter; |
---|
| 198 | |
---|
| 199 | // the buffer tail timestamp gives the timestamp of the last frame |
---|
| 200 | // that was put into the buffer |
---|
| 201 | uint64_t m_buffer_tail_timestamp; |
---|
| 202 | |
---|
| 203 | // the buffer head timestamp gives the timestamp of the first frame |
---|
| 204 | // that was put into the buffer |
---|
| 205 | uint64_t m_buffer_head_timestamp; |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | StreamProcessor *m_SyncSource; |
---|
| 209 | |
---|
| 210 | float m_ticks_per_frame; |
---|
| 211 | |
---|
| 212 | private: |
---|
| 213 | // this mutex protects the access to the framecounter |
---|
| 214 | // and the buffer head timestamp. |
---|
| 215 | pthread_mutex_t m_framecounter_lock; |
---|