File: test-isohandling.cpp

package info (click to toggle)
libffado 2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,320 kB
  • ctags: 11,892
  • sloc: cpp: 75,412; python: 8,911; ansic: 2,951; sh: 1,261; xml: 822; makefile: 54
file content (202 lines) | stat: -rw-r--r-- 5,644 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (C) 2005-2008 by Pieter Palmers
 *
 * This file is part of FFADO
 * FFADO = Free Firewire (pro-)audio drivers for linux
 *
 * FFADO is based upon FreeBoB.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <signal.h>
#include "src/debugmodule/debugmodule.h"

#include "libutil/ByteSwap.h"

#include "src/libutil/PosixThread.h"

#include "src/libstreaming/util/IsoHandler.h"
#include "src/libstreaming/util/StreamProcessorManager.h"
#include "src/libstreaming/util/IsoHandlerManager.h"
#include "src/libstreaming/amdtp/AmdtpStreamProcessor.h"
#include "src/libstreaming/amdtp/AmdtpPort.h"

using namespace Streaming;

int run;

static void sighandler (int sig)
{
    run = 0;
}

int main(int argc, char *argv[])
{

    int retval=0;
    int i=0;
    run=1;

    signal (SIGINT, sighandler);
    signal (SIGPIPE, sighandler);

    printf("FFADO streaming test application\n");
    printf(" ISO handler tests\n");

    // also create a processor manager to manage the actual stream
    // processors
    StreamProcessorManager *procMan = new StreamProcessorManager(512,3);
    if(!procMan) {
        printf("Could not create StreamProcessorManager\n");
        return -1;
    }
    procMan->setVerboseLevel(DEBUG_LEVEL_VERBOSE);

    // now we can allocate the stream processors themselves

//     StreamProcessor *spt = new AmdtpTransmitStreamProcessor(3,2,44100,10);
//     if(!spt) {
//         printf("Could not create transmit AmdtpTransmitStreamProcessor\n");
//         return -1;
//     }
//     spt->setVerboseLevel(DEBUG_LEVEL_VERBOSE);

     AmdtpReceiveStreamProcessor *spr = new AmdtpReceiveStreamProcessor(2,44100,7);
//     ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100);
    if(!spr) {
        printf("Could not create receive AmdtpStreamProcessor\n");
        return -1;
    }
    spr->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
    spr->setChannel(0);

     AmdtpReceiveStreamProcessor *spr2 = new AmdtpReceiveStreamProcessor(2,44100,11);
//     ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100);
    if(!spr2) {
        printf("Could not create receive AmdtpStreamProcessor\n");
        return -1;
    }
    spr2->setVerboseLevel(DEBUG_LEVEL_VERBOSE);
    spr2->setChannel(1);

//     printf("----------------------\n");
//     if (procMan->registerProcessor(spt)) {
//         printf("Could not register transmit stream processor with the Processor manager\n");
//         return -1;
//     }
//     printf("----------------------\n");

    // also register it with the processor manager, so that it is aware of
    // buffer sizes etc...
    if (procMan->registerProcessor(spr)) {
        printf("Could not register receive stream processor with the Processor manager\n");
        return -1;
    }
    printf("----------------------\n");

    if (procMan->registerProcessor(spr2)) {
        printf("Could not register receive stream processor with the Processor manager\n");
        return -1;
    }
    printf("----------------------\n");

    AmdtpAudioPort *p1=new AmdtpAudioPort(
                   std::string("Test port 1"),
                   AmdtpAudioPort::E_Capture,
                   1,
                   0,
                   AmdtpPortInfo::E_MBLA,
                   0
        );
    if (!p1) {
        printf("Could not create port 1\n");
        return -1;
    }

    p1->setBufferSize(512);

    printf("----------------------\n");

    if (spr2->addPort(p1)) {
        printf("Could not register port with receive stream processor\n");
        return -1;
    }

    Util::PosixThread *thread=new Util::PosixThread(procMan);


    procMan->prepare();

    // start the runner
    thread->Start();
    printf("----------------------\n");

    if(procMan->start()) {
        printf("Could not start handlers\n");
        return -1;
    }
    printf("----------------------\n");

    int periods=0;
    int periods_print=0;
    while(run) {
        periods++;
         if(periods>periods_print) {
            printf("\n");
            printf("============================================\n");
            procMan->dumpInfo();
            printf("--------------------------------------------\n");
/*            hexDumpQuadlets((quadlet_t*)(p1->getBufferAddress()),10);
            printf("--------------------------------------------\n");*/
            hexDumpQuadlets((quadlet_t*)(p1->getBufferAddress()),10);
            printf("============================================\n");
            printf("\n");
            periods_print+=100;
         }
        procMan->waitForPeriod();
        procMan->transfer();

    }

    thread->Stop();

    procMan->stop();

//     procMan->unregisterProcessor(spt);
    procMan->unregisterProcessor(spr);
    procMan->unregisterProcessor(spr2);

    delete thread;

    delete procMan;

//     delete spt;
    delete spr;
    delete spr2;

    printf("Bye...\n");


  return EXIT_SUCCESS;
}