root/branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h

Revision 1525, 6.8 kB (checked in by ppalmers, 12 years ago)

- Allow to specify the DLL bandwidths for the CycleTimerHelper? and the TimestampedBuffer? in absolute units (Hz). This ensures samplerate-independent operation
- Reduce the default DLL bandwidth for the TimestampedBuffer?'s. This improves timestamp timing with a factor 10x, which should benefit especially the timing sensitive devices (MOTU).
- Allow to specify the DLL bandwith and other transmit settings through the configuration file
- Implement a sanity check for the instantanous samplerate to detect bogus timestamp processing

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