Changeset 267

Show
Ignore:
Timestamp:
06/18/06 17:39:04 (16 years ago)
Author:
jwoithe
Message:

More Motu streaming infrastructure added.
Added more Motu device configuration details.
tests/teststreaming.c: added call to freebob_streaming_prepare() so this can
naively used to start exercising the Motu functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libfreebob-2.0/src/libstreaming/IsoHandler.cpp

    r244 r267  
    278278                                         m_irq_interval)) { 
    279279                debugFatal("Could not do receive initialisation!\n" ); 
     280                debugFatal("  %s\n",strerror(errno)); 
    280281 
    281282                return false; 
  • branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp

    r266 r267  
    292292                        max_packet_size=stream->getMaxPacketSize(); 
    293293                } 
    294                  
     294 
     295                // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits 
     296                // the maximum packet size to the pagesize. 
     297                if (max_packet_size > (unsigned int)getpagesize()) 
     298                        max_packet_size = getpagesize(); 
     299 
    295300                int irq_interval=packets_per_period / 4; 
    296301        if(irq_interval <= 0) irq_interval=1; 
     
    345350                        max_packet_size=stream->getMaxPacketSize(); 
    346351                } 
    347                  
     352 
     353                // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits 
     354                // the maximum packet size to the pagesize. 
     355                if (max_packet_size > (unsigned int)getpagesize()) 
     356                        max_packet_size = getpagesize(); 
     357 
    348358                int irq_interval=packets_per_period / 4; 
    349359                if(irq_interval <= 0) irq_interval=1; 
  • branches/libfreebob-2.0/src/libstreaming/MotuPort.h

    r265 r267  
    7979                           int position) 
    8080                : MidiPort(name, direction), 
    81                   MotuPortInfo(name, position, 16)  // TODO: add more port information parameters here if nescessary 
     81                  MotuPortInfo(name, position, 2)  // TODO: add more port information parameters here if nescessary 
    8282        {}; 
    8383 
     
    104104                           int position) 
    105105                : ControlPort(name, direction), 
    106                   MotuPortInfo(name, position, 16) // TODO: add more port information parameters here if nescessary  
     106                  MotuPortInfo(name, position, 2) // TODO: add more port information parameters here if nescessary  
    107107        {}; 
    108108 
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp

    r265 r267  
    3333#include "MotuPort.h" 
    3434 
     35#include <netinet/in.h> 
     36 
    3537namespace FreebobStreaming { 
    3638 
    3739IMPL_DEBUG_MODULE( MotuTransmitStreamProcessor, MotuTransmitStreamProcessor, DEBUG_LEVEL_NORMAL ); 
    3840IMPL_DEBUG_MODULE( MotuReceiveStreamProcessor, MotuReceiveStreamProcessor, DEBUG_LEVEL_NORMAL ); 
     41 
     42// A macro to extract specific bits from a native endian quadlet 
     43#define get_bits(_d,_start,_len) (((_d)>>((_start)-(_len)+1)) & ((1<<(_len))-1)) 
     44 
    3945 
    4046/* transmit */ 
     
    96102                return RAW1394_ISO_OK; 
    97103        } 
     104 
     105// FIXME: for now always just return NULL packets 
     106*length = 0; 
     107*tag = 0; 
     108*sy = 0; 
     109return RAW1394_ISO_OK; 
    98110         
    99111    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); 
     
    202214        return false;     
    203215    } 
    204      
     216 
    205217    return true; 
    206218} 
     
    216228        return false; 
    217229    } 
     230 
     231        m_PeriodStat.setName("XMT PERIOD"); 
     232        m_PacketStat.setName("XMT PACKET"); 
     233        m_WakeupStat.setName("XMT WAKEUP"); 
    218234     
    219235    // allocate the event buffer 
     
    305321    unsigned int write_size=size*sizeof(quadlet_t)*m_dimension; 
    306322    char *dummybuffer=(char *)calloc(sizeof(quadlet_t),size*m_dimension); 
     323 
    307324    transmitSilenceBlock(dummybuffer, size, 0); 
    308325 
     
    338355    int xrun; 
    339356    unsigned int offset=0; 
    340      
     357 
     358// FIXME: just return until we've got the transmit side of things functional 
     359return true; 
     360 
    341361    freebob_ringbuffer_data_t vec[2]; 
    342362    // we received one period of frames 
     
    519539    quadlet_t *target_event=NULL; 
    520540    int j; 
    521      
     541 
    522542    for ( PortVectorIterator it = m_PacketPorts.begin(); 
    523543          it != m_PacketPorts.end(); 
     
    667687     
    668688    enum raw1394_iso_disposition retval=RAW1394_ISO_OK; 
    669      
    670     if(1 /* if there are events in this packet */) { 
    671      
    672         unsigned int nevents=0; // TODO: calculate the number of events here 
    673          
    674         // signal that we're running 
    675                 if(nevents) m_running=true; 
    676          
    677         // don't process the stream when it is not enabled. 
    678         if(m_disabled) { 
    679             return RAW1394_ISO_OK; 
    680         } 
    681          
    682         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "put packet...\n"); 
    683          
    684         // see transmit processor 
    685         unsigned int write_size=nevents*sizeof(quadlet_t)*m_dimension; 
    686          
    687         // add the data payload (events) to the ringbuffer 
    688         if (freebob_ringbuffer_write(m_event_buffer,(char *)(data+8),write_size) < write_size)  
    689         { 
    690             debugWarning("Receive buffer overrun (cycle %d, FC=%d, PC=%d)\n",  
    691                  cycle, m_framecounter, m_handler->getPacketCount()); 
    692             m_xruns++; 
    693  
    694             retval=RAW1394_ISO_DEFER; 
    695         } else { 
    696             retval=RAW1394_ISO_OK; 
    697             // process all ports that should be handled on a per-packet base 
    698             // this is MIDI for AMDTP (due to the need of DBC) 
    699             int dbc=0; //get this from packet if needed, else change decodePacketPorts 
    700             if (!decodePacketPorts((quadlet_t *)(data+8), nevents, dbc)) { 
    701                 debugWarning("Problem decoding Packet Ports\n"); 
    702                 retval=RAW1394_ISO_DEFER; 
    703             } 
    704              
    705             // time stamp processing can be done here 
    706          
    707         } 
    708  
    709         // update the frame counter 
    710         incrementFrameCounter(nevents); 
    711         // keep this at the end, because otherwise the raw1394_loop_iterate functions inner loop 
    712         // keeps requesting packets without going to the xmit handler, leading to xmit starvation 
    713         if(m_framecounter>m_period) { 
    714            retval=RAW1394_ISO_DEFER; 
    715         } 
     689 
     690    // If the packet length is 8 bytes (ie: just a CIP-like header) there is 
     691    // no isodata. 
     692    if (length > 8) { 
     693        // Note: a freebob "event" is equivalent to an ieee1394 iso data 
     694        // block.  We'll try to stick to freebob terminology. 
     695        quadlet_t *quadlet = (quadlet_t *)data; 
     696        unsigned int dbs = get_bits(ntohl(quadlet[0]), 23, 8);  // ISO data block size in terms of fdf_size 
     697        unsigned int fdf_size = get_bits(ntohl(quadlet[1]), 23, 8) == 0x22 ? 32:0; // ISO block unit size in bits 
     698        unsigned int event_length = (fdf_size * dbs) / 8;       // Event (aka ISO block) size in bytes 
     699        unsigned int n_events = (length-8) / event_length; 
     700 
     701        // Don't even attempt to process a packet if it isn't what we expect 
     702        // from a MOTU 
     703        if (tag!=1 || fdf_size!=32) { 
     704                return RAW1394_ISO_OK; 
     705        } 
     706         
     707        // Signal that we're running 
     708        if (n_events) m_running=true; 
     709 
     710        // Don't process the stream when it is not enabled. 
     711        if (m_disabled) { 
     712                return RAW1394_ISO_OK; 
     713        } 
     714         
     715        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "put packet...\n"); 
     716 
     717        // Add the data payload (events) to the ringbuffer.  We'll just copy 
     718        // everything including the 4 byte timestamp at the start of each 
     719        // event (that is, everything except the CIP-like header).  The 
     720        // demultiplexer can deal with the complexities such as the channel 
     721        // 24-bit data. 
     722        unsigned int write_size = length-8; 
     723        if (freebob_ringbuffer_write(m_event_buffer,(char *)(data+8),write_size) < write_size) { 
     724                debugWarning("Receive buffer overrun (cycle %d, FC=%d, PC=%d)\n",  
     725                        cycle, m_framecounter, m_handler->getPacketCount()); 
     726                m_xruns++; 
     727 
     728                retval=RAW1394_ISO_DEFER; 
     729        } else { 
     730                retval=RAW1394_ISO_OK; 
     731                // Process all ports that should be handled on a per-packet basis 
     732                // This is MIDI for AMDTP (due to the need of DBC) 
     733                int dbc = get_bits(ntohl(quadlet[0]), 8, 8);  // Low byte of CIP quadlet 0 
     734                if (!decodePacketPorts((quadlet_t *)(data+8), n_events, dbc)) { 
     735                        debugWarning("Problem decoding Packet Ports\n"); 
     736                        retval=RAW1394_ISO_DEFER; 
     737                } 
     738                // time stamp processing can be done here 
     739        } 
     740 
     741        // update the frame counter 
     742        incrementFrameCounter(n_events); 
     743        // keep this at the end, because otherwise the raw1394_loop_iterate functions inner loop 
     744        // keeps requesting packets without going to the xmit handler, leading to xmit starvation 
     745        if(m_framecounter>m_period) { 
     746                retval=RAW1394_ISO_DEFER; 
     747        } 
    716748         
    717749    } else { // no events in packet 
    718         // discard packet 
    719         // can be important for sync though 
     750       // discard packet 
     751       // can be important for sync though 
    720752    } 
    721753     
     
    751783        // reset the event buffer, discard all content 
    752784        freebob_ringbuffer_reset(m_event_buffer); 
    753          
     785 
    754786        // reset all non-device specific stuff 
    755787        // i.e. the iso stream and the associated ports 
     
    770802                return false; 
    771803        } 
    772          
     804 
    773805        debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
    774806 
     807        m_PeriodStat.setName("RCV PERIOD"); 
     808        m_PacketStat.setName("RCV PACKET"); 
     809        m_WakeupStat.setName("RCV WAKEUP"); 
     810 
    775811    // setup any specific stuff here 
    776812 
    777     // allocate the event buffer 
    778     unsigned int ringbuffer_size_frames=m_nb_buffers * m_period; 
    779      
    780     if( !(m_event_buffer=freebob_ringbuffer_create( 
    781             (m_dimension * ringbuffer_size_frames) * sizeof(quadlet_t)))) { 
     813       // allocate the event buffer 
     814       unsigned int ringbuffer_size_frames=m_nb_buffers * m_period; 
     815 
     816       if( !(m_event_buffer=freebob_ringbuffer_create( 
     817               (m_dimension * ringbuffer_size_frames) * sizeof(quadlet_t)))) { 
    782818                debugFatal("Could not allocate memory event ringbuffer"); 
    783819                return false; 
     
    873909        unsigned int events2read=m_period*m_dimension; 
    874910        unsigned int bytes2read=events2read*sizeof(quadlet_t); 
     911 
     912// FIXME: remove once the stuff below has been tweaked for the MOTU 
     913return true; 
     914 
    875915        /* read events2read bytes from the ringbuffer  
    876916        *  first see if it can be done in one read.  
  • branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp

    r266 r267  
    403403                return false; 
    404404        } 
    405          
     405 
    406406        debugOutput( DEBUG_LEVEL_VERBOSE, "StreamProcessors running...\n"); 
    407407        debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting frame counters...\n"); 
     
    416416                        (*it)->dumpInfo(); 
    417417                } 
    418                  
     418 
    419419                (*it)->reset(); 
    420                  
     420 
    421421                if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 
    422422                        (*it)->dumpInfo(); 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.cpp

    r265 r267  
    4141char *motufw_modelname[] = {"[unknown]","828MkII", "Traveler"};  
    4242 
     43/* ======================================================================= */ 
     44/* Keep track of iso channels assigned to different MOTU devices.  This 
     45 * is slightly simplistic at present since it assumes there are no other 
     46 * users of iso channels on the firewire bus.  It does however allow 
     47 * more than one MOTU interface to exist on the same bus.  The first MOTU 
     48 * discovered will be allocated iso channels 0 (send) and 1 (receive) which 
     49 * mirrors what the official driver appears to do. 
     50 */ 
     51static signed int next_iso_recv_channel_num = 1; 
     52static signed int next_iso_send_channel_num = 0;   
     53       
     54static signed int next_iso_recv_channel(void) { 
     55/* 
     56 * Returns the next available channel for ISO receive.  If there are no more 
     57 * available -1 is returned.  Currently the odd channels (starting from 1) 
     58 * are used for iso receive.  No provision is made to reuse previously 
     59 * allocated channels in the event that the applicable interface has been 
     60 * removed - this may change in future. 
     61 */ 
     62        if (next_iso_recv_channel_num < 64) { 
     63                next_iso_recv_channel_num+=2; 
     64                return next_iso_recv_channel_num-2; 
     65        } 
     66        return -1; 
     67} 
     68static signed int next_iso_send_channel(void) { 
     69/* 
     70 * Returns the next available channel for ISO send.  If there are no more 
     71 * available -1 is returned.  Currently the even channels (starting from 0) 
     72 * are used for iso receive.  No provision is made to reuse previously 
     73 * allocated channels in the event that the applicable interface has been 
     74 * removed - this may change in future. 
     75 */ 
     76        if (next_iso_send_channel_num < 64) { 
     77                next_iso_send_channel_num+=2; 
     78                return next_iso_send_channel_num-2; 
     79        } 
     80        return -1; 
     81} 
     82/* ======================================================================= */ 
     83 
    4384MotuDevice::MotuDevice( Ieee1394Service& ieee1394service, 
    4485                        int nodeId, 
     
    4990    , m_verboseLevel( verboseLevel ) 
    5091    , m_id(0) 
     92    , m_iso_recv_channel ( -1 ) 
     93    , m_iso_send_channel ( -1 ) 
    5194    , m_receiveProcessor ( 0 ) 
    5295    , m_transmitProcessor ( 0 ) 
     
    91134                debugOutput( DEBUG_LEVEL_VERBOSE, "found MOTU %s\n", 
    92135                        motufw_modelname[m_motu_model]); 
     136 
     137                // Assign iso channels if not already done 
     138                if (m_iso_recv_channel < 0) 
     139                        m_iso_recv_channel = next_iso_recv_channel(); 
     140                if (m_iso_send_channel < 0) 
     141                        m_iso_send_channel = next_iso_send_channel(); 
    93142                return true; 
    94         } 
    95  
    96     return false; 
     143        } 
     144        return false; 
    97145} 
    98146 
     
    198246MotuDevice::prepare() { 
    199247 
    200     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing MotuDevice...\n" ); 
     248        int samp_freq = getSamplingFrequency(); 
     249        enum EMotuOpticalMode optical_mode = getOpticalMode(); 
     250 
     251        debugOutput(DEBUG_LEVEL_NORMAL, "Preparing MotuDevice...\n" ); 
    201252 
    202253        m_receiveProcessor=new FreebobStreaming::MotuReceiveStreamProcessor( 
    203                                  m_1394Service->getPort(), 
    204                                  getSamplingFrequency()); 
     254                                 m_1394Service->getPort(), samp_freq); 
    205255                                  
    206256        // the first thing is to initialize the processor 
     
    209259                debugFatal("Could not initialize receive processor!\n"); 
    210260                return false; 
    211          
    212         } 
    213  
    214     // now we add ports to the processor 
    215     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to receive processor\n"); 
     261        } 
     262        m_receiveProcessor->setVerboseLevel(getDebugLevel()); 
     263 
     264       // now we add ports to the processor 
     265       debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to receive processor\n"); 
    216266         
    217267        // TODO: change this into something based upon device detection/configuration 
    218          
    219     char *buff; 
    220     FreebobStreaming::Port *p=NULL; 
    221      
    222         // example of adding an audio port: 
    223     asprintf(&buff,"dev%d_cap_%s",m_id,"myportnamehere"); 
    224      
    225     p=new FreebobStreaming::MotuAudioPort( 
    226             buff, 
    227             FreebobStreaming::Port::E_Capture,  
    228             0, 
    229             0 // you can add all other port specific stuff you  
    230               // need to pass by extending MotuXXXPort and MotuPortInfo 
    231     ); 
    232      
    233     free(buff); 
    234  
    235     if (!p) { 
    236         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    237     } else { 
    238  
    239         if (!m_receiveProcessor->addPort(p)) { 
    240             debugWarning("Could not register port with stream processor\n"); 
    241             return false; 
    242         } else { 
    243             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    244          
    245         } 
    246     } 
    247      
     268        char *buff; 
     269        unsigned int i; 
     270        FreebobStreaming::Port *p=NULL; 
     271 
     272        // For now just add the 8 analog capture ports since they are always 
     273        // present no matter what the device configuration is. 
     274        for (i=0; i<8; i++) { 
     275                asprintf(&buff,"dev%d_cap_Analog%d",m_id,i+1); 
     276                p=new FreebobStreaming::MotuAudioPort( 
     277                        buff, 
     278                        FreebobStreaming::Port::E_Capture,  
     279                        0, 0); 
     280 
     281                if (!p) { 
     282                        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     283                } else { 
     284                        if (!m_receiveProcessor->addPort(p)) { 
     285                                debugWarning("Could not register port with stream processor\n"); 
     286                                free(buff); 
     287                                return false; 
     288                        } else { 
     289                                debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     290                        } 
     291                } 
     292                free(buff); 
     293        } 
     294 
    248295        // example of adding an midi port: 
    249     asprintf(&buff,"dev%d_cap_%s",m_id,"myportnamehere"); 
    250      
    251     p=new FreebobStreaming::MotuMidiPort( 
    252             buff, 
    253             FreebobStreaming::Port::E_Capture,  
    254             0 // you can add all other port specific stuff you  
    255               // need to pass by extending MotuXXXPort and MotuPortInfo 
    256     ); 
    257      
    258     free(buff); 
    259  
    260     if (!p) { 
    261         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    262     } else { 
    263  
    264         if (!m_receiveProcessor->addPort(p)) { 
    265             debugWarning("Could not register port with stream processor\n"); 
    266             return false; 
    267         } else { 
    268             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    269          
    270         } 
    271     } 
     296//    asprintf(&buff,"dev%d_cap_%s",m_id,"myportnamehere"); 
     297//    p=new FreebobStreaming::MotuMidiPort( 
     298//            buff, 
     299//            FreebobStreaming::Port::E_Capture,  
     300//            0 // you can add all other port specific stuff you  
     301//              // need to pass by extending MotuXXXPort and MotuPortInfo 
     302//    ); 
     303//    free(buff); 
     304// 
     305//    if (!p) { 
     306//        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     307//    } else { 
     308//        if (!m_receiveProcessor->addPort(p)) { 
     309//            debugWarning("Could not register port with stream processor\n"); 
     310//            return false; 
     311//        } else { 
     312//            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     313//        } 
     314//    } 
    272315     
    273316        // example of adding an control port: 
    274     asprintf(&buff,"dev%d_cap_%s",m_id,"myportnamehere"); 
    275      
    276     p=new FreebobStreaming::MotuControlPort( 
    277             buff, 
    278             FreebobStreaming::Port::E_Capture,  
    279             0 // you can add all other port specific stuff you  
    280               // need to pass by extending MotuXXXPort and MotuPortInfo 
    281     ); 
    282      
    283     free(buff); 
    284  
    285     if (!p) { 
    286         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    287     } else { 
    288  
    289         if (!m_receiveProcessor->addPort(p)) { 
    290             debugWarning("Could not register port with stream processor\n"); 
    291             return false; 
    292         } else { 
    293             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    294          
    295         } 
    296     } 
    297  
     317//    asprintf(&buff,"dev%d_cap_%s",m_id,"myportnamehere"); 
     318//    p=new FreebobStreaming::MotuControlPort( 
     319//            buff, 
     320//            FreebobStreaming::Port::E_Capture,  
     321//            0 // you can add all other port specific stuff you  
     322//              // need to pass by extending MotuXXXPort and MotuPortInfo 
     323//    ); 
     324//    free(buff); 
     325// 
     326//    if (!p) { 
     327//        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     328//    } else { 
     329// 
     330//        if (!m_receiveProcessor->addPort(p)) { 
     331//            debugWarning("Could not register port with stream processor\n"); 
     332//            return false; 
     333//        } else { 
     334//            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     335//        } 
     336//    } 
    298337 
    299338        // do the same for the transmit processor 
    300339        m_transmitProcessor=new FreebobStreaming::MotuTransmitStreamProcessor( 
    301                                  m_1394Service->getPort(), 
    302                                  getSamplingFrequency()); 
    303                                   
     340               m_1394Service->getPort(), 
     341               getSamplingFrequency()); 
     342 
    304343        m_transmitProcessor->setVerboseLevel(getDebugLevel()); 
    305344         
     
    307346                debugFatal("Could not initialize transmit processor!\n"); 
    308347                return false; 
    309          
    310         } 
    311  
    312     // now we add ports to the processor 
    313     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n"); 
    314      
    315         // example of adding an audio port: 
    316         // we change the naming and the direction to E_Playback 
    317     asprintf(&buff,"dev%d_pbk_%s",m_id,"myportnamehere"); 
    318      
    319     p=new FreebobStreaming::MotuAudioPort( 
    320             buff, 
    321             FreebobStreaming::Port::E_Playback,  
    322             0, 
    323             0 // you can add all other port specific stuff you  
    324               // need to pass by extending MotuXXXPort and MotuPortInfo 
    325     ); 
    326      
    327     free(buff); 
    328  
    329     if (!p) { 
    330         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    331     } else { 
    332  
    333         if (!m_transmitProcessor->addPort(p)) { 
    334             debugWarning("Could not register port with stream processor\n"); 
    335             return false; 
    336         } else { 
    337             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    338          
    339         } 
    340     } 
    341      
    342         // example of adding an midi port: 
    343     asprintf(&buff,"dev%d_pbk_%s",m_id,"myportnamehere"); 
    344      
    345     p=new FreebobStreaming::MotuMidiPort( 
    346             buff, 
    347             FreebobStreaming::Port::E_Playback,  
    348             0 // you can add all other port specific stuff you  
    349               // need to pass by extending MotuXXXPort and MotuPortInfo 
    350     ); 
    351      
    352     free(buff); 
    353  
    354     if (!p) { 
    355         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    356     } else { 
    357  
    358         if (!m_transmitProcessor->addPort(p)) { 
    359             debugWarning("Could not register port with stream processor\n"); 
    360             return false; 
    361         } else { 
    362             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    363          
    364         } 
    365     } 
     348        } 
     349 
     350        // now we add ports to the processor 
     351        debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n"); 
     352 
     353        // For now just add the 8 analog capture ports since they are always 
     354        // present no matter what the device configuration is.  Note the 
     355        // direction is now E_Playback. 
     356        for (i=0; i<8; i++) { 
     357                asprintf(&buff,"dev%d_pbk_Analog%d",m_id,i+1); 
     358 
     359                p=new FreebobStreaming::MotuAudioPort( 
     360                        buff, 
     361                        FreebobStreaming::Port::E_Playback,  
     362                        0, 0); 
     363 
     364                if (!p) { 
     365                        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     366                } else { 
     367                        if (!m_transmitProcessor->addPort(p)) { 
     368                                debugWarning("Could not register port with stream processor\n"); 
     369                                free(buff); 
     370                                return false; 
     371                        } else { 
     372                                debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     373                        } 
     374                } 
     375                free(buff); 
     376        } 
     377 
     378//      // example of adding an midi port: 
     379//    asprintf(&buff,"dev%d_pbk_%s",m_id,"myportnamehere"); 
     380//     
     381//    p=new FreebobStreaming::MotuMidiPort( 
     382//            buff, 
     383//            FreebobStreaming::Port::E_Playback,  
     384//            0 // you can add all other port specific stuff you  
     385//              // need to pass by extending MotuXXXPort and MotuPortInfo 
     386//    ); 
     387//    free(buff); 
     388// 
     389//    if (!p) { 
     390//        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     391//    } else { 
     392//        if (!m_transmitProcessor->addPort(p)) { 
     393//            debugWarning("Could not register port with stream processor\n"); 
     394//            return false; 
     395//        } else { 
     396//            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     397//        } 
     398//    } 
    366399     
    367400        // example of adding an control port: 
    368     asprintf(&buff,"dev%d_pbk_%s",m_id,"myportnamehere"); 
    369      
    370     p=new FreebobStreaming::MotuControlPort( 
    371             buff, 
    372             FreebobStreaming::Port::E_Playback,  
    373             0 // you can add all other port specific stuff you  
    374               // need to pass by extending MotuXXXPort and MotuPortInfo 
    375     ); 
    376      
    377     free(buff); 
    378  
    379     if (!p) { 
    380         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
    381     } else { 
    382  
    383         if (!m_transmitProcessor->addPort(p)) { 
    384             debugWarning("Could not register port with stream processor\n"); 
    385             return false; 
    386         } else { 
    387             debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
    388          
    389         } 
    390     } 
     401//    asprintf(&buff,"dev%d_pbk_%s",m_id,"myportnamehere"); 
     402//     
     403//    p=new FreebobStreaming::MotuControlPort( 
     404//            buff, 
     405//            FreebobStreaming::Port::E_Playback,  
     406//            0 // you can add all other port specific stuff you  
     407//              // need to pass by extending MotuXXXPort and MotuPortInfo 
     408//    ); 
     409//    free(buff); 
     410// 
     411//    if (!p) { 
     412//        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 
     413//    } else { 
     414//        if (!m_transmitProcessor->addPort(p)) { 
     415//            debugWarning("Could not register port with stream processor\n"); 
     416//            return false; 
     417//        } else { 
     418//            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 
     419//        } 
     420//    } 
    391421         
    392422        return true; 
     
    414444MotuDevice::startStreamByIndex(int i) { 
    415445 
    416     // NOTE: this assumes that you have two streams 
    417         switch (i) { 
     446quadlet_t isoctrl = ReadRegister(MOTUFW_REG_ISOCTRL); 
     447 
     448        // NOTE: this assumes that you have two streams 
     449        switch (i) { 
    418450        case 0: 
    419         // TODO: do the stuff that is nescessary to make the device 
    420         // transmit a stream 
    421  
    422  
    423                 // set the streamprocessor channel to the one obtained by  
     451                // TODO: do the stuff that is nescessary to make the device 
     452                // transmit a stream 
     453 
     454                // Set the streamprocessor channel to the one obtained by  
    424455                // the connection management 
    425                 // IMPORTANT!! 
    426                 m_receiveProcessor->setChannel(1); // TODO: change the channel NR 
    427                 break; 
    428         case 1: 
    429         // TODO: do the stuff that is nescessary to make the device 
    430         // receive a stream 
    431  
    432                 // set the streamprocessor channel to the one obtained by  
     456                m_receiveProcessor->setChannel(m_iso_recv_channel); 
     457 
     458                // Mask out current transmit settings of the MOTU and replace 
     459                // with new ones.  Turn bit 24 on to enable changes to the 
     460                // MOTU's iso transmit settings when the iso control register 
     461                // is written.  Bit 23 enables iso transmit from the MOTU. 
     462                isoctrl &= 0xff00ffff; 
     463                isoctrl |= (m_iso_recv_channel << 16); 
     464                isoctrl |= 0x00c00000; 
     465                WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl); 
     466                break; 
     467        case 1: 
     468                // TODO: do the stuff that is nescessary to make the device 
     469                // receive a stream 
     470 
     471                // Set the streamprocessor channel to the one obtained by  
    433472                // the connection management 
    434                 // IMPORTANT!! 
    435                 m_transmitProcessor->setChannel(0); // TODO: change the channel NR 
    436                 break; 
    437                  
    438         default: // invalid index 
    439                 return -1; 
    440         } 
     473                m_transmitProcessor->setChannel(m_iso_send_channel); 
     474 
     475                // Mask out current receive settings of the MOTU and replace 
     476                // with new ones.  Turn bit 31 on to enable changes to the 
     477                // MOTU's iso receive settings when the iso control register 
     478                // is written.  Bit 30 enables iso receive by the MOTU. 
     479                isoctrl &= 0x00ffffff; 
     480                isoctrl |= (m_iso_send_channel << 24); 
     481                isoctrl |= 0xc0000000; 
     482                WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl); 
     483                break; 
     484                 
     485        default: // Invalid stream index 
     486                return -1; 
     487        } 
    441488 
    442489        return 0; 
    443  
    444490} 
    445491 
    446492int 
    447493MotuDevice::stopStreamByIndex(int i) { 
     494 
     495quadlet_t isoctrl = ReadRegister(MOTUFW_REG_ISOCTRL); 
     496 
    448497        // TODO: connection management: break connection 
    449498        // cfr the start function 
    450499 
     500        // NOTE: this assumes that you have two streams 
     501        switch (i) { 
     502        case 0: 
     503                // Turn bit 22 off to disable iso send by the MOTU.  Turn 
     504                // bit 23 on to enable changes to the MOTU's iso transmit 
     505                // settings when the iso control register is written. 
     506                isoctrl &= 0xffbfffff; 
     507                WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl); 
     508                break; 
     509        case 1: 
     510                // Turn bit 30 off to disable iso receive by the MOTU.  Turn 
     511                // bit 31 on to enable changes to the MOTU's iso receive 
     512                // settings when the iso control register is written. 
     513                isoctrl &= 0xbfffffff; 
     514                WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl); 
     515                break; 
     516                 
     517        default: // Invalid stream index 
     518                return -1; 
     519        } 
     520 
    451521        return 0; 
    452522} 
    453523 
    454  
    455  
     524signed int MotuDevice::getIsoRecvChannel(void) { 
     525        return m_iso_recv_channel; 
     526
     527 
     528signed int MotuDevice::getIsoSendChannel(void) { 
     529        return m_iso_send_channel; 
     530
     531 
     532enum MotuDevice::EMotuOpticalMode MotuDevice::getOpticalMode(void) { 
     533        unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF); 
     534 
     535// FIXME: remove after debugging 
     536// Also, do we really want to mess with this enum? 
     537fprintf(stderr,"route-port conf reg: 0x%08x\n",reg); 
     538        return (enum EMotuOpticalMode)((reg & 0x00000300) >> 8); 
     539
     540 
     541signed int MotuDevice::setOpticalMode(enum EMotuOpticalMode mode) { 
     542  // FIXME: needs implementing 
     543  return -1; 
     544
    456545 
    457546/* ======================================================================== */ 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.h

    r262 r267  
    4040 
    4141/* Device registers */ 
    42 #define MOTUFW_REG_RATECTRL             0x0b14 
    43  
     42#define MOTUFW_REG_ISOCTRL              0x0b00 
     43#define MOTUFW_REG_RATECTRL             0x0b14 
     44#define MOTUFW_REG_ROUTE_PORT_CONF      0x0c04 
    4445 
    4546class ConfigRom; 
     
    5051class MotuDevice : public IAvDevice { 
    5152public: 
     53    enum EMotuModel { 
     54      MOTUFW_MODEL_NONE     = 0x0000, 
     55      MOTUFW_MODEL_828mkII  = 0x0001, 
     56      MOTUFW_MODEL_TRAVELER = 0x0002, 
     57    }; 
     58 
     59    enum EMotuOpticalMode { 
     60      MOTUFW_OPTICAL_OFF      = 0, 
     61      MOTUFW_OPTICAL_ADAT     = 1, 
     62      MOTUFW_OPTICAL_TOSLINK  = 2, 
     63    }; 
     64 
    5265    MotuDevice( Ieee1394Service& ieee1394Service, 
    5366                  int nodeId, 
     
    7689    virtual int stopStreamByIndex(int i); 
    7790 
    78     enum EMotuModel { 
    79       MOTUFW_MODEL_NONE     = 0x0000, 
    80       MOTUFW_MODEL_828mkII  = 0x0001, 
    81       MOTUFW_MODEL_TRAVELER = 0x0002, 
    82     }; 
    83  
     91    signed int getIsoRecvChannel(void); 
     92    signed int getIsoSendChannel(void); 
     93    enum EMotuOpticalMode getOpticalMode(void); 
     94    signed int setOpticalMode(enum EMotuOpticalMode mode); 
     95   
    8496protected: 
    8597    Ieee1394Service* m_1394Service; 
     
    88100    int              m_nodeId; 
    89101    int              m_verboseLevel; 
    90     unsigned int m_id; 
     102    signed int m_id; 
     103    signed int m_iso_recv_channel, m_iso_send_channel; 
    91104     
    92105        FreebobStreaming::MotuReceiveStreamProcessor *m_receiveProcessor; 
  • branches/libfreebob-2.0/tests/streaming/Makefile.am

    r250 r267  
    2424# noinst_HEADERS = debugtools.h 
    2525 
    26 # teststreaming_SOURCES = teststreaming.c debugtools.c 
    27 # teststreaming_LDADD   = @top_builddir@src/libfreebob.la \ 
    28 #     $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
     26teststreaming_SOURCES = teststreaming.c debugtools.c 
     27teststreaming_LDADD   = @top_builddir@src/libfreebob.la \ 
     28      $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
    2929#  
    3030# teststreaming2_SOURCES = teststreaming2.c debugtools.c 
     
    4040#       $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
    4141 
    42 noinst_PROGRAMS = test-isohandling 
    43 noinst_HEADERS =  
     42noinst_PROGRAMS = test-isohandling teststreaming 
     43noinst_HEADERS = debugtools.h 
    4444 
    4545test_isohandling_SOURCES = test-isohandling.cpp 
  • branches/libfreebob-2.0/tests/streaming/teststreaming.c

    r194 r267  
    148148        } 
    149149 
     150        freebob_streaming_prepare(dev); 
    150151        freebob_streaming_start(dev); 
    151152