Windows CE Blog |

Archive for March 2010

Mar/10

30

Performance Tuning on DirectShow Camera Application

Windows CE 6.0 supports DirectShow® components to develop a rich camera application. A minimum requirement of the camera application is to show preview, capturing the still images which is stored as a compressed file (JPG) format, capturing/multiplexing the video with or without audio i.e. stored as a compressed file (WMV) format.

Windows CE 6.0 provides sample applications for showing preview, capturing still and video using DirectShow® components. However these sample applications doesn’t cover all the aspects to develop a commercial application. A commercial camera application at least satisfies the following performance criteria.

  1. Video Captured with sufficient frame rate.
  2. User acceptable video processing time. Video processing involves converting and compressing the video frames to WMV file.
  3. Quality and size of the captured video.
  4. There shouldn’t be breaking in audio.
  5. Still Image compression quality.

The performance criteria mentioned here is related to audio, video and still encoders. I have taken the WMV encoders for video, audio source filter and JPEG encoder for still image as an example for performance tuning.
DMO & WMV Encoder

Windows CE 6.0 supports WMV encoder as a DirectX Media Object (DMO) and it can be accessible through DMO wrapper filter. The DMO Wrapper filter enables DirectShow application to use the DMO within a filter graph. The filter wraps the DMO and handles all the details such as passing data to and from the DMO. Let us take WMV encoder. Performance tuning can be done by understanding and playing with properties of WMV encoder.

Accessing WMV encoder properties:
All WMV encoder properties can be retrieved by querying the IPropertyBag interface. Following steps are involved to retrieve and set each filter properties.

  • Create the DMO Wrapper filter by the following way:

CComPtr pVideoDMOWrapperFilter;
CoCreateInstance( CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &pVideoDMOWrapperFilter );

  • Retrieve the DMO wrapper filter as follows:

CComPtr pVideoEncoderDMO;
pVideoDMOWrapperFilter.QueryInterface( &pVideoEncoderDMO );

  • Initialize the WMV video encoder filter using its class ID on the DMO wrapper filter.

pVideoEncoderDMO->Init(CLSID_CWMV9EncMediaObject, DMOCATEGORY_VIDEO_ENCODER );

  • Add the filter to filter graph by using the following interface.

CComPtr pGraph;
pGraph-> AddFilter(pVideoDMOWrapperFilter, TEXT(“Video Encoder”));

  • Retrieve the IPropertyBag interface by the bellow given way.

CComPtr pPropertyBag = NULL;
pVideoEncoderDMO.QueryInterface( &pPropertyBag);

  • Each property value can be read by using IPropertyBag::Read ().
  • Each property value can be modified by using IPropertyBag::Write ().

Tuning WMV encoder
There is a list of properties available for WMV filters, following properties are mainly considered to tune the performance.

Encoder algorithm complexity
Encoder algorithm complexity can be controlled through “_COMPLEXITYEX” property. This property covers the first two points in the performance criteria list. This property value is started from 0 to Maximum value supported by the codec.

Lowest value provides the real time processing of captured frames using simple encoding algorithm and it will provide user acceptable video processing time after finished the video capturing. But there is a possibility of missing frames and it is depends on the processing capability of the hardware.

Higher values provide quality output and no frames will be missed for encoding. In this case, it will use complex encoding algorithms but the processing time is more. After stop the video capturing, user has to wait for a long period to receive the video file.

Variable Bitrate Quality
Quality can be controlled through “_VBRQUALITY” property. This property covers the third point in the performance criteria list. This property indicating the quality level for quality based video encoding. The property value is started from 0 to 100. In this case, Quality is directly proportional to size of the video file. Higher property values increase the quality as well as the size of the video file. Users can fix the value based on their requirement on quality as well as requirement on size of the video file.

Tuning Audio
Audio quality can be tuned up by changing the audio input bit rate. Audio capturing can be multiplexed with video capturing and stored in the WMV file. Again increasing the bitrates will increase the audio quality and also the file size and lowering the bit rate reduce the file size and it may cause breaking on sounds. Changing bitrates are left to the user, based on their requirement.

Following steps involved in changing the bit rate of the audio pin:

  • Load the audio capture filter.

