libcamera: Use log categories

Use log categories in the whole existing code base.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2019-01-20 15:03:01 +02:00
parent 457208178c
commit 8b8ae52134
9 changed files with 107 additions and 60 deletions

View file

@ -21,6 +21,8 @@
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(Camera)
/** /**
* \class CameraManager * \class CameraManager
* \brief Provide access and manage all cameras in the system * \brief Provide access and manage all cameras in the system
@ -101,8 +103,9 @@ int CameraManager::start()
break; break;
} }
LOG(Debug) << "Pipeline handler \"" << factory->name() LOG(Camera, Debug)
<< "\" matched"; << "Pipeline handler \"" << factory->name()
<< "\" matched";
pipes_.push_back(pipe); pipes_.push_back(pipe);
} }
} }
@ -176,8 +179,9 @@ void CameraManager::addCamera(std::shared_ptr<Camera> camera)
{ {
for (std::shared_ptr<Camera> c : cameras_) { for (std::shared_ptr<Camera> c : cameras_) {
if (c->name() == camera->name()) { if (c->name() == camera->name()) {
LOG(Warning) << "Registering camera with duplicate name '" LOG(Camera, Warning)
<< camera->name() << "'"; << "Registering camera with duplicate name '"
<< camera->name() << "'";
break; break;
} }
} }
@ -216,7 +220,7 @@ CameraManager *CameraManager::instance()
void CameraManager::setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher) void CameraManager::setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher)
{ {
if (dispatcher_) { if (dispatcher_) {
LOG(Warning) << "Event dispatcher is already set"; LOG(Camera, Warning) << "Event dispatcher is already set";
return; return;
} }

View file

@ -42,6 +42,8 @@
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(DeviceEnumerator)
/** /**
* \class DeviceMatch * \class DeviceMatch
* \brief Description of a media device search pattern * \brief Description of a media device search pattern
@ -155,7 +157,8 @@ DeviceEnumerator::~DeviceEnumerator()
{ {
for (MediaDevice *dev : devices_) { for (MediaDevice *dev : devices_) {
if (dev->busy()) if (dev->busy())
LOG(Error) << "Removing media device while still in use"; LOG(DeviceEnumerator, Error)
<< "Removing media device while still in use";
delete dev; delete dev;
} }
@ -205,13 +208,15 @@ int DeviceEnumerator::addDevice(const std::string &devnode)
ret = media->populate(); ret = media->populate();
if (ret < 0) { if (ret < 0) {
LOG(Info) << "Unable to populate media device " << devnode << LOG(DeviceEnumerator, Info)
" (" << strerror(-ret) << "), skipping"; << "Unable to populate media device " << devnode
<< " (" << strerror(-ret) << "), skipping";
return ret; return ret;
} }
LOG(Debug) << "New media device \"" << media->driver() LOG(DeviceEnumerator, Debug)
<< "\" created from " << devnode; << "New media device \"" << media->driver()
<< "\" created from " << devnode;
/* Associate entities to device node paths. */ /* Associate entities to device node paths. */
for (MediaEntity *entity : media->entities()) { for (MediaEntity *entity : media->entities()) {
@ -251,8 +256,9 @@ MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm)
continue; continue;
if (dm.match(dev)) { if (dm.match(dev)) {
LOG(Debug) << "Successful match for media device \"" LOG(DeviceEnumerator, Debug)
<< dev->driver() << "\""; << "Successful match for media device \""
<< dev->driver() << "\"";
return dev; return dev;
} }
} }
@ -330,8 +336,9 @@ int DeviceEnumeratorUdev::enumerate()
dev = udev_device_new_from_syspath(udev_, syspath); dev = udev_device_new_from_syspath(udev_, syspath);
if (!dev) { if (!dev) {
LOG(Warning) << "Failed to get device for '" << LOG(DeviceEnumerator, Warning)
syspath << "', skipping"; << "Failed to get device for '"
<< syspath << "', skipping";
continue; continue;
} }

