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

Revision 341, 21.2 kB (checked in by pieterpalmers, 17 years ago)

- changed bebob avdevice to use debugmodule instead of printf/cout
- fixed some minor merge side-effects
- implement a RT safe mechanism to obtain the cycle counter.

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         // the tread that runs the packet iterators
153         m_streamingThread=new FreebobUtil::PosixThread(this, m_thread_realtime, m_thread_priority+5, 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         // the tread that keeps the handler's cycle counters up to date
169         // NOTE: is lower priority nescessary? it can block
170         m_isoManagerThread=new FreebobUtil::PosixThread(m_isoManager, m_thread_realtime, m_thread_priority+6, PTHREAD_CANCEL_DEFERRED);
171         if(!m_isoManagerThread) {
172                 debugFatal("Could not create iso manager thread\n");
173                 return false;
174         }
175
176         return true;
177 }
178
179 bool StreamProcessorManager::Init()
180 {
181         debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing runner...\n");
182        
183         // no xrun has occurred (yet)
184         m_xrun_happened=false;
185
186         if(sem_init(&m_period_semaphore, 0, 0)) {
187                 debugFatal( "Cannot init packet transfer semaphore\n");
188                 debugFatal( " Error: %s\n",strerror(errno));
189                 return false;
190     }
191  
192         return true;
193 }
194
195 bool StreamProcessorManager::prepare() {
196
197         debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n");
198         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
199         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
200                 it != m_ReceiveProcessors.end();
201                 ++it ) {
202                         if(!(*it)->prepare()) {
203                                 debugFatal(  " could not prepare (%p)...\n",(*it));
204                                 return false;
205                                
206                         }
207                 }
208
209         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
210         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
211                 it != m_TransmitProcessors.end();
212                 ++it ) {
213                         if(!(*it)->prepare()) {
214                                 debugFatal( " could not prepare (%p)...\n",(*it));
215                                 return false;
216                        
217                         }
218                        
219                 }
220
221         return true;
222 }
223
224 bool StreamProcessorManager::Execute()
225 {
226
227         bool period_ready=true;
228     bool xrun_has_occured=false;
229         bool this_period_ready;
230
231 //      debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "------------- EXECUTE -----------\n");
232
233         if(!m_isoManager->iterate()) {
234                 debugFatal("Could not iterate the isoManager\n");
235                 return false;
236         }
237        
238         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " RCV PROC: ");
239         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
240                 it != m_ReceiveProcessors.end();
241                 ++it ) {
242                
243                 this_period_ready = (*it)->isOnePeriodReady();
244                 period_ready = period_ready && this_period_ready;
245 //              if (this_period_ready) {
246 //                  m_isoManager->disablePolling(*it);
247 //              }
248 //             
249                 xrun_has_occured = xrun_has_occured || (*it)->xrunOccurred();
250                 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, xrun_has_occured,(*it)->m_framecounter);
251         }
252         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n");
253
254         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " XMIT PROC: ");
255         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
256                 it != m_TransmitProcessors.end();
257                 ++it ) {
258                 this_period_ready = (*it)->isOnePeriodReady();
259                 period_ready = period_ready && this_period_ready;
260 //              if (this_period_ready) {
261 //                  m_isoManager->disablePolling(*it);
262 //              }
263                 xrun_has_occured = xrun_has_occured || (*it)->xrunOccurred();
264                 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "(%d/%d/%d) ", period_ready, xrun_has_occured,(*it)->m_framecounter);
265         }
266         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n");
267
268         if(xrun_has_occured) {
269                 // do xrun signaling/handling
270                 debugWarning("Streaming thread detected xrun\n");
271                 m_xruns++;
272                 m_xrun_happened=true;
273                 sem_post(&m_period_semaphore);
274        
275                 return false; // stop thread
276         }
277
278         if(period_ready) {
279                 // signal the waiting thread(s?) that a period is ready
280                 sem_post(&m_period_semaphore);
281                 debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "Period done...\n");
282
283                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
284                         it != m_ReceiveProcessors.end();
285                         ++it ) {
286                         (*it)->decrementFrameCounter();
287 //                      m_isoManager->enablePolling(*it);
288                        
289                 }
290        
291                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
292                         it != m_TransmitProcessors.end();
293                         ++it ) {
294                         (*it)->decrementFrameCounter();
295 //                      m_isoManager->enablePolling(*it);
296                 }
297                
298                 m_nbperiods++;
299         }
300
301         return true;
302
303 }
304
305 bool StreamProcessorManager::start() {
306         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting Processors...\n");
307         assert(m_isoManager);
308        
309         debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handlers for the StreamProcessors...\n");
310         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
311         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
312                 it != m_ReceiveProcessors.end();
313                 ++it ) {
314                         if (!(*it)->preparedForStart()) {
315                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Receive stream processor (%p) failed to prepare for start\n", *it);
316                                 return false;
317                         }
318                         if (!m_isoManager->registerStream(*it)) {
319                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register receive stream processor (%p) with the Iso manager\n",*it);
320                                 return false;
321                         }
322                        
323                        
324                 }
325
326         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
327         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
328                 it != m_TransmitProcessors.end();
329                 ++it ) {
330                         if (!(*it)->preparedForStart()) {
331                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Transmit stream processor (%p) failed to prepare for start\n", *it);
332                                 return false;
333                         }
334                         if (!m_isoManager->registerStream(*it)) {
335                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register transmit stream processor (%p) with the Iso manager\n",*it);
336                                 return false;
337                         }
338                        
339                 }
340
341         debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing IsoHandlerManager...\n");
342         if (!m_isoManager->prepare()) {
343                 debugFatal("Could not prepare isoManager\n");
344                 return false;
345         }
346
347         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting IsoHandler...\n");
348         if (!m_isoManager->startHandlers(0)) {
349                 debugFatal("Could not start handlers...\n");
350                 return false;
351         }
352        
353         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting streaming thread...\n");
354        
355         // start the runner thread
356         m_streamingThread->Start();
357        
358         // start the runner thread
359         m_isoManagerThread->Start();
360                
361         debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to start running...\n");
362         // we have to wait until all streamprocessors indicate that they are running
363         // i.e. that there is actually some data stream flowing
364         int wait_cycles=2000; // two seconds
365         bool notRunning=true;
366         while (notRunning && wait_cycles) {
367                 wait_cycles--;
368                 notRunning=false;
369                
370                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
371                         it != m_ReceiveProcessors.end();
372                         ++it ) {
373                         if(!(*it)->isRunning()) notRunning=true;
374                 }
375        
376                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
377                         it != m_TransmitProcessors.end();
378                         ++it ) {
379                         if(!(*it)->isRunning()) notRunning=true;
380                 }
381                 usleep(1000);
382         }
383        
384         if(!wait_cycles) { // timout has occurred
385                 debugFatal("One or more streams are not starting up (timeout):\n");
386                            
387                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
388                         it != m_ReceiveProcessors.end();
389                         ++it ) {
390                         if(!(*it)->isRunning()) {
391                                 debugFatal(" receive stream %p not running\n",*it);
392                         } else {       
393                                 debugFatal(" receive stream %p running\n",*it);
394                         }
395                 }
396        
397                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
398                         it != m_TransmitProcessors.end();
399                         ++it ) {
400                         if(!(*it)->isRunning()) {
401                                 debugFatal(" transmit stream %p not running\n",*it);
402                         } else {       
403                                 debugFatal(" transmit stream %p running\n",*it);
404                         }
405                 }
406                 return false;
407         }
408
409         debugOutput( DEBUG_LEVEL_VERBOSE, "StreamProcessors running...\n");
410         debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting frame counters...\n");
411        
412         // now we reset the frame counters
413         // FIXME: check how we are going to do sync
414         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
415                 it != m_ReceiveProcessors.end();
416                 ++it ) {
417                
418                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
419                         (*it)->dumpInfo();
420                 }
421
422                 (*it)->reset();
423
424                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
425                         (*it)->dumpInfo();
426                 }
427                
428         }
429        
430         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
431                 it != m_TransmitProcessors.end();
432                 ++it ) {
433                
434                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
435                         (*it)->dumpInfo();
436                 }
437                
438                 (*it)->reset();
439                
440                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
441                         (*it)->dumpInfo();
442                 }
443         }
444        
445         debugOutput( DEBUG_LEVEL_VERBOSE, "Enabling StreamProcessors...\n");
446         // and we enable the streamprocessors
447         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
448                 it != m_ReceiveProcessors.end();
449                 ++it ) {               
450                 (*it)->enable();
451                 m_isoManager->enablePolling(*it);
452         }
453
454         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
455                 it != m_TransmitProcessors.end();
456                 ++it ) {
457                 (*it)->enable();
458                 m_isoManager->enablePolling(*it);
459         }
460        
461         // dump the iso stream information when in verbose mode
462         if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
463                 m_isoManager->dumpInfo();
464         }
465        
466         return true;
467        
468 }
469
470 bool StreamProcessorManager::stop() {
471         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping...\n");
472         assert(m_isoManager);
473         assert(m_streamingThread);
474
475         debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to prepare to stop...\n");
476         // Most stream processors can just stop without special treatment.  However, some
477         // (like the MOTU) need to do a few things before it's safe to turn off the iso
478         // handling.
479         int wait_cycles=2000; // two seconds ought to be sufficient
480         bool allReady = false;
481         while (!allReady && wait_cycles) {
482                 wait_cycles--;
483                 allReady = true;
484                
485                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
486                         it != m_ReceiveProcessors.end();
487                         ++it ) {
488                         if(!(*it)->preparedForStop()) allReady = false;
489                 }
490        
491                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
492                         it != m_TransmitProcessors.end();
493                         ++it ) {
494                         if(!(*it)->preparedForStop()) allReady = false;
495                 }
496                 usleep(1000);
497         }
498
499
500         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping threads...\n");
501        
502         m_streamingThread->Stop();
503         m_isoManagerThread->Stop();
504        
505         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handlers...\n");
506         if(!m_isoManager->stopHandlers()) {
507            debugFatal("Could not stop ISO handlers\n");
508            return false;
509         }
510        
511         debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering processors from handlers...\n");
512     // now unregister all streams from iso manager
513         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
514         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
515                 it != m_ReceiveProcessors.end();
516                 ++it ) {
517                         if (!m_isoManager->unregisterStream(*it)) {
518                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor (%p) from the Iso manager\n",*it);
519                                 return false;
520                         }
521                        
522                 }
523
524         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
525         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
526                 it != m_TransmitProcessors.end();
527                 ++it ) {
528                         if (!m_isoManager->unregisterStream(*it)) {
529                                 debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor (%p) from the Iso manager\n",*it);
530                                 return false;
531                         }
532                        
533                 }
534        
535         return true;
536        
537 }
538
539 bool StreamProcessorManager::waitForPeriod() {
540
541         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n");
542
543         // Wait for packetizer thread to signal a period completion
544         sem_wait(&m_period_semaphore);
545        
546         if(m_xrun_happened) {
547            debugWarning("Detected underrun\n");
548            dumpInfo();
549            return false;
550         }
551        
552         return true;
553
554 }
555
556 bool StreamProcessorManager::handleXrun() {
557
558         debugOutput( DEBUG_LEVEL_VERBOSE, "Handling Xrun ...\n");
559
560         /*
561          * Reset means:
562          * 1) Stopping the packetizer thread
563          * 2) Bringing all buffers & streamprocessors into a know state
564          *    - Clear all capture buffers
565          *    - Put nb_periods*period_size of null frames into the playback buffers
566          * 3) Restarting the packetizer thread
567          */
568         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping processormanager...\n");
569         if(!stop()) {
570            debugFatal("Could not stop.\n");
571            return false;
572         }
573
574         debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting Processors...\n");
575        
576         // now we reset the frame counters
577         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
578                 it != m_ReceiveProcessors.end();
579                 ++it ) {
580                
581                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
582                         (*it)->dumpInfo();
583                 }
584                
585                 (*it)->reset();
586                
587                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
588                         (*it)->dumpInfo();
589                 }
590                
591         }
592        
593         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
594                 it != m_TransmitProcessors.end();
595                 ++it ) {
596                
597                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
598                         (*it)->dumpInfo();
599                 }
600                
601                 (*it)->reset();
602                
603                 if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) {
604                         (*it)->dumpInfo();
605                 }
606         }
607
608         debugOutput( DEBUG_LEVEL_VERBOSE, "Starting processormanager...\n");
609
610         if(!start()) {
611            debugFatal("Could not start.\n");
612            return false;
613         }
614
615
616         debugOutput( DEBUG_LEVEL_VERBOSE, "Xrun handled...\n");
617        
618        
619         return true;
620 }
621
622 bool StreamProcessorManager::transfer() {
623
624         debugOutput( DEBUG_LEVEL_VERBOSE, "Transferring period...\n");
625
626         // a static cast could make sure that there is no performance
627         // penalty for the virtual functions (to be checked)
628
629         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
630                 it != m_ReceiveProcessors.end();
631                 ++it ) {
632                 if(!(*it)->transfer()) {
633                         debugFatal("could not transfer() stream processor (%p)",*it);
634                         return false;
635                 }
636         }
637
638         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
639                 it != m_TransmitProcessors.end();
640                 ++it ) {
641                 if(!(*it)->transfer()) {
642                         debugFatal("could not transfer() stream processor (%p)",*it);
643                         return false;
644                 }
645         }
646
647         return true;
648 }
649
650 bool StreamProcessorManager::transfer(enum StreamProcessor::EProcessorType t) {
651
652         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n");
653
654         // a static cast could make sure that there is no performance
655         // penalty for the virtual functions (to be checked)
656         if (t==StreamProcessor::E_Receive) {
657                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
658                         it != m_ReceiveProcessors.end();
659                         ++it ) {
660                         if(!(*it)->transfer()) {
661                                 debugFatal("could not transfer() stream processor (%p)",*it);
662                                 return false;
663                         }
664                 }
665         } else {
666                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
667                         it != m_TransmitProcessors.end();
668                         ++it ) {
669                         if(!(*it)->transfer()) {
670                                 debugFatal("could not transfer() stream processor (%p)",*it);
671                                 return false;
672                         }
673                 }
674         }
675
676         return true;
677 }
678
679 void StreamProcessorManager::dumpInfo() {
680         debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n");
681         debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping StreamProcessorManager information...\n");
682         debugOutputShort( DEBUG_LEVEL_NORMAL, "Period count: %d\n", m_nbperiods);
683
684         debugOutputShort( DEBUG_LEVEL_NORMAL, " Receive processors...\n");
685         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
686                 it != m_ReceiveProcessors.end();
687                 ++it ) {
688                 (*it)->dumpInfo();
689         }
690
691         debugOutputShort( DEBUG_LEVEL_NORMAL, " Transmit processors...\n");
692         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
693                 it != m_TransmitProcessors.end();
694                 ++it ) {
695                 (*it)->dumpInfo();
696         }
697
698         debugOutputShort( DEBUG_LEVEL_NORMAL, "Iso handler info:\n");
699         m_isoManager->dumpInfo();
700         debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n");
701
702 }
703
704 void StreamProcessorManager::setVerboseLevel(int l) {
705         setDebugLevel(l);
706
707         if (m_isoManager) m_isoManager->setVerboseLevel(l);
708
709         debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n");
710         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
711                 it != m_ReceiveProcessors.end();
712                 ++it ) {
713                 (*it)->setVerboseLevel(l);
714         }
715
716         debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n");
717         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
718                 it != m_TransmitProcessors.end();
719                 ++it ) {
720                 (*it)->setVerboseLevel(l);
721         }
722 }
723
724
725 int StreamProcessorManager::getPortCount(enum Port::E_PortType type, enum Port::E_Direction direction) {
726         int count=0;
727
728         if (direction == Port::E_Capture) {
729                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
730                         it != m_ReceiveProcessors.end();
731                         ++it ) {
732                         count += (*it)->getPortCount(type);
733                 }
734         } else {
735                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
736                         it != m_TransmitProcessors.end();
737                         ++it ) {
738                         count += (*it)->getPortCount(type);
739                 }
740         }
741         return count;
742 }
743
744 int StreamProcessorManager::getPortCount(enum Port::E_Direction direction) {
745         int count=0;
746
747         if (direction == Port::E_Capture) {
748                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
749                         it != m_ReceiveProcessors.end();
750                         ++it ) {
751                         count += (*it)->getPortCount();
752                 }
753         } else {
754                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
755                         it != m_TransmitProcessors.end();
756                         ++it ) {
757                         count += (*it)->getPortCount();
758                 }
759         }
760         return count;
761 }
762
763 // TODO: implement a port map here, instead of the loop
764
765 Port* StreamProcessorManager::getPortByIndex(int idx, enum Port::E_Direction direction) {
766         int count=0;
767         int prevcount=0;
768
769         if (direction == Port::E_Capture) {
770                 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();
771                         it != m_ReceiveProcessors.end();
772                         ++it ) {
773                         count += (*it)->getPortCount();
774                         if (count > idx) {
775                                 return (*it)->getPortAtIdx(idx-prevcount);
776                         }
777                         prevcount=count;
778                 }
779         } else {
780                 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();
781                         it != m_TransmitProcessors.end();
782                         ++it ) {
783                         count += (*it)->getPortCount();
784                         if (count > idx) {
785                                 return (*it)->getPortAtIdx(idx-prevcount);
786                         }
787                         prevcount=count;
788                 }
789         }
790         return NULL;
791 }
792
793 bool StreamProcessorManager::setThreadParameters(bool rt, int priority) {
794     m_thread_realtime=rt;
795     m_thread_priority=priority;
796     return true;
797 }
798
799
800 } // end of namespace
Note: See TracBrowser for help on using the browser.