Skip to content

[FR] Add the scheduled sending mode for live mode sending - #3198

Draft
ethouris wants to merge 43 commits into
Haivision:devfrom
ethouris:dev-sender-schedule
Draft

[FR] Add the scheduled sending mode for live mode sending#3198
ethouris wants to merge 43 commits into
Haivision:devfrom
ethouris:dev-sender-schedule

Conversation

@ethouris

@ethouris ethouris commented Aug 12, 2025

Copy link
Copy Markdown
Collaborator

The new scheduled sending mode should work the following way:

  1. As packets are being added to the sender buffer, the sending time will be assigned to them. The first in the schedule will get the last sending time plus interval, next ones will get sending times as calculated for the current situation, mainly basing on the current bandwidth limit, but possibly also with the current maximum availble bandwidth, if it's lower than the limit.
  2. Packet loss will be scheduled for the whole range of packets and they will be scheduled for sending with regard to maximum bandwidth and overhead.
  3. If the current schedule time for the next element is in the past, the base time is cut after exceeding 1 second ("forfeited time").

To use this mode, add the SRTO_SENDMODE option with value 1. sendmode can be used in the applications in the URI.

Development phases:

  1. Implement the scheduling mechanism. Use the m_tdSendInterval as the sending interval base and then just forfeit time exceeding 1 second. The m_tdSendInterval in case of live mode is using the "virtually unlimited" value or MAXBW can control the limit, as well as INPUTBW/OHEADBW. The "forfeit" mechanism means simply that you may potentially send packets that fast, but you don't because the packets scheduled for sending at the input (the srt_sendmsg2 calls) are sent slower than that. This means simply that packets are sent immediately, like before.
  2. Add the groupwise packet sending for the speed measurement mechanism. This should allow the application to schedule all packets "at once", just their delivery time declared in the time still holds.
  3. Add the speed measurement mechanism used for the measurement group and use it to distribute packets within the measurement group. This will dictate the times when packets should be physically sent, although their play time will be modified according to the required bandwidth.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Comment thread srtcore/common.h
namespace srt
{

// export import .api default;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/core.cpp Fixed
Comment thread srtcore/buffer_tools.h
typedef sync::steady_clock::time_point time_point;
typedef sync::steady_clock::duration duration;
CShaper (double min_tokens_capacity):
m_BurstPeriod(sync::milliseconds_from(BURSTPERIOD_DEFAULT())),

Check warning

Code scanning / CodeQL

Lossy function result cast Warning

Return value of type double is implicitly converted to signed long.
Comment thread srtcore/core.cpp Fixed
Comment thread srtcore/buffer_rcv.h Fixed
Comment thread apps/options.hpp
Comment on lines +548 to +554
/* XXX ProcessOptions not implemented to handle this;
may be added in the future.
void process(const std::vector<std::string>& args)
{
m_params = ProcessOptions(args);
}
*/

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/buffer_snd.h

int getAvgBufSize(int& bytes, int& timespan);

// bool getPacketRangeSize(int32_t seqlo, int32_t seqhi, int& w_packets, int& w_bytes);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/core.h

// For schedule mode sending
sync::steady_clock::time_point lastSchedTime() const { return m_LastSched.lastTime(); }
//sync::steady_clock::duration lastSendInterval() const { return m_LastSched.lastInterval(); }

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/schedule_snd.cpp
if (!have_task_ready())
{
m_TaskReadyCond.notify_all();
//IF_HEAVY_LOGGING(notif = " [NOTIFIED]");

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/schedule_snd.cpp
Comment on lines +137 to +177
/*
SendTask::taskiter_t SendScheduler::enqueue_task(socket_t id, const SchedPacket& proto, const clock_time& when, const clock_time& delivery)
{
if (m_bBroken)
{
HLOGC(qslog.Debug, log << "Schedule: ENQ: DENIED, schedule is broken");
return SendTask::none();
}

sync::ScopedLock lk (m_Lock);
SendTask::taskiter_t itask = create_task(proto, when, delivery);

bool was_ready = have_task_ready();

size_t pos = m_TaskQueue.insert(itask);

IF_HEAVY_LOGGING(bool was_first = false);
IF_HEAVY_LOGGING(bool now_ready = false);
if (pos == 0) // earliest task
{
m_tsAboutTime = m_TaskQueue.top()->m_tsSendTime; // INSERTED: will not be empty
IF_HEAVY_LOGGING(was_first = true);
}

// XXX Shouldn't it update always if m_tsAboutTime was updated?
if (!was_ready && have_task_ready())
{
m_TaskReadyCond.notify_all();
IF_HEAVY_LOGGING(now_ready = true);
}

HLOGC(qslog.Debug, log << "Schedule: ENQ: new"
<< fmt_if(now_ready, " READY")
<< " task at T=" << FormatTime(itask->m_tsSendTime)
<< fmt_if(was_first, " (NEW TOP)")
<< fmt_if(was_ready, " (NOW READY)", " (ONLY ADDED)")
<< fmt_if(now_ready, " - NOTIFY"));

return itask;
}
// */

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread srtcore/schedule_snd.h
return !m_bBroken;
}

// SendTask::taskiter_t enqueue_task(socket_t id, const SendTask& proto);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment thread logging/ofmt.h Fixed
Comment thread logging/ofmt.h Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants