YODAU 1.0
YEAR OF THE DEPEND ADULT UNDERGARMENT
Loading...
Searching...
No Matches
yodau::backend::stream Class Reference

Represents a single video stream and its analytic connections. More...

#include <backend/include/stream.hpp>

Public Member Functions

 stream (std::string path, std::string name, const std::string &type_str={}, bool loop=true)
 Construct a stream description.
 stream (const stream &)=delete
 Non-copyable (streams manage shared connections / mutex).
streamoperator= (const stream &)=delete
 Non-copyable (streams manage shared connections / mutex).
 stream (stream &&other) noexcept
 Move-construct a stream.
streamoperator= (stream &&other) noexcept
 Move-assign a stream.
std::string get_name () const
 Get logical stream name.
std::string get_path () const
 Get stream path or URL.
stream_type get_type () const
 Get the stream transport/source type.
bool is_looping () const
 Whether the stream is configured to loop on exhaustion.
void dump (std::ostream &out, bool connections=false) const
 Dump stream metadata to an output stream.
void activate (stream_pipeline pipeline=stream_pipeline::automatic)
 Activate the stream in a pipeline.
stream_pipeline pipeline () const
 Get current pipeline activity of the stream.
void deactivate ()
 Deactivate the stream.
void connect_line (line_ptr line)
 Connect a geometric line to this stream.
std::vector< std::string > line_names () const
 Get a list of names of all connected lines.
std::vector< line_ptrlines_snapshot () const
 Get a snapshot of all connected lines.

Static Public Member Functions

static stream_type identify (const std::string &path)
 Identify stream type from a path/URL.
static std::string type_name (const stream_type type)
 Convert a stream type to a canonical textual name.
static std::string pipeline_name (const stream_pipeline pipeline)
 Convert a pipeline mode to its textual name.

Private Attributes

std::string name
 Logical stream name.
std::string path
 Path or URL to the stream source.
stream_type type
 Detected or user-specified stream type.
bool loop { true }
 Looping behavior for file streams.
stream_pipeline active { stream_pipeline::none }
 Currently active pipeline mode.
std::unordered_map< std::string, line_ptrlines
 Connected lines keyed by their logical names.
std::mutex lines_mtx
 Mutex guarding lines.

Detailed Description

Represents a single video stream and its analytic connections.

A stream owns metadata about where it comes from (path, type), whether it should loop when exhausted, and which pipeline (if any) it is currently active in.

The stream also maintains a set of connected geometric lines (tripwires / ROIs), identified by their logical names.

Thread-safety:

  • All access to connected lines is synchronized via lines_mtx.
  • Non-line metadata (name/path/type/loop/active) is not internally synchronized.

Definition at line 64 of file stream.hpp.

Constructor & Destructor Documentation

◆ stream() [1/3]

yodau::backend::stream::stream ( std::string path,
std::string name,
const std::string & type_str = {},
bool loop = true )

Construct a stream description.

The actual stream_type is determined as:

  1. Detect type from path using identify().
  2. If type_str is empty or matches detected type name, use the detected type.
  3. Otherwise try to parse type_str as an explicit override. Unknown strings fall back to detection.
Parameters
pathStream path or URL.
nameLogical stream name/identifier.
type_strOptional textual override ("local", "file", "rtsp", "http").
loopWhether file-based streams should loop on end-of-file.

Definition at line 5 of file stream.cpp.

9 : name(std::move(name))
10 , path(std::move(path))
11 , loop(loop)
13 const auto detected = identify(this->path);
14
15 if (type_str.empty() || type_str == type_name(detected)) {
16 this->type = detected;
17 } else if (type_str == "local") {
19 } else if (type_str == "file") {
20 this->type = stream_type::file;
21 } else if (type_str == "rtsp") {
22 this->type = stream_type::rtsp;
23 } else if (type_str == "http") {
24 this->type = stream_type::http;
25 } else {
26 this->type = detected;
27 }
28}
std::string name
Logical stream name.
Definition stream.hpp:222
bool loop
Looping behavior for file streams.
Definition stream.hpp:231
std::string path
Path or URL to the stream source.
Definition stream.hpp:225
static std::string type_name(const stream_type type)
Convert a stream type to a canonical textual name.
Definition stream.cpp:73
static stream_type identify(const std::string &path)
Identify stream type from a path/URL.
Definition stream.cpp:60
stream_type type
Detected or user-specified stream type.
Definition stream.hpp:228
stream_pipeline active
Currently active pipeline mode.
Definition stream.hpp:234

References active, yodau::backend::file, yodau::backend::http, yodau::backend::local, loop, yodau::backend::none, yodau::backend::rtsp, type, and type_name().

