libcamera: stream: Add operator<<() to print StreamRole as a string

libcamera prints stream role values in log messages. To be more
user-friendly, add a specialization of operator<<() to print the role
name as a string instead of a numerical value.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2022-10-23 02:51:10 +03:00
parent c7bbe0ca3a
commit baf3be12ef
2 changed files with 22 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
@ -70,6 +71,8 @@ enum StreamRole {
using StreamRoles = std::vector<StreamRole>;
std::ostream &operator<<(std::ostream &out, StreamRole role);
class Stream
{
public:

View file

@ -417,6 +417,25 @@ std::string StreamConfiguration::toString() const
* acceptable.
*/
/**
* \brief Insert a text representation of a StreamRole into an output stream
* \param[in] out The output stream
* \param[in] role The StreamRole
* \return The output stream \a out
*/
std::ostream &operator<<(std::ostream &out, StreamRole role)
{
static constexpr std::array<const char *, 4> names{
"Raw",
"StillCapture",
"VideoRecording",
"Viewfinder",
};
out << names[static_cast<std::underlying_type_t<StreamRole>>(role)];
return out;
}
/**
* \typedef StreamRoles
* \brief A vector of StreamRole