JackTrip.h 6.15 KB
Newer Older
jcaceres's avatar
jcaceres committed
1
2
//*****************************************************************
/*
jcaceres's avatar
jcaceres committed
3
  JackTrip: A System for High-Quality Audio Network Performance
jcaceres's avatar
jcaceres committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  over the Internet

  Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe.
  SoundWIRE group at CCRMA, Stanford University.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:
  
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/
//*****************************************************************

/**
jcaceres's avatar
jcaceres committed
33
 * \file JackTrip.h
jcaceres's avatar
jcaceres committed
34
35
36
37
 * \author Juan-Pablo Caceres
 * \date July 2008
 */

jcaceres's avatar
jcaceres committed
38
39
#ifndef __JACKTRIP_H__
#define __JACKTRIP_H__
jcaceres's avatar
jcaceres committed
40

jcaceres's avatar
jcaceres committed
41
42
#include <tr1/memory> //for shared_ptr

jcaceres's avatar
jcaceres committed
43
44
#include <QString>

jcaceres's avatar
jcaceres committed
45
46
#include "DataProtocol.h"
#include "JackAudioInterface.h"
jcacerec's avatar
jcacerec committed
47
#include "PacketHeader.h"
jcaceres's avatar
jcaceres committed
48
49
50
51
52
53
54
55
56
57
58
59
60

/** \brief Default values
 */
/*
const dataProtocolT DefaultDataProtocolType = UDP;
const int DefaultNumChans = 2;
const int DefaultSampleRate = 48000;
const int DefaultAudioBufferSize = 128;
const int DefaultAudioBitResolution = 16;
*/

/** \brief
 *
jcacerec's avatar
jcacerec committed
61
 * \todo FINISH THIS: This class also acts as a Mediator between all the other class
jcaceres's avatar
jcaceres committed
62
 */
