gstreamer
Loading...
Searching...
No Matches
gstreamer_options.cc
Go to the documentation of this file.
1// gstreamer
2#include "gstreamer_options.h"
4
6#include "gstreamer.h"
7
8// namespace to define options
9namespace gstreamer {
10using std::string;
11using std::vector;
12
13// Implementation summary:
14// Parse the user-provided "gstreamer" option node into normalized
15// GStreamerDefinition objects used later by plugin-loading helpers.
16vector<GStreamerDefinition> getGStreamerDefinition(const std::shared_ptr<GOptions>& gopts) {
17 vector<GStreamerDefinition> goutputs;
18
19 if (!gopts->doesOptionExist("gstreamer")) { return goutputs; }
20
21 // The "gstreamer" option node contains a list of output objects.
22 // Each object is flattened into one GStreamerDefinition:
23 // - format : plugin selector
24 // - filename : output base name
25 // - type : semantic stream type, defaulting to "event"
26 auto goutput_node = gopts->getOptionNode("gstreamer");
27
28 if (!goutput_node || goutput_node.IsNull() || !goutput_node.IsSequence()) { return goutputs; }
29
30 for (auto goutput_item : goutput_node) {
31 goutputs.emplace_back(
32 gopts->get_required_variable_in_option<string>(goutput_item, "format"),
33 gopts->get_required_variable_in_option<string>(goutput_item, "filename"),
34 gopts->get_variable_in_option<string>(goutput_item, "type", "event")
35 );
36 }
37
38 return goutputs;
39}
40
41
42// Implementation summary:
43// Define the gstreamer module options and aggregate the options contributed
44// by dependent modules used together with the streaming layer.
47
48 // User-facing CLI help for the -gstreamer structured option.
49 // The file extension is added automatically by the selected plugin.
50 string help = "Define output formats and filenames. It can be used to select event or stream outputs.\n";
51 help += "The file extension is added automatically based on the format.\n \n";
52 help += "\nSupported formats:\n \n";
53 for (auto& format : GStreamer::supported_formats()) { help += " - " + format + "\n"; }
54 help += "\n \n";
55 help += "Output types:\n \n";
56 help += "\n";
57 help += " - event: write events\n";
58 help += " - stream: write frame time snapshots\n";
59 help += "\n \n";
60 help += "Example that defines two gstreamer outputs:\n \n";
61 help += " -gstreamer=\"[{format: root, filename: out}, {format: csv, filename: out}]\"\n";
62 help += "\n \n";
63 help += "The produced files structure depends on the accumulation method used: \n \n";
64 help += " - event-based digitization (like flux) will have one file for every thread, with \"_t<thread>\" appended to the filename \n";
65 help += " - run-based digitization (like dosimeter) will have one file only\n";
66
67 // Buffer flush limit:
68 // controls how many events each streamer instance may retain in memory
69 // before the base class forces a flush to the backend.
70 string ebuffer_help = "Number of events each streamer keeps in memory before flushing them to the\n";
71 ebuffer_help += "output file. Larger values reduce I/O frequency at the cost of more memory.\n \n";
72 ebuffer_help += "Example: -ebuffer=100\n";
74 "number of events kept in memory before flushing them to the filestream"), ebuffer_help);
75
76 // Schema of each object in the -gstreamer array.
77 vector<GVariable> gstreamer = {
78 {"filename", goptions::REQUIRED, "name of output file. "},
79 {"format", goptions::REQUIRED, "format of output file. "},
80 {"type", "event", "type of output file"},
81 };
82
83 goptions.defineOption("gstreamer", "define a gstreamer output", gstreamer, help);
84
85 // Merge dependent-module options so callers can build a single composite
86 // GOptions definition for applications and examples.
88
89 return goptions;
90}
91}
static const std::vector< std::string > & supported_formats()
Return the list of output format tokens supported by the module.
Definition gstreamer.cc:11
vector< GStreamerDefinition > getGStreamerDefinition(const std::shared_ptr< GOptions > &gopts)
Parse all configured gstreamer output definitions from the options container.
GOptions defineOptions()
Define the options contributed by the gstreamer module.
Shared constants and error codes for the gstreamer module.
Core streaming interface and helper utilities for the gstreamer module.
Option and configuration helpers for the gstreamer module.
constexpr const char * GSTREAMER_LOGGER
Logger category name used by gstreamer components.
GOptions defineOptions()
constexpr RequiredValue REQUIRED
constexpr int DEFAULT_GSTREAMER_BUFFER_FLUSH_LIMIT
Default number of buffered events before a GStreamer instance flushes its internal buffer.