Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

live source in directShow 1

Status
Not open for further replies.

vincenzino

Programmer
Feb 20, 2003
8
SD
I want to render a live source. I have tryed to go to "render URL" and place the URL but the filter graph that is creted does not render the live source. Any ideas on how I could crete a filter graph on the graphEditor to render a live source on the Internet.
P.S. I can render files on the network, the problem is just with live sources.

Thanks
VincenzoDaNapoli
 
Hi Vincenzino

Try reading the capture video sections in the DirectX SDK.

In GraphEdit there should be a selection in the insert Filters named: "Video Capture Sources" This selection contains the installed capture Filters.
If any capture devices are installed they appear under this section. Just select and insert it and render the output pin. You can change the resulting FilterGraph to your liking.

greetings Pjotr
 
If you have a look at the sample code in the directx sdk there is one called texture3D where an avi from the your C drive is streamed and placed as a texture for a cylinder. I would like to stream live video from the internet and place it as the texture. I can do it if I stream a file from the net just by replacing the file path with the URL but when I try to put a URL that contains live videos it tells me it cannot create the graph....
HELP PLEASE...

Bye
Vincenzo
 
Hi,

Have you tried using an URLStreamrenderer to render a video sample from the live source? (Also located in the DirectShow Filters)
 
This is the code that I have. At the moment I am streaming this file (" but if I try to stream (" an example of live source, then it cannot create the filter graph. Any combination I have tryed using the GraphEdit's filters will tell me that I cannot connect the different filters. If I put that URL in the windows media player it will show the video, so it recognises the URL unlike the program..I don't know why...

Thank you very much for the help, and I would be very greatfull I you can help me solve this problem...

Bye
Vincenzo
//-----------------------------------------------------------------------------
// File: DShowTextures.cpp
//
// Desc: DirectShow sample code - adds support for DirectShow videos playing
// on a DirectX 8.0 texture surface. Turns the D3D texture tutorial into
// a recreation of the VideoTex sample from previous versions of DirectX.
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#include "Textures.h"
#include "DShowTextures.h"
#include "DXUtil.h"

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------
//#define SOURCE_FILE TEXT("skiing.avi")

// An application can advertise the existence of its filter graph
// by registering the graph with a global Running Object Table (ROT).
// The GraphEdit application can detect and remotely view the running
// filter graph, allowing you to 'spy' on the graph with GraphEdit.
//
// To enable registration in this sample, define REGISTER_FILTERGRAPH.
//
#define REGISTER_FILTERGRAPH

//-----------------------------------------------------------------------------
// Global DirectShow pointers
//-----------------------------------------------------------------------------
CComPtr<IGraphBuilder> g_pGB; // GraphBuilder

CComPtr<IMediaControl> g_pMC; // Media Control
CComPtr<IMediaPosition> g_pMP; // Media Postion
CComPtr<IMediaEvent> g_pME; // Media Event

D3DFORMAT g_TextureFormat; // Texture format

//-----------------------------------------------------------------------------
// InitDShowTextureRenderer : Create DirectShow filter graph and run the graph
//-----------------------------------------------------------------------------

#define MAX_PATH2 520

HRESULT InitDShowTextureRenderer(LPDIRECT3DTEXTURE8 pTexture)
{
HRESULT hr = S_OK;
CComPtr<IBaseFilter> pFTR; // Texture Renderer Filter
CComPtr<IPin> pFTRPinIn; // Texture Renderer Input Pin
CComPtr<IBaseFilter> pFSrc; // Source Filter
CComPtr<IPin> pFSrcPinOut; // Source Filter Output Pin
CTextureRenderer *pCTR; // DShow Texture renderer
//CComPtr<IAMGraphStreams> pPS;



if (FAILED(g_pGB.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER)))
return E_FAIL;

#ifdef REGISTER_FILTERGRAPH
// Register the graph in the Running Object Table (for debug purposes)
AddToROT(g_pGB);
#endif

// Create the Texture Renderer object
pCTR = new CTextureRenderer(NULL, &hr);
if (FAILED(hr))
{
Msg(TEXT(&quot;Could not create texture renderer object! hr=0x%x&quot;), hr);
return E_FAIL;
}

// Get a pointer to the IBaseFilter on the TextureRenderer, add it to graph
pFTR = pCTR;

if (FAILED(hr = g_pGB->AddFilter(pFTR, L&quot;TEXTURERENDERER&quot;)))
{
Msg(TEXT(&quot;Could not add renderer filter to graph! hr=0x%x&quot;), hr);
return hr;
}

// Determine the file to load based on DirectX Media path (from SDK)
// Use a helper function included in DXUtils.cpp
TCHAR strFileName[MAX_PATH2];
WCHAR wFileName[MAX_PATH2];//C:\Documents and Settings\vincenzot\Desktop


(strFileName, &quot;
lstrcpy(strFileName, &quot;

#ifndef UNICODE
MultiByteToWideChar(CP_ACP, 0, strFileName, -1, wFileName, MAX_PATH2);
int a = 2;
//#else
// lstrcpy(wFileName, strFileName);
#endif
// /*
if (FAILED(hr = g_pGB->RenderFile(wFileName,NULL)))
{
Msg(TEXT(&quot;we guaglio'&quot;), hr);
return hr;
}



// Get the graph's media control, event & position interfaces


g_pGB.QueryInterface(&g_pMC);
g_pGB.QueryInterface(&g_pMP);
g_pGB.QueryInterface(&g_pME);

// Start the graph running;
if (FAILED(hr = g_pMC->Run()))
{
Msg(TEXT(&quot;Could not run the DirectShow graph! hr=0x%x&quot;), hr);
return hr;
}

return S_OK;
}


//-----------------------------------------------------------------------------
// CheckMovieStatus: If the movie has ended, rewind to beginning
//-----------------------------------------------------------------------------
void CheckMovieStatus(void)
{
long lEventCode;
long lParam1;
long lParam2;
HRESULT hr;

// Check for completion events
hr = g_pME->GetEvent(&lEventCode, (LONG_PTR *) &lParam1, (LONG_PTR *) &lParam2, 0);
if (SUCCEEDED(hr))
{
if (EC_COMPLETE == lEventCode)
{
hr = g_pMP->put_CurrentPosition(0);
}

// Free any memory associated with this event
hr = g_pME->FreeEventParams(lEventCode, lParam1, lParam2);
}
}


//-----------------------------------------------------------------------------
// CleanupDShow
//-----------------------------------------------------------------------------
void CleanupDShow(void)
{
#ifdef REGISTER_FILTERGRAPH
// Pull graph from Running Object Table (Debug)
RemoveFromROT();
#endif

// Shut down the graph
if (!(!g_pMC)) g_pMC->Stop();
if (!(!g_pMC)) g_pMC.Release();
if (!(!g_pME)) g_pME.Release();
if (!(!g_pMP)) g_pMP.Release();
if (!(!g_pGB)) g_pGB.Release();
}


//-----------------------------------------------------------------------------
// CTextureRenderer constructor
//-----------------------------------------------------------------------------
CTextureRenderer::CTextureRenderer( LPUNKNOWN pUnk, HRESULT *phr )
: CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
NAME(&quot;Texture Renderer&quot;), pUnk, phr)
{
// Store and AddRef the texture for our use.
*phr = S_OK;
}


//-----------------------------------------------------------------------------
// CTextureRenderer destructor
//-----------------------------------------------------------------------------
CTextureRenderer::~CTextureRenderer()
{
// Do nothing
}


//-----------------------------------------------------------------------------
// CheckMediaType: This method forces the graph to give us an R8G8B8 video
// type, making our copy to texture memory trivial.
//-----------------------------------------------------------------------------
HRESULT CTextureRenderer::CheckMediaType(const CMediaType *pmt)
{
HRESULT hr = E_FAIL;
VIDEOINFO *pvi;

// Reject the connection if this is not a video type
if( *pmt->FormatType() != FORMAT_VideoInfo ) {
return E_INVALIDARG;
}

// Only accept RGB24
pvi = (VIDEOINFO *)pmt->Format();
if(IsEqualGUID( *pmt->Type(), MEDIATYPE_Video) &&
IsEqualGUID( *pmt->Subtype(), MEDIASUBTYPE_RGB24))
{
hr = S_OK;
}

return hr;
}


//-----------------------------------------------------------------------------
// SetMediaType: Graph connection has been made.
//-----------------------------------------------------------------------------
HRESULT CTextureRenderer::SetMediaType(const CMediaType *pmt)
{
HRESULT hr;

// Retrive the size of this media type
VIDEOINFO *pviBmp; // Bitmap info header
pviBmp = (VIDEOINFO *)pmt->Format();
m_lVidWidth = pviBmp->bmiHeader.biWidth;
m_lVidHeight = abs(pviBmp->bmiHeader.biHeight);
m_lVidPitch = (m_lVidWidth * 3 + 3) & ~(3); // We are forcing RGB24

// Create the texture that maps to this media type
if( FAILED( hr = D3DXCreateTexture(g_pd3dDevice,
m_lVidWidth, m_lVidHeight,
1, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &g_pTexture ) ) )
{
Msg(TEXT(&quot;Could not create the D3DX texture! hr=0x%x&quot;), hr);
return hr;
}

// D3DXCreateTexture can silently change the parameters on us
D3DSURFACE_DESC ddsd;
if ( FAILED( hr = g_pTexture->GetLevelDesc( 0, &ddsd ) ) ) {
Msg(TEXT(&quot;Could not get level Description of D3DX texture! hr = 0x%x&quot;), hr);
return hr;
}
g_TextureFormat = ddsd.Format;
if (g_TextureFormat != D3DFMT_A8R8G8B8 &&
g_TextureFormat != D3DFMT_A1R5G5B5) {
Msg(TEXT(&quot;Texture is format we can't handle! Format = 0x%x&quot;), g_TextureFormat);
return VFW_E_TYPE_NOT_ACCEPTED;
}

return S_OK;
}


//-----------------------------------------------------------------------------
// DoRenderSample: A sample has been delivered. Copy it to the texture.
//-----------------------------------------------------------------------------
HRESULT CTextureRenderer::DoRenderSample( IMediaSample * pSample )
{
BYTE *pBmpBuffer, *pTxtBuffer; // Bitmap buffer, texture buffer
LONG lTxtPitch; // Pitch of bitmap, texture

// Get the video bitmap buffer
pSample->GetPointer( &pBmpBuffer );

// Lock the Texture
D3DLOCKED_RECT d3dlr;
if (FAILED(g_pTexture->LockRect(0, &d3dlr, 0, 0)))
return E_FAIL;

// Get the texture buffer & pitch
pTxtBuffer = static_cast<byte *>(d3dlr.pBits);
lTxtPitch = d3dlr.Pitch;

// Copy the bits
// OPTIMIZATION OPPORTUNITY: Use a video and texture
// format that allows a simpler copy than this one.
if (g_TextureFormat == D3DFMT_A8R8G8B8) {
for(int y = 0; y < m_lVidHeight; y++ ) {
BYTE *pBmpBufferOld = pBmpBuffer;
BYTE *pTxtBufferOld = pTxtBuffer;
for (int x = 0; x < m_lVidWidth; x++) {
pTxtBuffer[0] = pBmpBuffer[0];
pTxtBuffer[1] = pBmpBuffer[1];
pTxtBuffer[2] = pBmpBuffer[2];
pTxtBuffer[3] = 0xff;
pTxtBuffer += 4;
pBmpBuffer += 3;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}

if (g_TextureFormat == D3DFMT_A1R5G5B5) {
for(int y = 0; y < m_lVidHeight; y++ ) {
BYTE *pBmpBufferOld = pBmpBuffer;
BYTE *pTxtBufferOld = pTxtBuffer;
for (int x = 0; x < m_lVidWidth; x++) {
*(WORD *)pTxtBuffer = (WORD)
(0x8000 +
((pBmpBuffer[2] & 0xF8) << 7) +
((pBmpBuffer[1] & 0xF8) << 2) +
(pBmpBuffer[0] >> 3));
pTxtBuffer += 2;
pBmpBuffer += 3;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}


// Unlock the Texture
if (FAILED(g_pTexture->UnlockRect(0)))
return E_FAIL;

return S_OK;
}


#ifdef REGISTER_FILTERGRAPH

//-----------------------------------------------------------------------------
// Running Object Table functions: Used to debug. By registering the graph
// in the running object table, GraphEdit is able to connect to the running
// graph. This code should be removed before the application is shipped in
// order to avoid third parties from spying on your graph.
//-----------------------------------------------------------------------------
DWORD dwROTReg = 0xfedcba98;

HRESULT AddToROT(IUnknown *pUnkGraph)
{
IMoniker * pmk;
IRunningObjectTable *pirot;
if (FAILED(GetRunningObjectTable(0, &pirot))) {
return E_FAIL;
}
WCHAR wsz[256];
wsprintfW(wsz, L&quot;FilterGraph %08x pid %08x&quot;, (DWORD_PTR) 0, GetCurrentProcessId());
HRESULT hr = CreateItemMoniker(L&quot;!&quot;, wsz, &pmk);
if (SUCCEEDED(hr)) {
hr = pirot->Register(0, pUnkGraph, pmk, &dwROTReg);
pmk->Release();
}
pirot->Release();
return hr;
}

void RemoveFromROT(void)
{
IRunningObjectTable *pirot;
if (SUCCEEDED(GetRunningObjectTable(0, &pirot))) {
pirot->Revoke(dwROTReg);
pirot->Release();
}
}

#endif


//-----------------------------------------------------------------------------
// Msg: Display an error message box if needed
//-----------------------------------------------------------------------------
void Msg(TCHAR *szFormat, ...)
{
TCHAR szBuffer[512];

va_list pArgs;
va_start(pArgs, szFormat);
_vstprintf(szBuffer, szFormat, pArgs);
va_end(pArgs);

MessageBox(NULL, szBuffer, TEXT(&quot;DirectShow Texture3D Sample&quot;),
MB_OK | MB_ICONERROR);
}
 
Hi,

You are trying to stream an Java Server Page. Does that page contain an multimedia stream (something like mms://). Try looking in the source of the webpage if you can find the real url of the multimedia stream.
I'm browsing the internet with Mozilla on a Unix Server with very thight security, so I can't check out your source. Or connect directly to internet with windows and directshow.

good luck
Pjotr
 
I found the URL but the problem is that there is no extension since it is a live source. I think that this confuses the graph manager since it is waiting for an extension to understand what kind of file it is.

HELP PLEASE
 
Hi,

You don't have a clue in what format the video is broadcasted?

If not, open the stream in the windows media player and look at the properties of the stream. If I'm correct, the mediaplayer lists the filters used by its filtergraph. You can reconsturct these filters in graphedit and try to play the stream.

greetings Pjotr
 
If I check the properties in the Windows media player it tells me only the URL: &quot; and the video codec &quot;Windows Media Video V7&quot;. I cannot build a filter graph cause none of the source filters I try accept such a URL...the main problem i am havin is a source filter. If it is a live video stream in real time should the URL have an extension??

Thaks a lot for ur help

Vincenzo
 
Hi,

Also the URL looks a bit strange. Is it a local Network playing the movie? And it is using the http protocol, which I find a bit strange.
I suggest to use another source in your FilterGraph like:

mms://a1788.v27475.c2747.g.vm.akamaistream.net/7/1788/2747/3cce733e/
For other interested people.
This site hosts a large collection of short movies.

greetings Pjotr
 
I have a used the URL you told me and it works fine. The problem is that I would like to stream a live video; the file at that URL is just a file stored in a server, while I would like to stram a live camera for example, that strams continuosly, and i suppose in that case the file to stream would not have a defined dimension and I am not sure if it would have an extension or not. For example, if a live concert was being stramed over the internet while it is happening, I would like to view the concerts on the walls of my DirectX room.
I am not sure if I am making any sense, hopefully I am.
Thank you so much for the help...

P.S. In the case of a live event, would the URL have an extension? would it have a defined dimension and the content changes while it is happening?

Thanks again

Vincenzo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top