Set the playback speed during playback on Dahua devices

background


I used to be a video surveillance client for many years. For a while, I connected to Dahua, Hikvision, axis, Yichuan and other SDKs, and used them in our own surveillance system.

When the network is unstable, controlling the playback speed is always a headache.
There are two ways to set the playback speed, one is to transmit and calculate according to the speed, and the other is to calculate according to the frame rate.
Because Dahua's sdk uses the frame rate to calculate by default, if it is converted into a rate, the workload is very heavy, and the effort is not thankful. It is better to directly call the interface and set the frame rate.

There is such a workload for setting the rate to just use the original paused state.

the code

void CDevReplay::SetPlaySpeed( DOUBLE dOldSpeed, DOUBLE dNewSpeed )
{
	if(dOldSpeed == dNewSpeed)//不改变原来的速度
	{
		return 0;
	}
	if (dNewSpeed >= (-0.01) && dNewSpeed <= 0.01)
	{
		PauseOrContinue(1);//如果设置为0,暂停;
		return;
	}

	PauseOrContinue(0);
	if (dOldSpeed >= (-0.01) && dOldSpeed <= 0.01)
	{
		if (dNewSpeed < (-1.01) && dOldSpeed >= -8.00)
		{
			SetPlayDirection(TRUE);
			while(dNewSpeed < -1.01)
			{
				FastPlay();
				dNewSpeed += 1.0;
			}
		}
		else if (dOldSpeed <= -0.99 && dOldSpeed >= -1.01)
		{
			NormalPlay();
		}
		else if (dNewSpeed < (-0.01) && dNewSpeed > -0.99)
		{
			SetPlayDirection(TRUE);
			while(dNewSpeed > -1.0)
			{
				SlowPlay();
				dNewSpeed *= 2.0;
			}
		}
		else if ( dNewSpeed > 0.01 && dOldSpeed < 0.99)
		{
			while(dNewSpeed < 1.0)
			{
				SlowPlay();
				dNewSpeed *= 2.0;
			}
		}
		else if (dOldSpeed >= 0.99 && dOldSpeed <= 1.01)
		{
			NormalPlay();
		}
		else if (dOldSpeed > 1.01 && dOldSpeed < 8.00)
		{
			while(dNewSpeed > -1.01)
			{
				FastPlay();
				dNewSpeed -= 1.0;
			}
		}
	}
	else if(dOldSpeed > 0.01)
	{
	...
	}
	else if(dOldSpeed < -0.01)
	{
	...
	}
	return ;
}

void CDevReplay::SetPlaySpeed( DOUBLE dOldSpeed, DOUBLE dNewSpeed )
{
	if(dOldSpeed == dNewSpeed)//不改变原来的速度
	{
		return 0;
	}
	if (dNewSpeed >= (-0.01) && dNewSpeed <= 0.01)
	{
		PauseOrContinue(1);//如果设置为0,暂停;
		return;
	}

	if (dOldSpeed >= (-0.01) && dOldSpeed <= 0.01)
	{
		dOldSpeed = 1.0;
	}
	if (dOldSpeed * dNewSpeed < 0)
	{
		BOOL bBackward = (dNewSpeed < 0);
		SetPlayDirection(bBackward);
		NormalPlay();
		return;
	}

	PauseOrContinue(0);

	LONG nRate = GetFrameRate();
	DOUBLE fZoom = dNewSpeed/dOldSpeed;
	nRate = nRate*fZoom;
	SetFrameRate(nRate);

	return ;
}

LONG CDevReplay::GetFrameRate()
{
	if(0 == m_lPlayBack)return 10;

	int fileframerate = 25;
	int playframerate = 25;
	BOOL bRet = CLIENT_GetFramePlayBack(m_lPlayBack,&fileframerate,&playframerate);
	ATLASSERT(bRet);

	return playframerate;
}

LONG CDevReplay::SetFrameRate( LONG nRate )
{
	if(0 == m_lPlayBack)return 0;

	//设置回放帧率,目前定义的范围是(1~120),超过这个范围返回FALSE
	if (nRate < 1)nRate = 1;

	BOOL bRet =  CLIENT_SetFramePlayBack(m_lPlayBack,nRate);
	ATLASSERT(bRet);

	return 1;
}

Guess you like

Origin blog.csdn.net/lgs790709/article/details/125486440