Skip to content

Commit

Permalink
added ringbuffer size adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoyanonymous committed Nov 10, 2020
1 parent d3dddcf commit 3cd8232
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
5 changes: 5 additions & 0 deletions docs/mc.rtpsend~.maxref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<description>Retry intervals in milliseconds at connection </description>
</attribute>

<attribute name='ringbuf_framenum' get='1' set='1' type='float64' size='1' >
<digest>Size of an internal ring buffer (multiplied with signal vector size</digest>
<description>Size of an internal ring buffer (multiplied with signal vector size.) </description>
</attribute>

<attribute name='port' get='1' set='1' type='long' size='1' >
<digest>Destination Main Port </digest>
<description>Destination Main Port </description>
Expand Down
9 changes: 6 additions & 3 deletions source/projects/mc.rtpreceive_tilde/mc.rtpreceive_tilde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ message<> getlatency {this, "getlatency", MIN_FUNCTION {if (rtpreceiver != nullp
}
return {};
}
,description{"Outputs a packet latency in milliseconds at second outlet."}}
, description {
"Outputs a packet latency in milliseconds at second outlet."
}
}
;

static long setDspState(void* obj, long state) {
Expand Down Expand Up @@ -159,7 +162,7 @@ void resetReceiver(std::unique_ptr<rtpsr::RtspInOption> s) {
rtpreceiver.reset();
try {
s->port_range = getPortRange();
rtpreceiver = std::make_unique<rtpsr::RtpReceiver>(std::move(s), rtpsr::getCodecByName(codec.get()), cout);
rtpreceiver = std::make_unique<rtpsr::RtpReceiver>(std::move(s), rtpsr::getCodecByName(codec.get()), ringbuf_framenum, cout);
rtpreceiver->launchLoop();
}
catch (std::exception& e) {
Expand All @@ -169,7 +172,7 @@ void resetReceiver(std::unique_ptr<rtpsr::RtspInOption> s) {
void resetReceiver(std::unique_ptr<rtpsr::RtpInOption> s) {
rtpreceiver.reset();
try {
rtpreceiver = std::make_unique<rtpsr::RtpReceiver>(std::move(s), rtpsr::getCodecByName(codec.get()), cout);
rtpreceiver = std::make_unique<rtpsr::RtpReceiver>(std::move(s), rtpsr::getCodecByName(codec.get()), ringbuf_framenum, cout);
rtpreceiver->launchLoop();
}
catch (std::exception& e) {
Expand Down
5 changes: 4 additions & 1 deletion source/projects/mc.rtpsend_tilde/mc.rtpsend_tilde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class rtpsend_tilde : public object<rtpsend_tilde>, public mc_operator<> {
}
}
;

attribute<double> ringbuf_framenum {
this, "ringbuf_framenum", 4, range {1, 1000}, description {"Size of an internal ring buffer (multiplied with signal vector size.)"}};
attribute<double> retry_rate {this, "retry_rate", 500.0, description {"Retry intervals in milliseconds at connection"}};
attribute<double> reorder_queue_size {this, "reorder_queue_size", 500.0, description {"number of packets for reorder queue"}};
attribute<bool> use_rtsp {this,
Expand Down Expand Up @@ -137,6 +138,7 @@ void resetSender(double newvecsize) {
rtpsender = std::make_unique<rtpsr::RtpSender>(std::move(option),
rtpsr::getCodecByName(c),
std::chrono::milliseconds((long long)retry_rate.get()),
ringbuf_framenum,
cout);
}
else {
Expand All @@ -145,6 +147,7 @@ void resetSender(double newvecsize) {
rtpsender = std::make_unique<rtpsr::RtpSender>(std::move(option),
rtpsr::getCodecByName(c),
std::chrono::milliseconds((long long)retry_rate.get()),
ringbuf_framenum,
cout);
}
}
Expand Down
12 changes: 6 additions & 6 deletions source/rtpsendreceive_lib/rtpreceiver.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include "rtpreceiver.hpp"

namespace rtpsr {
RtpReceiver::RtpReceiver(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec, std::ostream& logger)
RtpReceiver::RtpReceiver(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec,double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*s, logger) {
auto option = std::make_unique<RtspInOption>(url, setting_ref.samplerate, setting_ref.channels, setting_ref.framesize);
input = std::make_unique<RtspInFormat>(std::move(option));
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples * 10.2);
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples *ringbuf_multiple);
this->codec = std::make_unique<Decoder>(setting_ref, codec);
init();
}
RtpReceiver::RtpReceiver(std::unique_ptr<RtpInOption> s, Codec codec, std::ostream& logger)
RtpReceiver::RtpReceiver(std::unique_ptr<RtpInOption> s, Codec codec,double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*s, logger) {
input = std::make_unique<RtpInFormat>(std::move(s));
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples * 10.2);
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples *ringbuf_multiple);
this->codec = std::make_unique<Decoder>(setting_ref, codec);
init();
}
RtpReceiver::RtpReceiver(std::unique_ptr<RtspInOption> s, Codec codec, std::ostream& logger)
RtpReceiver::RtpReceiver(std::unique_ptr<RtspInOption> s, Codec codec,double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*s, logger) {
input = std::make_unique<RtspInFormat>(std::move(s));
time_cache = std::chrono::high_resolution_clock::now();
input->ctx->interrupt_callback = AVIOInterruptCB {&RtpReceiver::timeoutCallback, this};
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples * 10.2);
output = std::make_unique<CustomCbAsyncOutFormat>(setting_ref, frame->nb_samples *ringbuf_multiple);
this->codec = std::make_unique<Decoder>(setting_ref, codec);
init();
}
Expand Down
6 changes: 3 additions & 3 deletions source/rtpsendreceive_lib/rtpreceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace rtpsr {
struct RtpReceiver : public RtpSRBase {
explicit RtpReceiver(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec, std::ostream& logger = std::cerr);
explicit RtpReceiver(std::unique_ptr<RtpInOption> s, Codec codec, std::ostream& logger = std::cerr);
explicit RtpReceiver(std::unique_ptr<RtspInOption> s, Codec codec, std::ostream& logger = std::cerr);
explicit RtpReceiver(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec, double ringbuf_multiple=4.2,std::ostream& logger = std::cerr);
explicit RtpReceiver(std::unique_ptr<RtpInOption> s, Codec codec,double ringbuf_multiple=4.2, std::ostream& logger = std::cerr);
explicit RtpReceiver(std::unique_ptr<RtspInOption> s, Codec codec, double ringbuf_multiple=4.2,std::ostream& logger = std::cerr);

~RtpReceiver();

Expand Down
17 changes: 9 additions & 8 deletions source/rtpsendreceive_lib/rtpsender.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#include "rtpsender.hpp"

namespace rtpsr {
RtpSender::RtpSender(
std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec, std::chrono::milliseconds init_retry_rate, std::ostream& logger)
RtpSender::RtpSender(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec, std::chrono::milliseconds init_retry_rate,
double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*s, logger)
, init_retry_rate(init_retry_rate)
, pollingrate(duration_type(static_cast<double>(s->framesize) * 0.5 * 48000 / s->samplerate)) {
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * 10.2);
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * ringbuf_multiple);
auto option = std::make_unique<RtspOutOption>(url, setting_ref.samplerate, setting_ref.channels, setting_ref.framesize);
output = std::make_unique<RtspOutFormat>(std::move(option));
this->codec = std::make_unique<Encoder>(*s, codec);
init();
}
RtpSender::RtpSender(std::unique_ptr<RtpOutOption> option, Codec codec, std::chrono::milliseconds init_retry_rate, std::ostream& logger)
RtpSender::RtpSender(std::unique_ptr<RtpOutOption> option, Codec codec, std::chrono::milliseconds init_retry_rate,
double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*static_cast<RtpSRSetting*>(option.get()), logger)
, init_retry_rate(init_retry_rate) {
pollingrate = duration_type(static_cast<double>(setting_ref.framesize) * 0.5 * 48000 / setting_ref.samplerate);
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * 10.2);
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * ringbuf_multiple);
output = std::make_unique<RtpOutFormat>(std::move(option));
this->codec = std::make_unique<Encoder>(setting_ref, codec);
init();
}

RtpSender::RtpSender(
std::unique_ptr<RtspOutOption> option, Codec codec, std::chrono::milliseconds init_retry_rate, std::ostream& logger)
RtpSender::RtpSender(std::unique_ptr<RtspOutOption> option, Codec codec, std::chrono::milliseconds init_retry_rate,
double ringbuf_multiple, std::ostream& logger)
: RtpSRBase(*static_cast<RtpSRSetting*>(option.get()), logger)
, init_retry_rate(init_retry_rate) {
pollingrate = duration_type(static_cast<double>(setting_ref.framesize) * 0.5 * 48000 / setting_ref.samplerate);
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * 10.2);
input = std::make_unique<CustomCbAsyncInFormat>(setting_ref, setting_ref.framesize * ringbuf_multiple);
output = std::make_unique<RtspOutFormat>(std::move(option));
this->codec = std::make_unique<Encoder>(setting_ref, codec);
init();
Expand Down
10 changes: 7 additions & 3 deletions source/rtpsendreceive_lib/rtpsender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
namespace rtpsr {
struct RtpSender : public RtpSRBase {
explicit RtpSender(std::unique_ptr<RtpSRSetting> s, Url const& url, Codec codec,
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), std::ostream& logger = std::cerr);
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), double ringbuf_multiple = 4.2,
std::ostream& logger = std::cerr);
// launch with raw rtp version;
explicit RtpSender(std::unique_ptr<RtpOutOption> option, Codec codec,
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), std::ostream& logger = std::cerr);
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), double ringbuf_multiple = 4.2,
std::ostream& logger = std::cerr);
// launch with rtsp version
explicit RtpSender(std::unique_ptr<RtspOutOption> option, Codec codec,
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), std::ostream& logger = std::cerr);
std::chrono::milliseconds init_retry_rate = std::chrono::milliseconds(init_retry_rate_int), double ringbuf_multiple = 4.2,
std::ostream& logger = std::cerr);
~RtpSender();

void launchLoop() override;
Expand All @@ -22,6 +25,7 @@ namespace rtpsr {
private:
int64_t timecount = 0;
std::vector<sample_t> framebuf;

// constructor must call init()
void init();
bool fillFrame();
Expand Down

0 comments on commit 3cd8232

Please sign in to comment.