Click here to Skip to main content
15,888,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone please help me fix the issue of video display hanging on Windows? The issue occurs after both manual and automatic locking of Windows. When I unlock, the video display hangs, but sound is heard and video packets are sent and recieved properly(confirmed from wireshark)


Code works completely fine on Linux.



Thanks in advance,
Faez
Posted
Updated 16-May-12 21:43pm
v2
Comments
Richard MacCutchan 17-May-12 4:14am    
You will need to provide a lot more information than this if you expect any sensible answers.
Faez Shingeri 17-May-12 5:13am    
But No error messages or anything is generated in the logs... and I can't paste the code here also.. :-|
Can you please tell me what more information would be helpful?
Thanks,
Richard MacCutchan 17-May-12 5:23am    
You have given no information on this whatsoever. All we know (or can guess) is that some program that works on Linux hangs on Windows. This is like phoning the garage to say "my car won't start, please fix it".

stib_markc 17-May-12 5:24am    
Did you try debugging? Display hangs for lot of reasons, which can figured out only if you check or provide some code.
Ed Nutting 25-May-12 10:15am    
How about what the program you are using is? Or at least what it's based on? Or have you written it all from scratch yourself? What were you actually trying to do - stream video from a server to a PC but via what? Windows form? Web plugin? There are all the details that and more that we need to be able to answer this properly. If you can't provide these or are prevented from providing the necessary then tell whoever is preventing you that it is their problem or if it's your boss, tell him/her nicely :)

Ed

1 solution

I don't know if you have solved this problem by now and as several people have told you, there is not enough information in your question to really help you out. However, I will take a stab at what could be going on as I fixed something similar 10-11 years ago and if this post does not help you at all, maybe somebody else can bring it to good use some day.

My advice is based on the following guesses:
- You are using DirectDraw to display the video.
- Your video display is in full-screen mode before Windows is locked.

If this is the case, I am betting your DD surfaces are "lost" and you need to restore them again. Basically, Windows takes control of the display, leaving you to do some error handling. See IDirectDrawSurface7::Restore()[^] "Remarks" section.
If am wrong and you are not using DirectDraw, it is probably a similar issue, but a different technology.

You should always check the state of your DD surfaces before operating on them. In DirectDraw based video applications, the video frame is normally written to an off-screen surface and later that surface is "blitted" to the primary (visible) surface - you need to check all your surfaces.

The code below is my quick mix of real and pseudo code without all the actual function parameters and with other standard operations (such as valid pointer checks) eliminated for readability.
Typically, you call PrepareVideoFrame() when you receive a video frame. When it is time to paint it, you call DisplayVideoFrame(). The functions are called from somewhere in your program and you should check the return values to see if there are problems.

The important part is this: When we have to write the video data to the off-screen surface, we first try to lock the surface. If that fails because the surface is lost, we try to restore it and lock it again. If we were unable to lock it on this attempt, we give up - it is very likely that Windows is displaying its "lock screen" and we just have to wait until it releases its hold on the display.
C++
BOOL PrepareVideoFrame(BYTE* pFrame)
{
	// Lock the off-screen surface.
	HRESULT ddErr = m_pOffScreen->Lock();
	if (ddErr != DD_OK)
	{
		// Something is wrong.
		if (ddErr == DDERR_SURFACELOST)
		{
			// The surface is lost.
			// We need to restore it before continuing.
			m_pOffScreen->Restore();

			// Try locking the surface now.
			if (m_pOffScreen->Lock() == DDERR_SURFACELOST)
			{
				// It is still failing. Do not go any further.
				return FALSE;
			}
		}
		else
		{
			// Just exit.
			return FALSE;
		}
	}

/*
Here is where the pFrame data is copied to the surface. Need to account for the surface's pitch as well as the video format.
*/

	// Release the off-screen surface.
	m_pOffScreen->Unlock();

	return TRUE;
}

BOOL DisplayVideoFrame()
{
	// Check the status of the off-screen surface.
	HRESULT ddErr = m_pOffScreen->GetBltStatus(DDGBS_CANBLT);
	if (ddErr != DD_OK && ddErr != DDERR_WASSTILLDRAWING)
	{
		// Something is wrong. Just exit.
		return FALSE;
	}

	// Restore the Primary surface if it is lost.
	if (m_pPrimary->IsLost())
	{
		m_pPrimary->Restore();
	}

	// Display the video frame.
	ddErr = m_pPrimary->Blt(m_pOffScreen);
	if (ddErr != DD_OK)
	{
		return FALSE;
	}

	return TRUE;
}



I hope this helps somebody out there.

Soren Madsen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900