Changeset 230
- Timestamp:
- 05/28/06 10:40:49 (16 years ago)
- Files:
-
- branches/libfreebob-2.0/src/bebob_light/bebob_light_avdevice.cpp (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/AmdtpStreamProcessor.cpp (modified) (14 diffs)
- branches/libfreebob-2.0/src/libstreaming/FreebobPosixThread.cpp (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/FreebobPosixThread.h (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/freebob_streaming.cpp (modified) (2 diffs)
- branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp (modified) (3 diffs)
- branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/IsoStream.cpp (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/IsoStream.h (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/Port.cpp (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/Port.h (modified) (1 diff)
- branches/libfreebob-2.0/src/libstreaming/StreamProcessor.cpp (modified) (7 diffs)
- branches/libfreebob-2.0/src/libstreaming/StreamProcessor.h (modified) (4 diffs)
- branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp (modified) (20 diffs)
- branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libfreebob-2.0/src/bebob_light/bebob_light_avdevice.cpp
r227 r230 1912 1912 1913 1913 } 1914 1914 1915 int 1915 1916 AvDevice::stopStreamByIndex(int i) { branches/libfreebob-2.0/src/libstreaming/AmdtpStreamProcessor.cpp
r228 r230 119 119 120 120 // signal underrun 121 // FIXME: underrun signaling turned off!!122 121 m_xruns++; 123 122 … … 141 140 // update the frame counter 142 141 m_framecounter+=nevents; 142 if(m_framecounter>m_period) { 143 retval=RAW1394_ISO_DEFER; 144 } 143 145 144 146 return (int)retval; … … 153 155 freebob_ringbuffer_reset(m_event_buffer); 154 156 157 // we should prefill the event buffer 158 int i=m_nb_buffers; 159 while(i--) { 160 if(!transferSilence()) { 161 debugFatal("Could not prefill transmit stream\n"); 162 return false; 163 } 164 } 165 155 166 // reset all non-device specific stuff 156 167 // i.e. the iso stream and the associated ports 157 return TransmitStreamProcessor::reset(); 168 if(!TransmitStreamProcessor::reset()) { 169 debugFatal("Could not do base class reset\n"); 170 return false; 171 } 172 return true; 158 173 } 159 174 … … 318 333 319 334 // we should prefill the event buffer 320 // FIXME: i have to solve this otherwise because the ports aren't ready yet321 // especially if there are no internal buffers=> segfault322 335 int i=m_nb_buffers; 323 336 while(i--) { … … 399 412 400 413 if(vec[0].len==0) { // this indicates a full event buffer 401 debugError(" Event buffer overrun in processor %d\n",this);414 debugError("XMT: Event buffer overrun in processor %p\n",this); 402 415 break; 403 416 } … … 416 429 if(xrun<0) { 417 430 // xrun detected 418 debugError(" Frame buffer underrun in processor %d\n",this);431 debugError("XMT: Frame buffer underrun in processor %p\n",this); 419 432 break; 420 433 } … … 444 457 if(xrun<0) { 445 458 // xrun detected 446 debugError(" Frame buffer underrun in processor %d\n",this);459 debugError("XMT: Frame buffer underrun in processor %p\n",this); 447 460 break; 448 461 } … … 720 733 if (freebob_ringbuffer_write(m_event_buffer,(char *)(data+8),write_size) < write_size) 721 734 { 722 debugWarning("Buffer overrun!\n"); 735 debugWarning("Receive buffer overrun (cycle %d, FC=%d, PC=%d)\n", 736 cycle, m_framecounter, m_handler->getPacketCount()); 723 737 m_xruns++; 724 738 … … 730 744 if (!decodePacketPorts((quadlet_t *)(data+8), nevents, packet->dbc)) { 731 745 debugWarning("Problem decoding Packet Ports\n"); 746 retval=RAW1394_ISO_DEFER; 732 747 } 733 748 } … … 745 760 // update the frame counter 746 761 m_framecounter+=nevents; 762 if(m_framecounter>m_period) { 763 retval=RAW1394_ISO_DEFER; 764 } 747 765 748 766 } else { … … 770 788 // reset all non-device specific stuff 771 789 // i.e. the iso stream and the associated ports 772 return ReceiveStreamProcessor::reset(); 790 if(!ReceiveStreamProcessor::reset()) { 791 debugFatal("Could not do base class reset\n"); 792 return false; 793 } 794 return true; 773 795 } 774 796 … … 951 973 952 974 if(vec[0].len==0) { // this indicates an empty event buffer 953 debugError(" Frame buffer underrun in processor %d\n",this);975 debugError("RCV: Event buffer underrun in processor %p\n",this); 954 976 break; 955 977 } … … 969 991 if(xrun<0) { 970 992 // xrun detected 971 debugError(" Frame buffer underrun in processor %d\n",this);993 debugError("RCV: Frame buffer overrun in processor %p\n",this); 972 994 break; 973 995 } … … 989 1011 if(xrun<0) { 990 1012 // xrun detected 991 debugError(" Frame buffer underrun in processor %d\n",this);1013 debugError("RCV: Frame buffer overrun in processor %p\n",this); 992 1014 break; 993 1015 } branches/libfreebob-2.0/src/libstreaming/FreebobPosixThread.cpp
r210 r230 116 116 return -1; 117 117 } 118 118 119 return 0; 119 120 } branches/libfreebob-2.0/src/libstreaming/FreebobPosixThread.h
r203 r230 78 78 pthread_t GetThreadID(); 79 79 80 void setVerboseLevel(int l) {setDebugLevel(l);}; 80 81 protected: 81 82 branches/libfreebob-2.0/src/libstreaming/freebob_streaming.cpp
r227 r230 229 229 int freebob_streaming_reset(freebob_device_t *dev) { 230 230 debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); 231 /* 232 * Reset means: 233 * 1) Stopping the packetizer thread 234 * 2) Bringing all buffers & connections into a know state 235 * - Clear all capture buffers 236 * - Put nb_periods*period_size of null frames into the playback buffers 237 * 3) Restarting the packetizer thread 238 */ 239 // dev->thread->Stop(); 240 // 241 // dev->processorManager->stop(); 242 // 231 243 232 // dev->processorManager->reset(); 244 //245 // dev->processorManager->start();246 //247 // dev->thread->Start();248 233 249 234 return 0; … … 251 236 252 237 int freebob_streaming_wait(freebob_device_t *dev) { 253 254 static int periods=0; 238 static int periods=0; 255 239 static int periods_print=0; 240 static int xruns=0; 241 256 242 periods++; 257 243 if(periods>periods_print) { 258 244 debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 259 245 debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 246 debugOutput(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); 247 debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 260 248 dev->processorManager->dumpInfo(); 261 debugOutput(DEBUG_LEVEL_VERBOSE, "--------------------------------------------\n"); 262 quadlet_t *addr=(quadlet_t*)(dev->processorManager->getPortByIndex(0, Port::E_Capture)->getBufferAddress()); 263 if (addr) hexDumpQuadlets(addr,10); 264 debugOutput(DEBUG_LEVEL_VERBOSE, "============================================\n"); 249 // debugOutput(DEBUG_LEVEL_VERBOSE, "--------------------------------------------\n"); 250 /* quadlet_t *addr=(quadlet_t*)(dev->processorManager->getPortByIndex(0, Port::E_Capture)->getBufferAddress()); 251 if (addr) hexDumpQuadlets(addr,10);*/ 265 252 debugOutput(DEBUG_LEVEL_VERBOSE, "\n"); 266 253 periods_print+=100; 267 254 } 268 dev->processorManager->waitForPeriod(); 269 return dev->options.period_size; 255 if(dev->processorManager->waitForPeriod()) { 256 return dev->options.period_size; 257 } else { 258 debugWarning("XRUN detected\n"); 259 // do xrun recovery 260 261 dev->processorManager->handleXrun(); 262 xruns++; 263 return -1; 264 } 270 265 } 271 266 branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp
r225 r230 194 194 bool IsoHandlerManager::registerStream(IsoStream *stream) 195 195 { 196 debugOutput( DEBUG_LEVEL_VERBOSE, " enter...\n");196 debugOutput( DEBUG_LEVEL_VERBOSE, "Registering stream %p\n",stream); 197 197 assert(stream); 198 198 … … 327 327 bool IsoHandlerManager::unregisterStream(IsoStream *stream) 328 328 { 329 debugOutput( DEBUG_LEVEL_VERBOSE, " enter...\n");329 debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering stream %p\n",stream); 330 330 assert(stream); 331 331 … … 420 420 debugOutput( DEBUG_LEVEL_VERBOSE, " stopping handler (%p)\n",*it); 421 421 if(!(*it)->stop()){ 422 debugOutput( DEBUG_LEVEL_VERBOSE, " could not st arthandler (%p)\n",*it);422 debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it); 423 423 return false; 424 424 } branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h
r225 r230 79 79 80 80 bool registerStream(IsoStream *); ///< register an iso stream with the manager 81 bool unregisterStream(IsoStream *); ///< unregister an iso stream withthe manager81 bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager 82 82 83 83 bool startHandlers(); ///< start the managed ISO handlers branches/libfreebob-2.0/src/libstreaming/IsoStream.cpp
r225 r230 107 107 108 108 void IsoStream::setHandler(IsoHandler *h) { 109 debugOutput( DEBUG_LEVEL_VERBOSE, "setting han lder of isostream %p to %p\n", this,h);109 debugOutput( DEBUG_LEVEL_VERBOSE, "setting handler of isostream %p to %p\n", this,h); 110 110 m_handler=h; 111 111 } 112 112 113 void IsoStream::clearHandler() { 114 debugOutput( DEBUG_LEVEL_VERBOSE, "clearing handler of isostream %p\n", this); 115 116 m_handler=0; 117 118 }; 113 119 } branches/libfreebob-2.0/src/libstreaming/IsoStream.h
r225 r230 98 98 99 99 void setHandler( IsoHandler * h) ; 100 void clearHandler() {m_handler=0;};100 void clearHandler(); 101 101 102 102 enum EStreamType m_type; branches/libfreebob-2.0/src/libstreaming/Port.cpp
r228 r230 111 111 } 112 112 113 bool Port::reset() { 114 if (m_BufferType==E_RingBuffer) { 115 freebob_ringbuffer_reset(m_ringbuffer); 116 } 117 return true; 118 }; 119 120 113 121 void Port::setVerboseLevel(int l) { 114 122 setDebugLevel(l); branches/libfreebob-2.0/src/libstreaming/Port.h
r228 r230 127 127 128 128 bool prepare() {return true;}; 129 bool reset() {return true;};129 bool reset(); 130 130 131 131 std::string getName() {return m_Name;}; branches/libfreebob-2.0/src/libstreaming/StreamProcessor.cpp
r225 r230 41 41 StreamProcessor::StreamProcessor(enum IsoStream::EStreamType type, int port, int framerate) 42 42 : IsoStream(type, port) 43 , m_nb_buffers(0) 43 44 , m_manager(0) 44 , m_nb_buffers(0)45 45 , m_period(0) 46 46 , m_xruns(0) … … 57 57 } 58 58 59 int StreamProcessor::putPacket(unsigned char *data, unsigned int length,60 unsigned char channel, unsigned char tag, unsigned char sy,61 unsigned int cycle, unsigned int dropped) {62 63 debugWarning("BUG: received packet in StreamProcessor base class!\n");64 65 return -1;66 }67 68 int StreamProcessor::getPacket(unsigned char *data, unsigned int *length,69 unsigned char *tag, unsigned char *sy,70 int cycle, unsigned int dropped, unsigned int max_length) {71 72 debugWarning("BUG: packet requested from StreamProcessor base class!\n");73 74 return -1;75 }76 77 59 void StreamProcessor::dumpInfo() 78 60 { … … 102 84 resetFrameCounter(); 103 85 86 resetXrunCounter(); 87 104 88 // loop over the ports to reset them 105 89 if (!PortManager::resetPorts()) { … … 113 97 return false; 114 98 } 115 99 return true; 100 116 101 } 117 102 … … 178 163 void StreamProcessor::resetFrameCounter() { 179 164 ZERO_ATOMIC((SInt32 *)&m_framecounter); 165 }; 166 167 /** 168 * Resets the xrun counter, in a atomic way. This 169 * is thread safe. 170 */ 171 void StreamProcessor::resetXrunCounter() { 172 ZERO_ATOMIC((SInt32 *)&m_xruns); 180 173 }; 181 174 … … 196 189 } 197 190 198 int ReceiveStreamProcessor::putPacket(unsigned char *data, unsigned int length,199 unsigned char channel, unsigned char tag, unsigned char sy,200 unsigned int cycle, unsigned int dropped) {201 202 debugOutput( DEBUG_LEVEL_VERY_VERBOSE,203 "received packet: length=%d, channel=%d, cycle=%d\n",204 length, channel, cycle );205 206 return 0;207 }208 209 191 void ReceiveStreamProcessor::setVerboseLevel(int l) { 210 192 setDebugLevel(l); … … 223 205 } 224 206 225 int TransmitStreamProcessor::getPacket(unsigned char *data, unsigned int *length,226 unsigned char *tag, unsigned char *sy,227 int cycle, unsigned int dropped, unsigned int max_length) {228 *length=0;229 *tag = 1;230 *sy = 0;231 232 return 0;233 }234 235 207 void TransmitStreamProcessor::setVerboseLevel(int l) { 236 208 setDebugLevel(l); branches/libfreebob-2.0/src/libstreaming/StreamProcessor.h
r225 r230 63 63 putPacket(unsigned char *data, unsigned int length, 64 64 unsigned char channel, unsigned char tag, unsigned char sy, 65 unsigned int cycle, unsigned int dropped) ;65 unsigned int cycle, unsigned int dropped) = 0; 66 66 virtual int 67 67 getPacket(unsigned char *data, unsigned int *length, 68 68 unsigned char *tag, unsigned char *sy, 69 int cycle, unsigned int dropped, unsigned int max_length) ;69 int cycle, unsigned int dropped, unsigned int max_length) = 0; 70 70 71 71 virtual enum EProcessorType getType() =0; … … 73 73 bool xrunOccurred() { return (m_xruns>0);}; 74 74 75 bool isOnePeriodReady() { return (m_framecounter > m_period); };75 bool isOnePeriodReady() { return (m_framecounter > (int)m_period); }; 76 76 unsigned int getNbPeriodsReady() { if(m_period) return m_framecounter/m_period; else return 0;}; 77 77 void decrementFrameCounter(); 78 79 // move to private? 78 80 void resetFrameCounter(); 81 void resetXrunCounter(); 79 82 80 83 bool isRunning(); ///< returns true if there is some stream data processed … … 133 136 134 137 virtual enum EProcessorType getType() {return E_Receive;}; 135 138 139 virtual int 140 getPacket(unsigned char *data, unsigned int *length, 141 unsigned char *tag, unsigned char *sy, 142 int cycle, unsigned int dropped, unsigned int max_length) {return 0;}; 143 136 144 virtual int putPacket(unsigned char *data, unsigned int length, 137 145 unsigned char channel, unsigned char tag, unsigned char sy, 138 unsigned int cycle, unsigned int dropped) ;146 unsigned int cycle, unsigned int dropped) = 0; 139 147 virtual void setVerboseLevel(int l); 140 148 … … 160 168 161 169 virtual int 170 putPacket(unsigned char *data, unsigned int length, 171 unsigned char channel, unsigned char tag, unsigned char sy, 172 unsigned int cycle, unsigned int dropped) {return 0;}; 173 174 virtual int 162 175 getPacket(unsigned char *data, unsigned int *length, 163 176 unsigned char *tag, unsigned char *sy, 164 int cycle, unsigned int dropped, unsigned int max_length) ;177 int cycle, unsigned int dropped, unsigned int max_length) = 0; 165 178 virtual void setVerboseLevel(int l); 166 179 branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp
r227 r230 151 151 152 152 // and the tread that runs the runner 153 streamingThread=new FreebobPosixThread(this);154 if(! streamingThread) {153 m_streamingThread=new FreebobPosixThread(this); 154 if(!m_streamingThread) { 155 155 debugFatal("Could not create streaming thread\n"); 156 156 return false; 157 157 } 158 159 m_streamingThread->setVerboseLevel(getDebugLevel()); 158 160 159 161 m_isoManager=new IsoHandlerManager(); … … 164 166 } 165 167 168 m_isoManager->setVerboseLevel(getDebugLevel()); 169 166 170 if(!m_isoManager->Init()) { 167 171 debugFatal("Could not init IsoHandlerManager\n"); 168 172 return false; 169 173 } 174 175 return true; 176 } 177 178 bool StreamProcessorManager::Init() 179 { 180 debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing runner...\n"); 181 182 // no xrun has occurred (yet) 183 m_xrun_happened=false; 170 184 171 185 if(sem_init(&m_period_semaphore, 0, 0)) { … … 173 187 debugFatal( " Error: %s\n",strerror(errno)); 174 188 return false; 175 } else { 176 debugOutput( DEBUG_LEVEL_VERBOSE,"Successfull init of packet transfer semaphore\n"); 177 } 178 179 return true; 180 } 181 182 bool StreamProcessorManager::Init() 183 { 184 debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 185 189 } 190 186 191 return true; 187 192 } … … 218 223 bool StreamProcessorManager::Execute() 219 224 { 225 226 bool period_ready=true; 227 bool xrun_has_occured=false; 228 220 229 debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 221 230 if(!m_isoManager->Execute()) { … … 223 232 return false; 224 233 } 225 226 bool period_ready=true; 227 m_xrun_has_occured=false; 228 234 229 235 debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " RCV PROC: "); 230 236 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); … … 232 238 ++it ) { 233 239 period_ready = period_ready && (*it)->isOnePeriodReady(); 234 m_xrun_has_occured = m_xrun_has_occured || (*it)->xrunOccurred();235 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, m_xrun_has_occured,(*it)->m_framecounter);240 xrun_has_occured = xrun_has_occured || (*it)->xrunOccurred(); 241 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, xrun_has_occured,(*it)->m_framecounter); 236 242 } 237 243 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n"); … … 242 248 ++it ) { 243 249 period_ready = period_ready && (*it)->isOnePeriodReady(); 244 m_xrun_has_occured = m_xrun_has_occured || (*it)->xrunOccurred();245 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, m_xrun_has_occured,(*it)->m_framecounter);250 xrun_has_occured = xrun_has_occured || (*it)->xrunOccurred(); 251 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, xrun_has_occured,(*it)->m_framecounter); 246 252 } 247 253 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n"); 248 254 249 if( m_xrun_has_occured) {255 if(xrun_has_occured) { 250 256 // do xrun signaling/handling 257 debugWarning("Streaming thread detected xrun\n"); 251 258 m_xruns++; 259 m_xrun_happened=true; 252 260 sem_post(&m_period_semaphore); 253 return false; 261 return false; // stop thread 254 262 } 255 263 … … 311 319 312 320 debugOutput( DEBUG_LEVEL_VERBOSE, "Starting IsoHandler...\n"); 313 if (!m_isoManager->startHandlers( )) {321 if (!m_isoManager->startHandlers(0)) { 314 322 debugFatal("Could not start handlers...\n"); 315 323 return false; … … 319 327 320 328 // start the runner thread 321 streamingThread->Start();329 m_streamingThread->Start(); 322 330 323 331 debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to start running...\n"); … … 382 390 } 383 391 384 (*it)->resetFrameCounter(); 385 } 386 387 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 388 it != m_TransmitProcessors.end(); 389 ++it ) { 392 (*it)->reset(); 390 393 391 394 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { … … 393 396 } 394 397 395 (*it)->resetFrameCounter(); 398 } 399 400 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 401 it != m_TransmitProcessors.end(); 402 ++it ) { 403 404 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 405 (*it)->dumpInfo(); 406 } 407 408 (*it)->reset(); 409 410 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 411 (*it)->dumpInfo(); 412 } 396 413 } 397 414 … … 415 432 } 416 433 434 return true; 435 417 436 } 418 437 419 438 bool StreamProcessorManager::stop() { 420 debugOutput( DEBUG_LEVEL_VERBOSE, " enter...\n");439 debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping...\n"); 421 440 assert(m_isoManager); 422 assert(streamingThread); 423 424 streamingThread->Stop(); 425 426 return m_isoManager->stopHandlers(); 441 assert(m_streamingThread); 442 debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping thread...\n"); 443 444 m_streamingThread->Stop(); 445 446 debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handlers...\n"); 447 if(!m_isoManager->stopHandlers()) { 448 debugFatal("Could not stop ISO handlers\n"); 449 return false; 450 } 451 452 debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering processors from handlers...\n"); 453 // now unregister all streams from iso manager 454 debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); 455 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 456 it != m_ReceiveProcessors.end(); 457 ++it ) { 458 if (!m_isoManager->unregisterStream(*it)) { 459 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor (%p) from the Iso manager\n",*it); 460 return false; 461 } 462 463 464 } 465 466 debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n"); 467 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 468 it != m_TransmitProcessors.end(); 469 ++it ) { 470 if (!m_isoManager->unregisterStream(*it)) { 471 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor (%p) from the Iso manager\n",*it); 472 return false; 473 } 474 475 } 476 477 478 return true; 427 479 428 480 } … … 435 487 sem_wait(&m_period_semaphore); 436 488 437 if(m_xrun_has_occured) return false; 438 439 return true; 440 441 } 442 443 bool StreamProcessorManager::reset() { 444 445 debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting processors...\n"); 489 if(m_xrun_happened) { 490 debugWarning("Detected underrun\n"); 491 dumpInfo(); 492 return false; 493 } 494 495 return true; 496 497 } 498 499 bool StreamProcessorManager::handleXrun() { 500 501 debugOutput( DEBUG_LEVEL_VERBOSE, "Handling Xrun ...\n"); 446 502 447 503 /* 448 504 * Reset means: 449 * Bringing all buffers & connections into a know state 450 * - Clear all capture buffers 451 * - Put nb_periods*period_size of null frames into the playback buffers 452 * => implemented by a reset() call, implementation dependant on the type 505 * 1) Stopping the packetizer thread 506 * 2) Bringing all buffers & streamprocessors into a know state 507 * - Clear all capture buffers 508 * - Put nb_periods*period_size of null frames into the playback buffers 509 * 3) Restarting the packetizer thread 453 510 */ 454 455 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Receive processors...\n"); 456 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 457 it != m_ReceiveProcessors.end(); 458 ++it ) { 459 if(!(*it)->reset()) { 460 debugFatal("could not reset stream processor (%p)",*it); 461 return false; 462 } 463 } 464 465 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Transmit processors...\n"); 466 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 467 it != m_TransmitProcessors.end(); 468 ++it ) { 469 if(!(*it)->reset()) { 470 debugFatal("could not reset stream processor (%p)",*it); 471 return false; 472 } 473 } 511 debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping processormanager...\n"); 512 if(!stop()) { 513 debugFatal("Could not stop.\n"); 514 return false; 515 } 516 517 debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting Processors...\n"); 518 519 // now we reset the frame counters 520 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 521 it != m_ReceiveProcessors.end(); 522 ++it ) { 523 524 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 525 (*it)->dumpInfo(); 526 } 527 528 (*it)->reset(); 529 530 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 531 (*it)->dumpInfo(); 532 } 533 534 } 535 536 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 537 it != m_TransmitProcessors.end(); 538 ++it ) { 539 540 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 541 (*it)->dumpInfo(); 542 } 543 544 (*it)->reset(); 545 546 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 547 (*it)->dumpInfo(); 548 } 549 } 550 551 debugOutput( DEBUG_LEVEL_VERBOSE, "Starting processormanager...\n"); 552 553 if(!start()) { 554 debugFatal("Could not start.\n"); 555 return false; 556 } 557 558 559 debugOutput( DEBUG_LEVEL_VERBOSE, "Xrun handled...\n"); 560 561 474 562 return true; 475 563 } … … 482 570 // penalty for the virtual functions (to be checked) 483 571 484 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Receive processors...\n");485 572 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 486 573 it != m_ReceiveProcessors.end(); … … 492 579 } 493 580 494 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Transmit processors...\n");495 581 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 496 582 it != m_TransmitProcessors.end(); … … 511 597 // a static cast could make sure that there is no performance 512 598 // penalty for the virtual functions (to be checked) 513 514 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Receive processors...\n");515 599 if (t==StreamProcessor::E_Receive) { 516 600 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); … … 523 607 } 524 608 } else { 525 // debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, " Transmit processors...\n");526 609 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 527 610 it != m_TransmitProcessors.end(); … … 538 621 539 622 void StreamProcessorManager::dumpInfo() { 623 debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n"); 540 624 debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping StreamProcessorManager information...\n"); 541 625 … … 556 640 debugOutputShort( DEBUG_LEVEL_NORMAL, "Iso handler info:\n"); 557 641 m_isoManager->dumpInfo(); 642 debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n"); 558 643 559 644 } … … 561 646 void StreamProcessorManager::setVerboseLevel(int l) { 562 647 setDebugLevel(l); 563 648 564 649 if (m_isoManager) m_isoManager->setVerboseLevel(l); 650 if (m_streamingThread) m_streamingThread->setVerboseLevel(l); 565 651 566 652 debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h
r227 r230 91 91 bool transfer(enum StreamProcessor::EProcessorType); ///< transfer the buffer contents from/to client (single processor type) 92 92 93 bool reset(); ///< reset the streams & buffers (e.g. after xrun)93 bool handleXrun(); ///< reset the streams & buffers after xrun 94 94 95 95 bool start(); … … 105 105 // thread sync primitives 106 106 sem_t m_period_semaphore; 107 // this may only be written by the packet thread, and read by 108 // the waiting thread. The packet thread terminates if this is 109 // true, therefore it will never by updated again. 110 // it can only be set to true before the period semaphore is 111 // signalled, which the waiting thread is waiting for. Therefore 112 // this variable is protected by the semaphore. 113 bool m_xrun_has_occured; 107 108 bool m_xrun_happened; 114 109 115 110 // processor list … … 123 118 IsoHandlerManager *m_isoManager; 124 119 125 FreebobPosixThread * streamingThread;120 FreebobPosixThread *m_streamingThread; 126 121 127 122 DECLARE_DEBUG_MODULE;