root/branches/streaming-rework/src/bounce/bounce_avdevice.cpp

Revision 413, 11.5 kB (checked in by pieterpalmers, 17 years ago)

- moved all generic IEEE1394 classes into libieee1394

src/libieee1394/ieee1394service.h
src/libieee1394/csr1212.h
src/libieee1394/configrom.cpp
src/libieee1394/configrom.h
src/libieee1394/ieee1394service.cpp
src/libieee1394/csr1212.c

Line 
1 /* bounce_avdevice.cpp
2  * Copyright (C) 2006 by Pieter Palmers
3  * Copyright (C) 2006 by Daniel Wagner
4  *
5  * This file is part of FreeBoB.
6  *
7  * FreeBoB is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  * FreeBoB is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with FreeBoB; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA.
20  */
21 #include "bounce/bounce_avdevice.h"
22
23 #include "libieee1394/configrom.h"
24 #include "libieee1394/ieee1394service.h"
25
26 #include "libfreebobavc/avc_plug_info.h"
27 #include "libfreebobavc/avc_extended_plug_info.h"
28 #include "libfreebobavc/avc_subunit_info.h"
29 #include "libfreebobavc/avc_extended_stream_format.h"
30 #include "libfreebobavc/avc_serialize.h"
31 #include "libfreebobavc/avc_definitions.h"
32
33 #include "debugmodule/debugmodule.h"
34
35 #include <iostream>
36 #include <sstream>
37 #include <stdint.h>
38
39 #include <string>
40 #include <netinet/in.h>
41
42 namespace Bounce {
43
44 // to define the supported devices
45 static VendorModelEntry supportedDeviceList[] =
46 {
47     {0x0B0001, 0x0B0001, 0x0B0001, "FreeBoB", "Bounce"},
48 };
49
50 IMPL_DEBUG_MODULE( BounceDevice, BounceDevice, DEBUG_LEVEL_VERBOSE );
51
52
53 BounceDevice::BounceDevice( std::auto_ptr< ConfigRom >( configRom ),
54                             Ieee1394Service& ieee1394service,
55                             int nodeId,
56                             int verboseLevel )
57     : m_configRom( configRom )
58     , m_1394Service( &ieee1394service )
59     , m_nodeId( nodeId )
60     , m_verboseLevel( verboseLevel )
61     , m_samplerate (44100)
62     , m_model( NULL )
63     , m_id(0)
64     , m_receiveProcessor ( 0 )
65     , m_receiveProcessorBandwidth ( -1 )
66     , m_transmitProcessor ( 0 )
67     , m_transmitProcessorBandwidth ( -1 )
68 {
69     setDebugLevel( verboseLevel );
70
71     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Bounce::BounceDevice (NodeID %d)\n",
72                  nodeId );
73 }
74
75 BounceDevice::~BounceDevice()
76 {
77
78 }
79
80 ConfigRom&
81 BounceDevice::getConfigRom() const
82 {
83     return *m_configRom;
84 }
85
86 bool
87 BounceDevice::probe( ConfigRom& configRom )
88 {
89 //     unsigned int vendorId = configRom.getNodeVendorId();
90     unsigned int modelId = configRom.getModelId();
91     unsigned int unitSpecifierId = configRom.getUnitSpecifierId();
92
93     for ( unsigned int i = 0;
94           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
95           ++i )
96     {
97         if (
98 //             ( supportedDeviceList[i].vendor_id == vendorId )
99              ( supportedDeviceList[i].model_id == modelId )
100              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
101            )
102         {
103             return true;
104         }
105     }
106
107     return false;
108 }
109
110 bool
111 BounceDevice::discover()
112 {
113 //      unsigned int resp_len=0;
114 //      quadlet_t request[6];
115 //      quadlet_t *resp;
116
117 //     unsigned int vendorId = m_configRom->getNodeVendorId();
118     unsigned int modelId = m_configRom->getModelId();
119     unsigned int unitSpecifierId = m_configRom->getUnitSpecifierId();
120
121     for ( unsigned int i = 0;
122           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
123           ++i )
124     {
125         if ( //( supportedDeviceList[i].vendor_id == vendorId )
126              ( supportedDeviceList[i].model_id == modelId )
127              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
128            )
129         {
130             m_model = &(supportedDeviceList[i]);
131         }
132     }
133
134     if (m_model != NULL) {
135         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
136                 m_model->vendor_name, m_model->model_name);
137         return true;
138     }
139    
140     debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering...\n" );
141
142         std::string vendor=std::string(FREEBOB_BOUNCE_SERVER_VENDORNAME);
143         std::string model=std::string(FREEBOB_BOUNCE_SERVER_MODELNAME);
144
145         if (!(m_configRom->getVendorName().compare(0,vendor.length(),vendor,0,vendor.length())==0)
146             || !(m_configRom->getModelName().compare(0,model.length(),model,0,model.length())==0)) {
147                 return false;
148         }
149 /*
150 // AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT
151         request[0] = htonl( AVC1394_CTYPE_STATUS | (AVC1394_SUBUNIT_TYPE_FREEBOB_BOUNCE_SERVER << 19) | (0 << 16)
152                         | AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT | 0x00);
153
154         request[1] =  0xFFFFFFFF;
155         resp = m_1394Service->transactionBlock( m_nodeId,
156                                                        request,
157                                                        2,
158                                                                &resp_len );
159 //      hexDump((unsigned char *)request,6*4);
160         if(resp) {
161                 char *buffer=(char *)&resp[1];
162                 resp[resp_len-1]=0;
163                 xmlDescription=buffer;
164 //              hexDump((unsigned char *)resp,6*4);
165         }
166 */
167         return true;
168 }
169
170 int BounceDevice::getSamplingFrequency( ) {
171     return m_samplerate;
172 }
173
174 bool BounceDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency ) {
175     int retval=convertESamplingFrequency( samplingFrequency );
176     if (retval) {
177         m_samplerate=retval;
178         return true;
179     } else return false;
180 }
181
182 bool BounceDevice::setId( unsigned int id) {
183     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id);
184     m_id=id;
185     return true;
186 }
187
188 bool
189 BounceDevice::lock() {
190
191     return true;
192 }
193
194
195 bool
196 BounceDevice::unlock() {
197
198     return true;
199 }
200
201 void
202 BounceDevice::showDevice() const
203 {
204     debugOutput(DEBUG_LEVEL_NORMAL, "\nI am the bouncedevice, the bouncedevice I am...\n" );
205     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor            :  %s\n", m_configRom->getVendorName().c_str());
206     debugOutput(DEBUG_LEVEL_NORMAL, "Model             :  %s\n", m_configRom->getModelName().c_str());
207     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor Name       :  %s\n", m_model->vendor_name);
208     debugOutput(DEBUG_LEVEL_NORMAL, "Model Name        :  %s\n", m_model->model_name);
209     debugOutput(DEBUG_LEVEL_NORMAL, "Node              :  %d\n", m_nodeId);
210     debugOutput(DEBUG_LEVEL_NORMAL, "GUID              :  0x%016llX\n", m_configRom->getGuid());
211     debugOutput(DEBUG_LEVEL_NORMAL, "AVC test response :  %s\n", xmlDescription.c_str());
212     debugOutput(DEBUG_LEVEL_NORMAL, "\n" );
213 }
214
215 bool
216 BounceDevice::addXmlDescription( xmlNodePtr deviceNode )
217 {
218
219     return false;
220
221 }
222
223 #define BOUNCE_NR_OF_CHANNELS 2
224
225 bool
226 BounceDevice::addPortsToProcessor(
227         FreebobStreaming::StreamProcessor *processor,
228         FreebobStreaming::AmdtpAudioPort::E_Direction direction) {
229
230     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to processor\n");
231
232     int i=0;
233     for (i=0;i<BOUNCE_NR_OF_CHANNELS;i++) {
234         char *buff;
235         asprintf(&buff,"dev%d%s_Port%d",m_id,direction==FreebobStreaming::AmdtpAudioPort::E_Playback?"p":"c",i);
236
237         FreebobStreaming::Port *p=NULL;
238         p=new FreebobStreaming::AmdtpAudioPort(
239                 buff,
240                 direction,
241                 // \todo: streaming backend expects indexing starting from 0
242                 // but bebob reports it starting from 1. Decide where
243                 // and how to handle this (pp: here)
244                 i,
245                 0,
246                 FreebobStreaming::AmdtpPortInfo::E_MBLA,
247                 0
248         );
249
250         if (!p) {
251             debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff);
252         } else {
253
254             if (!processor->addPort(p)) {
255                 debugWarning("Could not register port with stream processor\n");
256                 free(buff);
257                 return false;
258             } else {
259                 debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff);
260             }
261         }
262
263         free(buff);
264
265      }
266
267         return true;
268 }
269
270 bool
271 BounceDevice::prepare() {
272
273     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing BounceDevice...\n" );
274
275         m_receiveProcessor=new FreebobStreaming::AmdtpReceiveStreamProcessor(
276                                  m_1394Service->getPort(),
277                                  m_samplerate,
278                                  BOUNCE_NR_OF_CHANNELS);
279
280         if(!m_receiveProcessor->init()) {
281                 debugFatal("Could not initialize receive processor!\n");
282                 return false;
283
284         }
285
286         if (!addPortsToProcessor(m_receiveProcessor,
287                 FreebobStreaming::AmdtpAudioPort::E_Capture)) {
288                 debugFatal("Could not add ports to processor!\n");
289                 return false;
290         }
291
292         // do the transmit processor
293         m_transmitProcessor=new FreebobStreaming::AmdtpTransmitStreamProcessor(
294                                  m_1394Service->getPort(),
295                                  m_samplerate,
296                                  BOUNCE_NR_OF_CHANNELS);
297
298         m_transmitProcessor->setVerboseLevel(getDebugLevel());
299
300         if(!m_transmitProcessor->init()) {
301                 debugFatal("Could not initialize transmit processor!\n");
302                 return false;
303
304         }
305
306         if (!addPortsToProcessor(m_transmitProcessor,
307                 FreebobStreaming::AmdtpAudioPort::E_Playback)) {
308                 debugFatal("Could not add ports to processor!\n");
309                 return false;
310         }
311
312         return true;
313 }
314
315 int
316 BounceDevice::getStreamCount() {
317         return 2; // one receive, one transmit
318 }
319
320 FreebobStreaming::StreamProcessor *
321 BounceDevice::getStreamProcessorByIndex(int i) {
322         switch (i) {
323         case 0:
324                 return m_receiveProcessor;
325         case 1:
326                 return m_transmitProcessor;
327         default:
328                 return NULL;
329         }
330         return 0;
331 }
332
333 int
334 BounceDevice::startStreamByIndex(int i) {
335 //      int iso_channel=0;
336 //      int plug=0;
337 //      int hostplug=-1;
338 //
339         switch (i) {
340         case 0:
341 //              // do connection management: make connection
342 //              iso_channel = iec61883_cmp_connect(
343 //                      m_1394Service->getHandle(),
344 //                      m_nodeId | 0xffc0,
345 //                      &plug,
346 //                      raw1394_get_local_id (m_1394Service->getHandle()),
347 //                      &hostplug,
348 //                      &m_receiveProcessorBandwidth);
349 //
350 //              // set the channel obtained by the connection management
351     #warning TEST CODE FOR BOUNCE DEVICE !!
352         if (m_configRom->getNodeId()==0) {
353             m_receiveProcessor->setChannel(1);
354         } else {
355             m_receiveProcessor->setChannel(0);
356         }
357                 break;
358         case 1:
359 //              // do connection management: make connection
360 //              iso_channel = iec61883_cmp_connect(
361 //                      m_1394Service->getHandle(),
362 //                      raw1394_get_local_id (m_1394Service->getHandle()),
363 //                      &hostplug,
364 //                      m_nodeId | 0xffc0,
365 //                      &plug,
366 //                      &m_transmitProcessorBandwidth);
367 //
368 //              // set the channel obtained by the connection management
369 // //           m_receiveProcessor2->setChannel(iso_channel);
370     #warning TEST CODE FOR BOUNCE DEVICE !!
371         if (m_configRom->getNodeId()==0) {
372             m_transmitProcessor->setChannel(0);
373         } else {
374             m_transmitProcessor->setChannel(1);
375         }
376                 break;
377         default:
378                 return -1;
379         }
380
381         return 0;
382
383 }
384
385 int
386 BounceDevice::stopStreamByIndex(int i) {
387         // do connection management: break connection
388
389 //      int plug=0;
390 //      int hostplug=-1;
391 //
392 //      switch (i) {
393 //      case 0:
394 //              // do connection management: break connection
395 //              iec61883_cmp_disconnect(
396 //                      m_1394Service->getHandle(),
397 //                      m_nodeId | 0xffc0,
398 //                      plug,
399 //                      raw1394_get_local_id (m_1394Service->getHandle()),
400 //                      hostplug,
401 //                      m_receiveProcessor->getChannel(),
402 //                      m_receiveProcessorBandwidth);
403 //
404 //              break;
405 //      case 1:
406 //              // do connection management: break connection
407 //              iec61883_cmp_disconnect(
408 //                      m_1394Service->getHandle(),
409 //                      raw1394_get_local_id (m_1394Service->getHandle()),
410 //                      hostplug,
411 //                      m_nodeId | 0xffc0,
412 //                      plug,
413 //                      m_transmitProcessor->getChannel(),
414 //                      m_transmitProcessorBandwidth);
415 //
416 //              // set the channel obtained by the connection management
417 // //           m_receiveProcessor2->setChannel(iso_channel);
418 //              break;
419 //      default:
420 //              return 0;
421 //      }
422
423         return 0;
424 }
425
426 } // namespace
Note: See TracBrowser for help on using the browser.