YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
image_compression_ffmpegTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
11#include <yarp/sig/Image.h>
12
14
15#include <array>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21TEST_CASE("pm::image_compression_ffmpegTest", "[yarp::pm]")
22{
23 YARP_REQUIRE_PLUGIN("image_compression_ffmpeg", "portmonitor")
24
26
29
30 struct TestCarrier
31 {
32 std::string carrier;
33 bool mandatory;
34 };
35
36 auto tc = GENERATE(
37 TestCarrier("fast_tcp", true),
38 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+type.dll+recv.portmonitor+file.image_compression_ffmpeg+type.dll",true),
39 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+encoder.mpeg2video+qmin.3+type.dll+recv.portmonitor+file.image_compression_ffmpeg+decoder.mpeg2video+qmin.3+type.dll",true),
40 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+encoder.h264+type.dll+recv.portmonitor+file.image_compression_ffmpeg+decoder.h264+type.dll",false),
41 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+encoder.h265+type.dll+recv.portmonitor+file.image_compression_ffmpeg+decoder.h265+type.dll",false),
42 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+encoder.mjpeg+pixel_format.0+color_range.jpeg+type.dll+recv.portmonitor+file.image_compression_ffmpeg+decoder.mjpeg+pixel_format.0+color_range.jpeg+type.dll",false),
43 TestCarrier("fast_tcp+send.portmonitor+file.image_compression_ffmpeg+encoder.mjpeg+pixel_format.12+strict.-2+type.dll+recv.portmonitor+file.image_compression_ffmpeg+decoder.mjpeg+pixel_format.12+strict.-2+type.dll",false)
44 );
45
46 SECTION("Test that normally the portmonitor is not used")
47 {
50
51 sender.open("/send");
52 receiver.open("/recv");
53
54 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
55 REQUIRE(b);
56
58 imgsend.resize(640, 480);
59 sender.write();
60
61 // Poll for up to 5 seconds with a non-blocking read
62 constexpr double maxWaitSeconds = 5.0;
63 constexpr double pollIntervalSeconds = 0.1;
65 double elapsed = 0.0;
66 while (elapsed < maxWaitSeconds)
67 {
68 imgrecv = receiver.read(/*shouldWait=*/false);
69 if (imgrecv != nullptr)
70 {
71 break;
72 }
73 yarp::os::Time::delay(pollIntervalSeconds);
74 elapsed += pollIntervalSeconds;
75 }
76
77 if (imgrecv != nullptr)
78 {
79 CHECK(imgrecv->width() == 640);
80 CHECK(imgrecv->height() == 480);
81 }
82 else
83 {
84 if (tc.mandatory)
85 {
86 REQUIRE(imgrecv);
87 }
88 else
89 {
90 std::string ss = "Non mandatory test failed with carrier: " + tc.carrier;
91 WARN(ss);
92 }
93 }
94
95 receiver.close();
96 sender.close();
97 }
98
100}
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:751
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1118
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
Typed image class.
Definition Image.h:603
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:387
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
TEST_CASE("pm::image_compression_ffmpegTest", "[yarp::pm]")
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16