@@ -81,14 +81,16 @@ struct output::impl
81
81
82
82
bool remove (const spl::shared_ptr<frame_consumer>& consumer) { return remove (consumer->index ()); }
83
83
84
+ size_t consumer_count ()
85
+ {
86
+ std::lock_guard<std::mutex> lock (consumers_mutex_);
87
+ return consumers_.size ();
88
+ }
89
+
84
90
void operator ()(const const_frame& input_frame1,
85
91
const const_frame& input_frame2,
86
92
const core::video_format_desc& format_desc)
87
93
{
88
- if (!input_frame1) {
89
- return ;
90
- }
91
-
92
94
auto time = std::move (time_);
93
95
94
96
if (format_desc_ != format_desc) {
@@ -107,6 +109,18 @@ struct output::impl
107
109
return ;
108
110
}
109
111
112
+ // If no frame is provided, this should only happen when the channel has no consumers.
113
+ // Take a shortcut and perform the sleep to let the channel tick correctly.
114
+ if (!input_frame1) {
115
+ if (!time) {
116
+ time = std::chrono::high_resolution_clock::now ();
117
+ } else {
118
+ std::this_thread::sleep_until (*time);
119
+ }
120
+ time_ = *time + std::chrono::microseconds (static_cast <int >(1e6 / format_desc_.hz ));
121
+ return ;
122
+ }
123
+
110
124
const auto bytesPerComponent1 =
111
125
input_frame1.pixel_format_desc ().planes .at (0 ).depth == common::bit_depth::bit8 ? 1 : 2 ;
112
126
if (input_frame1.size () != format_desc_.size * bytesPerComponent1) {
@@ -204,11 +218,12 @@ output::output(const spl::shared_ptr<diagnostics::graph>& graph,
204
218
{
205
219
}
206
220
output::~output () {}
207
- void output::add (int index, const spl::shared_ptr<frame_consumer>& consumer) { impl_->add (index, consumer); }
208
- void output::add (const spl::shared_ptr<frame_consumer>& consumer) { impl_->add (consumer); }
209
- bool output::remove (int index) { return impl_->remove (index); }
210
- bool output::remove (const spl::shared_ptr<frame_consumer>& consumer) { return impl_->remove (consumer); }
211
- void output::operator ()(const const_frame& frame, const const_frame& frame2, const video_format_desc& format_desc)
221
+ void output::add (int index, const spl::shared_ptr<frame_consumer>& consumer) { impl_->add (index, consumer); }
222
+ void output::add (const spl::shared_ptr<frame_consumer>& consumer) { impl_->add (consumer); }
223
+ bool output::remove (int index) { return impl_->remove (index); }
224
+ bool output::remove (const spl::shared_ptr<frame_consumer>& consumer) { return impl_->remove (consumer); }
225
+ size_t output::consumer_count () const { return impl_->consumer_count (); }
226
+ void output::operator ()(const const_frame& frame, const const_frame& frame2, const video_format_desc& format_desc)
212
227
{
213
228
return (*impl_)(frame, frame2, format_desc);
214
229
}
0 commit comments