View file

@ -7,12 +7,16 @@
#include <libcamera/event_dispatcher.h> #include <libcamera/event_dispatcher.h>
#include "log.h"
/** /**
* \file event_dispatcher.h * \file event_dispatcher.h
*/ */
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(Event)
/** /**
* \class EventDispatcher * \class EventDispatcher
* \brief Interface to manage the libcamera events and timers * \brief Interface to manage the libcamera events and timers

View file

@ -22,6 +22,8 @@
namespace libcamera { namespace libcamera {
LOG_DECLARE_CATEGORY(Event)
static const char *notifierType(EventNotifier::Type type) static const char *notifierType(EventNotifier::Type type)
{ {
if (type == EventNotifier::Read) if (type == EventNotifier::Read)
@ -53,8 +55,9 @@ void EventDispatcherPoll::registerEventNotifier(EventNotifier *notifier)
EventNotifier::Type type = notifier->type(); EventNotifier::Type type = notifier->type();
if (set.notifiers[type] && set.notifiers[type] != notifier) { if (set.notifiers[type] && set.notifiers[type] != notifier) {
LOG(Warning) << "Ignoring duplicate " << notifierType(type) LOG(Event, Warning)
<< " notifier for fd " << notifier->fd(); << "Ignoring duplicate " << notifierType(type)
<< " notifier for fd " << notifier->fd();
return; return;
} }
@ -74,8 +77,9 @@ void EventDispatcherPoll::unregisterEventNotifier(EventNotifier *notifier)
return; return;
if (set.notifiers[type] != notifier) { if (set.notifiers[type] != notifier) {
LOG(Warning) << notifierType(type) << " notifier for fd " LOG(Event, Warning)
<< notifier->fd() << " is not registered"; << notifierType(type) << " notifier for fd "
<< notifier->fd() << " is not registered";
return; return;
} }
@ -141,9 +145,10 @@ void EventDispatcherPoll::processEvents()
timeout.tv_nsec = 0; timeout.tv_nsec = 0;
} }
LOG(Debug) << "timeout " << timeout.tv_sec << "." LOG(Event, Debug)
<< std::setfill('0') << std::setw(9) << "timeout " << timeout.tv_sec << "."
<< timeout.tv_nsec; << std::setfill('0') << std::setw(9)
<< timeout.tv_nsec;
} }
/* Wait for events and process notifiers and timers. */ /* Wait for events and process notifiers and timers. */
@ -151,7 +156,7 @@ void EventDispatcherPoll::processEvents()
nextTimer ? &timeout : nullptr, nullptr); nextTimer ? &timeout : nullptr, nullptr);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Warning) << "poll() failed with " << strerror(-ret); LOG(Event, Warning) << "poll() failed with " << strerror(-ret);
} else if (ret > 0) { } else if (ret > 0) {
processNotifiers(pollfds); processNotifiers(pollfds);
} }
@ -201,9 +206,10 @@ void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pol
* notifier immediately. * notifier immediately.
*/ */
if (pfd.revents & POLLNVAL) { if (pfd.revents & POLLNVAL) {
LOG(Warning) << "Disabling " << notifierType(event.type) LOG(Event, Warning)
<< " due to invalid file descriptor " << "Disabling " << notifierType(event.type)
<< pfd.fd; << " due to invalid file descriptor "
<< pfd.fd;
unregisterEventNotifier(notifier); unregisterEventNotifier(notifier);
continue; continue;
} }

View file

