root/branches/streaming-rework/src/libieee1394/ieee1394service.h

Revision 424, 7.4 kB (checked in by pieterpalmers, 15 years ago)

- The library can now be started in 'slave mode', creating a BounceSlaveDevice?.

On a discovering node, this slave device is discovered as a BounceDevice?.
Streaming does not work yet, something wrong with the timestamps.

- Implemented the 'snoop mode', that allows a client to 'snoop' the streams

between another host and a device. It is only implemented for BeBoB devices.
The channel numbers and stream configuration are automatically detected.
Note that it currently relies on a rather hackish support for reading the
{i,o}PCR plugs by using private functions of libiec61883

- changed jack backend to support these two new features

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* Ieee1394Service.cpp
2  * Copyright (C) 2005,06 by Daniel Wagner
3  * Copyright (C) 2007 by Pieter Palmers
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 #ifndef FREEBOBIEEE1394SERVICE_H
23 #define FREEBOBIEEE1394SERVICE_H
24
25 #include "fbtypes.h"
26 #include "threads.h"
27
28 #include "debugmodule/debugmodule.h"
29
30 #include "IEC61883.h"
31
32 #include <libraw1394/raw1394.h>
33 #include <pthread.h>
34
35 #include <vector>
36
37 class ARMHandler;
38
39 class Ieee1394Service : public IEC61883 {
40 public:
41     Ieee1394Service();
42     ~Ieee1394Service();
43
44     bool initialize( int port );
45
46     int getPort()
47         { return m_port; }
48    /**
49     * @brief get number of nodes on the bus
50     *
51     * Since the root node always has
52     * the highest node ID, this number can be used to determine that ID (it's
53     * LOCAL_BUS|(count-1)).
54     *
55     * @return the number of nodes on the bus to which the port is connected.
56     * This value can change with every bus reset.
57     */
58     int getNodeCount();
59    
60    /**
61     * @brief get the node id of the local node
62     *
63     * @note does not include the bus part (0xFFC0)
64     *
65     * @return the node id of the local node
66     * This value can change with every bus reset.
67     */
68     nodeid_t getLocalNodeId();
69    
70    /**
71     * @brief send async read request to a node and wait for response.
72     *
73     * This does the complete transaction and will return when it's finished.
74     *
75     * @param node target node (\todo needs 0xffc0 stuff)
76     * @param addr address to read from
77     * @param length amount of data to read in quadlets
78     * @param buffer pointer to buffer where data will be saved
79    
80     * @return true on success or false on failure (sets errno)
81     */
82     bool read( fb_nodeid_t nodeId,
83                fb_nodeaddr_t addr,
84                size_t length,
85                fb_quadlet_t* buffer );
86
87     bool read_quadlet( fb_nodeid_t nodeId,
88                        fb_nodeaddr_t addr,
89                        fb_quadlet_t* buffer );
90
91     bool read_octlet( fb_nodeid_t nodeId,
92                       fb_nodeaddr_t addr,
93                       fb_octlet_t* buffer );
94
95     /**
96     * @brief send async write request to a node and wait for response.
97     *
98     * This does the complete transaction and will return when it's finished.
99     *
100     * @param node target node (\XXX needs 0xffc0 stuff)
101     * @param addr address to write to
102     * @param length amount of data to write in quadlets
103     * @param data pointer to data to be sent
104     *
105     * @return true on success or false on failure (sets errno)
106     */
107     bool write( fb_nodeid_t nodeId,
108                 fb_nodeaddr_t addr,
109                 size_t length,
110                 fb_quadlet_t* data );
111
112     bool write_quadlet( fb_nodeid_t nodeId,
113                         fb_nodeaddr_t addr,
114                         fb_quadlet_t data );
115
116     bool write_octlet(  fb_nodeid_t nodeId,
117                         fb_nodeaddr_t addr,
118                         fb_octlet_t data );
119
120     /**
121      * @brief send 64-bit compare-swap lock request and wait for response.
122      *
123      * swaps the content of \ref addr with \ref swap_value , but only if
124      * the content of \ref addr equals \ref compare_with
125      *
126      * @param nodeId target node ID
127      * @param addr address within target node address space
128      * @param compare_with value to compare \ref addr with
129      * @param swap_value new value to put in \ref addr
130      * @param result the value (originally) in \ref addr
131      *
132      * @return true if succesful, false otherwise
133      */
134     bool lockCompareSwap64(  fb_nodeid_t nodeId,
135                         fb_nodeaddr_t addr,
136                         fb_octlet_t  compare_value,
137                         fb_octlet_t  swap_value,
138                         fb_octlet_t* result );
139
140     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
141                                     fb_quadlet_t* buf,
142                                     int len,
143                                     unsigned int* resp_len );
144
145     bool transactionBlockClose();
146
147     raw1394handle_t getHandle() {return m_handle;};
148
149     bool setVerbose( int verboseLevel );
150     int getVerboseLevel();
151
152     bool addBusResetHandler( Functor* functor );
153     bool remBusResetHandler( Functor* functor );
154    
155     /**
156      * @brief register an AddressRangeMapping Handler
157      * @param h pointer to the handler to register
158      *
159      * @return true on success or false on failure
160      **/
161
162     bool registerARMHandler( ARMHandler *h );
163
164     /**
165      * @brief unregister ARM range
166      * @param h pointer to the handler to unregister
167      * @return true if successful, false otherwise
168      */
169     bool unregisterARMHandler( ARMHandler *h );
170    
171     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
172
173 // ISO channel stuff
174 public:
175     signed int getAvailableBandwidth();
176     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
177     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
178                                      nodeid_t recv_node, int recv_plug);
179     bool freeIsoChannel(signed int channel);
180    
181 private:
182     enum EAllocType {
183         AllocFree = 0, // not allocated (by us)
184         AllocGeneric = 1, // allocated with generic functions
185         AllocCMP=2 // allocated with CMP
186     };
187
188     struct ChannelInfo {
189         int channel;
190         int bandwidth;
191         enum EAllocType alloctype;
192         nodeid_t xmit_node;
193         int xmit_plug;
194         nodeid_t recv_node;
195         int recv_plug;
196     };
197    
198     // the info for the channels we manage
199     struct ChannelInfo m_channels[64];
200    
201     bool unregisterIsoChannel(unsigned int c);
202     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
203
204 private:
205
206     bool startRHThread();
207     void stopRHThread();
208     static void* rHThread( void* arg );
209
210     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
211     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
212    
213     static int resetHandlerLowLevel( raw1394handle_t handle,
214                     unsigned int generation );
215     bool resetHandler( unsigned int generation );
216    
217     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
218                      byte_t request_type, unsigned int requested_length,
219                      void *data);
220     bool armHandler(  unsigned long arm_tag,
221                      byte_t request_type, unsigned int requested_length,
222                      void *data);
223
224     raw1394handle_t m_handle;
225     raw1394handle_t m_resetHandle;
226     int             m_port;
227     unsigned int    m_generation;
228
229     pthread_t       m_thread;
230     pthread_mutex_t m_mutex;
231     bool            m_threadRunning;
232
233     typedef std::vector< Functor* > reset_handler_vec_t;
234     reset_handler_vec_t m_busResetHandlers;
235    
236     // ARM stuff
237     arm_tag_handler_t m_default_arm_handler;
238    
239     typedef std::vector< ARMHandler * > arm_handler_vec_t;
240     arm_handler_vec_t m_armHandlers;
241    
242     DECLARE_DEBUG_MODULE;
243 };
244
245 #endif
Note: See TracBrowser for help on using the browser.