Skip to content
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

LIV-1205: Transcoder overload protection. #181

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- reduce cold (heat up) period to 0
igorshevach committed Nov 6, 2023
commit c812e2845ce6ea3fdcde7b4aff73584d94269234
3 changes: 1 addition & 2 deletions transcoder/receiver_server.c
Original file line number Diff line number Diff line change
@@ -28,9 +28,8 @@ int atomFileWrite (char* fileName,char* content,size_t size)
int processedFrameCB(receiver_server_session_t *session,bool completed)
{
uint64_t now=av_gettime();
receiver_server_t *server=session->server;
if (completed || now-session->lastStatsUpdated>session->diagnosticsIntervalInSeconds) {//1 second interval

receiver_server_t *server=session->server;


char* tmpBuf=av_malloc(MAX_DIAGNOSTICS_STRING_LENGTH);
147 changes: 147 additions & 0 deletions transcoder/tests/config_a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"input": {
"file": "/media/worng_order_audio_only.ts",
"realTime": false,
"activeStream": 0,
"zduration": 9000000,
"randomDataPercentage": 0,
"xhiccupIntervalSec": 5,
"xhiccupDurationSec": 2
},
"throttler": {
"maxDataRate": 1.5,
"coldSeconds": 0,
"minThrottleWaitMs": 1
},
"frameDropper1": {
"enabled": false,
"queueDuration": 10,
"queueSize": 0,
"nonKeyFrameDropperThreshold": 4,
"decodedFrameDropperThreshold": 2
},
"logger": {
"logLevels": ["DEBUG","VERBOSE","INFO","WARN","ERROR","FATAL","PANIC"],
"logLevel": "DEBUG"
},
"kmp": {
"listenPort": 16543,
"listenAddress": "0.0.0.0",
"acceptTimeout": 15,
"idleTimeout": 10,
"connectTimeout": 10
},
"control": {
"listenPort": 18001,
"listenAddress": "0.0.0.0"
},
"debug": {
"diagnosticsIntervalInSeconds": 1
},
"output": {
"saveFile": true,
"outputFileNamePattern": "./output_%s.ts",
"streamingUrla": "kmp://localhost:6543",
"streamingUrl12": "kmp://192.168.11.59:6543",
"streamingUrl1": ""
},
"engine": {
"encoders": {
"h264": ["h264_nvenc","libx264","h264_videotoolbox"]
},
"presets": {
"A": {
"h264_videotoolbox": "default",
"libx264": "veryfast",
"h264_nvenc": "fast"
}
}
},
"errorPolicy": {
"exitOnError": false
},
"outputTracks": [
{
"trackId": "v32",
"enabled": false,
"passthrough": true
},
{
"trackId": "a32",
"enabled": true,
"passthrough": true
},
{
"trackId": "a33",
"enabled": true,
"bitrate": 64,
"passthrough": false,
"codec": "aac",
"audioParams": {
"samplingRate": -1,
"channels": 2
}
},
{
"trackId": "v33",
"passthrough": false,
"enabled": false,
"bitrate": 900,
"codec": "h264",
"videoParams": {
"profile": "main",
"preset": "A",
"height": 480
}
},
{
"trackId": "v34",
"enabled": false,
"passthrough": false,
"bitrate": 600,
"codec": "h264",
"videoParams": {
"profile": "baseline",
"preset": "A",
"height": 360
}
},
{
"trackId": "v35",
"enabled": false,
"passthrough": false,
"bitrate": 400,
"codec": "h264",
"videoParams": {
"profile": "baseline",
"preset": "A",
"height": 360
}
},
{
"trackId": "v42",
"enabled": false,
"passthrough": false,
"bitrate": 1500,
"codec": "h264",
"videoParams": {
"profile": "high",
"preset": "A",
"height": 720
}
},
{
"trackId": "v43",
"enabled": false,
"passthrough": false,
"bitrate": 2500,
"codec": "h264",
"videoParams": {
"profile": "high",
"preset": "A",
"height": 2160,
"skipFrame": 1
}
}
]
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
},
"throttler": {
"maxDataRate": 1.5,
"coldSeconds": 0,
"coldSeconds": 1,
"minThrottleWaitMs": 1
},
"frameDropper1": {
16 changes: 9 additions & 7 deletions transcoder/utils/throttler.c
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
#include "json_parser.h"

static void doThrottle(float maxDataRate,
int coldSeconds,
float coldSeconds,
int minThrottleWaitMs,
samples_stats_t *stats,
AVRational targetFramerate);
@@ -21,7 +21,7 @@ throttler_init(samples_stats_t *stats,throttler_t *throttler) {
json_get_double(config,"throttler.maxDataRate",INFINITY,(double*)&throttler->maxDataRate);
*(bool*)&throttler->enabled = throttler->maxDataRate < INFINITY;
if(throttler->enabled){
json_get_int(config,"throttler.coldSeconds",0,(int*)&throttler->coldSeconds);
json_get_double(config,"throttler.coldSeconds",0,(double*)&throttler->coldSeconds);
json_get_int(config,"throttler.minThrottleWaitMs",1,(int*)&throttler->minThrottleWaitMs);
throttler->stats = stats;
}
@@ -50,7 +50,7 @@ throttler_process(throttler_t *throttler,transcode_session_t *transcode_session)
static
void
doThrottle(float maxDataRate,
int coldSeconds,
float coldSeconds,
int minThrottleWaitMs,
samples_stats_t *stats,
AVRational targetFramerate)
@@ -61,11 +61,13 @@ doThrottle(float maxDataRate,

samples_stats_log(CATEGORY_RECEIVER,AV_LOG_DEBUG,stats,"throttleThread-Stats");

if(stats->totalFrames < coldSeconds * targetFramerate.num / targetFramerate.den) {
if(stats->totalFrames * targetFramerate.den < coldSeconds * targetFramerate.num ) {
return;
}

currentDataRate = stats->currentFrameRate * targetFramerate.den / (float)targetFramerate.num;
// when starting up use actual number of frames received so far and
// not the speed at which they accumulate
const currentFrameRate = __MIN(stats->totalFrames,stats->currentFrameRate);
currentDataRate = currentFrameRate * targetFramerate.den / (float)targetFramerate.num;

LOGGER(CATEGORY_THROTTLER,
AV_LOG_DEBUG,"throttleThread. data rate current: %.3f max: %.3f",
@@ -78,7 +80,7 @@ doThrottle(float maxDataRate,
const int minThrottleWaitMs = 1;
if(throttleWaitUSec > minThrottleWaitMs * 1000) {
LOGGER(CATEGORY_THROTTLER,AV_LOG_INFO,"throttleThread. throttling %.3f ms",throttleWaitUSec / 1000.f);
stats->throttleWait += av_rescale_q( throttleWaitUSec, clockScale, standard_timebase);
stats->throttleWait += av_rescale_q(throttleWaitUSec, clockScale, standard_timebase);
av_usleep(throttleWaitUSec);
}
}
2 changes: 1 addition & 1 deletion transcoder/utils/throttler.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
typedef struct {
const bool enabled;
const double maxDataRate;
const int coldSeconds;
const double coldSeconds;
const int minThrottleWaitMs;
samples_stats_t *stats;
} throttler_t;