Ring Daemon 16.0.0
Loading...
Searching...
No Matches
tonecontrol.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include "audio/tonecontrol.h"
23#include "sound/tonelist.h"
24#include "client/ring_signal.h"
25#include "jami/callmanager_interface.h" // for CallSignal
26
27namespace jami {
28
29static constexpr unsigned DEFAULT_SAMPLE_RATE = 8000;
30
32 : prefs_(preferences)
33 , sampleRate_(DEFAULT_SAMPLE_RATE)
34{}
35
37
38void
40{
41 std::lock_guard lk(mutex_);
42 sampleRate_ = rate;
43 sampleFormat_ = sampleFormat;
44 if (!telephoneTone_)
45 telephoneTone_.reset(new TelephoneTone(prefs_.getZoneToneChoice(), rate, sampleFormat));
46 else
47 telephoneTone_->setSampleRate(rate, sampleFormat);
48 if (!audioFile_) {
49 return;
50 }
51 auto path = audioFile_->getFilePath();
52 try {
53 audioFile_.reset(new AudioFile(path, sampleRate_, sampleFormat));
54 } catch (const AudioFileException& e) {
55 JAMI_WARN("Audio file error: %s", e.what());
56 }
57}
58
59std::shared_ptr<AudioLoop>
61{
62 std::lock_guard lk(mutex_);
63 if (telephoneTone_)
64 return telephoneTone_->getCurrentTone();
65 return nullptr;
66}
67
68std::shared_ptr<AudioLoop>
70{
71 std::lock_guard lk(mutex_);
72 return audioFile_;
73}
74
75bool
77{
78 std::lock_guard lk(mutex_);
79
80 if (audioFile_) {
82 audioFile_.reset();
83 }
84
85 try {
86 audioFile_.reset(new AudioFile(file, sampleRate_, sampleFormat_));
87 } catch (const AudioFileException& e) {
88 JAMI_WARN("Audio file error: %s", e.what());
89 }
90
91 return static_cast<bool>(audioFile_);
92}
93
94void
96{
97 std::lock_guard lk(mutex_);
98
99 if (audioFile_) {
101 audioFile_.reset();
102 }
103}
104
105void
107{
108 std::lock_guard lk(mutex_);
109
110 if (telephoneTone_)
111 telephoneTone_->setCurrentTone(Tone::ToneId::TONE_NULL);
112
113 if (audioFile_) {
115 audioFile_.reset();
116 }
117}
118
119void
121{
122 std::lock_guard lk(mutex_);
123
124 if (telephoneTone_)
125 telephoneTone_->setCurrentTone(toneId);
126}
127
128void
130{
131 std::lock_guard lk(mutex_);
132
133 if (audioFile_)
134 audioFile_->seek(value);
135}
136
137} // namespace jami
Abstract interface for file readers.
Definition audiofile.h:40
std::string getZoneToneChoice() const
Definition preferences.h:74
std::shared_ptr< AudioLoop > getTelephoneTone()
void setSampleRate(unsigned rate, AVSampleFormat sampleFormat)
bool setAudioFile(const std::string &file)
void seek(double value)
void play(Tone::ToneId toneId)
std::shared_ptr< AudioLoop > getTelephoneFile(void)
ToneControl()=delete
ToneId
The different kind of tones.
Definition tone.h:43
#define JAMI_WARN(...)
Definition logger.h:217
void emitSignal(Args... args)
Definition ring_signal.h:64
static constexpr unsigned DEFAULT_SAMPLE_RATE