Skip to content

Commit

Permalink
- add hiccup simulation to file streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
igorshevach committed Nov 6, 2023
1 parent d752bbe commit 572ece9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion transcoder/config_v.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"activeStream": 0,
"xduration": 9000000,
"randomDataPercentage": 0,
"jumpOffsetSec": -60
"jumpOffsetSec": -60,
"hiccupIntervalSec": 0,
"hiccupDurationSec": 0
},
"throttler": {
"maxDataRate": 1.5,
Expand Down
25 changes: 22 additions & 3 deletions transcoder/debug/file_streamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ void* thread_stream_from_file(void *vargp)
char channelId[KMP_MAX_CHANNEL_ID];
json_get_string(GetConfig(),"input.channelId","1_abcdefgh",channelId,sizeof(channelId));

int jumpOffsetSec=0;
int64_t jumpOffsetSec=0;
json_get_int64(GetConfig(),"input.jumpoffsetsec",0,&jumpOffsetSec);

int64_t hiccupDurationSec, hiccupIntervalSec;
json_get_int64(GetConfig(),"input.hiccupDurationSec",0,&hiccupDurationSec);

json_get_int64(GetConfig(),"input.hiccupIntervalSec",0,&hiccupIntervalSec);

AVPacket packet;
av_init_packet(&packet);

Expand Down Expand Up @@ -86,8 +91,10 @@ void* thread_stream_from_file(void *vargp)
LOGGER("SENDER",AV_LOG_INFO,"Realtime = %s",realTime ? "true" : "false");
srand((int)time(NULL));
uint64_t lastDts=0;
int64_t start_time=av_gettime_relative();

int64_t start_time=av_gettime_relative(),
hiccup_duration = hiccupDurationSec * 1000 * 1000,
hiccup_interval = hiccupIntervalSec * 1000 * 1000,
next_hiccup = start_time + hiccup_interval;

samples_stats_t stats;
sample_stats_init(&stats,standard_timebase);
Expand Down Expand Up @@ -144,6 +151,18 @@ void* thread_stream_from_file(void *vargp)

int64_t timePassed=av_rescale_q(packet.dts,standard_timebase,AV_TIME_BASE_Q) + start_time,
clockPassed = av_gettime_relative();

if(clockPassed >= next_hiccup && clockPassed < next_hiccup + hiccup_duration) {
next_hiccup += hiccup_duration;
LOGGER("SENDER",AV_LOG_INFO,"hiccup! [ %ld - %ld ]",
ts2str((clockPassed - start_time) * 90,true),
ts2str((next_hiccup - start_time) * 90,true));

av_usleep(next_hiccup - clockPassed);

next_hiccup = av_gettime_relative() + hiccup_interval;
}

LOGGER("SENDER",AV_LOG_DEBUG,"XXXX clockPassed=%ld timePassed=%ld", clockPassed - start_time,timePassed - start_time);
while (clockPassed < timePassed) {

Expand Down

0 comments on commit 572ece9

Please sign in to comment.