Skip to content

Commit

Permalink
WIP: Introduce rtp_stream="wait"
Browse files Browse the repository at this point in the history
TODO:
* Abort the call on timeout
* Support ontimeout
* TEST
  • Loading branch information
orgads committed Jan 14, 2024
1 parent 925e67a commit 16f8ed7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/scenarios/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ action controls this.
playback.
+ <exec rtp_stream="resume" /> will resume any currently paused
playback.
+ <exec rtp_stream="wait" [timeout="10000"] /> will wait for the active
playback to end before proceeding to the next action.


PCAP play commands (specified using play_pcap_audio / play_pcap_video
Expand Down
1 change: 1 addition & 0 deletions include/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CAction
#endif
E_AT_RTP_STREAM_PAUSE,
E_AT_RTP_STREAM_RESUME,
E_AT_RTP_STREAM_WAIT,
E_AT_RTP_STREAM_PLAY,
E_AT_RTP_ECHO,
E_AT_RTP_STREAM_PAUSEAPATTERN,
Expand Down
2 changes: 2 additions & 0 deletions include/rtpstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct rtpstream_callinfo_t
int local_videoport;
int remote_audioport;
int remote_videoport;
unsigned int timeout;
pthread_t threadID;
};

Expand Down Expand Up @@ -224,6 +225,7 @@ int rtpstream_cache_file(char *filename,
void rtpstream_play(rtpstream_callinfo_t *callinfo, rtpstream_actinfo_t *actioninfo);
void rtpstream_pause(rtpstream_callinfo_t *callinfo);
void rtpstream_resume(rtpstream_callinfo_t *callinfo);
bool rtpstream_is_playing(rtpstream_callinfo_t *callinfo);

void rtpstream_playapattern(rtpstream_callinfo_t *callinfo, rtpstream_actinfo_t *actioninfo, JLSRTP& txUACAudio, JLSRTP& rxUACAudio);
void rtpstream_pauseapattern(rtpstream_callinfo_t *callinfo);
Expand Down
2 changes: 2 additions & 0 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ void CAction::printInfo(char* buf, int len)
snprintf(buf, len, "Type[%d] - rtp_stream pause", M_action);
} else if (M_action == E_AT_RTP_STREAM_RESUME) {
snprintf(buf, len, "Type[%d] - rtp_stream resume", M_action);
} else if (M_action == E_AT_RTP_STREAM_WAIT) {
snprintf(buf, len, "Type[%d] - rtp_stream wait [timeout=%d]", M_action, M_varId);
} else if (M_action == E_AT_RTP_STREAM_PLAYAPATTERN) {
snprintf(buf,
len,
Expand Down
19 changes: 16 additions & 3 deletions src/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ unsigned int call::wake()
wake = recv_timeout;
}

if (rtpstream_callinfo.timeout && (!wake || rtpstream_callinfo.timeout < wake)) {
wake = rtpstream_callinfo.timeout;
}
return wake;
}

Expand Down Expand Up @@ -2078,10 +2081,13 @@ bool call::executeMessage(message *curmsg)
delete this;
return false;
}
} else if (curmsg->timeout || defl_recv_timeout) {
if (curmsg->timeout)
} else if (curmsg->timeout || defl_recv_timeout || rtpstream_callinfo.timeout) {
unsigned int min_timeout = curmsg->timeout;
if (!min_timeout || min_timeout > rtpstream_callinfo.timeout)
min_timeout = rtpstream_callinfo.timeout;
if (min_timeout)
// If timeout is specified on message receive, use it
recv_timeout = getmilliseconds() + curmsg->timeout;
recv_timeout = getmilliseconds() + min_timeout;
else
// Else use the default timeout if specified
recv_timeout = getmilliseconds() + defl_recv_timeout;
Expand Down Expand Up @@ -6139,6 +6145,13 @@ call::T_ActionResult call::executeAction(const char* msg, message* curmsg)
rtpstream_pause(&rtpstream_callinfo);
} else if (currentAction->getActionType() == CAction::E_AT_RTP_STREAM_RESUME) {
rtpstream_resume(&rtpstream_callinfo);
} else if (currentAction->getActionType() == CAction::E_AT_RTP_STREAM_WAIT) {
if (rtpstream_is_playing(&rtpstream_callinfo)) {
setPaused();
} else {
rtpstream_callinfo.timeout = 0;
setRunning();
}
} else if (currentAction->getActionType() == CAction::E_AT_RTP_STREAM_PLAY) {
const char *fileName = createSendingMessage(currentAction->getMessage());
currentAction->setRTPStreamActInfo(fileName);
Expand Down
10 changes: 10 additions & 0 deletions src/rtpstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,16 @@ void rtpstream_resume(rtpstream_callinfo_t* callinfo)
}
}

bool rtpstream_is_playing(rtpstream_callinfo_t *callinfo)
{
debugprint("rtpstream_is_playing callinfo=%p\n", callinfo);

if (taskentry_t *taskinfo = callinfo->taskinfo) {
return taskinfo->audio_loop_count > 0 || taskinfo->video_loop_count > 0;
}
return false;
}

void rtpstream_playapattern(rtpstream_callinfo_t* callinfo, rtpstream_actinfo_t* actioninfo, JLSRTP& txUACAudio, JLSRTP& rxUACAudio)
{
debugprint("rtpstream_playapattern callinfo=%p filename %s pattern_id %d loop %d bytes %d payload %d ptime %d tick %d\n",
Expand Down
6 changes: 6 additions & 0 deletions src/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,12 @@ void scenario::parseAction(CActions *actions)
{
tmpAction->setActionType(CAction::E_AT_RTP_STREAM_RESUME);
}
else if (!strcmp(ptr, "wait"))
{
tmpAction->setActionType(CAction::E_AT_RTP_STREAM_WAIT);
// Abuse VarId for the timeout value
tmpAction->setVarId(xp_get_long("timeout", "wait timeout", 0));
}
else
{
tmpAction->setMessage(ptr);
Expand Down

0 comments on commit 16f8ed7

Please sign in to comment.