Changeset 967
- Timestamp:
- 03/22/08 14:48:09 (15 years ago)
- Files:
-
- trunk/libffado/libffado/ffado.h (modified) (1 diff)
- trunk/libffado/SConstruct (modified) (1 diff)
- trunk/libffado/src/devicemanager.cpp (modified) (2 diffs)
- trunk/libffado/src/devicemanager.h (modified) (1 diff)
- trunk/libffado/src/ffado.cpp (modified) (1 diff)
- trunk/libffado/src/ffadodevice.cpp (modified) (4 diffs)
- trunk/libffado/src/ffadodevice.h (modified) (2 diffs)
- trunk/libffado/src/genericavc/avc_avdevice.cpp (modified) (32 diffs)
- trunk/libffado/src/libieee1394/IsoHandler.cpp (modified) (1 diff)
- trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (modified) (1 diff)
- trunk/libffado/src/libieee1394/IsoHandlerManager.h (modified) (2 diffs)
- trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp (modified) (5 diffs)
- trunk/libffado/src/libstreaming/generic/StreamProcessor.h (modified) (3 diffs)
- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (modified) (9 diffs)
- trunk/libffado/src/libstreaming/StreamProcessorManager.h (modified) (4 diffs)
- trunk/libffado/src/libutil/Mutex.h (added)
- trunk/libffado/src/libutil/PosixMutex.cpp (added)
- trunk/libffado/src/libutil/PosixMutex.h (added)
- trunk/libffado/src/SConscript (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/libffado/ffado.h
r864 r967 222 222 */ 223 223 typedef enum { 224 ffado_wait_shutdown = -3, 224 225 ffado_wait_error = -2, 225 226 ffado_wait_xrun = -1, trunk/libffado/SConstruct
r948 r967 24 24 # 25 25 26 FFADO_API_VERSION=" 7"27 FFADO_VERSION="1.999.1 6"26 FFADO_API_VERSION="8" 27 FFADO_VERSION="1.999.17" 28 28 29 29 import os trunk/libffado/src/devicemanager.cpp
r964 r967 225 225 { 226 226 (*it)->handleBusReset(); 227 } 228 229 // notify the streamprocessormanager of the busreset 230 if(m_processorManager) { 231 m_processorManager->handleBusReset(); 232 } else { 233 debugWarning("No valid SPM\n"); 227 234 } 228 235 … … 732 739 return eWR_OK; 733 740 } else { 734 debugWarning("XRUN detected\n"); 735 // do xrun recovery 736 if(m_processorManager->handleXrun()) { 737 return eWR_Xrun; 741 if(m_processorManager->shutdownNeeded()) { 742 debugWarning("Shutdown requested\n"); 743 return eWR_Shutdown; 738 744 } else { 739 debugError("Could not handle XRUN\n"); 740 return eWR_Error; 745 debugWarning("XRUN detected\n"); 746 // do xrun recovery 747 if(m_processorManager->handleXrun()) { 748 return eWR_Xrun; 749 } else { 750 debugError("Could not handle XRUN\n"); 751 return eWR_Error; 752 } 741 753 } 742 754 } trunk/libffado/src/devicemanager.h
r960 r967 72 72 eWR_Xrun, 73 73 eWR_Error, 74 eWR_Shutdown, 74 75 }; 75 76 trunk/libffado/src/ffado.cpp
r864 r967 251 251 xruns++; 252 252 return ffado_wait_xrun; 253 } else if (result == DeviceManager::eWR_Shutdown) { 254 debugWarning("Streaming system requests shutdown.\n"); 255 return ffado_wait_shutdown; 253 256 } else { 254 debugError(" Unhandled XRUN (BUG)\n");257 debugError("Error condition while waiting (Unhandled XRUN)\n"); 255 258 xruns++; 256 259 return ffado_wait_error; trunk/libffado/src/ffadodevice.cpp
r958 r967 142 142 FFADODevice::setId( unsigned int id) 143 143 { 144 m_DeviceMutex.Lock(); 144 145 bool retval; 145 146 // FIXME: decent ID system nescessary … … 149 150 150 151 retval=setOption("id",idstr.str()); 152 m_DeviceMutex.Unlock(); 151 153 return retval; 152 154 } … … 156 158 { 157 159 debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n"); 158 160 159 161 // update the config rom node id 160 162 sleep(1); 163 164 m_DeviceMutex.Lock(); 161 165 getConfigRom().setVerboseLevel(getDebugLevel()); 162 166 getConfigRom().updatedNodeId(); 163 167 m_DeviceMutex.Unlock(); 164 168 } 165 169 … … 169 173 debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 170 174 setDebugLevel(l); 175 m_DeviceMutex.setVerboseLevel(l); 171 176 getConfigRom().setVerboseLevel(l); 172 177 } trunk/libffado/src/ffadodevice.h
r958 r967 27 27 28 28 #include "libutil/OptionContainer.h" 29 #include "libutil/PosixMutex.h" 30 29 31 #include "libcontrol/BasicElements.h" 30 32 … … 438 440 protected: 439 441 DECLARE_DEBUG_MODULE; 442 Util::PosixMutex m_DeviceMutex; 440 443 }; 441 444 trunk/libffado/src/genericavc/avc_avdevice.cpp
r864 r967 98 98 AvDevice::discover() 99 99 { 100 m_DeviceMutex.Lock(); 100 101 // check if we already have a valid VendorModel entry 101 102 // e.g. because a subclass called this function … … 110 111 111 112 if (!GenericAVC::VendorModel::isValid(m_model)) { 113 m_DeviceMutex.Unlock(); 112 114 return false; 113 115 } … … 118 120 if ( !Unit::discover() ) { 119 121 debugError( "Could not discover unit\n" ); 122 m_DeviceMutex.Unlock(); 120 123 return false; 121 124 } … … 123 126 if((getAudioSubunit( 0 ) == NULL)) { 124 127 debugError( "Unit doesn't have an Audio subunit.\n"); 128 m_DeviceMutex.Unlock(); 125 129 return false; 126 130 } 127 131 if((getMusicSubunit( 0 ) == NULL)) { 128 132 debugError( "Unit doesn't have a Music subunit.\n"); 129 return false; 130 } 133 m_DeviceMutex.Unlock(); 134 return false; 135 } 136 m_DeviceMutex.Unlock(); 131 137 132 138 return true; … … 136 142 AvDevice::setVerboseLevel(int l) 137 143 { 144 m_DeviceMutex.Lock(); 138 145 setDebugLevel(l); 139 146 m_pPlugManager->setVerboseLevel(l); … … 141 148 AVC::Unit::setVerboseLevel(l); 142 149 debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 150 m_DeviceMutex.Unlock(); 143 151 } 144 152 … … 168 176 AvDevice::setSamplingFrequency( int s ) 169 177 { 178 m_DeviceMutex.Lock(); 170 179 bool snoopMode=false; 171 180 if(!getOption("snoopMode", snoopMode)) { … … 178 187 debugError("In snoop mode it is impossible to set the sample rate.\n"); 179 188 debugError("Please start the client with the correct setting.\n"); 180 return false; 181 } 189 m_DeviceMutex.Unlock(); 190 return false; 191 } 192 m_DeviceMutex.Unlock(); 182 193 return true; 183 194 } else { … … 185 196 if ( !plug ) { 186 197 debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 198 m_DeviceMutex.Unlock(); 187 199 return false; 188 200 } … … 191 203 { 192 204 debugError( "setSampleRate: Setting sample rate failed\n" ); 205 m_DeviceMutex.Unlock(); 193 206 return false; 194 207 } … … 197 210 if ( !plug ) { 198 211 debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 212 m_DeviceMutex.Unlock(); 199 213 return false; 200 214 } … … 203 217 { 204 218 debugError( "setSampleRate: Setting sample rate failed\n" ); 219 m_DeviceMutex.Unlock(); 205 220 return false; 206 221 } … … 209 224 "setSampleRate: Set sample rate to %d\n", 210 225 s ); 226 m_DeviceMutex.Unlock(); 211 227 return true; 212 228 } 213 229 // not executable 230 m_DeviceMutex.Unlock(); 214 231 return false; 215 232 … … 219 236 AvDevice::getSupportedClockSources() { 220 237 FFADODevice::ClockSourceVector r; 238 239 m_DeviceMutex.Lock(); 221 240 222 241 PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( … … 256 275 } 257 276 277 m_DeviceMutex.Unlock(); 258 278 return r; 259 279 } … … 267 287 } 268 288 289 m_DeviceMutex.Lock(); 269 290 for ( SyncInfoVector::const_iterator it 270 291 = getSyncInfos().begin(); … … 275 296 276 297 if (si.m_source==src) { 298 m_DeviceMutex.Unlock(); 277 299 return setActiveSync(si); 278 300 } 279 301 } 302 m_DeviceMutex.Unlock(); 280 303 281 304 return false; … … 368 391 AvDevice::lock() { 369 392 bool snoopMode=false; 393 m_DeviceMutex.Lock(); 370 394 if(!getOption("snoopMode", snoopMode)) { 371 395 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); … … 377 401 // return Unit::reserve(4); 378 402 } 403 m_DeviceMutex.Unlock(); 379 404 380 405 return true; … … 384 409 AvDevice::unlock() { 385 410 bool snoopMode=false; 411 m_DeviceMutex.Lock(); 386 412 if(!getOption("snoopMode", snoopMode)) { 387 413 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); … … 393 419 // return Unit::reserve(0); 394 420 } 421 m_DeviceMutex.Unlock(); 395 422 return true; 396 423 } … … 408 435 AvDevice::prepare() { 409 436 bool snoopMode=false; 437 m_DeviceMutex.Lock(); 410 438 if(!getOption("snoopMode", snoopMode)) { 411 439 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); … … 418 446 if ( !inputPlug ) { 419 447 debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 448 m_DeviceMutex.Unlock(); 420 449 return false; 421 450 } … … 423 452 if ( !outputPlug ) { 424 453 debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 454 m_DeviceMutex.Unlock(); 425 455 return false; 426 456 } … … 432 462 if ( outputPlug->getNrOfChannels() == 0 ) { 433 463 debugError("Receive plug has no channels\n"); 464 m_DeviceMutex.Unlock(); 434 465 return false; 435 466 } … … 440 471 debugFatal("Could not initialize receive processor!\n"); 441 472 delete p; 473 m_DeviceMutex.Unlock(); 442 474 return false; 443 475 } … … 447 479 debugFatal("Could not add plug to processor!\n"); 448 480 delete p; 481 m_DeviceMutex.Unlock(); 449 482 return false; 450 483 } … … 468 501 (snoopMode?" in snoop mode":"")); 469 502 delete p; 503 m_DeviceMutex.Unlock(); 470 504 return false; 471 505 } … … 475 509 Streaming::Port::E_Capture)) { 476 510 debugFatal("Could not add plug to processor!\n"); 511 m_DeviceMutex.Unlock(); 477 512 return false; 478 513 } … … 481 516 Streaming::Port::E_Playback)) { 482 517 debugFatal("Could not add plug to processor!\n"); 518 m_DeviceMutex.Unlock(); 483 519 return false; 484 520 } … … 491 527 m_transmitProcessors.push_back(p); 492 528 529 m_DeviceMutex.Unlock(); 493 530 return true; 494 531 } … … 592 629 int 593 630 AvDevice::getStreamCount() { 594 return m_receiveProcessors.size() + m_transmitProcessors.size(); 631 int retval; 632 m_DeviceMutex.Lock(); 633 retval = m_receiveProcessors.size() + m_transmitProcessors.size(); 634 m_DeviceMutex.Unlock(); 635 return retval; 595 636 //return 1; 596 637 } trunk/libffado/src/libieee1394/IsoHandler.cpp
r930 r967 353 353 raw1394_read(m_handle, raw1394_get_local_id(m_handle), 354 354 CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); 355 356 // notify the client of the fact that we have died 357 m_Client->handlerDied(); 358 359 if(!disable()) { 360 debugError("(%p) Could not disable IsoHandler\n", this); 361 } 362 363 // request the manager to update it's shadow map 364 m_manager.requestShadowMapUpdate(); 355 365 return 0; 356 366 } trunk/libffado/src/libieee1394/IsoHandlerManager.cpp
r940 r967 292 292 } 293 293 294 void 295 IsoHandlerManager::requestShadowMapUpdate() 296 { 297 if(m_IsoTask) m_IsoTask->requestShadowMapUpdate(); 298 } 299 294 300 bool 295 301 IsoHandlerManager::setThreadParameters(bool rt, int priority) { trunk/libffado/src/libieee1394/IsoHandlerManager.h
r938 r967 107 107 friend class Streaming::StreamProcessorManager; 108 108 friend class IsoTask; 109 friend class IsoHandler; 109 110 110 111 public: … … 151 152 Ieee1394Service& get1394Service() {return m_service;}; 152 153 154 protected: 155 void requestShadowMapUpdate(); 156 153 157 // the state machine 154 158 private: trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp
r938 r967 98 98 if (m_data_buffer) delete m_data_buffer; 99 99 if (m_scratch_buffer) delete[] m_scratch_buffer; 100 } 101 102 void 103 StreamProcessor::handleBusReset() 104 { 105 debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) handling busreset\n", this); 106 // for now, we try and make sure everything is cleanly shutdown 107 if(!stopRunning(-1)) { 108 debugError("Failed to stop SP\n"); 109 } 110 SIGNAL_ACTIVITY; 111 } 112 113 void StreamProcessor::handlerDied() 114 { 115 debugWarning("Handler died for %p\n", this); 116 m_state = ePS_Stopped; 117 m_in_xrun = true; 100 118 } 101 119 … … 1208 1226 1209 1227 bool StreamProcessor::startDryRunning(int64_t t) { 1228 if(getState() == ePS_DryRunning) { 1229 // already in the correct state 1230 return true; 1231 } 1210 1232 if(!scheduleStartDryRunning(t)) { 1211 1233 debugError("Could not schedule transition\n"); … … 1220 1242 1221 1243 bool StreamProcessor::startRunning(int64_t t) { 1244 if(getState() == ePS_Running) { 1245 // already in the correct state 1246 return true; 1247 } 1222 1248 if(!scheduleStartRunning(t)) { 1223 1249 debugError("Could not schedule transition\n"); … … 1232 1258 1233 1259 bool StreamProcessor::stopDryRunning(int64_t t) { 1260 if(getState() == ePS_Stopped) { 1261 // already in the correct state 1262 return true; 1263 } 1234 1264 if(!scheduleStopDryRunning(t)) { 1235 1265 debugError("Could not schedule transition\n"); … … 1244 1274 1245 1275 bool StreamProcessor::stopRunning(int64_t t) { 1276 if(getState() == ePS_DryRunning) { 1277 // already in the correct state 1278 return true; 1279 } 1246 1280 if(!scheduleStopRunning(t)) { 1247 1281 debugError("Could not schedule transition\n"); trunk/libffado/src/libstreaming/generic/StreamProcessor.h
r930 r967 73 73 ePS_Invalid, 74 74 ePS_Created, 75 // ePS_WaitingToStop, FIXME: this will be needed for the MOTU's76 75 ePS_Stopped, 77 76 ePS_WaitingForStream, … … 131 130 bool init(); 132 131 bool prepare(); 132 133 void handleBusReset(); 133 134 134 135 public: // constructor/destructor … … 294 295 // move to private? 295 296 bool xrunOccurred() { return m_in_xrun; }; 297 void handlerDied(); 296 298 297 299 // the ISO interface (can we get rid of this?) trunk/libffado/src/libstreaming/StreamProcessorManager.cpp
r918 r967 47 47 , m_nominal_framerate ( 0 ) 48 48 , m_xruns(0) 49 , m_shutdown_needed(false) 49 50 , m_nbperiods(0) 50 51 { … … 61 62 , m_nominal_framerate ( framerate ) 62 63 , m_xruns(0) 64 , m_shutdown_needed(false) 63 65 , m_nbperiods(0) 64 66 { … … 67 69 68 70 StreamProcessorManager::~StreamProcessorManager() { 71 } 72 73 void 74 StreamProcessorManager::handleBusReset() 75 { 76 debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Handle bus reset...\n", this); 77 78 // FIXME: we request shutdown for now. 79 m_shutdown_needed=true; 80 81 // note that all receive streams are gone once a device is unplugged 82 83 // synchronize with the wait lock 84 m_WaitLock.Lock(); 85 86 debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) got wait lock...\n", this); 87 // cause all SP's to bail out 88 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 89 it != m_ReceiveProcessors.end(); 90 ++it ) 91 { 92 (*it)->handleBusReset(); 93 } 94 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 95 it != m_TransmitProcessors.end(); 96 ++it ) 97 { 98 (*it)->handleBusReset(); 99 } 100 101 m_WaitLock.Unlock(); 69 102 } 70 103 … … 151 184 152 185 debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 153 154 186 m_is_slave=false; 155 187 if(!getOption("slaveMode", m_is_slave)) { 156 188 debugWarning("Could not retrieve slaveMode parameter, defaulting to false\n"); 157 189 } 190 191 m_shutdown_needed=false; 158 192 159 193 // if no sync source is set, select one here … … 692 726 bool start_result = false; 693 727 for (int ntries=0; ntries < STREAMPROCESSORMANAGER_SYNCSTART_TRIES; ntries++) { 728 if(m_shutdown_needed) { 729 debugOutput(DEBUG_LEVEL_VERBOSE, "Shutdown requested...\n"); 730 return true; 731 } 694 732 // put all SP's into dry-running state 695 733 if (!startDryRunning()) { … … 722 760 * ready to be transferred. 723 761 * 724 * @return true if the period is ready, false if an xrun occurred762 * @return true if the period is ready, false if not 725 763 */ 726 764 bool StreamProcessorManager::waitForPeriod() { 727 765 if(m_SyncSource == NULL) return false; 766 if(m_shutdown_needed) return false; 728 767 bool xrun_occurred = false; 729 768 bool period_not_ready = true; 769 770 // grab the wait lock 771 m_WaitLock.Lock(); 730 772 731 773 while(period_not_ready) { … … 778 820 if(xrun_occurred) break; 779 821 // FIXME: make sure we also exit this loop when something else happens (e.g. signal, iso error) 822 823 // if we have to shutdown due to some async event (busreset), do so 824 if(m_shutdown_needed) break; 780 825 } 781 826 … … 861 906 862 907 m_nbperiods++; 908 909 m_WaitLock.Unlock(); 863 910 // now we can signal the client that we are (should be) ready 864 911 return !xrun_occurred; … … 1033 1080 void StreamProcessorManager::setVerboseLevel(int l) { 1034 1081 setDebugLevel(l); 1082 m_WaitLock.setVerboseLevel(l); 1035 1083 1036 1084 debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); trunk/libffado/src/libstreaming/StreamProcessorManager.h
r864 r967 30 30 #include "debugmodule/debugmodule.h" 31 31 #include "libutil/Thread.h" 32 #include "libutil/PosixMutex.h" 32 33 #include "libutil/OptionContainer.h" 33 34 … … 58 59 StreamProcessorManager(unsigned int period, unsigned int rate, unsigned int nb_buffers); 59 60 virtual ~StreamProcessorManager(); 61 62 void handleBusReset(); 60 63 61 64 bool prepare(); ///< to be called after the processors are registered … … 102 105 int getDelayedUsecs() {return m_delayed_usecs;}; 103 106 bool xrunOccurred(); 107 bool shutdownNeeded() {return m_shutdown_needed;}; 104 108 int getXrunCount() {return m_xruns;}; 105 109 … … 151 155 unsigned int m_nominal_framerate; 152 156 unsigned int m_xruns; 157 bool m_shutdown_needed; 153 158 154 159 unsigned int m_nbperiods; 160 161 Util::PosixMutex m_WaitLock; 155 162 156 163 DECLARE_DEBUG_MODULE; trunk/libffado/src/SConscript
r959 r967 75 75 libutil/PacketBuffer.cpp \ 76 76 libutil/OptionContainer.cpp \ 77 libutil/PosixMutex.cpp \ 77 78 libutil/PosixThread.cpp \ 78 79 libutil/ringbuffer.c \