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

Revision 1531, 6.9 kB (checked in by ppalmers, 14 years ago)

svn merge -r 1506:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

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 #include "config.h"
31
32 #include "debugmodule/debugmodule.h"
33
34 #include "../generic/StreamProcessor.h"
35 #include "../util/cip.h"
36
37 #include <libiec61883/iec61883.h>
38 #include <pthread.h>
39
40 #define AMDTP_MAX_PACKET_SIZE 2048
41
42 #define IEC61883_STREAM_TYPE_MIDI   0x0D
43 #define IEC61883_STREAM_TYPE_SPDIF  0x00
44 #define IEC61883_STREAM_TYPE_MBLA   0x06
45
46 #define IEC61883_AM824_LABEL_MASK             0xFF000000
47 #define IEC61883_AM824_GET_LABEL(x)         (((x) & 0xFF000000) >> 24)
48 #define IEC61883_AM824_SET_LABEL(x,y)         ((x) | ((y)<<24))
49
50 #define IEC61883_AM824_LABEL_MIDI_NO_DATA     0x80
51 #define IEC61883_AM824_LABEL_MIDI_1X          0x81
52 #define IEC61883_AM824_LABEL_MIDI_2X          0x82
53 #define IEC61883_AM824_LABEL_MIDI_3X          0x83
54
55 #define IEC61883_AM824_HAS_LABEL(x, lbl)         (((x) & 0xFF000000) == (((quadlet_t)(lbl))<<24))
56
57 namespace Streaming {
58
59 class Port;
60 class AmdtpAudioPort;
61 class AmdtpMidiPort;
62
63 /*!
64 \brief The Base Class for an AMDTP transmit stream processor
65
66  This class implements a TransmitStreamProcessor that multiplexes Ports
67  into AMDTP streams.
68
69 */
70 class AmdtpTransmitStreamProcessor
71     : public StreamProcessor
72 {
73
74 public:
75     /**
76      * Create a AMDTP transmit StreamProcessor
77      * @param port 1394 port
78      * @param framerate frame rate
79      * @param dimension number of substreams in the ISO stream
80      *                  (midi-muxed is only one stream)
81      */
82     AmdtpTransmitStreamProcessor(FFADODevice &parent, int dimension);
83     virtual ~AmdtpTransmitStreamProcessor() {};
84
85     enum eChildReturnValue generatePacketHeader(unsigned char *data, unsigned int *length,
86                                                 unsigned char *tag, unsigned char *sy,
87                                                 uint32_t pkt_ctr);
88     enum eChildReturnValue generatePacketData(unsigned char *data, unsigned int *length);
89     enum eChildReturnValue generateEmptyPacketHeader(unsigned char *data, unsigned int *length,
90                                                      unsigned char *tag, unsigned char *sy,
91                                                      uint32_t pkt_ctr);
92     enum eChildReturnValue generateEmptyPacketData(unsigned char *data, unsigned int *length);
93     enum eChildReturnValue generateSilentPacketHeader(unsigned char *data, unsigned int *length,
94                                                       unsigned char *tag, unsigned char *sy,
95                                                       uint32_t pkt_ctr);
96     enum eChildReturnValue generateSilentPacketData(unsigned char *data, unsigned int *length);
97     virtual bool prepareChild();
98
99 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT
100 public:
101     void sendPayloadForNoDataPackets(bool b) {m_send_nodata_payload = b;};
102 #endif
103
104 public:
105     virtual unsigned int getEventSize()
106                     {return 4;};
107     virtual unsigned int getMaxPacketSize()
108                     {return 4 * (2 + getSytInterval() * m_dimension);};
109     virtual unsigned int getEventsPerFrame()
110                     { return m_dimension; };
111     virtual unsigned int getNominalFramesPerPacket()
112                     {return getSytInterval();};
113     // transmit control parameters
114     virtual int getMaxCyclesToTransmitEarly()
115                     {return m_max_cycles_to_transmit_early;};
116     virtual void setMaxCyclesToTransmitEarly(int x)
117                     {m_max_cycles_to_transmit_early = x;};
118     virtual unsigned int getTransferDelay()
119                     {return m_transmit_transfer_delay;};
120     virtual void setTransferDelay(unsigned int x)
121                     {m_transmit_transfer_delay = x;};
122     virtual int getMinCyclesBeforePresentation()
123                     {return m_min_cycles_before_presentation;};
124     virtual void setMinCyclesBeforePresentation(int x)
125                     {m_min_cycles_before_presentation = x;};
126
127 protected:
128     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
129     bool transmitSilenceBlock(char *data, unsigned int nevents, unsigned int offset);
130
131 private:
132     unsigned int fillNoDataPacketHeader(struct iec61883_packet *packet, unsigned int* length);
133     unsigned int fillDataPacketHeader(struct iec61883_packet *packet, unsigned int* length, uint32_t ts);
134
135     int transmitBlock(char *data, unsigned int nevents,
136                         unsigned int offset);
137
138     void encodeAudioPortsSilence(quadlet_t *data, unsigned int offset, unsigned int nevents);
139     void encodeAudioPortsFloat(quadlet_t *data, unsigned int offset, unsigned int nevents);
140     void encodeAudioPortsInt24(quadlet_t *data, unsigned int offset, unsigned int nevents);
141     void encodeMidiPortsSilence(quadlet_t *data, unsigned int offset, unsigned int nevents);
142     void encodeMidiPorts(quadlet_t *data, unsigned int offset, unsigned int nevents);
143
144     unsigned int getFDF();
145     unsigned int getSytInterval();
146
147     struct iec61883_cip m_cip_status;
148     int m_dimension;
149     unsigned int m_syt_interval;
150     int m_fdf;
151     unsigned int m_dbc;
152
153 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT
154 private:
155     bool m_send_nodata_payload;
156 #endif
157     int m_max_cycles_to_transmit_early;
158     unsigned int m_transmit_transfer_delay;
159     int m_min_cycles_before_presentation;
160
161 private: // local port caching for performance
162     struct _MBLA_port_cache {
163         AmdtpAudioPort*     port;
164         void*               buffer;
165         bool                enabled;
166 #ifdef DEBUG
167         unsigned int        buffer_size;
168 #endif
169     };
170     std::vector<struct _MBLA_port_cache> m_audio_ports;
171     int m_nb_audio_ports;
172
173     struct _MIDI_port_cache {
174         AmdtpMidiPort*      port;
175         void*               buffer;
176         bool                enabled;
177         unsigned int        position;
178         unsigned int        location;
179 #ifdef DEBUG
180         unsigned int        buffer_size;
181 #endif
182     };
183     std::vector<struct _MIDI_port_cache> m_midi_ports;
184     int m_nb_midi_ports;
185
186     bool initPortCache();
187     void updatePortCache();
188 };
189
190 } // end of namespace Streaming
191
192 #endif /* __FFADO_AMDTPTRANSMITSTREAMPROCESSOR__ */
193
Note: See TracBrowser for help on using the browser.