CComPtr pAudioCapture;
CcomPtr< IPersistPropertyBag > pPropertyBag;
hr = CoCreateInstance( CLSID_AudioCapture, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &pAudioCapture );
pAudioCaptureFilter.QueryInterface( &pPropertyBag );
pPropertyBag->Load( NULL, NULL );
pGraph->AddFilter(pAudioCapture, L”Audio Capture Filter” ); //
Assume Filter graph manager is already created

  • Retrieves the IAMStreamConfig interface for Audio capture filter. Assumed that Capture Graph filter is already created.

CcomPtr< IAMStreamConfig> pAudioStreamConfig;
hr = m_pCaptureGraphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Audio, m_pAudioCapture, IID_IAMStreamConfig, (void **) &pAudioStreamConfig);

  • Retrieves the current format of waveform audio data and set the new bit rate. New bitrates value can be assigned using WAVEFORMATEX structure. AM_MEDIA_TYPE contains the audio configuration data provided, when the IAMStreamConfig is retrieved from audio capture filter.

AM_MEDIA_TYPE *pmt; WAVEFORMATEX *pWft; pAudioStreamConfigDMO->GetFormat(&pmt);
pWft = (WAVEFORMATEX*)pmt->pbFormat; //Current waveform audio configurations
pWft->wBitsPerSample=8;
pWft->nBlockAlign=1;
pWft->nAvgBytesPerSec=8000;
pWft->nSamplesPerSec=8000;
pWft->nChannels=1; //Mono channel
pWft->wFormatTag=1; // Normally WAVE_FORMAT_PCM
pAudioStreamConfigDMO->SetFormat(pmt); //
Assign the new waveform audio configurations

Average bytes per second (nAvgBytesPerSec) is calculated as follows:
nAvgBytesPerSec = nSamplesPerSec* wBitsPerSample/8 (since wBitsPerSample is maintaining the bit value)
Playing with these values make you to change the bit rate of the audio input.

Tuning the Still image quality
Windows CE supports image sink filter for capturing still image. Since image sink filter is using Imaging API, it will support JPG, BMP, TIFF and GIF etc…. Image sink filter uses the following registry to obtain parameter values that are passed on to the image encoding factory.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectShow\ImageSink\Quality\ <Quality Level> \ <File Extension> \ <Parameter Name>

GUID – BINARY (The GUID for the encoding parameter)
Value – DWORD (The number of parameter values that are contained in Value)
Type – DWORD (The data type for the parameter)
NumberOfValues – DWORD (The value of the parameter)

There are set of encoding parameters such as Quality, compression and scan method etc… All these encoding parameters can be added through registry.Following registry setting is an example for tuning the Quality for JPG encoding.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectShow\ImageSink\Quality\ <Quality Level>>\jpg\Quality
“GUID”=”1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB”
“Value”=dword:00000019
“Type”=dword:00000004
“NumberOfValues”=dword:00000001

is started from 0 and it represents the lowest quality level and each represents the unique quality level. The sub keys GUID, value, Type and NumberOfValues are passed as a parameter to image encoding factory using the structure StructEncoderParameter. Required Encoding parameters can be set through registry for the same by changing the GUID, Value, Type and NumberOfValues.

GUID represents that the encoding parameter is quality. The range of the value is from 0-100. Lower value represents the lower quality and increasing this value will increase the quality. User can set the required quality level using IImageSinkFilter::SetQuality(). Quality parameters for the current image encoding can be taken from the above given registry based on the . The Value ‘n’ passed as an argument to the SetQuality() is used to select the corresponding registry by comparing with of the above given registry.
Steps to use the IImageSinkFilter::SetQuality()

  • Load the Image Sink Filter

CComPtr pStillSink;
CComPtr
pImageSinkFilter;
hr = CoCreateInstance( CLSID_IMGSinkFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &pStillSink );
hr = m_pGraph->AddFilter( pStillSink, TEXT(“Image Sink Filter”)); //Add the filter to filter graph.
pStillSink.QueryInterface( &pImageSinkFilter );

  • Set the required quality parameter.

hr = pImageSinkFilter->SetQuality(n);
Where ‘n’ represents the <Quality Level>

· ·

Mar/10

23

Application Verifier Hangs While Adding The Application

In this blog post, I am going to list out some of the most common issues that we face with application verifier while connecting it through active sync. Application verifier is used to test the application written for Win CE devices. Application verifier can be executed separately without using CETK. Go to the location “C:\Program Files\Microsoft Platform Builder\6.00\cepb\wcetk\ddtk\desktop”, just execute “appverifce.exe”.