@ -27,6 +27,8 @@
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(MediaDevice)
/** /**
* \class MediaDevice * \class MediaDevice
* \brief The MediaDevice represents a Media Controller device with its full * \brief The MediaDevice represents a Media Controller device with its full
@ -139,15 +141,16 @@ bool MediaDevice::acquire()
int MediaDevice::open() int MediaDevice::open()
{ {
if (fd_ != -1) { if (fd_ != -1) {
LOG(Error) << "MediaDevice already open"; LOG(MediaDevice, Error) << "MediaDevice already open";
return -EBUSY; return -EBUSY;
} }
int ret = ::open(devnode_.c_str(), O_RDWR); int ret = ::open(devnode_.c_str(), O_RDWR);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to open media device at " << devnode_ LOG(MediaDevice, Error)
<< ": " << strerror(-ret); << "Failed to open media device at "
<< devnode_ << ": " << strerror(-ret);
return ret; return ret;
} }
fd_ = ret; fd_ = ret;
@ -156,8 +159,9 @@ int MediaDevice::open()
ret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info); ret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info);
if (ret) { if (ret) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to get media device info " LOG(MediaDevice, Error)
<< ": " << strerror(-ret); << "Failed to get media device info "
<< ": " << strerror(-ret);
return ret; return ret;
} }
@ -227,8 +231,9 @@ int MediaDevice::populate()
ret = ioctl(fd_, MEDIA_IOC_G_TOPOLOGY, &topology); ret = ioctl(fd_, MEDIA_IOC_G_TOPOLOGY, &topology);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to enumerate topology: " LOG(MediaDevice, Error)
<< strerror(-ret); << "Failed to enumerate topology: "
<< strerror(-ret);
return ret; return ret;
} }
@ -445,8 +450,9 @@ bool MediaDevice::addObject(MediaObject *object)
{ {
if (objects_.find(object->id()) != objects_.end()) { if (objects_.find(object->id()) != objects_.end()) {
LOG(Error) << "Element with id " << object->id() LOG(MediaDevice, Error)
<< " already enumerated."; << "Element with id " << object->id()
<< " already enumerated.";
return false; return false;
} }
@ -568,8 +574,9 @@ bool MediaDevice::populatePads(const struct media_v2_topology &topology)
MediaEntity *mediaEntity = dynamic_cast<MediaEntity *> MediaEntity *mediaEntity = dynamic_cast<MediaEntity *>
(object(entity_id)); (object(entity_id));
if (!mediaEntity) { if (!mediaEntity) {
LOG(Error) << "Failed to find entity with id: " LOG(MediaDevice, Error)
<< entity_id; << "Failed to find entity with id: "
<< entity_id;
return false; return false;
} }
@ -604,8 +611,9 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
MediaPad *source = dynamic_cast<MediaPad *> MediaPad *source = dynamic_cast<MediaPad *>
(object(source_id)); (object(source_id));
if (!source) { if (!source) {
LOG(Error) << "Failed to find pad with id: " LOG(MediaDevice, Error)
<< source_id; << "Failed to find pad with id: "
<< source_id;
return false; return false;
} }
@ -613,8 +621,9 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
MediaPad *sink = dynamic_cast<MediaPad *> MediaPad *sink = dynamic_cast<MediaPad *>
(object(sink_id)); (object(sink_id));
if (!sink) { if (!sink) {
LOG(Error) << "Failed to find pad with id: " LOG(MediaDevice, Error)
<< sink_id; << "Failed to find pad with id: "
<< sink_id;
return false; return false;
} }
@ -665,14 +674,17 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
int ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc); int ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc);
if (ret) { if (ret) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to setup link: " << strerror(-ret); LOG(MediaDevice, Error)
<< "Failed to setup link: "
<< strerror(-ret);
return ret; return ret;
} }
LOG(Debug) << source->entity()->name() << "[" LOG(MediaDevice, Debug)
<< source->index() << "] -> " << source->entity()->name() << "["
<< sink->entity()->name() << "[" << source->index() << "] -> "
<< sink->index() << "]: " << flags; << sink->entity()->name() << "["
<< sink->index() << "]: " << flags;
return 0; return 0;
} }

View file

@ -39,6 +39,8 @@
namespace libcamera { namespace libcamera {
LOG_DECLARE_CATEGORY(MediaDevice)
/** /**
* \class MediaObject * \class MediaObject
* \brief Base class for all media objects * \brief Base class for all media objects
@ -334,8 +336,9 @@ int MediaEntity::setDeviceNode(const std::string &devnode)
int ret = ::access(devnode.c_str(), R_OK | W_OK); int ret = ::access(devnode.c_str(), R_OK | W_OK);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Error) << "Device node " << devnode << " can't be accessed: " LOG(MediaDevice, Error)
<< strerror(-ret); << "Device node " << devnode << " can't be accessed: "
<< strerror(-ret);
return ret; return ret;
} }

View file

@ -24,6 +24,8 @@
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(Pipeline)
/** /**
* \class PipelineHandler * \class PipelineHandler
* \brief Create and manage cameras based on a set of media devices * \brief Create and manage cameras based on a set of media devices
@ -120,7 +122,8 @@ void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory)
factories.push_back(factory); factories.push_back(factory);
LOG(Debug) << "Registered pipeline handler \"" << factory->name() << "\""; LOG(Pipeline, Debug)
<< "Registered pipeline handler \"" << factory->name() << "\"";
} }
/** /**

View file

@ -20,6 +20,8 @@
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(Timer)
/** /**
* \class Timer * \class Timer
* \brief Single-shot timer interface * \brief Single-shot timer interface
@ -54,8 +56,9 @@ void Timer::start(unsigned int msec)
interval_ = msec; interval_ = msec;
deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000ULL; deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000ULL;
LOG(Debug) << "Starting timer " << this << " with interval " << msec LOG(Timer, Debug)
<< ": deadline " << deadline_; << "Starting timer " << this << " with interval "
<< msec << ": deadline " << deadline_;
CameraManager::instance()->eventDispatcher()->registerTimer(this); CameraManager::instance()->eventDispatcher()->registerTimer(this);
} }

View file

@ -20,6 +20,8 @@
*/ */
namespace libcamera { namespace libcamera {
LOG_DEFINE_CATEGORY(V4L2)
/** /**
* \struct V4L2Capability * \struct V4L2Capability
* \brief struct v4l2_capability object wrapper and helpers * \brief struct v4l2_capability object wrapper and helpers
@ -106,15 +108,16 @@ int V4L2Device::open()
int ret; int ret;
if (isOpen()) { if (isOpen()) {
LOG(Error) << "Device already open"; LOG(V4L2, Error) << "Device already open";
return -EBUSY; return -EBUSY;
} }
ret = ::open(devnode_.c_str(), O_RDWR); ret = ::open(devnode_.c_str(), O_RDWR);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to open V4L2 device '" << devnode_ LOG(V4L2, Error)
<< "': " << strerror(-ret); << "Failed to open V4L2 device '" << devnode_
<< "': " << strerror(-ret);
return ret; return ret;
} }
fd_ = ret; fd_ = ret;
@ -122,22 +125,24 @@ int V4L2Device::open()
ret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_); ret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
LOG(Error) << "Failed to query device capabilities: " LOG(V4L2, Error)
<< strerror(-ret); << "Failed to query device capabilities: "
<< strerror(-ret);
return ret; return ret;
} }
LOG(Debug) << "Opened '" << devnode_ << "' " LOG(V4L2, Debug)
<< caps_.bus_info() << ": " << caps_.driver() << "Opened '" << devnode_ << "' "
<< ": " << caps_.card(); << caps_.bus_info() << ": " << caps_.driver()
<< ": " << caps_.card();
if (!caps_.isCapture() && !caps_.isOutput()) { if (!caps_.isCapture() && !caps_.isOutput()) {
LOG(Debug) << "Device is not a supported type"; LOG(V4L2, Debug) << "Device is not a supported type";
return -EINVAL; return -EINVAL;
} }
if (!caps_.hasStreaming()) { if (!caps_.hasStreaming()) {
LOG(Error) << "Device does not support streaming I/O"; LOG(V4L2, Error) << "Device does not support streaming I/O";
return -EINVAL; return -EINVAL;
} }