diff --git a/daemon/src/video/video_v4l2.cpp b/daemon/src/video/video_v4l2.cpp index dab26b618eabf292d8b3b576c4faff92ab6ad11e..47771827648e937cdabc67937eec1ada6fcecba0 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 df24e08ff3af917091f10db62a9535be059f7580..7d51f3a7db8ba3016b0cec4b626815e45eecb158 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]; };