For active sync connection change the device properties as shown below:

For ARM processor application verifier may not connect through Active Sync. This may be because of version incapability. Go to “C:\Program Files\Common Files\Microsoft Shared\Windows CE Tools\Platman\target\wce600” directory. Now, simply copy the ARMV4i folder to create an ARMV4 directory. This will fix the ARM incapability issue.

Next is to run the application on the device using application verifier. Many face an issue in adding the files that are placed on the device. Application verifier may hang when we try to add device side files. To fix this issue click add button, add some files from the PC and then connect with the device using active sync. After connecting with the device, add the files from the device.

· ·

Mar/10

18

Compiling bsect.asm of X86 to create bsect.img

Most of the programmers find it difficult to compile the bsect.asm file. This is because of 32 bit assembly controller and not defining the build.bat file properly. Here you will find simple steps to compile the bsect.asm.

Step1:
To compile the bsect.asm we need 32bit assemble compiler. Microsoft provides MASM32, which is a 32 bit assembly compiler.

Download the 32bit assembly compiler from the following link “http://www.masm32.com/masmdl.htm”

Install the MASM32 SDK in “C” drive.

Step 2:
Use Visual Studio command prompt for compiling, open the prompt and go to the bootsector location or the location where bsect.asm file available.

Step 3:
“The system cannot find the path specified” error will occur if the build.bat file is not changed.
Then change the build.bat file from

ml /Zm /c bsect.asm
c:\msvc\bin\link bsect.obj,bsect.com,,,,
debug bsect.com < getbsect.scr

to

C:\masm32\bin\ml /Zm /Flbsect.lst /c bsect.asm
C:\masm32\bin\link16 bsect.obj,bsect.com,,,,
debug bsect.com < getbsect.scr

Define the path correctly. It is the path of the drive in which MASM32 is installed.

Step 4:
Give build command in the Visual Studio command prompt to compile.
After compiling you can find the “BSECT.IMG” file in the bsect.asm folder.

· ·

Mar/10

12

Resolution Switching in DirectShow Camera Application

DirectShow sample camera test application source code resides in the ($(WINCEROOT)\PRIVATE\TEST\MULTIMEDIA\DIRECTX\DSHOW\CAMERA) directory of the WINCE 6.0 installation.

The CameraFramework source present on the private code supports functions which can be used to develop full functional directshow camera application.

Many of them were asking about the how to switch between the supported resolutions of the PINS in the application.

In the default application source present in the PRIVATE source we don’t have option for switching between the resolutions supported by camera driver.

The default application will simply make use of the first resolution supported by the camera driver(say for ex:320×240).

Following are the routines which are used for enumerating the supported resolutions of the camera driver.

int iCount = 0, iSize = 0;
hr = g_DShowCaptureGraph.GetNumberOfCapabilities(nStream, &iCount, &iSize);

nStream – Pin details(CAPTURE,PREVIEW,STILL)
iCount - Number of formats supported by the driver for the selected PIN.

Calling the GetStreamCaps () function will retrieve the format capabilities of the selected PIN. Enumerate the supported resolutions using following calls and list it in the application(ex : Using List box or group Radio Buttons).

Resolution Swtiching in DirectShow Camera Application

// Check the size to make sure we pass in the correct structure.
if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))
{
// Use the video capabilities structure.
for (int iFormat = 0; iFormat < iCount; iFormat++)
{
VIDEO_STREAM_CONFIG_CAPS scc;
AM_MEDIA_TYPE *pmtConfig;
VIDEOINFOHEADER *pVih;
hr = g_DShowCaptureGraph.GetStreamCaps(nStream,iFormat, &pmtConfig, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
// Examine the format.
pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
RETAILMSG(1,(TEXT("Width = %d , Height = %d \r\n"),pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight));
}
}
}

After allowing the user to select the format set the corresponding resolution format using the following call of the camera framework.

hr = g_DShowCaptureGraph.SetFormat(nStream,pmtConfig);
if (SUCCEEDED(hr))
{
RETAILMSG(1,(TEXT("SetFormat Success ***********\r\n")));
}

nStream – Pin details(CAPTURE,PREVIEW,STILL)
pmtConfig – Structure returned by the GetStreamCaps()

· · · · ·

Theme Design by devolux.nh2.me