2

I'd like some help understanding why my publishers aren't emitting elements through the combineLatest operator. I have a publisher that emits video frames, and another publisher that consumes these video frames and extracts faces from these frames. I'm now trying to combine the original video frames and the transformed output into one using combineLatest (I am using some custom publishers to extract video frames and transform the frames):

let videoPublisher = VideoPublisher //Custom Publisher that outputs CVImageBuffers
.share()

let faceDetectionPublisher = videoPublisher
.detectFaces() // Custom Publisher/subscriber that takes in video frames and outputs an array of VNFaceObservations

let featurePublisher = videoPublisher.combineLatest(faceDetectionPublisher)
.sink(receiveCompletion:{_ in
                print("done")
            }, receiveValue: { (video, faces) in
                print("video", video)
                print("faces", faces)
            })

I'm not getting any activity out of combineLatest, however. After some debugging, I think the issue is that all the videoFrames from videoPublisher are published before any can successfully flow through faceDetectionPublisher. If I attach print statements to the end of the videoPublisher and faceDetectionPublisher, I can see output from the former but none from the latter. I've read up on combine and other techniques such as multicasting, but haven't figured out a working solution. I'd love any combine expertise or guidance on how to better understand the framework!

Christina
  • 51
  • 2
  • Just to clarify -- `.detectFaces()` never produces a printed output? – inokey Nov 02 '19 at 05:18
  • 1
    Can you show how `detectFaces` is implemented? – Sweeper Nov 02 '19 at 09:35
  • detectFaces() emits an output if it's not connected with the combineLatest publisher! For example, something like videoPublisher.detectFaces().sink() results in values fed to sink – Christina Nov 04 '19 at 03:48

1 Answers1

0

Your combineLatest won't emit anything until each of its sources emit at least one value. Since detectFaces() never emits, your chain is stalling. Something is wrong in your detectFaces() operator or maybe there are no faces to detects, in which case your logic is off.

If the latter case, then use prepend on the result of detectFaces() to seed the pipeline with some default value (maybe an empty array?)

Daniel T.
  • 32,821
  • 6
  • 50
  • 72