root/branches/libfreebob-2.0/src/bounce/bounce_avdevice.cpp

Revision 336, 10.1 kB (checked in by pieterpalmers, 17 years ago)

- Merged the developments on trunk since branch-off:

branch occurred at rev 194
svn merge -r 194:HEAD https://svn.sourceforge.net/svnroot/freebob/trunk/libfreebob

- Modified libfreebobavc to use the messagebuffer for debug info.
- This should compile and run

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
22 #include "bounce/bounce_avdevice.h"
23 #include "configrom.h"
24
25 #include "libfreebobavc/avc_plug_info.h"
26 #include "libfreebobavc/avc_extended_plug_info.h"
27 #include "libfreebobavc/avc_subunit_info.h"
28 #include "libfreebobavc/avc_extended_stream_format.h"
29 #include "libfreebobavc/serialize.h"
30 #include "libfreebobavc/ieee1394service.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 IMPL_DEBUG_MODULE( BounceDevice, BounceDevice, DEBUG_LEVEL_VERBOSE );
45
46
47 BounceDevice::BounceDevice( std::auto_ptr< ConfigRom >( configRom ),
48                             Ieee1394Service& ieee1394service,
49                             int nodeId,
50                             int verboseLevel )
51     : m_configRom( configRom )
52     , m_1394Service( &ieee1394service )
53     , m_nodeId( nodeId )
54     , m_verboseLevel( verboseLevel )
55     , m_samplerate (44100)
56     , m_id(0)
57     , m_receiveProcessor ( 0 )
58     , m_receiveProcessorBandwidth ( -1 )
59     , m_transmitProcessor ( 0 )
60     , m_transmitProcessorBandwidth ( -1 )
61 {
62     setDebugLevel( verboseLevel );
63    
64     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Bounce::BounceDevice (NodeID %d)\n",
65                  nodeId );
66 }
67
68 BounceDevice::~BounceDevice()
69 {
70
71 }
72
73 ConfigRom&
74 BounceDevice::getConfigRom() const
75 {
76     return *m_configRom;
77 }
78
79 struct VendorModelEntry {
80     unsigned int vendor_id;
81     unsigned int model_id;
82 };
83
84 static VendorModelEntry supportedDeviceList[] =
85 {
86 //     {0x0000, 0x000000}, 
87 };
88
89 bool
90 BounceDevice::probe( ConfigRom& configRom )
91 {
92     unsigned int vendorId = configRom.getNodeVendorId();
93     unsigned int modelId = configRom.getModelId();
94
95     for ( unsigned int i = 0;
96           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
97           ++i )
98     {
99         if ( ( supportedDeviceList[i].vendor_id == vendorId )
100              && ( supportedDeviceList[i].model_id == modelId )
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     debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering...\n" );
118
119         std::string vendor=std::string(FREEBOB_BOUNCE_SERVER_VENDORNAME);
120         std::string model=std::string(FREEBOB_BOUNCE_SERVER_MODELNAME);
121        
122         if (!(m_configRom->getVendorName().compare(0,vendor.length(),vendor,0,vendor.length())==0)
123             || !(m_configRom->getModelName().compare(0,model.length(),model,0,model.length())==0)) {
124                 return false;
125         }
126 /*
127 // AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT
128         request[0] = htonl( AVC1394_CTYPE_STATUS | (AVC1394_SUBUNIT_TYPE_FREEBOB_BOUNCE_SERVER << 19) | (0 << 16)
129                         | AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT | 0x00);
130
131         request[1] =  0xFFFFFFFF;
132         resp = m_1394Service->transactionBlock( m_nodeId,
133                                                        request,
134                                                        2,
135                                                                &resp_len );
136 //      hexDump((unsigned char *)request,6*4);
137         if(resp) {
138                 char *buffer=(char *)&resp[1];
139                 resp[resp_len-1]=0;
140                 xmlDescription=buffer;
141 //              hexDump((unsigned char *)resp,6*4);
142         }
143 */
144         return true;
145 }
146
147 int BounceDevice::getSamplingFrequency( ) {
148     return m_samplerate;
149 }
150
151 bool BounceDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency ) {
152     int retval=convertESamplingFrequency( samplingFrequency );
153     if (retval) {
154         m_samplerate=retval;
155         return true;
156     } else return false;
157 }
158
159 bool BounceDevice::setId( unsigned int id) {
160     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id);
161     m_id=id;
162     return true;
163 }
164
165 void
166 BounceDevice::showDevice() const
167 {
168     debugOutput(DEBUG_LEVEL_NORMAL, "\nI am the bouncedevice, the bouncedevice I am...\n" );
169     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor            :  %s\n", m_configRom->getVendorName().c_str());
170     debugOutput(DEBUG_LEVEL_NORMAL, "Model             :  %s\n", m_configRom->getModelName().c_str());
171     debugOutput(DEBUG_LEVEL_NORMAL, "Node              :  %d\n", m_nodeId);
172     debugOutput(DEBUG_LEVEL_NORMAL, "GUID              :  0x%016llX\n", m_configRom->getGuid());
173     debugOutput(DEBUG_LEVEL_NORMAL, "AVC test response :  %s\n", xmlDescription.c_str());
174     debugOutput(DEBUG_LEVEL_NORMAL, "\n" );
175 }
176
177 bool
178 BounceDevice::addXmlDescription( xmlNodePtr deviceNode )
179 {
180    
181     return false;
182
183 }
184
185 #define BOUNCE_NR_OF_CHANNELS 2
186
187 bool
188 BounceDevice::addPortsToProcessor(
189         FreebobStreaming::StreamProcessor *processor,
190         FreebobStreaming::AmdtpAudioPort::E_Direction direction) {
191        
192     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to processor\n");
193        
194     int i=0;
195     for (i=0;i<BOUNCE_NR_OF_CHANNELS;i++) {
196         char *buff;
197         asprintf(&buff,"dev%d%s_Port%d",m_id,direction==FreebobStreaming::AmdtpAudioPort::E_Playback?"p":"c",i);
198        
199         FreebobStreaming::Port *p=NULL;
200         p=new FreebobStreaming::AmdtpAudioPort(
201                 buff,
202                 direction,
203                 // \todo: streaming backend expects indexing starting from 0
204                 // but bebob reports it starting from 1. Decide where
205                 // and how to handle this (pp: here)
206                 i,
207                 0,
208                 FreebobStreaming::AmdtpPortInfo::E_MBLA,
209                 0
210         );
211    
212         if (!p) {
213             debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff);
214         } else {
215    
216             if (!processor->addPort(p)) {
217                 debugWarning("Could not register port with stream processor\n");
218                 free(buff);
219                 return false;
220             } else {
221                 debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff);
222            
223             }
224         }
225        
226         free(buff);
227        
228      }
229
230         return true;
231 }
232
233 bool
234 BounceDevice::prepare() {
235
236     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing BounceDevice...\n" );
237
238         m_receiveProcessor=new FreebobStreaming::AmdtpReceiveStreamProcessor(
239                                  m_1394Service->getPort(),
240                                  m_samplerate,
241                                  BOUNCE_NR_OF_CHANNELS);
242                                  
243         if(!m_receiveProcessor->init()) {
244                 debugFatal("Could not initialize receive processor!\n");
245                 return false;
246        
247         }
248
249         if (!addPortsToProcessor(m_receiveProcessor,
250                 FreebobStreaming::AmdtpAudioPort::E_Capture)) {
251                 debugFatal("Could not add ports to processor!\n");
252                 return false;
253         }
254
255         // do the transmit processor
256         m_transmitProcessor=new FreebobStreaming::AmdtpTransmitStreamProcessor(
257                                  m_1394Service->getPort(),
258                                  m_samplerate,
259                                  BOUNCE_NR_OF_CHANNELS);
260                                  
261         m_transmitProcessor->setVerboseLevel(getDebugLevel());
262        
263         if(!m_transmitProcessor->init()) {
264                 debugFatal("Could not initialize transmit processor!\n");
265                 return false;
266        
267         }
268
269         if (!addPortsToProcessor(m_transmitProcessor,
270                 FreebobStreaming::AmdtpAudioPort::E_Playback)) {
271                 debugFatal("Could not add ports to processor!\n");
272                 return false;
273         }
274        
275         return true;
276 }
277
278 int
279 BounceDevice::getStreamCount() {
280         return 2; // one receive, one transmit
281 }
282
283 FreebobStreaming::StreamProcessor *
284 BounceDevice::getStreamProcessorByIndex(int i) {
285         switch (i) {
286         case 0:
287                 return m_receiveProcessor;
288         case 1:
289                 return m_transmitProcessor;
290         default:
291                 return NULL;
292         }
293         return 0;
294 }
295
296 int
297 BounceDevice::startStreamByIndex(int i) {
298 //      int iso_channel=0;
299 //      int plug=0;
300 //      int hostplug=-1;
301 //     
302         switch (i) {
303         case 0:
304 //              // do connection management: make connection
305 //              iso_channel = iec61883_cmp_connect(
306 //                      m_1394Service->getHandle(),
307 //                      m_nodeId | 0xffc0,
308 //                      &plug,
309 //                      raw1394_get_local_id (m_1394Service->getHandle()),
310 //                      &hostplug,
311 //                      &m_receiveProcessorBandwidth);
312 //             
313 //              // set the channel obtained by the connection management
314                 m_receiveProcessor->setChannel(1);
315                 break;
316         case 1:
317 //              // do connection management: make connection
318 //              iso_channel = iec61883_cmp_connect(
319 //                      m_1394Service->getHandle(),
320 //                      raw1394_get_local_id (m_1394Service->getHandle()),
321 //                      &hostplug,
322 //                      m_nodeId | 0xffc0,
323 //                      &plug,
324 //                      &m_transmitProcessorBandwidth);
325 //             
326 //              // set the channel obtained by the connection management
327 // //           m_receiveProcessor2->setChannel(iso_channel);
328                 m_transmitProcessor->setChannel(0);
329                 break;
330         default:
331                 return -1;
332         }
333
334         return 0;
335
336 }
337
338 int
339 BounceDevice::stopStreamByIndex(int i) {
340         // do connection management: break connection
341
342 //      int plug=0;
343 //      int hostplug=-1;
344 //
345 //      switch (i) {
346 //      case 0:
347 //              // do connection management: break connection
348 //              iec61883_cmp_disconnect(
349 //                      m_1394Service->getHandle(),
350 //                      m_nodeId | 0xffc0,
351 //                      plug,
352 //                      raw1394_get_local_id (m_1394Service->getHandle()),
353 //                      hostplug,
354 //                      m_receiveProcessor->getChannel(),
355 //                      m_receiveProcessorBandwidth);
356 //
357 //              break;
358 //      case 1:
359 //              // do connection management: break connection
360 //              iec61883_cmp_disconnect(
361 //                      m_1394Service->getHandle(),
362 //                      raw1394_get_local_id (m_1394Service->getHandle()),
363 //                      hostplug,
364 //                      m_nodeId | 0xffc0,
365 //                      plug,
366 //                      m_transmitProcessor->getChannel(),
367 //                      m_transmitProcessorBandwidth);
368 //
369 //              // set the channel obtained by the connection management
370 // //           m_receiveProcessor2->setChannel(iso_channel);
371 //              break;
372 //      default:
373 //              return 0;
374 //      }
375
376         return 0;
377 }
378
379
380
381 }
Note: See TracBrowser for help on using the browser.