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

Revision 1556, 6.1 kB (checked in by ppalmers, 12 years ago)

fixes #207

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