-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added bulk mode UDP #75
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,22 +9,22 @@ | |||||
|
||||||
// OpenSRT | ||||||
#include "uriparser.hpp" | ||||||
#include "netinet_any.h" | ||||||
#include "srt.h" | ||||||
|
||||||
namespace xtransmit | ||||||
{ | ||||||
namespace socket | ||||||
{ | ||||||
|
||||||
class udp | ||||||
: public std::enable_shared_from_this<udp> | ||||||
, public isocket | ||||||
class udp_base | ||||||
Check warning Code scanning / CodeQL Non-virtual destructor in base class
A base class with a virtual function should define a virtual destructor.
|
||||||
: public isocket | ||||||
{ | ||||||
using shared_udp = std::shared_ptr<udp>; | ||||||
using string = std::string; | ||||||
|
||||||
public: | ||||||
udp(const UriParser &src_uri); | ||||||
~udp(); | ||||||
udp_base(const UriParser &src_uri); | ||||||
~udp_base(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
public: | ||||||
void listen(); | ||||||
|
@@ -34,6 +34,25 @@ class udp | |||||
|
||||||
SOCKET id() const final { return m_bind_socket; } | ||||||
|
||||||
protected: | ||||||
SOCKET m_bind_socket = -1; // INVALID_SOCK; | ||||||
sockaddr_in m_dst_addr = {}; | ||||||
|
||||||
bool m_blocking_mode = false; | ||||||
string m_host; | ||||||
int m_port; | ||||||
std::map<string, string> m_options; // All other options, as provided in the URI | ||||||
}; | ||||||
|
||||||
class udp | ||||||
: public std::enable_shared_from_this<udp> | ||||||
, public udp_base | ||||||
{ | ||||||
using shared_udp = std::shared_ptr<udp>; | ||||||
|
||||||
public: | ||||||
using udp_base::udp_base; | ||||||
|
||||||
public: | ||||||
/** | ||||||
* @returns The number of bytes received. | ||||||
|
@@ -43,15 +62,41 @@ class udp | |||||
size_t read(const mutable_buffer &buffer, int timeout_ms = -1) final; | ||||||
int write(const const_buffer &buffer, int timeout_ms = -1) final; | ||||||
|
||||||
private: | ||||||
SOCKET m_bind_socket = -1; // INVALID_SOCK; | ||||||
sockaddr_in m_dst_addr = {}; | ||||||
}; | ||||||
|
||||||
#ifdef __linux__ | ||||||
|
||||||
const auto MAX_SINGLE_READ = 10; | ||||||
|
||||||
class mudp | ||||||
: public std::enable_shared_from_this<mudp> | ||||||
, public udp_base | ||||||
{ | ||||||
using shared_udp = std::shared_ptr<mudp>; | ||||||
char bufspace[MAX_SINGLE_READ][SRT_LIVE_MAX_PLSIZE]; | ||||||
::srt::sockaddr_any addresses[MAX_SINGLE_READ]; | ||||||
mmsghdr mm_array[MAX_SINGLE_READ]; | ||||||
iovec iovec_array[MAX_SINGLE_READ][1]; | ||||||
|
||||||
unsigned int* bufsizes[MAX_SINGLE_READ]; | ||||||
size_t nbuffers = 0; | ||||||
size_t cbuffer = 0; | ||||||
|
||||||
|
||||||
public: | ||||||
mudp(const UriParser& u); | ||||||
|
||||||
public: | ||||||
/** | ||||||
* @returns The number of bytes received. | ||||||
* | ||||||
* @throws socket_exception Thrown on failure. | ||||||
*/ | ||||||
size_t read(const mutable_buffer &buffer, int timeout_ms = -1) override final; | ||||||
int write(const const_buffer &buffer, int timeout_ms = -1) override final; | ||||||
|
||||||
bool m_blocking_mode = false; | ||||||
string m_host; | ||||||
int m_port; | ||||||
std::map<string, string> m_options; // All other options, as provided in the URI | ||||||
}; | ||||||
#endif | ||||||
|
||||||
} // namespace socket | ||||||
} // namespace xtransmit |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,12 @@ using namespace std; | |
|
||
atomic_bool force_break(false); | ||
|
||
namespace xtransmit { | ||
#ifdef __linux__ | ||
bool g_udp_mode_bulk = false; | ||
#endif | ||
} | ||
|
||
void OnINT_ForceExit(int) | ||
{ | ||
cerr << "\n-------- REQUESTED INTERRUPT!\n"; | ||
|
@@ -177,6 +183,17 @@ int main(int argc, char** argv) | |
}, | ||
"log level [debug, error, note, info, fatal]"); | ||
|
||
#ifdef __linux__ | ||
app.add_option( | ||
"--udp-mode", | ||
[](CLI::results_t val) { | ||
if (val[0] == "bulk") | ||
::xtransmit::g_udp_mode_bulk = true; | ||
return true; | ||
}, | ||
"UDP mode: simple or bulk [Linux only]"); | ||
Comment on lines
+190
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To detect possible typos (if returning
|
||
#endif | ||
|
||
const string logfa_desc = create_srt_logfa_description(); | ||
app.add_option( | ||
"--logfa", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to block if there is a cached buffer to read.