1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(avform): Separeted search of preferred index in function

This commit is contained in:
Diadlo 2016-06-13 23:22:36 +03:00
parent 3f82396173
commit 33729dcf4a
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 25 additions and 23 deletions

View File

@ -226,25 +226,15 @@ void AVForm::selectBestModes(QVector<VideoMode> &allVideoModes)
allVideoModes = newVideoModes;
}
int AVForm::fillModesComboBox()
void AVForm::fillModesComboBox()
{
bool previouslyBlocked = bodyUI->videoModescomboBox->blockSignals(true);
bodyUI->videoModescomboBox->clear();
int prefResIndex = -1;
QSize prefRes = Settings::getInstance().getCamVideoRes();
unsigned short prefFPS = Settings::getInstance().getCamVideoFPS();
for(int i = 0; i < videoModes.size(); i++)
{
VideoMode mode = videoModes[i];
if (mode.width == prefRes.width()
&& mode.height == prefRes.height()
&& mode.FPS == prefFPS
&& prefResIndex == -1)
prefResIndex = i;
QString str;
QString pixelFormat = CameraDevice::getPixelFormatString(mode.pixel_format);
qDebug("width: %d, height: %d, FPS: %f, pixel format: %s\n", mode.width, mode.height, mode.FPS, pixelFormat.toStdString().c_str());
@ -261,7 +251,23 @@ int AVForm::fillModesComboBox()
bodyUI->videoModescomboBox->addItem(tr("Default resolution"));
bodyUI->videoModescomboBox->blockSignals(previouslyBlocked);
return prefResIndex;
}
int AVForm::searchPreferredIndex()
{
QSize prefRes = Settings::getInstance().getCamVideoRes();
unsigned short prefFPS = Settings::getInstance().getCamVideoFPS();
for (int i = 0; i < videoModes.size(); i++)
{
VideoMode mode = videoModes[i];
if (mode.width == prefRes.width()
&& mode.height == prefRes.height()
&& mode.FPS == prefFPS)
return i;
}
return -1;
}
void AVForm::updateVideoModes(int curIndex)
@ -279,17 +285,12 @@ void AVForm::updateVideoModes(int curIndex)
videoModes = allVideoModes;
qDebug("selected Modes:");
int prefResIndex = fillModesComboBox();
if (prefResIndex != -1)
{
bodyUI->videoModescomboBox->setCurrentIndex(prefResIndex);
return;
}
fillModesComboBox();
if (videoModes.size() == 0)
int preferedIndex = searchPreferredIndex();
if (preferedIndex!= -1)
{
// We don't have any video modes, open it with the default mode
camera.open(devName);
bodyUI->videoModescomboBox->setCurrentIndex(preferedIndex);
return;
}
@ -300,7 +301,7 @@ void AVForm::updateVideoModes(int curIndex)
// but if we picked the largest, FPS would be bad and thus quality bad too.
int numRes=0;
QSize lastSize;
for (int i=0; i<videoModes.size(); i++)
for (int i = 0; i<videoModes.size(); i++)
{
if (lastSize != QSize{videoModes[i].width, videoModes[i].height})
{

View File

@ -47,7 +47,8 @@ private:
void getVideoDevices();
void selectBestModes(QVector<VideoMode> &allVideoModes);
int fillModesComboBox();
void fillModesComboBox();
int searchPreferredIndex();
void createVideoSurface();
void killVideoSurface();