Babel
Epitech's C++ VoIP project
UDPSocket.hpp
Go to the documentation of this file.
1 //
2 // Created by mgl on 10/11/21.
3 //
4 
5 #ifndef BABEL_UDPSOCKET_HPP
6 #define BABEL_UDPSOCKET_HPP
7 
8 #include <QUdpSocket>
9 #include <map>
10 #include <mutex>
11 #include "Audio/Opus/ICodec.hpp"
12 #include "Audio/IAudioManager.hpp"
13 
14 namespace Babel {
16  class UDPSocket : public QObject {
17  Q_OBJECT
18  public:
20  UDPSocket(std::int16_t port, std::shared_ptr<Babel::IAudioManager> &, std::shared_ptr<Babel::ICodec> &);
21 
23  ~UDPSocket() override;
24 
26  std::int64_t
27  write(std::array<unsigned char, 4000> &data, std::int32_t size, const std::string &address, int port);
28 
30  void close();
31 
33  void readPending();
34 
36  uint16_t getLocalPort() const;
37 
38  private:
40  std::mutex _mutex;
42  std::unique_ptr<QUdpSocket> _socket;
44  std::shared_ptr<Babel::IAudioManager> _audio;
46  std::shared_ptr<Babel::ICodec> _codec;
47  };
48 }
49 
50 
51 #endif //BABEL_UDPSOCKET_HPP
Babel::UDPSocket::_audio
std::shared_ptr< Babel::IAudioManager > _audio
audio interface to play sound
Definition: UDPSocket.hpp:44
Babel::UDPSocket::_socket
std::unique_ptr< QUdpSocket > _socket
Qt's UDP socket.
Definition: UDPSocket.hpp:42
Babel::UDPSocket::close
void close()
closes the socket
Definition: UDPSocket.cpp:60
Babel::UDPSocket
wrapper around Qt UDP socket, ICodec and Portaudio
Definition: UDPSocket.hpp:16
Babel
Definition: IAudioManager.hpp:13
Babel::UDPSocket::_mutex
std::mutex _mutex
mutex for closing the socket
Definition: UDPSocket.hpp:40
ICodec.hpp
Babel::UDPSocket::write
std::int64_t write(std::array< unsigned char, 4000 > &data, std::int32_t size, const std::string &address, int port)
writes data to socket
Definition: UDPSocket.cpp:27
Babel::UDPSocket::UDPSocket
UDPSocket(std::int16_t port, std::shared_ptr< Babel::IAudioManager > &, std::shared_ptr< Babel::ICodec > &)
ctor
Definition: UDPSocket.cpp:15
Babel::UDPSocket::_codec
std::shared_ptr< Babel::ICodec > _codec
codec interface to encode and decode sound
Definition: UDPSocket.hpp:46
Babel::UDPSocket::readPending
void readPending()
reads the incoming datagrams when they arrive
Definition: UDPSocket.cpp:37
Babel::UDPSocket::~UDPSocket
~UDPSocket() override
dtor
Definition: UDPSocket.cpp:56
Babel::UDPSocket::getLocalPort
uint16_t getLocalPort() const
get the port that the UDPSocket is listening
Definition: UDPSocket.cpp:65
IAudioManager.hpp