hydrogen 1.2.3
PulseAudioDriver.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22#ifndef H2_PULSE_AUDIO_DRIVER_H
23#define H2_PULSE_AUDIO_DRIVER_H
24
25
26#include <core/IO/AudioOutput.h>
27
28#if defined(H2CORE_HAVE_PULSEAUDIO) || _DOXYGEN_
29
30#include <pthread.h>
31#include <inttypes.h>
32#include <pulse/pulseaudio.h>
33
34namespace H2Core
35{
36
37
41
42class PulseAudioDriver : public Object<PulseAudioDriver>, public AudioOutput
43{
45public:
48
49 virtual int init( unsigned nBufferSize ) override;
50 virtual int connect() override;
51 virtual void disconnect() override;
52 virtual unsigned getBufferSize() override;
53 virtual unsigned getSampleRate() override;
54 virtual float* getOut_L() override;
55 virtual float* getOut_R() override;
56
57private:
58 pthread_t m_thread;
59 pthread_mutex_t m_mutex;
60 pthread_cond_t m_cond;
63 int m_pipe[2];
65 pa_mainloop* m_main_loop;
66 pa_context* m_ctx;
67 pa_stream* m_stream;
70 unsigned m_sample_rate;
71 unsigned m_buffer_size;
72 float* m_outL;
73 float* m_outR;
74
75 static void* s_thread_body(void*);
76 int thread_body();
77
78 static void ctx_state_callback(pa_context* ctx, void* udata);
79 static void stream_state_callback(pa_stream* stream, void* udata);
80 static void stream_write_callback(pa_stream* stream, size_t bytes, void* udata);
81 static void pipe_callback(pa_mainloop_api*, pa_io_event*, int fd,
82 pa_io_event_flags_t events, void *udata);
83};
84
85} //namespace H2Core
86
87#else
88
89#include <core/IO/NullDriver.h>
90
91namespace H2Core {
93 class PulseAudioDriver : public NullDriver
94 {
96 public:
97 PulseAudioDriver( audioProcessCallback processCallback ) : NullDriver( processCallback ) {}
98
99 };
100}
101
102#endif //H2CORE_HAVE_PULSEAUDIO
103
104
105#endif //H2_PULSE_AUDIO_DRIVER_H
106
107
#define H2_OBJECT(name)
Definition Object.h:224
Base abstract class for audio output classes.
Definition AudioOutput.h:39
virtual void disconnect() override
virtual float * getOut_L() override
virtual int init(unsigned nBufferSize) override
static void ctx_state_callback(pa_context *ctx, void *udata)
static void stream_write_callback(pa_stream *stream, size_t bytes, void *udata)
static void pipe_callback(pa_mainloop_api *, pa_io_event *, int fd, pa_io_event_flags_t events, void *udata)
audioProcessCallback m_callback
static void stream_state_callback(pa_stream *stream, void *udata)
static void * s_thread_body(void *)
virtual float * getOut_R() override
virtual unsigned getBufferSize() override
virtual int connect() override
PulseAudioDriver(audioProcessCallback processCallback)
int m_pipe[2]
File descriptors used to write data to (m_pipe[1]) and read data from (m_pipe[0]) the pipe.
virtual unsigned getSampleRate() override
int(* audioProcessCallback)(uint32_t, void *)
Definition AudioOutput.h:32