~fboucault/telepathy-ofono/crossbuild_fixes

38.1.1 by David Henningsson
Add PulseAudio backend
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
5
**
6
** This file was taken from qt5 and modified by 
7
** David Henningsson <david.henningsson@canonical.com> for usage in 
8
** telepathy-ofono.
9
**
10
** GNU Lesser General Public License Usage
11
** Alternatively, this file may be used under the terms of the GNU Lesser
12
** General Public License version 2.1 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.LGPL included in the
14
** packaging of this file.  Please review the following information to
15
** ensure the GNU Lesser General Public License version 2.1 requirements
16
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
****************************************************************************/
19
20
#ifndef QPULSEAUDIOENGINE_H
21
#define QPULSEAUDIOENGINE_H
22
23
#include <QtCore/qmap.h>
24
#include <QtCore/qbytearray.h>
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
25
#include <QThread>
38.1.1 by David Henningsson
Add PulseAudio backend
26
#include <pulse/pulseaudio.h>
27
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
28
enum AudioMode {
29
    AudioModeEarpiece = 0x0001,
30
    AudioModeWiredHeadset = 0x0002,
31
    AudioModeSpeaker = 0x0004,
32
    AudioModeBluetooth = 0x0008,
33
    AudioModeBtOrWiredOrEarpiece = AudioModeBluetooth | AudioModeWiredHeadset | AudioModeEarpiece,
34
    AudioModeWiredOrEarpiece = AudioModeWiredHeadset | AudioModeEarpiece,
35
    AudioModeWiredOrSpeaker = AudioModeWiredHeadset | AudioModeSpeaker
36
};
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
37
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
38
Q_DECLARE_METATYPE(AudioMode)
39
40
typedef QList<AudioMode> AudioModes;
41
Q_DECLARE_METATYPE(AudioModes)
42
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
43
enum CallStatus {
44
    CallRinging,
45
    CallActive,
46
    CallEnded
47
};
48
49
Q_DECLARE_METATYPE(CallStatus)
50
38.1.1 by David Henningsson
Add PulseAudio backend
51
QT_BEGIN_NAMESPACE
52
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
53
class QPulseAudioEngineWorker : public QObject
38.1.1 by David Henningsson
Add PulseAudio backend
54
{
55
    Q_OBJECT
56
57
public:
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
58
    QPulseAudioEngineWorker(QObject *parent = 0);
59
    ~QPulseAudioEngineWorker();
60
38.1.1 by David Henningsson
Add PulseAudio backend
61
    pa_threaded_mainloop *mainloop() { return m_mainLoop; }
62
    pa_context *context() { return m_context; }
154.2.1 by Tiago Salem Herrmann
Check and create PA context before using it.
63
    bool createPulseContext(void);
101.1.7 by Ricardo Salveti de Araujo
qpulseaudioengine: better handling the pulseaudio connection
64
    int setupVoiceCall(void);
91.1.1 by Ricardo Salveti de Araujo
Adding support for handsfree/headset (bluetooth).
65
    void restoreVoiceCall(void);
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
66
    /* Callbacks to be used internally */
38.1.1 by David Henningsson
Add PulseAudio backend
67
    void cardInfoCallback(const pa_card_info *card);
68
    void sinkInfoCallback(const pa_sink_info *sink);
45.1.4 by David Henningsson
Add function for setting mic mute
69
    void sourceInfoCallback(const pa_source_info *source);
91.1.1 by Ricardo Salveti de Araujo
Adding support for handsfree/headset (bluetooth).
70
    void serverInfoCallback(const pa_server_info *server);
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
71
    void plugCardCallback(const pa_card_info *card);
72
    void updateCardCallback(const pa_card_info *card);
73
    void unplugCardCallback();
74
75
Q_SIGNALS:
76
    void audioModeChanged(const AudioMode mode);
77
    void availableAudioModesChanged(const AudioModes modes);
78
44.1.1 by David Henningsson
Ensure output is correct even after plug/unplug of headphones
79
public Q_SLOTS:
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
80
    void handleCardEvent(const int evt, const unsigned int idx);
149.1.2 by Tiago Salem Herrmann
Fix signaling between threads
81
    void setCallMode(CallStatus callstatus, AudioMode audiomode);
82
    void setMicMute(bool muted); /* True if muted, false if unmuted */
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
83
38.1.1 by David Henningsson
Add PulseAudio backend
84
private:
85
    pa_mainloop_api *m_mainLoopApi;
86
    pa_threaded_mainloop *m_mainLoop;
87
    pa_context *m_context;
88
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
89
    AudioModes m_availableAudioModes;
91.1.1 by Ricardo Salveti de Araujo
Adding support for handsfree/headset (bluetooth).
90
    CallStatus m_callstatus;
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
91
    AudioMode m_audiomode;
101.1.6 by Ricardo Salveti de Araujo
Only switch to wired in case of earpiece or speaker
92
    AudioMode m_audiomodetoset;
101.1.1 by Ricardo Salveti de Araujo
Improve event handling from pulse, also exporting mode changes.
93
    bool m_micmute, m_handleevent;
45.1.3 by David Henningsson
Refactor four variables into two
94
    std::string m_nametoset, m_valuetoset;
91.1.1 by Ricardo Salveti de Araujo
Adding support for handsfree/headset (bluetooth).
95
    std::string m_defaultsink, m_defaultsource;
96
    std::string m_bt_hsp, m_bt_hsp_a2dp;
97
    std::string m_voicecallcard, m_voicecallhighest, m_voicecallprofile;
45.1.2 by David Henningsson
Refactor waiting for pulseaudio into separate function
98
99
    bool handleOperation(pa_operation *operation, const char *func_name);
101.1.7 by Ricardo Salveti de Araujo
qpulseaudioengine: better handling the pulseaudio connection
100
    void releasePulseContext(void);
149.1.1 by Tiago Salem Herrmann
Move pulseaudio operations to a separate thread.
101
};
102
103
class QPulseAudioEngine : public QObject
104
{
105
    Q_OBJECT
106
public:
107
    explicit QPulseAudioEngine(QObject *parent = 0);
108
    ~QPulseAudioEngine();
109
    static QPulseAudioEngine *instance();
110
111
    void setCallMode(CallStatus callstatus, AudioMode audiomode);
112
    void setMicMute(bool muted); /* True if muted, false if unmuted */
113
114
Q_SIGNALS:
115
    void audioModeChanged(const AudioMode mode);
116
    void availableAudioModesChanged(const AudioModes modes);
117
private:
118
    QPulseAudioEngineWorker *mWorker;
119
    QThread mThread;
120
};
38.1.1 by David Henningsson
Add PulseAudio backend
121
122
QT_END_NAMESPACE
123
124
#endif