|
17 | 17 |
|
18 | 18 | #include <cinttypes>
|
19 | 19 |
|
| 20 | +// Maximum reconnect attempts with an invalid key error before giving up (roughly 30 seconds with default start value). |
| 21 | +static constexpr uint8_t MAX_RECONNECT_ATTEMPTS = 5; |
| 22 | + |
20 | 23 | Qt::ConnectionType BlockingConnectionTypeFor(QObject *object)
|
21 | 24 | {
|
22 | 25 | return object->thread() == QThread::currentThread() ? Qt::DirectConnection : Qt::BlockingQueuedConnection;
|
@@ -395,10 +398,11 @@ void MultitrackVideoOutput::PrepareStreaming(QWidget *parent, const char *servic
|
395 | 398 | obs_output_add_packet_callback(output, bpm_inject, NULL);
|
396 | 399 |
|
397 | 400 | // Set callback to prevent reconnection attempts once the stream key has become invalid
|
398 |
| - static auto reconnect_cb = [](void *, obs_output_t *, int code) -> bool { |
399 |
| - return code != OBS_OUTPUT_INVALID_STREAM; |
| 401 | + static auto reconnect_cb = [](void *param, obs_output_t *, int code) -> bool { |
| 402 | + auto _this = static_cast<MultitrackVideoOutput *>(param); |
| 403 | + return code != OBS_OUTPUT_INVALID_STREAM || (_this->reconnect_attempts++ < MAX_RECONNECT_ATTEMPTS); |
400 | 404 | };
|
401 |
| - obs_output_set_reconnect_callback(output, reconnect_cb, nullptr); |
| 405 | + obs_output_set_reconnect_callback(output, reconnect_cb, this); |
402 | 406 |
|
403 | 407 | OBSSignal start_streaming;
|
404 | 408 | OBSSignal stop_streaming;
|
@@ -810,6 +814,7 @@ void StreamStartHandler(void *arg, calldata_t *)
|
810 | 814 | {
|
811 | 815 | auto self = static_cast<MultitrackVideoOutput *>(arg);
|
812 | 816 | self->restart_on_error = true;
|
| 817 | + self->reconnect_attempts = 0; |
813 | 818 | }
|
814 | 819 |
|
815 | 820 | void StreamStopHandler(void *arg, calldata_t *data)
|
|
0 commit comments