Showing posts with label Directshow Editing Services. Show all posts
Showing posts with label Directshow Editing Services. Show all posts

Tuesday, April 10, 2012

DirectX Transform Editing Services

http://sworks.com/keng/da/multimedia/dtrans/c++/ - we can have the code for the DirectX Transform samples
http://com.it-berater.org/COM/webbrowser/filters_reference.htm

Thursday, May 03, 2007

Enumerating the List of DirectX transform Effects in a system

I developed the sample application to enumerate the list of filters already available in a system.

I added tne strmiids.lib for this application.

CLSID_VideoEffects1Category - 1 input filters
CLSID_VideoEffects2Category - 2 input filters


The "Video Effects (1 input)" and "Video Effects (2 inputs)" categories contain video effects and transitions for DirectShow Editing Services.


we can search the following GUIDs in a registry.

it is in the following category
HKEY_CURRENT_USER->Software-> Microsoft ->ActiveSetup ->Active movie ->DevEnum->{CC7BFB42-F175-11D1-A392-00E0291F3959}(CLSID_VideoEffects1Category ->have the
list of filters available in a system.


#include "atlbase.h"
#include "dshow.h"
#include "conio.h"


EXTERN_GUID(CLSID_VideoEffects1Category, 0xcc7bfb42, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);
EXTERN_GUID(CLSID_VideoEffects2Category, 0xcc7bfb43, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);

/*
EXTERN_GUID(CLSID_VideoEffects1Category, 0xcc7bfb42, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);
EXTERN_GUID(CLSID_VideoEffects2Category, 0xcc7bfb43, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);
EXTERN_GUID(CLSID_AudioEffects1Category, 0xcc7bfb44, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);
EXTERN_GUID(CLSID_AudioEffects2Category, 0xcc7bfb45, 0xf175, 0x11d1, 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59);

*/

// Enumerate all of the effects.
HRESULT EnumerateEffects(CLSID searchType)
{
// Once again, code stolen from the DX9 SDK.

// Create the System Device Enumerator.
ICreateDevEnum *pSysDevEnum = NULL;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
{
return hr;
}

// Obtain a class enumerator for the effect category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(searchType, &pEnumCat, 0);

if (hr == S_OK)
{
// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
// Bind the first moniker to an object.
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropBag);
if (SUCCEEDED(hr))
{
// To retrieve the filter's friendly name, do the following:
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
wprintf(L"Effect: %s\n", varName.bstrVal);
}
VariantClear(&varName);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
return hr;
}

// A very simple program to list DES effects using DirectShow.
//
int main(int argc, char* argv[])
{

// Initialize the COM library.
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
// We'll send our error messages to the console.
printf("ERROR - Could not initialize COM library");
return hr;
}

// OK, so now we want to build the filter graph
// using an AudioCapture filter.
// But there are several to choose from,
// so we need to enumerate them, then pick one.
hr = EnumerateEffects(CLSID_VideoEffects1Category);

getch();
hr = EnumerateEffects(CLSID_VideoEffects2Category);
CoUninitialize();
getch();


return 0;
}

Wednesday, May 02, 2007

DirectX Transform Experiences

1.I tried the Flip() using the DirectX transform filter

Execute() method of a transform filter is failed..
Now I am working with this...


1.Identify whether it is possible to work with DirectX transform filter

Just copy the input surface image to the output surface image.


C:\Program Files \ IE6_LIB\
dtbase.h - these two files have the CDXBaseNTo1 class
dtbase.cpp

Any number of input image and only one output image...

Working WorkProc() fn
-----------------------------------

HRESULT CDXTWipe::WorkProc( const CDXTWorkInfoNTo1& WI, BOOL* pbContinue )
{
HRESULT hr = NOERROR;

HDC hdc1;
HDC hdc2;

OutputDebugString("\n CDXTWipe::WorkProc() fn");
hr = InputSurface(0)->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&ppSurf);
if(ppSurf == NULL)
{
OutputDebugString("\n InputSurface(0)->GetDirectDrawSurface() failed");
return E_FAIL;
}
hr = OutputSurface()->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&ppSurfOut);

if(ppSurfOut == NULL)
{
OutputDebugString("\n OutputSurface()->GetDirectDrawSurface() failed");
return E_FAIL;
}
// hr = ppSurfOut->Flip((LPDIRECTDRAWSURFACE)&ppSurf,DDFLIP_DONOTWAIT);



ppSurf->GetDC(&hdc1);
ppSurfOut->GetDC(&hdc2);
BitBlt(hdc2,0,0,300,300,hdc1,0,0,SRCCOPY);
TextOut(hdc2,10,10,"Sundar",6);
OutputDebugString("\n End of CDXTWipe::OnExecute() fn");

return hr;

}



we are deriving our DirectX transform filter from CDXBaseNTo1 class..


