Sure. I think I’m already doing that. I’m sending time stamps in both channels:
Video frames channel: (video_frame, source_camera, time_stamp)
Detection channel: (detection_status, source_camera, time_stamp)
Right now I’m merging these two tuples into a single one and sending it along the merged channel:
((video_frame, source_camera, time_stamp), (detection_status, source_camera, time_stamp))
The time stamps accompanying each frame are acting as serial numbers.
Now, that’s really interesting, @tkf .
Maybe I could use multiple dispatch to define two inner methods in the buffer_frames()
function to process the data taken from the merged channel?
function buffer_frames()
function do_work(data::PushFrame)
# Add 'data' (a video frame) to the circular buffer
...
end
function do_work(data::DetectionNotification)
# Use the frame buffer to create a video on disk
end
for data in incoming_channel
do_work(data)
end
end
tkf
September 26, 2021, 10:30pm
23
Yes, multiple dispatch works pretty well for this. You can also do simple if _ isa _
dispatch:
for data in incoming_channel
if data isa PushFrame
...
else
@assert data isa DetectionNotification
...
end
end
Both approaches are supported by the compiler very well.
I thought of using if isa ...
as well, but I thought that was considered bad programming practice. It certainly reminds me from my old Python days…
Hi @tkf ,
Just out of curiosity: could FLoops.jl help me with any of this or is it meant specifically for data parallelism problems?
Thanks a lot for all your help with this.
tkf
September 27, 2021, 12:48am
26
Yes, FLoops.jl is for data parallelism (plus sequential loops). FLoops.jl doesn’t help much if you are juggling channels.