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