Show
Ignore:
Timestamp:
01/30/07 13:11:25 (16 years ago)
Author:
pieterpalmers
Message:

- temporary commit as backup measure
- rewrote synchronisation code
- receive streaming based on SYT works
- transmit streaming synced to received stream sort of works, still

have to iron out some issues.

NOTE: all devices but the bebob's are disabled in this code,

because they still have to be ported to the new sync
mechanism.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/libstreaming/StreamProcessor.h

    r383 r384  
    3434#include "PortManager.h" 
    3535#include "streamstatistics.h" 
     36 
     37#include <pthread.h> 
    3638 
    3739namespace FreebobStreaming { 
     
    7375 
    7476    bool xrunOccurred() { return (m_xruns>0);}; 
    75  
    76     /** 
    77      * This is used for implementing the synchronisation. 
    78      * As long as this function doesn't return true, the current buffer 
    79      * contents are not transfered to the packet decoders. 
    80      * 
    81      * This means that there can be more events in the buffer than 
    82      * one period worth of them, should the synchronisation mechanism  
    83      * require this 
    84      * @return  
    85      */ 
    86     virtual bool isOnePeriodReady()=0; 
    87      
    88     unsigned int getNbPeriodsReady() { if(m_period) return m_framecounter/m_period; else return 0;}; 
    89         virtual void decrementFrameCounter(); 
    90         virtual void incrementFrameCounter(int nbframes); 
    9177     
    9278    // move to private? 
    93         void resetFrameCounter(); 
    9479    void resetXrunCounter(); 
    9580 
     
    9984    bool isEnabled() {return !m_disabled;}; 
    10085 
    101     virtual bool transfer(); ///< transfer the buffer contents from/to client 
     86    virtual bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from client 
     87    virtual bool getFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents to the client 
    10288 
    10389    virtual bool reset(); ///< reset the streams & buffers (e.g. after xrun) 
     
    11197    virtual void setVerboseLevel(int l); 
    11298 
    113     virtual bool preparedForStop() {return true;}; 
    114     virtual bool preparedForStart() {return true;}; 
     99    virtual bool prepareForStop() {return true;}; 
     100    virtual bool prepareForStart() {return true;}; 
     101     
     102    virtual bool prepareForEnable() {return true;}; 
     103    virtual bool prepareForDisable() {return true;}; 
    115104 
    116105protected: 
     
    124113 
    125114    unsigned int m_xruns; 
    126         signed int m_framecounter; 
    127115 
    128116    unsigned int m_framerate; 
    129117 
    130118    StreamProcessorManager *m_manager; 
    131  
     119     
    132120    bool m_running; 
    133121    bool m_disabled; 
     
    141129    DECLARE_DEBUG_MODULE; 
    142130     
     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; 
    143216 
    144217};