socket and direct show

D

Dave

Hi,

i am writing a c# application that use direct show to play mpg file but when
i declere a socket in my c# application i just cant play the file enymore,

It seems that the problem is because we are tring to write this lines:

IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];

TcpListener tcpServerListener = new TcpListener(ipAddress,5555);

And not the openning of thread!

When we just try to open or use win sock the file playin is hang like
someone blocking it!!!

The code that play the file is inside managed c++ class assembly the my c#
application link to it,

The c++ code for playing the file:

CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **)&m_pGraph[m_nDevices]);

....

m_pGrabber[m_nDevices].CoCreateInstance( CLSID_SampleGrabber );

CComQIPtr< IBaseFilter, &IID_IBaseFilter >
pGrabBase(m_pGrabber[m_nDevices]);

HRESULT hr = m_pGraph[m_nDevices]->AddFilter( pGrabBase, L"Grabber" );


//Force it to connect to video, 24 bit

CMediaType VideoType;

VideoType.SetType( &MEDIATYPE_Video );

//VideoType.SetSubtype( &MEDIASUBTYPE_RGB24 );

VideoType.SetSubtype( &MEDIASUBTYPE_YUY2 );

hr = m_pGrabber[m_nDevices]->SetMediaType( &VideoType ); // shouldn't fail


hr = m_pGraph[m_nDevices]->QueryInterface(IID_IMediaSeeking, (void
**)&m_pMediaSeeking[m_nDevices]);

hr =m_pMediaSeeking[m_nDevices]->SetTimeFormat(&TIME_FORMAT_FRAME);

// add the grabber to the graph

//hr = m_pGraph[m_nDevices]->AddFilter( pGrabBase, L"Grabber" );

hr = m_pGrabber[m_nDevices]->SetBufferSamples( FALSE );

hr = m_pGrabber[m_nDevices]->SetOneShot( FALSE );

hr = m_pGrabber[m_nDevices]->SetCallback(&mCB[m_nDevices], 1 );



//LPCWSTR str1=(LPCWSTR)str;

hr = m_pGraph[m_nDevices]->RenderFile((LPCWSTR)lstr, NULL);

hr = m_pGraph[m_nDevices]->QueryInterface(IID_IMediaControl, (void
**)&m_pMediaControl[m_nDevices]);


LONGLONG lDuration,lPos,lPos1,llAmount=0;

hr = m_pMediaSeeking[m_nDevices]->SetTimeFormat(&TIME_FORMAT_FRAME);

hr = m_pMediaSeeking[m_nDevices]->GetDuration(&lDuration);

hr = m_pMediaSeeking[m_nDevices]->GetCurrentPosition(&lPos);

hr = m_pMediaSeeking[m_nDevices]->GetStopPosition(&lPos1);


IBasicVideo* pVideo;

hr = m_pGraph[m_nDevices]->QueryInterface(IID_IBasicVideo,(void **)&pVideo);

LONG lWidth, lHeight;

hr = pVideo->GetVideoSize(&lWidth,&lHeight);

REFTIME rtTime;

hr = pVideo->get_AvgTimePerFrame(&rtTime);

double dRate;

dRate = 1.0/rtTime;


llAmount=(LONGLONG)(lPos1/dRate);


// ask for the connection media type so we know how big

// it is, so we can write out bitmaps

//

AM_MEDIA_TYPE mt;

ZeroMemory(&mt,sizeof(mt));

hr = m_pGrabber[m_nDevices]->GetConnectedMediaType( &mt );

VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) mt.pbFormat;

int h=(int)vih->bmiHeader.biHeight;

int w=(int)vih->bmiHeader.biWidth;



FreeMediaType( mt );


//mCB[m_nDevices].m_hWinHwd=g_hwnd;

// Specify the owner window.

m_pGraph[m_nDevices]->QueryInterface(IID_IVideoWindow, (void
**)&m_pWindow[m_nDevices]);

m_pWindow[m_nDevices]->put_Owner((OAHWND)g_hwnd);

m_pWindow[m_nDevices]->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);


RECT grc;

GetClientRect(g_hwnd, &grc);

//::ScreenToClient(&grc);

m_pWindow[m_nDevices]->SetWindowPosition(grc.left, grc.top,
(grc.right-grc.left), (grc.bottom-grc.top));

// Run the graph.

m_pMediaControl[m_nDevices]->Run();

Everything work fine and playing whell until I write the line above to
define the socket, Why???

I am using the

class CSampleGrabberCB : public ISampleGrabberCB

{

....

}

Class for grabing the file frame and when I use the socket it seems that the
callback function of this class or the thread that run this class is beeing
hang because of the declering of the socket!!!

I try every thing and I think that it is a microsoft bug!!!

Do you have any idea???

Thanks!
 
G

Guest

