Skip to content

Commit

Permalink
Improve startup time for mpegts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Dave committed Oct 31, 2024
1 parent 3e995bc commit 9bb83f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/webu_mpegts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ ssize_t cls_webu_mpegts::response(char *buf, size_t max)
}

if (stream_pos == 0) {
if ((webus->time_last.tv_sec - st_mono_time.tv_sec) < 2) {
webus->stream_fps = 30;
} else {
webus->set_fps();
}
webus->delay();
resetpos();
if (getimg() < 0) {
Expand Down Expand Up @@ -297,9 +302,10 @@ int cls_webu_mpegts::open_mpegts()
size_t aviobuf_sz;

opts = NULL;
webus->stream_fps = 10000; /* For quick start up*/
webus->stream_fps = 30;
aviobuf_sz = 4096;
clock_gettime(CLOCK_REALTIME, &start_time);
clock_gettime(CLOCK_MONOTONIC, &st_mono_time);

fmtctx = avformat_alloc_context();
fmtctx->oformat = av_guess_format("mpegts", NULL, NULL);
Expand Down Expand Up @@ -392,8 +398,6 @@ int cls_webu_mpegts::open_mpegts()

av_dict_free(&opts);

webus->set_fps();

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/webu_mpegts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
AVCodecContext *ctx_codec;
size_t stream_pos; /* Stream position of sent image */
struct timespec start_time; /* Start time of the stream*/
struct timespec st_mono_time;

int pic_send(unsigned char *img);
int pic_get();
Expand Down

0 comments on commit 9bb83f4

Please sign in to comment.