root/trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.h

Revision 1535, 4.5 kB (checked in by ppalmers, 15 years ago)

add support for the FCA-202, and possibly other Oxford FW-92x devices

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __FFADO_AMDTPRECEIVESTREAMPROCESSOR__
25 #define __FFADO_AMDTPRECEIVESTREAMPROCESSOR__
26
27 /**
28  * This class implements IEC61883-6 / AM824 / AMDTP based streaming
29  */
30
31 #include "debugmodule/debugmodule.h"
32
33 #include "../generic/StreamProcessor.h"
34 #include "../util/cip.h"
35
36 #include <libiec61883/iec61883.h>
37 #include <pthread.h>
38
39 #define AMDTP_MAX_PACKET_SIZE 2048
40
41 #define IEC61883_STREAM_TYPE_MIDI   0x0D
42 #define IEC61883_STREAM_TYPE_SPDIF  0x00
43 #define IEC61883_STREAM_TYPE_MBLA   0x06
44
45 #define IEC61883_AM824_LABEL_MASK             0xFF000000
46 #define IEC61883_AM824_GET_LABEL(x)         (((x) & 0xFF000000) >> 24)
47 #define IEC61883_AM824_SET_LABEL(x,y)         ((x) | ((y)<<24))
48
49 #define IEC61883_AM824_LABEL_MIDI_NO_DATA     0x80
50 #define IEC61883_AM824_LABEL_MIDI_1X          0x81
51 #define IEC61883_AM824_LABEL_MIDI_2X          0x82
52 #define IEC61883_AM824_LABEL_MIDI_3X          0x83
53
54 #define IEC61883_AM824_HAS_LABEL(x, lbl)         (((x) & 0xFF000000) == (((quadlet_t)(lbl))<<24))
55
56 namespace Streaming {
57
58 class Port;
59 class AmdtpAudioPort;
60 class AmdtpMidiPort;
61 /*!
62 \brief The Base Class for an AMDTP receive stream processor
63
64  This class implements a ReceiveStreamProcessor that demultiplexes
65  AMDTP streams into Ports.
66
67 */
68 class AmdtpReceiveStreamProcessor
69     : public StreamProcessor
70 {
71
72 public:
73     /**
74      * Create a AMDTP receive StreamProcessor
75      * @param port 1394 port
76      * @param dimension number of substreams in the ISO stream
77      *                  (midi-muxed is only one stream)
78      */
79     AmdtpReceiveStreamProcessor(FFADODevice &parent, int dimension);
80     virtual ~AmdtpReceiveStreamProcessor() {};
81
82     virtual enum eChildReturnValue processPacketHeader(unsigned char *data, unsigned int length,
83                                                        unsigned char tag, unsigned char sy,
84                                                        uint32_t pkt_ctr);
85     virtual enum eChildReturnValue processPacketData(unsigned char *data, unsigned int length);
86
87     virtual bool prepareChild();
88
89 public:
90     virtual unsigned int getEventSize()
91                     {return 4;};
92     virtual unsigned int getMaxPacketSize()
93                     {return 4 * (2 + getSytInterval() * m_dimension);};
94     virtual unsigned int getEventsPerFrame()
95                     { return m_dimension; };
96     virtual unsigned int getNominalFramesPerPacket()
97                     {return getSytInterval();};
98
99 protected:
100     bool processReadBlock(char *data, unsigned int nevents, unsigned int offset);
101
102 protected:
103     void decodeAudioPortsFloat(quadlet_t *data, unsigned int offset, unsigned int nevents);
104     void decodeAudioPortsInt24(quadlet_t *data, unsigned int offset, unsigned int nevents);
105     void decodeMidiPorts(quadlet_t *data, unsigned int offset, unsigned int nevents);
106
107     unsigned int getSytInterval();
108
109     int m_dimension;
110     unsigned int m_syt_interval;
111
112 private: // local port caching for performance
113     struct _MBLA_port_cache {
114         AmdtpAudioPort*     port;
115         void*               buffer;
116         bool                enabled;
117 #ifdef DEBUG
118         unsigned int        buffer_size;
119 #endif
120     };
121     std::vector<struct _MBLA_port_cache> m_audio_ports;
122     unsigned int m_nb_audio_ports;
123
124     struct _MIDI_port_cache {
125         AmdtpMidiPort*      port;
126         void*               buffer;
127         bool                enabled;
128         unsigned int        position;
129         unsigned int        location;
130 #ifdef DEBUG
131         unsigned int        buffer_size;
132 #endif
133     };
134     std::vector<struct _MIDI_port_cache> m_midi_ports;
135     unsigned int m_nb_midi_ports;
136
137     bool initPortCache();
138     void updatePortCache();
139 };
140
141
142 } // end of namespace Streaming
143
144 #endif /* __FFADO_AMDTPRECEIVESTREAMPROCESSOR__ */
145
Note: See TracBrowser for help on using the browser.