Skip to content

Commit

Permalink
Fixed passing the chunk size by transmit to SRTO_PAYLOADSIZE option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Oct 13, 2017
1 parent 84a4202 commit 7fd7c0f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 9 additions & 5 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@
#include <srt.h>
#include <logging.h>

// 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;


Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -286,6 +289,7 @@ int main( int argc, char** argv )
}
}


#ifdef WIN32
#define alarm(argument) (void)0
#else
Expand Down
1 change: 1 addition & 0 deletions common/transmitbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 15 additions & 1 deletion common/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -168,9 +169,22 @@ void SrtCommon::InitParameters(string host, map<string,string> 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)
Expand Down

0 comments on commit 7fd7c0f

Please sign in to comment.