root/branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h

Revision 715, 4.6 kB (checked in by ppalmers, 15 years ago)

some more cleaning

Line 
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_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 namespace Streaming {
55
56 class Port;
57 class AmdtpAudioPort;
58 class AmdtpMidiPort;
59
60 /*!
61 \brief The Base Class for an AMDTP transmit stream processor
62
63  This class implements a TransmitStreamProcessor that multiplexes Ports
64  into AMDTP streams.
65
66 */
67 class AmdtpTransmitStreamProcessor
68     : public StreamProcessor
69 {
70
71 public:
72     /**
73      * Create a AMDTP transmit StreamProcessor
74      * @param port 1394 port
75      * @param framerate frame rate
76      * @param dimension number of substreams in the ISO stream
77      *                  (midi-muxed is only one stream)
78      */
79     AmdtpTransmitStreamProcessor(int port, int dimension);
80     virtual ~AmdtpTransmitStreamProcessor() {};
81
82     enum raw1394_iso_disposition
83             getPacket(unsigned char *data, unsigned int *length,
84                     unsigned char *tag, unsigned char *sy,
85                     int cycle, unsigned int dropped, unsigned int max_length);
86
87     bool init();
88     bool reset();
89     bool prepare();
90
91     bool prepareForStop();
92     bool prepareForStart();
93
94     bool prepareForEnable(uint64_t time_to_enable_at);
95
96     bool putFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents from the client
97     bool putFramesDry(unsigned int nbframes, int64_t ts);
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     unsigned int getPacketsPerPeriod();
107
108     unsigned int getMaxPacketSize() {return 4 * (2 + m_syt_interval * m_dimension);};
109
110 protected:
111     bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset);
112
113     struct iec61883_cip m_cip_status;
114
115     int m_dimension;
116     unsigned int m_syt_interval;
117
118     int m_fdf;
119
120     bool prefill();
121
122     unsigned int fillNoDataPacketHeader(struct iec61883_packet *packet, unsigned int* length);
123     unsigned int fillDataPacketHeader(struct iec61883_packet *packet, unsigned int* length, uint32_t ts);
124
125
126     bool transferSilence(unsigned int size);
127
128     int transmitBlock(char *data, unsigned int nevents,
129                         unsigned int offset);
130
131     bool encodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc);
132     int encodePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
133                                 unsigned int offset, unsigned int nevents);
134
135     int transmitSilenceBlock(char *data, unsigned int nevents,
136                         unsigned int offset);
137     int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data,
138                                 unsigned int offset, unsigned int nevents);
139     void updatePreparedState();
140
141     unsigned long m_last_timestamp;
142
143     unsigned int m_dbc;
144
145     unsigned int m_ringbuffer_size_frames;
146 };
147
148 } // end of namespace Streaming
149
150 #endif /* __FFADO_AMDTPTRANSMITSTREAMPROCESSOR__ */
151
Note: See TracBrowser for help on using the browser.