1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 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 library is free software; you can redistribute it and/or |
---|
10 |
* modify it under the terms of the GNU Lesser General Public |
---|
11 |
* License version 2.1, as published by the Free Software Foundation; |
---|
12 |
* |
---|
13 |
* This library is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 |
* Lesser General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU Lesser General Public |
---|
19 |
* License along with this library; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 |
* MA 02110-1301 USA |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#ifndef __FFADO_AMDTPRECEIVESTREAMPROCESSOR__ |
---|
25 |
#define __FFADO_AMDTPRECEIVESTREAMPROCESSOR__ |
---|
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 |
\brief The Base Class for an AMDTP receive stream processor |
---|
61 |
|
---|
62 |
This class implements a ReceiveStreamProcessor that demultiplexes |
---|
63 |
AMDTP streams into Ports. |
---|
64 |
|
---|
65 |
*/ |
---|
66 |
class AmdtpReceiveStreamProcessor |
---|
67 |
: public StreamProcessor |
---|
68 |
{ |
---|
69 |
|
---|
70 |
public: |
---|
71 |
/** |
---|
72 |
* Create a AMDTP receive StreamProcessor |
---|
73 |
* @param port 1394 port |
---|
74 |
* @param dimension number of substreams in the ISO stream |
---|
75 |
* (midi-muxed is only one stream) |
---|
76 |
*/ |
---|
77 |
AmdtpReceiveStreamProcessor(int port, int dimension); |
---|
78 |
virtual ~AmdtpReceiveStreamProcessor() {}; |
---|
79 |
|
---|
80 |
bool processPacketHeader(unsigned char *data, unsigned int length, |
---|
81 |
unsigned char channel, unsigned char tag, unsigned char sy, |
---|
82 |
unsigned int cycle, unsigned int dropped); |
---|
83 |
bool processPacketData(unsigned char *data, unsigned int length, |
---|
84 |
unsigned char channel, unsigned char tag, unsigned char sy, |
---|
85 |
unsigned int cycle, unsigned int dropped); |
---|
86 |
|
---|
87 |
virtual bool prepareChild(); |
---|
88 |
|
---|
89 |
public: |
---|
90 |
virtual unsigned int getEventSize() |
---|
91 |
{return 4;}; |
---|
92 |
virtual unsigned int getMaxPacketSize() |
---|
93 |
{return 4 * (2 + m_syt_interval * m_dimension);}; |
---|
94 |
virtual unsigned int getEventsPerFrame() |
---|
95 |
{ return m_dimension; }; |
---|
96 |
virtual unsigned int getUpdatePeriod() |
---|
97 |
{return m_syt_interval;}; |
---|
98 |
|
---|
99 |
// We have 1 period of samples = m_period |
---|
100 |
// this period takes m_period/m_framerate seconds of time |
---|
101 |
// during this time, 8000 packets are sent |
---|
102 |
// unsigned int getPacketsPerPeriod() {return (m_period*8000)/m_framerate;}; |
---|
103 |
|
---|
104 |
// however, if we only count the number of used packets |
---|
105 |
// it is m_period / m_syt_interval |
---|
106 |
virtual unsigned int getPacketsPerPeriod(); |
---|
107 |
|
---|
108 |
protected: |
---|
109 |
|
---|
110 |
bool processReadBlock(char *data, unsigned int nevents, unsigned int offset); |
---|
111 |
bool provideSilenceBlock(unsigned int nevents, unsigned int offset); |
---|
112 |
|
---|
113 |
bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); |
---|
114 |
|
---|
115 |
int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); |
---|
116 |
int provideSilenceToPort(AmdtpAudioPort *p, unsigned int offset, unsigned int nevents); |
---|
117 |
|
---|
118 |
int m_dimension; |
---|
119 |
unsigned int m_syt_interval; |
---|
120 |
|
---|
121 |
uint64_t m_last_syt; /// FIXME:debug |
---|
122 |
uint64_t m_last_now; /// FIXME:debug |
---|
123 |
}; |
---|
124 |
|
---|
125 |
|
---|
126 |
} // end of namespace Streaming |
---|
127 |
|
---|
128 |
#endif /* __FFADO_AMDTPRECEIVESTREAMPROCESSOR__ */ |
---|
129 |
|
---|