multiplex: Add rtcp_reader class

This commit is contained in:
Heikki Tampio 2023-05-04 08:28:40 +03:00
parent 415546facf
commit 2493e5fdd5
3 changed files with 119 additions and 0 deletions

View File

@ -95,6 +95,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/srtp/srtcp.cc
src/wrapper_c.cc
src/socketfactory.cc
src/rtcp_reader.cc
)
source_group(src/srtp src/srtp/.*)
@ -146,6 +147,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/srtp/srtp.hh
src/srtp/srtcp.hh
src/socketfactory.hh
src/rtcp_reader.hh
include/uvgrtp/util.hh
include/uvgrtp/clock.hh

78
src/rtcp_reader.cc Normal file
View File

@ -0,0 +1,78 @@
#include "rtcp_reader.hh"
#include "uvgrtp/util.hh"
#include "uvgrtp/frame.hh"
#include "rtcp_packets.hh"
#include "poll.hh"
#include "uvgrtp/rtcp.hh"
#include "socket.hh"
#include "global.hh"
#include "debug.hh"
#ifndef _WIN32
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#else
#include <ws2ipdef.h>
#endif
const int MAX_PACKET = 65536;
uvgrtp::rtcp_reader::rtcp_reader(std::shared_ptr<uvgrtp::socketfactory> sfp) :
active_(false),
sfp_(sfp),
socket_(nullptr),
rtcps_map_({})
{
}
uvgrtp::rtcp_reader::~rtcp_reader()
{
}
void uvgrtp::rtcp_reader::rtcp_report_reader() {
UVG_LOG_INFO("RTCP report reader created!");
std::unique_ptr<uint8_t[]> buffer = std::unique_ptr<uint8_t[]>(new uint8_t[MAX_PACKET]);
rtp_error_t ret = RTP_OK;
int max_poll_timeout_ms = 100;
while (active_) {
int nread = 0;
std::vector<std::shared_ptr<uvgrtp::socket>> temp = {};
temp.push_back(socket_);
ret = uvgrtp::poll::poll(temp, buffer.get(), MAX_PACKET, max_poll_timeout_ms, &nread);
if (ret == RTP_OK && nread > 0)
{
uint32_t sender_ssrc = ntohl(*(uint32_t*)&buffer.get()[0 + RTCP_HEADER_SIZE]);
for (auto& p : rtcps_map_) {
if (sender_ssrc == p.first) {
std::shared_ptr<uvgrtp::rtcp> rtcp_ptr = p.second;
(void)rtcp_ptr->handle_incoming_packet(buffer.get(), (size_t)nread);
}
}
}
else if (ret == RTP_INTERRUPTED) {
/* do nothing */
}
else {
UVG_LOG_ERROR("poll failed, %d", ret);
break; // TODO the sockets should be manages so that this is not needed
}
}
UVG_LOG_DEBUG("Exited RTCP report reader loop");
}
bool uvgrtp::rtcp_reader::set_socket(std::shared_ptr<uvgrtp::socket> socket)
{
socket_ = socket;
return true;
}

39
src/rtcp_reader.hh Normal file
View File

@ -0,0 +1,39 @@
#pragma once
#include "uvgrtp/clock.hh"
#include "uvgrtp/util.hh"
#include "uvgrtp/frame.hh"
#ifdef _WIN32
#include <ws2ipdef.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include <vector>
#include <memory>
#include <map>
namespace uvgrtp {
class socketfactory;
class rtcp;
class socket;
class rtcp_reader {
public:
rtcp_reader(std::shared_ptr<uvgrtp::socketfactory> sfp);
~rtcp_reader();
void rtcp_report_reader();
bool set_socket(std::shared_ptr<uvgrtp::socket> socket);
private:
bool active_;
std::shared_ptr<uvgrtp::socketfactory> sfp_;
std::shared_ptr<uvgrtp::socket> socket_;
std::map<uint32_t, std::shared_ptr<uvgrtp::rtcp>> rtcps_map_;
};
}