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 creat socket member and
not by openning a thread, we 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!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OE**************@TK2MSFTNGP09.phx.gbl...
Dave,
Again, without seeing what you are trying to do, it is impossible to
help you. There is no such thing as "regular direct show code" or
"regular code" for that matter. Everyone codes different, and not
everyone codes the same way (and that's assuming they are doing the right
thing).
Are you trying to run the filter graph from another thread? If so, is
that thread initialized to use com? Also, are you trying to update the UI
from that thread? Obviously, there are many questions which are more
easily answered with a complete example, since there is so much that can
go wrong.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <be******@netvision.net.il> wrote in message
news:uq**************@tk2msftngp13.phx.gbl... Hi,
The code for playing the file is regular direct show code that use the
SampleGrabber to get the frames from the file, i wrote it inside a c++
managed dll that i connect it from the c# gui application,
I dont getting any error when i am creating new thread but i just get
black
image from the file and it seems the it is not calling to the
ISampleBuffer!
Thanks,
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:#y*************@TK2MSFTNGP15.phx.gbl... Dave,
Can you post the relevant sections of code, or better yet, a
complete
dong example of what is causing the error? It's nearly impossible to
determine
the error without seeing any of what you are doing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <be******@netvision.net.il> wrote in message
news:OZ*************@TK2MSFTNGP10.phx.gbl...
> Hi,
> I am writing a c# application that using a directshow to play file and
> display it on my C# gui, its work just fine but when i try to open
another > thread in my c# application the file stop playing and i get black
image!!! > Why?
> What i should considre when i open a new thread in c# application??
>
> Thanks
>
>