Skip to content

Commit

Permalink
repeat blank every second on offline
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 5, 2024
1 parent e558b0f commit e92002c
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/ustreamer/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ static int _stream_init_loop(us_stream_s *stream) {

bool waiting_reported = false;
while (!atomic_load(&stream->run->stop)) {
# ifdef WITH_GPIO
us_gpio_set_stream_online(false);
# endif

// Флаги has_clients у синков не обновляются сами по себе, поэтому обновим их
// на каждой итерации старта стрима. После старта этим будут заниматься воркеры.
if (stream->jpeg_sink != NULL) {
Expand All @@ -470,25 +474,6 @@ static int _stream_init_loop(us_stream_s *stream) {

_stream_check_suicide(stream);

uint width = stream->dev->run->width;
uint height = stream->dev->run->height;
if (width == 0 || height == 0) {
width = stream->dev->width;
height = stream->dev->height;
}
us_blank_draw(run->blank, "< NO SIGNAL >", width, height);

_stream_set_capture_state(stream, width, height, false, 0);
# ifdef WITH_GPIO
us_gpio_set_stream_online(false);
# endif

_stream_expose_jpeg(stream, run->blank->jpeg);
if (run->h264 != NULL) {
us_h264_stream_process(run->h264, run->blank->raw, true);
}
_stream_expose_raw(stream, run->blank->raw);

stream->dev->dma_export = (
stream->enc->type == US_ENCODER_TYPE_M2M_VIDEO
|| stream->enc->type == US_ENCODER_TYPE_M2M_IMAGE
Expand All @@ -500,20 +485,38 @@ static int _stream_init_loop(us_stream_s *stream) {
waiting_reported = true;
US_LOG_INFO("Waiting for the capture device ...");
}
goto sleep_and_retry;
goto offline_and_retry;
case -1:
waiting_reported = false;
goto sleep_and_retry;
goto offline_and_retry;
default: break;
}
us_encoder_open(stream->enc, stream->dev);
return 0;

sleep_and_retry:
offline_and_retry:
for (uint count = 0; count < stream->error_delay * 10; ++count) {
if (atomic_load(&run->stop)) {
break;
}
if (count % 10 == 0) {
// Каждую секунду повторяем blank
uint width = stream->dev->run->width;
uint height = stream->dev->run->height;
if (width == 0 || height == 0) {
width = stream->dev->width;
height = stream->dev->height;
}
us_blank_draw(run->blank, "< NO SIGNAL >", width, height);

_stream_set_capture_state(stream, width, height, false, 0);

_stream_expose_jpeg(stream, run->blank->jpeg);
if (run->h264 != NULL) {
us_h264_stream_process(run->h264, run->blank->raw, true);
}
_stream_expose_raw(stream, run->blank->raw);
}
usleep(100 * 1000);
}
}
Expand Down

0 comments on commit e92002c

Please sign in to comment.