This should have been a part of r2210.
[ffado.git] / libffado / tests / test-streamdump.cpp
blobe4b7a1a7ada1a3750ba7a3fd334d46745f3f8be0
1 /*
2 * Copyright (C) 2005-2008 by Daniel Wagner
3 * Copyright (C) 2005-2008 by Pieter Palmers
5 * This file is part of FFADO
6 * FFADO = Free Firewire (pro-)audio drivers for linux
8 * FFADO is based upon FreeBoB
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.
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.
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/>.
25 #include <libraw1394/raw1394.h>
26 #include <libiec61883/iec61883.h>
28 #include <argp.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <iostream>
33 using namespace std;
35 ////////////////////////////////////////////////
36 // arg parsing
37 ////////////////////////////////////////////////
38 const char *argp_program_version = "test-streamdump 0.1";
39 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
40 static char doc[] = "test-streamdump -- test program to get a BeBoB device to stream and to save the streams";
41 static char args_doc[] = "NODE_ID";
42 static struct argp_option options[] = {
43 {"verbose", 'v', 0, 0, "Produce verbose output" },
44 {"port", 'p', "PORT", 0, "Set port" },
45 { 0 }
48 struct arguments
50 arguments()
51 : verbose( false )
52 , test( false )
53 , port( 0 )
55 args[0] = 0;
58 char* args[1];
59 bool verbose;
60 bool test;
61 int port;
62 } arguments;
64 // Parse a single option.
65 static error_t
66 parse_opt( int key, char* arg, struct argp_state* state )
68 // Get the input argument from `argp_parse', which we
69 // know is a pointer to our arguments structure.
70 struct arguments* arguments = ( struct arguments* ) state->input;
72 char* tail;
73 errno = 0;
74 switch (key) {
75 case 'v':
76 arguments->verbose = true;
77 break;
78 case 't':
79 arguments->test = true;
80 break;
81 case 'p':
82 arguments->port = strtol(arg, &tail, 0);
83 if (errno) {
84 perror("argument parsing failed:");
85 return errno;
87 break;
88 case ARGP_KEY_ARG:
89 if (state->arg_num >= 1) {
90 // Too many arguments.
91 argp_usage (state);
93 arguments->args[state->arg_num] = arg;
94 break;
95 case ARGP_KEY_END:
96 if (state->arg_num < 1) {
97 // Not enough arguments.
98 argp_usage (state);
100 break;
101 default:
102 return ARGP_ERR_UNKNOWN;
104 return 0;
107 static struct argp argp = { options, parse_opt, args_doc, doc };
109 ///////////////////////////
110 // main
111 //////////////////////////
113 main(int argc, char **argv)
115 // arg parsing
116 argp_parse (&argp, argc, argv, 0, 0, &arguments);
118 errno = 0;
119 char* tail;
120 int iNodeId = strtol(arguments.args[0], &tail, 0);
121 if (errno) {
122 perror("argument parsing failed:");
123 return -1;
126 raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port );
127 if ( !pHandle ) {
128 if ( !errno ) {
129 cerr << "libraw1394 not compatible" << endl;
130 } else {
131 perror( "Could not get 1394 handle" );
132 cerr << "Is ieee1394 and raw1394 driver loaded?" << endl;
134 return -1;
137 struct Connection {
138 int m_output;
139 int m_oplug;
140 int m_input;
141 int m_iplug;
142 int m_iBandwith;
143 int m_iIsoChannel;
147 int iLocalId = raw1394_get_local_id( pHandle );
148 int iRemoteId = iNodeId | 0xffc0;
149 Connection cons[] = {
150 // output, oplug, input, iplug, bandwith, iso channel
151 { iRemoteId, 0, iLocalId, -1, 0x148, -1 }, // oPCR[0]
152 // { iRemoteId, 1, iLocalId, -1, 0x148, -1 }, // oPCR[1]
153 // { iRemoteId, 2, iLocalId, -1, 0, -1 }, // oPCR[2]: cmp not supported
154 // { iLocalId, -1, iRemoteId, 0, 0x148, -1 }, // iPCR[0]
155 // { iLocalId, -1, iRemoteId, 1, 0x148, -1 }, // iPCR[1]
156 // { iLocalId, -1, iRemoteId, 2, 0, -1 }, // iPCR[2]: cmp not supported
159 printf( "local node id %d\n", iLocalId & ~0xffc0);
160 printf( "remote node id %d\n", iRemoteId & ~0xffc0);
162 for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
163 Connection* pCons = &cons[i];
165 // the bandwith calculation fails, so its better to use
166 // some default values.
167 pCons->m_iBandwith = iec61883_cmp_calc_bandwidth ( pHandle,
168 pCons->m_output,
169 pCons->m_oplug,
170 IEC61883_DATARATE_400 );
171 sleep(1);
172 pCons->m_iIsoChannel = iec61883_cmp_connect( pHandle,
173 pCons->m_output,
174 &pCons->m_oplug,
175 pCons->m_input,
176 &pCons->m_iplug,
177 &pCons->m_iBandwith );
178 printf( "%2d -> %2d %cPCR[%2d]: bw = %4d, ch = %2d\n",
179 pCons->m_output & ~0xffc0,
180 pCons->m_input & ~0xffc0,
181 pCons->m_oplug == -1? 'i' : 'o',
182 pCons->m_oplug == -1? pCons->m_iplug: pCons->m_oplug,
183 pCons->m_iBandwith,
184 pCons->m_iIsoChannel );
185 sleep(1);
188 sleep( 5 );
190 for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
191 Connection* pCons = &cons[i];
193 if ( pCons->m_iIsoChannel != -1 ) {
194 printf( "disconnect\n");
195 iec61883_cmp_disconnect( pHandle,
196 pCons->m_output,
197 pCons->m_oplug,
198 pCons->m_input,
199 pCons->m_iplug,
200 pCons->m_iIsoChannel,
201 pCons->m_iBandwith );
208 raw1394_destroy_handle( pHandle );
209 return 0;