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

Revision 1336, 5.9 kB (checked in by ppalmers, 15 years ago)

Bring trunk up to date with branches/libffado-2.0:

"""
svn merge -r 1254:1299 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1301:1320 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1322:1323 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1329:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
"""

Add getSupportedSamplingFrequencies() to DICE, RME and Metric Halo AvDevices?

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_AMDTPTRANSMITSTREAMPROCESSOR__
25 #define __FFADO_AMDTPTRANSMITSTREAMPROCESSOR__
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 namespace Streaming {
55
56 class Port;
57 class AmdtpAudioPort;
58 class AmdtpMidiPort;
59
60 /*!
61 \brief The Base Class for an AMDTP transmit stream processor
62
63  This class implements a TransmitStreamProcessor that multiplexes Ports
64  into AMDTP streams.
65
66 */
67 class AmdtpTransmitStreamProcessor
68     : public StreamProcessor
69 {
70
71 public:
72     /**
73      * Create a AMDTP transmit StreamProcessor
74      * @param port 1394 port
75      * @param framerate frame rate
76      * @param dimension number of substreams in the ISO stream
77      *                  (midi-muxed is only one stream)
78      */
79     AmdtpTransmitStreamProcessor(FFADODevice &parent, int dimension);
80     virtual ~AmdtpTransmitStreamProcessor() {};
81
82     enum eChildReturnValue generatePacketHeader(unsigned char *data, unsigned int *length,
83                                                 unsigned char *tag, unsigned char *sy,
84                                                 uint32_t pkt_ctr);
85     enum eChildReturnValue generatePacketData(unsigned char *data, unsigned int *length);
86     enum eChildReturnValue generateEmptyPacketHeader(unsigned char *data, unsigned int *length,
87                                                      unsigned char *tag, unsigned char *sy,
88                                                      uint32_t pkt_ctr);
89     enum eChildReturnValue generateEmptyPacketData(unsigned char *data, unsigned int *length);
90     enum eChildReturnValue generateSilentPacketHeader(unsigned char *data, unsigned int *length,
91                                                       unsigned char *tag, unsigned char *sy,
92                                                       uint32_t pkt_ctr);
93     enum eChildReturnValue generateSilentPacketData(unsigned char *data, unsigned int *length);
94     virtual bool prepareChild();
95
96 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT
97 public:
98     void sendPayloadForNoDataPackets(bool b) {m_send_nodata_payload = b;};
99 #endif
100
101 public:
102     virtual unsigned int getEventSize()
103                     {return 4;};
104     virtual unsigned int getMaxPacketSize()
105                     {return 4 * (2 + getSytInterval() * m_dimension);};
106     virtual unsigned int getEventsPerFrame()
107                     { return m_dimension; };
108     virtual unsigned int getNominalFramesPerPacket()
109                     {return getSytInterval();};
110
111 protected:
112     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
113     bool transmitSilenceBlock(char *data, unsigned int nevents, unsigned int offset);
114
115 private:
116     unsigned int fillNoDataPacketHeader(struct iec61883_packet *packet, unsigned int* length);
117     unsigned int fillDataPacketHeader(struct iec61883_packet *packet, unsigned int* length, uint32_t ts);
118
119     int transmitBlock(char *data, unsigned int nevents,
120                         unsigned int offset);
121
122     void encodeAudioPortsSilence(quadlet_t *data, unsigned int offset, unsigned int nevents);
123     void encodeAudioPortsFloat(quadlet_t *data, unsigned int offset, unsigned int nevents);
124     void encodeAudioPortsInt24(quadlet_t *data, unsigned int offset, unsigned int nevents);
125     void encodeMidiPortsSilence(quadlet_t *data, unsigned int offset, unsigned int nevents);
126     void encodeMidiPorts(quadlet_t *data, unsigned int offset, unsigned int nevents);
127
128     unsigned int getFDF();
129     unsigned int getSytInterval();
130
131     struct iec61883_cip m_cip_status;
132     int m_dimension;
133     unsigned int m_syt_interval;
134     int m_fdf;
135     unsigned int m_dbc;
136
137 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT
138 private:
139     bool m_send_nodata_payload;
140 #endif
141
142 private: // local port caching for performance
143     struct _MBLA_port_cache {
144         AmdtpAudioPort*     port;
145         void*               buffer;
146         bool                enabled;
147 #ifdef DEBUG
148         unsigned int        buffer_size;
149 #endif
150     };
151     std::vector<struct _MBLA_port_cache> m_audio_ports;
152     int m_nb_audio_ports;
153
154     struct _MIDI_port_cache {
155         AmdtpMidiPort*      port;
156         void*               buffer;
157         bool                enabled;
158         unsigned int        position;
159         unsigned int        location;
160 #ifdef DEBUG
161         unsigned int        buffer_size;
162 #endif
163     };
164     std::vector<struct _MIDI_port_cache> m_midi_ports;
165     int m_nb_midi_ports;
166
167     bool initPortCache();
168     void updatePortCache();
169 };
170
171 } // end of namespace Streaming
172
173 #endif /* __FFADO_AMDTPTRANSMITSTREAMPROCESSOR__ */
174
Note: See TracBrowser for help on using the browser.