Here is the call graph for this function:

◆ stream() [2/3]

yodau::backend::stream::stream ( const stream & )
delete

Non-copyable (streams manage shared connections / mutex).

◆ stream() [3/3]

yodau::backend::stream::stream ( stream && other)
noexcept

Move-construct a stream.

Moves metadata and connected lines. The moved-from object remains valid but in an unspecified state.

Definition at line 30 of file stream.cpp.

31 : name(std::move(other.name))
32 , path(std::move(other.path))
33 , type(other.type)
34 , loop(other.loop)
35 , active(other.active) {
36
37 std::scoped_lock lock(other.lines_mtx);
38 lines = std::move(other.lines);
39}
std::unordered_map< std::string, line_ptr > lines
Connected lines keyed by their logical names.
Definition stream.hpp:241

References active, loop, stream(), and type.

Referenced by stream().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ activate()

void yodau::backend::stream::activate ( stream_pipeline pipeline = stream_pipeline::automatic)

Activate the stream in a pipeline.

This sets the current active pipeline mode.

Parameters
pipelinePipeline to activate in (default: automatic).

Definition at line 129 of file stream.cpp.

129 {
131}
stream_pipeline pipeline() const
Get current pipeline activity of the stream.
Definition stream.cpp:133

References active.

◆ connect_line()

void yodau::backend::stream::connect_line ( line_ptr line)

Connect a geometric line to this stream.

The line is stored by its line::name. If line is null, the call is ignored.

Parameters
lineShared pointer to an immutable line.

Definition at line 139 of file stream.cpp.

139 {
140 if (!line) {
141 return;
142 }
143 std::scoped_lock lock(lines_mtx);
144 lines.emplace(line->name, line);
145}
std::mutex lines_mtx
Mutex guarding lines.
Definition stream.hpp:244

◆ deactivate()

void yodau::backend::stream::deactivate ( )

Deactivate the stream.

Sets pipeline mode to stream_pipeline::none.

Definition at line 137 of file stream.cpp.

References active, and yodau::backend::none.

◆ dump()

void yodau::backend::stream::dump ( std::ostream & out,
bool connections = false ) const

Dump stream metadata to an output stream.

If connections is true, also prints names of any connected lines.

Parameters
outOutput stream.
connectionsWhether to include connected line names.

Definition at line 106 of file stream.cpp.

108 {
109 out << "Stream(name=" << name << ", path=" << path
110 << ", type=" << type_name(type)
111 << ", loop=" << (loop ? "true" : "false")
112 << ", active_pipeline=" << pipeline_name(active) << ")";
113
114 if (!connections) {
115 return;
116 }
117
118 const auto names = line_names();
119 if (names.empty()) {
120 return;
121 }
122
123 out << "\n\tConnected lines:";
124 for (const auto& ln : names) {
125 out << ' ' << ln;
126 }
127}
std::vector< std::string > line_names() const
Get a list of names of all connected lines.
Definition stream.cpp:147
static std::string pipeline_name(const stream_pipeline pipeline)
Convert a pipeline mode to its textual name.
Definition stream.cpp:85

◆ get_name()

std::string yodau::backend::stream::get_name ( ) const

Get logical stream name.

Definition at line 96 of file stream.cpp.

96{ return name; }

◆ get_path()

std::string yodau::backend::stream::get_path ( ) const

Get stream path or URL.

Definition at line 98 of file stream.cpp.

98{ return path; }

◆ get_type()

yodau::backend::stream_type yodau::backend::stream::get_type ( ) const

Get the stream transport/source type.

Definition at line 100 of file stream.cpp.

100 {
101 return type;
102}

References type.

◆ identify()

yodau::backend::stream_type yodau::backend::stream::identify ( const std::string & path)
static

Identify stream type from a path/URL.

Detection rules (as implemented):

Parameters
pathStream path or URL.
Returns
Detected stream_type.

Definition at line 60 of file stream.cpp.

60 {
61 if (path.rfind("/dev/video", 0) == 0) {
62 return stream_type::local;
63 }
64 if (path.rfind("rtsp://", 0) == 0) {
65 return stream_type::rtsp;
66 }
67 if (path.rfind("http://", 0) == 0 || path.rfind("https://", 0) == 0) {
68 return stream_type::http;
69 }
70 return stream_type::file;
71}

References yodau::backend::file, yodau::backend::http, yodau::backend::local, and yodau::backend::rtsp.

◆ is_looping()

bool yodau::backend::stream::is_looping ( ) const

Whether the stream is configured to loop on exhaustion.

Typically relevant for file streams.

Definition at line 104 of file stream.cpp.

104{ return loop; }

References loop.

