Commit f5a841d8 authored by Tristan Matthews's avatar Tristan Matthews

* #7845: fixed more Weffc++ warnings

parent 42ad4b61
......@@ -46,7 +46,7 @@ const char* ConfigurationManager::SERVER_PATH =
"/org/sflphone/SFLphone/ConfigurationManager";
ConfigurationManager::ConfigurationManager(DBus::Connection& connection) :
DBus::ObjectAdaptor(connection, SERVER_PATH)
DBus::ObjectAdaptor(connection, SERVER_PATH), preview_()
{}
std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails()
......
......@@ -63,7 +63,6 @@ class ConfigurationManager
public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor {
private:
std::vector<std::string> shortcutsKeys;
// FIXME: this probably shouldn't live here
std::tr1::shared_ptr<sfl_video::VideoPreview> preview_;
......
......@@ -71,7 +71,7 @@
ManagerImpl::ManagerImpl() :
preferences(), voipPreferences(), addressbookPreference(),
hookPreference(), audioPreference(), shortcutPreferences(),
hookPreference(), audioPreference(), videoPreference(), shortcutPreferences(),
hasTriedToRegister_(false), audioCodecFactory(), dbus_(), config_(), currentCallId_(),
currentCallMutex_(), audiodriver_(0), dtmfKey_(0), toneMutex_(),
telephoneTone_(0), audiofile_(0), speakerVolume_(0), micVolume_(0),
......
......@@ -409,9 +409,9 @@ void AudioPreference::unserialize(Conf::MappingNode *map)
}
VideoPreference::VideoPreference() :
device_(), channel_(), size_(), rate_()
v4l2_list_(0), device_(), channel_(), size_(), rate_()
{
v4l2_list_ = new VideoV4l2List();
v4l2_list_ = new VideoV4l2ListThread();
v4l2_list_->start();
}
......
......@@ -636,9 +636,10 @@ class VideoPreference : public Serializable
private:
NON_COPYABLE(VideoPreference);
// V4L2 devices
sfl_video::VideoV4l2List *v4l2_list_;
sfl_video::VideoV4l2ListThread *v4l2_list_;
std::string device_;
std::string channel_;
......
......@@ -35,7 +35,9 @@
namespace sfl_video {
VideoPreview::VideoPreview(const std::map<std::string, std::string> &args) : args_(args) {}
VideoPreview::VideoPreview(const std::map<std::string, std::string> &args) :
receiveThread_(), args_(args), shmKey_(0), semKey_(0), videoBufferSize_(0)
{}
bool VideoPreview::start()
{
......
......@@ -56,7 +56,6 @@ class VideoPreview {
int semKey_;
int videoBufferSize_;
};
}
#endif // __VIDEO_PREVIEW_H__
......@@ -379,11 +379,14 @@ void VideoReceiveThread::createScalingContext()
}
VideoReceiveThread::VideoReceiveThread(const std::map<std::string, std::string> &args) : args_(args),
test_source_(args_["input"] == "SFLTEST"),
frameNumber_(0),
shmBuffer_(0),
shmID_(-1),
semSetID_(-1),
shmKey_(-1),
semKey_(-1),
videoBufferSize_(0),
decoderCtx_(0),
rawFrame_(0),
scaledPicture_(0),
......@@ -391,9 +394,10 @@ VideoReceiveThread::VideoReceiveThread(const std::map<std::string, std::string>
inputCtx_(0),
imgConvertCtx_(0),
dstWidth_(-1),
dstHeight_(-1)
dstHeight_(-1),
shmReady_(),
sdpFilename_()
{
test_source_ = (args_["input"] == "SFLTEST");
setCancel(cancelDeferred);
}
......
......@@ -34,7 +34,8 @@
#include <cc++/thread.h>
#include <map>
#include <string>
#include <limits.h>
#include <climits>
#include "noncopyable.h"
class SwsContext;
class AVCodecContext;
......@@ -45,9 +46,10 @@ class AVFrame;
namespace sfl_video {
class VideoReceiveThread : public ost::Thread {
private:
NON_COPYABLE(VideoReceiveThread);
std::map<std::string, std::string> args_;
bool test_source_;
unsigned frameNumber_;
std::map<std::string, std::string> args_;
/*-------------------------------------------------------------*/
/* These variables should be used in thread (i.e. run()) only! */
......@@ -84,9 +86,9 @@ class VideoReceiveThread : public ost::Thread {
virtual void run();
void waitForShm();
int getShmKey() { return shmKey_; }
int getSemKey() { return semKey_; }
int getVideoBufferSize(void) { return videoBufferSize_; }
int getShmKey() const { return shmKey_; }
int getSemKey() const { return semKey_; }
int getVideoBufferSize() const { return videoBufferSize_; }
};
}
......
......@@ -44,7 +44,8 @@
namespace sfl_video {
VideoRtpSession::VideoRtpSession() : sending_(true), receiving_(true)
VideoRtpSession::VideoRtpSession() : sendThread_(), receiveThread_(),
txArgs_(), rxArgs_(), sending_(true), receiving_(true)
{
txArgs_ = Manager::instance().videoPreference.getVideoSettings();
txArgs_["bitrate"] = "500000";
......@@ -52,7 +53,8 @@ VideoRtpSession::VideoRtpSession() : sending_(true), receiving_(true)
VideoRtpSession::VideoRtpSession(const std::map<std::string, std::string> &txArgs,
const std::map<std::string, std::string> &rxArgs) :
txArgs_(txArgs), rxArgs_(rxArgs), sending_(true), receiving_(true)
sendThread_(), receiveThread_(), txArgs_(txArgs), rxArgs_(rxArgs),
sending_(true), receiving_(true)
{}
void VideoRtpSession::updateSDP(const Sdp &sdp)
......
......@@ -303,6 +303,8 @@ void VideoSendThread::createScalingContext()
}
VideoSendThread::VideoSendThread(const std::map<std::string, std::string> &args) :
test_source_(false),
sdpReady_(),
args_(args),
scaledPictureBuf_(0),
outbuf_(0),
......@@ -316,7 +318,7 @@ VideoSendThread::VideoSendThread(const std::map<std::string, std::string> &args)
inputCtx_(0),
outputCtx_(0),
imgConvertCtx_(0),
sdp_("")
sdp_()
{
test_source_ = (args_["input"] == "SFLTEST");
setCancel(cancelDeferred);
......
......@@ -34,6 +34,7 @@
#include <cc++/thread.h>
#include <map>
#include <string>
#include "noncopyable.h"
class SwsContext;
class AVCodecContext;
......@@ -46,12 +47,13 @@ namespace sfl_video {
class VideoSendThread : public ost::Thread {
private:
bool test_source_;
NON_COPYABLE(VideoSendThread);
void forcePresetX264();
void print_and_save_sdp();
void setup();
void prepareEncoderContext(AVCodec *encoder);
void createScalingContext();
bool test_source_;
ost::Event sdpReady_;
std::map<std::string, std::string> args_;
......
......@@ -125,18 +125,19 @@ static unsigned int pixelformat_score(unsigned pixelformat)
return UINT_MAX - 1;
}
VideoV4l2Size::VideoV4l2Size(unsigned height, unsigned width) : height(height), width(width) {}
VideoV4l2Size::VideoV4l2Size(unsigned height, unsigned width) :
height(height), width(width), rates_() {}
std::vector<std::string> VideoV4l2Size::getRateList()
{
std::vector<std::string> v;
std::stringstream ss;
size_t n = rates.size();
size_t n = rates_.size();
unsigned i;
for (i = 0 ; i < n ; i++) {
std::stringstream ss;
ss << rates[i];
ss << rates_[i];
v.push_back(ss.str());
}
......@@ -144,10 +145,10 @@ std::vector<std::string> VideoV4l2Size::getRateList()
}
void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format)
void VideoV4l2Size::getFrameRates(int fd, unsigned int pixel_format)
{
if (fd == -1) { // SFL_TEST
rates.push_back(30);
rates_.push_back(30);
return;
}
......@@ -158,7 +159,7 @@ void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format)
frmival.height = height;
if (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival)) {
rates.push_back(25);
rates_.push_back(25);
ERROR("could not query frame interval for size");
return;
}
......@@ -166,47 +167,47 @@ void VideoV4l2Size::GetFrameRates(int fd, unsigned int pixel_format)
switch(frmival.type) {
case V4L2_FRMIVAL_TYPE_DISCRETE:
do {
rates.push_back(frmival.discrete.denominator/frmival.discrete.numerator);
rates_.push_back(frmival.discrete.denominator/frmival.discrete.numerator);
frmival.index++;
} while (!ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival));
break;
case V4L2_FRMIVAL_TYPE_CONTINUOUS:
rates.push_back(25);
rates_.push_back(25);
// TODO
ERROR("Continuous Frame Intervals not supported");
break;
case V4L2_FRMIVAL_TYPE_STEPWISE:
rates.push_back(25);
rates_.push_back(25);
// TODO
ERROR("Stepwise Frame Intervals not supported");
break;
}
}
VideoV4l2Channel::VideoV4l2Channel(unsigned idx, const char *s) : idx(idx), name(s) { }
VideoV4l2Channel::VideoV4l2Channel(unsigned idx, const char *s) : idx(idx),
name(s), sizes_() {}
void VideoV4l2Channel::SetFourcc(unsigned code)
void VideoV4l2Channel::setFourcc(unsigned code)
{
fourcc[0] = code;
fourcc[1] = code >> 8;
fourcc[2] = code >> 16;
fourcc[3] = code >> 24;
fourcc[4] = '\0';
fourcc_[0] = code;
fourcc_[1] = code >> 8;
fourcc_[2] = code >> 16;
fourcc_[3] = code >> 24;
fourcc_[4] = '\0';
}
const char * VideoV4l2Channel::GetFourcc()
const char * VideoV4l2Channel::getFourcc()
{
return fourcc;
return fourcc_;
}
std::vector<std::string> VideoV4l2Channel::getSizeList(void)
std::vector<std::string> VideoV4l2Channel::getSizeList()
{
std::vector<std::string> v;
size_t n = sizes.size();
unsigned i;
for (i = 0 ; i < n ; i++) {
VideoV4l2Size &size = sizes[i];
size_t n = sizes_.size();
for (size_t i = 0 ; i < n ; ++i) {
VideoV4l2Size &size = sizes_[i];
std::stringstream ss;
ss << size.width << "x" << size.height;
v.push_back(ss.str());
......@@ -217,12 +218,12 @@ std::vector<std::string> VideoV4l2Channel::getSizeList(void)
unsigned int VideoV4l2Channel::GetSizes(int fd, unsigned int pixelformat)
unsigned int VideoV4l2Channel::getSizes(int fd, unsigned int pixelformat)
{
if (fd == -1) { //SFL_TEST
VideoV4l2Size s(288, 352);
s.GetFrameRates(-1, 0);
sizes.push_back(s);
s.getFrameRates(-1, 0);
sizes_.push_back(s);
return 0;
}
......@@ -237,9 +238,9 @@ unsigned int VideoV4l2Channel::GetSizes(int fd, unsigned int pixelformat)
case V4L2_FRMSIZE_TYPE_DISCRETE:
do {
VideoV4l2Size size(frmsize.discrete.height, frmsize.discrete.width);
size.GetFrameRates(fd, frmsize.pixel_format);
sizes.push_back(size);
frmsize.index++;
size.getFrameRates(fd, frmsize.pixel_format);
sizes_.push_back(size);
++frmsize.index;
} while (!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize));
return pixelformat;
......@@ -263,13 +264,13 @@ fallback:
throw std::runtime_error("Couldnt get format");
VideoV4l2Size size(fmt.fmt.pix.height, fmt.fmt.pix.width);
size.GetFrameRates(fd, fmt.fmt.pix.pixelformat);
sizes.push_back(size);
size.getFrameRates(fd, fmt.fmt.pix.pixelformat);
sizes_.push_back(size);
return fmt.fmt.pix.pixelformat;
}
void VideoV4l2Channel::GetFormat(int fd)
void VideoV4l2Channel::getFormat(int fd)
{
if (ioctl(fd, VIDIOC_S_INPUT, &idx))
throw std::runtime_error("VIDIOC_S_INPUT failed");
......@@ -300,38 +301,34 @@ void VideoV4l2Channel::GetFormat(int fd)
throw std::runtime_error("Could not enumerate formats");
fmt.index = best_idx;
pixelformat = GetSizes(fd, pixelformat);
pixelformat = getSizes(fd, pixelformat);
SetFourcc(pixelformat);
setFourcc(pixelformat);
}
VideoV4l2Size VideoV4l2Channel::getSize(const std::string &name)
{
for (size_t i = 0; i < sizes.size(); i++) {
for (size_t i = 0; i < sizes_.size(); ++i) {
std::stringstream ss;
ss << sizes[i].width << "x" << sizes[i].height;
ss << sizes_[i].width << "x" << sizes_[i].height;
if (ss.str() == name)
return sizes[i];
return sizes_[i];
}
return sizes.back();
return sizes_.back();
}
VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device)
VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device) :
device(device), name("TEST"), channels()
{
if (fd == -1) {
VideoV4l2Channel c(0, "#^&");
c.GetSizes(-1, 0);
c.getSizes(-1, 0);
channels.push_back(c);
name = "TEST";
this->device = device;
return;
}
unsigned idx;
v4l2_capability cap;
if (ioctl(fd, VIDIOC_QUERYCAP, &cap))
throw std::runtime_error("could not query capabilities");
......@@ -343,6 +340,7 @@ VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device)
v4l2_input input;
memset(&input, 0x0, sizeof input);
unsigned idx;
input.index = idx = 0;
while (!ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
if (idx != input.index)
......@@ -350,23 +348,20 @@ VideoV4l2Device::VideoV4l2Device(int fd, const std::string &device)
if (input.type & V4L2_INPUT_TYPE_CAMERA) {
VideoV4l2Channel channel(idx, (const char*)input.name);
channel.GetFormat(fd);
channel.getFormat(fd);
channels.push_back(channel);
}
input.index = ++idx;
}
this->device = device;
}
std::vector<std::string> VideoV4l2Device::getChannelList(void)
std::vector<std::string> VideoV4l2Device::getChannelList() const
{
std::vector<std::string> v;
size_t n = channels.size();
unsigned i;
for (i = 0 ; i < n ; i++)
for (size_t i = 0 ; i < n ; i++)
v.push_back(channels[i].name);
return v;
......
......@@ -52,14 +52,14 @@ class VideoV4l2Size {
/**
* @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();
unsigned height;
unsigned width;
private:
std::vector<float> rates;
std::vector<float> rates_;
};
class VideoV4l2Channel {
......@@ -69,24 +69,24 @@ class VideoV4l2Channel {
/**
* @throw std::runtime_error
*/
void GetFormat(int fd);
void getFormat(int fd);
/**
* @throw std::runtime_error
*/
unsigned int GetSizes(int fd, unsigned int pixel_format);
unsigned int getSizes(int fd, unsigned int pixel_format);
void SetFourcc(unsigned code);
const char * GetFourcc();
void setFourcc(unsigned code);
const char * getFourcc();
std::vector<std::string> getSizeList(void);
std::vector<std::string> getSizeList();
VideoV4l2Size getSize(const std::string &name);
unsigned idx;
std::string name;
private:
std::vector<VideoV4l2Size> sizes;
char fourcc[5];
std::vector<VideoV4l2Size> sizes_;
char fourcc_[5];
};
class VideoV4l2Device {
......@@ -99,7 +99,7 @@ class VideoV4l2Device {
std::string device;
std::string name;
std::vector<std::string> getChannelList(void);
std::vector<std::string> getChannelList() const;
VideoV4l2Channel &getChannel(const std::string &name);
......
......@@ -62,53 +62,52 @@ namespace sfl_video {
static int is_v4l2(struct udev_device *dev)
{
const char *version;
version = udev_device_get_property_value (dev, "ID_V4L_VERSION");
const char *version = udev_device_get_property_value(dev, "ID_V4L_VERSION");
/* we do not support video4linux 1 */
return version && strcmp (version, "1");
return version and strcmp(version, "1");
}
VideoV4l2List::VideoV4l2List() : _udev_mon(NULL)
VideoV4l2ListThread::VideoV4l2ListThread() : devices_(), mutex_(), udev_(0), udev_mon_(0)
{
struct udev_list_entry *devlist;
struct udev_enumerate *devenum;
udev_list_entry *devlist;
udev_enumerate *devenum;
addDevice("SFLTEST");
_udev = udev_new();
if (!_udev)
udev_ = udev_new();
if (!udev_)
goto udev_failed;
_udev_mon = udev_monitor_new_from_netlink (_udev, "udev");
if (!_udev_mon)
udev_mon_ = udev_monitor_new_from_netlink(udev_, "udev");
if (!udev_mon_)
goto udev_failed;
if (udev_monitor_filter_add_match_subsystem_devtype (_udev_mon, "video4linux", NULL))
if (udev_monitor_filter_add_match_subsystem_devtype(udev_mon_, "video4linux", NULL))
goto udev_failed;
/* Enumerate existing devices */
devenum = udev_enumerate_new (_udev);
devenum = udev_enumerate_new(udev_);
if (devenum == NULL)
goto udev_failed;
if (udev_enumerate_add_match_subsystem (devenum, "video4linux"))
if (udev_enumerate_add_match_subsystem(devenum, "video4linux"))
{
udev_enumerate_unref (devenum);
udev_enumerate_unref(devenum);
goto udev_failed;
}
udev_monitor_enable_receiving (_udev_mon);
udev_monitor_enable_receiving(udev_mon_);
/* Note that we enumerate _after_ monitoring is enabled so that we do not
* loose device events occuring while we are enumerating. We could still
* loose events if the Netlink socket receive buffer overflows. */
udev_enumerate_scan_devices (devenum);
devlist = udev_enumerate_get_list_entry (devenum);
udev_enumerate_scan_devices(devenum);
devlist = udev_enumerate_get_list_entry(devenum);
struct udev_list_entry *deventry;
udev_list_entry_foreach (deventry, devlist)
udev_list_entry_foreach(deventry, devlist)
{
const char *path = udev_list_entry_get_name (deventry);
struct udev_device *dev = udev_device_new_from_syspath (_udev, path);
const char *path = udev_list_entry_get_name(deventry);
struct udev_device *dev = udev_device_new_from_syspath(udev_, path);
if (is_v4l2(dev)) {
const char *devpath = udev_device_get_devnode (dev);
const char *devpath = udev_device_get_devnode(dev);
if (devpath) {
try {
addDevice(devpath);
......@@ -117,9 +116,9 @@ VideoV4l2List::VideoV4l2List() : _udev_mon(NULL)
}
}
}
udev_device_unref (dev);
udev_device_unref(dev);
}
udev_enumerate_unref (devenum);
udev_enumerate_unref(devenum);
return;
......@@ -127,12 +126,12 @@ udev_failed:
ERROR("udev enumeration failed");
if (_udev_mon)
udev_monitor_unref (_udev_mon);
if (_udev)
udev_unref (_udev);
_udev_mon = NULL;
_udev = NULL;
if (udev_mon_)
udev_monitor_unref(udev_mon_);
if (udev_)
udev_unref(udev_);
udev_mon_ = NULL;
udev_ = NULL;
/* fallback : go through /dev/video* */
int idx;
......@@ -154,10 +153,9 @@ namespace {
int GetNumber(const std::string &name, size_t *sharp)
{
size_t len = name.length();
if (len < 3) {
// name is too short to be numbered
// name is too short to be numbered
if (len < 3)
return -1;