root/trunk/libffado/tests/test-streamdump.cpp

Revision 864, 6.5 kB (checked in by ppalmers, 16 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include <libraw1394/raw1394.h>
26 #include <libiec61883/iec61883.h>
27
28 #include <argp.h>
29 #include <stdlib.h>
30 #include <iostream>
31
32 using namespace std;
33
34 ////////////////////////////////////////////////
35 // arg parsing
36 ////////////////////////////////////////////////
37 const char *argp_program_version = "test-streamdump 0.1";
38 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
39 static char doc[] = "test-streamdump -- test program to get a BeBoB device to stream and to save the streams";
40 static char args_doc[] = "NODE_ID";
41 static struct argp_option options[] = {
42     {"verbose",   'v', 0,           0,  "Produce verbose output" },
43     {"port",      'p', "PORT",      0,  "Set port" },
44    { 0 }
45 };
46
47 struct arguments
48 {
49     arguments()
50         : verbose( false )
51         , test( false )
52         , port( 0 )
53         {
54             args[0] = 0;
55         }
56
57     char* args[1];
58     bool  verbose;
59     bool  test;
60     int   port;
61 } arguments;
62
63 // Parse a single option.
64 static error_t
65 parse_opt( int key, char* arg, struct argp_state* state )
66 {
67     // Get the input argument from `argp_parse', which we
68     // know is a pointer to our arguments structure.
69     struct arguments* arguments = ( struct arguments* ) state->input;
70
71     char* tail;
72     switch (key) {
73     case 'v':
74         arguments->verbose = true;
75         break;
76     case 't':
77         arguments->test = true;
78         break;
79     case 'p':
80         errno = 0;
81         arguments->port = strtol(arg, &tail, 0);
82         if (errno) {
83             perror("argument parsing failed:");
84             return errno;
85         }
86         break;
87     case ARGP_KEY_ARG:
88         if (state->arg_num >= 1) {
89             // Too many arguments.
90             argp_usage (state);
91         }
92         arguments->args[state->arg_num] = arg;
93         break;
94     case ARGP_KEY_END:
95         if (state->arg_num < 1) {
96             // Not enough arguments.
97             argp_usage (state);
98         }
99         break;
100     default:
101         return ARGP_ERR_UNKNOWN;
102     }
103     return 0;
104 }
105
106 static struct argp argp = { options, parse_opt, args_doc, doc };
107
108 ///////////////////////////
109 // main
110 //////////////////////////
111 int
112 main(int argc, char **argv)
113 {
114     // arg parsing
115     argp_parse (&argp, argc, argv, 0, 0, &arguments);
116
117     errno = 0;
118     char* tail;
119     int iNodeId = strtol(arguments.args[0], &tail, 0);
120     if (errno) {
121     perror("argument parsing failed:");
122     return -1;
123     }
124
125     raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port );
126     if ( !pHandle ) {
127         if ( !errno ) {
128             cerr << "libraw1394 not compatible" << endl;
129         } else {
130             perror( "Could not get 1394 handle" );
131             cerr << "Is ieee1394 and raw1394 driver loaded?" << endl;
132         }
133         return -1;
134     }
135
136     struct Connection {
137         int m_output;
138         int m_oplug;
139         int m_input;
140         int m_iplug;
141         int m_iBandwith;
142         int m_iIsoChannel;
143     };
144
145
146     int iLocalId  = raw1394_get_local_id( pHandle );
147     int iRemoteId = iNodeId | 0xffc0;
148     Connection cons[] = {
149         //   output,  oplug,     input, iplug, bandwith, iso channel
150         { iRemoteId,      0,  iLocalId,    -1,    0x148,          -1 },     // oPCR[0]
151 //         { iRemoteId,      1,  iLocalId,    -1,    0x148,          -1 },     // oPCR[1]
152         //        { iRemoteId,      2,  iLocalId,    -1,        0,          -1 },     // oPCR[2]: cmp not supported
153 //         {  iLocalId,     -1, iRemoteId,     0,    0x148,          -1 },     // iPCR[0]
154 //         {  iLocalId,     -1, iRemoteId,     1,    0x148,          -1 },     // iPCR[1]
155         //        {  iLocalId,     -1, iRemoteId,     2,        0,          -1 },     // iPCR[2]: cmp not supported
156     };
157
158     printf( "local node id %d\n", iLocalId  & ~0xffc0);
159     printf( "remote node id %d\n", iRemoteId & ~0xffc0);
160
161     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
162         Connection* pCons = &cons[i];
163
164         // the bandwith calculation fails, so its better to use
165         // some default values.
166         pCons->m_iBandwith = iec61883_cmp_calc_bandwidth ( pHandle,
167                                                            pCons->m_output,
168                                                            pCons->m_oplug,
169                                                            IEC61883_DATARATE_400 );
170         sleep(1);
171         pCons->m_iIsoChannel = iec61883_cmp_connect( pHandle,
172                                                      pCons->m_output,
173                                                      &pCons->m_oplug,
174                                                      pCons->m_input,
175                                                      &pCons->m_iplug,
176                                                      &pCons->m_iBandwith );
177         printf( "%2d -> %2d %cPCR[%2d]: bw = %4d, ch = %2d\n",
178                 pCons->m_output & ~0xffc0,
179                 pCons->m_input & ~0xffc0,
180                 pCons->m_oplug == -1? 'i' : 'o',
181                 pCons->m_oplug == -1? pCons->m_iplug: pCons->m_oplug,
182                 pCons->m_iBandwith,
183                 pCons->m_iIsoChannel );
184         sleep(1);
185     }
186
187     sleep( 5 );
188
189     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
190         Connection* pCons = &cons[i];
191
192         if ( pCons->m_iIsoChannel != -1 ) {
193             printf( "disconnect\n");
194             iec61883_cmp_disconnect( pHandle,
195                                      pCons->m_output,
196                                      pCons->m_oplug,
197                                      pCons->m_input,
198                                      pCons->m_iplug,
199                                      pCons->m_iIsoChannel,
200                                      pCons->m_iBandwith );
201
202
203         }
204     }
205
206
207     raw1394_destroy_handle( pHandle );
208     return 0;
209 }
Note: See TracBrowser for help on using the browser.