◆ line_names()

std::vector< std::string > yodau::backend::stream::line_names ( ) const

Get a list of names of all connected lines.

Returns
Vector of line names.

Definition at line 147 of file stream.cpp.

147 {
148 std::scoped_lock lock(lines_mtx);
149 return lines | std::views::keys
150 | std::ranges::to<std::vector<std::string>>();
151}

◆ lines_snapshot()

std::vector< yodau::backend::line_ptr > yodau::backend::stream::lines_snapshot ( ) const

Get a snapshot of all connected lines.

Returns a stable copy of shared pointers at the time of call.

Returns
Vector of connected line_ptr.

Definition at line 154 of file stream.cpp.

154 {
155 std::scoped_lock lock(lines_mtx);
156 std::vector<line_ptr> out;
157 out.reserve(lines.size());
158 for (const auto& lp : lines | std::views::values) {
159 out.push_back(lp);
160 }
161 return out;
162}

◆ operator=() [1/2]

stream & yodau::backend::stream::operator= ( const stream & )
delete

Non-copyable (streams manage shared connections / mutex).

◆ operator=() [2/2]

yodau::backend::stream & yodau::backend::stream::operator= ( stream && other)
noexcept

Move-assign a stream.

Safely swaps line connections under locks of both objects.

Returns
*this.

Definition at line 42 of file stream.cpp.

42 {
43 if (this == &other) {
44 return *this;
45 }
46
47 std::scoped_lock lock(lines_mtx, other.lines_mtx);
48
49 name = std::move(other.name);
50 path = std::move(other.path);
51 type = other.type;
52 loop = other.loop;
53 active = other.active;
54 lines = std::move(other.lines);
55
56 return *this;
57}

References active, loop, and type.

◆ pipeline()

yodau::backend::stream_pipeline yodau::backend::stream::pipeline ( ) const

Get current pipeline activity of the stream.

Returns
Current stream_pipeline.

Definition at line 133 of file stream.cpp.

133 {
134 return active;
135}

References active.

◆ pipeline_name()

std::string yodau::backend::stream::pipeline_name ( const stream_pipeline pipeline)
static

Convert a pipeline mode to its textual name.

Parameters
pipelinePipeline kind.
Returns
One of: "manual", "automatic", "none", or "unknown".

Definition at line 85 of file stream.cpp.

85 {
86 static constexpr std::array<std::string_view, 3> pipeline_names {
87 "manual", "automatic", "none"
88 };
89 const auto idx = static_cast<size_t>(pipeline);
90 if (idx >= pipeline_names.size()) {
91 return "unknown";
92 }
93 return std::string(pipeline_names[idx]);
94}

◆ type_name()

std::string yodau::backend::stream::type_name ( const stream_type type)
static

Convert a stream type to a canonical textual name.

Parameters
typeStream type.
Returns
One of: "local", "file", "rtsp", "http", or "unknown".

Definition at line 73 of file stream.cpp.

73 {
74 static constexpr std::array<std::string_view, 4> type_names {
75 "local", "file", "rtsp", "http"
76 };
77 const auto idx = static_cast<size_t>(type);
78 if (idx >= type_names.size()) {
79 return "unknown";
80 }
81 return std::string(type_names[idx]);
82}

Referenced by stream().

Here is the caller graph for this function:

Member Data Documentation

◆ active

stream_pipeline yodau::backend::stream::active { stream_pipeline::none }
private

Currently active pipeline mode.

Definition at line 234 of file stream.hpp.

Referenced by activate(), deactivate(), operator=(), pipeline(), stream(), and stream().

◆ lines

std::unordered_map<std::string, line_ptr> yodau::backend::stream::lines
private

Connected lines keyed by their logical names.

Protected by lines_mtx.

Definition at line 241 of file stream.hpp.

◆ lines_mtx

std::mutex yodau::backend::stream::lines_mtx
mutableprivate

Mutex guarding lines.

Definition at line 244 of file stream.hpp.

◆ loop

bool yodau::backend::stream::loop { true }
private

Looping behavior for file streams.

Definition at line 231 of file stream.hpp.

231{ true };

Referenced by is_looping(), operator=(), stream(), and stream().

◆ name

std::string yodau::backend::stream::name
private

Logical stream name.

Definition at line 222 of file stream.hpp.

◆ path

std::string yodau::backend::stream::path
private

Path or URL to the stream source.

Definition at line 225 of file stream.hpp.

◆ type

stream_type yodau::backend::stream::type
private

Detected or user-specified stream type.

Definition at line 228 of file stream.hpp.

Referenced by get_type(), operator=(), stream(), and stream().


The documentation for this class was generated from the following files: