@@ -154,7 +154,7 @@ In the *meson.build* file, add the *vivid.cpp* file as a build source for
154154libcamera by adding it to the global meson ``libcamera_internal_sources ``
155155variable:
156156
157- .. code-block :: none
157+ .. code-block :: meson
158158
159159 # SPDX-License-Identifier: CC0-1.0
160160
@@ -170,7 +170,7 @@ a comma separated list with ``-Dpipelines`` when generating a build directory:
170170
171171.. code-block :: shell
172172
173- meson build -Dpipelines=ipu3,uvcvideo,vivid
173+ meson setup build -Dpipelines=ipu3,uvcvideo,vivid
174174
175175 Read the `Meson build configuration `_ documentation for more information on
176176configuring a build directory.
@@ -180,7 +180,7 @@ configuring a build directory.
180180To add the new pipeline handler to this list of options, add its directory name
181181to the libcamera build options in the top level ``meson_options.txt ``.
182182
183- .. code-block :: none
183+ .. code-block :: meson
184184
185185 option('pipelines',
186186 type : 'array',
@@ -201,12 +201,12 @@ stub implementations for the overridden class members.
201201 public:
202202 PipelineHandlerVivid(CameraManager *manager);
203203
204- CameraConfiguration *generateConfiguration(Camera *camera,
205- Span<const StreamRole> roles) override;
204+ std::unique_ptr< CameraConfiguration>
205+ generateConfiguration(Camera *camera, Span<const StreamRole> roles) override;
206206 int configure(Camera *camera, CameraConfiguration *config) override;
207207
208208 int exportFrameBuffers(Camera *camera, Stream *stream,
209- std::vector<std::unique_ptr<FrameBuffer>> *buffers) override;
209+ std::vector<std::unique_ptr<FrameBuffer>> *buffers) override;
210210
211211 int start(Camera *camera, const ControlList *controls) override;
212212 void stopDevice(Camera *camera) override;
@@ -221,8 +221,9 @@ stub implementations for the overridden class members.
221221 {
222222 }
223223
224- CameraConfiguration *PipelineHandlerVivid::generateConfiguration(Camera *camera,
225- Span<const StreamRole> roles)
224+ std::unique_ptr<CameraConfiguration>
225+ PipelineHandlerVivid::generateConfiguration(Camera *camera,
226+ Span<const StreamRole> roles)
226227 {
227228 return nullptr;
228229 }
@@ -293,8 +294,7 @@ Run the following commands:
293294
294295.. code-block :: shell
295296
296- meson build
297- ninja -C build
297+ meson compile -C build
298298
299299 To build the libcamera code base, and confirm that the build system found the
300300new pipeline handler by running:
@@ -305,9 +305,9 @@ new pipeline handler by running:
305305
306306 And you should see output like the below:
307307
308- .. code-block :: shell
308+ .. code-block :: text
309309
310- DEBUG Camera camera_manager.cpp:148 Found registered pipeline handler ' PipelineHandlerVivid '
310+ DEBUG Camera camera_manager.cpp:143 Found registered pipeline handler 'vivid '
311311
312312 Matching devices
313313~~~~~~~~~~~~~~~~
@@ -352,7 +352,7 @@ Add the following below ``dm.add("vivid-000-vid-cap");``:
352352
353353.. code-block :: cpp
354354
355- MediaDevice * media = acquireMediaDevice(enumerator, dm);
355+ std::shared_ptr< MediaDevice> media = acquireMediaDevice(enumerator, dm);
356356 if (!media)
357357 return false;
358358
@@ -382,7 +382,7 @@ running
382382
383383.. code-block :: shell
384384
385- ninja -C build
385+ meson compile -C build
386386 LIBCAMERA_LOG_LEVELS=Pipeline,VIVID:0 ./build/src/cam/cam -l
387387
388388 And you should see output like the below:
@@ -423,21 +423,15 @@ it will be used:
423423 class VividCameraData : public Camera::Private
424424 {
425425 public:
426- VividCameraData(PipelineHandler *pipe, MediaDevice *media)
427- : Camera::Private(pipe), media_(media), video_(nullptr)
428- {
429- }
430-
431- ~VividCameraData()
426+ VividCameraData(PipelineHandler *pipe)
427+ : Camera::Private(pipe)
432428 {
433- delete video_;
434429 }
435430
436- int init();
431+ int init(const MediaDevice *media );
437432 void bufferReady(FrameBuffer *buffer);
438433
439- MediaDevice *media_;
440- V4L2VideoDevice *video_;
434+ std::unique_ptr<V4L2VideoDevice> video_;
441435 Stream stream_;
442436 };
443437
@@ -466,9 +460,9 @@ open a single capture device named 'vivid-000-vid-cap' by the device.
466460
467461.. code-block :: cpp
468462
469- int VividCameraData::init()
463+ int VividCameraData::init(const MediaDevice *media )
470464 {
471- video_ = new V4L2VideoDevice(media_ ->getEntityByName("vivid-000-vid-cap"));
465+ video_ = std::make_unique< V4L2VideoDevice>(media ->getEntityByName("vivid-000-vid-cap"));
472466 if (video_->open())
473467 return -ENODEV;
474468
@@ -487,9 +481,9 @@ handler.
487481
488482.. code-block :: cpp
489483
490- std::unique_ptr<VividCameraData> data = std::make_unique<VividCameraData>(this, media );
484+ std::unique_ptr<VividCameraData> data = std::make_unique<VividCameraData>(this);
491485
492- if (data->init())
486+ if (data->init(media.get() ))
493487 return false;
494488
495489
@@ -506,7 +500,8 @@ PipelineHandler successfully matched and constructed a device.
506500.. code-block :: cpp
507501
508502 std::set<Stream *> streams{ &data->stream_ };
509- std::shared_ptr<Camera> camera = Camera::create(std::move(data), data->video_->deviceName(), streams);
503+ const char *id = data->video_->deviceName();
504+ std::shared_ptr<Camera> camera = Camera::create(std::move(data), id, streams);
510505 registerCamera(std::move(camera));
511506
512507 return true;
@@ -521,19 +516,20 @@ Our match function should now look like the following:
521516 DeviceMatch dm("vivid");
522517 dm.add("vivid-000-vid-cap");
523518
524- MediaDevice * media = acquireMediaDevice(enumerator, dm);
519+ std::shared_ptr< MediaDevice> media = acquireMediaDevice(enumerator, dm);
525520 if (!media)
526521 return false;
527522
528- std::unique_ptr<VividCameraData> data = std::make_unique<VividCameraData>(this, media );
523+ std::unique_ptr<VividCameraData> data = std::make_unique<VividCameraData>(this);
529524
530525 /* Locate and open the capture video node. */
531- if (data->init())
526+ if (data->init(media.get() ))
532527 return false;
533528
534529 /* Create and register the camera. */
535530 std::set<Stream *> streams{ &data->stream_ };
536- std::shared_ptr<Camera> camera = Camera::create(std::move(data), data->video_->deviceName(), streams);
531+ const char *id = data->video_->deviceName();
532+ std::shared_ptr<Camera> camera = Camera::create(std::move(data), id, streams);
537533 registerCamera(std::move(camera));
538534
539535 return true;
@@ -897,7 +893,7 @@ Add the following function implementation to your file:
897893 const std::vector<libcamera::PixelFormat> &formats = cfg.formats().pixelformats();
898894 if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) == formats.end()) {
899895 cfg.pixelFormat = formats[0];
900- LOG(VIVID, Debug) << "Adjusting format to " << cfg.pixelFormat.toString() ;
896+ LOG(VIVID, Debug) << "Adjusting format to " << cfg.pixelFormat;
901897 status = Adjusted;
902898 }
903899
@@ -912,13 +908,13 @@ codebase, and test:
912908
913909.. code-block :: shell
914910
915- ninja -C build
911+ meson compile -C build
916912 LIBCAMERA_LOG_LEVELS=Pipeline,VIVID:0 ./build/src/cam/cam -c vivid -I
917913
918914 You should see the following output showing the capabilites of our new pipeline
919915handler, and showing that our configurations have been generated:
920916
921- .. code-block :: shell
917+ .. code-block :: text
922918
923919 Using camera vivid
924920 0: 1280x720-BGR888
@@ -989,8 +985,9 @@ Add the following code beneath the code from above:
989985
990986.. code-block :: cpp
991987
988+ const V4L2PixelFormat fourcc = data->video_->toV4L2PixelFormat(cfg.pixelFormat);
992989 V4L2DeviceFormat format = {};
993- format.fourcc = data->video_->toV4L2PixelFormat(cfg.pixelFormat) ;
990+ format.fourcc = fourcc ;
994991 format.size = cfg.size;
995992
996993 Set the video device format defined above using the
@@ -1007,8 +1004,7 @@ Continue the implementation with the following code:
10071004 if (ret)
10081005 return ret;
10091006
1010- if (format.size != cfg.size ||
1011- format.fourcc != data->video_->toV4L2PixelFormat(cfg.pixelFormat))
1007+ if (format.size != cfg.size || format.fourcc != fourcc)
10121008 return -EINVAL;
10131009
10141010 Finally, store and set stream-specific data reflecting the state of the stream.
@@ -1130,7 +1126,7 @@ prepares the video device accordingly.
11301126Implement the pipeline handler ``start() `` function by replacing the stub
11311127version with the following code:
11321128
1133- .. code-block :: c++
1129+ .. code-block :: cpp
11341130
11351131 VividCameraData *data = cameraData(camera);
11361132 unsigned int count = data->stream_.configuration().bufferCount;
@@ -1262,8 +1258,7 @@ before being set.
12621258 {
12631259 ControlList controls(data->video_->controls());
12641260
1265- for (auto it : request->controls()) {
1266- unsigned int id = it.first;
1261+ for (const auto &[id, v] : request->controls()) {
12671262 unsigned int offset;
12681263 uint32_t cid;
12691264
@@ -1280,7 +1275,7 @@ before being set.
12801275 continue;
12811276 }
12821277
1283- int32_t value = std::lround(it.second .get<float>() * 128 + offset);
1278+ int32_t value = std::lround(v .get<float>() * 128 + offset);
12841279 controls.set(cid, std::clamp(value, 0, 255));
12851280 }
12861281
@@ -1421,7 +1416,7 @@ capture through the pipeline through both of the cam and qcam utilities.
14211416
14221417.. code-block :: shell
14231418
1424- ninja -C build
1419+ meson compile -C build
14251420 ./build/src/cam/cam -c vivid -C5
14261421
14271422 To test that the pipeline handler can detect a device, and capture input.
@@ -1430,7 +1425,7 @@ Running the command above outputs (a lot of) information about pixel formats,
14301425and then starts capturing frame data, and should provide an output such as the
14311426following:
14321427
1433- .. code-block :: none
1428+ .. code-block :: text
14341429
14351430 user@dev:/home/libcamera$ ./build/src/cam/cam -c vivid -C5
14361431 [42:34:08.573066847] [186470] INFO IPAManager ipa_manager.cpp:136 libcamera is not installed. Adding '/home/libcamera/build/src/ipa' to the IPA search path
0 commit comments