Skip to content

Commit

Permalink
Fix video resolution setting
Browse files Browse the repository at this point in the history
Index the filtered modes when selecting from the combobox, not from the
full list.

Closes qTox#1033.
  • Loading branch information
b4n committed Jun 9, 2016
1 parent 76239aa commit 872941c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ void AVForm::updateVideoModes(int curIndex)
return;
}
QString devName = videoDeviceList[curIndex].first;
videoModes = CameraDevice::getVideoModes(devName);
std::sort(videoModes.begin(), videoModes.end(),
QVector<VideoMode> allVideoModes = CameraDevice::getVideoModes(devName);
std::sort(allVideoModes.begin(), allVideoModes.end(),
[](const VideoMode& a, const VideoMode& b)
{return a.width!=b.width ? a.width>b.width :
a.height!=b.height ? a.height>b.height :
Expand All @@ -179,9 +179,9 @@ void AVForm::updateVideoModes(int curIndex)
std::map<int, int> bestModeInds;

qDebug("available Modes:");
for (int i=0; i<videoModes.size(); ++i)
for (int i=0; i<allVideoModes.size(); ++i)
{
VideoMode mode = videoModes[i];
VideoMode mode = allVideoModes[i];
qDebug("width: %d, height: %d, FPS: %f, pixel format: %s", mode.width, mode.height, mode.FPS, CameraDevice::getPixelFormatString(mode.pixel_format).toStdString().c_str());

// PS3-Cam protection, everything above 60fps makes no sense
Expand All @@ -203,19 +203,19 @@ void AVForm::updateVideoModes(int curIndex)
continue;
}
int ind = bestModeInds[res];
if (mode.norm(idealMode) < videoModes[ind].norm(idealMode))
if (mode.norm(idealMode) < allVideoModes[ind].norm(idealMode))
{
bestModeInds[res] = i;
}
else if (mode.norm(idealMode) == videoModes[ind].norm(idealMode))
else if (mode.norm(idealMode) == allVideoModes[ind].norm(idealMode))
{
// prefer higher FPS and "better" pixel formats
if (mode.FPS > videoModes[ind].FPS)
if (mode.FPS > allVideoModes[ind].FPS)
{
bestModeInds[res] = i;
}
else if (mode.FPS == videoModes[ind].FPS &&
CameraDevice::betterPixelFormat(mode.pixel_format, videoModes[ind].pixel_format))
else if (mode.FPS == allVideoModes[ind].FPS &&
CameraDevice::betterPixelFormat(mode.pixel_format, allVideoModes[ind].pixel_format))
{
bestModeInds[res] = i;
}
Expand All @@ -227,12 +227,14 @@ void AVForm::updateVideoModes(int curIndex)
QSize prefRes = Settings::getInstance().getCamVideoRes();
unsigned short prefFPS = Settings::getInstance().getCamVideoFPS();
// Iterate backwards to show higest resolution first.
videoModes.clear();
for(auto iter = bestModeInds.rbegin(); iter != bestModeInds.rend(); ++iter)
{
int i = iter->second;
VideoMode mode = videoModes[i];
VideoMode mode = allVideoModes[i];
videoModes.push_back(mode);
if (mode.width==prefRes.width() && mode.height==prefRes.height() && mode.FPS == prefFPS && prefResIndex==-1)
prefResIndex = i;
prefResIndex = videoModes.size() - 1;
QString str;
qDebug("width: %d, height: %d, FPS: %f, pixel format: %s\n", mode.width, mode.height, mode.FPS, CameraDevice::getPixelFormatString(mode.pixel_format).toStdString().c_str());
if (mode.height && mode.width)
Expand Down

0 comments on commit 872941c

Please sign in to comment.