diff --git a/DigestPlay.c b/DigestPlay.c index 273e163..de4142f 100644 --- a/DigestPlay.c +++ b/DigestPlay.c @@ -47,7 +47,8 @@ int main(int argc, char* argv[]) struct RewindSuperHeader header; memset(&header, 0, sizeof(struct RewindSuperHeader)); - time_t waiting = 0; + time_t interval1 = 0; + time_t interval2 = 0; struct RewindSessionPollData poll; // Start up @@ -62,6 +63,7 @@ int main(int argc, char* argv[]) { "group-id", required_argument, NULL, 'g' }, { "talker-alias", required_argument, NULL, 't' }, { "wait", required_argument, NULL, 'o' }, + { "pause", required_argument, NULL, 'e' }, { "linear", no_argument, NULL, 'l' }, { "mode33", no_argument, NULL, 'm' }, { NULL, 0, NULL, 0 } @@ -71,7 +73,7 @@ int main(int argc, char* argv[]) int control = 0; int selection = 0; - while ((selection = getopt_long(argc, argv, "w:c:s:p:u:g:t:o:lm", options, NULL)) != EOF) + while ((selection = getopt_long(argc, argv, "w:c:s:p:u:g:t:o:e:lm", options, NULL)) != EOF) switch (selection) { case 'w': @@ -117,7 +119,11 @@ int main(int argc, char* argv[]) break; case 'o': - waiting = strtol(optarg, NULL, 10); + interval1 = strtol(optarg, NULL, 10); + break; + + case 'e': + interval2 = strtol(optarg, NULL, 10); break; case 'l': @@ -143,7 +149,8 @@ int main(int argc, char* argv[]) " --talker-alias \n" " --linear (use AMBE linear format instead of DSD)\n" " --mode33 (use AMBE mode 33 format instead of DSD)\n" - " --wait \n" + " --wait \n" + " --pause \n" "\n", argv[0]); return EXIT_FAILURE; @@ -187,12 +194,16 @@ int main(int argc, char* argv[]) // Wait for the end of existing call session if required - if (waiting > 0) + if ((interval1 > 0) || + (interval2 > 0)) { poll.type = htole32(TREE_SESSION_BY_TARGET); poll.flag = htole32(SESSION_TYPE_FLAG_GROUP); - result = WaitForRewindSessionEnd(context, &poll, waiting); + printf("Waiting...\r"); + fflush(stdout); + + result = WaitForRewindSessionEnd(context, &poll, interval1, interval2); if (result != CLIENT_ERROR_SUCCESS) { diff --git a/RewindClient.c b/RewindClient.c index 5592294..dd7c00d 100644 --- a/RewindClient.c +++ b/RewindClient.c @@ -289,7 +289,7 @@ int ConnectRewindClient(struct RewindContext* context, const char* location, con return CLIENT_ERROR_RESPONSE_TIMEOUT; } -int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionPollData* request, time_t interval) +int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionPollData* request, time_t interval1, time_t interval2) { struct RewindData* buffer = (struct RewindData*)alloca(BUFFER_SIZE); struct RewindSessionPollData* response = (struct RewindSessionPollData*)buffer->data; @@ -297,13 +297,18 @@ int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionP uint32_t state = 0b00; struct timeval now; - struct timeval threshold; + struct timeval threshold1; + struct timeval threshold2; gettimeofday(&now, NULL); - threshold.tv_sec = now.tv_sec + interval; - threshold.tv_usec = now.tv_usec; - while (timercmp(&now, &threshold, <)) + threshold1.tv_sec = now.tv_sec + interval1 + interval2; + threshold1.tv_usec = now.tv_usec; + + threshold2.tv_sec = 0; + threshold2.tv_usec = 0; + + while (timercmp(&now, &threshold1, <)) { TransmitRewindData(context, REWIND_TYPE_KEEP_ALIVE, REWIND_FLAG_NONE, context->data, context->length); TransmitRewindData(context, REWIND_TYPE_SESSION_POLL, REWIND_FLAG_NONE, request, sizeof(struct RewindSessionPollData)); @@ -328,15 +333,29 @@ int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionP break; case REWIND_TYPE_SESSION_POLL: - if (response->state == 0) + if ((response->state == 0) && + (threshold2.tv_sec == 0)) { - // No active sessions - return CLIENT_ERROR_SUCCESS; + threshold2.tv_sec = now.tv_sec + interval2; + threshold2.tv_usec = now.tv_usec; + } + if ((response->state != 0) && + (threshold2.tv_sec != 0)) + { + threshold2.tv_sec = 0; + threshold2.tv_usec = 0; } state |= 0b10; break; } + if ((threshold2.tv_sec != 0) && + (timercmp(&now, &threshold2, >))) + { + // No active sessions during + return CLIENT_ERROR_SUCCESS; + } + if (state == 0b11) { // Got REWIND_TYPE_KEEP_ALIVE and REWIND_TYPE_SESSION_POLL diff --git a/RewindClient.h b/RewindClient.h index d29bb6f..93b453f 100644 --- a/RewindClient.h +++ b/RewindClient.h @@ -49,7 +49,7 @@ void TransmitRewindData(struct RewindContext* context, uint16_t type, uint16_t f ssize_t ReceiveRewindData(struct RewindContext* context, struct RewindData* buffer, ssize_t length); int ConnectRewindClient(struct RewindContext* context, const char* location, const char* port, const char* password, uint32_t options); -int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionPollData* request, time_t interval); +int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionPollData* request, time_t interval1, time_t interval2); #define TransmitRewindKeepAlive(context) TransmitRewindData(context, REWIND_TYPE_KEEP_ALIVE, REWIND_FLAG_NONE, context->data, context->length); #define TransmitRewindCloae(context) TransmitRewindData(context, REWIND_TYPE_CLOSE, REWIND_FLAG_NONE, NULL, 0 ); diff --git a/Version.h b/Version.h index 69e1cd7..52ecbe6 100644 --- a/Version.h +++ b/Version.h @@ -1 +1 @@ -#define VERSION 20170607 +#define VERSION 20170608