fix(decklink-bridge): prevent redundant fc_writer_open loops via last_format tracking

This commit is contained in:
Wild Dragon Dev 2026-06-04 01:10:47 +00:00
parent d957ce74ae
commit 5b72ee167d

View file

@ -107,6 +107,10 @@ struct DeviceState {
int height = 0; int height = 0;
int fps_num = 0; int fps_num = 0;
int fps_den = 1; int fps_den = 1;
int last_width = 0;
int last_height = 0;
int last_fps_num = 0;
int last_fps_den = 1;
bool interlaced = false; bool interlaced = false;
std::atomic<bool> signal_reported{false}; std::atomic<bool> signal_reported{false};
@ -362,16 +366,17 @@ private:
pthread_mutex_lock(&m_ds->fc_lock); pthread_mutex_lock(&m_ds->fc_lock);
// If already open with same format, do nothing. // If already open with same format, do nothing.
if (m_ds->fc_writer &&
m_ds->width == m_ds->last_width &&
m_ds->height == m_ds->last_height &&
m_ds->fps_num == m_ds->last_fps_num &&
m_ds->fps_den == m_ds->last_fps_den)
{
pthread_mutex_unlock(&m_ds->fc_lock);
return;
}
if (m_ds->fc_writer) { if (m_ds->fc_writer) {
fc_hdr_t *h = (fc_hdr_t *)m_ds->fc_writer->base;
if (h->width == (uint32_t)m_ds->width &&
h->height == (uint32_t)m_ds->height &&
h->fps_num == (uint32_t)m_ds->fps_num &&
h->fps_den == (uint32_t)m_ds->fps_den)
{
pthread_mutex_unlock(&m_ds->fc_lock);
return;
}
fc_writer_close(m_ds->fc_writer); fc_writer_close(m_ds->fc_writer);
m_ds->fc_writer = nullptr; m_ds->fc_writer = nullptr;
} }
@ -382,7 +387,12 @@ private:
m_ds->slot_id.c_str(), m_ds->slot_id.c_str(),
(uint32_t)m_ds->width, (uint32_t)m_ds->height, (uint32_t)m_ds->width, (uint32_t)m_ds->height,
(uint32_t)m_ds->fps_num, (uint32_t)m_ds->fps_den); (uint32_t)m_ds->fps_num, (uint32_t)m_ds->fps_den);
if (!m_ds->fc_writer) { if (m_ds->fc_writer) {
m_ds->last_width = m_ds->width;
m_ds->last_height = m_ds->height;
m_ds->last_fps_num = m_ds->fps_num;
m_ds->last_fps_den = m_ds->fps_den;
} else {
fprintf(stderr, "[decklink:%d] framecache unavailable\n", fprintf(stderr, "[decklink:%d] framecache unavailable\n",
m_ds->device_idx); m_ds->device_idx);
} }