Thread sleep required to make code work

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

bilaldeniz

  • Posts: 2
  • Joined: Tue Jun 15, 2021 2:29 pm
  • Real Name: Bilal Deniz

Thread sleep required to make code work

PostFri Jun 18, 2021 5:23 am

Hi,

I'm testing a very simple C++ console application in Windows to set a particular input and exit.

I find that if I don't add some sort of delay, or further processing after a call to IBMDSwitcherMixEffectBlock::SetProgramInput, then the switching doesn't work.

A 100ms delay seems to be enough. 50ms introduces inconsistencies.

I'm not (deliberately) threading or anything in my code.

If I perform further processing (such as all the stuff printed in the sample DeviceInfo), then I don't need the delay.

It seems like there are some asynchronous operations in the main DLL and exiting suddenly doesn't allow enough time for things to happen.

It seems. I don't like the uncertainty.

Couldn't find anything specific in the docs, apart from the avoiding delays with callbacks.

Christian Schultz had put up some sample code in his "Turn mic input on" thread which also has:

cschultz wrote:
Code: Select all
         // Don't ask me why, but without this delay the code below does not work
            Thread.Sleep(100);


So it seems I'm not the only one.

The issue is the same whether using C++ or C#.

Hoping to eliminate the "yuckiness" in my program.

Bilal
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Thread sleep required to make code work

PostMon Jul 05, 2021 2:01 am

Hi Bilal,

I tested the code and did not observe any difference between code built with or without the thread sleep. Are you observing difference yourself?

In your case of IBMDSwitcherMixEffectBlock::SetProgramInput, rather than adding a fixed delay, it is good practice to implement IBMDSwitcherMixEffectBlockCallback to receive feedback of changes to the mix effect block. In your implementation of IBMDSwitcherMixEffectBlockCallback::Notify, filter for event type bmdSwitcherMixEffectBlockEventTypeProgramInputChanged.

Regards
Cameron
Offline

bilaldeniz

  • Posts: 2
  • Joined: Tue Jun 15, 2021 2:29 pm
  • Real Name: Bilal Deniz

Re: Thread sleep required to make code work

PostMon Jul 05, 2021 4:27 am

Hi Cameron,

Cameron Nichols wrote:I tested the code and did not observe any difference between code built with or without the thread sleep. Are you observing difference yourself?


The plot thickens!

Cameron Nichols wrote:Are you observing difference yourself?


Yes.

I like the idea of the event handler. Good idea for the next iteration. Would still have to sleep and wait for the events or to clean them up (which then makes the delay/sleep thing a non-issue).

Regards,
Bilal

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 20 guests