did you try the computer name instead?

Dave said:
Hi,

i am writing a c# application that use direct show to play mpg file but when
i declere a socket in my c# application i just cant play the file enymore,

It seems that the problem is because we are tring to write this lines:

IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];

TcpListener tcpServerListener = new TcpListener(ipAddress,5555);

And not the openning of thread!

When we just try to open or use win sock the file playin is hang like
someone blocking it!!!

The code that play the file is inside managed c++ class assembly the my c#
application link to it,

The c++ code for playing the file:

CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **)&m_pGraph[m_nDevices]);

....

m_pGrabber[m_nDevices].CoCreateInstance( CLSID_SampleGrabber );

CComQIPtr< IBaseFilter, &IID_IBaseFilter >
pGrabBase(m_pGrabber[m_nDevices]);

HRESULT hr = m_pGraph[m_nDevices]->AddFilter( pGrabBase, L"Grabber" );


//Force it to connect to video, 24 bit

CMediaType VideoType;

VideoType.SetType( &MEDIATYPE_Video );

//VideoType.SetSubtype( &MEDIASUBTYPE_RGB24 );

VideoType.SetSubtype( &MEDIASUBTYPE_YUY2 );

hr = m_pGrabber[m_nDevices]->SetMediaType( &VideoType ); // shouldn't fail


hr = m_pGraph[m_nDevices]->QueryInterface(IID_IMediaSeeking, (void
**)&m_pMediaSeeking[m_nDevices]);

hr =m_pMediaSeeking[m_nDevices]->SetTimeFormat(&TIME_FORMAT_FRAME);

// add the grabber to the graph

//hr = m_pGraph[m_nDevices]->AddFilter( pGrabBase, L"Grabber" );

hr = m_pGrabber[m_nDevices]->SetBufferSamples( FALSE );

hr = m_pGrabber[m_nDevices]->SetOneShot( FALSE );

hr = m_pGrabber[m_nDevices]->SetCallback(&mCB[m_nDevices], 1 );



//LPCWSTR str1=(LPCWSTR)str;

hr = m_pGraph[m_nDevices]->RenderFile((LPCWSTR)lstr, NULL);

hr = m_pGraph[m_nDevices]->QueryInterface(IID_IMediaControl, (void
**)&m_pMediaControl[m_nDevices]);


LONGLONG lDuration,lPos,lPos1,llAmount=0;

hr = m_pMediaSeeking[m_nDevices]->SetTimeFormat(&TIME_FORMAT_FRAME);

hr = m_pMediaSeeking[m_nDevices]->GetDuration(&lDuration);

hr = m_pMediaSeeking[m_nDevices]->GetCurrentPosition(&lPos);

hr = m_pMediaSeeking[m_nDevices]->GetStopPosition(&lPos1);


IBasicVideo* pVideo;

hr = m_pGraph[m_nDevices]->QueryInterface(IID_IBasicVideo,(void **)&pVideo);

LONG lWidth, lHeight;

hr = pVideo->GetVideoSize(&lWidth,&lHeight);

REFTIME rtTime;

hr = pVideo->get_AvgTimePerFrame(&rtTime);

double dRate;

dRate = 1.0/rtTime;


llAmount=(LONGLONG)(lPos1/dRate);


// ask for the connection media type so we know how big

// it is, so we can write out bitmaps

//

AM_MEDIA_TYPE mt;

ZeroMemory(&mt,sizeof(mt));

hr = m_pGrabber[m_nDevices]->GetConnectedMediaType( &mt );

VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) mt.pbFormat;

int h=(int)vih->bmiHeader.biHeight;

int w=(int)vih->bmiHeader.biWidth;



FreeMediaType( mt );


//mCB[m_nDevices].m_hWinHwd=g_hwnd;

// Specify the owner window.

m_pGraph[m_nDevices]->QueryInterface(IID_IVideoWindow, (void
**)&m_pWindow[m_nDevices]);

m_pWindow[m_nDevices]->put_Owner((OAHWND)g_hwnd);

m_pWindow[m_nDevices]->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);


RECT grc;

GetClientRect(g_hwnd, &grc);

//::ScreenToClient(&grc);

m_pWindow[m_nDevices]->SetWindowPosition(grc.left, grc.top,
(grc.right-grc.left), (grc.bottom-grc.top));

// Run the graph.

m_pMediaControl[m_nDevices]->Run();

Everything work fine and playing whell until I write the line above to
define the socket, Why???

I am using the

class CSampleGrabberCB : public ISampleGrabberCB

{

....

}

Class for grabing the file frame and when I use the socket it seems that the
callback function of this class or the thread that run this class is beeing
hang because of the declering of the socket!!!

I try every thing and I think that it is a microsoft bug!!!

Do you have any idea???

Thanks!
 
Top