Community
cancel
Showing results for 
Search instead for 
Did you mean: 
bcisrd
Beginner
126 Views

C# application crashes on close

Hello,
I have develop a c++ dll which basically encapsulates UMC::H264VideoEncoder and UMC::H264VideoDecoder classes. This dll is used by applications develop in unmanaged c++ and C#. At this time the c++ application functions without errors. On the other hand, the c# application has an issue on closing.

Parameters:
All applications including dll is compiled using Visual Studio 2005
IPP version is 6.1.1.035
IPP sample version 6.0.0.130

Basically the c# application captures video from a web camera using Video Capture Functions defined in avicap32.dll. I have a c# wrapper class for c++ dll which passes video frame to dll to be compress and sends compress frame across the network. While running this app works properly with out error. When I close the c# application I get An unhandled exception of type 'System.AccessViolationException'.

Being that the same dll when used by a c++ application, doing simular task, does not generate execption I believe I am missing something and am hoping someone can direct me on what to look at.

The problem is related to my UMC::H264VideoEncoder class. Previously I had omitted calling UMC::H264VideoEncoders close function, and I periotically would get a crash. Once I added this call the application throws the stated exception everytime.

Here are some code snipits/information:
I am capturing video 640/480 rgb24

//*************************************************************************************************
//C# code
//*************************************************************************************************
[StructLayout(LayoutKind.Sequential)]
public struct VIDEOHEADER
{
public IntPtr lpData;
public uint dwBufferLength;
public uint dwBytesUsed;
public uint dwTimeCaptured;
public uint dwUser;
public uint dwFlags;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray)]
public byte[] dwReserved;
}

public delegate void CallBackDelegate(IntPtr hwnd, ref VIDEOHEADER hdr);
CallBackDelegate delegateFrameCallBack = null;


delegateFrameCallBack = MyCallBack;
if (SendHeaderMessage(m_capwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, delegateFrameCallBack) > 0)



private void FrameCallBack(IntPtr hwnd, ref VIDEOHEADER hdr)
{
if ( (hdr.dwBytesUsed > 0) && (m_bDrawReady) )
{
DrawVideo(hdr.lpData, (int)hdr.dwBytesUsed);
}
}

private void DrawVideo(IntPtr Buf, int nSize)
{
m_MyWrapperDll.DataStream(Buf, nSize);
}

[DllImport("MyDll.dll")]
unsafe private static extern void MyDll_DataStream(IntPtr pBuf, int nSize);
public void DataStream(IntPtr pBuf, int nSize)
{
MyDll_DataStream(pBuf, nSize);
}

//**********************************************************************************************
//C++ Code
//**********************************************************************************************
void __stdcall MyDll_DataStream (unsigned char* pData, int nSize)
{

BYTE *pBuf = g_pMyEncoder->EncodeFrame (pData, nSize);
if(pBuf)
{

delete [] pBuf;
}
}


class CMyEncoder
{
UMC::H264VideoEncoder *m_pvidEncoder;
UMC::VideoData m_inVid;
UMC::VideoData m_outVid;
public:

void Free ();
BYTE* EncodeFrame (BYTE *pData, unsigned long &nSize);
};

void CMyEncoder::Free ()
{
if(m_pvidEncoder)
{
m_pvidEncoder->Close ();
delete m_pvidEncoder;
}
m_outVid.Close ();
m_inVid.Close ();
}

0 Kudos
2 Replies
bcisrd
Beginner
126 Views

There seems to be some issues with both UMC::H264VideoDecoder & UMC::H264VideoEncoder 'Close' function!

UMC::H264VideoDecoder - According to documentation "... method is optional" because it is called by the destructor. My application while running is continually creating and releasing h264decoder instances. Though it runs stable an exception random occurs which causes the application to close. By calling it's 'Close' function from within my code, not depending on the destructor seems to clear this problem!

UMC::H264VideoEncoder - Conversely its documentation does not state that it is optional. So the only conclusion I have is that it is suppose to be called by my code. But, by calling Close it consistently causes an exception to be thrown. Removing the call eliminates the exception and allows the application to close without error. Currently my application opens an encoder and close it 1 time for the life of the process so I dont know if there are issues (memory leaks, resource leaks, ) by not calling Close.
shinjite
Beginner
126 Views

Close on the h264 decoder works, I have it using the threads (4 of them) and for the longest of time - like many eons.. it would crash in library internally. In order to close a decoder you need to empty the internal frames out of the buffer - then close(at least that works for me).

Encoding close? Same thing it just keeps breaking on me wish I knew how to fix it. Well- had time to fix it that is.

Quoting - bcisrd
There seems to be some issues with both UMC::H264VideoDecoder & UMC::H264VideoEncoder 'Close' function!

UMC::H264VideoDecoder - According to documentation "... method is optional" because it is called by the destructor. My application while running is continually creating and releasing h264decoder instances. Though it runs stable an exception random occurs which causes the application to close. By calling it's 'Close' function from within my code, not depending on the destructor seems to clear this problem!

UMC::H264VideoEncoder - Conversely its documentation does not state that it is optional. So the only conclusion I have is that it is suppose to be called by my code. But, by calling Close it consistently causes an exception to be thrown. Removing the call eliminates the exception and allows the application to close without error. Currently my application opens an encoder and close it 1 time for the life of the process so I dont know if there are issues (memory leaks, resource leaks, ) by not calling Close.

Reply