fixed audio not being received properly.
This commit is contained in:
parent
724cad320f
commit
3d38302e2f
4 changed files with 24 additions and 8 deletions
|
@ -120,7 +120,7 @@ void EventManager::loopSender() {
|
|||
try {
|
||||
task = this->taskRegistry.at(this->context.me.status);
|
||||
} catch (const std::out_of_range& exception) {
|
||||
std::cerr << "Unsupported status." << std::endl;
|
||||
std::cerr << "[Sender] Unsupported status." << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ void AudioEvent::handle(
|
|||
// get the audio data in the content
|
||||
packet::AudioPacketData audioData;
|
||||
std::memcpy(&audioData, content.data.data(), sizeof(packet::AudioPacketData));
|
||||
|
||||
// save it in the audio queue
|
||||
this->audioQueue.push(audioData);
|
||||
// notify that a new audio chunk is available
|
||||
|
@ -119,10 +120,11 @@ void AudioEvent::loopPlay() {
|
|||
switch (error) {
|
||||
// success
|
||||
case paNoError:
|
||||
// the output might be very slightly underflown,
|
||||
break;
|
||||
// the output might be very slightly underflowed,
|
||||
// causing a very small period where no noise will be played.
|
||||
case paOutputUnderflowed:
|
||||
break;
|
||||
std::cerr << "[Client] Underflowed!" << std::endl;
|
||||
|
||||
default:
|
||||
std::cerr << "[Client] Could not write to the audio stream: " << Pa_GetErrorText(error) << std::endl;
|
||||
|
|
|
@ -15,7 +15,7 @@ void InfoEvent::handle(
|
|||
) {
|
||||
// get the peer information
|
||||
Peer peer;
|
||||
std::memcpy(&peer, &content, sizeof(Peer));
|
||||
std::memcpy(&peer, content.data.data(), sizeof(Peer));
|
||||
|
||||
// check if the peer address is already in the map
|
||||
const auto iterator = context.remotePeers.find(peer.id);
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
#include <thread>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "../../events/types.hpp"
|
||||
#include "../../packets/audio/AudioPacketData.hpp"
|
||||
#include "../../packets/base/GenericPacket.hpp"
|
||||
#include "../../utils/audio.hpp"
|
||||
|
||||
|
||||
|
@ -56,9 +58,16 @@ void ServerTask::handle(Context& context) {
|
|||
// TODO(Faraphel): create a chrony server
|
||||
|
||||
// read the file
|
||||
packet::GenericPacket packet {};
|
||||
packet::GenericPacketContent packetContent {};
|
||||
packet::AudioPacketData audioPacket;
|
||||
std::size_t done;
|
||||
|
||||
// create a packet
|
||||
// TODO(Faraphel): should not be broadcast plaintext
|
||||
packet.channel = 0;
|
||||
packet.securityMode = static_cast<std::uint8_t>(packet::SecurityMode::PLAIN);
|
||||
|
||||
if (mpg123_read(
|
||||
this->mpgHandle,
|
||||
&audioPacket.content,
|
||||
|
@ -76,19 +85,24 @@ void ServerTask::handle(Context& context) {
|
|||
std::chrono::high_resolution_clock::now() +
|
||||
std::chrono::milliseconds(5000);
|
||||
|
||||
// set the size of the content
|
||||
audioPacket.contentSize = done;
|
||||
|
||||
// set the audio settings
|
||||
audioPacket.channels = this->channels;
|
||||
audioPacket.sampleFormat = util::encoding_mpg123_to_PulseAudio(this->encoding);
|
||||
audioPacket.sampleRate = this->sampleRate;
|
||||
|
||||
// set the size of the content
|
||||
audioPacket.contentSize = done;
|
||||
// wrap the audio packet in the content
|
||||
packetContent.eventType = static_cast<std::uint8_t>(event::EventType::AUDIO);
|
||||
std::memcpy(packetContent.data.data(), &audioPacket, packetContent.data.size());
|
||||
packet.setContent(packetContent);
|
||||
|
||||
// broadcast the audio data
|
||||
if (sendto(
|
||||
context.socket,
|
||||
&audioPacket,
|
||||
sizeof(audioPacket),
|
||||
&packet,
|
||||
sizeof(packet),
|
||||
0,
|
||||
context.broadcastAddressInfo->ai_addr,
|
||||
context.broadcastAddressInfo->ai_addrlen
|
||||
|
|
Loading…
Reference in a new issue