From 46dc2da71748e2f4da823f3a5319a6b7dd127498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= <rafael.carre@savoirfairelinux.com> Date: Wed, 29 Jun 2011 11:34:04 -0400 Subject: [PATCH] * #6179 : Move code from video_v4l2.h to video_v4l2.cpp --- sflphone-common/src/video/video_v4l2.cpp | 120 +++++++++++++++++++++++ sflphone-common/src/video/video_v4l2.h | 110 ++++----------------- 2 files changed, 138 insertions(+), 92 deletions(-) diff --git a/sflphone-common/src/video/video_v4l2.cpp b/sflphone-common/src/video/video_v4l2.cpp index 3dc215e8b7..29ac3b60f3 100644 --- a/sflphone-common/src/video/video_v4l2.cpp +++ b/sflphone-common/src/video/video_v4l2.cpp @@ -124,6 +124,44 @@ static unsigned int pixelformat_score(unsigned pixelformat) return UINT_MAX - 1; } +VideoV4l2Size::VideoV4l2Size(unsigned height, unsigned width) : height(height), width(width), _currentRate(0) {} + +std::vector<std::string> VideoV4l2Size::getRateList() +{ + std::vector<std::string> v; + std::stringstream ss; + + size_t n = rates.size(); + unsigned i; + for (i = 0 ; i < n ; i++) { + VideoV4l2Rate rate = rates[i]; + std::stringstream ss; + ss << (float)rate.den / rate.num; + v.push_back(ss.str()); + } + + return v; +} + +void VideoV4l2Size::setRate(unsigned index) +{ + if (index >= rates.size()) + index = rates.size() - 1; + _currentRate = index; +} + +unsigned VideoV4l2Size::getRateIndex() +{ + return _currentRate; +} + +VideoV4l2Rate &VideoV4l2Size::getRate() +{ + return rates[_currentRate]; +} + + + void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format) { struct v4l2_frmivalenum frmival = { @@ -162,6 +200,58 @@ void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format) } } +VideoV4l2Channel::VideoV4l2Channel(unsigned idx, const char *s) : idx(idx), name(s), _currentSize(0) { } + +void VideoV4l2Channel::SetFourcc(unsigned code) +{ + fourcc[0] = code; + fourcc[1] = code >> 8; + fourcc[2] = code >> 16; + fourcc[3] = code >> 24; + fourcc[4] = '\0'; +} + +const char * VideoV4l2Channel::GetFourcc() +{ + return fourcc; +} + +void VideoV4l2Channel::setSize(unsigned index) +{ + if (index >= sizes.size()) + index = sizes.size() - 1; + _currentSize = index; +} + +std::vector<std::string> VideoV4l2Channel::getSizeList(void) +{ + std::vector<std::string> v; + + size_t n = sizes.size(); + unsigned i; + for (i = 0 ; i < n ; i++) { + VideoV4l2Size &size = sizes[i]; + std::stringstream ss; + ss << size.width << "x" << size.height; + v.push_back(ss.str()); + } + + return v; +} + + +unsigned VideoV4l2Channel::getSizeIndex() +{ + return _currentSize; +} + +VideoV4l2Size &VideoV4l2Channel::getSize() +{ + return sizes[_currentSize]; +} + + + unsigned int VideoV4l2Channel::GetSizes(int fd, unsigned int pixelformat) { struct v4l2_frmsizeenum frmsize; @@ -271,4 +361,34 @@ VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device) : _currentCh this->device = device; } +std::vector<std::string> VideoV4l2Device::getChannelList(void) +{ + std::vector<std::string> v; + + size_t n = channels.size(); + unsigned i; + for (i = 0 ; i < n ; i++) + v.push_back(channels[i].name); + + return v; +} + +void VideoV4l2Device::setChannel(unsigned index) +{ + if (index >= channels.size()) + index = channels.size() - 1; + _currentChannel = index; +} + +unsigned VideoV4l2Device::getChannelIndex() +{ + return _currentChannel; +} + +VideoV4l2Channel &VideoV4l2Device::getChannel() +{ + return channels[_currentChannel]; +} + + } // end namespace sfl diff --git a/sflphone-common/src/video/video_v4l2.h b/sflphone-common/src/video/video_v4l2.h index 62cb1810a1..647316fda9 100644 --- a/sflphone-common/src/video/video_v4l2.h +++ b/sflphone-common/src/video/video_v4l2.h @@ -55,47 +55,22 @@ class VideoV4l2Rate { class VideoV4l2Size { public: - VideoV4l2Size(unsigned height, unsigned width) : height(height), width(width), _currentRate(0) {} + VideoV4l2Size(unsigned height, unsigned width); /** * @throw std::runtime_error */ void GetFrameRates(int fd, unsigned int pixel_format); + std::vector<std::string> getRateList(); - std::vector<std::string> getRateList() { - std::vector<std::string> v; - std::stringstream ss; - - size_t n = rates.size(); - unsigned i; - for (i = 0 ; i < n ; i++) { - VideoV4l2Rate rate = rates[i]; - std::stringstream ss; - ss << (float)rate.den / rate.num; - v.push_back(ss.str()); - } - - return v; - } + void setRate(unsigned index); + unsigned getRateIndex(); + VideoV4l2Rate &getRate(); unsigned height; unsigned width; - void setRate(unsigned index) { - if (index >= rates.size()) - index = rates.size() - 1; - _currentRate = index; - } - - unsigned getRateIndex() { - return _currentRate; - } - - VideoV4l2Rate &getRate() { - return rates[_currentRate]; - } - private: std::vector<VideoV4l2Rate> rates; unsigned _currentRate; @@ -103,7 +78,7 @@ class VideoV4l2Size { class VideoV4l2Channel { public: - VideoV4l2Channel(unsigned idx, const char *s) : idx(idx), name(s), _currentSize(0) { } + VideoV4l2Channel(unsigned idx, const char *s); /** * @throw std::runtime_error @@ -114,47 +89,18 @@ class VideoV4l2Channel { */ unsigned int GetSizes(int fd, unsigned int pixel_format); - void SetFourcc(unsigned code) { - fourcc[0] = code; - fourcc[1] = code >> 8; - fourcc[2] = code >> 16; - fourcc[3] = code >> 24; - fourcc[4] = '\0'; - } - - const char * GetFourcc() { return fourcc; } - unsigned idx; - std::string name; - - void setSize(unsigned index) { - if (index >= sizes.size()) - index = sizes.size() - 1; - _currentSize = index; - } + void SetFourcc(unsigned code); + const char * GetFourcc(); - std::vector<std::string> getSizeList(void) { - std::vector<std::string> v; + void setSize(unsigned index); - size_t n = sizes.size(); - unsigned i; - for (i = 0 ; i < n ; i++) { - VideoV4l2Size &size = sizes[i]; - std::stringstream ss; - ss << size.width << "x" << size.height; - v.push_back(ss.str()); - } + std::vector<std::string> getSizeList(void); + unsigned getSizeIndex(); - return v; - } + VideoV4l2Size &getSize(); - - unsigned getSizeIndex() { - return _currentSize; - } - - VideoV4l2Size &getSize() { - return sizes[_currentSize]; - } + unsigned idx; + std::string name; private: std::vector<VideoV4l2Size> sizes; @@ -172,30 +118,10 @@ class VideoV4l2Device { std::string device; std::string name; - std::vector<std::string> getChannelList(void) { - std::vector<std::string> v; - - size_t n = channels.size(); - unsigned i; - for (i = 0 ; i < n ; i++) - v.push_back(channels[i].name); - - return v; - } - - void setChannel(unsigned index) { - if (index >= channels.size()) - index = channels.size() - 1; - _currentChannel = index; - } - - unsigned getChannelIndex() { - return _currentChannel; - } - - VideoV4l2Channel &getChannel() { - return channels[_currentChannel]; - } + std::vector<std::string> getChannelList(void); + void setChannel(unsigned index); + unsigned getChannelIndex(); + VideoV4l2Channel &getChannel(); private: std::vector<VideoV4l2Channel> channels; -- GitLab