jcaceres's avatar
jcaceres committed
63
class JackTrip
jcaceres's avatar
jcaceres committed
64
65
66
{
public:

jcaceres's avatar
more    
jcaceres committed
67
  //----------ENUMS------------------------------------------
jcaceres's avatar
jcaceres committed
68
69
70
71
72
73
74
  /// \brief Enum for the data Protocol. At this time only UDP is implemented
  enum dataProtocolT {
    UDP, ///< Use UDP (User Datagram Protocol) 
    TCP, ///< <B>NOT IMPLEMENTED</B>: Use TCP (Transmission Control Protocol)
    SCTP ///< <B>NOT IMPLEMENTED</B>: Use SCTP (Stream Control Transmission Protocol)
  };

jcaceres's avatar
more    
jcaceres committed
75
76
77
78
79
80
81
  /// \brief Enum for the JackTrip mode
  enum jacktripModeT {
    SERVER, ///< Run in Server Mode
    CLIENT  ///< Run in Client Mode
  };
  //---------------------------------------------------------

jcaceres's avatar
more    
jcaceres committed
82

jcaceres's avatar
jcaceres committed
83
  /** \brief The class Constructor with Default Parameters
jcaceres's avatar
jcaceres committed
84
85
86
87
   * \param JacktripMode JackTrip::CLIENT or JackTrip::SERVER
   * \param DataProtocolType JackTrip::dataProtocolT
   * \param NumChans Number of Audio Channels (same for inputs and outputs)
   * \param BufferQueueLength Audio Buffer for receiving packets
jcaceres's avatar
jcaceres committed
88
   * \param AudioBitResolution Audio Sample Resolutions in bits
jcaceres's avatar
jcaceres committed
89
   */
jcaceres's avatar
jcaceres committed
90
  JackTrip(jacktripModeT JacktripMode = CLIENT,
jcaceres's avatar
jcaceres committed
91
92
93
	   dataProtocolT DataProtocolType = UDP,
	   int NumChans = 2,
	   int BufferQueueLength = 8,
jcaceres's avatar
more    
jcaceres committed
94
	   JackAudioInterface::audioBitResolutionT AudioBitResolution = 
jcaceres's avatar
jcaceres committed
95
	   JackAudioInterface::BIT16);
jcaceres's avatar
jcaceres committed
96
97
  
  /// \brief The class destructor
jcaceres's avatar
jcaceres committed
98
  virtual ~JackTrip();
jcaceres's avatar
jcaceres committed
99

jcaceres's avatar
jcaceres committed
100
101
  /// \brief Set the Peer Address for jacktripModeT::CLIENT mode only
  void setPeerAddress(char* PeerHostOrIP);
jcaceres's avatar
jcaceres committed
102

jcaceres's avatar
jcaceres committed
103
104
105
  /** \brief Append a process plugin. Processes will be appended in order
   * \param plugin Pointer to ProcessPlugin Class
   */
106
107
  void appendProcessPlugin(const std::tr1::shared_ptr<ProcessPlugin> plugin);

jcaceres's avatar
jcaceres committed
108
109
  /// \brief Start the processes
  void start();
jcaceres's avatar
jcaceres committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

  //------------------------------------------------------------------------------------
  /// \name Methods to change parameters after construction
  //@{
  // 
  /// \brief Sets (override) JackTrip Mode after construction
  void setJackTripMode(jacktripModeT JacktripMode)
  { mJackTripMode = JacktripMode; };
  /// \brief Sets (override) DataProtocol Type after construction
  void setDataProtocoType(dataProtocolT DataProtocolType)
  {mDataProtocol = DataProtocolType; };
  /// \brief Sets (override) Number of Channels after construction
  void setNumChannels(int NumChans)
  { mNumChans=NumChans; };
/// \brief Sets (override) Buffer Queue Length Mode after construction
  void setBufferQueueLength(int BufferQueueLength)
  { mBufferQueueLength = BufferQueueLength; };
  /// \brief Sets (override) Audio Bit Resolution after construction
  void setAudioBitResolution(JackAudioInterface::audioBitResolutionT AudioBitResolution)
  { mAudioBitResolution = AudioBitResolution; }
  //@}
  //------------------------------------------------------------------------------------

jcaceres's avatar
jcaceres committed
133
134

private:
jcaceres's avatar
jcaceres committed
135
136
137
138
139
140
141

  /// \brief Set the JackAudioInteface object
  void setupJackAudio();
  /// \brief Set the DataProtocol objects
  void setupDataProtocol();
  /// \brief Set the RingBuffer objects
  void setupRingBuffers();
142
  /// \brief Start for the CLIENT mode
jcaceres's avatar
jcaceres committed
143
  void clientStart();
144
  /// \brief Start for the SERVER mode
jcaceres's avatar
jcaceres committed
145
146
  void serverStart();

jcacerec's avatar
jcacerec committed
147
148
149
150
151

  void createHeader(const DataProtocol::packetHeaderTypeT headertype);
  void putHeaderInPacket(int8_t* full_packet);


jcaceres's avatar
jcaceres committed
152
153
154
  jacktripModeT mJackTripMode; ///< JackTrip::jacktripModeT
  dataProtocolT mDataProtocol; ///< Data Protocol
  int mNumChans; ///< Number of Channels (inputs = outputs)
jcaceres's avatar
jcaceres committed
155
  int mBufferQueueLength; ///< Audio Buffer from network queue length
jcaceres's avatar
more    
jcaceres committed
156
157
  uint32_t mSampleRate; ///< Sample Rate
  uint32_t mAudioBufferSize; ///< Audio buffer size to process on each callback
jcaceres's avatar
jcaceres committed
158
159
  JackAudioInterface::audioBitResolutionT mAudioBitResolution;
  QString mPeerAddress; ///< Peer Address to use in jacktripModeT::CLIENT Mode
jcaceres's avatar
more    
jcaceres committed
160

jcaceres's avatar
jcaceres committed
161
162
163
164
165
  /// Pointer to Abstract Type DataProtocol that sends packets
  DataProtocol* mDataProtocolSender;
  ///< Pointer to Abstract Type DataProtocol that receives packets
  DataProtocol* mDataProtocolReceiver;
  JackAudioInterface* mJackAudio; ///< Interface to Jack Client
jcacerec's avatar
jcacerec committed
166
  PacketHeader* mPacketHeader;
jcaceres's avatar
jcaceres committed
167
168

  /// Shared (smart) Pointer for the Send RingBuffer
jcaceres's avatar
jcaceres committed
169
  std::tr1::shared_ptr<RingBuffer> mSendRingBuffer; 
jcaceres's avatar
jcaceres committed
170
  /// Shared (smart) Pointer for the Receive RingBuffer
jcaceres's avatar
jcaceres committed
171
  std::tr1::shared_ptr<RingBuffer> mReceiveRingBuffer; 
jcacerec's avatar
jcacerec committed
172
173

  //JackTripMediator mJackTripMediator;
jcaceres's avatar
jcaceres committed
174
175
176
};

#endif