build: Remove unused class dispatch

This class was used to speed up the sending end, but it did not actually
affect the sending  speed and has been disabled ever since.
This commit is contained in:
Joni Räsänen 2022-03-03 08:01:06 +02:00
parent 9ef02a72f8
commit 8aa2268597
5 changed files with 0 additions and 210 deletions

View File

@ -28,7 +28,6 @@ set(UVGRTP_LINKER_FLAGS "")
target_sources(${PROJECT_NAME} PRIVATE
src/clock.cc
src/crypto.cc
src/dispatch.cc
src/frame.cc
src/hostname.cc
src/context.cc
@ -75,7 +74,6 @@ source_group(include include/.*)
# Including header files so VisualStudio will list them correctly
target_sources(${PROJECT_NAME} PRIVATE
src/random.hh
src/dispatch.hh
src/holepuncher.hh
src/hostname.hh
src/mingw_inet.hh

View File

@ -1,113 +0,0 @@
#include "dispatch.hh"
#include "queue.hh"
#include "uvgrtp/socket.hh"
#include "uvgrtp/debug.hh"
#ifndef _WIN32
uvgrtp::dispatcher::dispatcher(uvgrtp::socket *socket):
socket_(socket)
{
}
uvgrtp::dispatcher::~dispatcher()
{
}
rtp_error_t uvgrtp::dispatcher::start()
{
runner_ = new std::thread(dispatch_runner, this, socket_);
runner_->detach();
return uvgrtp::runner::start();
}
rtp_error_t uvgrtp::dispatcher::stop()
{
if (tasks_.size() > 0)
return RTP_NOT_READY;
/* notify dispatcher that we must stop now, lock the dispatcher mutex
* and wait until it's unlocked by the dispatcher at which point it is safe
* to return and release all memory */
(void)uvgrtp::runner::stop();
d_mtx_.lock();
cv_.notify_one();
while (d_mtx_.try_lock());
return RTP_OK;
}
std::condition_variable& uvgrtp::dispatcher::get_cvar()
{
return cv_;
}
std::mutex& uvgrtp::dispatcher::get_mutex()
{
return d_mtx_;
}
rtp_error_t uvgrtp::dispatcher::trigger_send(uvgrtp::transaction_t *t)
{
std::lock_guard<std::mutex> lock(d_mtx_);
if (!t)
return RTP_INVALID_VALUE;
tasks_.push(t);
cv_.notify_one();
return RTP_OK;
}
uvgrtp::transaction_t *uvgrtp::dispatcher::get_transaction()
{
std::lock_guard<std::mutex> lock(d_mtx_);
if (tasks_.size() == 0)
return nullptr;
auto elem = tasks_.front();
tasks_.pop();
return elem;
}
void uvgrtp::dispatcher::dispatch_runner(uvgrtp::dispatcher *dispatcher, uvgrtp::socket *socket)
{
if (!dispatcher || !socket) {
LOG_ERROR("System call dispatcher cannot continue, invalid value given!");
return;
}
std::mutex m;
std::unique_lock<std::mutex> lk(m);
uvgrtp::transaction_t *t = nullptr;
while (!dispatcher->active())
;
while (dispatcher->active()) {
if ((t = dispatcher->get_transaction()) == nullptr) {
dispatcher->get_cvar().wait(lk);
t = dispatcher->get_transaction();
if (t == nullptr)
break;
}
do {
/* socket->send_vecio(t->headers, t->hdr_ptr, 0); */
if (t->fqueue)
t->fqueue->deinit_transaction(t->key);
} while ((t = dispatcher->get_transaction()) != nullptr);
dispatcher->get_cvar().notify_one();
}
dispatcher->get_mutex().unlock();
}
#endif

View File

@ -1,89 +0,0 @@
#pragma once
#include "uvgrtp/runner.hh"
#include "uvgrtp/util.hh"
#include <condition_variable>
#include <queue>
#include <thread>
#include <mutex>
namespace uvgrtp {
/* System call dispatcher is an optimization technique which aims to minimize
* the delay application experiences when calling push_frame().
*
* The push_frame() is divided roughly into frontend and backend:
* Frontend is the part that executes in the context of the calling application. During this
* phase, the HEVC frame is packetized into smaller frames and put into frame queue.
* On Linux this step is very fast, the application only loops through the HEVC frame and
* sets pointers to frame queue.
* On windows it's a little more work because we can't send multiple packets using one system call
* AND use scatter-gather I/O so it's either or.
*
* When the frame has been split into smaller chunks, the frontend will call the backend
* using trigger_send() functions. This function signals the dispatcher thread that there is
* a frame waiting to be sent. When trigger_send() returns, the application exists from the
* library code and the frame is sent in the background.
*
* By using a separate dispatcher thread, we're able to reduce the amount of delay application
* experiences to very small (<50 us even for large frames [>170 kB]) */
typedef struct transaction transaction_t;
class socket;
class dispatcher;
class dispatcher : public runner {
public:
dispatcher(uvgrtp::socket *socket);
~dispatcher();
/* Add new transaction to dispatcher's task queue
* The task queue is emptied in FIFO style */
rtp_error_t trigger_send(uvgrtp::transaction_t *transaction);
/* Create new thread object and start the dispatcher thread
*
* Return RTP_OK on success
* Return RTP_MEMORY_ERROR if allocation fails */
rtp_error_t start();
/* Stop the dispatcher thread
*
* Return RTP_OK on success
* Return RTP_NOT_READY if there are tasks to be processed in "tasks_" */
rtp_error_t stop();
/* Application and dispatcher communicate with each other using a condition variable
*
* If the task queue is empty, dispatcher will wait on a condition variable
* and when application pushes a new transaction to task queue, it will notify
* the dispatcher that it can start the send process. */
std::condition_variable& get_cvar();
/* When the stream is stopped, it is not a good idea to use condition variable to
* notify main thread that dispatcher is stopped because of the race condition between
* main thread's notify + wait and dispatcher's wait + notify
*
* The safest way is to lock the dispatcher mutex when waiting for dispatcher to stop
* and let it reopen it when it has sent all transactions */
std::mutex& get_mutex();
/* Get next transaction from task queue
* Return nullptr if the task queue is empty */
uvgrtp::transaction_t *get_transaction();
private:
static void dispatch_runner(uvgrtp::dispatcher *dispatcher, uvgrtp::socket *socket);
std::condition_variable cv_;
std::mutex d_mtx_;
std::queue<uvgrtp::transaction_t *> tasks_;
uvgrtp::socket *socket_;
};
}
namespace uvg_rtp = uvgrtp;

View File

@ -26,7 +26,6 @@ uvgrtp::frame_queue::frame_queue(uvgrtp::socket *socket, uvgrtp::rtp *rtp, int f
rtp_(rtp), socket_(socket), flags_(flags)
{
active_ = nullptr;
dispatcher_ = nullptr;
max_queued_ = MAX_QUEUED_MSGS;
max_mcount_ = MAX_MSG_COUNT;

View File

@ -20,8 +20,6 @@ const int MAX_QUEUED_MSGS = 10;
const int MAX_CHUNK_COUNT = 4;
namespace uvgrtp {
class dispatcher;
class frame_queue;
class rtp;
@ -204,9 +202,6 @@ namespace uvgrtp {
transaction_t *active_;
/* Set to nullptr if this frame queue doesn't use dispatcher */
uvgrtp::dispatcher *dispatcher_;
/* Deallocation hook is stored here and copied to transaction upon initialization */
void (*dealloc_hook_)(void *);