[libcamera-devel] [PATCH 2/2] libcamera: Switch from utils::make_unique to std::make_unique

Niklas Söderlund niklas.soderlund at ragnatech.se
Tue Jan 14 15:22:17 CET 2020


Hi Laurent,

Thanks for your patch.

On 2020-01-14 02:15:31 +0200, Laurent Pinchart wrote:
> Now that we're using C++-14, drop utils::make_unique for
> std::make_unique.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  src/android/camera_device.cpp                      |  2 +-
>  src/ipa/ipa_vimc.cpp                               |  3 +--
>  src/ipa/libipa/ipa_interface_wrapper.cpp           |  2 +-
>  src/ipa/rkisp1/rkisp1.cpp                          |  2 +-
>  src/libcamera/bound_method.cpp                     |  5 ++---
>  src/libcamera/control_serializer.cpp               |  2 +-
>  src/libcamera/device_enumerator.cpp                |  5 ++---
>  src/libcamera/include/ipa_proxy.h                  |  3 +--
>  src/libcamera/include/utils.h                      |  7 -------
>  src/libcamera/ipa_manager.cpp                      |  2 +-
>  src/libcamera/pipeline/ipu3/ipu3.cpp               |  2 +-
>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 14 +++++++-------
>  src/libcamera/pipeline/uvcvideo.cpp                |  2 +-
>  src/libcamera/pipeline/vimc.cpp                    |  2 +-
>  .../proxy/worker/ipa_proxy_linux_worker.cpp        |  3 +--
>  src/libcamera/utils.cpp                            |  5 -----
>  src/libcamera/v4l2_device.cpp                      |  2 +-
>  src/libcamera/v4l2_videodevice.cpp                 |  2 +-
>  src/v4l2/v4l2_camera.cpp                           |  3 +--
>  src/v4l2/v4l2_camera_proxy.cpp                     |  2 +-
>  test/ipa/ipa_wrappers_test.cpp                     |  3 +--
>  test/message.cpp                                   |  5 ++---
>  22 files changed, 29 insertions(+), 49 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index a98fd744f534..67c1d47e67ed 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -860,7 +860,7 @@ std::unique_ptr<CameraMetadata> CameraDevice::getResultMetadata(int frame_number
>  	 * Currently: 12 entries, 36 bytes
>  	 */
>  	std::unique_ptr<CameraMetadata> resultMetadata =
> -		utils::make_unique<CameraMetadata>(15, 50);
> +		std::make_unique<CameraMetadata>(15, 50);
>  	if (!resultMetadata->isValid()) {
>  		LOG(HAL, Error) << "Failed to allocate static metadata";
>  		return nullptr;
> diff --git a/src/ipa/ipa_vimc.cpp b/src/ipa/ipa_vimc.cpp
> index 8f03e811acc7..4751ad919a0f 100644
> --- a/src/ipa/ipa_vimc.cpp
> +++ b/src/ipa/ipa_vimc.cpp
> @@ -20,7 +20,6 @@
>  #include "libipa/ipa_interface_wrapper.h"
>  
>  #include "log.h"
> -#include "utils.h"
>  
>  namespace libcamera {
>  
> @@ -113,7 +112,7 @@ const struct IPAModuleInfo ipaModuleInfo = {
>  
>  struct ipa_context *ipaCreate()
>  {
> -	return new IPAInterfaceWrapper(utils::make_unique<IPAVimc>());
> +	return new IPAInterfaceWrapper(std::make_unique<IPAVimc>());
>  }
>  }
>  
> diff --git a/src/ipa/libipa/ipa_interface_wrapper.cpp b/src/ipa/libipa/ipa_interface_wrapper.cpp
> index 3628a785dc3e..b93c1c1f1c1a 100644
> --- a/src/ipa/libipa/ipa_interface_wrapper.cpp
> +++ b/src/ipa/libipa/ipa_interface_wrapper.cpp
> @@ -45,7 +45,7 @@ namespace libcamera {
>   *
>   * struct ipa_context *ipaCreate()
>   * {
> - * 	return new IPAInterfaceWrapper(utils::make_unique<MyIPA>());
> + * 	return new IPAInterfaceWrapper(std::make_unique<MyIPA>());
>   * }
>   * \endcode
>   *
> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
> index a8dd1645d3e8..438b3c66f77a 100644
> --- a/src/ipa/rkisp1/rkisp1.cpp
> +++ b/src/ipa/rkisp1/rkisp1.cpp
> @@ -278,7 +278,7 @@ const struct IPAModuleInfo ipaModuleInfo = {
>  
>  struct ipa_context *ipaCreate()
>  {
> -	return new IPAInterfaceWrapper(utils::make_unique<IPARkISP1>());
> +	return new IPAInterfaceWrapper(std::make_unique<IPARkISP1>());
>  }
>  }
>  
> diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp
> index 8e95c7eec92c..e18c2eb4c68e 100644
> --- a/src/libcamera/bound_method.cpp
> +++ b/src/libcamera/bound_method.cpp
> @@ -10,7 +10,6 @@
>  #include "message.h"
>  #include "semaphore.h"
>  #include "thread.h"
> -#include "utils.h"
>  
>  /**
>   * \file bound_method.h
> @@ -84,7 +83,7 @@ bool BoundMethodBase::activatePack(std::shared_ptr<BoundMethodPackBase> pack,
>  
>  	case ConnectionTypeQueued: {
>  		std::unique_ptr<Message> msg =
> -			utils::make_unique<InvokeMessage>(this, pack, nullptr, deleteMethod);
> +			std::make_unique<InvokeMessage>(this, pack, nullptr, deleteMethod);
>  		object_->postMessage(std::move(msg));
>  		return false;
>  	}
> @@ -93,7 +92,7 @@ bool BoundMethodBase::activatePack(std::shared_ptr<BoundMethodPackBase> pack,
>  		Semaphore semaphore;
>  
>  		std::unique_ptr<Message> msg =
> -			utils::make_unique<InvokeMessage>(this, pack, &semaphore, deleteMethod);
> +			std::make_unique<InvokeMessage>(this, pack, &semaphore, deleteMethod);
>  		object_->postMessage(std::move(msg));
>  
>  		semaphore.acquire();
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index a5d6d875c76f..803ac16c2456 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -414,7 +414,7 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &
>  		 * \todo Find a way to preserve the control name for debugging
>  		 * purpose.
>  		 */
> -		controlIds_.emplace_back(utils::make_unique<ControlId>(entry.id, "", type));
> +		controlIds_.emplace_back(std::make_unique<ControlId>(entry.id, "", type));
>  
>  		if (entry.offset != values.offset()) {
>  			LOG(Serializer, Error)
> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
> index 0b596bcec363..a8b5c90f5a5d 100644
> --- a/src/libcamera/device_enumerator.cpp
> +++ b/src/libcamera/device_enumerator.cpp
> @@ -13,7 +13,6 @@
>  
>  #include "log.h"
>  #include "media_device.h"
> -#include "utils.h"
>  
>  /**
>   * \file device_enumerator.h
> @@ -145,7 +144,7 @@ std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()
>  	std::unique_ptr<DeviceEnumerator> enumerator;
>  
>  #ifdef HAVE_LIBUDEV
> -	enumerator = utils::make_unique<DeviceEnumeratorUdev>();
> +	enumerator = std::make_unique<DeviceEnumeratorUdev>();
>  	if (!enumerator->init())
>  		return enumerator;
>  #endif
> @@ -154,7 +153,7 @@ std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()
>  	 * Either udev is not available or udev initialization failed. Fall back
>  	 * on the sysfs enumerator.
>  	 */
> -	enumerator = utils::make_unique<DeviceEnumeratorSysfs>();
> +	enumerator = std::make_unique<DeviceEnumeratorSysfs>();
>  	if (!enumerator->init())
>  		return enumerator;
>  
> diff --git a/src/libcamera/include/ipa_proxy.h b/src/libcamera/include/ipa_proxy.h
> index add40b4b3368..e696551af39f 100644
> --- a/src/libcamera/include/ipa_proxy.h
> +++ b/src/libcamera/include/ipa_proxy.h
> @@ -14,7 +14,6 @@
>  #include <ipa/ipa_interface.h>
>  
>  #include "ipa_module.h"
> -#include "utils.h"
>  
>  namespace libcamera {
>  
> @@ -56,7 +55,7 @@ public:							\
>  	proxy##Factory() : IPAProxyFactory(#proxy) {}	\
>  	std::unique_ptr<IPAProxy> create(IPAModule *ipam)	\
>  	{						\
> -		return utils::make_unique<proxy>(ipam);	\
> +		return std::make_unique<proxy>(ipam);	\
>  	}						\
>  };							\
>  static proxy##Factory global_##proxy##Factory;
> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
> index badc77533fa1..e467eb21c518 100644
> --- a/src/libcamera/include/utils.h
> +++ b/src/libcamera/include/utils.h
> @@ -32,13 +32,6 @@ namespace utils {
>  
>  const char *basename(const char *path);
>  
> -/* C++11 doesn't provide std::make_unique */
> -template<typename T, typename... Args>
> -std::unique_ptr<T> make_unique(Args&&... args)
> -{
> -	return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
> -}
> -
>  char *secure_getenv(const char *name);
>  
>  template<class InputIt1, class InputIt2>
> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp
> index 90eef12dbaf5..92adc6c45015 100644
> --- a/src/libcamera/ipa_manager.cpp
> +++ b/src/libcamera/ipa_manager.cpp
> @@ -264,7 +264,7 @@ std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe,
>  	if (!ctx)
>  		return nullptr;
>  
> -	return utils::make_unique<IPAContextWrapper>(ctx);
> +	return std::make_unique<IPAContextWrapper>(ctx);
>  }
>  
>  } /* namespace libcamera */
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 7894084a025e..8e8e370922ad 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -876,7 +876,7 @@ int PipelineHandlerIPU3::registerCameras()
>  	unsigned int numCameras = 0;
>  	for (unsigned int id = 0; id < 4 && numCameras < 2; ++id) {
>  		std::unique_ptr<IPU3CameraData> data =
> -			utils::make_unique<IPU3CameraData>(this);
> +			std::make_unique<IPU3CameraData>(this);
>  		std::set<Stream *> streams = {
>  			&data->outStream_,
>  			&data->vfStream_,
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 389a99cf52bd..0b3dd9759387 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -388,9 +388,9 @@ void RkISP1CameraData::queueFrameAction(unsigned int frame,
>  	switch (action.operation) {
>  	case RKISP1_IPA_ACTION_V4L2_SET: {
>  		const ControlList &controls = action.controls[0];
> -		timeline_.scheduleAction(utils::make_unique<RkISP1ActionSetSensor>(frame,
> -										   sensor_,
> -										   controls));
> +		timeline_.scheduleAction(std::make_unique<RkISP1ActionSetSensor>(frame,
> +										 sensor_,
> +										 controls));
>  		break;
>  	}
>  	case RKISP1_IPA_ACTION_PARAM_FILLED: {
> @@ -846,9 +846,9 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera,
>  	op.controls = { request->controls() };
>  	data->ipa_->processEvent(op);
>  
> -	data->timeline_.scheduleAction(utils::make_unique<RkISP1ActionQueueBuffers>(data->frame_,
> -										    data,
> -										    this));
> +	data->timeline_.scheduleAction(std::make_unique<RkISP1ActionQueueBuffers>(data->frame_,
> +										  data,
> +										  this));
>  
>  	data->frame_++;
>  
> @@ -892,7 +892,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)
>  	int ret;
>  
>  	std::unique_ptr<RkISP1CameraData> data =
> -		utils::make_unique<RkISP1CameraData>(this);
> +		std::make_unique<RkISP1CameraData>(this);
>  
>  	ControlInfoMap::Map ctrls;
>  	ctrls.emplace(std::piecewise_construct,
> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
> index 47916ffb4536..83093676ec73 100644
> --- a/src/libcamera/pipeline/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo.cpp
> @@ -296,7 +296,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
>  	if (!media)
>  		return false;
>  
> -	std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this);
> +	std::unique_ptr<UVCCameraData> data = std::make_unique<UVCCameraData>(this);
>  
>  	/* Locate and initialise the camera data with the default video node. */
>  	const std::vector<MediaEntity *> &entities = media->entities();
> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
> index 1700ac967299..c99560a45cfa 100644
> --- a/src/libcamera/pipeline/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc.cpp
> @@ -365,7 +365,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
>  	if (!media)
>  		return false;
>  
> -	std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);
> +	std::unique_ptr<VimcCameraData> data = std::make_unique<VimcCameraData>(this);
>  
>  	data->ipa_ = IPAManager::instance()->createIPA(this, 0, 0);
>  	if (data->ipa_ == nullptr)
> diff --git a/src/libcamera/proxy/worker/ipa_proxy_linux_worker.cpp b/src/libcamera/proxy/worker/ipa_proxy_linux_worker.cpp
> index 07380c16e2d5..7d6287c7115b 100644
> --- a/src/libcamera/proxy/worker/ipa_proxy_linux_worker.cpp
> +++ b/src/libcamera/proxy/worker/ipa_proxy_linux_worker.cpp
> @@ -17,7 +17,6 @@
>  #include "ipc_unixsocket.h"
>  #include "log.h"
>  #include "thread.h"
> -#include "utils.h"
>  
>  using namespace libcamera;
>  
> @@ -58,7 +57,7 @@ int main(int argc, char **argv)
>  		<< "Starting worker for IPA module " << argv[1]
>  		<< " with IPC fd = " << fd;
>  
> -	std::unique_ptr<IPAModule> ipam = utils::make_unique<IPAModule>(argv[1]);
> +	std::unique_ptr<IPAModule> ipam = std::make_unique<IPAModule>(argv[1]);
>  	if (!ipam->isValid() || !ipam->load()) {
>  		LOG(IPAProxyLinuxWorker, Error)
>  			<< "IPAModule " << argv[1] << " should be valid but isn't";
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 5de9e4813353..4beffdab5eb6 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -70,11 +70,6 @@ char *secure_getenv(const char *name)
>  #endif
>  }
>  
> -/**
> - * \fn libcamera::utils::make_unique(Args &&... args)
> - * \brief Constructs an object of type T and wraps it in a std::unique_ptr.
> - */
> -
>  /**
>   * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1,
>   *				     InputIt2 first2, InputIt2 last2)
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index c13eddc84c7c..1698d2451449 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -380,7 +380,7 @@ void V4L2Device::listControls()
>  			continue;
>  		}
>  
> -		controlIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));
> +		controlIds_.emplace_back(std::make_unique<V4L2ControlId>(ctrl));
>  		ctrls.emplace(controlIds_.back().get(), V4L2ControlRange(ctrl));
>  	}
>  
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 66adf7b29572..18220b81af21 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1054,7 +1054,7 @@ V4L2VideoDevice::createBuffer(const struct v4l2_buffer &buf)
>  		planes.push_back(std::move(plane));
>  	}
>  
> -	return utils::make_unique<FrameBuffer>(std::move(planes));
> +	return std::make_unique<FrameBuffer>(std::move(planes));
>  }
>  
>  FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index,
> diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp
> index 44cb4e7c551b..e7018b566475 100644
> --- a/src/v4l2/v4l2_camera.cpp
> +++ b/src/v4l2/v4l2_camera.cpp
> @@ -10,7 +10,6 @@
>  #include <errno.h>
>  
>  #include "log.h"
> -#include "utils.h"
>  
>  using namespace libcamera;
>  
> @@ -81,7 +80,7 @@ void V4L2Camera::requestComplete(Request *request)
>  	bufferLock_.lock();
>  	FrameBuffer *buffer = request->buffers().begin()->second;
>  	std::unique_ptr<Buffer> metadata =
> -		utils::make_unique<Buffer>(request->cookie(), buffer->metadata());
> +		std::make_unique<Buffer>(request->cookie(), buffer->metadata());
>  	completedBuffers_.push_back(std::move(metadata));
>  	bufferLock_.unlock();
>  
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index 28e587226a97..3013a3d17568 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -32,7 +32,7 @@ LOG_DECLARE_CATEGORY(V4L2Compat);
>  V4L2CameraProxy::V4L2CameraProxy(unsigned int index,
>  				 std::shared_ptr<Camera> camera)
>  	: refcount_(0), index_(index), bufferCount_(0), currentBuf_(0),
> -	  vcam_(utils::make_unique<V4L2Camera>(camera))
> +	  vcam_(std::make_unique<V4L2Camera>(camera))
>  {
>  	querycap(camera);
>  }
> diff --git a/test/ipa/ipa_wrappers_test.cpp b/test/ipa/ipa_wrappers_test.cpp
> index e711e4fe318d..1ae1781169c8 100644
> --- a/test/ipa/ipa_wrappers_test.cpp
> +++ b/test/ipa/ipa_wrappers_test.cpp
> @@ -18,7 +18,6 @@
>  #include "device_enumerator.h"
>  #include "ipa_context_wrapper.h"
>  #include "media_device.h"
> -#include "utils.h"
>  #include "v4l2_subdevice.h"
>  
>  #include "test.h"
> @@ -254,7 +253,7 @@ protected:
>  		if (ret)
>  			return TestFail;
>  
> -		std::unique_ptr<IPAInterface> intf = utils::make_unique<TestIPAInterface>();
> +		std::unique_ptr<IPAInterface> intf = std::make_unique<TestIPAInterface>();
>  		wrapper_ = new IPAContextWrapper(new IPAInterfaceWrapper(std::move(intf)));
>  		wrapper_->queueFrameAction.connect(this, &IPAWrappersTest::queueFrameAction);
>  
> diff --git a/test/message.cpp b/test/message.cpp
> index 7ebedb557502..478bc79dffa6 100644
> --- a/test/message.cpp
> +++ b/test/message.cpp
> @@ -12,7 +12,6 @@
>  #include "message.h"
>  #include "thread.h"
>  #include "test.h"
> -#include "utils.h"
>  
>  using namespace std;
>  using namespace libcamera;
> @@ -92,7 +91,7 @@ protected:
>  
>  		thread_.start();
>  
> -		receiver.postMessage(utils::make_unique<Message>(Message::None));
> +		receiver.postMessage(std::make_unique<Message>(Message::None));
>  
>  		this_thread::sleep_for(chrono::milliseconds(100));
>  
> @@ -114,7 +113,7 @@ protected:
>  		 */
>  		SlowMessageReceiver *slowReceiver = new SlowMessageReceiver();
>  		slowReceiver->moveToThread(&thread_);
> -		slowReceiver->postMessage(utils::make_unique<Message>(Message::None));
> +		slowReceiver->postMessage(std::make_unique<Message>(Message::None));
>  
>  		this_thread::sleep_for(chrono::milliseconds(10));
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list