it takes n number of input images and produce only one output. IDXSurface interface wrapped the IDirectDrawSurface interface.


We can retrieve the input interface in a CDXBaseNTo1 class derived class as follows

IDirectDrawSurface* g_pSurfIn;
InputInterface(0) ->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&g_pSurfIn);


we can retrieve the second surface interface (image) using

InputInterface(1)

OutputInterface() - used to retrieve output surface.


we can use DirectDraw or GDI mechanism to add effects to the filter....


we can query the DirectDrawSurface using the following from the IDXSurface interface.



IDirectDrawSurface* g_pSurfIn;
InputInterface(0) ->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&g_pSurfIn);

Afterwards...

HDC hdc1;
g_pSurfIn->GetDC( &hdc1); //Get the Device context from the IDirectDrawSurface and next use the GDI functions to change the image



CDXBaseNTo1 class has Execute() fn...

Actually from the client application, we call this method for executing the transform..

this will in turn calls the


OnInitInstData()
WorkProc()
OnFreeInstData()

CDXBaseNTo1 also has the OnExecute() fn.

These three functions are virtual functions, So the derived class can change the behavior of the execution.

OnExecute() fn is not called. I wasted my time to focus on it...

But During execution, it is not called.

Execute()
{
OnInitInstData() - Init instance data
WorkProc() - This will contains the transformation code.For RGB to Gray filter
-RGB to Gray conversion is done here.

OnFreeInstData() - instance data to be released
}



How can we get the IDXSurface width and height ?


The CDXBnds template class is used to simplify construction and manipulation of the DXBNDS structure.


CDXDBnds InBounds(InputSurface(0), hr);
SIZE m_InputSize;


if (SUCCEEDED(hr))
{
InBounds.GetXYSize(m_InputSize);
}
m_InputSize has width and height of the inputSurface 0


we can identify whether the DirectDrawSurface can be flipped or not using the

GetFlipStatus() fn of the IDirectDrawSurface interface.


IDXSurface* g_pInSurfA;
IDXSurface* g_pInSurfB;




Error in IDXTransform:: Setup () fn:
------------------------------------------------------



Actually I developed the filter from the

CDXBaseNTo1 class.
In that filter

m_ulMaxInputs = 2; //These two are the members of CDXBaseNTo1 class
m_ulNumInRequired = 2;

while calling the IDXTransform interface method
Setup() fn used to pass the argument to the filter.

IUnknown* In[1];
IUnknown* Out[1];
In[0] = g_pInSurfA;
//In[1] = g_pInSurfB;
Out[0]= g_pOutSurf;
hr = g_pWipeTrans->Setup( In, 1, Out, 1, 0 );
//one input and one output


Even though I set it, the Setup() fn failed.

I changed the values as follows :

m_ulMaxInputs = 1;
m_ulNumInRequired = 1;


How can we do the DirectX transform filters :
Within DirectX transform filters we can do transform in the following ways :

1.GDI
2.GDI+
3.OpenCV
4.DirectDraw
5.Direct3D


How can we use t the the Device context from the IDXSurface ?
follow these three steps to use the device context from IDXSurface:

1.Get the DirectDraw Surface from the valid IDXSurface
2.Get the Device context from the DirectDraw Surface.
3.After processing release Device context using DirectDraw Surface.


Check this Process in the following Code :

IDirectDrawSurface* ppSurf, *ppSurfOut;
SIZE m_OutputSize;

HRESULT CDXTWipe::OnInitInstData( CDXTWorkInfoNTo1 &WorkInfo, ULONG &ulNumBandsToDo)
{
HRESULT hr = NOERROR;



//1. Get the DirectDraw Surface from the valid IDXSurface
hr = InputSurface(0)->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&ppSurf);
if(ppSurf == NULL)
{
OutputDebugString("\n InputSurface(0)->GetDirectDrawSurface() failed");
return E_FAIL;
}
hr = OutputSurface()->GetDirectDrawSurface(IID_IDirectDrawSurface,(void**)&ppSurfOut);

if(ppSurfOut == NULL)
{
OutputDebugString("\n OutputSurface()->GetDirectDrawSurface() failed");
return E_FAIL;
}

CDXDBnds outBnds(OutputSurface(),hr); // To get the output surface's width and height

if(SUCCEEDED(hr))
{
outBnds.GetXYSize(m_OutputSize);
}

return hr;

}

HRESULT WorkProc()
{
HRESULT hr = S_OK;

//2.Get the Device Context from the DirectDrawSurface

ppSurf->GetDC(&hdcInput);
ppSurfOut->GetDC(&hdcOutput);

//Processing

BitBlt(hdcOutput,0,0,m_OutputSize.cx,m_OutputSize.cy,hdcInput,0,0,SRCCOPY);
TextOut(hdcOutput,10,10,"Sundar",6);

// 3.After processing release Device context using DirectDraw Surface.
//release DC
ppSurf->ReleaseDC(hdcInput);
ppSurfOut->ReleaseDC(hdcOutput);

return hr;

}

