From 7fc90e4439e5ddec308f258fe01119b81396b6b6 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Mon, 6 Aug 2012 15:59:23 -0400 Subject: [PATCH] * #14402: video: put CIF first in list of resolutions --- daemon/src/video/video_v4l2.cpp | 20 ++++++++++++++++++++ daemon/src/video/video_v4l2.h | 1 + 2 files changed, 21 insertions(+) diff --git a/daemon/src/video/video_v4l2.cpp b/daemon/src/video/video_v4l2.cpp index dab26b618e..4777182764 100644 --- a/daemon/src/video/video_v4l2.cpp +++ b/daemon/src/video/video_v4l2.cpp @@ -30,6 +30,7 @@ #include <string> #include <cstring> // for memset +#include <algorithm> #include <vector> #include <climits> #include <stdexcept> @@ -256,6 +257,24 @@ VideoV4l2Channel::getSizes(int fd, unsigned int pixelformat) return fmt.fmt.pix.pixelformat; } +namespace { + bool isCIF(const VideoV4l2Size &size) + { + const unsigned CIF_WIDTH = 352; + const unsigned CIF_HEIGHT = 288; + return size.width == CIF_WIDTH and size.height == CIF_HEIGHT; + } +} + +// Put CIF resolution (352x288) first in the list since it is more prevalent in +// VoIP +void VideoV4l2Channel::putCIFFirst() +{ + std::vector<VideoV4l2Size>::iterator iter = std::find_if(sizes_.begin(), sizes_.end(), isCIF); + if (iter != sizes_.end() and iter != sizes_.begin()) + std::swap(*iter, *sizes_.begin()); +} + void VideoV4l2Channel::getFormat(int fd) { if (ioctl(fd, VIDIOC_S_INPUT, &idx)) @@ -288,6 +307,7 @@ void VideoV4l2Channel::getFormat(int fd) fmt.index = best_idx; pixelformat = getSizes(fd, pixelformat); + putCIFFirst(); setFourcc(pixelformat); } diff --git a/daemon/src/video/video_v4l2.h b/daemon/src/video/video_v4l2.h index df24e08ff3..7d51f3a7db 100644 --- a/daemon/src/video/video_v4l2.h +++ b/daemon/src/video/video_v4l2.h @@ -84,6 +84,7 @@ class VideoV4l2Channel { std::string name; private: + void putCIFFirst(); std::vector<VideoV4l2Size> sizes_; char fourcc_[5]; }; -- GitLab