mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-04 15:50:42 -07:00
iidx: camera hook improvements (#841)
## Link to GitHub Issue or related Pull Request, if one exists #201 ## Description of change - Adds MJPEG camera support using Media Foundation decoding. - Moves camera capture to asynchronous Source Reader callbacks. - Supports native NV12 and YUY2 capture, preferring target-sized native formats over MJPEG when possible. - Improves capture and rendering performance through callback-paced reads, bulk frame uploads, optimized row-based flips, and lazy allocation of flip textures. - Makes runtime media-type changes interrupt pending reads and safely flush and reconfigure the Source Reader. - Improves automatic mode selection based on aspect ratio, proximity to 1280x720, frame rate, and capture format. - Hardens camera shutdown, flush handling, media-type changes, and repeated capture failures. ## Testing Tested with two cameras in tdj
This commit is contained in:
@@ -82,9 +82,14 @@ namespace overlay::windows {
|
||||
ImGui::Text("Rendering");
|
||||
|
||||
// Media Type Selector
|
||||
int selectedMediaTypeIndex = selectedCamera->m_selectedMediaTypeIndex;
|
||||
int selectedMediaTypeIndex = selectedCamera->GetSelectedMediaTypeIndex();
|
||||
auto numMediaTypes = selectedCamera->m_mediaTypeInfos.size();
|
||||
|
||||
if (numMediaTypes == 0) {
|
||||
ImGui::TextColored(ImVec4(1.f, 1.f, 0.f, 1.f), "%s", "No supported media types");
|
||||
return;
|
||||
}
|
||||
|
||||
auto selectedMediaTypeIndexChanged = ImGui::BeginCombo(
|
||||
"Media Type", selectedCamera->m_mediaTypeInfos.at(selectedMediaTypeIndex).description.c_str()
|
||||
);
|
||||
@@ -103,9 +108,9 @@ namespace overlay::windows {
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if (selectedMediaTypeIndexChanged && selectedMediaTypeIndex != selectedCamera->m_selectedMediaTypeIndex) {
|
||||
if (selectedMediaTypeIndexChanged && selectedMediaTypeIndex != selectedCamera->GetSelectedMediaTypeIndex()) {
|
||||
selectedCamera->m_useAutoMediaType = false;
|
||||
selectedCamera->ChangeMediaType(selectedCamera->m_mediaTypeInfos.at(selectedMediaTypeIndex).p_mediaType);
|
||||
selectedCamera->RequestMediaType(selectedCamera->m_mediaTypeInfos.at(selectedMediaTypeIndex).p_mediaType);
|
||||
}
|
||||
|
||||
// Auto media type
|
||||
@@ -114,13 +119,14 @@ namespace overlay::windows {
|
||||
if (ImGui::Checkbox("Auto##MediaType", &isAutoMediaType)) {
|
||||
selectedCamera->m_useAutoMediaType = isAutoMediaType;
|
||||
if (isAutoMediaType) {
|
||||
selectedCamera->ChangeMediaType(selectedCamera->m_pAutoMediaType);
|
||||
selectedCamera->RequestMediaType(selectedCamera->m_pAutoMediaType);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw mode
|
||||
int selectedDrawModeIndex = selectedCamera->m_drawMode;
|
||||
if (ImGui::BeginCombo("Draw Mode", DRAW_MODE_LABELS[selectedCamera->m_drawMode].c_str())) {
|
||||
const auto drawMode = selectedCamera->m_drawMode.load();
|
||||
int selectedDrawModeIndex = drawMode;
|
||||
if (ImGui::BeginCombo("Draw Mode", DRAW_MODE_LABELS[drawMode].c_str())) {
|
||||
for (size_t i = 0; i < DRAW_MODE_SIZE; i++) {
|
||||
const bool is_selected = (selectedDrawModeIndex == (int) i);
|
||||
if (ImGui::Selectable(DRAW_MODE_LABELS[i].c_str(), is_selected)) {
|
||||
@@ -142,15 +148,25 @@ namespace overlay::windows {
|
||||
"Letterbox to 4:3: Like Letterbox, but target 4:3"
|
||||
);
|
||||
|
||||
if (selectedDrawModeIndex != selectedCamera->m_drawMode) {
|
||||
selectedCamera->m_drawMode = (LocalCameraDrawMode)selectedDrawModeIndex;
|
||||
if (selectedDrawModeIndex != selectedCamera->m_drawMode.load()) {
|
||||
selectedCamera->m_drawMode.store((LocalCameraDrawMode)selectedDrawModeIndex);
|
||||
selectedCamera->UpdateDrawRect();
|
||||
}
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Checkbox("Horizontal Flip", &selectedCamera->m_flipHorizontal);
|
||||
bool flipHorizontal = selectedCamera->m_flipHorizontal.load();
|
||||
if (ImGui::Checkbox("Horizontal Flip", &flipHorizontal)) {
|
||||
selectedCamera->m_flipHorizontal.store(flipHorizontal);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Vertical Flip", &selectedCamera->m_flipVertical);
|
||||
bool flipVertical = selectedCamera->m_flipVertical.load();
|
||||
if (ImGui::Checkbox("Vertical Flip", &flipVertical)) {
|
||||
selectedCamera->m_flipVertical.store(flipVertical);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::HelpMarker(
|
||||
"Flips are done by the CPU and can be very expensive, potentially causing frame drops! "
|
||||
"Prefer to use camera's built-in flip if available.");
|
||||
|
||||
// Camera control parameters
|
||||
ImGui::Separator();
|
||||
|
||||
Reference in New Issue
Block a user