Tuesday, May 01, 2007

DirectX Transform Sample application

CoInitialize(NULL);
CoUnitialize();


IDXTransformFactory* g_pTransFact;
IDXSurfaceFactory* g_pSurfFact;
IDXTransform* g_pWipeTrans;

IDXSurface* g_pInSurfA;
IDXSurface* g_pInSurfB;
IDXEffect* g_pEffect;


BOOL ReadImageFile (IDXSurface **lplpDXSurf, PTSTR pstrFileName)
{
WCHAR pwcsBuffer[256] ;
HRESULT hr;
char szString[256];

#ifndef UNICODE
mbstowcs( pwcsBuffer, pstrFileName, strlen(pstrFileName)+1 );
#endif

// Load Input surfaces
hr = g_pSurfFact->LoadImage( pwcsBuffer, NULL, NULL,
&DDPF_PMARGB32, IID_IDXSurface, (void**)lplpDXSurf );

if (FAILED(hr))
{
wsprintf(szString, "Couldn't load image! hr=0x%08x", hr);
MessageBox(g_hDlg, szString, _T("Error Loading"), MB_ICONERROR );
}

return SUCCEEDED( hr );
}



//Create the transform factory

hr = CoCreateInstance( CLSID_DXTransformFactory,
NULL,
CLSCTX_INPROC,
IID_IDXTransformFactory,
(void**) &g_pTransFact );

_ASSERTE( g_pTransFact != NULL);


if(SUCCEEDED(hr))
{

//--- Get the surface factory interface
hr = g_pTransFact->QueryService( SID_SDXSurfaceFactory,
IID_IDXSurfaceFactory,
(void**) & g_pSurfFact
);

_ASSERTE ( g_pSurfFact != NULL);

}


//Create the Wipe transform and set it up...


if(SUCCEEDED(hr))
{
hr = g_pTransFact->CreateTransform( NULL,
0,
NULL,
0,
NULL,
NULL,
CLSID_DXTWipe,
IID_IDXTransform,
(void**)&g_pWipeTrans
);

_ASSERTE( g_pWipeTrans != NULL);


}

// Get the Effect interface. We'll use this to set
// execution properties for the effect (ie PercentComplete, Duration)

if( SUCCEEDED(hr))
{
hr = g_pWipeTrans ->QueryInterface( IID_IDXEffect,
(void**) &g_pEffect
);

_ASSERTE( g_pEffect != NULL);

}

int width = 400;
int height = 400;
CDXDBnds bnds;
bnds.SetXYSize( width, height);

hr = g_pSurfFact->CreateSurface( NULL,
NULL,
&DDPF_PMARGB32,
&bnds,
0,
NULL,
IID_IDXSurface,
(void**) g_pSurfFact );


ReadImageFile(g_pInSurf1,"test.png");
ReadImageFile(g_pInSurf2,"test2.png");



void HandlePlayForward()
{
float PercentComplete = 0;

do
{
g_pEffect->put_progress(PercentComplete);
PercentComplete = PercentComplete + 0.1f;
}
while( PercentComplete <= 1.0);


}

Monday, April 30, 2007

DirectX transform with IDXSurface

I added the

dxtransguid.h
dxTmsftGuid.h

files to the C:\Program Files\ IE6_LIB\ Include directory



http://msdn2.microsoft.com/en-us/library/aa753550.aspx -


1.Understand the Inner workings of an WipeDlg application
2. How to load the raw buffer data to the input Surfaces ?...
3.Retrieve the Raw buffer from Output Surface ...


Use IDXARGBReadPtr
IDXARGBReadWritePtr interface


two ways to create the Image from the Raw Data... IDXSurfaceFactory interface...

1.CreateSurface() fn
2.CreateFromDDSurface() fn


Set of Processes involved in it :
--------------------------------------------
1.Create an offscreen surface
2.Create the HBITMAP from Raw buffer
3.Get the DC of an Offscreen surface
4.Select the raw buffer's HBITMAP to the offscreen surface DC.




DirectX Transform filters :
-----------------------------------------
DES(Directshow Editing Services) uses the DirectX transform filters.


Advantages of DirectX transform filters :
--------------------------------------------------------------

1.DES uses DirectX transform filters

2.it supports transform in HTML also
3.this also enables to use graphics processor to accelearate some of the transforms
4.mostly PC games use graphics processor hardware and most of the time is idle.
5.Graphics processor is equipped withn high performace processor and some of the effects can be done in realtime.
mostly PC games use that hardware.
6. it supports graphics processor from NVIDIA and ATI develope their own language for this.
7.graphics processor supports PC Games...
8. DirectX transform filter is used with DirectD raw so much more efficient than DirectShow baseclasses derived filters