Create routines for destroying RTP readers/writers

The RTP connection should be destroyed by calling context->destroy_*
functions to ensure that the session is completely destroyed.

These functions will call the writer's/reader's destructor, close the
socket, release all common resources, remove them from the global
hashmap and send RTCP BYE message to all other participants
This commit is contained in:
Aaro Altonen 2019-05-23 09:14:34 +03:00
parent 6ea1f1fc7d
commit 50606cc6b4
3 changed files with 31 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#ifdef __linux__
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <cstring>
#include <iostream>
@ -20,6 +21,15 @@ kvz_rtp::connection::connection(bool reader):
kvz_rtp::connection::~connection()
{
/* this is going to cause problems if config was allocated from stack... */
if (config_)
delete config_;
#ifdef __linux__
close(socket_);
#else
/* TODO: close socket a la windows */
#endif
}
void kvz_rtp::connection::set_payload(rtp_format_t fmt)

View File

@ -91,3 +91,19 @@ kvz_rtp::writer *kvz_rtp::context::create_writer(std::string dstAddr, int dstPor
writer->set_payload(fmt);
return writer;
}
rtp_error_t kvz_rtp::context::destroy_writer(kvz_rtp::writer *writer)
{
conns_.erase(writer->get_ssrc());
/* TODO: rtcp bye */
delete writer;
}
rtp_error_t kvz_rtp::context::destroy_reader(kvz_rtp::reader *reader)
{
conns_.erase(reader->get_ssrc());
/* TODO: rtcp bye */
delete reader;
}

View File

@ -27,6 +27,11 @@ namespace kvz_rtp {
kvz_rtp::writer *create_writer(std::string dst_addr, int dst_port, int src_port);
kvz_rtp::writer *create_writer(std::string dst_addr, int dst_port, int src_port, rtp_format_t fmt);
/* call reader/writer-specific destroy functions, send an RTCP BYE message
* and remove the connection from conns_ map */
rtp_error_t destroy_writer(kvz_rtp::writer *writer);
rtp_error_t destroy_reader(kvz_rtp::reader *reader);
private:
std::map<uint32_t, connection *> conns_;
};