Babel
Epitech's C++ VoIP project
SoundHandler.hpp
Go to the documentation of this file.
1 //
2 // SoundHhandler class
3 // @brief Handle the sound inputs and outputs, as well as the udp connexion
4 //
5 
6 #ifndef SOUNDHANDLER_HPP_
7 #define SOUNDHANDLER_HPP_
8 
9 #include <memory>
10 #include <map>
11 #include <thread>
12 #include <condition_variable>
13 #include <QApplication>
14 #include "Audio/Opus/ICodec.hpp"
15 #include "Audio/IAudioManager.hpp"
18 #include "Network/RFCCodes.hpp"
19 #include "Network/UDPSocket.hpp"
20 #include "Network/AudioPacket.hpp"
21 
22 namespace Babel {
23  class SoundHandler {
24  public:
26  explicit SoundHandler(std::uint16_t port);
27 
29  ~SoundHandler();
30 
32  void startCall();
33 
35  void stopCall();
36 
38  void addClient(const std::string &userid, const std::string &ipAddres, std::uint16_t port);
39 
41  void removeClient(const std::string &userid);
42 
44  uint16_t getLocalPort() const;
45 
46  private:
48  std::shared_ptr<Babel::IAudioManager> _audio;
50  std::shared_ptr<Babel::ICodec> _codec;
52  std::shared_ptr<Babel::UDPSocket> _socket;
54  std::map<std::string, std::pair<std::string, std::uint16_t>> _userlist;
56  std::mutex _userlist_mtx;
58  std::condition_variable _blocker;
62  std::mutex _exit_mtx;
66  std::mutex _play_mtx;
68  std::thread _execthread;
70  std::mutex _condVarMutex;
71  };
72 }
73 
74 #endif
75 
Babel::SoundHandler::_exit_mtx
std::mutex _exit_mtx
mutex for should exit variable
Definition: SoundHandler.hpp:62
Babel::SoundHandler::_userlist_mtx
std::mutex _userlist_mtx
mutex to access the userlist
Definition: SoundHandler.hpp:56
Babel::SoundHandler::_userlist
std::map< std::string, std::pair< std::string, std::uint16_t > > _userlist
list of all users used in current call
Definition: SoundHandler.hpp:54
Babel::SoundHandler::startCall
void startCall()
notify the sound handler to start to send data and to receive it
Definition: SoundHandler.cpp:70
UDPSocket.hpp
Babel::SoundHandler::_socket
std::shared_ptr< Babel::UDPSocket > _socket
pointer to the udp socket for input and output on network
Definition: SoundHandler.hpp:52
RFCCodes.hpp
Babel::SoundHandler::removeClient
void removeClient(const std::string &userid)
remove a client to the current call
Definition: SoundHandler.cpp:89
Babel::SoundHandler::_execthread
std::thread _execthread
thread for broadcasting data from audio library to udp
Definition: SoundHandler.hpp:68
Babel::SoundHandler::_blocker
std::condition_variable _blocker
@condition variable for stopping or enabling thread
Definition: SoundHandler.hpp:58
Babel::SoundHandler::_play_mtx
std::mutex _play_mtx
mutex for should exit variable
Definition: SoundHandler.hpp:66
Babel::SoundHandler::~SoundHandler
~SoundHandler()
sound handler destructor
Definition: SoundHandler.cpp:59
PortAudioException.hpp
Babel
Definition: IAudioManager.hpp:13
Babel::SoundHandler::SoundHandler
SoundHandler(std::uint16_t port)
sound handler constructor
Definition: SoundHandler.cpp:15
Babel::SoundHandler::addClient
void addClient(const std::string &userid, const std::string &ipAddres, std::uint16_t port)
add a client to the current call
Definition: SoundHandler.cpp:84
Babel::SoundHandler::_shouldExit
bool _shouldExit
boolean to tell when the thread should exit;
Definition: SoundHandler.hpp:60
ICodec.hpp
QtTCPConnection.hpp
Babel::SoundHandler::_shouldPlay
bool _shouldPlay
boolean to tell when the thread should record;
Definition: SoundHandler.hpp:64
Babel::SoundHandler::_codec
std::shared_ptr< Babel::ICodec > _codec
pointer to the codec
Definition: SoundHandler.hpp:50
Babel::SoundHandler
Definition: SoundHandler.hpp:23
Babel::SoundHandler::getLocalPort
uint16_t getLocalPort() const
get the port that the soundHandler is listening
Definition: SoundHandler.cpp:94
Babel::SoundHandler::stopCall
void stopCall()
notify the sound handler to stop
Definition: SoundHandler.cpp:76
Babel::SoundHandler::_audio
std::shared_ptr< Babel::IAudioManager > _audio
pointer to audio input and outputs
Definition: SoundHandler.hpp:48
Babel::SoundHandler::_condVarMutex
std::mutex _condVarMutex
mutex used for the condition variable
Definition: SoundHandler.hpp:70
AudioPacket.hpp
IAudioManager.hpp