Changeset 383

Show
Ignore:
Timestamp:
01/28/07 09:36:11 (16 years ago)
Author:
pieterpalmers
Message:

mostly whitespace fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/debugmodule/debugmodule.cpp

    r377 r383  
    213213DebugModuleManager::registerModule( DebugModule& debugModule ) 
    214214{ 
    215     m_debugModules.push_back( &debugModule ); 
     215        m_debugModules.push_back( &debugModule ); 
    216216    return true; 
    217217} 
     
    229229        } 
    230230    } 
    231  
     231     
    232232    cerr << "DebugModuleManager::unregisterModule: Could not unregister " 
    233233         << "DebugModule (" << debugModule.getName() << ")" << endl; 
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp

    r360 r383  
    9494                      int cycle, unsigned int dropped, unsigned int max_length) { 
    9595     
    96        struct iec61883_packet *packet = (struct iec61883_packet *) data; 
    97        unsigned int nevents=0; 
    98          
     96    struct iec61883_packet *packet = (struct iec61883_packet *) data; 
     97    unsigned int nevents=0; 
     98     
    9999    packet->eoh0 = 0; 
    100100     
     
    118118    packet->fmt = IEC61883_FMT_AMDTP; 
    119119 
    120        // signal that we are running (a transmit stream is always 'runnable') 
    121        m_running=true; 
    122          
    123        // don't process the stream when it is not enabled. 
    124        // however, we do have to generate (semi) valid packets 
    125        // that means that we'll send NODATA packets FIXME: check!! 
    126        if(m_disabled) { 
    127           // no-data packets have syt=0xFFFF 
    128           // and have the usual amount of events as dummy data  
     120    // signal that we are running (a transmit stream is always 'runnable') 
     121    m_running=true; 
     122     
     123    // don't process the stream when it is not enabled. 
     124    // however, we do have to generate (semi) valid packets 
     125    // that means that we'll send NODATA packets FIXME: check!! 
     126    if(m_disabled) { 
     127        // no-data packets have syt=0xFFFF 
     128        // and have the usual amount of events as dummy data  
    129129        packet->fdf = IEC61883_FDF_NODATA; 
    130130        packet->syt = 0xffff; 
     
    133133        m_dbc += m_syt_interval; 
    134134 
    135                *length = 2*sizeof(quadlet_t) + m_syt_interval * m_dimension * sizeof(quadlet_t); 
    136                *tag = IEC61883_TAG_WITH_CIP; 
    137                *sy = 0; 
    138          
    139                return RAW1394_ISO_DEFER; 
    140        
     135        *length = 2*sizeof(quadlet_t) + m_syt_interval * m_dimension * sizeof(quadlet_t); 
     136        *tag = IEC61883_TAG_WITH_CIP; 
     137        *sy = 0; 
     138 
     139        return RAW1394_ISO_DEFER; 
     140   
    141141     
    142142    packet->fdf = m_fdf; 
     
    447447     
    448448    // reset the statistics 
    449        m_PeriodStat.reset(); 
     449    m_PeriodStat.reset(); 
    450450    m_PacketStat.reset(); 
    451451    m_WakeupStat.reset(); 
     
    10481048         
    10491049        unsigned int syt_timestamp=ntohs(packet->syt); 
    1050         // reconstruct the top part of the timestamp using the current cycle number 
     1050        // reconstruct the top part of the timestamp using the current cycle number 
    10511051        unsigned int now_cycle_masked=cycle & 0xF; 
    10521052        unsigned int syt_cycle=CYCLE_COUNTER_GET_CYCLES(syt_timestamp); 
     
    10901090                measured_difference+=TICKS_PER_SECOND; 
    10911091            } 
    1092              
     1092 
    10931093            // implement a 1st order DLL to estimate the framerate 
    10941094            // this is the number of ticks between two samples 
     
    11151115         
    11161116         debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"R-SYT for cycle (%2d %2d)=>%2d: %5uT (%04uC + %04uT) %04X %04X %d\n", 
    1117          cycle,now_cycle_masked,delta_cycles, 
     1117            cycle,now_cycle_masked,delta_cycles, 
    11181118         CYCLE_COUNTER_TO_TICKS(m_last_timestamp), 
    11191119         CYCLE_COUNTER_GET_CYCLES(m_last_timestamp), 
     
    11211121         ntohs(packet->syt),m_last_timestamp&0xFFFF, dropped 
    11221122         ); 
    1123               
     1123 
    11241124#ifdef DEBUG 
    11251125        if(m_last_timestamp<m_last_timestamp2) { 
     
    11341134        } 
    11351135#endif 
    1136          
     1136 
    11371137        // don't process the stream samples when it is not enabled. 
    11381138        if(m_disabled) { 
     
    11751175        } 
    11761176#endif 
    1177          
     1177 
    11781178        // update the frame counter 
    11791179        incrementFrameCounter(nevents); 
     
    11821182           debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"defer!\n"); 
    11831183        } 
    1184          
     1184 
    11851185    } else { 
    11861186        // discard packet 
     
    14191419bool AmdtpReceiveStreamProcessor::reset() { 
    14201420 
    1421        debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n"); 
    1422  
    1423        // reset the event buffer, discard all content 
    1424        freebob_ringbuffer_reset(m_event_buffer); 
    1425          
     1421    debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n"); 
     1422 
     1423    // reset the event buffer, discard all content 
     1424    freebob_ringbuffer_reset(m_event_buffer); 
     1425     
    14261426        // reset the last timestamp 
    14271427        m_last_timestamp=0; 
    14281428         
    1429        m_PeriodStat.reset(); 
     1429    m_PeriodStat.reset(); 
    14301430    m_PacketStat.reset(); 
    14311431    m_WakeupStat.reset(); 
     
    14401440        m_last_timestamp2=0; 
    14411441         
    1442        m_one_period_passed=false; 
    1443          
    1444        // reset all non-device specific stuff 
    1445        // i.e. the iso stream and the associated ports 
    1446        if(!ReceiveStreamProcessor::reset()) { 
    1447                debugFatal("Could not do base class reset\n"); 
    1448                return false; 
    1449        
    1450        return true; 
     1442    m_one_period_passed=false; 
     1443 
     1444    // reset all non-device specific stuff 
     1445    // i.e. the iso stream and the associated ports 
     1446    if(!ReceiveStreamProcessor::reset()) { 
     1447            debugFatal("Could not do base class reset\n"); 
     1448            return false; 
     1449   
     1450    return true; 
    14511451} 
    14521452 
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.h

    r360 r383  
    7676    friend class AmdtpReceiveStreamProcessor; 
    7777     
    78        AmdtpTransmitStreamProcessor(int port, int framerate, int dimension); 
    79  
    80        virtual ~AmdtpTransmitStreamProcessor(); 
    81  
    82        enum raw1394_iso_disposition  
    83                getPacket(unsigned char *data, unsigned int *length, 
    84                      unsigned char *tag, unsigned char *sy, 
    85                      int cycle, unsigned int dropped, unsigned int max_length); 
    86  
    87        bool init(); 
    88        bool reset(); 
    89        bool prepare(); 
    90        bool transfer(); 
    91        virtual void setVerboseLevel(int l); 
    92          
    93        bool isOnePeriodReady(); 
     78    AmdtpTransmitStreamProcessor(int port, int framerate, int dimension); 
     79 
     80    virtual ~AmdtpTransmitStreamProcessor(); 
     81 
     82    enum raw1394_iso_disposition  
     83            getPacket(unsigned char *data, unsigned int *length, 
     84                    unsigned char *tag, unsigned char *sy, 
     85                    int cycle, unsigned int dropped, unsigned int max_length); 
     86 
     87    bool init(); 
     88    bool reset(); 
     89    bool prepare(); 
     90    bool transfer(); 
     91    virtual void setVerboseLevel(int l); 
     92     
     93    bool isOnePeriodReady(); 
    9494 
    9595    // We have 1 period of samples = m_period 
     
    100100    // however, if we only count the number of used packets 
    101101    // it is m_period / m_syt_interval 
    102        unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;}; 
    103          
    104        unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};  
     102    unsigned int getPacketsPerPeriod() {return (m_period)/m_syt_interval;}; 
     103     
     104    unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};  
    105105 
    106106    // FIXME: do this the proper way! 
     
    116116protected: 
    117117 
    118        struct iec61883_cip m_cip_status; 
    119  
    120        freebob_ringbuffer_t * m_event_buffer; 
    121        char* m_cluster_buffer; 
    122        int m_dimension; 
    123        unsigned int m_syt_interval; 
    124  
    125        int m_fdf; 
    126          
     118    struct iec61883_cip m_cip_status; 
     119 
     120    freebob_ringbuffer_t * m_event_buffer; 
     121    char* m_cluster_buffer; 
     122    int m_dimension; 
     123    unsigned int m_syt_interval; 
     124 
     125    int m_fdf; 
     126     
    127127    bool prefill(); 
    128128     
    129        bool transferSilence(unsigned int size); 
    130  
    131        int transmitBlock(char *data, unsigned int nevents,  
    132                          unsigned int offset); 
    133                           
    134        bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 
    135        int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data, 
    136                                   unsigned int offset, unsigned int nevents); 
    137          
    138        int transmitSilenceBlock(char *data, unsigned int nevents,  
    139                          unsigned int offset); 
    140        int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data, 
    141                                   unsigned int offset, unsigned int nevents); 
     129    bool transferSilence(unsigned int size); 
     130 
     131    int transmitBlock(char *data, unsigned int nevents,  
     132                        unsigned int offset); 
     133                         
     134    bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 
     135    int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data, 
     136                                unsigned int offset, unsigned int nevents); 
     137     
     138    int transmitSilenceBlock(char *data, unsigned int nevents,  
     139                        unsigned int offset); 
     140    int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data, 
     141                                unsigned int offset, unsigned int nevents); 
    142142 
    143143    unsigned long m_last_timestamp; 
     
    201201protected: 
    202202 
    203        int receiveBlock(char *data, unsigned int nevents, unsigned int offset); 
    204        bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 
    205          
    206        int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
    207  
    208        freebob_ringbuffer_t * m_event_buffer; 
    209        char* m_cluster_buffer; 
    210        int m_dimension; 
    211        unsigned int m_syt_interval; 
     203    int receiveBlock(char *data, unsigned int nevents, unsigned int offset); 
     204    bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 
     205     
     206    int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
     207 
     208    freebob_ringbuffer_t * m_event_buffer; 
     209    char* m_cluster_buffer; 
     210    int m_dimension; 
     211    unsigned int m_syt_interval; 
    212212     
    213213    unsigned int m_last_timestamp; 
  • branches/streaming-rework/src/libstreaming/freebob_streaming.cpp

    r360 r383  
    22 
    33/* 
    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  */ 
     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*/ 
    2828 
    2929/* freebob_streaming.c 
    30 
    31  * Implementation of the FreeBob Streaming API 
    32 
    33  */ 
     30
     31* Implementation of the FreeBob Streaming API 
     32
     33*/ 
    3434 
    3535#include "libfreebob/freebob_streaming.h" 
     
    5252 
    5353/** 
    54  * Device structure 
    55  */ 
     54* Device structure 
     55*/ 
    5656 
    5757DECLARE_GLOBAL_DEBUG_MODULE; 
     
    6161struct _freebob_device 
    6262{        
    63        DeviceManager * m_deviceManager; 
    64        StreamProcessorManager *processorManager; 
    65  
    66        freebob_options_t options; 
    67        freebob_device_info_t device_info; 
     63        DeviceManager * m_deviceManager; 
     64        StreamProcessorManager *processorManager; 
     65 
     66        freebob_options_t options; 
     67        freebob_device_info_t device_info; 
    6868};  
    6969 
    7070freebob_device_t *freebob_streaming_init (freebob_device_info_t *device_info, freebob_options_t options) { 
    71         unsigned int i=0; 
    72  
    73         struct _freebob_device *dev = new struct _freebob_device; 
    74  
    75     debugFatal("%s built %s %s\n", freebob_get_version(), __DATE__, __TIME__); 
    76  
    77         if(!dev) { 
    78                 debugFatal( "Could not allocate streaming device\n" ); 
    79                 return 0; 
    80         } 
    81  
    82         memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); 
    83         memcpy((void *)&dev->device_info, (void *)device_info, sizeof(dev->device_info)); 
    84  
    85         dev->m_deviceManager = new DeviceManager(); 
    86         if ( !dev->m_deviceManager ) { 
    87                 debugFatal( "Could not allocate device manager\n" ); 
    88                 delete dev; 
    89                 return 0; 
    90         } 
    91         if ( !dev->m_deviceManager->initialize( dev->options.port ) ) { 
    92                 debugFatal( "Could not initialize device manager\n" ); 
    93                 delete dev->m_deviceManager; 
    94                 delete dev; 
    95                 return 0; 
    96         } 
    97  
    98         // create a processor manager to manage the actual stream 
    99         // processors    
    100         dev->processorManager = new StreamProcessorManager(dev->options.period_size,dev->options.nb_buffers); 
    101         if(!dev->processorManager) { 
    102                 debugFatal("Could not create StreamProcessorManager\n"); 
    103         delete dev->m_deviceManager; 
    104                 delete dev; 
    105                 return 0; 
    106         } 
    107          
    108     dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 
    109          
    110         dev->processorManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    111         if(!dev->processorManager->init()) { 
    112                 debugFatal("Could not init StreamProcessorManager\n"); 
    113                 delete dev->processorManager; 
    114         delete dev->m_deviceManager; 
    115                 delete dev; 
    116                 return 0; 
    117         } 
    118  
    119         // discover the devices on the bus 
    120         if(!dev->m_deviceManager->discover(DEBUG_LEVEL_NORMAL)) { 
    121                 debugOutput(DEBUG_LEVEL_VERBOSE, "Could not discover devices\n"); 
    122                 delete dev->processorManager; 
    123         delete dev->m_deviceManager; 
    124                 delete dev;              
    125                 return 0; 
    126         } 
    127  
    128         // iterate over the found devices 
    129         // add the stream processors of the devices to the managers 
    130         for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    131                 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    132                 assert(device); 
    133  
    134                 // Set the device's sampling rate to that requested 
    135                 // FIXME: does this really belong here?  If so we need to handle errors. 
    136                 if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 
    137                   // try again: 
    138                   if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 
     71        unsigned int i=0; 
     72 
     73        struct _freebob_device *dev = new struct _freebob_device; 
     74 
     75        debugFatal("%s built %s %s\n", freebob_get_version(), __DATE__, __TIME__); 
     76 
     77        if(!dev) { 
     78                debugFatal( "Could not allocate streaming device\n" ); 
     79                return 0; 
     80        } 
     81 
     82        memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); 
     83        memcpy((void *)&dev->device_info, (void *)device_info, sizeof(dev->device_info)); 
     84 
     85        dev->m_deviceManager = new DeviceManager(); 
     86        if ( !dev->m_deviceManager ) { 
     87                debugFatal( "Could not allocate device manager\n" ); 
     88                delete dev; 
     89                return 0; 
     90        } 
     91        if ( !dev->m_deviceManager->initialize( dev->options.port ) ) { 
     92                debugFatal( "Could not initialize device manager\n" ); 
     93                delete dev->m_deviceManager; 
     94                delete dev; 
     95                return 0; 
     96        } 
     97 
     98        // create a processor manager to manage the actual stream 
     99        // processors    
     100        dev->processorManager = new StreamProcessorManager(dev->options.period_size,dev->options.nb_buffers); 
     101        if(!dev->processorManager) { 
     102                debugFatal("Could not create StreamProcessorManager\n"); 
     103                delete dev->m_deviceManager; 
     104                delete dev; 
     105                return 0; 
     106        } 
     107         
     108        dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 
     109         
     110        dev->processorManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     111        if(!dev->processorManager->init()) { 
     112                debugFatal("Could not init StreamProcessorManager\n"); 
    139113                delete dev->processorManager; 
    140114                delete dev->m_deviceManager; 
    141115                delete dev; 
    142                 debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); 
    143                 return 0; 
    144                   } 
    145                 } 
    146  
    147                 // prepare the device 
    148                 device->prepare(); 
    149  
    150                 int j=0; 
    151                 for(j=0; j<device->getStreamCount();j++) { 
    152                         StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); 
    153                         debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); 
    154                         if (!dev->processorManager->registerProcessor(streamproc)) { 
    155                                 debugWarning("Could not register stream processor (%p) with the Processor manager\n",streamproc); 
    156                         } 
    157                 } 
    158         } 
    159  
    160         // we are ready! 
     116                return 0; 
     117        } 
     118 
     119        // discover the devices on the bus 
     120        if(!dev->m_deviceManager->discover(DEBUG_LEVEL_NORMAL)) { 
     121                debugOutput(DEBUG_LEVEL_VERBOSE, "Could not discover devices\n"); 
     122                delete dev->processorManager; 
     123                delete dev->m_deviceManager; 
     124                delete dev; 
     125                return 0; 
     126        } 
     127 
     128        // iterate over the found devices 
     129        // add the stream processors of the devices to the managers 
     130        for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
     131            IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
     132            assert(device); 
     133 
     134            // Set the device's sampling rate to that requested 
     135            // FIXME: does this really belong here?  If so we need to handle errors. 
     136            if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 
     137                // try again: 
     138                if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 
     139                    delete dev->processorManager; 
     140                    delete dev->m_deviceManager; 
     141                    delete dev; 
     142                    debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); 
     143                    return 0; 
     144                } 
     145            } 
     146 
     147            // prepare the device 
     148            device->prepare(); 
     149 
     150            int j=0; 
     151            for(j=0; j<device->getStreamCount();j++) { 
     152                StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); 
     153                debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); 
     154                if (!dev->processorManager->registerProcessor(streamproc)) { 
     155                    debugWarning("Could not register stream processor (%p) with the Processor manager\n",streamproc); 
     156                } 
     157            } 
     158        } 
     159 
     160        // we are ready! 
    161161         
    162        debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); 
    163        return dev; 
     162        debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); 
     163        return dev; 
    164164 
    165165} 
    166166 
    167167int freebob_streaming_prepare(freebob_device_t *dev) { 
    168         debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
     168        debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
     169         
     170        if (!dev->processorManager->prepare()) { 
     171        debugFatal("Could not prepare streaming...\n"); 
     172        return false; 
     173        } 
     174 
     175        return true; 
     176
     177 
     178void freebob_streaming_finish(freebob_device_t *dev) { 
     179 
     180        assert(dev); 
     181 
     182        delete dev->processorManager; 
     183        delete dev->m_deviceManager; 
     184        delete dev; 
     185 
     186        return; 
     187
     188 
     189int freebob_streaming_start(freebob_device_t *dev) { 
     190    unsigned int i=0; 
     191    debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Start -------------\n"); 
     192     
    169193         
    170         if (!dev->processorManager->prepare()) { 
    171            debugFatal("Could not prepare streaming...\n"); 
    172            return false; 
    173         } 
    174  
    175         return true; 
    176 
    177  
    178 void freebob_streaming_finish(freebob_device_t *dev) { 
    179  
    180         assert(dev); 
    181  
    182         delete dev->processorManager; 
    183         delete dev->m_deviceManager; 
    184         delete dev; 
    185  
    186         return; 
    187 
    188  
    189 int freebob_streaming_start(freebob_device_t *dev) { 
    190         unsigned int i=0; 
    191         debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Start -------------\n"); 
    192  
    193          
    194         // create the connections for all devices 
    195         // iterate over the found devices 
    196         // add the stream processors of the devices to the managers 
    197         for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    198                 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    199                 assert(device); 
    200  
    201                 int j=0; 
    202                 for(j=0; j<device->getStreamCount();j++) { 
    203                 debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %d\n",j,i); 
    204                         // start the stream 
    205                         device->startStreamByIndex(j); 
    206                 } 
    207         } 
     194    // create the connections for all devices 
     195    // iterate over the found devices 
     196    // add the stream processors of the devices to the managers 
     197    for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
     198        IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
     199        assert(device); 
     200     
     201        int j=0; 
     202        for(j=0; j<device->getStreamCount();j++) { 
     203        debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %d\n",j,i); 
     204            // start the stream 
     205            device->startStreamByIndex(j); 
     206        } 
     207    } 
    208208 
    209209        dev->processorManager->start(); 
    210210 
    211        return 0; 
     211        return 0; 
    212212} 
    213213 
    214214int freebob_streaming_stop(freebob_device_t *dev) { 
    215        unsigned int i; 
    216        debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); 
    217  
    218        dev->processorManager->stop(); 
    219  
    220        // create the connections for all devices 
    221        // iterate over the found devices 
    222        // add the stream processors of the devices to the managers 
    223        for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    224                IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    225                assert(device); 
    226                  
    227  
    228                int j=0; 
    229                for(j=0; j<device->getStreamCount();j++) { 
    230                debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); 
    231                        // stop the stream 
    232                        device->stopStreamByIndex(j); 
    233                
    234        
    235  
    236        return 0; 
     215        unsigned int i; 
     216        debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); 
     217 
     218        dev->processorManager->stop(); 
     219 
     220        // create the connections for all devices 
     221        // iterate over the found devices 
     222        // add the stream processors of the devices to the managers 
     223        for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
     224            IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
     225            assert(device); 
     226                 
     227 
     228            int j=0; 
     229            for(j=0; j<device->getStreamCount();j++) { 
     230                debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); 
     231                // stop the stream 
     232                device->stopStreamByIndex(j); 
     233           
     234       
     235 
     236        return 0; 
    237237} 
    238238 
    239239int freebob_streaming_reset(freebob_device_t *dev) { 
    240        debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); 
     240        debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); 
    241241 
    242242//      dev->processorManager->reset(); 
    243243 
    244        return 0; 
     244        return 0; 
    245245} 
    246246 
    247247int freebob_streaming_wait(freebob_device_t *dev) { 
    248        static int periods=0; 
    249        static int periods_print=0; 
    250        static int xruns=0; 
    251                  
    252                periods++; 
    253                if(periods>periods_print) { 
    254                        debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 
    255                        debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
    256                        debugOutput(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); 
    257                        debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
    258                        dev->processorManager->dumpInfo(); 
     248        static int periods=0; 
     249        static int periods_print=0; 
     250        static int xruns=0; 
     251                 
     252                periods++; 
     253                if(periods>periods_print) { 
     254                        debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 
     255                        debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
     256                        debugOutput(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); 
     257                        debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
     258                        dev->processorManager->dumpInfo(); 
    259259//                      debugOutput(DEBUG_LEVEL_VERBOSE, "--------------------------------------------\n"); 
    260260/*                      quadlet_t *addr=(quadlet_t*)(dev->processorManager->getPortByIndex(0, Port::E_Capture)->getBufferAddress()); 
    261                        if (addr) hexDumpQuadlets(addr,10);*/ 
    262                        debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 
    263                        periods_print+=100; 
    264                
    265        if(dev->processorManager->waitForPeriod()) { 
    266                return dev->options.period_size; 
    267        } else { 
    268                debugWarning("XRUN detected\n"); 
    269                // do xrun recovery 
    270                  
    271                dev->processorManager->handleXrun(); 
    272                xruns++; 
    273                return -1; 
    274        
     261                        if (addr) hexDumpQuadlets(addr,10);*/ 
     262                        debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 
     263                        periods_print+=100; 
     264               
     265        if(dev->processorManager->waitForPeriod()) { 
     266                return dev->options.period_size; 
     267        } else { 
     268                debugWarning("XRUN detected\n"); 
     269                // do xrun recovery 
     270                 
     271                dev->processorManager->handleXrun(); 
     272                xruns++; 
     273                return -1; 
     274       
    275275} 
    276276 
    277277int freebob_streaming_transfer_capture_buffers(freebob_device_t *dev) { 
    278        return dev->processorManager->transfer(StreamProcessor::E_Receive); 
     278        return dev->processorManager->transfer(StreamProcessor::E_Receive); 
    279279} 
    280280 
    281281int freebob_streaming_transfer_playback_buffers(freebob_device_t *dev) { 
    282        return dev->processorManager->transfer(StreamProcessor::E_Transmit); 
     282        return dev->processorManager->transfer(StreamProcessor::E_Transmit); 
    283283} 
    284284 
    285285int freebob_streaming_transfer_buffers(freebob_device_t *dev) { 
    286        return dev->processorManager->transfer(); 
     286        return dev->processorManager->transfer(); 
    287287} 
    288288 
     
    290290int freebob_streaming_write(freebob_device_t *dev, int i, freebob_sample_t *buffer, int nsamples) { 
    291291// debugFatal("Not implemented\n"); 
    292        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
    293        // use an assert here performancewise,  
    294        // it should already have failed before, if not correct 
    295        assert(p);  
    296          
    297        return p->writeEvents((void *)buffer, nsamples); 
     292        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     293        // use an assert here performancewise,  
     294        // it should already have failed before, if not correct 
     295        assert(p);  
     296         
     297        return p->writeEvents((void *)buffer, nsamples); 
    298298} 
    299299 
    300300int freebob_streaming_read(freebob_device_t *dev, int i, freebob_sample_t *buffer, int nsamples) { 
    301        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
    302        // use an assert here performancewise,  
    303        // it should already have failed before, if not correct 
    304        assert(p);  
    305          
    306        return p->readEvents((void *)buffer, nsamples); 
     301        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     302        // use an assert here performancewise,  
     303        // it should already have failed before, if not correct 
     304        assert(p);  
     305         
     306        return p->readEvents((void *)buffer, nsamples); 
    307307} 
    308308 
    309309pthread_t freebob_streaming_get_packetizer_thread(freebob_device_t *dev) { 
    310310//      debugFatal("Not implemented\n"); 
    311        return 0; 
     311        return 0; 
    312312} 
    313313 
    314314 
    315315int freebob_streaming_get_nb_capture_streams(freebob_device_t *dev) { 
    316        return dev->processorManager->getPortCount(Port::E_Capture); 
     316        return dev->processorManager->getPortCount(Port::E_Capture); 
    317317} 
    318318 
    319319int freebob_streaming_get_nb_playback_streams(freebob_device_t *dev) { 
    320        return dev->processorManager->getPortCount(Port::E_Playback); 
     320        return dev->processorManager->getPortCount(Port::E_Playback); 
    321321} 
    322322 
    323323int freebob_streaming_get_capture_stream_name(freebob_device_t *dev, int i, char* buffer, size_t buffersize) { 
    324        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
    325        if(!p) { 
    326                debugWarning("Could not get capture port at index %d\n",i); 
    327                return -1; 
    328        
    329  
    330        std::string name=p->getName(); 
    331        if (!strncpy(buffer, name.c_str(), buffersize)) { 
    332                debugWarning("Could not copy name\n"); 
    333                return -1; 
    334        } else return 0; 
     324        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     325        if(!p) { 
     326                debugWarning("Could not get capture port at index %d\n",i); 
     327                return -1; 
     328       
     329 
     330        std::string name=p->getName(); 
     331        if (!strncpy(buffer, name.c_str(), buffersize)) { 
     332                debugWarning("Could not copy name\n"); 
     333                return -1; 
     334        } else return 0; 
    335335} 
    336336 
    337337int freebob_streaming_get_playback_stream_name(freebob_device_t *dev, int i, char* buffer, size_t buffersize) { 
    338          
    339        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
    340        if(!p) { 
    341                debugWarning("Could not get playback port at index %d\n",i); 
    342                return -1; 
    343        
    344  
    345        std::string name=p->getName(); 
    346        if (!strncpy(buffer, name.c_str(), buffersize)) { 
    347                debugWarning("Could not copy name\n"); 
    348                return -1; 
    349        } else return 0; 
     338         
     339        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     340        if(!p) { 
     341                debugWarning("Could not get playback port at index %d\n",i); 
     342                return -1; 
     343       
     344 
     345        std::string name=p->getName(); 
     346        if (!strncpy(buffer, name.c_str(), buffersize)) { 
     347                debugWarning("Could not copy name\n"); 
     348                return -1; 
     349        } else return 0; 
    350350} 
    351351 
    352352freebob_streaming_stream_type freebob_streaming_get_capture_stream_type(freebob_device_t *dev, int i) { 
    353        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
    354        if(!p) { 
    355                debugWarning("Could not get capture port at index %d\n",i); 
    356                return freebob_stream_type_invalid; 
    357        
    358        switch(p->getPortType()) { 
    359        case Port::E_Audio: 
    360                return freebob_stream_type_audio; 
    361        case Port::E_Midi: 
    362                return freebob_stream_type_midi; 
    363        case Port::E_Control: 
    364                return freebob_stream_type_control; 
    365        default: 
    366                return freebob_stream_type_unknown; 
    367        
     353        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     354        if(!p) { 
     355                debugWarning("Could not get capture port at index %d\n",i); 
     356                return freebob_stream_type_invalid; 
     357       
     358        switch(p->getPortType()) { 
     359        case Port::E_Audio: 
     360                return freebob_stream_type_audio; 
     361        case Port::E_Midi: 
     362                return freebob_stream_type_midi; 
     363        case Port::E_Control: 
     364                return freebob_stream_type_control; 
     365        default: 
     366                return freebob_stream_type_unknown; 
     367       
    368368} 
    369369 
    370370freebob_streaming_stream_type freebob_streaming_get_playback_stream_type(freebob_device_t *dev, int i) { 
    371        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
    372        if(!p) { 
    373                debugWarning("Could not get playback port at index %d\n",i); 
    374                return freebob_stream_type_invalid; 
    375        
    376        switch(p->getPortType()) { 
    377        case Port::E_Audio: 
    378                return freebob_stream_type_audio; 
    379        case Port::E_Midi: 
    380                return freebob_stream_type_midi; 
    381        case Port::E_Control: 
    382                return freebob_stream_type_control; 
    383        default: 
    384                return freebob_stream_type_unknown; 
    385        
     371        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     372        if(!p) { 
     373                debugWarning("Could not get playback port at index %d\n",i); 
     374                return freebob_stream_type_invalid; 
     375       
     376        switch(p->getPortType()) { 
     377        case Port::E_Audio: 
     378                return freebob_stream_type_audio; 
     379        case Port::E_Midi: 
     380                return freebob_stream_type_midi; 
     381        case Port::E_Control: 
     382                return freebob_stream_type_control; 
     383        default: 
     384                return freebob_stream_type_unknown; 
     385       
    386386} 
    387387 
     
    389389        freebob_streaming_buffer_type t, enum Port::E_Direction direction) { 
    390390 
    391        Port *p=dev->processorManager->getPortByIndex(i, direction); 
    392        if(!p) { 
    393                debugWarning("Could not get %s port at index %d\n", 
    394                      (direction==Port::E_Playback?"Playback":"Capture"),i); 
    395                return -1; 
    396        
    397          
    398        switch(t) { 
    399        case freebob_buffer_type_int24: 
    400           if (!p->setDataType(Port::E_Int24)) { 
    401               debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); 
    402               return -1; 
    403           } 
    404           if (!p->setBufferType(Port::E_PointerBuffer)) { 
    405               debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
    406               return -1; 
    407           } 
    408           break; 
    409        case freebob_buffer_type_float: 
    410           if (!p->setDataType(Port::E_Float)) { 
    411               debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); 
    412               return -1; 
    413           } 
    414           if (!p->setBufferType(Port::E_PointerBuffer)) { 
    415               debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
    416               return -1; 
    417           } 
    418           break; 
    419        case freebob_buffer_type_midi: 
    420           if (!p->setDataType(Port::E_MidiEvent)) { 
    421               debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); 
    422               return -1; 
    423           } 
    424           if (!p->setBufferType(Port::E_RingBuffer)) { 
    425               debugWarning("%s: Could not set buffer type to Ringbuffer\n",p->getName().c_str()); 
    426               return -1; 
    427           } 
    428           break; 
    429        default: 
    430        debugWarning("%s: Unsupported buffer type\n",p->getName().c_str()); 
    431        return -1; 
    432        
     391        Port *p=dev->processorManager->getPortByIndex(i, direction); 
     392        if(!p) { 
     393                debugWarning("Could not get %s port at index %d\n", 
     394                    (direction==Port::E_Playback?"Playback":"Capture"),i); 
     395                return -1; 
     396       
     397         
     398        switch(t) { 
     399        case freebob_buffer_type_int24: 
     400        if (!p->setDataType(Port::E_Int24)) { 
     401            debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); 
     402            return -1; 
     403        } 
     404        if (!p->setBufferType(Port::E_PointerBuffer)) { 
     405            debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
     406            return -1; 
     407        } 
     408        break; 
     409        case freebob_buffer_type_float: 
     410        if (!p->setDataType(Port::E_Float)) { 
     411            debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); 
     412            return -1; 
     413        } 
     414        if (!p->setBufferType(Port::E_PointerBuffer)) { 
     415            debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
     416            return -1; 
     417        } 
     418        break; 
     419        case freebob_buffer_type_midi: 
     420        if (!p->setDataType(Port::E_MidiEvent)) { 
     421            debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); 
     422            return -1; 
     423        } 
     424        if (!p->setBufferType(Port::E_RingBuffer)) { 
     425            debugWarning("%s: Could not set buffer type to Ringbuffer\n",p->getName().c_str()); 
     426            return -1; 
     427        } 
     428        break; 
     429        default: 
     430    debugWarning("%s: Unsupported buffer type\n",p->getName().c_str()); 
     431    return -1; 
     432       
    433433    return 0; 
    434434 
     
    445445int freebob_streaming_stream_onoff(freebob_device_t *dev, int i,  
    446446        int on, enum Port::E_Direction direction) { 
    447        Port *p=dev->processorManager->getPortByIndex(i, direction); 
    448        if(!p) { 
    449                debugWarning("Could not get %s port at index %d\n", 
    450                      (direction==Port::E_Playback?"Playback":"Capture"),i); 
    451                return -1; 
    452        
    453        if(on) { 
    454           p->enable(); 
    455        } else { 
    456           p->disable(); 
    457        
    458        return 0; 
     447        Port *p=dev->processorManager->getPortByIndex(i, direction); 
     448        if(!p) { 
     449                debugWarning("Could not get %s port at index %d\n", 
     450                    (direction==Port::E_Playback?"Playback":"Capture"),i); 
     451                return -1; 
     452       
     453        if(on) { 
     454        p->enable(); 
     455        } else { 
     456        p->disable(); 
     457       
     458        return 0; 
    459459} 
    460460 
     
    469469// TODO: the way port buffers are set in the C api doesn't satisfy me 
    470470int freebob_streaming_set_capture_stream_buffer(freebob_device_t *dev, int i, char *buff) { 
    471        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
    472          
    473        // use an assert here performancewise,  
    474        // it should already have failed before, if not correct 
    475        assert(p);  
    476          
    477        p->useExternalBuffer(true); 
    478        p->setExternalBufferAddress((void *)buff); 
    479  
    480        return 0; 
     471        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     472         
     473        // use an assert here performancewise,  
     474        // it should already have failed before, if not correct 
     475        assert(p);  
     476         
     477        p->useExternalBuffer(true); 
     478        p->setExternalBufferAddress((void *)buff); 
     479 
     480        return 0; 
    481481 
    482482} 
    483483 
    484484int freebob_streaming_set_playback_stream_buffer(freebob_device_t *dev, int i, char *buff) { 
    485        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
    486        // use an assert here performancewise,  
    487        // it should already have failed before, if not correct 
    488        assert(p);  
    489          
    490        p->useExternalBuffer(true); 
    491        p->setExternalBufferAddress((void *)buff); 
    492  
    493        return 0; 
    494 } 
    495  
     485        Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     486        // use an assert here performancewise,  
     487        // it should already have failed before, if not correct 
     488        assert(p);  
     489         
     490        p->useExternalBuffer(true); 
     491        p->setExternalBufferAddress((void *)buff); 
     492 
     493        return 0; 
     494} 
     495 
  • branches/streaming-rework/src/libstreaming/IsoHandler.cpp

    r360 r383  
    118118IsoHandler::~IsoHandler() { 
    119119    if(m_handle) { 
    120         stop(); 
     120            stop(); 
    121121        raw1394_destroy_handle(m_handle); 
    122122    } 
     
    129129IsoHandler::init() 
    130130{ 
    131        debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) enter...\n",this); 
    132  
    133        m_handle = raw1394_new_handle_on_port( m_port ); 
    134        if ( !m_handle ) { 
    135                if ( !errno ) { 
     131    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) enter...\n",this); 
     132 
     133    m_handle = raw1394_new_handle_on_port( m_port ); 
     134    if ( !m_handle ) { 
     135        if ( !errno ) { 
    136136                        cerr << "libraw1394 not compatible" << endl; 
    137                } else { 
     137        } else { 
    138138                        perror( "IsoHandler::Initialize: Could not get 1394 handle" ); 
    139139                        cerr << "Is ieee1394 and raw1394 driver loaded?" << endl; 
    140                
    141                return false; 
    142        
    143        raw1394_set_userdata(m_handle, static_cast<void *>(this)); 
    144          
    145        // a second handle for utility stuff 
    146        m_handle_util = raw1394_new_handle_on_port( m_port ); 
    147        if ( !m_handle_util ) { 
    148                if ( !errno ) { 
     140       
     141        return false; 
     142   
     143    raw1394_set_userdata(m_handle, static_cast<void *>(this)); 
     144     
     145    // a second handle for utility stuff 
     146    m_handle_util = raw1394_new_handle_on_port( m_port ); 
     147    if ( !m_handle_util ) { 
     148        if ( !errno ) { 
    149149                        cerr << "libraw1394 not compatible" << endl; 
    150                } else { 
     150        } else { 
    151151                        perror( "IsoHandler::Initialize: Could not get 1394 handle" ); 
    152152                        cerr << "Is ieee1394 and raw1394 driver loaded?" << endl; 
    153                 } 
    154                 return false; 
     153        } 
     154        return false; 
     155    } 
     156         
     157    raw1394_set_userdata(m_handle_util, static_cast<void *>(this)); 
     158         
     159    if(raw1394_busreset_notify (m_handle, RAW1394_NOTIFY_ON)) { 
     160        debugWarning("Could not enable busreset notification.\n"); 
     161        debugWarning(" Error message: %s\n",strerror(errno)); 
    155162        } 
    156163         
    157         raw1394_set_userdata(m_handle_util, static_cast<void *>(this)); 
    158          
    159         if(raw1394_busreset_notify (m_handle, RAW1394_NOTIFY_ON)) { 
    160                 debugWarning("Could not enable busreset notification.\n"); 
    161                 debugWarning(" Error message: %s\n",strerror(errno)); 
    162         } 
    163          
    164         raw1394_set_bus_reset_handler(m_handle, busreset_handler); 
     164        raw1394_set_bus_reset_handler(m_handle, busreset_handler); 
    165165 
    166166    // initialize the local timesource 
     
    171171    raw1394_read(m_handle_util, raw1394_get_local_id(m_handle_util),  
    172172        CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); 
    173      
     173 
    174174    new_counter= ntohl(buf) & 0xFFFFFFFF; 
    175175    m_TimeSource_LastSecs=CYCLE_COUNTER_GET_SECS(new_counter); 
     
    177177    // update the cycle counter value for initial value 
    178178    initCycleCounter(); 
    179  
    180        return true; 
     179     
     180    return true; 
    181181} 
    182182 
     
    185185{ 
    186186    m_TimeSource=t; 
    187      
     187 
    188188    // update the cycle counter value for initial value 
    189189    initCycleCounter(); 
    190      
     190 
    191191    return true; 
    192192} 
     
    194194bool IsoHandler::stop() 
    195195{ 
    196        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    197         raw1394_iso_stop(m_handle);  
    198        return true; 
     196    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     197    raw1394_iso_stop(m_handle); 
     198    return true; 
    199199} 
    200200 
     
    206206  
    207207int IsoHandler::handleBusReset(unsigned int generation) { 
    208        debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); 
    209          
    210        // as busreset can elect a new cycle master, 
    211        // we need to re-initialize our timing code 
     208    debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); 
     209     
     210    // as busreset can elect a new cycle master, 
     211    // we need to re-initialize our timing code 
    212212    initCycleCounter(); 
    213213     
    214        return 0; 
     214    return 0; 
    215215} 
    216216 
     
    225225    // and the estimated tick rate 
    226226    freebob_microsecs_t now=m_TimeSource->getCurrentTimeAsUsecs(); 
    227      
     227 
    228228    // linear interpolation 
    229229    int delta_usecs=now-m_lastmeas_usecs; 
    230230 
    231231    float offset=m_ticks_per_usec * ((float)delta_usecs); 
    232      
     232 
    233233    unsigned int pred_ticks=m_cyclecounter_ticks+(unsigned int)offset; 
    234      
     234 
    235235    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Get CC: d_usecs=%d, offset=%f, cc_ticks=%lu, pred_ticks=%lu\n", 
    236236      delta_usecs, offset, m_cyclecounter_ticks,pred_ticks 
    237237      ); 
    238        
     238 
    239239    // if we need to wrap, do it 
    240240    if (pred_ticks > TICKS_PER_SECOND * 128) { 
     
    247247bool IsoHandler::updateCycleCounter() { 
    248248    quadlet_t buf=0; 
    249      
     249 
    250250    freebob_microsecs_t prev_usecs=m_lastmeas_usecs; 
    251251    unsigned int prev_ticks=m_cyclecounter_ticks; 
     
    295295        CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); 
    296296    new_usecs=m_TimeSource->getCurrentTimeAsUsecs(); 
    297      
     297 
    298298    new_counter= ntohl(buf) & 0xFFFFFFFF; 
    299299    new_ticks=CYCLE_COUNTER_TO_TICKS(new_counter); 
    300      
     300 
    301301    // the difference in system time 
    302302    int delta_usecs=new_usecs-prev_usecs; 
     
    386386            m_cyclecounter_ticks -= TICKS_PER_SECOND * 128; 
    387387        } 
    388              
     388 
    389389        m_lastmeas_usecs = new_usecs; 
    390390 
     
    446446            CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); 
    447447        new_usecs=m_TimeSource->getCurrentTimeAsUsecs(); 
    448          
     448 
    449449        new_counter= ntohl(buf) & 0xFFFFFFFF; 
    450450        new_ticks=CYCLE_COUNTER_TO_TICKS(new_counter); 
     
    490490{ 
    491491 
    492        int channel=-1; 
    493        if (m_Client) channel=m_Client->getChannel(); 
    494  
    495        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Handler type    : %s\n", 
    496             (this->getType()==EHT_Receive ? "Receive" : "Transmit")); 
    497        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %2d, %2d\n", 
    498             m_port, channel); 
    499        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Packet count   : %10d (%5d dropped)\n", 
    500             this->getPacketCount(), this->getDroppedCount()); 
     492    int channel=-1; 
     493    if (m_Client) channel=m_Client->getChannel(); 
     494 
     495    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Handler type    : %s\n", 
     496            (this->getType()==EHT_Receive ? "Receive" : "Transmit")); 
     497    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %2d, %2d\n", 
     498            m_port, channel); 
     499    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Packet count   : %10d (%5d dropped)\n", 
     500            this->getPacketCount(), this->getDroppedCount()); 
    501501    #ifdef DEBUG 
    502502    unsigned int cc=this->getCycleCounter(); 
    503503        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Cycle counter  : %10lu (%03us, %04ucycles, %04uticks)\n", 
    504             cc,TICKS_TO_SECS(cc),TICKS_TO_CYCLES(cc),TICKS_TO_OFFSET(cc)); 
    505        #endif 
    506        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Ticks/usec     : %8.6f (dll2: %8.6e)\n\n", 
    507             this->getTicksPerUsec(), m_ticks_per_usec_dll_err2); 
     504            cc,TICKS_TO_SECS(cc),TICKS_TO_CYCLES(cc),TICKS_TO_OFFSET(cc)); 
     505    #endif 
     506    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Ticks/usec     : %8.6f (dll2: %8.6e)\n\n", 
     507            this->getTicksPerUsec(), m_ticks_per_usec_dll_err2); 
    508508 
    509509}; 
     
    511511void IsoHandler::setVerboseLevel(int l) 
    512512{ 
    513        setDebugLevel(l); 
     513    setDebugLevel(l); 
    514514} 
    515515 
    516516bool IsoHandler::registerStream(IsoStream *stream) 
    517517{ 
    518        assert(stream); 
    519        debugOutput( DEBUG_LEVEL_VERBOSE, "registering stream (%p)\n", stream); 
    520  
    521        if (m_Client) { 
    522                debugFatal( "Generic IsoHandlers can have only one client\n");  
    523                return false; 
    524        
    525  
    526        m_Client=stream; 
    527  
    528        m_Client->setHandler(this); 
    529  
    530        return true; 
     518    assert(stream); 
     519    debugOutput( DEBUG_LEVEL_VERBOSE, "registering stream (%p)\n", stream); 
     520 
     521    if (m_Client) { 
     522            debugFatal( "Generic IsoHandlers can have only one client\n");     
     523            return false; 
     524   
     525 
     526    m_Client=stream; 
     527 
     528    m_Client->setHandler(this); 
     529 
     530    return true; 
    531531 
    532532} 
     
    534534bool IsoHandler::unregisterStream(IsoStream *stream) 
    535535{ 
    536        assert(stream); 
    537        debugOutput( DEBUG_LEVEL_VERBOSE, "unregistering stream (%p)\n", stream); 
    538  
    539        if(stream != m_Client) { 
    540                debugFatal( "no client registered\n");  
    541                return false; 
    542        
    543  
    544        m_Client->clearHandler(); 
    545          
    546        m_Client=0; 
    547        return true; 
     536    assert(stream); 
     537    debugOutput( DEBUG_LEVEL_VERBOSE, "unregistering stream (%p)\n", stream); 
     538 
     539    if(stream != m_Client) { 
     540            debugFatal( "no client registered\n");     
     541            return false; 
     542   
     543 
     544    m_Client->clearHandler(); 
     545     
     546    m_Client=0; 
     547    return true; 
    548548 
    549549} 
     
    595595 
    596596IsoRecvHandler::IsoRecvHandler(int port) 
    597                : IsoHandler(port) 
    598 { 
    599        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     597                : IsoHandler(port) 
     598{ 
     599    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    600600} 
    601601IsoRecvHandler::IsoRecvHandler(int port, unsigned int buf_packets,  
    602602                               unsigned int max_packet_size, int irq) 
    603                : IsoHandler(port, buf_packets,max_packet_size,irq) 
    604 { 
    605        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     603                : IsoHandler(port, buf_packets,max_packet_size,irq) 
     604{ 
     605    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    606606 
    607607} 
     
    619619bool 
    620620IsoRecvHandler::init() { 
    621        debugOutput( DEBUG_LEVEL_VERBOSE, "init recv handler %p\n",this); 
    622  
    623        if(!(IsoHandler::init())) { 
    624                return false; 
    625        
    626        return true; 
     621    debugOutput( DEBUG_LEVEL_VERBOSE, "init recv handler %p\n",this); 
     622 
     623    if(!(IsoHandler::init())) { 
     624        return false; 
     625   
     626    return true; 
    627627 
    628628} 
    629629 
    630630enum raw1394_iso_disposition IsoRecvHandler::putPacket(unsigned char *data, unsigned int length,  
    631                              unsigned char channel, unsigned char tag, unsigned char sy,  
    632                                  unsigned int cycle, unsigned int dropped) { 
    633  
    634        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
    635                     "received packet: length=%d, channel=%d, cycle=%d\n", 
    636                     length, channel, cycle ); 
    637        m_packetcount++; 
    638        m_dropped+=dropped; 
    639  
    640        if(m_Client) { 
    641                return m_Client->putPacket(data, length, channel, tag, sy, cycle, dropped); 
    642        
    643          
    644        return RAW1394_ISO_OK; 
     631                    unsigned char channel, unsigned char tag, unsigned char sy,  
     632                    unsigned int cycle, unsigned int dropped) { 
     633 
     634    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
     635                 "received packet: length=%d, channel=%d, cycle=%d\n", 
     636                 length, channel, cycle ); 
     637    m_packetcount++; 
     638    m_dropped+=dropped; 
     639 
     640    if(m_Client) { 
     641        return m_Client->putPacket(data, length, channel, tag, sy, cycle, dropped); 
     642   
     643     
     644    return RAW1394_ISO_OK; 
    645645} 
    646646 
     
    651651// confirmed present in libraw1394 1.2.1. 
    652652//      raw1394_iso_shutdown(m_handle); 
    653          
    654        debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p)\n",this); 
    655        debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers         : %d \n",m_buf_packets); 
    656        debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n",m_max_packet_size); 
    657        debugOutput( DEBUG_LEVEL_VERBOSE, " Channel         : %d \n",m_Client->getChannel()); 
    658        debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval    : %d \n",m_irq_interval); 
     653 
     654    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p)\n",this); 
     655    debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers         : %d \n",m_buf_packets); 
     656    debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n",m_max_packet_size); 
     657    debugOutput( DEBUG_LEVEL_VERBOSE, " Channel         : %d \n",m_Client->getChannel()); 
     658    debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval    : %d \n",m_irq_interval); 
    659659 
    660660        if(raw1394_iso_recv_init(m_handle,   iso_receive_handler, 
    661                                          m_buf_packets, 
    662                                          m_max_packet_size, 
    663                                             m_Client->getChannel(), 
    664                                             RAW1394_DMA_BUFFERFILL, 
    665                                          m_irq_interval)) { 
    666                debugFatal("Could not do receive initialisation!\n" ); 
    667                debugFatal("  %s\n",strerror(errno)); 
    668  
    669                return false; 
    670        
    671        return true; 
     661                             m_buf_packets, 
     662                             m_max_packet_size, 
     663                             m_Client->getChannel(), 
     664                             RAW1394_DMA_BUFFERFILL, 
     665                             m_irq_interval)) { 
     666        debugFatal("Could not do receive initialisation!\n" ); 
     667        debugFatal("  %s\n",strerror(errno)); 
     668 
     669        return false; 
     670   
     671    return true; 
    672672} 
    673673 
    674674bool IsoRecvHandler::start(int cycle) 
    675675{ 
    676        debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); 
    677          
    678        if(raw1394_iso_recv_start(m_handle, cycle, -1, 0)) { 
    679                debugFatal("Could not start receive handler (%s)\n",strerror(errno)); 
    680                return false; 
    681        
    682        return true; 
     676    debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); 
     677     
     678    if(raw1394_iso_recv_start(m_handle, cycle, -1, 0)) { 
     679        debugFatal("Could not start receive handler (%s)\n",strerror(errno)); 
     680        return false; 
     681   
     682    return true; 
    683683} 
    684684 
    685685int IsoRecvHandler::handleBusReset(unsigned int generation) { 
    686        debugOutput( DEBUG_LEVEL_VERBOSE, "handle bus reset...\n"); 
    687          
    688        //TODO: implement busreset 
    689          
    690        // pass on the busreset signal 
    691        if(IsoHandler::handleBusReset(generation)) { 
    692                return -1; 
    693        
    694        return 0; 
     686    debugOutput( DEBUG_LEVEL_VERBOSE, "handle bus reset...\n"); 
     687     
     688    //TODO: implement busreset 
     689     
     690    // pass on the busreset signal 
     691    if(IsoHandler::handleBusReset(generation)) { 
     692        return -1; 
     693   
     694    return 0; 
    695695} 
    696696 
     
    698698 
    699699IsoXmitHandler::IsoXmitHandler(int port) 
    700                : IsoHandler(port), m_prebuffers(0) 
    701 { 
    702        debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
     700                : IsoHandler(port), m_prebuffers(0) 
     701{ 
     702    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
    703703 
    704704} 
    705705IsoXmitHandler::IsoXmitHandler(int port, unsigned int buf_packets,  
    706706                               unsigned int max_packet_size, int irq) 
    707                : IsoHandler(port, buf_packets, max_packet_size,irq), 
    708                  m_speed(RAW1394_ISO_SPEED_400), m_prebuffers(0) 
    709 { 
    710        debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
     707                : IsoHandler(port, buf_packets, max_packet_size,irq), 
     708                  m_speed(RAW1394_ISO_SPEED_400), m_prebuffers(0) 
     709{ 
     710    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
    711711 
    712712} 
     
    714714                               unsigned int max_packet_size, int irq, 
    715715                               enum raw1394_iso_speed speed) 
    716                : IsoHandler(port, buf_packets,max_packet_size,irq), 
    717                  m_speed(speed), m_prebuffers(0) 
    718 { 
    719        debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
     716                : IsoHandler(port, buf_packets,max_packet_size,irq), 
     717                  m_speed(speed), m_prebuffers(0) 
     718{ 
     719    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
    720720 
    721721} 
     
    735735IsoXmitHandler::init() { 
    736736 
    737        debugOutput( DEBUG_LEVEL_VERBOSE, "init xmit handler %p\n",this); 
    738  
    739        if(!(IsoHandler::init())) { 
    740                return false; 
    741        
    742  
    743        return true; 
     737    debugOutput( DEBUG_LEVEL_VERBOSE, "init xmit handler %p\n",this); 
     738 
     739    if(!(IsoHandler::init())) { 
     740        return false; 
     741   
     742 
     743    return true; 
    744744 
    745745} 
     
    764764bool IsoXmitHandler::prepare() 
    765765{ 
    766        debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso transmit handler (%p, client=%p)\n",this,m_Client); 
    767          
     766    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso transmit handler (%p, client=%p)\n",this,m_Client); 
     767 
    768768//      raw1394_iso_shutdown(m_handle); 
    769        debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers         : %d \n",m_buf_packets); 
    770        debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n",m_max_packet_size); 
    771        debugOutput( DEBUG_LEVEL_VERBOSE, " Channel         : %d \n",m_Client->getChannel()); 
    772        debugOutput( DEBUG_LEVEL_VERBOSE, " Speed           : %d \n",m_speed); 
    773        debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval    : %d \n",m_irq_interval); 
    774  
    775        if(raw1394_iso_xmit_init(m_handle, 
     769    debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers         : %d \n",m_buf_packets); 
     770    debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n",m_max_packet_size); 
     771    debugOutput( DEBUG_LEVEL_VERBOSE, " Channel         : %d \n",m_Client->getChannel()); 
     772    debugOutput( DEBUG_LEVEL_VERBOSE, " Speed           : %d \n",m_speed); 
     773    debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval    : %d \n",m_irq_interval); 
     774 
     775    if(raw1394_iso_xmit_init(m_handle, 
    776776                             iso_transmit_handler, 
    777777                             m_buf_packets, 
    778778                             m_max_packet_size, 
    779                                 m_Client->getChannel(), 
    780                                 m_speed, 
     779                             m_Client->getChannel(), 
     780                             m_speed, 
    781781                             m_irq_interval)) { 
    782                debugFatal("Could not do xmit initialisation!\n" ); 
    783  
    784                return false; 
    785        
    786  
    787        return true; 
     782        debugFatal("Could not do xmit initialisation!\n" ); 
     783 
     784        return false; 
     785   
     786 
     787    return true; 
    788788} 
    789789 
    790790bool IsoXmitHandler::start(int cycle) 
    791791{ 
    792        debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); 
    793        if(raw1394_iso_xmit_start(m_handle, cycle, m_prebuffers)) { 
    794                debugFatal("Could not start xmit handler (%s)\n",strerror(errno)); 
    795                return false; 
    796        
    797        return true; 
     792    debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); 
     793    if(raw1394_iso_xmit_start(m_handle, cycle, m_prebuffers)) { 
     794        debugFatal("Could not start xmit handler (%s)\n",strerror(errno)); 
     795        return false; 
     796   
     797    return true; 
    798798} 
    799799 
    800800int IsoXmitHandler::handleBusReset(unsigned int generation) { 
    801        debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); 
    802        //TODO: implement busreset 
    803          
    804        // pass on the busreset signal 
    805        if(IsoHandler::handleBusReset(generation)) { 
    806                return -1; 
    807        
    808          
    809        return 0; 
     801    debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); 
     802    //TODO: implement busreset 
     803     
     804    // pass on the busreset signal 
     805    if(IsoHandler::handleBusReset(generation)) { 
     806            return -1; 
     807   
     808     
     809    return 0; 
    810810} 
    811811 
  • branches/streaming-rework/src/libstreaming/IsoHandler.h

    r360 r383  
    5252class IsoHandler : public FreebobUtil::TimeSource 
    5353{ 
    54         protected: 
     54    protected: 
     55     
     56    public: 
    5557         
    56         public: 
    57          
    58                 enum EHandlerType { 
    59                         EHT_Receive, 
    60                         EHT_Transmit 
    61                 }; 
    62          
    63                 IsoHandler(int port); 
    64  
    65                 IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
    66  
    67                 virtual ~IsoHandler(); 
    68  
    69                 virtual bool init(); 
    70                  
    71                 int iterate() { if(m_handle) return raw1394_loop_iterate(m_handle); else return -1; }; 
    72                  
    73                 void setVerboseLevel(int l); 
    74  
    75                 // no setter functions, because those would require a re-init 
    76                 unsigned int getMaxPacketSize() { return m_max_packet_size;}; 
    77                 unsigned int getBuffersize() { return m_buf_packets;}; 
    78                 int getWakeupInterval() { return m_irq_interval;}; 
    79  
    80                 int getPacketCount() {return m_packetcount;}; 
    81                 void resetPacketCount() {m_packetcount=0;}; 
    82  
    83                 int getDroppedCount() {return m_dropped;}; 
    84                 void resetDroppedCount() {m_dropped=0;}; 
    85  
    86                 virtual enum EHandlerType getType() = 0; 
     58        enum EHandlerType { 
     59                EHT_Receive, 
     60                EHT_Transmit 
     61        }; 
     62 
     63        IsoHandler(int port); 
     64 
     65        IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
     66 
     67        virtual ~IsoHandler(); 
     68 
     69        virtual bool init(); 
     70         
     71        int iterate() { if(m_handle) return raw1394_loop_iterate(m_handle); else return -1; }; 
     72         
     73        void setVerboseLevel(int l); 
     74 
     75        // no setter functions, because those would require a re-init 
     76        unsigned int getMaxPacketSize() { return m_max_packet_size;}; 
     77        unsigned int getBuffersize() { return m_buf_packets;}; 
     78        int getWakeupInterval() { return m_irq_interval;}; 
     79 
     80        int getPacketCount() {return m_packetcount;}; 
     81        void resetPacketCount() {m_packetcount=0;}; 
     82 
     83        int getDroppedCount() {return m_dropped;}; 
     84        void resetDroppedCount() {m_dropped=0;}; 
     85 
     86        virtual enum EHandlerType getType() = 0; 
    8787 
    8888                virtual bool start(int cycle) = 0; 
    8989                virtual bool stop(); 
    9090                 
    91                int getFileDescriptor() { return raw1394_get_fd(m_handle);}; 
    92  
    93                void dumpInfo(); 
    94  
    95                bool inUse() {return (m_Client != 0) ;}; 
    96                virtual bool isStreamRegistered(IsoStream *s) {return (m_Client == s);}; 
    97  
    98                virtual bool registerStream(IsoStream *); 
    99                virtual bool unregisterStream(IsoStream *); 
    100  
    101                int getLocalNodeId() {return raw1394_get_local_id( m_handle );}; 
    102                int getPort() {return m_port;}; 
     91        int getFileDescriptor() { return raw1394_get_fd(m_handle);}; 
     92 
     93        void dumpInfo(); 
     94 
     95        bool inUse() {return (m_Client != 0) ;}; 
     96        virtual bool isStreamRegistered(IsoStream *s) {return (m_Client == s);}; 
     97 
     98        virtual bool registerStream(IsoStream *); 
     99        virtual bool unregisterStream(IsoStream *); 
     100 
     101        int getLocalNodeId() {return raw1394_get_local_id( m_handle );}; 
     102        int getPort() {return m_port;}; 
    103103 
    104104                virtual bool prepare() = 0; 
     
    117117        bool setSyncMaster(FreebobUtil::TimeSource *t); 
    118118     
    119        protected: 
    120            raw1394handle_t m_handle; 
     119    protected: 
     120        raw1394handle_t m_handle; 
    121121        raw1394handle_t m_handle_util; 
    122                int             m_port; 
    123                unsigned int    m_buf_packets; 
    124                unsigned int    m_max_packet_size; 
    125                int             m_irq_interval; 
    126                  
     122        int             m_port; 
     123        unsigned int    m_buf_packets; 
     124        unsigned int    m_max_packet_size; 
     125        int             m_irq_interval; 
     126         
    127127                unsigned int        m_cyclecounter_ticks; 
    128128        freebob_microsecs_t m_lastmeas_usecs; 
     
    130130        float               m_ticks_per_usec_dll_err2; 
    131131         
    132                int m_packetcount; 
    133                int m_dropped; 
    134  
    135                IsoStream *m_Client; 
     132        int m_packetcount; 
     133        int m_dropped; 
     134 
     135        IsoStream *m_Client; 
    136136 
    137137        FreebobUtil::TimeSource *m_TimeSource; 
    138138 
    139                virtual int handleBusReset(unsigned int generation); 
    140  
    141  
    142                DECLARE_DEBUG_MODULE; 
    143  
    144        private: 
    145                static int busreset_handler(raw1394handle_t handle, unsigned int generation); 
     139        virtual int handleBusReset(unsigned int generation); 
     140 
     141 
     142        DECLARE_DEBUG_MODULE; 
     143 
     144    private: 
     145        static int busreset_handler(raw1394handle_t handle, unsigned int generation); 
    146146 
    147147        void initCycleCounter(); 
     
    165165{ 
    166166 
    167        public: 
    168                IsoRecvHandler(int port); 
    169                IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
    170                virtual ~IsoRecvHandler(); 
    171  
    172                bool init(); 
    173          
    174                enum EHandlerType getType() { return EHT_Receive;}; 
     167    public: 
     168        IsoRecvHandler(int port); 
     169        IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
     170        virtual ~IsoRecvHandler(); 
     171 
     172        bool init(); 
     173     
     174        enum EHandlerType getType() { return EHT_Receive;}; 
    175175 
    176176//              int registerStream(IsoStream *); 
    177177//              int unregisterStream(IsoStream *); 
    178178 
    179                bool start(int cycle); 
    180  
    181                bool prepare(); 
    182  
    183        protected: 
    184                int handleBusReset(unsigned int generation); 
    185  
    186        private: 
    187                static enum raw1394_iso_disposition  
    188                iso_receive_handler(raw1394handle_t handle, unsigned char *data,  
    189                                                unsigned int length, unsigned char channel, 
    190                                                unsigned char tag, unsigned char sy, unsigned int cycle,  
    191                                                unsigned int dropped); 
    192  
    193                enum raw1394_iso_disposition   
    194                        putPacket(unsigned char *data, unsigned int length,  
    195                              unsigned char channel, unsigned char tag, unsigned char sy,  
    196                                  unsigned int cycle, unsigned int dropped); 
     179        bool start(int cycle); 
     180 
     181        bool prepare(); 
     182 
     183    protected: 
     184        int handleBusReset(unsigned int generation); 
     185 
     186    private: 
     187        static enum raw1394_iso_disposition  
     188        iso_receive_handler(raw1394handle_t handle, unsigned char *data,  
     189                            unsigned int length, unsigned char channel, 
     190                            unsigned char tag, unsigned char sy, unsigned int cycle,  
     191                            unsigned int dropped); 
     192 
     193        enum raw1394_iso_disposition   
     194                putPacket(unsigned char *data, unsigned int length,  
     195                          unsigned char channel, unsigned char tag, unsigned char sy,  
     196                          unsigned int cycle, unsigned int dropped); 
    197197 
    198198}; 
     
    204204class IsoXmitHandler  : public IsoHandler  
    205205{ 
    206        public: 
    207                IsoXmitHandler(int port); 
    208                IsoXmitHandler(int port, unsigned int buf_packets,  
    209                               unsigned int max_packet_size, int irq); 
    210                IsoXmitHandler(int port, unsigned int buf_packets,  
    211                               unsigned int max_packet_size, int irq,  
    212                               enum raw1394_iso_speed speed); 
    213                virtual ~IsoXmitHandler(); 
    214  
    215                bool init(); 
    216                  
    217                enum EHandlerType getType() { return EHT_Transmit;}; 
     206    public: 
     207        IsoXmitHandler(int port); 
     208        IsoXmitHandler(int port, unsigned int buf_packets,  
     209                        unsigned int max_packet_size, int irq); 
     210        IsoXmitHandler(int port, unsigned int buf_packets,  
     211                        unsigned int max_packet_size, int irq,  
     212                        enum raw1394_iso_speed speed); 
     213        virtual ~IsoXmitHandler(); 
     214 
     215        bool init(); 
     216         
     217        enum EHandlerType getType() { return EHT_Transmit;}; 
    218218 
    219219//              int registerStream(IsoStream *); 
    220220//              int unregisterStream(IsoStream *); 
    221221 
    222                unsigned int getPreBuffers() {return m_prebuffers;}; 
    223                void setPreBuffers(unsigned int n) {m_prebuffers=n;}; 
    224  
    225                bool start(int cycle); 
    226  
    227                bool prepare(); 
    228  
    229     protected: 
    230        int handleBusReset(unsigned int generation); 
    231  
    232        private: 
    233                static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle, 
    234                                unsigned char *data, unsigned int *length, 
    235                                unsigned char *tag, unsigned char *sy, 
    236                                int cycle, unsigned int dropped); 
    237                enum raw1394_iso_disposition   
    238                        getPacket(unsigned char *data, unsigned int *length, 
    239                              unsigned char *tag, unsigned char *sy, 
    240                              int cycle, unsigned int dropped); 
    241  
    242                enum raw1394_iso_speed m_speed; 
    243                  
    244                unsigned int m_prebuffers; 
     222        unsigned int getPreBuffers() {return m_prebuffers;}; 
     223        void setPreBuffers(unsigned int n) {m_prebuffers=n;}; 
     224 
     225        bool start(int cycle); 
     226 
     227        bool prepare(); 
     228 
     229    protected: 
     230        int handleBusReset(unsigned int generation); 
     231 
     232    private: 
     233        static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle, 
     234                        unsigned char *data, unsigned int *length, 
     235                        unsigned char *tag, unsigned char *sy, 
     236                        int cycle, unsigned int dropped); 
     237        enum raw1394_iso_disposition   
     238                getPacket(unsigned char *data, unsigned int *length, 
     239                        unsigned char *tag, unsigned char *sy, 
     240                        int cycle, unsigned int dropped); 
     241 
     242        enum raw1394_iso_speed m_speed; 
     243         
     244        unsigned int m_prebuffers; 
    245245 
    246246}; 
  • branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp

    r360 r383  
    106106// updates the internal cycle counter caches of the handlers 
    107107void IsoHandlerManager::updateCycleCounters() { 
    108        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 
    109          
     108    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 
     109     
    110110    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    111111          it != m_IsoHandlers.end(); 
     
    140140bool IsoHandlerManager::registerHandler(IsoHandler *handler) 
    141141{ 
    142        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    143        assert(handler); 
    144          
    145        m_IsoHandlers.push_back(handler); 
    146          
    147        handler->setVerboseLevel(getDebugLevel()); 
    148  
    149        // rebuild the fd map for poll()'ing. 
    150        return rebuildFdMap();  
     142    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     143    assert(handler); 
     144     
     145    m_IsoHandlers.push_back(handler); 
     146     
     147    handler->setVerboseLevel(getDebugLevel()); 
     148 
     149    // rebuild the fd map for poll()'ing. 
     150    return rebuildFdMap();     
    151151 
    152152} 
     
    206206void IsoHandlerManager::disablePolling(IsoStream *stream) { 
    207207    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Disable polling on stream %p\n",stream); 
    208        int i=0; 
    209        for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    210          it != m_IsoHandlers.end(); 
    211          ++it ) 
    212        
    213           if ((*it)->isStreamRegistered(stream)) { 
    214               m_poll_fds[i].events = 0; 
    215               m_poll_fds[i].revents = 0; 
     208    int i=0; 
     209    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     210        it != m_IsoHandlers.end(); 
     211        ++it ) 
     212   
     213        if ((*it)->isStreamRegistered(stream)) { 
     214            m_poll_fds[i].events = 0; 
     215            m_poll_fds[i].revents = 0; 
    216216            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "polling disabled\n"); 
    217           } 
    218           i++; 
    219        
     217        } 
     218        i++; 
     219   
    220220 
    221221} 
     
    223223void IsoHandlerManager::enablePolling(IsoStream *stream) { 
    224224    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Enable polling on stream %p\n",stream); 
    225        int i=0; 
    226        for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    227          it != m_IsoHandlers.end(); 
    228          ++it ) 
    229        
    230           if ((*it)->isStreamRegistered(stream)) { 
    231               m_poll_fds[i].events = POLLIN; 
    232               m_poll_fds[i].revents = 0; 
     225    int i=0; 
     226    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     227        it != m_IsoHandlers.end(); 
     228        ++it ) 
     229   
     230        if ((*it)->isStreamRegistered(stream)) { 
     231            m_poll_fds[i].events = POLLIN; 
     232            m_poll_fds[i].revents = 0; 
    233233            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "polling enabled\n"); 
    234           } 
    235           i++; 
    236        
     234        } 
     235        i++; 
     236   
    237237} 
    238238 
     
    444444 
    445445void IsoHandlerManager::pruneHandlers() { 
    446        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    447        IsoHandlerVector toUnregister; 
    448  
    449        // find all handlers that are not in use 
     446    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     447    IsoHandlerVector toUnregister; 
     448 
     449    // find all handlers that are not in use 
    450450    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    451451          it != m_IsoHandlers.end(); 
    452452          ++it ) 
    453453    { 
    454                if(!((*it)->inUse())) { 
    455                        debugOutput( DEBUG_LEVEL_VERBOSE, " handler (%p) not in use\n",*it); 
    456                        toUnregister.push_back(*it); 
    457                
    458     } 
    459        // delete them 
     454        if(!((*it)->inUse())) { 
     455            debugOutput( DEBUG_LEVEL_VERBOSE, " handler (%p) not in use\n",*it); 
     456            toUnregister.push_back(*it); 
     457       
     458    } 
     459    // delete them 
    460460    for ( IsoHandlerVectorIterator it = toUnregister.begin(); 
    461461          it != toUnregister.end(); 
    462462          ++it ) 
    463463    { 
    464                unregisterHandler(*it); 
    465                debugOutput( DEBUG_LEVEL_VERBOSE, " deleting handler (%p)\n",*it); 
    466  
    467                // Now the handler's been unregistered it won't be reused 
    468                // again.  Therefore it really needs to be formally deleted 
    469                // to free up the raw1394 handle.  Otherwise things fall 
    470                // apart after several xrun recoveries as the system runs 
    471                // out of resources to support all the disused but still 
    472                // allocated raw1394 handles.  At least this is the current 
    473                // theory as to why we end up with "memory allocation" 
    474                // failures after several Xrun recoveries. 
    475                delete *it; 
     464        unregisterHandler(*it); 
     465        debugOutput( DEBUG_LEVEL_VERBOSE, " deleting handler (%p)\n",*it); 
     466 
     467        // Now the handler's been unregistered it won't be reused 
     468        // again.  Therefore it really needs to be formally deleted 
     469        // to free up the raw1394 handle.  Otherwise things fall 
     470        // apart after several xrun recoveries as the system runs 
     471        // out of resources to support all the disused but still 
     472        // allocated raw1394 handles.  At least this is the current 
     473        // theory as to why we end up with "memory allocation" 
     474        // failures after several Xrun recoveries. 
     475        delete *it; 
    476476    } 
    477477 
     
    479479 
    480480bool IsoHandlerManager::startHandlers() { 
    481        return startHandlers(-1); 
     481    return startHandlers(-1); 
    482482} 
    483483 
    484484bool IsoHandlerManager::startHandlers(int cycle) { 
    485        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    486  
    487        for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    488          it != m_IsoHandlers.end(); 
    489          ++it ) 
    490        
    491                debugOutput( DEBUG_LEVEL_VERBOSE, " starting handler (%p)\n",*it); 
    492                if(!(*it)->start(cycle)) { 
    493                        debugOutput( DEBUG_LEVEL_VERBOSE, " could not start handler (%p)\n",*it); 
    494                         return false; 
    495                
    496        
    497          
     485    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     486     
     487    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     488        it != m_IsoHandlers.end(); 
     489        ++it ) 
     490   
     491        debugOutput( DEBUG_LEVEL_VERBOSE, " starting handler (%p)\n",*it); 
     492        if(!(*it)->start(cycle)) { 
     493            debugOutput( DEBUG_LEVEL_VERBOSE, " could not start handler (%p)\n",*it); 
     494                        return false; 
     495       
     496   
     497     
    498498        return true; 
    499499} 
    500500 
    501501bool IsoHandlerManager::stopHandlers() { 
    502        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    503  
    504        for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    505          it != m_IsoHandlers.end(); 
    506          ++it ) 
    507        
    508                debugOutput( DEBUG_LEVEL_VERBOSE, " stopping handler (%p)\n",*it); 
    509                if(!(*it)->stop()){ 
    510                        debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it); 
    511                         return false; 
    512                
    513        
     502    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     503     
     504    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     505        it != m_IsoHandlers.end(); 
     506        ++it ) 
     507   
     508        debugOutput( DEBUG_LEVEL_VERBOSE, " stopping handler (%p)\n",*it); 
     509        if(!(*it)->stop()){ 
     510            debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it); 
     511                        return false; 
     512       
     513   
    514514        return true; 
    515515} 
    516516 
    517517void IsoHandlerManager::setVerboseLevel(int i) { 
    518        setDebugLevel(i); 
     518    setDebugLevel(i); 
    519519 
    520520    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     
    522522          ++it ) 
    523523    { 
    524                (*it)->setVerboseLevel(i); 
     524        (*it)->setVerboseLevel(i); 
    525525    } 
    526526} 
     
    528528void IsoHandlerManager::dumpInfo() { 
    529529        debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping IsoHandlerManager Stream handler information...\n"); 
    530        int i=0; 
    531  
     530    int i=0; 
     531     
    532532    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    533533          it != m_IsoHandlers.end(); 
    534534          ++it ) 
    535535    { 
    536                debugOutputShort( DEBUG_LEVEL_NORMAL, " IsoHandler %d (%p)\n",i++,*it); 
    537  
    538                (*it)->dumpInfo(); 
     536        debugOutputShort( DEBUG_LEVEL_NORMAL, " IsoHandler %d (%p)\n",i++,*it); 
     537 
     538        (*it)->dumpInfo(); 
    539539    } 
    540540 
  • branches/streaming-rework/src/libstreaming/IsoHandlerManager.h

    r360 r383  
    6868class IsoHandlerManager : public FreebobUtil::RunnableInterface 
    6969{ 
    70        friend class StreamProcessorManager; 
     70    friend class StreamProcessorManager; 
    7171 
    7272    public: 
     
    7575        virtual ~IsoHandlerManager(); 
    7676 
    77                void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll() 
    78                int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll() 
     77        void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll() 
     78        int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll() 
    7979 
    80                void setVerboseLevel(int l); ///< set the verbose level 
     80        void setVerboseLevel(int l); ///< set the verbose level 
    8181 
    82                void dumpInfo(); ///< print some information about the manager to stdout/stderr 
     82        void dumpInfo(); ///< print some information about the manager to stdout/stderr 
    8383 
    84                bool registerStream(IsoStream *); ///< register an iso stream with the manager 
    85                bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager 
     84        bool registerStream(IsoStream *); ///< register an iso stream with the manager 
     85        bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager 
    8686 
    87                bool startHandlers(); ///< start the managed ISO handlers  
    88                bool startHandlers(int cycle); ///< start the managed ISO handlers  
    89                bool stopHandlers(); ///< stop the managed ISO handlers  
     87        bool startHandlers(); ///< start the managed ISO handlers  
     88        bool startHandlers(int cycle); ///< start the managed ISO handlers  
     89        bool stopHandlers(); ///< stop the managed ISO handlers  
    9090 
    9191                bool reset() {return true;}; ///< reset the ISO manager and all streams 
    9292 
    93                bool prepare(); ///< prepare the ISO manager and all streams 
    94                  
    95                void disablePolling(IsoStream *); ///< disables polling on a stream 
    96                void enablePolling(IsoStream *); ///< enables polling on a stream 
     93        bool prepare(); ///< prepare the ISO manager and all streams 
     94         
     95        void disablePolling(IsoStream *); ///< disables polling on a stream 
     96        void enablePolling(IsoStream *); ///< enables polling on a stream 
    9797 
    9898        public: 
    9999         
    100100             
    101                // RunnableInterface interface 
    102                bool Execute(); // note that this is called in we while(running) loop 
    103                bool Init(); 
    104  
     101    // RunnableInterface interface 
     102        bool Execute(); // note that this is called in we while(running) loop 
     103        bool Init(); 
     104         
    105105            // iterate all handlers 
    106106            bool iterate(); 
     
    109109        void updateCycleCounters(); 
    110110         
    111                // note: there is a disctinction between streams and handlers 
    112                // because one handler can serve multiple streams (in case of  
    113                // multichannel receive) 
     111        // note: there is a disctinction between streams and handlers 
     112        // because one handler can serve multiple streams (in case of  
     113        // multichannel receive) 
    114114 
    115                // only streams are allowed to be registered externally. 
    116                // we allocate a handler if we need one, otherwise the stream 
    117                // is assigned to another handler 
     115        // only streams are allowed to be registered externally. 
     116        // we allocate a handler if we need one, otherwise the stream 
     117        // is assigned to another handler 
    118118 
    119                // the collection of handlers 
    120                IsoHandlerVector m_IsoHandlers; 
     119        // the collection of handlers 
     120        IsoHandlerVector m_IsoHandlers; 
    121121 
    122                bool registerHandler(IsoHandler *); 
    123                bool unregisterHandler(IsoHandler *); 
    124                void pruneHandlers(); 
     122        bool registerHandler(IsoHandler *); 
     123        bool unregisterHandler(IsoHandler *); 
     124        void pruneHandlers(); 
    125125 
    126                // the collection of streams 
    127                IsoStreamVector m_IsoStreams; 
     126        // the collection of streams 
     127        IsoStreamVector m_IsoStreams; 
    128128 
    129                // poll stuff 
    130                int m_poll_timeout; 
    131                struct pollfd *m_poll_fds; 
    132                int m_poll_nfds; 
     129        // poll stuff 
     130        int m_poll_timeout; 
     131        struct pollfd *m_poll_fds; 
     132        int m_poll_nfds; 
    133133 
    134                bool rebuildFdMap(); 
     134        bool rebuildFdMap(); 
    135135 
    136136 
    137            DECLARE_DEBUG_MODULE; 
     137        DECLARE_DEBUG_MODULE; 
    138138 
    139139}; 
  • branches/streaming-rework/src/libstreaming/IsoStream.cpp

    r244 r383  
    3939enum raw1394_iso_disposition  
    4040IsoStream::putPacket(unsigned char *data, unsigned int length,  
    41                              unsigned char channel, unsigned char tag, unsigned char sy,  
    42                                  unsigned int cycle, unsigned int dropped) { 
     41                     unsigned char channel, unsigned char tag, unsigned char sy,  
     42                     unsigned int cycle, unsigned int dropped) { 
    4343 
    44        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
    45                     "received packet: length=%d, channel=%d, cycle=%d\n", 
    46                     length, channel, cycle ); 
     44    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
     45                 "received packet: length=%d, channel=%d, cycle=%d\n", 
     46                 length, channel, cycle ); 
    4747 
    48        return RAW1394_ISO_OK; 
     48    return RAW1394_ISO_OK; 
    4949} 
    5050 
    5151enum raw1394_iso_disposition  
    5252IsoStream::getPacket(unsigned char *data, unsigned int *length, 
    53                              unsigned char *tag, unsigned char *sy, 
    54                              int cycle, unsigned int dropped, unsigned int max_length) { 
    55        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
    56                     "sending packet: length=%d, cycle=%d\n", 
    57                     *length, cycle ); 
     53                     unsigned char *tag, unsigned char *sy, 
     54                     int cycle, unsigned int dropped, unsigned int max_length) { 
     55    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
     56                 "sending packet: length=%d, cycle=%d\n", 
     57                 *length, cycle ); 
    5858 
    59        memcpy(data,&cycle,sizeof(cycle)); 
    60        *length=sizeof(cycle); 
    61        *tag = 1; 
    62        *sy = 0; 
     59    memcpy(data,&cycle,sizeof(cycle)); 
     60    *length=sizeof(cycle); 
     61    *tag = 1; 
     62    *sy = 0; 
    6363 
    6464 
    65        return RAW1394_ISO_OK; 
     65    return RAW1394_ISO_OK; 
    6666} 
    6767 
    6868int IsoStream::getNodeId() { 
    69        if (m_handler) { 
    70                return m_handler->getLocalNodeId(); 
    71        
    72        return -1; 
     69    if (m_handler) { 
     70        return m_handler->getLocalNodeId(); 
     71   
     72    return -1; 
    7373} 
    7474 
     
    7777{ 
    7878 
    79        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Address        : %p\n",this); 
    80        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Stream type    : %s\n", 
    81             (this->getType()==EST_Receive ? "Receive" : "Transmit")); 
    82        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %d, %d\n", 
    83             m_port, m_channel); 
     79    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Address        : %p\n",this); 
     80    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Stream type    : %s\n", 
     81            (this->getType()==EST_Receive ? "Receive" : "Transmit")); 
     82    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %d, %d\n", 
     83            m_port, m_channel); 
    8484 
    8585}; 
    8686 
    8787bool IsoStream::setChannel(int c) { 
    88        debugOutput( DEBUG_LEVEL_VERBOSE, "setting channel to %d\n",c); 
     88    debugOutput( DEBUG_LEVEL_VERBOSE, "setting channel to %d\n",c); 
    8989 
    90        m_channel=c; 
    91        return true; 
     90    m_channel=c; 
     91    return true; 
    9292} 
    9393 
    9494 
    9595bool IsoStream::reset() { 
    96        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    97        return true; 
     96    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     97    return true; 
    9898} 
    9999 
    100100bool IsoStream::prepare() { 
    101        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    102        return true; 
     101    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     102    return true; 
    103103} 
    104104 
    105105bool IsoStream::init() { 
    106        debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    107        return true; 
     106    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     107    return true; 
    108108 
    109109} 
    110110 
    111111void IsoStream::setHandler(IsoHandler *h) { 
    112        debugOutput( DEBUG_LEVEL_VERBOSE, "setting handler of isostream %p to %p\n", this,h); 
    113        m_handler=h; 
     112    debugOutput( DEBUG_LEVEL_VERBOSE, "setting handler of isostream %p to %p\n", this,h); 
     113    m_handler=h; 
    114114} 
    115115 
    116116void IsoStream::clearHandler() { 
    117        debugOutput( DEBUG_LEVEL_VERBOSE, "clearing handler of isostream %p\n", this); 
     117    debugOutput( DEBUG_LEVEL_VERBOSE, "clearing handler of isostream %p\n", this); 
    118118 
    119119    m_handler=0; 
  • branches/streaming-rework/src/libstreaming/IsoStream.h

    r244 r383  
    4444class IsoStream 
    4545{ 
    46        friend class IsoHandler; 
    47        friend class IsoRecvHandler; 
    48        friend class IsoXmitHandler; 
     46    friend class IsoHandler; 
     47    friend class IsoRecvHandler; 
     48    friend class IsoXmitHandler; 
    4949 
    5050    public: 
    5151 
    52                enum EStreamType { 
    53                        EST_Receive, 
    54                        EST_Transmit 
    55                }; 
     52        enum EStreamType { 
     53                EST_Receive, 
     54                EST_Transmit 
     55        }; 
    5656 
    5757        IsoStream(enum EStreamType type)  
    58                   : m_type(type), m_channel(-1), m_port(0), m_handler(0) 
     58                    : m_type(type), m_channel(-1), m_port(0), m_handler(0) 
    5959        {}; 
    6060        IsoStream(enum EStreamType type, int port)  
    61                   : m_type(type), m_channel(-1), m_port(port), m_handler(0) 
     61                    : m_type(type), m_channel(-1), m_port(port), m_handler(0) 
    6262        {}; 
    6363        virtual ~IsoStream() 
    6464        {}; 
     65     
     66        virtual void setVerboseLevel(int l) { setDebugLevel( l ); }; 
    6567 
    66                 virtual void setVerboseLevel(int l) { setDebugLevel( l ); }; 
     68        int getChannel() {return m_channel;}; 
     69        bool setChannel(int c); 
    6770 
    68                 int getChannel() {return m_channel;}; 
    69                 bool setChannel(int c); 
     71        int getPort() {return m_port;}; 
    7072 
    71                int getPort() {return m_port;}; 
     73        enum EStreamType getType() { return m_type;}; 
    7274 
    73                 enum EStreamType getType() { return m_type;}; 
     75        virtual unsigned int getPacketsPerPeriod() {return 1;}; 
     76        virtual unsigned int getMaxPacketSize() {return 1024;}; //FIXME: arbitrary 
     77         
     78        virtual bool init(); 
    7479 
    75                 virtual unsigned int getPacketsPerPeriod() {return 1;}; 
    76                 virtual unsigned int getMaxPacketSize() {return 1024;}; //FIXME: arbitrary 
    77                  
    78                 virtual bool init(); 
     80        virtual enum raw1394_iso_disposition  
     81                putPacket(unsigned char *data, unsigned int length,  
     82                        unsigned char channel, unsigned char tag, unsigned char sy,  
     83                            unsigned int cycle, unsigned int dropped); 
     84        virtual enum raw1394_iso_disposition  
     85                getPacket(unsigned char *data, unsigned int *length, 
     86                        unsigned char *tag, unsigned char *sy, 
     87                        int cycle, unsigned int dropped, unsigned int max_length); 
    7988 
    80                 virtual enum raw1394_iso_disposition  
    81                         putPacket(unsigned char *data, unsigned int length,  
    82                               unsigned char channel, unsigned char tag, unsigned char sy,  
    83                                   unsigned int cycle, unsigned int dropped); 
    84                 virtual enum raw1394_iso_disposition  
    85                         getPacket(unsigned char *data, unsigned int *length, 
    86                               unsigned char *tag, unsigned char *sy, 
    87                               int cycle, unsigned int dropped, unsigned int max_length); 
     89        void dumpInfo(); 
    8890 
    89                 void dumpInfo(); 
     91        int getNodeId(); 
     92         
     93        virtual bool reset(); 
     94        virtual bool prepare();  
     95     
     96    protected: 
    9097 
    91                 int getNodeId(); 
    92                  
    93                 virtual bool reset(); 
    94                 virtual bool prepare();  
    95      
    96         protected: 
     98        void setHandler( IsoHandler * h) ; 
     99        void clearHandler(); 
    97100 
    98                 void setHandler( IsoHandler * h) ; 
    99                 void clearHandler(); 
     101        enum EStreamType m_type; 
     102        int m_channel; 
     103        int m_port; 
    100104 
    101                 enum EStreamType m_type; 
    102                 int m_channel; 
    103                 int m_port; 
     105        IsoHandler *m_handler; 
    104106 
    105                 IsoHandler *m_handler; 
    106  
    107                 DECLARE_DEBUG_MODULE; 
     107        DECLARE_DEBUG_MODULE; 
    108108 
    109109}; 
  • branches/streaming-rework/src/libstreaming/MotuStreamProcessor.cpp

    r333 r383  
    2727 * 
    2828 */ 
    29  
     29  
    3030 
    3131#include "MotuStreamProcessor.h" 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.cpp

    r265 r383  
    6060{ 
    6161 
    62        debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor information\n"); 
    63        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Iso stream info:\n"); 
    64          
    65        IsoStream::dumpInfo(); 
    66        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Frame counter  : %d\n", m_framecounter); 
    67        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Xruns          : %d\n", m_xruns); 
    68        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Running        : %d\n", m_running); 
    69        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Enabled        : %d\n", !m_disabled); 
    70          
     62    debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor information\n"); 
     63    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Iso stream info:\n"); 
     64     
     65    IsoStream::dumpInfo(); 
     66    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Frame counter  : %d\n", m_framecounter); 
     67    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Xruns          : %d\n", m_xruns); 
     68    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Running        : %d\n", m_running); 
     69    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Enabled        : %d\n", !m_disabled); 
     70     
    7171    m_PeriodStat.dumpInfo(); 
    7272    m_PacketStat.dumpInfo(); 
     
    7878bool StreamProcessor::init() 
    7979{ 
    80        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 
    81  
    82        return IsoStream::init(); 
     80    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 
     81     
     82    return IsoStream::init(); 
    8383} 
    8484 
     
    8989bool StreamProcessor::reset() { 
    9090 
    91        debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n"); 
    92  
    93        resetFrameCounter(); 
    94  
    95        resetXrunCounter(); 
    96  
    97        // loop over the ports to reset them 
    98        if (!PortManager::resetPorts()) { 
    99                debugFatal("Could not reset ports\n"); 
    100                return false; 
    101        
    102  
    103        // reset the iso stream 
    104        if (!IsoStream::reset()) { 
    105                debugFatal("Could not reset isostream\n"); 
    106                return false; 
    107        
    108        return true; 
     91    debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n"); 
     92 
     93    resetFrameCounter(); 
     94 
     95    resetXrunCounter(); 
     96 
     97    // loop over the ports to reset them 
     98    if (!PortManager::resetPorts()) { 
     99        debugFatal("Could not reset ports\n"); 
     100        return false; 
     101   
     102 
     103    // reset the iso stream 
     104    if (!IsoStream::reset()) { 
     105        debugFatal("Could not reset isostream\n"); 
     106        return false; 
     107   
     108    return true; 
    109109         
    110110} 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.h

    r312 r383  
    5050                        public PortManager { 
    5151 
    52        friend class StreamProcessorManager; 
     52    friend class StreamProcessorManager; 
    5353 
    5454public: 
    55        enum EProcessorType { 
    56                E_Receive, 
    57                E_Transmit 
    58        }; 
    59  
    60        StreamProcessor(enum IsoStream::EStreamType type, int port, int framerate); 
    61        virtual ~StreamProcessor(); 
    62  
    63        virtual enum raw1394_iso_disposition  
    64                putPacket(unsigned char *data, unsigned int length,  
    65                      unsigned char channel, unsigned char tag, unsigned char sy,  
    66                          unsigned int cycle, unsigned int dropped) = 0; 
    67        virtual enum raw1394_iso_disposition  
    68                getPacket(unsigned char *data, unsigned int *length, 
    69                      unsigned char *tag, unsigned char *sy, 
    70                      int cycle, unsigned int dropped, unsigned int max_length) = 0; 
    71  
    72        virtual enum EProcessorType getType() =0; 
    73  
    74        bool xrunOccurred() { return (m_xruns>0);}; 
     55    enum EProcessorType { 
     56            E_Receive, 
     57            E_Transmit 
     58    }; 
     59 
     60    StreamProcessor(enum IsoStream::EStreamType type, int port, int framerate); 
     61    virtual ~StreamProcessor(); 
     62 
     63    virtual enum raw1394_iso_disposition  
     64            putPacket(unsigned char *data, unsigned int length,  
     65                    unsigned char channel, unsigned char tag, unsigned char sy,  
     66                        unsigned int cycle, unsigned int dropped) = 0; 
     67    virtual enum raw1394_iso_disposition  
     68            getPacket(unsigned char *data, unsigned int *length, 
     69                    unsigned char *tag, unsigned char *sy, 
     70                    int cycle, unsigned int dropped, unsigned int max_length) = 0; 
     71 
     72    virtual enum EProcessorType getType() =0; 
     73 
     74    bool xrunOccurred() { return (m_xruns>0);}; 
    7575 
    7676    /** 
     
    8484     * @return  
    8585     */ 
    86        virtual bool isOnePeriodReady()=0; 
    87          
    88        unsigned int getNbPeriodsReady() { if(m_period) return m_framecounter/m_period; else return 0;}; 
     86    virtual bool isOnePeriodReady()=0; 
     87     
     88    unsigned int getNbPeriodsReady() { if(m_period) return m_framecounter/m_period; else return 0;}; 
    8989        virtual void decrementFrameCounter(); 
    9090        virtual void incrementFrameCounter(int nbframes); 
    91          
    92        // move to private? 
     91     
     92    // move to private? 
    9393        void resetFrameCounter(); 
    9494    void resetXrunCounter(); 
    9595 
    96        bool isRunning(); ///< returns true if there is some stream data processed 
    97        void enable(); ///< enable the stream processing  
    98        void disable() {m_disabled=true;}; ///< disable the stream processing  
    99        bool isEnabled() {return !m_disabled;}; 
    100  
    101        virtual bool transfer(); ///< transfer the buffer contents from/to client 
    102  
    103        virtual bool reset(); ///< reset the streams & buffers (e.g. after xrun) 
    104  
    105        virtual bool prepare(); ///< prepare the streams & buffers (e.g. prefill) 
    106  
    107        virtual void dumpInfo(); 
    108  
    109        virtual bool init(); 
    110  
    111        virtual void setVerboseLevel(int l); 
    112  
    113        virtual bool preparedForStop() {return true;}; 
    114        virtual bool preparedForStart() {return true;}; 
     96    bool isRunning(); ///< returns true if there is some stream data processed 
     97    void enable(); ///< enable the stream processing  
     98    void disable() {m_disabled=true;}; ///< disable the stream processing  
     99    bool isEnabled() {return !m_disabled;}; 
     100 
     101    virtual bool transfer(); ///< transfer the buffer contents from/to client 
     102 
     103    virtual bool reset(); ///< reset the streams & buffers (e.g. after xrun) 
     104 
     105    virtual bool prepare(); ///< prepare the streams & buffers (e.g. prefill) 
     106 
     107    virtual void dumpInfo(); 
     108 
     109    virtual bool init(); 
     110 
     111    virtual void setVerboseLevel(int l); 
     112 
     113    virtual bool preparedForStop() {return true;}; 
     114    virtual bool preparedForStart() {return true;}; 
    115115 
    116116protected: 
    117117         
    118118 
    119        void setManager(StreamProcessorManager *manager) {m_manager=manager;}; 
    120        void clearManager() {m_manager=0;}; 
    121  
    122        unsigned int m_nb_buffers; ///< cached from manager->getNbBuffers(), the number of periods to buffer 
    123        unsigned int m_period; ///< cached from manager->getPeriod(), the period size 
    124  
    125        unsigned int m_xruns; 
     119    void setManager(StreamProcessorManager *manager) {m_manager=manager;}; 
     120    void clearManager() {m_manager=0;}; 
     121 
     122    unsigned int m_nb_buffers; ///< cached from manager->getNbBuffers(), the number of periods to buffer 
     123    unsigned int m_period; ///< cached from manager->getPeriod(), the period size 
     124 
     125    unsigned int m_xruns; 
    126126        signed int m_framecounter; 
    127127 
    128        unsigned int m_framerate; 
    129  
    130        StreamProcessorManager *m_manager; 
    131  
    132        bool m_running; 
    133        bool m_disabled; 
     128    unsigned int m_framerate; 
     129 
     130    StreamProcessorManager *m_manager; 
     131 
     132    bool m_running; 
     133    bool m_disabled; 
    134134 
    135135    StreamStatistics m_PacketStat; 
     
    140140 
    141141    DECLARE_DEBUG_MODULE; 
    142  
     142     
    143143 
    144144}; 
  • branches/streaming-rework/src/libstreaming/StreamProcessorManager.cpp

    r360 r383  
    195195bool StreamProcessorManager::Init() 
    196196{ 
    197        debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing runner...\n"); 
    198          
    199        // no xrun has occurred (yet) 
    200        m_xrun_happened=false; 
    201  
    202        if(sem_init(&m_period_semaphore, 0, 0)) { 
     197    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing runner...\n"); 
     198 
     199    // no xrun has occurred (yet) 
     200    m_xrun_happened=false; 
     201 
     202    if(sem_init(&m_period_semaphore, 0, 0)) { 
    203203                debugFatal( "Cannot init packet transfer semaphore\n"); 
    204                debugFatal( " Error: %s\n",strerror(errno)); 
    205                return false; 
     204        debugFatal( " Error: %s\n",strerror(errno)); 
     205        return false; 
    206206    } 
    207   
    208        return true; 
     207 
     208    return true; 
    209209} 
    210210 
     
    249249 
    250250        bool period_ready=true; 
    251     bool xrun_has_occured=false; 
     251        bool xrun_has_occured=false; 
    252252        bool this_period_ready; 
    253253 
     
    258258                return false; 
    259259        } 
    260        
     260       
    261261        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " RCV PROC: "); 
    262262        for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     
    381381        // start the runner thread 
    382382        m_isoManagerThread->Start(); 
    383                  
     383 
    384384        debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to start running...\n"); 
    385385        // we have to wait until all streamprocessors indicate that they are running 
     
    592592        if(!stop()) { 
    593593           debugFatal("Could not stop.\n"); 
    594            return false; 
     594               return false; 
    595595        } 
    596596 
     
    633633        if(!start()) { 
    634634           debugFatal("Could not start.\n"); 
    635            return false; 
     635               return false; 
    636636        } 
    637637 
  • branches/streaming-rework/src/libstreaming/StreamProcessorManager.h

    r341 r383  
    5858public: 
    5959 
    60        StreamProcessorManager(unsigned int period, unsigned int nb_buffers); 
    61        virtual ~StreamProcessorManager(); 
     60    StreamProcessorManager(unsigned int period, unsigned int nb_buffers); 
     61    virtual ~StreamProcessorManager(); 
    6262 
    63        bool init(); ///< to be called immediately after the construction 
    64        bool prepare(); ///< to be called after the processors are registered 
     63    bool init(); ///< to be called immediately after the construction 
     64    bool prepare(); ///< to be called after the processors are registered 
    6565 
    66        virtual void setVerboseLevel(int l); 
    67        void dumpInfo(); 
     66    virtual void setVerboseLevel(int l); 
     67    void dumpInfo(); 
    6868 
    69        // this is the setup API 
    70        bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor 
    71        bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor 
     69    // this is the setup API 
     70    bool registerProcessor(StreamProcessor *processor); ///< start managing a streamprocessor 
     71    bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor 
    7272 
    73        void setPeriodSize(unsigned int period); 
    74        void setPeriodSize(unsigned int period, unsigned int nb_buffers); 
    75        int getPeriodSize() {return m_period;}; 
     73    void setPeriodSize(unsigned int period); 
     74    void setPeriodSize(unsigned int period, unsigned int nb_buffers); 
     75    int getPeriodSize() {return m_period;}; 
    7676 
    77        void setNbBuffers(unsigned int nb_buffers); 
    78        int getNbBuffers() {return m_nb_buffers;}; 
     77    void setNbBuffers(unsigned int nb_buffers); 
     78    int getNbBuffers() {return m_nb_buffers;}; 
    7979 
    80        int getPortCount(enum Port::E_PortType, enum Port::E_Direction); 
    81        int getPortCount(enum Port::E_Direction); 
    82        Port* getPortByIndex(int idx, enum Port::E_Direction); 
     80    int getPortCount(enum Port::E_PortType, enum Port::E_Direction); 
     81    int getPortCount(enum Port::E_Direction); 
     82    Port* getPortByIndex(int idx, enum Port::E_Direction); 
    8383 
    84        // the client-side functions 
    85        bool xrunOccurred(); 
    86        int getXrunCount() {return m_xruns;}; 
     84    // the client-side functions 
     85    bool xrunOccurred(); 
     86    int getXrunCount() {return m_xruns;}; 
    8787 
    88        bool waitForPeriod(); ///< wait for the next period 
     88    bool waitForPeriod(); ///< wait for the next period 
    8989 
    90        bool transfer(); ///< transfer the buffer contents from/to client 
    91        bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type) 
     90    bool transfer(); ///< transfer the buffer contents from/to client 
     91    bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type) 
    9292 
    93        bool handleXrun(); ///< reset the streams & buffers after xrun 
     93    bool handleXrun(); ///< reset the streams & buffers after xrun 
    9494 
    95        bool start(); 
    96        bool stop(); 
     95    bool start(); 
     96    bool stop(); 
    9797 
    9898    bool setThreadParameters(bool rt, int priority); 
     
    100100        // the ISO-side functions 
    101101protected: 
    102        int signalWaiters(); // call this to signal a period boundary 
    103        // RunnableInterface interface 
    104        bool Execute(); // note that this is called in we while(running) loop 
    105        bool Init(); 
     102    int signalWaiters(); // call this to signal a period boundary 
     103    // RunnableInterface interface 
     104    bool Execute(); // note that this is called in we while(running) loop 
     105    bool Init(); 
    106106 
    107        // thread sync primitives 
    108        sem_t m_period_semaphore; 
     107    // thread sync primitives 
     108    sem_t m_period_semaphore; 
    109109 
    110        bool m_xrun_happened;  
     110    bool m_xrun_happened;  
    111111 
    112112    bool m_thread_realtime; 
    113113    int m_thread_priority; 
    114114 
    115        // processor list 
    116        StreamProcessorVector m_ReceiveProcessors; 
    117        StreamProcessorVector m_TransmitProcessors; 
     115    // processor list 
     116    StreamProcessorVector m_ReceiveProcessors; 
     117    StreamProcessorVector m_TransmitProcessors; 
    118118 
    119        unsigned int m_nb_buffers; 
    120        unsigned int m_period; 
    121        unsigned int m_xruns; 
    122          
    123        IsoHandlerManager *m_isoManager; 
     119    unsigned int m_nb_buffers; 
     120    unsigned int m_period; 
     121    unsigned int m_xruns; 
     122     
     123    IsoHandlerManager *m_isoManager; 
    124124 
    125        FreebobUtil::PosixThread *m_streamingThread; 
    126        FreebobUtil::PosixThread *m_isoManagerThread; 
     125    FreebobUtil::PosixThread *m_streamingThread; 
     126    FreebobUtil::PosixThread *m_isoManagerThread; 
    127127 
    128128    unsigned int m_nbperiods; 
  • branches/streaming-rework/src/libutil/TimeSource.h

    r360 r383  
    3939public: 
    4040 
    41        TimeSource(); 
    42        virtual ~TimeSource(); 
     41    TimeSource(); 
     42    virtual ~TimeSource(); 
    4343 
    4444    virtual freebob_microsecs_t getCurrentTime()=0; 
    4545    virtual freebob_microsecs_t getCurrentTimeAsUsecs()=0; 
    46  
     46     
    4747protected: 
    4848 
  • branches/streaming-rework/src/Makefile.am

    r365 r383  
    3636        rme/rme_avdevice.h 
    3737 
    38 libfreebob_la_SOURCES =                                
     38libfreebob_la_SOURCES =
    3939        iavdevice.h                                     \ 
    40        configrom.cpp                                   
    41        csr1212.c                                       
    42        devicemanager.cpp                               
    43        freebob.cpp                                     
    44        xmlparser.c                                     
     40        configrom.cpp
     41        csr1212.c
     42        devicemanager.cpp
     43        freebob.cpp
     44        xmlparser.c
    4545        threads.h                                       \ 
    4646        bebob/bebob_avdevice.h                          \ 
    47        bebob/bebob_avdevice.cpp                       
     47        bebob/bebob_avdevice.cpp
    4848        bebob/bebob_avdevice_xml.cpp                    \ 
    4949        bebob/bebob_avdevice_subunit.h                  \ 
    50        bebob/bebob_avdevice_subunit.cpp               
     50        bebob/bebob_avdevice_subunit.cpp
    5151        bebob/bebob_avplug.h                            \ 
    52        bebob/bebob_avplug.cpp                         
    53        bebob/bebob_avplug_xml.cpp                     
     52        bebob/bebob_avplug.cpp
     53        bebob/bebob_avplug_xml.cpp
    5454        bebob/bebob_functionblock.h                     \ 
    5555        bebob/bebob_functionblock.cpp                   \ 
     
    5959        bebob/bebob_dl_codes.cpp                        \ 
    6060        bebob/bebob_dl_bcd.h                            \ 
    61        bebob/bebob_dl_bcd.cpp                         
     61        bebob/bebob_dl_bcd.cpp
    6262        motu/motu_avdevice.cpp                          \ 
    6363        motu/motu_avdevice.h                            \ 
     
    6565        rme/rme_avdevice.h                              \ 
    6666        bounce/bounce_avdevice.h                        \ 
    67        bounce/bounce_avdevice.cpp                     
     67        bounce/bounce_avdevice.cpp
    6868        maudio/maudio_avdevice.h                        \ 
    69        maudio/maudio_avdevice.cpp                     
    70        libfreebobavc/avc_connect.cpp                   
    71        libfreebobavc/avc_definitions.cpp               
    72        libfreebobavc/avc_extended_cmd_generic.cpp     
    73        libfreebobavc/avc_extended_plug_info.cpp       
    74        libfreebobavc/avc_extended_stream_format.cpp   
    75        libfreebobavc/avc_extended_subunit_info.cpp     
    76        libfreebobavc/avc_function_block.cpp           
     69        maudio/maudio_avdevice.cpp
     70        libfreebobavc/avc_connect.cpp
     71        libfreebobavc/avc_definitions.cpp
     72        libfreebobavc/avc_extended_cmd_generic.cpp
     73        libfreebobavc/avc_extended_plug_info.cpp
     74        libfreebobavc/avc_extended_stream_format.cpp
     75        libfreebobavc/avc_extended_subunit_info.cpp
     76        libfreebobavc/avc_function_block.cpp
    7777        libfreebobavc/avc_function_block.h              \ 
    78        libfreebobavc/avc_generic.cpp                   
    79        libfreebobavc/avc_plug_info.cpp                 
    80        libfreebobavc/avc_signal_source.cpp             
    81        libfreebobavc/avc_subunit_info.cpp             
    82        libfreebobavc/avc_unit_info.cpp                 
    83        libfreebobavc/ieee1394service.cpp               
     78        libfreebobavc/avc_generic.cpp
     79        libfreebobavc/avc_plug_info.cpp
     80        libfreebobavc/avc_signal_source.cpp
     81        libfreebobavc/avc_subunit_info.cpp
     82        libfreebobavc/avc_unit_info.cpp
     83        libfreebobavc/ieee1394service.cpp
    8484        libfreebobavc/avc_serialize.cpp                 \ 
    8585        libfreebobavc/avc_connect.h                     \ 
     
    9898        debugmodule/debugmodule.h                       \ 
    9999        debugmodule/debugmodule.cpp                     \ 
    100        libstreaming/cip.c                             
     100        libstreaming/cip.c
    101101        libstreaming/cyclecounter.h                     \ 
    102        libstreaming/freebob_streaming.cpp             
    103        libstreaming/IsoHandler.cpp                     
    104        libstreaming/IsoHandlerManager.cpp             
    105        libstreaming/IsoStream.cpp                     
    106        libstreaming/PacketBuffer.cpp                   
     102        libstreaming/freebob_streaming.cpp
     103        libstreaming/IsoHandler.cpp
     104        libstreaming/IsoHandlerManager.cpp
     105        libstreaming/IsoStream.cpp
     106        libstreaming/PacketBuffer.cpp
    107107        libstreaming/PortManager.cpp                    \ 
    108        libstreaming/Port.cpp                           
    109        libstreaming/StreamProcessor.cpp               
    110        libstreaming/StreamProcessorManager.cpp         
     108        libstreaming/Port.cpp
     109        libstreaming/StreamProcessor.cpp
     110        libstreaming/StreamProcessorManager.cpp
    111111        libstreaming/AmdtpPortInfo.cpp                  \ 
    112112        libstreaming/AmdtpPort.cpp                      \ 
    113113        libstreaming/AmdtpStreamProcessor.cpp           \ 
    114114        libstreaming/ringbuffer.c                       \ 
    115        libstreaming/streamstatistics.cpp               
     115        libstreaming/streamstatistics.cpp
    116116        libstreaming/MotuStreamProcessor.cpp            \ 
    117117        libstreaming/MotuPort.cpp                       \ 
     
    121121        libutil/PosixThread.h                           \ 
    122122        libutil/Thread.h                                \ 
    123        libutil/DelayLockedLoop.cpp                     
    124        libutil/PosixThread.cpp                         
     123        libutil/DelayLockedLoop.cpp
     124        libutil/PosixThread.cpp
    125125        libutil/Time.c                                  \ 
    126126        libutil/Time.h                                  \ 
    127127        libutil/TimeSource.cpp                          \ 
    128128        libutil/TimeSource.h                            \ 
    129        libutil/SystemTimeSource.cpp                   
     129        libutil/SystemTimeSource.cpp
    130130        libutil/SystemTimeSource.h                      \ 
    131131        libutil/cycles.h                                \ 
  • branches/streaming-rework/tests/test-sytmonitor.cpp

    r360 r383  
    11/*************************************************************************** 
    2   Copyright (C) 2005 by Pieter Palmers   * 
     2Copyright (C) 2005 by Pieter Palmers   * 
    33                                                                        * 
    4   This program is free software; you can redistribute it and/or modify  * 
    5   it under the terms of the GNU General Public License as published by  * 
    6   the Free Software Foundation; either version 2 of the License, or     * 
    7   (at your option) any later version.                                   * 
     4This program is free software; you can redistribute it and/or modify  * 
     5it under the terms of the GNU General Public License as published by  * 
     6the Free Software Foundation; either version 2 of the License, or     * 
     7(at your option) any later version.                                   * 
    88                                                                        * 
    9   This program is distributed in the hope that it will be useful,       * 
    10   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
    11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
    12   GNU General Public License for more details.                          * 
     9This program is distributed in the hope that it will be useful,       * 
     10but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
     11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
     12GNU General Public License for more details.                          * 
    1313                                                                        * 
    14   You should have received a copy of the GNU General Public License     * 
    15   along with this program; if not, write to the                         * 
    16   Free Software Foundation, Inc.,                                       * 
    17   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
    18  ***************************************************************************/ 
     14You should have received a copy of the GNU General Public License     * 
     15along with this program; if not, write to the                         * 
     16Free Software Foundation, Inc.,                                       * 
     1759 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
     18***************************************************************************/ 
    1919 
    2020#ifdef HAVE_CONFIG_H 
     
    9292 
    9393    switch (key) { 
    94        case 'p': 
    95            if (arg) { 
     94        case 'p': 
     95            if (arg) { 
    9696            arguments->port = strtol( arg, &tail, 0 ); 
    9797            if ( errno ) { 
     
    9999                return ARGP_ERR_UNKNOWN; 
    100100            } 
    101            } else { 
     101            } else { 
    102102            if ( errno ) { 
    103103                fprintf( stderr, "Could not parse 'port' argumen\n" ); 
    104104                return ARGP_ERR_UNKNOWN; 
    105105            } 
    106            } 
    107            break; 
    108        case 'R': 
     106            } 
     107            break; 
     108        case 'R': 
    109109        arguments->realtime = true; 
    110            break;          
    111        case 'r': 
    112            if (arg) { 
     110            break;         
     111        case 'r': 
     112            if (arg) { 
    113113            arguments->rtprio = strtol( arg, &tail, 0 ); 
    114114            if ( errno ) { 
     
    116116                return ARGP_ERR_UNKNOWN; 
    117117            } 
    118            } 
    119            break;                  
    120        case ARGP_KEY_ARG: 
    121            if (state->arg_num >= 128) { 
     118            } 
     119            break;                 
     120        case ARGP_KEY_ARG: 
     121            if (state->arg_num >= 128) { 
    122122            // Too many arguments. 
    123123            argp_usage( state ); 
    124            } 
    125             
    126            if(sscanf( arg, "%d,%d",  
    127               &arguments->args[state->arg_num].port,  
    128               &arguments->args[state->arg_num].channel) != 2) { 
    129            fprintf( stderr,  "Could not parse port-channel specification ('%s')\n", arg); 
    130                
    131            } else { 
     124            } 
     125             
     126            if(sscanf( arg, "%d,%d",  
     127            &arguments->args[state->arg_num].port,  
     128            &arguments->args[state->arg_num].channel) != 2) { 
     129        fprintf( stderr,  "Could not parse port-channel specification ('%s')\n", arg); 
     130             
     131            } else { 
    132132            printf("Adding Port %d, Channel %d to list...\n", 
    133                arguments->args[state->arg_num].port, 
    134                arguments->args[state->arg_num].channel); 
    135               arguments->nb_combos++; 
    136            } 
    137            break; 
    138        case ARGP_KEY_END: 
    139            if (state->arg_num < 1) { 
     133            arguments->args[state->arg_num].port, 
     134            arguments->args[state->arg_num].channel); 
     135            arguments->nb_combos++; 
     136            } 
     137            break; 
     138        case ARGP_KEY_END: 
     139            if (state->arg_num < 1) { 
    140140            // Not enough arguments. 
    141141            argp_usage( state ); 
    142            } 
    143            break; 
    144        default: 
    145            return ARGP_ERR_UNKNOWN; 
     142            } 
     143            break; 
     144        default: 
     145            return ARGP_ERR_UNKNOWN; 
    146146    } 
    147147    return 0; 
     
    154154static void sighandler (int sig) 
    155155{ 
    156        run = 0; 
     156        run = 0; 
    157157} 
    158158 
     
    162162        int target_channel_1=0; 
    163163        int target_channel_2=0; 
    164        bool run_realtime=false; 
    165        int realtime_prio=20; 
    166        int nb_iter; 
    167        int i; 
    168        struct sched_param params; 
    169          
    170        IsoHandlerManager *m_isoManager=NULL; 
     164    bool run_realtime=false; 
     165    int realtime_prio=20; 
     166    int nb_iter; 
     167    int i; 
     168    struct sched_param params; 
     169     
     170    IsoHandlerManager *m_isoManager=NULL; 
    171171    PosixThread * m_isoManagerThread=NULL; 
    172172     
    173173    SytMonitor *monitors[128]; 
    174174    int stream_offset_ticks[128]; 
    175         
     175     
    176176    struct arguments arguments; 
    177177 
     
    193193     
    194194     
    195        run=1; 
    196          
    197        run_realtime=arguments.realtime; 
    198        realtime_prio=arguments.rtprio; 
    199  
    200        signal (SIGINT, sighandler); 
    201        signal (SIGPIPE, sighandler); 
    202  
    203        debugOutput(DEBUG_LEVEL_NORMAL, "Freebob SYT monitor\n"); 
    204          
    205        m_isoManager=new IsoHandlerManager(); 
    206          
    207        if(!m_isoManager) { 
    208                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create IsoHandlerManager\n"); 
    209                goto finish; 
    210        
    211          
    212        m_isoManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    213                  
     195        run=1; 
     196         
     197        run_realtime=arguments.realtime; 
     198        realtime_prio=arguments.rtprio; 
     199 
     200        signal (SIGINT, sighandler); 
     201        signal (SIGPIPE, sighandler); 
     202 
     203        debugOutput(DEBUG_LEVEL_NORMAL, "Freebob SYT monitor\n"); 
     204         
     205        m_isoManager=new IsoHandlerManager(); 
     206         
     207        if(!m_isoManager) { 
     208                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create IsoHandlerManager\n"); 
     209                goto finish; 
     210       
     211         
     212        m_isoManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     213                 
    214214    // the thread to execute the manager 
    215        m_isoManagerThread=new PosixThread( 
    216              m_isoManager,  
    217              run_realtime, realtime_prio, 
    218              PTHREAD_CANCEL_DEFERRED); 
    219               
    220        if(!m_isoManagerThread) { 
    221                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create iso manager thread\n"); 
    222                goto finish; 
    223        
    224          
    225        // register monitors 
    226        for (i=0;i<arguments.nb_combos;i++) { 
    227         debugOutput(DEBUG_LEVEL_NORMAL, "Registering SytMonitor %d\n",i); 
    228          
    229         // add a stream to the manager so that it has something to do 
    230         monitors[i]=new SytMonitor(arguments.args[i].port); 
    231          
    232         if (!monitors[i]) { 
    233             debugOutput(DEBUG_LEVEL_NORMAL, "Could not create SytMonitor %d\n", i); 
    234             goto finish; 
    235         }      
    236          
    237         monitors[i]->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    238          
    239         if (!monitors[i]->init()) { 
    240             debugOutput(DEBUG_LEVEL_NORMAL, "Could not init SytMonitor %d\n", i); 
    241             goto finish; 
    242        
    243          
    244         monitors[i]->setChannel(arguments.args[i].channel); 
    245          
    246         if(!m_isoManager->registerStream(monitors[i])) { 
     215        m_isoManagerThread=new PosixThread( 
     216            m_isoManager,  
     217            run_realtime, realtime_prio, 
     218            PTHREAD_CANCEL_DEFERRED); 
     219             
     220        if(!m_isoManagerThread) { 
     221                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create iso manager thread\n"); 
     222                goto finish; 
     223       
     224         
     225        // register monitors 
     226        for (i=0;i<arguments.nb_combos;i++) { 
     227            debugOutput(DEBUG_LEVEL_NORMAL, "Registering SytMonitor %d\n",i); 
     228         
     229            // add a stream to the manager so that it has something to do 
     230            monitors[i]=new SytMonitor(arguments.args[i].port); 
     231             
     232            if (!monitors[i]) { 
     233                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create SytMonitor %d\n", i); 
     234                goto finish; 
     235            }  
     236         
     237            monitors[i]->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     238         
     239            if (!monitors[i]->init()) { 
     240                debugOutput(DEBUG_LEVEL_NORMAL, "Could not init SytMonitor %d\n", i); 
     241                goto finish; 
     242           
     243         
     244            monitors[i]->setChannel(arguments.args[i].channel); 
     245             
     246            if(!m_isoManager->registerStream(monitors[i])) { 
    247247            debugOutput(DEBUG_LEVEL_NORMAL, "Could not register SytMonitor %d\n", i); 
    248             goto finish; 
    249        
     248                goto finish; 
     249           
    250250    } 
    251  
    252  
    253        debugOutput(DEBUG_LEVEL_NORMAL,   "Preparing IsoHandlerManager...\n"); 
    254        if (!m_isoManager->prepare()) { 
    255                debugOutput(DEBUG_LEVEL_NORMAL, "Could not prepare isoManager\n"); 
    256                goto finish; 
    257        
    258  
    259        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting ISO manager sync update thread...\n"); 
     251             
     252 
     253        debugOutput(DEBUG_LEVEL_NORMAL,   "Preparing IsoHandlerManager...\n"); 
     254        if (!m_isoManager->prepare()) { 
     255                debugOutput(DEBUG_LEVEL_NORMAL, "Could not prepare isoManager\n"); 
     256                goto finish; 
     257       
     258 
     259        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting ISO manager sync update thread...\n"); 
    260260 
    261261        // start the runner thread 
    262262        m_isoManagerThread->Start(); 
    263263 
    264        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting IsoHandlers...\n"); 
    265        if (!m_isoManager->startHandlers(0)) { 
    266                debugOutput(DEBUG_LEVEL_NORMAL, "Could not start handlers...\n"); 
    267                goto finish; 
    268        
    269          
    270     if (arguments.realtime) { 
    271         // get rt priority for this thread too. 
    272         params.sched_priority = arguments.rtprio + 1; 
    273         if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &params)) { 
    274             debugWarning("Couldn't set realtime prio for main thread..."); 
    275        
    276    
    277      
    278     // do the actual work 
    279     nb_iter=0; 
    280        while(run) { 
     264        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting IsoHandlers...\n"); 
     265        if (!m_isoManager->startHandlers(0)) { 
     266                debugOutput(DEBUG_LEVEL_NORMAL, "Could not start handlers...\n"); 
     267                goto finish; 
     268       
     269         
     270        if (arguments.realtime) { 
     271            // get rt priority for this thread too. 
     272            params.sched_priority = arguments.rtprio + 1; 
     273            if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &params)) { 
     274                debugWarning("Couldn't set realtime prio for main thread..."); 
     275           
     276       
     277     
     278        // do the actual work 
     279        nb_iter=0; 
     280        while(run) { 
    281281        debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"--- Iterate ---\n"); 
    282282         
     
    325325 
    326326                        if(cif.cycle==master_cif.cycle 
    327                            && cif.seconds==master_cif.seconds) { // this is the one 
     327                        && cif.seconds==master_cif.seconds) { // this is the one 
    328328                            debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"  GOOD : [%2d: %04us %04uc, %04X]\n", 
    329329                                i,cif.seconds, cif.cycle,cif.syt); 
     
    339339                                    cif.pres_ticks += TICKS_PER_SECOND*128; 
    340340                                } 
    341                                // average out the offset 
     341                            // average out the offset 
    342342                                int err=(((long)master_cif.pres_ticks) - ((long)cif.pres_ticks)); 
    343343                                 
     
    383383                            if ((cif.seconds < master_cif.seconds) ||  
    384384                                ((cif.seconds == master_cif.seconds)  
    385                                 && (cif.cycle < master_cif.cycle))) { 
     385                                && (cif.cycle < master_cif.cycle))) { 
    386386                                 
    387387                                debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"  LAGS : [%2d: %04us %04uc, %04X]\n", 
     
    419419        } 
    420420         
    421         // show info every x iterations 
     421            // show info every x iterations 
    422422        if ((nb_iter++ % 4000)==0) { 
    423             m_isoManager->dumpInfo(); 
    424             for (i=0;i<arguments.nb_combos;i++) { 
    425                 monitors[i]->dumpInfo(); 
     423                m_isoManager->dumpInfo(); 
     424                for (i=0;i<arguments.nb_combos;i++) { 
     425                    monitors[i]->dumpInfo(); 
    426426                debugOutput(DEBUG_LEVEL_NORMAL,"    ==> Stream offset: %10d ticks\n",stream_offset_ticks[i]); 
    427            
    428        
    429        
    430  
    431        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping handlers...\n"); 
    432        if(!m_isoManager->stopHandlers()) { 
    433           debugOutput(DEBUG_LEVEL_NORMAL, "Could not stop ISO handlers\n"); 
    434           goto finish; 
    435        
    436          
    437        // stop the sync thread 
    438        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping ISO manager sync update thread...\n"); 
    439        m_isoManagerThread->Stop(); 
    440          
    441        // unregister monitors 
    442        for (i=0;i<arguments.nb_combos;i++) { 
     427               
     428           
     429       
     430 
     431        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping handlers...\n"); 
     432        if(!m_isoManager->stopHandlers()) { 
     433            debugOutput(DEBUG_LEVEL_NORMAL, "Could not stop ISO handlers\n"); 
     434            goto finish; 
     435       
     436         
     437        // stop the sync thread 
     438        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping ISO manager sync update thread...\n"); 
     439        m_isoManagerThread->Stop(); 
     440         
     441        // unregister monitors 
     442        for (i=0;i<arguments.nb_combos;i++) { 
    443443        debugOutput(DEBUG_LEVEL_NORMAL, "Unregistering SytMonitor %d\n",i); 
    444          
     444         
    445445        if(!m_isoManager->unregisterStream(monitors[i])) { 
    446446            debugOutput(DEBUG_LEVEL_NORMAL, "Could not unregister SytMonitor %d\n",i); 
    447447            goto finish; 
    448            } 
    449            delete monitors[i]; 
     448            } 
     449            delete monitors[i]; 
    450450    } 
    451          
    452        delete m_isoManagerThread; 
     451         
     452        delete m_isoManagerThread; 
    453453    delete m_isoManager; 
    454454 
    455455finish: 
    456         debugOutput(DEBUG_LEVEL_NORMAL, "Bye...\n"); 
    457  
    458     delete DebugModuleManager::instance(); 
    459          
    460   return EXIT_SUCCESS; 
     456        debugOutput(DEBUG_LEVEL_NORMAL, "Bye...\n"); 
     457     delete DebugModuleManager::instance(); 
     458          
     459return EXIT_SUCCESS; 
    461460}