MythTV  master
audiooutputjack.h
Go to the documentation of this file.
1 #ifndef AUDIOOUTPUTJACK
2 #define AUDIOOUTPUTJACK
3 
4 // Qt headers
5 #include <QCoreApplication>
6 
7 #include <jack/jack.h>
8 #include <jack/statistics.h>
9 #include "audiooutputbase.h"
10 #include "audiooutputsettings.h"
11 
13 #define JACK_CHANNELS_MIN 2
14 #define JACK_CHANNELS_MAX 8
15 
17 {
19 
20  public:
21  explicit AudioOutputJACK(const AudioSettings &settings);
22  ~AudioOutputJACK() override;
23 
24  // Volume control
25  int GetVolumeChannel(int channel) const override; // VolumeBase
26  void SetVolumeChannel(int channel, int volume) override; // VolumeBase
27 
28  protected:
29 
30  // You need to implement the following functions
31  bool OpenDevice(void) override; // AudioOutputBase
32  void CloseDevice(void) override; // AudioOutputBase
33  void WriteAudio(unsigned char *aubuf, int size) override; // AudioOutputBase
34  int GetBufferedOnSoundcard(void) const override; // AudioOutputBase
35  AudioOutputSettings* GetOutputSettings(bool digital) override; // AudioOutputBase
36 
37  // Overriding these to do nothing. Not needed here.
38  bool StartOutputThread(void) override; // AudioOutputBase
39  void StopOutputThread(void) override; // AudioOutputBase
40 
41  private:
42 
43  void VolumeInit(void);
44 
45  // Our various callback functions
46  inline int JackCallback(jack_nframes_t nframes);
47  static int JackCallbackHelper(jack_nframes_t nframes, void *arg);
48  inline int JackXRunCallback();
49  static int JackXRunCallbackHelper(void *arg);
50  inline int JackGraphOrderCallback();
51  static int JackGraphOrderCallbackHelper(void *arg);
52 
53  static jack_client_t* JackClientOpen(void);
54  const char** JackGetPorts(void);
55  bool JackConnectPorts(const char** /*matching_ports*/);
56  inline void JackClientClose(jack_client_t **client);
57 
58  void DeinterleaveAudio(const float *aubuf, float **bufs,
59  int nframes, const int* channel_volumes);
60 
61  jack_port_t *m_ports[JACK_CHANNELS_MAX] {};
63  jack_client_t *m_client {nullptr};
64  jack_client_t *m_staleClient {nullptr};
65  int m_jackLatency {0};
66  int m_jackXruns {0};
67  unsigned char *m_auBuf {nullptr};
68 
69 
70 };
71 
72 #endif
73 
jack_client_t * m_client
#define JACK_CHANNELS_MAX
void CloseDevice(void) override
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
void DeinterleaveAudio(const float *aubuf, float **bufs, int nframes, const int *channel_volumes)
static int JackCallbackHelper(jack_nframes_t nframes, void *arg)
AudioOutputJACK(const AudioSettings &settings)
void WriteAudio(unsigned char *aubuf, int size) override
static int JackGraphOrderCallbackHelper(void *arg)
int GetVolumeChannel(int channel) const override
static int JackXRunCallbackHelper(void *arg)
void SetVolumeChannel(int channel, int volume) override
bool OpenDevice(void) override
~AudioOutputJACK() override
int JackCallback(jack_nframes_t nframes)
jack_port_t * m_ports[JACK_CHANNELS_MAX]
unsigned char * m_auBuf
void JackClientClose(jack_client_t **client)
static jack_client_t * JackClientOpen(void)
int m_chanVolumes[JACK_CHANNELS_MAX]
bool StartOutputThread(void) override
AudioOutputSettings * GetOutputSettings(bool digital) override
jack_client_t * m_staleClient
const char ** JackGetPorts(void)
Q_DECLARE_TR_FUNCTIONS(AudioOutputJACK)
bool JackConnectPorts(const char **)
void StopOutputThread(void) override