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

fix(video): use float framerates also for V4L2

also make -1 the default value for the framerate
This commit is contained in:
sudden6 2017-12-21 23:35:39 +01:00
parent db7ee65d0e
commit a2927de27d
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
5 changed files with 16 additions and 16 deletions

View File

@ -91,17 +91,17 @@ fail:
return -1; return -1;
} }
static QVector<unsigned short> getDeviceModeFramerates(int fd, unsigned w, unsigned h, static QVector<float> getDeviceModeFramerates(int fd, unsigned w, unsigned h,
uint32_t pixelFormat) uint32_t pixelFormat)
{ {
QVector<unsigned short> rates; QVector<float> rates;
v4l2_frmivalenum vfve{}; v4l2_frmivalenum vfve{};
vfve.pixel_format = pixelFormat; vfve.pixel_format = pixelFormat;
vfve.height = h; vfve.height = h;
vfve.width = w; vfve.width = w;
while (!ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &vfve)) { while (!ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &vfve)) {
int rate; float rate;
switch (vfve.type) { switch (vfve.type) {
case V4L2_FRMSIZE_TYPE_DISCRETE: case V4L2_FRMSIZE_TYPE_DISCRETE:
rate = vfve.discrete.denominator / vfve.discrete.numerator; rate = vfve.discrete.denominator / vfve.discrete.numerator;
@ -154,9 +154,9 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
continue; continue;
} }
QVector<unsigned short> rates = QVector<float> rates =
getDeviceModeFramerates(fd, mode.width, mode.height, vfd.pixelformat); getDeviceModeFramerates(fd, mode.width, mode.height, vfd.pixelformat);
for (unsigned short rate : rates) { for (float rate : rates) {
mode.FPS = rate; mode.FPS = rate;
if (!modes.contains(mode)) if (!modes.contains(mode))
modes.append(std::move(mode)); modes.append(std::move(mode));

View File

@ -284,8 +284,9 @@ void CameraSource::openDevice()
// We need to open the device as many time as we already have subscribers, // We need to open the device as many time as we already have subscribers,
// otherwise the device could get closed while we still have subscribers // otherwise the device could get closed while we still have subscribers
for (int i = 0; i < subscriptions; ++i) for (int i = 0; i < subscriptions; ++i) {
device->open(); device->open();
}
// Find the first video stream, if any // Find the first video stream, if any
for (unsigned i = 0; i < device->context->nb_streams; ++i) { for (unsigned i = 0; i < device->context->nb_streams; ++i) {

View File

@ -31,15 +31,15 @@
* *
* @var float VideoMode::FPS * @var float VideoMode::FPS
* @brief Frames per second supported by the device at this resolution * @brief Frames per second supported by the device at this resolution
* @note a value < 0 indicates an invalid value
*/ */
VideoMode::VideoMode(int width, int height, int x, int y, float FPS, int format) VideoMode::VideoMode(int width, int height, int x, int y, float FPS)
: width(width) : width(width)
, height(height) , height(height)
, x(x) , x(x)
, y(y) , y(y)
, FPS(FPS) , FPS(FPS)
, pixel_format(format)
{ {
} }
@ -48,8 +48,6 @@ VideoMode::VideoMode(QRect rect)
, height(rect.height()) , height(rect.height())
, x(rect.x()) , x(rect.x())
, y(rect.y()) , y(rect.y())
, FPS(0)
, pixel_format(0)
{ {
} }
@ -74,5 +72,5 @@ uint32_t VideoMode::norm(const VideoMode& other) const
*/ */
VideoMode::operator bool() const VideoMode::operator bool() const
{ {
return width || height || FPS; return width || height || (FPS < 0);
} }

View File

@ -27,10 +27,10 @@ struct VideoMode
{ {
int width, height; int width, height;
int x, y; int x, y;
float FPS; float FPS = -1.0f;
uint32_t pixel_format; uint32_t pixel_format = 0;
VideoMode(int width = 0, int height = 0, int x = 0, int y = 0, float FPS = 0.0f, int format = 0); VideoMode(int width = 0, int height = 0, int x = 0, int y = 0, float FPS = -1.0f);
explicit VideoMode(QRect rect); explicit VideoMode(QRect rect);

View File

@ -319,13 +319,14 @@ void AVForm::fillCameraModesComboBox()
int AVForm::searchPreferredIndex() int AVForm::searchPreferredIndex()
{ {
QRect prefRes = videoSettings->getCamVideoRes(); QRect prefRes = videoSettings->getCamVideoRes();
quint16 prefFPS = videoSettings->getCamVideoFPS(); float prefFPS = videoSettings->getCamVideoFPS();
for (int i = 0; i < videoModes.size(); ++i) { for (int i = 0; i < videoModes.size(); ++i) {
VideoMode mode = videoModes[i]; VideoMode mode = videoModes[i];
if (mode.width == prefRes.width() && mode.height == prefRes.height() if (mode.width == prefRes.width() && mode.height == prefRes.height()
&& static_cast<quint16>(mode.FPS) == prefFPS) && (qAbs(mode.FPS - prefFPS) < 0.0001f)) {
return i; return i;
}
} }
return -1; return -1;