root/branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp

Revision 312, 21.3 kB (checked in by jwoithe, 16 years ago)

MOTU: fix xrun recovery glitches inadvertantly introduced in r309.
MOTU: preliminary MIDI port support. Rate control still needs to be added so it probably won't work in its current form yet. MIDI has not yet been tested.
MOTU: tweaks to receive/transmit missed cycle detection.
jack driver: during driver shutdown don't try to free NULL ports created for non-audio ports during initialisation to preserve device port index locations.

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28
29 #include "StreamProcessorManager.h"
30 #include "StreamProcessor.h"
31 #include "Port.h"
32 #include <errno.h>
33 #include <assert.h>
34
35
36 namespace FreebobStreaming {
37
38 IMPL_DEBUG_MODULE( StreamProcessorManager, StreamProcessorManager, DEBUG_LEVEL_NORMAL );
39
40 StreamProcessorManager::StreamProcessorManager(unsigned int period, unsigned int nb_buffers)
41         : m_nb_buffers(nb_buffers), m_period(period), m_xruns(0), m_isoManager(0), m_nbperiods(0) {
42
43 }
44
45 StreamProcessorManager::~StreamProcessorManager() {
46         if (m_isoManager) delete m_isoManager;
47        
48 }
49
50 /**
51  * Registers \ref processor with this manager.
52  *
53  * also registers it with the isohandlermanager
54  *
55  * be sure to call isohandlermanager->init() first!
56  * and be sure that the processors are also ->init()'ed
57  *
58  * @param processor
59  * @return true if successfull
60  */
61 bool StreamProcessorManager::registerProcessor(StreamProcessor *processor)
62 {
63         debugOutput( DEBUG_LEVEL_VERBOSE, "Registering processor (%p)\n",processor);
64         assert(processor);
65         assert(m_isoManager);
66
67         if (processor->getType()==StreamProcessor::E_Receive) {
68                 processor->setVerboseLevel(getDebugLevel()); // inherit debug level
69                
70                 m_ReceiveProcessors.push_back(processor);
71                
72                 processor->setManager(this);
73                                
74                 return true;
75         }
76        
77         if (processor->getType()==StreamProcessor::E_Transmit) {
78                 processor->setVerboseLevel(getDebugLevel()); // inherit debug level
79                
80                 m_TransmitProcessors.push_back(processor);
81                
82                 processor->setManager(this);
83                
84                 return true;
85         }
86
87         debugFatal("Unsupported processor type!\n");
88        
89         return false;
90 }
91
92 bool StreamProcessorManager::unregisterProcessor(StreamProcessor *processor)
93 {
94         debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering processor (%p)\n",processor);
95         assert(processor);
96
97         if (processor->getType()==StreamProcessor::E_Receive) {
98
99                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
100                         it != m_ReceiveProcessors.end();
101                         ++it ) {
102
103                         if ( *it == processor ) {
104                                         m_ReceiveProcessors.erase(it);
105                                        
106                                         processor->clearManager();
107                                        
108                                         if(!m_isoManager->unregisterStream(processor)) {
109                                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor from the Iso manager\n");
110                                                
111                                                 return false;
112                                                
113                                         }
114                                        
115                                         return true;
116                                 }
117                 }
118         }
119
120         if (processor->getType()==StreamProcessor::E_Transmit) {
121                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
122                         it != m_TransmitProcessors.end();
123                         ++it ) {
124
125                         if ( *it == processor ) {
126                                         m_TransmitProcessors.erase(it);
127                                        
128                                         processor->clearManager();
129                                        
130                                         if(!m_isoManager->unregisterStream(processor)) {
131                                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor from the Iso manager\n");
132                                                
133                                                 return false;
134                                                
135                                         }
136                                        
137                                         return true;
138                                 }
139                 }
140         }
141        
142         debugFatal("Processor (%p) not found!\n",processor);
143
144         return false; //not found
145
146 }
147
148 bool StreamProcessorManager::init()
149 {
150         debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
151
152         // and the tread that runs the runner
153         m_streamingThread=new FreebobUtil::PosixThread(this, m_thread_realtime, m_thread_priority, PTHREAD_CANCEL_DEFERRED);
154         if(!m_streamingThread) {
155                 debugFatal("Could not create streaming thread\n");
156                 return false;
157         }
158        
159         m_isoManager=new IsoHandlerManager();
160        
161         if(!m_isoManager) {
162                 debugFatal("Could not create IsoHandlerManager\n");
163                 return false;
164         }
165        
166         m_isoManager->setVerboseLevel(getDebugLevel());
167        
168         if(!m_isoManager->Init()) {
169                 debugFatal("Could not init IsoHandlerManager\n");
170                 return false;
171         }
172
173         return true;
174 }
175
176 bool StreamProcessorManager::Init()
177 {
178         debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing runner...\n");
179        
180         // no xrun has occurred (yet)
181         m_xrun_happened=false;
182
183         if(sem_init(&m_period_semaphore, 0, 0)) {
184                 debugFatal( "Cannot init packet transfer semaphore\n");
185                 debugFatal( " Error: %s\n",strerror(errno));
186                 return false;
187     }
188  
189         return true;
190 }
191
192 bool StreamProcessorManager::prepare() {
193
194         debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n");
195         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
196         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
197                 it != m_ReceiveProcessors.end();
198                 ++it ) {
199                         if(!(*it)->prepare()) {
200                                 debugFatal(  " could not prepare (%p)...\n",(*it));
201                                 return false;
202                                
203                         }
204                 }
205
206         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
207         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
208                 it != m_TransmitProcessors.end();
209                 ++it ) {
210                         if(!(*it)->prepare()) {
211                                 debugFatal( " could not prepare (%p)...\n",(*it));
212                                 return false;
213                        
214                         }
215                        
216                 }
217
218         return true;
219 }
220
221 bool StreamProcessorManager::Execute()
222 {
223
224         bool period_ready=true;
225     bool xrun_has_occured=false;
226         bool this_period_ready;
227        
228         unsigned long tstamp_enter=debugGetCurrentTSC();
229        
230 //      debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "------------- EXECUTE -----------\n");
231        
232         if(!m_isoManager->Execute()) {
233                 debugFatal("Could not execute isoManager\n");
234                 return false;
235         }
236        
237         unsigned long tstamp_iso=debugGetCurrentTSC();
238        
239         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " RCV PROC: ");
240         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
241                 it != m_ReceiveProcessors.end();
242                 ++it ) {
243                
244                 this_period_ready = (*it)->isOnePeriodReady();
245                 period_ready = period_ready && this_period_ready;
246 //              if (this_period_ready) {
247 //                  m_isoManager->disablePolling(*it);
248 //              }
249 //             
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);
252         }
253         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n");
254
255         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " XMIT PROC: ");
256         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
257                 it != m_TransmitProcessors.end();
258                 ++it ) {
259                 this_period_ready = (*it)->isOnePeriodReady();
260                 period_ready = period_ready && this_period_ready;
261 //              if (this_period_ready) {
262 //                  m_isoManager->disablePolling(*it);
263 //              }
264                 xrun_has_occured = xrun_has_occured || (*it)->xrunOccurred();
265                 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, xrun_has_occured,(*it)->m_framecounter);
266         }
267         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n");
268        
269         unsigned long tstamp_periodcheck=debugGetCurrentTSC();
270
271         if(xrun_has_occured) {
272                 // do xrun signaling/handling
273                 debugWarning("Streaming thread detected xrun\n");
274                 m_xruns++;
275                 m_xrun_happened=true;
276                 sem_post(&m_period_semaphore);
277                 return false; // stop thread
278         }
279
280         if(period_ready) {
281                 // signal the waiting thread(s?) that a period is ready
282                 sem_post(&m_period_semaphore);
283                 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "Period done...\n");
284
285                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
286                         it != m_ReceiveProcessors.end();
287                         ++it ) {
288                         (*it)->decrementFrameCounter();
289 //                      m_isoManager->enablePolling(*it);
290                        
291                 }
292        
293                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
294                         it != m_TransmitProcessors.end();
295                         ++it ) {
296                         (*it)->decrementFrameCounter();
297 //                      m_isoManager->enablePolling(*it);
298                 }
299                
300                 m_nbperiods++;
301         }
302        
303         unsigned long tstamp_exit=debugGetCurrentTSC();
304        
305 //      debugOutput( DEBUG_LEVEL_VERBOSE, "EXECUTE TIME: ISO: %6d | PeriodCheck: %6d | FrameCounter: %6d \n",
306 //         tstamp_iso-tstamp_enter, tstamp_periodcheck-tstamp_iso, tstamp_exit-tstamp_periodcheck
307 //         );
308
309         return true;
310
311 }
312
313 bool StreamProcessorManager::start() {
314         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting Processors...\n");
315         assert(m_isoManager);
316        
317         debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handlers for the StreamProcessors...\n");
318         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
319         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
320                 it != m_ReceiveProcessors.end();
321                 ++it ) {
322                         if (!(*it)->preparedForStart()) {
323                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Receive stream processor (%p) failed to prepare for start\n", *it);
324                                 return false;
325                         }
326                         if (!m_isoManager->registerStream(*it)) {
327                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register receive stream processor (%p) with the Iso manager\n",*it);
328                                 return false;
329                         }
330                        
331                        
332                 }
333
334         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
335         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
336                 it != m_TransmitProcessors.end();
337                 ++it ) {
338                         if (!(*it)->preparedForStart()) {
339                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Transmit stream processor (%p) failed to prepare for start\n", *it);
340                                 return false;
341                         }
342                         if (!m_isoManager->registerStream(*it)) {
343                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register transmit stream processor (%p) with the Iso manager\n",*it);
344                                 return false;
345                         }
346                        
347                 }
348
349         debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing IsoHandlerManager...\n");
350         if (!m_isoManager->prepare()) {
351                 debugFatal("Could not prepare isoManager\n");
352                 return false;
353         }
354
355         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting IsoHandler...\n");
356         if (!m_isoManager->startHandlers(0)) {
357                 debugFatal("Could not start handlers...\n");
358                 return false;
359         }
360        
361         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting streaming thread...\n");
362        
363         // start the runner thread
364         m_streamingThread->Start();
365        
366         debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to start running...\n");
367         // we have to wait until all streamprocessors indicate that they are running
368         // i.e. that there is actually some data stream flowing
369         int wait_cycles=2000; // two seconds
370         bool notRunning=true;
371         while (notRunning && wait_cycles) {
372                 wait_cycles--;
373                 notRunning=false;
374                
375                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
376                         it != m_ReceiveProcessors.end();
377                         ++it ) {
378                         if(!(*it)->isRunning()) notRunning=true;
379                 }
380        
381                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
382                         it != m_TransmitProcessors.end();
383                         ++it ) {
384                         if(!(*it)->isRunning()) notRunning=true;
385                 }
386                 usleep(1000);
387         }
388        
389         if(!wait_cycles) { // timout has occurred
390                 debugFatal("One or more streams are not starting up (timeout):\n");
391                            
392                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
393                         it != m_ReceiveProcessors.end();
394                         ++it ) {
395                         if(!(*it)->isRunning()) {
396                                 debugFatal(" receive stream %p not running\n",*it);
397                         } else {       
398                                 debugFatal(" receive stream %p running\n",*it);
399                         }
400                 }
401        
402                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
403                         it != m_TransmitProcessors.end();
404                         ++it ) {
405                         if(!(*it)->isRunning()) {
406                                 debugFatal(" transmit stream %p not running\n",*it);
407                         } else {       
408                                 debugFatal(" transmit stream %p running\n",*it);
409                         }
410                 }
411                 return false;
412         }
413
414         debugOutput( DEBUG_LEVEL_VERBOSE, "StreamProcessors running...\n");
415         debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting frame counters...\n");
416        
417         // now we reset the frame counters
418         // FIXME: check how we are going to do sync
419         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
420                 it != m_ReceiveProcessors.end();
421                 ++it ) {
422                
423                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
424                         (*it)->dumpInfo();
425                 }
426
427                 (*it)->reset();
428
429                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
430                         (*it)->dumpInfo();
431                 }
432                
433         }
434        
435         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
436                 it != m_TransmitProcessors.end();
437                 ++it ) {
438                
439                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
440                         (*it)->dumpInfo();
441                 }
442                
443                 (*it)->reset();
444                
445                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
446                         (*it)->dumpInfo();
447                 }
448         }
449        
450         debugOutput( DEBUG_LEVEL_VERBOSE, "Enabling StreamProcessors...\n");
451         // and we enable the streamprocessors
452         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
453                 it != m_ReceiveProcessors.end();
454                 ++it ) {               
455                 (*it)->enable();
456                 m_isoManager->enablePolling(*it);
457         }
458
459         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
460                 it != m_TransmitProcessors.end();
461                 ++it ) {
462                 (*it)->enable();
463                 m_isoManager->enablePolling(*it);
464         }
465        
466         // dump the iso stream information when in verbose mode
467         if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
468                 m_isoManager->dumpInfo();
469         }
470        
471         return true;
472        
473 }
474
475 bool StreamProcessorManager::stop() {
476         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping...\n");
477         assert(m_isoManager);
478         assert(m_streamingThread);
479
480         debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to prepare to stop...\n");
481         // Most stream processors can just stop without special treatment.  However, some
482         // (like the MOTU) need to do a few things before it's safe to turn off the iso
483         // handling.
484         int wait_cycles=2000; // two seconds ought to be sufficient
485         bool allReady = false;
486         while (!allReady && wait_cycles) {
487                 wait_cycles--;
488                 allReady = true;
489                
490                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
491                         it != m_ReceiveProcessors.end();
492                         ++it ) {
493                         if(!(*it)->preparedForStop()) allReady = false;
494                 }
495        
496                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
497                         it != m_TransmitProcessors.end();
498                         ++it ) {
499                         if(!(*it)->preparedForStop()) allReady = false;
500                 }
501                 usleep(1000);
502         }
503
504
505         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping thread...\n");
506        
507         m_streamingThread->Stop();
508        
509         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handlers...\n");
510         if(!m_isoManager->stopHandlers()) {
511            debugFatal("Could not stop ISO handlers\n");
512            return false;
513         }
514        
515         debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering processors from handlers...\n");
516     // now unregister all streams from iso manager
517         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
518         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
519                 it != m_ReceiveProcessors.end();
520                 ++it ) {
521                         if (!m_isoManager->unregisterStream(*it)) {
522                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor (%p) from the Iso manager\n",*it);
523                                 return false;
524                         }
525                        
526                 }
527
528         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
529         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
530                 it != m_TransmitProcessors.end();
531                 ++it ) {
532                         if (!m_isoManager->unregisterStream(*it)) {
533                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor (%p) from the Iso manager\n",*it);
534                                 return false;
535                         }
536                        
537                 }
538        
539         return true;
540        
541 }
542
543 bool StreamProcessorManager::waitForPeriod() {
544
545         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n");
546
547         // Wait for packetizer thread to signal a period completion
548         sem_wait(&m_period_semaphore);
549        
550         if(m_xrun_happened) {
551            debugWarning("Detected underrun\n");
552            dumpInfo();
553            return false;
554         }
555        
556         return true;
557
558 }
559
560 bool StreamProcessorManager::handleXrun() {
561
562         debugOutput( DEBUG_LEVEL_VERBOSE, "Handling Xrun ...\n");
563
564         /*
565          * Reset means:
566          * 1) Stopping the packetizer thread
567          * 2) Bringing all buffers & streamprocessors into a know state
568          *    - Clear all capture buffers
569          *    - Put nb_periods*period_size of null frames into the playback buffers
570          * 3) Restarting the packetizer thread
571          */
572         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping processormanager...\n");
573         if(!stop()) {
574            debugFatal("Could not stop.\n");
575            return false;
576         }
577
578         debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting Processors...\n");
579        
580         // now we reset the frame counters
581         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
582                 it != m_ReceiveProcessors.end();
583                 ++it ) {
584                
585                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
586                         (*it)->dumpInfo();
587                 }
588                
589                 (*it)->reset();
590                
591                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
592                         (*it)->dumpInfo();
593                 }
594                
595         }
596        
597         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
598                 it != m_TransmitProcessors.end();
599                 ++it ) {
600                
601                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
602                         (*it)->dumpInfo();
603                 }
604                
605                 (*it)->reset();
606                
607                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
608                         (*it)->dumpInfo();
609                 }
610         }
611
612         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting processormanager...\n");
613
614         if(!start()) {
615            debugFatal("Could not start.\n");
616            return false;
617         }
618
619
620         debugOutput( DEBUG_LEVEL_VERBOSE, "Xrun handled...\n");
621        
622        
623         return true;
624 }
625
626 bool StreamProcessorManager::transfer() {
627
628         debugOutput( DEBUG_LEVEL_VERBOSE, "Transferring period...\n");
629
630         // a static cast could make sure that there is no performance
631         // penalty for the virtual functions (to be checked)
632
633         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
634                 it != m_ReceiveProcessors.end();
635                 ++it ) {
636                 if(!(*it)->transfer()) {
637                         debugFatal("could not transfer() stream processor (%p)",*it);
638                         return false;
639                 }
640         }
641
642         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
643                 it != m_TransmitProcessors.end();
644                 ++it ) {
645                 if(!(*it)->transfer()) {
646                         debugFatal("could not transfer() stream processor (%p)",*it);
647                         return false;
648                 }
649         }
650
651         return true;
652 }
653
654 bool StreamProcessorManager::transfer(enum StreamProcessor::EProcessorType t) {
655
656         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n");
657
658         // a static cast could make sure that there is no performance
659         // penalty for the virtual functions (to be checked)
660         if (t==StreamProcessor::E_Receive) {
661                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
662                         it != m_ReceiveProcessors.end();
663                         ++it ) {
664                         if(!(*it)->transfer()) {
665                                 debugFatal("could not transfer() stream processor (%p)",*it);
666                                 return false;
667                         }
668                 }
669         } else {
670                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
671                         it != m_TransmitProcessors.end();
672                         ++it ) {
673                         if(!(*it)->transfer()) {
674                                 debugFatal("could not transfer() stream processor (%p)",*it);
675                                 return false;
676                         }
677                 }
678         }
679
680         return true;
681 }
682
683 void StreamProcessorManager::dumpInfo() {
684         debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n");
685         debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping StreamProcessorManager information...\n");
686         debugOutputShort( DEBUG_LEVEL_NORMAL, "Period count: %d\n", m_nbperiods);
687
688         debugOutputShort( DEBUG_LEVEL_NORMAL, " Receive processors...\n");
689         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
690                 it != m_ReceiveProcessors.end();
691                 ++it ) {
692                 (*it)->dumpInfo();
693         }
694
695         debugOutputShort( DEBUG_LEVEL_NORMAL, " Transmit processors...\n");
696         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
697                 it != m_TransmitProcessors.end();
698                 ++it ) {
699                 (*it)->dumpInfo();
700         }
701
702         debugOutputShort( DEBUG_LEVEL_NORMAL, "Iso handler info:\n");
703         m_isoManager->dumpInfo();
704         debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n");
705
706 }
707
708 void StreamProcessorManager::setVerboseLevel(int l) {
709         setDebugLevel(l);
710
711         if (m_isoManager) m_isoManager->setVerboseLevel(l);
712
713         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
714         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
715                 it != m_ReceiveProcessors.end();
716                 ++it ) {
717                 (*it)->setVerboseLevel(l);
718         }
719
720         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
721         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
722                 it != m_TransmitProcessors.end();
723                 ++it ) {
724                 (*it)->setVerboseLevel(l);
725         }
726 }
727
728
729 int StreamProcessorManager::getPortCount(enum Port::E_PortType type, enum Port::E_Direction direction) {
730         int count=0;
731
732         if (direction == Port::E_Capture) {
733                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
734                         it != m_ReceiveProcessors.end();
735                         ++it ) {
736                         count += (*it)->getPortCount(type);
737                 }
738         } else {
739                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
740                         it != m_TransmitProcessors.end();
741                         ++it ) {
742                         count += (*it)->getPortCount(type);
743                 }
744         }
745         return count;
746 }
747
748 int StreamProcessorManager::getPortCount(enum Port::E_Direction direction) {
749         int count=0;
750
751         if (direction == Port::E_Capture) {
752                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
753                         it != m_ReceiveProcessors.end();
754                         ++it ) {
755                         count += (*it)->getPortCount();
756                 }
757         } else {
758                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
759                         it != m_TransmitProcessors.end();
760                         ++it ) {
761                         count += (*it)->getPortCount();
762                 }
763         }
764         return count;
765 }
766
767 // TODO: implement a port map here, instead of the loop
768
769 Port* StreamProcessorManager::getPortByIndex(int idx, enum Port::E_Direction direction) {
770         int count=0;
771         int prevcount=0;
772
773         if (direction == Port::E_Capture) {
774                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
775                         it != m_ReceiveProcessors.end();
776                         ++it ) {
777                         count += (*it)->getPortCount();
778                         if (count > idx) {
779                                 return (*it)->getPortAtIdx(idx-prevcount);
780                         }
781                         prevcount=count;
782                 }
783         } else {
784                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
785                         it != m_TransmitProcessors.end();
786                         ++it ) {
787                         count += (*it)->getPortCount();
788                         if (count > idx) {
789                                 return (*it)->getPortAtIdx(idx-prevcount);
790                         }
791                         prevcount=count;
792                 }
793         }
794         return NULL;
795 }
796
797 bool StreamProcessorManager::setThreadParameters(bool rt, int priority) {
798     m_thread_realtime=rt;
799     m_thread_priority=priority;
800     return true;
801 }
802
803
804 } // end of namespace
Note: See TracBrowser for help on using the browser.