Changeset 269

Show
Ignore:
Timestamp:
06/20/06 23:46:20 (16 years ago)
Author:
jwoithe
Message:

More MOTU port infrastructure developments.
Make teststreaming2 compile and maybe work.
Fix some comments in IsoHandlerManager?.cpp and freebob_streaming.cpp.

Files:

Legend:

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

    r265 r269  
    456456        assert(p);  
    457457         
     458        p->useExternalBuffer(true); 
    458459        p->setExternalBufferAddress((void *)buff); 
    459460 
     
    468469        assert(p);  
    469470         
     471        p->useExternalBuffer(true); 
    470472        p->setExternalBufferAddress((void *)buff); 
    471473 
  • branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp

    r267 r269  
    293293                } 
    294294 
    295                 // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits 
    296                 // the maximum packet size to the pagesize. 
     295                // Ensure we don't request a packet size bigger than the 
     296                // kernel-enforced maximum which is currently 1 page. 
    297297                if (max_packet_size > (unsigned int)getpagesize()) 
    298298                        max_packet_size = getpagesize(); 
     
    351351                } 
    352352 
    353                 // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits 
    354                 // the maximum packet size to the pagesize. 
     353                // Ensure we don't request a packet size bigger than the 
     354                // kernel-enforced maximum which is currently 1 page. 
    355355                if (max_packet_size > (unsigned int)getpagesize()) 
    356356                        max_packet_size = getpagesize(); 
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp

    r268 r269  
    691691    // no isodata. 
    692692    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. 
     693        // The iso data blocks from the MOTUs comprise a CIP-like header 
     694        // followed by a number of events (8 for 1x rates, 16 for 2x rates, 
     695        // 32 for 4x rates). 
    695696        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 
     697        unsigned int dbs = get_bits(ntohl(quadlet[0]), 23, 8);  // Size of one event in terms of fdf_size 
     698        unsigned int fdf_size = get_bits(ntohl(quadlet[1]), 23, 8) == 0x22 ? 32:0; // Event unit size in bits 
     699        unsigned int event_length = (fdf_size * dbs) / 8;       // Event size in bytes 
    699700        unsigned int n_events = (length-8) / event_length; 
    700701 
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h

    r253 r269  
    6060        bool isOnePeriodReady(); 
    6161 
    62     // these two are important to calculate the optimal 
    63     // ISO DMA buffers size 
    64     // an estimate will do 
    65         unsigned int getPacketsPerPeriod() {return 1;}; 
    66         unsigned int getMaxPacketSize() {return 2048;};  
     62        // These two are important to calculate the optimal ISO DMA buffers 
     63        // size.  An estimate will do. 
     64        unsigned int getPacketsPerPeriod() {return (m_period*8000) / m_framerate;}; 
     65        unsigned int getMaxPacketSize() {return m_framerate<=48000?616:(m_framerate<=96000?1032:1160);};  
    6766 
    6867        virtual void setVerboseLevel(int l); 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.cpp

    r267 r269  
    4242 
    4343/* ======================================================================= */ 
    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. 
     44/* Provide a mechanism for allocating iso channels to MOTU interfaces. 
     45 * 
     46 * FIXME: This is overly simplistic at present since it assumes there are no 
     47 * other users of iso channels on the firewire bus except MOTU interfaces.  
     48 * It does however allow more than one MOTU interface to exist on the same 
     49 * bus.  For now the first MOTU discovered will be allocated iso channels 0 
     50 * (send) and 1 (receive) which mirrors what the official driver appears to 
     51 * do.  Ultimately we need code to query the IRM for iso channels. 
    5052 */ 
    5153static signed int next_iso_recv_channel_num = 1; 
     
    5860 * are used for iso receive.  No provision is made to reuse previously 
    5961 * allocated channels in the event that the applicable interface has been 
    60  * removed - this may change in future
     62 * removed - this will change in future to use the IRM
    6163 */ 
    6264        if (next_iso_recv_channel_num < 64) { 
     
    7274 * are used for iso receive.  No provision is made to reuse previously 
    7375 * allocated channels in the event that the applicable interface has been 
    74  * removed - this may change in future
     76 * removed - this will all change in future to use the IRM
    7577 */ 
    7678        if (next_iso_send_channel_num < 64) { 
     
    247249 
    248250        int samp_freq = getSamplingFrequency(); 
    249         enum EMotuOpticalMode optical_mode = getOpticalMode(); 
     251        unsigned int optical_mode = getOpticalMode(); 
    250252 
    251253        debugOutput(DEBUG_LEVEL_NORMAL, "Preparing MotuDevice...\n" ); 
     
    270272        FreebobStreaming::Port *p=NULL; 
    271273 
    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); 
     274        // Add audio capture ports 
     275        if (!addDirPorts(FreebobStreaming::Port::E_Capture, samp_freq, optical_mode)) { 
     276                return false; 
    293277        } 
    294278 
     
    351335        debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n"); 
    352336 
    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         } 
     337        // Add audio playback ports 
     338        if (!addDirPorts(FreebobStreaming::Port::E_Playback, samp_freq, optical_mode)) { 
     339                return false; 
     340        } 
    377341 
    378342//      // example of adding an midi port: 
     
    530494} 
    531495 
    532 enum MotuDevice::EMotuOpticalMode MotuDevice::getOpticalMode(void) { 
     496unsigned int MotuDevice::getOpticalMode(void) { 
    533497        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? 
    537 fprintf(stderr,"route-port conf reg: 0x%08x\n",reg); 
    538         return (enum EMotuOpticalMode)((reg & 0x00000300) >> 8); 
    539 
    540  
    541 signed int MotuDevice::setOpticalMode(enum EMotuOpticalMode mode) { 
    542   // FIXME: needs implementing 
    543   return -1; 
    544 
    545  
     498        return reg & MOTUFW_OPTICAL_MODE_MASK; 
     499
     500 
     501signed int MotuDevice::setOpticalMode(unsigned int mode) { 
     502        unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF); 
     503 
     504        // FIXME: there seems to be more to it than this. 
     505        reg &= ~MOTUFW_OPTICAL_MODE_MASK; 
     506        reg |= mode & MOTUFW_OPTICAL_MODE_MASK; 
     507        return WriteRegister(MOTUFW_REG_ROUTE_PORT_CONF, reg); 
     508
     509 
     510/* ======================================================================= */ 
     511 
     512bool MotuDevice::addPort(FreebobStreaming::StreamProcessor *s_processor, 
     513  char *name, enum FreebobStreaming::Port::E_Direction direction,  
     514  int position, int size) { 
     515/* 
     516 * Internal helper function to add a MOTU port to a given stream processor.  
     517 * This just saves the unnecessary replication of what is essentially 
     518 * boilerplate code.  Note that the port name is freed by this function 
     519 * prior to exit. 
     520 */ 
     521FreebobStreaming::Port *p=NULL; 
     522 
     523        p = new FreebobStreaming::MotuAudioPort(name, direction, position, size); 
     524 
     525        if (!p) { 
     526                debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",name); 
     527        } else { 
     528                if (!s_processor->addPort(p)) { 
     529                        debugWarning("Could not register port with stream processor\n"); 
     530                        free(name); 
     531                        return false; 
     532                } else { 
     533                        debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",name); 
     534                } 
     535        } 
     536        free(name); 
     537        return true; 
     538
     539/* ======================================================================= */ 
     540 
     541bool MotuDevice::addDirPorts( 
     542  enum FreebobStreaming::Port::E_Direction direction,  
     543  unsigned int sample_rate, unsigned int optical_mode) { 
     544/* 
     545 * Internal helper method: adds all required ports for the given direction 
     546 * based on the indicated sample rate and optical mode. 
     547 * 
     548 * Notes: currently ports are not created if they are disabled due to sample 
     549 * rate or optical mode.  However, it might be better to unconditionally 
     550 * create all ports and just disable those which are not active. 
     551 */ 
     552const char *mode_str = direction==FreebobStreaming::Port::E_Capture?"cap":"pbk"; 
     553const char *aux_str = direction==FreebobStreaming::Port::E_Capture?"Mix1":"Phones"; 
     554FreebobStreaming::StreamProcessor *s_processor; 
     555unsigned int i; 
     556char *buff; 
     557 
     558        if (direction == FreebobStreaming::Port::E_Capture) { 
     559                s_processor = m_receiveProcessor; 
     560        } else { 
     561                s_processor = m_transmitProcessor; 
     562        } 
     563 
     564        // Unconditionally add the 8 analog capture ports since they are 
     565        // always present no matter what the device configuration is. 
     566        for (i=0; i<8; i++) { 
     567                asprintf(&buff,"dev%d_%s_Analog%d", m_id, mode_str, i+1); 
     568                if (!addPort(s_processor, buff, direction, 0, 0)) 
     569                        return false; 
     570        } 
     571 
     572        // AES/EBU ports are present for 1x and 2x sampling rates 
     573        if (sample_rate <= 96000) { 
     574                for (i=0; i<2; i++) { 
     575                        asprintf(&buff,"dev%d_%s_AES/EBU%d", m_id, mode_str, i+1); 
     576                        if (!addPort(s_processor, buff, direction, 0, 0)) 
     577                                return false; 
     578                } 
     579        } 
     580 
     581        // SPDIF ports are present for 1x and 2x sampling rates so long 
     582        // as the optical mode is not TOSLINK. 
     583        if (sample_rate<=96000 && optical_mode!=MOTUFW_OPTICAL_MODE_TOSLINK) { 
     584                for (i=0; i<2; i++) { 
     585                        asprintf(&buff,"dev%d_%s_SPDIF%d", m_id, mode_str, i+1); 
     586                        if (!addPort(s_processor, buff, direction, 0, 0)) 
     587                                return false; 
     588                } 
     589        } 
     590 
     591        // ADAT ports 1-4 are present for 1x and 2x sampling rates so long 
     592        // as the optical mode is set to ADAT. 
     593        if (sample_rate<=96000 && optical_mode==MOTUFW_OPTICAL_MODE_ADAT) { 
     594                for (i=0; i<4; i++) { 
     595                        asprintf(&buff,"dev%d_%s_ADAT%d", m_id, mode_str, i+1); 
     596                        if (!addPort(s_processor, buff, direction, 0, 0)) 
     597                                return false; 
     598                } 
     599        } 
     600 
     601        // ADAT ports 5-8 are present for 1x sampling rates so long as the 
     602        // optical mode is set to ADAT. 
     603        if (sample_rate<=48000 && optical_mode==MOTUFW_OPTICAL_MODE_ADAT) { 
     604                for (i=4; i<8; i++) { 
     605                        asprintf(&buff,"dev%d_%s_ADAT%d", m_id, mode_str, i+1); 
     606                        if (!addPort(s_processor, buff, direction, 0, 0)) 
     607                                return false; 
     608                } 
     609        } 
     610 
     611        // Finally add ports for the Mix1 return / Phones send which is 
     612        // present for 1x and 2x sampling rates. 
     613        if (sample_rate<=96000) { 
     614                for (i=0; i<2; i++) { 
     615                        asprintf(&buff,"dev%d_%s_%s-%c", m_id, mode_str, 
     616                          aux_str, i==0?'L':'R'); 
     617                        if (!addPort(s_processor, buff, direction, 0, 0)) 
     618                                return false; 
     619                } 
     620        } 
     621 
     622        return true; 
     623
    546624/* ======================================================================== */ 
    547625 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.h

    r267 r269  
    3030#include "libstreaming/MotuStreamProcessor.h" 
    3131 
    32 #define MOTUFW_BASE_ADDR     0xfffff0000000ULL 
     32#define MOTUFW_BASE_ADDR                0xfffff0000000ULL 
    3333#define MOTUFW_BASE_RATE_44100          (0<<3) 
    3434#define MOTUFW_BASE_RATE_48000          (1<<3) 
     
    3838#define MOTUFW_BASE_RATE_MASK           (0x00000008) 
    3939#define MOTUFW_RATE_MULTIPLIER_MASK     (0x00000030) 
     40 
     41#define MOTUFW_OPTICAL_MODE_OFF         (0<<8) 
     42#define MOTUFW_OPTICAL_MODE_ADAT        (1<<8) 
     43#define MOTUFW_OPTICAL_MODE_TOSLINK     (2<<8) 
     44#define MOTUFW_OPTICAL_MODE_MASK        (0x00000300) 
    4045 
    4146/* Device registers */ 
     
    5560      MOTUFW_MODEL_828mkII  = 0x0001, 
    5661      MOTUFW_MODEL_TRAVELER = 0x0002, 
    57     }; 
    58  
    59     enum EMotuOpticalMode { 
    60       MOTUFW_OPTICAL_OFF      = 0, 
    61       MOTUFW_OPTICAL_ADAT     = 1, 
    62       MOTUFW_OPTICAL_TOSLINK  = 2, 
    6362    }; 
    6463 
     
    9190    signed int getIsoRecvChannel(void); 
    9291    signed int getIsoSendChannel(void); 
    93     enum EMotuOpticalMode getOpticalMode(void); 
    94     signed int setOpticalMode(enum EMotuOpticalMode mode); 
     92    unsigned int getOpticalMode(void); 
     93    signed int setOpticalMode(unsigned int mode); 
    9594   
    9695protected: 
     
    107106 
    108107private: 
    109  
     108        bool addPort(FreebobStreaming::StreamProcessor *s_processor, 
     109                char *name,  
     110                enum FreebobStreaming::Port::E_Direction direction, 
     111                int position, int size); 
     112        bool MotuDevice::addDirPorts( 
     113                enum FreebobStreaming::Port::E_Direction direction, 
     114                unsigned int sample_rate, unsigned int optical_mode); 
     115         
    110116        unsigned int ReadRegister(unsigned int reg); 
    111117        signed int WriteRegister(unsigned int reg, quadlet_t data); 
  • branches/libfreebob-2.0/tests/streaming/Makefile.am

    r267 r269  
    2727teststreaming_LDADD   = @top_builddir@src/libfreebob.la \ 
    2828        $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
    29 #  
    30 # teststreaming2_SOURCES = teststreaming2.c debugtools.c 
    31 # teststreaming2_LDADD   = @top_builddir@src/libfreebob.la \ 
    32 #     $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
     29  
     30teststreaming2_SOURCES = teststreaming2.c debugtools.c 
     31teststreaming2_LDADD   = @top_builddir@src/libfreebob.la \ 
     32      $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
    3333#  
    3434# teststreaming3_SOURCES = teststreaming3.c debugtools.c 
     
    4040#       $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 
    4141 
    42 noinst_PROGRAMS = test-isohandling teststreaming 
     42noinst_PROGRAMS = test-isohandling teststreaming teststreaming2 
    4343noinst_HEADERS = debugtools.h 
    4444 
  • branches/libfreebob-2.0/tests/streaming/teststreaming2.c

    r194 r269  
    7676        dev_options.nb_buffers=3; 
    7777 
    78         dev_options.port=1
     78        dev_options.port=0
    7979        dev_options.node_id=-1; 
    8080         
     
    9999                        case freebob_stream_type_audio: 
    100100                                /* assign the audiobuffer to the stream */ 
    101                                 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i]), freebob_buffer_type_uint24); 
     101                                freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 
    102102                                break; 
    103103                                // this is done with read/write routines because the nb of bytes can differ. 
     
    179179        } 
    180180 
    181         // start the streaming layer 
     181        // prepare and start the streaming layer 
     182        freebob_streaming_prepare(dev); 
    182183        freebob_streaming_start(dev); 
    183184