Friday, June 27, 2008
Performance of video rendering in Capture application
-------------------------------------------------------------------------------
I am loading the COM environment for every graph building;
Loading of COM environment and releasing of an environment done by CoInitialize() fn and
CoUninitialize() fn;
it takes much time to render the video in Recorder application ( loading of COM environment every time takes much time);
if I am loading the COM environment everytime that takes much time but if I am loading the COM
environment only once that makes the rendering of video so fast compare to everytime loading of
COM environment;
Error While Releasing the Dshow Filters ( Windows Mobile)
-------------------------------
Data Abort: Thread=8a9e50b4 Proc=88a8b6d0 'RecorderApp.exe'
AKY=00020001 PC=000175f8(RecorderApp.exe+0x000075f8) RA=0001562c(RecorderApp.exe+0x0000562c) BVA=24000008 FSR=00000007
Solution:
----------
Just Stop the Recording using ControlStream() fn and Stop the Media Control ( pMediacontrol->Stop() fn);
and then Release the filters; this error wont occur;
CLSID_VideoCapture Filter Problem in windows Mobile Recorder application
----------------------------------------
I have developed the video capture application;
I have created the object for video capture filter( CoCreateInstance(CLSID_VideoCapture)),
and rendered the video successfully, if I released the video capture filter and created the CoCreateInstance(CLSID_VideoCapture Filter) I got the problem
in
PropertyBag->Load() fn;
CComPtr
CPropertyBag m_PropBag;
CComVariant m_varCamName;
hr = CoCreateInstance( CLSID_VideoCapture, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void** ) &m_pVideoCaptureFilter );
hr = m_pVideoCaptureFilter->QueryInterface( &m_pPropertyBag );
m_varCamName = _T ("CAM1:");
hr = m_PropBag.Write( L"VCapName", &m_varCamName );
hr = m_pPropertyBag->Load( &m_PropBag, NULL);
m_pPropertyBag.Release();
If I released the video capture filter and created the Second time , I got the error in
hr = m_pPropertyBag->Load( &m_PropBag, NULL); fn, it returns error as
" The Specified network resource or device is no longer available"
Solution:
------------
Error Message indicates "Video capture filter was not properly released;"
We need to release it properly;
We are releasing the video Capture Filter properly But it is not released; So Next time we got problems;
So Just confirm it, we have to release the video capture Filters only after all the Streams are stopped;
Code:
---------
For Releasing All the Filters and their Pins use the following code:
For Releasing the Source Filter use the following two methods and release all other things normally;
void CRecorder::NukeDownstream(IBaseFilter *pf)
{
IPin *pP=0, *pTo=0;
ULONG u;
IEnumPins *pins = NULL;
PIN_INFO pininfo;
if (!pf)
return;
HRESULT hr = pf->EnumPins(&pins);
pins->Reset();
while(hr == NOERROR)
{
hr = pins->Next(1, &pP, &u);
if(hr == S_OK && pP)
{
pP->ConnectedTo(&pTo);
if(pTo)
{
hr = pTo->QueryPinInfo(&pininfo);
if(hr == NOERROR)
{
if(pininfo.dir == PINDIR_INPUT)
{
NukeDownstream(pininfo.pFilter);
m_pGraphBuilder->Disconnect(pTo);
m_pGraphBuilder->Disconnect(pP);
m_pGraphBuilder->RemoveFilter(pininfo.pFilter);
}
pininfo.pFilter->Release();
}
pTo->Release();
}
pP->Release();
}
}
if(pins)
pins->Release();
}
void CRecorder::MyNukeDown( IBaseFilter *pFilter )
{
IEnumPins *pEnumPins;
IPin *pPin;
ULONG uNumPin;
HRESULT hr;
do
{
if( NULL == pFilter )
{
break;
}
hr = pFilter->EnumPins(&pEnumPins);
pEnumPins->Reset();
if( FAILED(hr) )
{
break;
}
while( S_OK == pEnumPins->Next( 1, &pPin, &uNumPin ) )
{
hr = m_pGraphBuilder->Disconnect(pPin);
if( S_OK != hr )
{
OutputDebugString(L"\n Disconect Failed");
}
}
m_pGraphBuilder->RemoveFilter( pFilter );
pFilter->Release();
//HELPER_RELEASE( pFilter );
pPin->Release();
pEnumPins->Release();
}while( FALSE );
}
Usage of this code is as follows:
NukeDownstream(m_pVideoCaptureFilter);
MyNukeDown(m_pVideoCaptureFilter);
CHECK_AND_RELEASE_COM_QI(m_pVideoWindow);
#ifdef _STILL
CHECK_AND_RELEASE_COM(m_pIImageSinkFilter);
CHECK_AND_RELEASE_COM(m_pImageSinkFilter);
#endif
CHECK_AND_RELEASE_COM(m_pVideoRenderer);
CHECK_AND_RELEASE_COM(m_pVideoEncoder);
CHECK_AND_RELEASE_COM(m_pVideoCaptureFilter);
Dshow Camera capture application Problem in Windows Mobile
-----------------------------------------------------------
pimg.exe (Pictures and videos) behavior:
-----------------------------------------
if we are writing camera capture application, whenever the user hits Home button, the application must release the
Video and audio Capture Source; whenever the back button is pressed (if available) or Thru Task manager they switch to the Camera application ,
the camera capture application must starts its execution normally (render video from video source);
It makes use of the video and audio capture filters;
So Every camera capture application must follow this behavior;
I am writing the camera capture application, whenever the user hits the Home Button, the application focus is changed;
So The Windows Mobile OS will send the following messages sequentially;
1.WM_ACTIVATE 's WA_INACTIVE
2.WM_ACTIVATE 's WA_ACTIVE
So whenever the user hits the Home button, the WM_ACTIVATE message with WA_INACTIVE fired.
Steps:
-------
1.Home Button was pressed ( that indicates WM_ACTIVATE's WA_INACTIVE),Release the video and audio capture filters in WM_ACTIVATE's WA_INACTIVE and
set the boolean variable bInActive as TRUE;
2.When Back button was pressed, The camera application was focused; But it didnt get any message like focus or Activate app or WM_ACTIVATE message;
So what I did was, whenever our camera application got focus, it must paint the camera application window;
So within WM_PAINT message, I will check if bInActive flag was set, then CreateInstance for the video capture filter and audio capture filter and Starts rendering video;
Dshow Camera capture application Problem in Windows Mobile
Dshow Camera capture application Problem in Windows Mobile:
-----------------------------------------------------------
pimg.exe (Pictures and videos) behavior:
-----------------------------------------
if we are writing camera capture application, whenever the user hits Home button, the application must release the
Video and audio Capture Source; whenever the back button is pressed (if available) or Thru Task manager they switch to the Camera application ,
the camera capture application must starts its execution normally (render video from video source);
It makes use of the video and audio capture filters;
So Every camera capture application must follow this behavior;
I am writing the camera capture application, whenever the user hits the Home Button, the application focus is changed;
So The Windows Mobile OS will send the following messages sequentially;
1.WM_ACTIVATE 's WA_INACTIVE
2.WM_ACTIVATE 's WA_ACTIVE
So whenever the user hits the Home button, the WM_ACTIVATE message with WA_INACTIVE fired.
Steps:
-------
1.Home Button was pressed ( that indicates WM_ACTIVATE's WA_INACTIVE),Release the video and audio capture filters in WM_ACTIVATE's WA_INACTIVE and
set the boolean variable bInActive as TRUE;
2.When Back button was pressed, The camera application was focused; But it didnt get any message like focus or Activate app or WM_ACTIVATE message;
So what I did was, whenever our camera application got focus, it must paint the camera application window;
So within WM_PAINT message, I will check if bInActive flag was set, then CreateInstance for the video capture filter and audio capture filter and Starts rendering video;
Tuesday, June 24, 2008
VS2005 Output Window display Problem
--------------------------------------------------------------
While developing an application in VS2005,
I faced the problem in viewing Output Window; Even though
I have selected View -> Output, that doesnt display the Output Window;
Solution :
-----------
Window-> Reset window layout Now Click the View-> Output displays the
Output window;
Note:
----------
Not Only for Output Window, we can use the same approach for all
windows available in VS 2005.
Thursday, June 19, 2008
WinCE Camera application architecture
-----------------------------------------------------------------------
1.Preview pin is connected to the Video Renderer
2.Capture pin is connected as follows:
Capture Pin -> Video Encoder -> Muxer filter
Normally preview pin will render the video; Capture Pin Stream is
stopped using ControlStream() fn;
whenever the "Start Recording" button was pressed then we need to
Start the capture Pin Stream;
In other words we need to Captured video data to be written into media
file as well as to be rendered on screen;
For doing this, we will connect the filters as follows:
Video Capture Pin -> Video Encoder->Muxer
Audio Capture Pin ->Audio Encoder->Muxer
video Preview pin -> Video Renderer;
Until the user gives "Start Recording" command, we need to Stop the
Stream in Video capture and Audio Capture pin;
we need to Start them only when the user gives "Start Recording";
if No media file was recorded, then during the connection itself the
muxer filter will creates an empty file;
we need to delete it ; if No media file was recorded, then the current
filename is to be deleted from the file system;
This is what we have done ;
WinCE Live Capture ControlStream problem
------------------------
m_pCaptureGraphBuilder2->ControlStream //Stop the capture Pin
(
&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video,
m_pVideoCaptureFilter,
&rtStart,
&rtStop,1,2
);
ControlStream of Live Source will do the Start and Stop of the Stream;
0,MAXLONGLONG - To Start the Stream
MAXLONGLONG,0 - To Stop the Stream;
Problem :
----------
1. I have Stopped the Capture Pin and Started the Preview Pin using
ControlStream() fn;
it gives the Black rectangle instead of rendering video;
Solution;
---------
I have deeply analyzed the Stream;
Reason for the problem is I have not Started the MediaControl using
Run() method;
if I called the IMediaControl's Run() method it works fine;
HRESULT StartPreview()
{
HRESULT hr = S_OK;
REFERENCE_TIME rtPreviewStart = 0,rtPreviewStop = MAXLONGLONG;
REFERENCE_TIME rtStart, rtStop;
rtStart = MAXLONGLONG;
rtStop = 0;
hr = m_pCaptureGraphBuilder2->ControlStream //Stop the capture Pin
(
&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video,
m_pVideoCaptureFilter,
&rtStart,
&rtStop,1,2
);
if(FAILED(hr))
{
printf("\n VideoControlStream() Stop Failure Error Code:%x",hr);
return hr;
}
//Start the Preview Stream
hr = m_pCaptureGraphBuilder2->ControlStream( &PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video,
m_pVideoCaptureFilter,
&rtPreviewStart, // Start now.
&rtPreviewStop, // (Don't care.)
3,4
);
if(FAILED(hr))
{
printf("\n ControlStream() fn Error : %x",hr);
return hr;
}
hr = m_pCaptureGraphBuilder2->ControlStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Audio,
m_pAudioCaptureFilter,
&rtStart, // Start now.
&rtStop, // (Don't care.)
5,6
);
if(FAILED(hr))
{
printf("\n Audio ControlStream() Stop Failure Error Code:%x",hr);
return hr;
}
}
if(m_pMediaControl)
{
m_pMediaControl->Run();
}
return hr;
}
Tuesday, June 17, 2008
WinCE Directshow Video Capture application Problem
RenderStream() fn executed without giving any problem for the first
time; During the second time, RenderStream() fn I got an error as
E_FAIL
Solution:
------------------
1.CLSID_VideoCapture ( Video Source Filters CoCreateInstance
must be called only once in a program otherwise we will get
RenderStream() fn failure error;
whenever we reconstruct the filter graphs by releasing filters in a
filter graph.
2.But For VideoCapture source filter we need to create the
object (using CoCreateInstance) and we have to use that object thru
out the application.
otherwise we will get RenderStream() fn failure message;