diff --git a/apps/srt-live-transmit.cpp b/apps/srt-live-transmit.cpp index 11fae0efa..fffbebfff 100644 --- a/apps/srt-live-transmit.cpp +++ b/apps/srt-live-transmit.cpp @@ -82,10 +82,6 @@ #include #include -// The length of the SRT payload used in srt_recvmsg call. -// So far, this function must be used and up to this length of payload. -const size_t DEFAULT_CHUNK = 1316; - using namespace std; @@ -240,7 +236,14 @@ int main( int argc, char** argv ) int timeout = stoi(Option("30", "t", "to", "timeout"), 0, 0); size_t chunk = stoul(Option("0", "c", "chunk"), 0, 0); if ( chunk == 0 ) - chunk = DEFAULT_CHUNK; + { + chunk = SRT_LIVE_DEF_PLSIZE; + } + else + { + transmit_chunk_size = chunk; + } + size_t bandwidth = stoul(Option("0", "b", "bandwidth", "bitrate"), 0, 0); transmit_bw_report = stoul(Option("0", "r", "report", "bandwidth-report", "bitrate-report"), 0, 0); transmit_verbose = Option("no", "v", "verbose") != "no"; @@ -286,6 +289,7 @@ int main( int argc, char** argv ) } } + #ifdef WIN32 #define alarm(argument) (void)0 #else diff --git a/common/transmitbase.hpp b/common/transmitbase.hpp index a43c9a652..da90d94a9 100644 --- a/common/transmitbase.hpp +++ b/common/transmitbase.hpp @@ -12,6 +12,7 @@ extern volatile bool transmit_throw_on_interrupt; extern int transmit_bw_report; extern unsigned transmit_stats_report; extern std::ostream* transmit_cverb; +extern size_t transmit_chunk_size; static const struct VerboseLogNoEol { VerboseLogNoEol() {} } VerbNoEOL; diff --git a/common/transmitmedia.cpp b/common/transmitmedia.cpp index 6729c0c2c..0e38a174b 100644 --- a/common/transmitmedia.cpp +++ b/common/transmitmedia.cpp @@ -24,6 +24,7 @@ std::ostream* transmit_cverb = nullptr; volatile bool transmit_throw_on_interrupt = false; int transmit_bw_report = 0; unsigned transmit_stats_report = 0; +size_t transmit_chunk_size = SRT_LIVE_DEF_PLSIZE; class FileSource: public Source { @@ -168,9 +169,22 @@ void SrtCommon::InitParameters(string host, map par) par.erase("port"); } + // That's kinda clumsy, but it must rely on the defaults. + // Default mode is live, so check if the file mode was enforced + if (par.count("transtype") == 0 || par["transtype"] != "file") + { + // If the Live chunk size was nondefault, enforce the size. + if (transmit_chunk_size != SRT_LIVE_DEF_PLSIZE) + { + if (transmit_chunk_size > SRT_LIVE_MAX_PLSIZE) + throw std::runtime_error("Chunk size in live mode exceeds 1456 bytes; this is not supported"); + + par["payloadsize"] = Sprint(transmit_chunk_size); + } + } + // Assign the others here. m_options = par; - } void SrtCommon::PrepareListener(string host, int port, int backlog)