Skip to content
Snippets Groups Projects
Commit 46dc2da7 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6179 : Move code from video_v4l2.h to video_v4l2.cpp

parent ccdd3eba
No related branches found
No related tags found
No related merge requests found
...@@ -124,6 +124,44 @@ static unsigned int pixelformat_score(unsigned pixelformat) ...@@ -124,6 +124,44 @@ static unsigned int pixelformat_score(unsigned pixelformat)
return UINT_MAX - 1; 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) void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format)
{ {
struct v4l2_frmivalenum frmival = { struct v4l2_frmivalenum frmival = {
...@@ -162,6 +200,58 @@ void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format) ...@@ -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) unsigned int VideoV4l2Channel::GetSizes(int fd, unsigned int pixelformat)
{ {
struct v4l2_frmsizeenum frmsize; struct v4l2_frmsizeenum frmsize;
...@@ -271,4 +361,34 @@ VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device) : _currentCh ...@@ -271,4 +361,34 @@ VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device) : _currentCh
this->device = device; 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 } // end namespace sfl
...@@ -55,47 +55,22 @@ class VideoV4l2Rate { ...@@ -55,47 +55,22 @@ class VideoV4l2Rate {
class VideoV4l2Size { class VideoV4l2Size {
public: public:
VideoV4l2Size(unsigned height, unsigned width) : height(height), width(width), _currentRate(0) {} VideoV4l2Size(unsigned height, unsigned width);
/** /**
* @throw std::runtime_error * @throw std::runtime_error
*/ */
void GetFrameRates(int fd, unsigned int pixel_format); 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 height;
unsigned width; 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: private:
std::vector<VideoV4l2Rate> rates; std::vector<VideoV4l2Rate> rates;
unsigned _currentRate; unsigned _currentRate;
...@@ -103,7 +78,7 @@ class VideoV4l2Size { ...@@ -103,7 +78,7 @@ class VideoV4l2Size {
class VideoV4l2Channel { class VideoV4l2Channel {
public: public:
VideoV4l2Channel(unsigned idx, const char *s) : idx(idx), name(s), _currentSize(0) { } VideoV4l2Channel(unsigned idx, const char *s);
/** /**
* @throw std::runtime_error * @throw std::runtime_error
...@@ -114,47 +89,18 @@ class VideoV4l2Channel { ...@@ -114,47 +89,18 @@ class VideoV4l2Channel {
*/ */
unsigned int GetSizes(int fd, unsigned int pixel_format); unsigned int GetSizes(int fd, unsigned int pixel_format);
void SetFourcc(unsigned code) { void SetFourcc(unsigned code);
fourcc[0] = code; const char * GetFourcc();
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;
}
std::vector<std::string> getSizeList(void) {
std::vector<std::string> v;
size_t n = sizes.size(); void setSize(unsigned index);
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;
}
std::vector<std::string> getSizeList(void);
unsigned getSizeIndex();
unsigned getSizeIndex() { VideoV4l2Size &getSize();
return _currentSize;
}
VideoV4l2Size &getSize() { unsigned idx;
return sizes[_currentSize]; std::string name;
}
private: private:
std::vector<VideoV4l2Size> sizes; std::vector<VideoV4l2Size> sizes;
...@@ -172,30 +118,10 @@ class VideoV4l2Device { ...@@ -172,30 +118,10 @@ class VideoV4l2Device {
std::string device; std::string device;
std::string name; std::string name;
std::vector<std::string> getChannelList(void) { std::vector<std::string> getChannelList(void);
std::vector<std::string> v; void setChannel(unsigned index);
unsigned getChannelIndex();
size_t n = channels.size(); VideoV4l2Channel &getChannel();
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];
}
private: private:
std::vector<VideoV4l2Channel> channels; std::vector<VideoV4l2Channel> channels;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment