libvdo
vdo-example-channel-filter.cc
#include <vdo-error.h>
#include <vdo-channel.h>
#include <cstdio>
#include <print>
#include <utility>
using std::println;
int main()
try
{
g_autoptr(GError) error = nullptr;
g_autoptr(VdoMap) filter = vdo_map_new();
// Filter for all input channels.
vdo_map_set_string(filter, "key", "input");
g_autolist(VdoChannel) filtered_channels = vdo_channel_get_filtered(filter, &error);
// Differentiate between errors and empty lists.
if (error) {
// Maintenance in progress?
if (!vdo_error_is_expected(&error))
println(stderr, "Failed to get inputs: {}", error->message);
return EXIT_FAILURE;
}
// A valid but empty GList.
if (!filtered_channels) {
println(stderr, "No input channels available.");
return EXIT_FAILURE;
}
// Iterate over all received channels, get and print channel info.
for (GList* iter = filtered_channels; iter != nullptr; iter = iter->next) {
// Automatically destroyed by g_autolist
auto channel = VDO_CHANNEL(iter->data);
g_autoptr(VdoMap) info = vdo_channel_get_info(channel, &error);
if (!info) {
println(stderr, "Failed to get channel info: {}", error->message);
return EXIT_FAILURE;
}
auto channel_id = vdo_channel_get_id(channel);
auto input_id = vdo_map_get_uint32(info, "type.id", 0);
println("Channel {}: Input {}", channel_id, input_id);
}
}
catch(const std::exception& e)
{
std::ignore = fprintf(stderr, "Exception: %s\n", e.what());
return EXIT_FAILURE;
}
A video channel.
A class representing a dictionary mapping keys to values.
A class representing a channel.
GList * vdo_channel_get_filtered(VdoMap *filter, GError **error)
Get all existing channels matching a filter.
VdoMap * vdo_channel_get_info(VdoChannel *self, GError **error)
Get the info for this channel.
guint vdo_channel_get_id(VdoChannel *self)
Get the ID of a VdoChannel.
Definitions related to error reporting, e.g. error codes.
gboolean vdo_error_is_expected(GError **error)
Check if error is expected.
guint32 vdo_map_get_uint32(const VdoMap *self, const gchar *name, guint32 def)
Returns the value which the key name is associated with.
VdoMap * vdo_map_new(void)
Constructs a new empty VdoMap.
void vdo_map_set_string(VdoMap *self, const gchar *name, const gchar *value)
Sets the value associated with the specified key.