Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,34 @@ static std::vector<encoder_t> encoders {
};

void reset_display(std::shared_ptr<platf::display_t> &disp, AVHWDeviceType type, const std::string &display_name, const config_t &config) {
// We try this twice, in case we still get an error on reinitialization
for(int x = 0; x < 2; ++x) {
int reset_count = 0;
const int max_reset_count = 2;
bool possible_invalid_display_name = false;

// We are going to try to reset the display up to 2 times.
// Just in case if the display failed initialization.
while(reset_count < max_reset_count) {
disp.reset();
disp = platf::display(map_base_dev_type(type), display_name, config);
if(disp) {
break;
disp = platf::display(map_base_dev_type(type), possible_invalid_display_name ? "" : display_name, config);

if(!disp) {
reset_count++;
}

// If we reached the maximum attempts and user configured a display name, it might be invalid.
if(reset_count == 2 && !disp && !display_name.empty()) {
possible_invalid_display_name = true;
BOOST_LOG(warning) << "Failed to set display preference for: " << display_name << " falling back to next available display"sv;
reset_count = 0;
}

// The capture code depends on us to sleep between failures
std::this_thread::sleep_for(200ms);

if(disp) {
// No need to try again if we succeded the first attempt.
break;
}
}
}

Expand Down Expand Up @@ -1684,6 +1702,8 @@ enum validate_flag_e {

int validate_config(std::shared_ptr<platf::display_t> &disp, const encoder_t &encoder, const config_t &config) {
reset_display(disp, encoder.base_dev_type, config::video.output_name, config);


if(!disp) {
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion tools/ddprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ int main(int argc, char *argv[]) {
}
}

return 0;
// In order to prevent potential false positives, we will return an error here.
return -1;
}