Windows .NET SDK - IVideoSettingsContext Events

I’m having trouble getting the event to fire in the IVideoSettingContext wrapper. This is my implementation:

// video_setting_context_wrap.h
class ISettingServiceWrap;
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner);
void UninitIVideoSettingContextFunc(IVideoSettingContext* obj);
BEGIN_CLASS_DEFINE_WITHCALLBACK(IVideoSettingContext, IVideoSettingContextEvent)
NORMAL_CLASS(IVideoSettingContext)
INIT_UNINIT_WITHEVENT_AND_OWNSERVICE(IVideoSettingContext, ISettingServiceWrap)

// function definitions omitted for brevity

CallBack_FUNC_1(onComputerCamDeviceChanged, IList*, pNewCameraList)

END_CLASS_DEFINE(IVideoSettingContext)
END_ZOOM_SDK_NAMESPACE

// video_setting_context_wrap.cpp
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner)
{
	if (pOwner && pOwner->GetSDKObj())
	{
		ZOOM_SDK_NAMESPACE::IVideoSettingContext* pObj = pOwner->GetSDKObj()->GetVideoSettings();
		if (pObj)
		{
			// the following returns SDKERR_SUCCESS
			pObj->SetVideoDeviceEvent(pEvent);
		}

		return pObj;
	}

	return NULL;
}

void UninitIVideoSettingContextFunc(IVideoSettingContext* pObj)
{
	if (pObj)
	{
		pObj->SetVideoDeviceEvent(NULL);
	}
}

I originally asked this question via email and received this response, which I have some questions about:

From the snippet code, we assume that Lenovo is using the same macro_define.h as we do. The most possible reason that the callback event is not fired is that they didn’t wrap the class IVideoSettingContext in a right way. This class should be wrapped in another way. Here is the code snippet for how to wrap IVideoSettingContext. The code also works for IAudioSettingContext.

  1. Make sure to have following codes at the beginning of the video_setting_context_wrap.h. ( Note that we can not use the macro INIT_UNINIT_WITHEVENT_AND_OWNSERVICE here)
class ISettingServiceWrap;
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner);
void UninitIVideoSettingContextFunc(ISettingServiceWrap* obj);
BEGIN_CLASS_DEFINE_WITHCALLBACK(IVideoSettingContext, IVideoSettingContextEvent)
NORMAL_CLASS(IVideoSettingContext)
void Init(ISettingServiceWrap* pOwner) {m_obj = InitIVideoSettingContextFunc(this, pOwner);};
void Uninit(ISettingServiceWrap* pOwner) {UninitIVideoSettingContextFunc(pOwner);m_obj=NULL;};
  1. Make sure to implement the function InitIVideoSettingContextFunc() in video_setting_context_wrap.cpp
IVideoSettingContext* InitIVideoSettingContextFunc(IVideoSettingContextEvent* pEvent, ISettingServiceWrap* pOwner)
{
	if (pOwner && pOwner->GetSDKObj())
	{
		pOwner->SetVideoDeviceEvent(pEvent);
		ZOOM_SDK_NAMESPACE::IVideoSettingContext* pObj = pOwner->GetSDKObj()->GetVideoSettings();

		return pObj;
	}

	return NULL;
}

void UninitIVideoSettingContextFunc(ISettingServiceWrap* pOwner)
{
	if (pOwner)
	{
		pOwner->SetEvent(NULL);
	}
}

In the InitIVideoSettingContextFunc function, you’re calling pOwner->SetVideoDeviceEvent(pEvent). In this case pOwner is a pointer to ISettingServiceWrap, which doesn’t contain the function SetVideoDeviceEvent, it’s defined instead for IVideoSettingContext, so I don’t see how this can work.

@cfrost

Thanks for pointing out the mistake! When I wrote those snippet code, I haven’t VS2015 with me and didn’t test it. Sorry about that!

You are right, we should use pOwner->GetSDKObj()->SetVideoDeviceEvent(pEvent) to set the event handler. It seems that your wrapper has nothing wrong.

There is another reason that the callback isn’t fired. Do you call the CVideoSettingContextDotNetWrap::BindEvent() anywhere? It’s better to call it in the function GetVideoSettings().

If it still does’t work, please let me know. I will try to find out the reason next week.

Regards,
Wilmer

1 Like

No worries, I thought that might be the case.

I do call BindEvent in GetVideoSettings(), and the binding appears to be working.

IVideoSettingContextDotNetWrap^ CSettingServiceDotNetWrap::GetVideoSettings()
{
	if (CVideoSettingContextDotNetWrap::Instance)
	{
		CVideoSettingContextDotNetWrap::Instance->BindEvent();
	}

	return CVideoSettingContextDotNetWrap::Instance;
}

I appreciate any guidance you can provide.

Well, the root cause is that the ISettingServiceWrap is initialized at a wrong place. The setting service only can be initialized successfully once the authentication of zoom sdk is passed.

In zoom_sdk_dotnet_wrap.cpp, remove the following code from the function InitAllService()
ZOOM_SDK_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap().Init();

In auth_service_dotnet_wrap.cpp, add the following code to the success case in the function onAuthenticationReturn()
ZOOM_SDK_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap().Init();
ZOOM_SDK_NAMESPACE::ISettingserviceWrap& settingWrap = ZOOM_SDK_NAMESPACE::CSDKWrap::GetInst().GetSettingServiceWrap();
ZOOM_SDK_NAMESPACE::IVideoSettingContextWrap& videosettingwrap = settingWrap.GetVideoSettings();
videosettingwrap.Init(&settingWrap);

Thus, the callback can be fired.

Regards,
Wilmer

Hi Wilmer,

Yes, I remember when it worked in the SDK demo, it had to be after authentication, so this implementation makes perfect sense.

Much appreciated!
Corey