root/branches/ppalmers-streaming/tests/test-streamdump.cpp

Revision 464, 6.5 kB (checked in by ppalmers, 17 years ago)

BeBoB stream start utility

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 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  * FFADO 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) any later version.
14  * FFADO is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with FFADO; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA.
23  *
24  */
25
26 #include <libraw1394/raw1394.h>
27 #include <libiec61883/iec61883.h>
28
29 #include <argp.h>
30 #include <stdlib.h>
31 #include <iostream>
32
33 using namespace std;
34
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 }
46 };
47
48 struct arguments
49 {
50     arguments()
51         : verbose( false )
52         , test( false )
53         , port( 0 )
54         {
55             args[0] = 0;
56         }
57
58     char* args[1];
59     bool  verbose;
60     bool  test;
61     int   port;
62 } arguments;
63
64 // Parse a single option.
65 static error_t
66 parse_opt( int key, char* arg, struct argp_state* state )
67 {
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;
71
72     char* tail;
73     switch (key) {
74     case 'v':
75         arguments->verbose = true;
76         break;
77     case 't':
78         arguments->test = true;
79         break;
80     case 'p':
81         errno = 0;
82         arguments->port = strtol(arg, &tail, 0);
83         if (errno) {
84             perror("argument parsing failed:");
85             return errno;
86         }
87         break;
88     case ARGP_KEY_ARG:
89         if (state->arg_num >= 1) {
90             // Too many arguments.
91             argp_usage (state);
92         }
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);
99         }
100         break;
101     default:
102         return ARGP_ERR_UNKNOWN;
103     }
104     return 0;
105 }
106
107 static struct argp argp = { options, parse_opt, args_doc, doc };
108
109 ///////////////////////////
110 // main
111 //////////////////////////
112 int
113 main(int argc, char **argv)
114 {
115     // arg parsing
116     argp_parse (&argp, argc, argv, 0, 0, &arguments);
117
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;
124     }
125
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;
133         }
134         return -1;
135     }
136
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;
144     };
145
146
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
157     };
158
159     printf( "local node id %d\n", iLocalId  & ~0xffc0);
160     printf( "remote node id %d\n", iRemoteId & ~0xffc0);
161
162     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
163         Connection* pCons = &cons[i];
164
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);
186     }
187
188     sleep( 5 );
189
190     for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) {
191         Connection* pCons = &cons[i];
192
193         if ( pCons->m_iIsoChannel != -1 ) {
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.