Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
Manager.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** record_compress_decompress_play
4** File description:
5** Compressor.hpp
6*/
7
13#pragma once
14
15#include <vector>
16#include <iostream>
17#include <stdexcept>
18#include <mutex>
19#include <array>
20
21#include <opus.h>
22
23#include "Logging.hpp"
24#include "Audio/Sample.hpp"
25#include "Compressor/Packet.hpp"
26
27namespace Compressor
28{
32 class Manager {
33 public:
37 Manager();
38
43 Manager(const Audio::Sample &sample);
44
48 ~Manager();
49
53 void compress();
54
60 void encode(std::vector<float> &sound, std::vector<unsigned char> &output);
61
67 void decode(std::vector<unsigned char> &sound, std::vector<float> &output);
68
72 void decompress();
73
78 void setMaxPacketSize(const unsigned int maxPacketSize);
79
84 const unsigned int getMaxPacketSize() const;
85
91
97
102 void setUncompressedStream(const Audio::Sample &data);
103
109
110 private:
116 void handleOpusError(int errorCode, const std::string &context) const;
117
118 int _error;
119 bool _rawStreamSet = false;
120 bool _hasBeenCompressed = false;
121 unsigned int _maxPacketSize = 4000;
122 OpusEncoder *_encoder = nullptr;
123 OpusDecoder *_decoder = nullptr;
124 Audio::Sample _uncompressedStream;
125 Compressor::Packet _compressedStream;
126 mutable std::mutex _mutex;
127 };
128}
Aggregates logging-related headers.
This file contains the definition of the Packet structure used for storing compressed audio data.
Defines the structure representing an audio sample.
Class responsible for managing audio compression and decompression.
Definition Manager.hpp:32
void decompress()
Decompress the compressed audio stream.
Definition Manager.cpp:181
const Audio::Sample & getUncompressedStream() const
Get the uncompressed audio stream.
Definition Manager.cpp:245
void decode(std::vector< unsigned char > &sound, std::vector< float > &output)
Decode compressed audio data into raw format.
Definition Manager.cpp:348
~Manager()
Destructor.
Definition Manager.cpp:84
void compress()
Compress the uncompressed audio stream.
Definition Manager.cpp:127
void setUncompressedStream(const Audio::Sample &data)
Set the uncompressed audio stream.
Definition Manager.cpp:262
void setMaxPacketSize(const unsigned int maxPacketSize)
Set the maximum packet size for compression.
Definition Manager.cpp:106
void encode(std::vector< float > &sound, std::vector< unsigned char > &output)
Encode raw audio data into compressed format.
Definition Manager.cpp:286
void setCompressedStream(const Compressor::Packet &data)
Set the compressed audio stream.
Definition Manager.cpp:231
const unsigned int getMaxPacketSize() const
Get the maximum packet size for compression.
Definition Manager.cpp:118
const Compressor::Packet & getCompressedStream() const
Get the compressed audio stream.
Definition Manager.cpp:214
Manager()
Default constructor.
Definition Manager.cpp:15
Structure representing an audio sample.
Definition Sample.hpp:22
Structure representing a packet of compressed audio data.
Definition Packet.hpp:22