YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
AudioRecorderServerImpl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7#include <yarp/os/LogStream.h>
9
12using namespace yarp::os;
13using namespace yarp::dev;
14using namespace std;
15
16
17namespace {
18YARP_LOG_COMPONENT(AUDIOGRAB_RPC, "yarp.device.map2D_nws_yarp.IAudioGrabberRPCd")
19}
20
21#define CHECK_POINTER(xxx) {if (xxx==nullptr) {yCError(AUDIOGRAB_RPC, "Invalid interface"); return ReturnValue::return_code::return_value_error_not_ready;}}
22
24{
25 std::lock_guard <std::mutex> lg(m_mutex);
26
27 CHECK_POINTER(m_igrab)
28
29 auto ret = m_igrab->setHWGain(gain);
30 if (!ret)
31 {
32 yCError(AUDIOGRAB_RPC, "Unable to setHWGain");
33 return ret;
34 }
35 return ret;
36}
37
39{
40 std::lock_guard <std::mutex> lg(m_mutex);
41
42 CHECK_POINTER(m_igrab)
43
44 auto ret = m_igrab->setSWGain(gain);
45 if (!ret)
46 {
47 yCError(AUDIOGRAB_RPC, "Unable to setSWGain");
48 return ret;
49 }
50 return ret;
51}
52
54{
55 std::lock_guard <std::mutex> lg(m_mutex);
56
57 CHECK_POINTER(m_igrab)
58
59 auto ret = m_igrab->resetRecordingAudioBuffer();
60 if (!ret)
61 {
62 yCError(AUDIOGRAB_RPC, "Unable to resetRecordingAudioBuffer");
63 return ret;
64 }
65 return ret;
66}
67
69{
70 std::lock_guard <std::mutex> lg(m_mutex);
71
72 CHECK_POINTER(m_igrab)
73
74 auto ret = m_igrab->startRecording();
75 if (!ret)
76 {
77 yCError(AUDIOGRAB_RPC, "Unable to startRecording");
78 return ret;
79 }
80 return ret;
81}
82
84{
85 std::lock_guard <std::mutex> lg(m_mutex);
86
87 CHECK_POINTER(m_igrab)
88
89 auto ret = m_igrab->stopRecording();
90 if (!ret)
91 {
92 yCError(AUDIOGRAB_RPC, "Unable to stopRecording");
93 return ret;
94 }
95 return ret;
96}
97
99{
100 std::lock_guard <std::mutex> lg(m_mutex);
101
103 if (m_igrab == nullptr)
104 {
105 yCError(AUDIOGRAB_RPC, "Invalid interface");
106 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
107 return ret;
108 }
109
110 bool recording_enabled=false;
111 auto rec_ret = m_igrab->isRecording(recording_enabled);
112 if (!rec_ret)
113 {
114 yCError(AUDIOGRAB_RPC, "Unable to evaluate isRecording");
115 ret.ret = rec_ret;
116 return ret;
117 }
118
119 ret.ret = ReturnValue_ok;
120 ret.isRecording= recording_enabled;
121 return ret;
122}
123
124return_getSound IAudioGrabberRPCd::getSound_RPC(const size_t min_number_of_samples, const size_t max_number_of_samples, const double max_samples_timeout_s)
125{
126 std::lock_guard <std::mutex> lg(m_mutex);
127
129 if (m_igrab == nullptr)
130 {
131 yCError(AUDIOGRAB_RPC, "Invalid interface");
132 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
133 return ret;
134 }
135
136 ret.ret = m_igrab->getSound(ret.sound, min_number_of_samples, max_number_of_samples, max_samples_timeout_s);
137 if (!ret.ret)
138 {
139 yCError(AUDIOGRAB_RPC, "Unable to evaluate isRecording");
140 return ret;
141 }
142
143 ret.ret = ReturnValue_ok;
144 return ret;
145}
146
148{
149 std::lock_guard <std::mutex> lg(m_mutex);
150
152 if (m_igrab == nullptr)
153 {
154 yCError(AUDIOGRAB_RPC, "Invalid interface");
155 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
156 return ret;
157 }
158
160 if (!r2)
161 {
162 yCError(AUDIOGRAB_RPC, "Unable to evaluate isRecording");
163 ret.ret = r2;
164 return ret;
165 }
166
167 ret.ret = ReturnValue_ok;
168 return ret;
169}
170
172{
173 std::lock_guard <std::mutex> lg(m_mutex);
174
176 if (m_igrab == nullptr)
177 {
178 yCError(AUDIOGRAB_RPC, "Invalid interface");
179 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
180 return ret;
181 }
182
184 if (!r2)
185 {
186 yCError(AUDIOGRAB_RPC, "Unable to evaluate isRecording");
187 ret.ret = r2;
188 return ret;
189 }
190
191 ret.ret = ReturnValue_ok;
192 return ret;
193}
#define CHECK_POINTER(xxx)
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
virtual return_isRecording isRecording_RPC() override
virtual return_getSound getSound_RPC(const size_t min_number_of_samples, const size_t max_number_of_samples, const double max_samples_timeout_s) override
virtual yarp::dev::ReturnValue resetRecordingAudioBuffer_RPC() override
virtual yarp::dev::ReturnValue stopRecording_RPC() override
virtual yarp::dev::ReturnValue setSWGain_RPC(const double gain) override
virtual return_getRecordingAudioBufferMaxSize getRecordingAudioBufferMaxSize_RPC() override
virtual yarp::dev::ReturnValue setHWGain_RPC(const double gain) override
virtual yarp::dev::ReturnValue startRecording_RPC() override
virtual return_getRecordingAudioBufferCurrentSize getRecordingAudioBufferCurrentSize_RPC() override
virtual yarp::dev::ReturnValue getRecordingAudioBufferCurrentSize(yarp::sig::AudioBufferSize &size)=0
virtual yarp::dev::ReturnValue getSound(yarp::sig::Sound &sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s)=0
Get a sound from a device.
virtual yarp::dev::ReturnValue stopRecording()=0
Stop the recording.
virtual yarp::dev::ReturnValue resetRecordingAudioBuffer()=0
virtual yarp::dev::ReturnValue isRecording(bool &recording_enabled)=0
Check if the recording has been enabled (e.g.
virtual yarp::dev::ReturnValue setHWGain(double gain)=0
Sets the hardware gain of the grabbing device (if supported by the hardware)
virtual yarp::dev::ReturnValue startRecording()=0
Start the recording.
virtual yarp::dev::ReturnValue setSWGain(double gain)=0
Sets a software gain for the grabbed audio.
virtual yarp::dev::ReturnValue getRecordingAudioBufferMaxSize(yarp::sig::AudioBufferSize &size)=0
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.