root/branches/libfreebob-2.0/tests/streaming/test-isohandling.cpp

Revision 212, 6.0 kB (checked in by pieterpalmers, 18 years ago)

- end of day commit

Line 
1 /***************************************************************************
2   Copyright (C) 2005 by Pieter Palmers   *
3                                                                         *
4   This program is free software; you can redistribute it and/or modify  *
5   it under the terms of the GNU General Public License as published by  *
6   the Free Software Foundation; either version 2 of the License, or     *
7   (at your option) any later version.                                   *
8                                                                         *
9   This program is distributed in the hope that it will be useful,       *
10   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12   GNU General Public License for more details.                          *
13                                                                         *
14   You should have received a copy of the GNU General Public License     *
15   along with this program; if not, write to the                         *
16   Free Software Foundation, Inc.,                                       *
17   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include <signal.h>
29 #include "debugmodule/debugmodule.h"
30
31 #include "IsoHandler.h"
32 #include "IsoStream.h"
33 #include "StreamProcessorManager.h"
34 #include "AmdtpStreamProcessor.h"
35 #include "IsoHandlerManager.h"
36 #include "StreamRunner.h"
37 #include "FreebobPosixThread.h"
38
39 using namespace FreebobStreaming;
40
41 int run;
42
43 static void sighandler (int sig)
44 {
45         run = 0;
46 }
47
48 int main(int argc, char *argv[])
49 {
50
51         int retval=0;
52         int i=0;
53         run=1;
54
55         signal (SIGINT, sighandler);
56         signal (SIGPIPE, sighandler);
57
58         printf("Freebob streaming test application\n");
59         printf(" ISO handler tests\n");
60
61         // the first thing we need is a ISO handler manager
62         IsoHandlerManager *isomanager = new IsoHandlerManager();
63         if(!isomanager) {
64                 printf("Could not create IsoHandlerManager\n");
65                 return -1;
66         }
67
68         isomanager->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
69         printf("----------------------\n");
70
71         // also create a processor manager to manage the actual stream
72         // processors   
73         StreamProcessorManager *procMan = new StreamProcessorManager(512,3);
74         if(!procMan) {
75                 printf("Could not create StreamProcessorManager\n");
76                 return -1;
77         }
78         procMan->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
79
80         // now we can allocate the stream processors themselves
81
82 //      StreamProcessor *spt = new AmdtpTransmitStreamProcessor(3,2,44100,10);
83 //      if(!spt) {
84 //              printf("Could not create transmit AmdtpTransmitStreamProcessor\n");
85 //              return -1;
86 //      }
87 //      spt->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
88
89         AmdtpReceiveStreamProcessor *spr = new AmdtpReceiveStreamProcessor(0,2,44100,11);
90 //      ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100);
91         if(!spr) {
92                 printf("Could not create receive AmdtpStreamProcessor\n");
93                 return -1;
94         }
95         spr->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
96
97         AmdtpReceiveStreamProcessor *spr2 = new AmdtpReceiveStreamProcessor(1,2,44100,7);
98 //      ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100);
99         if(!spr2) {
100                 printf("Could not create receive AmdtpStreamProcessor\n");
101                 return -1;
102         }
103         spr2->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
104
105 //      if (isomanager->registerStream(spt)) {
106 //              printf("Could not register transmit stream processor with the ISO manager\n");
107 //              return -1;
108 //      }
109 //      printf("----------------------\n");
110
111
112         // now we have an xmit stream,
113         // register it with the manager that assigns an iso handler
114
115         if (isomanager->registerStream(spr)) {
116                 printf("Could not register receive stream processor with the ISO manager\n");
117                 return -1;
118         }
119         printf("----------------------\n");
120
121         if (isomanager->registerStream(spr2)) {
122                 printf("Could not register receive stream processor with the ISO manager\n");
123                 return -1;
124         }
125         printf("----------------------\n");
126
127 //      printf("----------------------\n");
128 //      if (procMan->registerProcessor(spt)) {
129 //              printf("Could not register transmit stream processor with the Processor manager\n");
130 //              return -1;
131 //      }
132 //      printf("----------------------\n");
133
134         // also register it with the processor manager, so that it is aware of
135         // buffer sizes etc...
136         if (procMan->registerProcessor(spr)) {
137                 printf("Could not register receive stream processor with the Processor manager\n");
138                 return -1;
139         }
140         printf("----------------------\n");
141
142         if (procMan->registerProcessor(spr2)) {
143                 printf("Could not register receive stream processor with the Processor manager\n");
144                 return -1;
145         }
146         printf("----------------------\n");
147
148         // now create the runner that does the actual streaming
149         StreamRunner *runner = new StreamRunner(isomanager,procMan);
150         if(!runner) {
151                 printf("Could not create StreamRunner\n");
152                 return -1;
153         }
154
155         FreebobPosixThread *thread=new FreebobPosixThread(runner);
156
157         // start the runner
158         thread->Start();
159         printf("----------------------\n");
160
161         if(isomanager->startHandlers()) {
162                 printf("Could not start handlers\n");
163                 return -1;
164         }
165         printf("----------------------\n");
166
167         int periods=0;
168         int periods_print=0;
169         while(run) {
170                 periods++;
171                 if(periods>periods_print) {
172                         printf("\n");
173                         printf("============================================\n");
174                         isomanager->dumpInfo();
175                         printf("--------------------------------------------\n");
176                         procMan->dumpInfo();
177                         printf("============================================\n");
178                         printf("\n");
179                         periods_print+=100;
180                 }
181                 procMan->waitForPeriod();
182                 procMan->transfer();
183                
184         }
185
186         thread->Stop();
187
188         isomanager->stopHandlers();
189
190 //      isomanager->unregisterStream(spt);
191         isomanager->unregisterStream(spr);
192         isomanager->unregisterStream(spr2);
193
194 //      procMan->unregisterProcessor(spt);
195         procMan->unregisterProcessor(spr);
196         procMan->unregisterProcessor(spr2);
197
198         delete thread;
199         delete runner;
200         delete procMan;
201         delete isomanager;
202
203 //      delete spt;
204         delete spr;
205         delete spr2;
206
207         printf("Bye...\n");
208
209
210   return EXIT_SUCCESS;
211 }
Note: See TracBrowser for help on using the browser.