[PATCH v2 7/7] gstreamer: Replace NULL with nullptr
Nicolas Dufresne
nicolas.dufresne at collabora.com
Thu Jun 5 14:53:18 CEST 2025
Le mercredi 04 juin 2025 à 15:23 +0200, Barnabás Pőcze a écrit :
> Hi
>
> 2025. 06. 04. 15:07 keltezéssel, Laurent Pinchart írta:
> > Usage of NULL has slowly crept in the libcamerasrc sources. Replace it
> > with nullptr.
>
> I think we should set up clang-tidy in the CI. It has:
> https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nullptr.html
> and many more useful things. Unfortunately every time I run it I am faced
> with the fact that it runs quite slowly when using a number of checks, so
> it would probably have to be limited to the changed source files.
>
> Reviewed-by: Barnabás Pőcze <barnabas.pocze at ideasonboard.com>
Reported-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
cheers,
Nicolas
>
>
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > ---
> > src/gstreamer/gstlibcamera-controls.cpp.in | 2 +-
> > src/gstreamer/gstlibcamerapad.cpp | 2 +-
> > src/gstreamer/gstlibcamerasrc.cpp | 23 +++++++++++-----------
> > 3 files changed, 14 insertions(+), 13 deletions(-)
> >
> > diff --git a/src/gstreamer/gstlibcamera-controls.cpp.in b/src/gstreamer/gstlibcamera-controls.cpp.in
> > index 89c530da0b4a..2a16b39a93d9 100644
> > --- a/src/gstreamer/gstlibcamera-controls.cpp.in
> > +++ b/src/gstreamer/gstlibcamera-controls.cpp.in
> > @@ -68,7 +68,7 @@ static const GEnumValue {{ ctrl.name|snake_case }}_types[] = {
> > "{{ enum.gst_name }}"
> > },
> > {%- endfor %}
> > - {0, NULL, NULL}
> > + {0, nullptr, nullptr}
> > };
> >
> > #define TYPE_{{ ctrl.name|snake_case|upper }} \
> > diff --git a/src/gstreamer/gstlibcamerapad.cpp b/src/gstreamer/gstlibcamerapad.cpp
> > index 3bc2bc87e773..81a0ef44cc6f 100644
> > --- a/src/gstreamer/gstlibcamerapad.cpp
> > +++ b/src/gstreamer/gstlibcamerapad.cpp
> > @@ -102,7 +102,7 @@ gst_libcamera_stream_role_get_type()
> > "libcamera::Viewfinder",
> > "view-finder",
> > },
> > - { 0, NULL, NULL }
> > + { 0, nullptr, nullptr }
> > };
> >
> > if (!type)
> > diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
> > index eec8163e88e7..16b1d08b3053 100644
> > --- a/src/gstreamer/gstlibcamerasrc.cpp
> > +++ b/src/gstreamer/gstlibcamerasrc.cpp
> > @@ -367,10 +367,10 @@ int GstLibcameraSrcState::processRequest()
> >
> > if (video_pool) {
> > /* Only set video pool when a copy is needed. */
> > - GstBuffer *copy = NULL;
> > + GstBuffer *copy = nullptr;
> > const GstVideoInfo info = gst_libcamera_pad_get_video_info(srcpad);
> >
> > - ret = gst_buffer_pool_acquire_buffer(video_pool, ©, NULL);
> > + ret = gst_buffer_pool_acquire_buffer(video_pool, ©, nullptr);
> > if (ret != GST_FLOW_OK) {
> > gst_buffer_unref(buffer);
> > GST_ELEMENT_ERROR(src_, RESOURCE, SETTINGS,
> > @@ -541,8 +541,8 @@ static std::tuple<GstBufferPool *, int>
> > gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
> > GstCaps *caps, const GstVideoInfo *info)
> > {
> > - g_autoptr(GstQuery) query = NULL;
> > - g_autoptr(GstBufferPool) pool = NULL;
> > + g_autoptr(GstQuery) query = nullptr;
> > + g_autoptr(GstBufferPool) pool = nullptr;
> > const gboolean need_pool = true;
> >
> > /*
> > @@ -554,8 +554,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
> >
> > if (!gst_pad_peer_query(srcpad, query))
> > GST_DEBUG_OBJECT(self, "Didn't get downstream ALLOCATION hints");
> > - else if (gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL))
> > - return { NULL, 0 };
> > + else if (gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, nullptr))
> > + return { nullptr, 0 };
> >
> > GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame.");
> >
> > @@ -564,7 +564,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
> > * create a new pool.
> > */
> > if (gst_query_get_n_allocation_pools(query) > 0)
> > - gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL);
> > + gst_query_parse_nth_allocation_pool(query, 0, &pool, nullptr,
> > + nullptr, nullptr);
> >
> > if (!pool) {
> > GstStructure *config;
> > @@ -583,7 +584,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
> > GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
> > ("Failed to active buffer pool"),
> > ("gst_libcamera_src_negotiate() failed."));
> > - return { NULL, -EINVAL };
> > + return { nullptr, -EINVAL };
> > }
> >
> > return { reinterpret_cast<GstBufferPool *>(g_steal_pointer(&pool)), 0 };
> > @@ -660,7 +661,7 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
> > for (gsize i = 0; i < state->srcpads_.size(); i++) {
> > GstPad *srcpad = state->srcpads_[i];
> > const StreamConfiguration &stream_cfg = state->config_->at(i);
> > - GstBufferPool *video_pool = NULL;
> > + GstBufferPool *video_pool = nullptr;
> > GstVideoInfo info;
> >
> > g_autoptr(GstCaps) caps = gst_libcamera_stream_configuration_to_caps(stream_cfg, transfer[i]);
> > @@ -1065,7 +1066,7 @@ gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ,
> > const gchar *name, [[maybe_unused]] const GstCaps *caps)
> > {
> > GstLibcameraSrc *self = GST_LIBCAMERA_SRC(element);
> > - g_autoptr(GstPad) pad = NULL;
> > + g_autoptr(GstPad) pad = nullptr;
> >
> > GST_DEBUG_OBJECT(self, "new request pad created");
> >
> > @@ -1079,7 +1080,7 @@ gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ,
> > GST_ELEMENT_ERROR(element, STREAM, FAILED,
> > ("Internal data stream error."),
> > ("Could not add pad to element"));
> > - return NULL;
> > + return nullptr;
> > }
> >
> > gst_child_proxy_child_added(GST_CHILD_PROXY(self), G_OBJECT(pad), GST_OBJECT_NAME(pad));
More information about the libcamera-devel
mailing list