Changeset 269
- Timestamp:
- 06/20/06 23:46:20 (16 years ago)
- Files:
-
- branches/libfreebob-2.0/src/libstreaming/freebob_streaming.cpp (modified) (2 diffs)
- branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp (modified) (2 diffs)
- branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h (modified) (1 diff)
- branches/libfreebob-2.0/src/motu/motu_avdevice.cpp (modified) (7 diffs)
- branches/libfreebob-2.0/src/motu/motu_avdevice.h (modified) (5 diffs)
- branches/libfreebob-2.0/tests/streaming/Makefile.am (modified) (2 diffs)
- branches/libfreebob-2.0/tests/streaming/teststreaming2.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libfreebob-2.0/src/libstreaming/freebob_streaming.cpp
r265 r269 456 456 assert(p); 457 457 458 p->useExternalBuffer(true); 458 459 p->setExternalBufferAddress((void *)buff); 459 460 … … 468 469 assert(p); 469 470 471 p->useExternalBuffer(true); 470 472 p->setExternalBufferAddress((void *)buff); 471 473 branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp
r267 r269 293 293 } 294 294 295 // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits296 // 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. 297 297 if (max_packet_size > (unsigned int)getpagesize()) 298 298 max_packet_size = getpagesize(); … … 351 351 } 352 352 353 // FIXME: this is all very well, but libraw1394 as of 1.2.1 implicitly limits354 // 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. 355 355 if (max_packet_size > (unsigned int)getpagesize()) 356 356 max_packet_size = getpagesize(); branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp
r268 r269 691 691 // no isodata. 692 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. 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). 695 696 quadlet_t *quadlet = (quadlet_t *)data; 696 unsigned int dbs = get_bits(ntohl(quadlet[0]), 23, 8); // ISO data block sizein terms of fdf_size697 unsigned int fdf_size = get_bits(ntohl(quadlet[1]), 23, 8) == 0x22 ? 32:0; // ISO blockunit size in bits698 unsigned int event_length = (fdf_size * dbs) / 8; // Event (aka ISO block)size in bytes697 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 699 700 unsigned int n_events = (length-8) / event_length; 700 701 branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h
r253 r269 60 60 bool isOnePeriodReady(); 61 61 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);}; 67 66 68 67 virtual void setVerboseLevel(int l); branches/libfreebob-2.0/src/motu/motu_avdevice.cpp
r267 r269 42 42 43 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. 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. 50 52 */ 51 53 static signed int next_iso_recv_channel_num = 1; … … 58 60 * are used for iso receive. No provision is made to reuse previously 59 61 * 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. 61 63 */ 62 64 if (next_iso_recv_channel_num < 64) { … … 72 74 * are used for iso receive. No provision is made to reuse previously 73 75 * 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. 75 77 */ 76 78 if (next_iso_send_channel_num < 64) { … … 247 249 248 250 int samp_freq = getSamplingFrequency(); 249 enum EMotuOpticalModeoptical_mode = getOpticalMode();251 unsigned int optical_mode = getOpticalMode(); 250 252 251 253 debugOutput(DEBUG_LEVEL_NORMAL, "Preparing MotuDevice...\n" ); … … 270 272 FreebobStreaming::Port *p=NULL; 271 273 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; 293 277 } 294 278 … … 351 335 debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n"); 352 336 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 } 377 341 378 342 // // example of adding an midi port: … … 530 494 } 531 495 532 enum MotuDevice::EMotuOpticalModeMotuDevice::getOpticalMode(void) {496 unsigned int MotuDevice::getOpticalMode(void) { 533 497 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 501 signed 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 512 bool 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 */ 521 FreebobStreaming::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 541 bool 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 */ 552 const char *mode_str = direction==FreebobStreaming::Port::E_Capture?"cap":"pbk"; 553 const char *aux_str = direction==FreebobStreaming::Port::E_Capture?"Mix1":"Phones"; 554 FreebobStreaming::StreamProcessor *s_processor; 555 unsigned int i; 556 char *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 } 546 624 /* ======================================================================== */ 547 625 branches/libfreebob-2.0/src/motu/motu_avdevice.h
r267 r269 30 30 #include "libstreaming/MotuStreamProcessor.h" 31 31 32 #define MOTUFW_BASE_ADDR 0xfffff0000000ULL32 #define MOTUFW_BASE_ADDR 0xfffff0000000ULL 33 33 #define MOTUFW_BASE_RATE_44100 (0<<3) 34 34 #define MOTUFW_BASE_RATE_48000 (1<<3) … … 38 38 #define MOTUFW_BASE_RATE_MASK (0x00000008) 39 39 #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) 40 45 41 46 /* Device registers */ … … 55 60 MOTUFW_MODEL_828mkII = 0x0001, 56 61 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 62 }; 64 63 … … 91 90 signed int getIsoRecvChannel(void); 92 91 signed int getIsoSendChannel(void); 93 enum EMotuOpticalModegetOpticalMode(void);94 signed int setOpticalMode( enum EMotuOpticalModemode);92 unsigned int getOpticalMode(void); 93 signed int setOpticalMode(unsigned int mode); 95 94 96 95 protected: … … 107 106 108 107 private: 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 110 116 unsigned int ReadRegister(unsigned int reg); 111 117 signed int WriteRegister(unsigned int reg, quadlet_t data); branches/libfreebob-2.0/tests/streaming/Makefile.am
r267 r269 27 27 teststreaming_LDADD = @top_builddir@src/libfreebob.la \ 28 28 $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 29 #30 #teststreaming2_SOURCES = teststreaming2.c debugtools.c31 #teststreaming2_LDADD = @top_builddir@src/libfreebob.la \32 #$(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) 33 33 # 34 34 # teststreaming3_SOURCES = teststreaming3.c debugtools.c … … 40 40 # $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 41 41 42 noinst_PROGRAMS = test-isohandling teststreaming 42 noinst_PROGRAMS = test-isohandling teststreaming teststreaming2 43 43 noinst_HEADERS = debugtools.h 44 44 branches/libfreebob-2.0/tests/streaming/teststreaming2.c
r194 r269 76 76 dev_options.nb_buffers=3; 77 77 78 dev_options.port= 1;78 dev_options.port=0; 79 79 dev_options.node_id=-1; 80 80 … … 99 99 case freebob_stream_type_audio: 100 100 /* 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])); 102 102 break; 103 103 // this is done with read/write routines because the nb of bytes can differ. … … 179 179 } 180 180 181 // start the streaming layer 181 // prepare and start the streaming layer 182 freebob_streaming_prepare(dev); 182 183 freebob_streaming_start(dev); 183 184