Tuesday, July 29, 2008

Application Crashing Problem in Release version in VC++ with Map File

Application Crashing Problem in Release version in VC++:
-------------------------------------------------------------------------


Crash is as follows:

Data Abort: Thread=8dac8ba4 Proc=8037c870 'TestApp.exe'
AKY=ffffffff PC=78a3e118(image_proc.dll+0x0001e118) RA=00013178(StreamingPlayer.exe+0x00003178) BVA=241dc35e FSR=00000807

Data Abort: Thread=8d89dc34 Proc=8037c870 'TestApp.exe'

AKY=ffffffff PC=78a3e118(image_proc.dll+0x0001e118) RA=00013178(StreamingPlayer.exe+0x00003178) BVA=241dc35e FSR=00000807

Unhandled exception at 0x78a3e118 in TestApp.exe: 0xC0000005: Access violation writing location 0x001dc35e.

Data Abort: Thread=8d739000 Proc=8037c960 'wmplayer.exe'

AKY=ffffffff PC=7894e118(imageLib.dll+0x0001e118) RA=00013178(wmplayer.exe+0x00003178) BVA=260ec35e FSR=00000807








if we are building our application in release version, at client side it crashed with some address;
How can we trace which function is failed and locate where the error is ?


1.Solution for the above thing is to make use of .map file


.map file content sample:
---------------------------
imageLib
Timestamp is 488496e7 (Mon Jul 21 19:32:15 2008)
Preferred load address is 10000000


Start Length Name Class
0001:00000000 000004bcH gTest CODE
0002:00000000 00000e30H Addition CODE

Address Publics by Value Rva+Base Lib:Object

0000:00000000 ___safe_se_handler_table 00000000
0000:00000000 ___safe_se_handler_count 00000000
0001:00000000 RGB565toYUV420 10001000 ColorConversion.obj
0002:00000000 UYVYtoRGB565 10002000 ColorConversion.obj
0002:000003d4 Rotate 100023d4 ImageOps.obj
0002:00000660 Blur 10002660 ImageOps.obj


Static symbols

0010:0000417c Init 1001517c f InitOps.obj






Crash will throw some address which caused the problem;




There are two types of crash;Crash may be in executables or may be in DLLs;



Solution for Crash in Executable Application:
------------------------------------------

Example:
---------
AKY=ffffffff PC=7894e118(TestApp.exe 0x1001e118) Data abort

if it is executables, the Solution is as follows:


0x1001e118 - is a Crash Address;


Function Address = Crash Address - Preferred Load Address in Map file - 0x1000 ( For Portable Executable File Format Infos) ;


Solution for Crash in DLL:
-----------------------------


AKY=ffffffff PC=7894e118(imageLib.dll+0x0002478) RA=00013178(wmplayer.exe+0x00003178)


ImageLib.dll + 0x0001e118 means

Crash Address = Preferred Load address in Map File + Crash Address;
= 10000000 + 2478
= 10002478 This Crash Address is in between Rotate and Blur Function;
So the crash is in Rotate function;





Preferred load address is 10000000
0002:000003d4 Rotate 100023d4 ImageOps.obj
0002:00000660 Blur 10002660 ImageOps.obj


Note:
--------
100023d4 - Starting Address of the Rotate() fn
( Rotate fn code occupies memory range from 100023d4 to 1000265F )
10002660 - Starting Address of the Blur() fn



Creation of a Map File in Vs2005:
--------------------------------------------------

At the time of building the project, if we specified this macro

/MAP[:file name] will leads to create the map file ;




/MAP (Generate Mapfile)


/MAP[:filename]
Remarks
where:

filename
A user-specified name for the mapfile. It replaces the default name.

Remarks
The /MAP option tells the linker to create a mapfile.

By default, the linker names the mapfile with the base name of the program and the extension .map. The optional filename allows you to override the default name for a mapfile.

A mapfile is a text file that contains the following information about the program being linked:

The module name, which is the base name of the file

The timestamp from the program file header (not from the file system)

A list of groups in the program, with each group's start address (as section:offset), length, group name, and class

A list of public symbols, with each address (as section:offset), symbol name, flat address, and .obj file where the symbol is defined

The entry point (as section:offset)

The /MAPINFO option specifies additional information to be included in the mapfile.

To set this linker option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.

Click the Linker folder.

Click the Debug property page.

Modify the Generate Map File property

Application Crashing Problem in Release version in VC++ with Map File

Application Crashing Problem in Release version in VC++:
-------------------------------------------------------------------------


Crash is as follows:

Data Abort: Thread=8dac8ba4 Proc=8037c870 'TestApp.exe'
AKY=ffffffff PC=78a3e118(image_proc.dll+0x0001e118) RA=00013178(StreamingPlayer.exe+0x00003178) BVA=241dc35e FSR=00000807

Data Abort: Thread=8d89dc34 Proc=8037c870 'TestApp.exe'

AKY=ffffffff PC=78a3e118(image_proc.dll+0x0001e118) RA=00013178(StreamingPlayer.exe+0x00003178) BVA=241dc35e FSR=00000807

Unhandled exception at 0x78a3e118 in TestApp.exe: 0xC0000005: Access violation writing location 0x001dc35e.

Data Abort: Thread=8d739000 Proc=8037c960 'wmplayer.exe'

AKY=ffffffff PC=7894e118(imageLib.dll+0x0001e118) RA=00013178(wmplayer.exe+0x00003178) BVA=260ec35e FSR=00000807








if we are building our application in release version, at client side it crashed with some address;
How can we trace which function is failed and locate where the error is ?


1.Solution for the above thing is to make use of .map file


.map file content sample:
---------------------------
imageLib
Timestamp is 488496e7 (Mon Jul 21 19:32:15 2008)
Preferred load address is 10000000


Start Length Name Class
0001:00000000 000004bcH gTest CODE
0002:00000000 00000e30H Addition CODE

Address Publics by Value Rva+Base Lib:Object

0000:00000000 ___safe_se_handler_table 00000000
0000:00000000 ___safe_se_handler_count 00000000
0001:00000000 RGB565toYUV420 10001000 ColorConversion.obj
0002:00000000 UYVYtoRGB565 10002000 ColorConversion.obj
0002:000003d4 Rotate 100023d4 ImageOps.obj
0002:00000660 Blur 10002660 ImageOps.obj


Static symbols

0010:0000417c Init 1001517c f InitOps.obj






Crash will throw some address which caused the problem;




There are two types of crash;Crash may be in executables or may be in DLLs;



Solution for Crash in Executable Application:
------------------------------------------

Example:
---------
AKY=ffffffff PC=7894e118(TestApp.exe 0x1001e118) Data abort

if it is executables, the Solution is as follows:


0x1001e118 - is a Crash Address;


Function Address = Crash Address - Preferred Load Address in Map file - 0x1000 ( For Portable Executable File Format Infos) ;


Solution for Crash in DLL:
-----------------------------


AKY=ffffffff PC=7894e118(imageLib.dll+0x0002478) RA=00013178(wmplayer.exe+0x00003178)


ImageLib.dll + 0x0001e118 means

Crash Address = Preferred Load address in Map File + Crash Address;
= 10000000 + 2478
= 10002478 This Crash Address is in between Rotate and Blur Function;
So the crash is in Rotate function;





Preferred load address is 10000000
0002:000003d4 Rotate 100023d4 ImageOps.obj
0002:00000660 Blur 10002660 ImageOps.obj


Note:
--------
100023d4 - Starting Address of the Rotate() fn
( Rotate fn code occupies memory range from 100023d4 to 1000265F )
10002660 - Starting Address of the Blur() fn



Creation of a Map File in Vs2005:
--------------------------------------------------

At the time of building the project, if we specified this macro

/MAP[:file name] will leads to create the map file ;




/MAP (Generate Mapfile)


/MAP[:filename]
Remarks
where:

filename
A user-specified name for the mapfile. It replaces the default name.

Remarks
The /MAP option tells the linker to create a mapfile.

By default, the linker names the mapfile with the base name of the program and the extension .map. The optional filename allows you to override the default name for a mapfile.

A mapfile is a text file that contains the following information about the program being linked:

The module name, which is the base name of the file

The timestamp from the program file header (not from the file system)

A list of groups in the program, with each group's start address (as section:offset), length, group name, and class

A list of public symbols, with each address (as section:offset), symbol name, flat address, and .obj file where the symbol is defined

The entry point (as section:offset)

The /MAPINFO option specifies additional information to be included in the mapfile.

To set this linker option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.

Click the Linker folder.

Click the Debug property page.

Modify the Generate Map File property


For More Info:
http://www.codeproject.com/KB/debug/mapfile.aspx

Friday, July 25, 2008

Streaming Versus Progressive Download

Streaming Versus Progressive Download :
-------------------------------------------------
There are trade-offs to consider when deciding whether to deliver a movie using progressive download, streaming, or broadcasting.
All QuickTime media types can be delivered as progressive downloads. Streaming is limited to sound, video, and text. Broadcasting is further limited to compression schemes and quality settings compatible with real-time capture and compression.
Progressive download works even when the bandwidth is not sufficient for real-time playback; it simply buffers incoming data and delivers delayed playback. Streaming and broadcasting are bandwidth limited; if the connection is not fast enough, the movie cannot play.
Streaming movies do not store a copy of the movie on the client computer, making them inherently more difficult to copy without the consent of the movie’s owner. This can be an important consideration, and is one reason why people choose streaming over progressive download.
Streams take up a specified amount of bandwidth, whereas HTTP file downloads proceed as quickly as the connection allows. It is therefore easier to manage the bandwidth usage of a streaming server than of a web server delivering progressive-download movies.
Broadcasting allows you to deliver coverage of live events as they happen, or to provide real time "chat" between computers.
To sum up, if your movie includes live coverage, you must use broadcasting. If bandwidth management and copy discouragement are paramount considerations, streaming may be your best choice for stored content. If simplicity, reliability, or quality regardless of connection speed are most important to you, progressive download is probably best.

Ref:
http://developer.apple.com/documentation/QuickTime/RM/Fundamentals/QTOverview/QTOverview_Document/chapter_1000_section_6.html

Thursday, July 24, 2008

How to download you tube video as MP4 file:

How to download you tube video as MP4 file:
-------------------------------------------------------------------
http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18
Download Youtube video:
--------------------------------------
copy the Youtube link
and go to the following URL and give the youtube link in the following site:
"http://vixy.net/rawvideo/"
we will get something like "Right click here to save as mp4 file";
and right click it and open it in a new window;

we will get the URL like above
http://youtube.com/get_video.php?video_id=zskO9O3hF78&t=OEgsToPDskI7pZ1ChBCot9co5DvFysF9&fmt=18
then it will show the file download dialog; and click on save button so that we can save it in local disk;

http://youtube.com/get_video.php?video_id=xoKbDNY0Zwg&t=OEgsToPDskJI-k1mwTeJHOC9_dadX340&fmt=18

Progressive Download Streaming with Quicktime player

Progressive Download Streaming with Quicktime player:
-------------------------------------------------------
1.Install apache
For Progressive Download Streaming, we have to install the Apache server and configured the httpd.conf file's listen 80 as
listen desired_port
listen 8080
put streamable clips in htdocs( default virtual directory of the Apache)
2.Create Streamable clips with Helix mobile producer
Input/Output tab select the input and output file and select the export type and Click on "Export Settings and Meta data" tab and select Export Settings option
as Progressive Download and then select the "Encode" button;
Next thru Quicktime player or Progressive Download Streaming filter, we can do the following;
http://ApacheRunningIP:8080/clip_path
Qt player will play the file;

WMP doesnt load the Source Filter

WMP doesnt load the Source Filter Problem:
------------------------------------------------
if we are giving the URL like this:
http://www.youtube.com/get_video?video_id=AdZC8EAp62c&t=OEgsToPDskL9x6BrV7XCzFzahexhvDdL&fm t=18
then the windows media player is not loaded the PD Stream Source DLL;

Currently the youtube URL is not accessible in my system;So kindly give another Wrong URL and check whether the Windows Media player loads our PD Stream Source Filter;
Eventhough the invalid URL we have given to the Windows media player (http://10.205.3.30:8080/test.3gp), the Windows media player loads the PdStream Source filter;
http://10.203./get_video?video_id=AdZC8EAp62c&t=OEgsToPDskL9x6BrV7XCzFzahexhvDdL&fm

with URL without extension, it is not loading the source filter ( Ex: http://192.168.233:8080/test);
I got parameter incorrect if I am using the http://192.168.233:8080/




Even though we registered the custom file type( http://), Windows media player is not able to load the source filter; ( We already registered the File type and source filter in registry ).
Windows media player is able to load the source filter only for the following URL:
URL WindowsMediaPlayer error
http://192.10.198.2:5050/ Parameter Incorrect
http://192.168.10.3:5050/test SourceFilter for this file can't be loaded
http://192.168.10.3:5050/get_video?video_Id=adAZd& t=susisueie&fmt=18
Source Filter for this file can't be loaded

Source Filter class ID is:
{018778CE-07D8-4656-982E-B5DDB16C71DF}

We have not registered the File Extension type (http://) separately. So the Register Custom File type can be done within the Source Filter;( By addding the registry settings Programmatically);

HKEY_CLASSES_ROOT

Source Filter =
Extensions
<.ext1> =
<.ext2> =

if we have sepcified any extensions, if the URL is having that extension, then only the source filter will be loaded;
Ex:
HKEY_CLASSES_ROOT
http://
Source Filter =
Extensions
.ext1 =".mp3"
.ext2 =".mp4"
http://192.168.3.10:5000/test.mp4
http://192.168.3.10:5000/test.mp3 then only it will loads the Source filter
otherwise it will not loads the Source Filter;

Another way of resgistering the source Filter :
----------------------------------------------
HKCR\http
HKCR\http\extensions\
Key and value is as follows:
.mp4 { Filter CLASS ID}
.mp3 { Filter Class ID}
So whenever it is having URL with extension then only WMP will loads the specified class ID source filter;

Finally I have solved the problem;
Solution:
-------------
we have to add the Source Filter and class ID in the HKCR\http;
So now WMP will loads the Source Filter automatically;

Tuesday, July 15, 2008

Mp4UI tool is an open source file. Many converters are not properly converting the meta data. For Example, If I am converting the video from WMV to MP4 , the meta data available in a WMV is not available in ConvertedMP4 file;

So we can make use of the MP4UI tool to add meta data to the MP4 file;


MP4UI dialog:





Click New/Open button and select MP4 file;




Look at the Lower Right corner, it is having M symbol Just click on this;





After Entering all these information and enable the Part of a compilation check box and Click on OK; it will add the Meta data to the MP4 file;


Using this Metadata, we can know the artist, composer, Singer, Film and so on information about the media file;



Monday, July 14, 2008

Add Meta data to mp4 file thru MP4UI tool

m4a clip meta data problem

m4a clip meta data problem:
-------------------------------------------
we are having two different APIs to read iTune based file format and other 3GP standard file format;
iTune file format is based on Quicktime file format;
They called the m4a file as iTune file format;
M4A,MP4,M4V, MSNV ( MSNV for Sony PSP Video) files are based on the MPEG4 File Format;
MPEG4 File format is based on Quicktime container format;
iTune is also follows Quicktime container format;So quicktime 3GP,MP4 are all based on Quicktime container format;
Even though we rename the files from mp4 to 3GP or 3GP to mp4, the Quicktime displays the video and audio with meta data;
We are having two set of APIs One is to read meta data from Quicktime Meta data(Mp4) and another one is to read meta data from the
3GP file;
Solution:
------------
1.We can call the two APIs Successively to get the meta data information from a file;
2.We can call the Meta data APIs based on file type
( It may not display meta data if we renamed the 3GP file to MP4 file)
3.One more Solution is checking the File format;




Quicktime's iTune,MP4 and 3GP uses the same container format;
Atom:
--------
We can call the meta data APIs based on the file atom;
if the atom is 'ftyp';
Atom Syntax:
--------------
ftyp PreferredBrand MinorVersion CompatibleBrands NULL
Example:
ftyp 3GP4 00 00 02 00( version in Hex) 3Gp4 isom mp41
Compatible brands are
3GP4 isom, mp41;

Preferred Brand:
-----------------
1.4 bytes code ( it may be like 3GP or mp4)
Note:
--------
the Preferred Brand must occur in Compatible Brands list;

3GP standards may have the following
3GP4
3GP5
3GP6
So we will compare the first 3 codes with 3GP, if it is zero


if(_stricmp(code,"3gp") == 0) //Start Code is Equal;
{
}

for MP4 file, it may have mp4,m4v,m4a and isom and so on;
mp41,mp42
so we can make a check like "mp4" with first 3 start codes;
While downloading the MP4 file I faced the problem; its ftyp or Brand code is equal
to 'MSNV' it is not matching to any of the format;MSNV is a sony video PSP recorder format;
Quicktime will do the following to check the file format;

ftyp 3GP4 00 00 02 00( version in Hex) 3Gp4 isom mp41


Quicktime will enumerates the compatible Brands;
Quicktime will checks whether the file is according to the 3GP4 Spec,if it is not, then it will checks
the file format is in isom and if the file format is not in a format of Isom, then Quicktime will check with the
mp41 format; if it is the correct format, then according to the file format,Quicktime will read data from the
file; if media file is not matched with any of the compatible brands, then it will throw "Invalid file format specification"
error;

Thursday, July 10, 2008

Return values in function argument Pointers

Pointers Sample application:
----------------------------------------
int Function( char* arr)
{
strcpy(arr,"sun");
return 0;
}

void Main()
{
char arr[3];
Function(arr);
printf("\n %s",arr);
}
Expected Output : sun
Actual Result : I got some invalid junk data;


So I modified the main()fn call as follows:

void Main()
{
char arr[3];
Function(&arr[0]);
printf("\n %s",arr);
}
the Output is : sun

Return values at function argument pointers

Pointers Sample application:
----------------------------------------
int Function( char* arr)
{
strcpy(arr,"sun");
return 0;
}

void Main()
{
char arr[3];
Function(arr);
printf("\n %s",arr);
}
Expected Output : sun
Actual Result : I got some invalid junk data;


So I modified the main()fn call as follows:

void Main()
{
char arr[3];
Function(&arr[0]);
printf("\n %s",arr);
}
the Output is : sun

Differentiate 3GPP and Quicktime compliant

Differentiate 3GPP and Quicktime compliant:
---------------------------------------------------------------
if the atom is 'ftyp',then we will read next 3 bytes;
Based on these 3 bytes, we will identify whether the file is a quicktime compliant or
3GPP compliant;
it may be the following for 3GP compliant:
3GP or 3G2 ( ftyp3gp or ftyp3g2)
For Quicktime compliant ftyp following codes are :
mp4,m4v,m4a (ftypmp4 , ftypm4v,ftypm4a)

Note:
if the file type is .mp4, it may contains the ftyp3GP code

Wednesday, July 09, 2008

Camera Driver Pin resolution problem


Camera Driver Pin resolution problem:
---------------------------------------------------------
1.Capture pin resolutions must be supported in Preview Pin Resolution;
if Capture Pin resolutions are not matched with the Preview Pin Resolution;
Cause:
--------
This is the bug in camera or capture driver;Capture Pin resolution must be supported in Preview Pin resolution;

Monday, July 07, 2008

DSHOW ATL Error

When I try to compile and run the PlayWnd Example in 2005,
the following link problem appears.

error LNK2001: unresolved external symbol "unsigned int (__stdcall* ATL::g_pfnGetThreadACP)(void)" (?g_pfnGetThreadACP@ATL@@3P6GIXZA)

Solution:
------------
I found g_pfnGetThreadACP is defined in USES_CONVERSION which is used in W2T and so on.
Include the atlsd.lib ( It contains the USES_CONVERSION definition);

Observation about Less than 1 Sec Video

What I was Done:
------------------
1.I have Queried the GetCurrentPosition () fn from the Player Application;
TIME_FORMAT_MEDIA_TIME flag is set as same as our Filters;
30000 is the Maximum Duration means,if we set the 30001 will set the end of the file;



TrackType =0, Start : 0,Stop :990000
TrackType =0, Start : 990000,Stop :1990000
TrackType =0, Start : 1990000,Stop :3050000
TrackType =0, Start : 3050000,Stop :3990000
TrackType =0, Start : 3990000,Stop :4990000
TrackType =0, Start : 4990000,Stop :5980000
TrackType =0, Start : 5980000,Stop :6980000
Track Type:0 Track Duration is 798,Total Duration is:798
VideoTrack Reaches End: 8380000
TrackType =0, Start : 6980000,Stop :8380000
Stream Time is :7980000 Set it as Properly;
m_nCurrentPos :7980000 for the Last Media Sample we set the TimeStamp as 8380000;
It is more than the Timestamp;

I have used the Player Application there I get the total duration of the media file;
and moreover I printed the current Position using IMediaSeeking interface;
This is the Problem with multimedia file having less than 1 seconds of video and audio;
if I am adding the 200 milli seconds then it works fine;

Tuesday, July 01, 2008

windows media player Seek Bar will not work for video having less than 1 second duration?:


windows media player Seek Bar will not work for video having less than 1 second duration?:
-------------------------------------------------------------------------------------------
We checked whether the windows media player will not display the seek bar properly for video having less than 1 second duration;We recorded the wmv video using PIMG with less than 1 second; it is playing fine in media player;

within Motorola cell, we hard reset the device; By default it is having wmv recording;
and recorded the file for testing this scenario;

Problem while Playing the video less than one second

Problem while Playing the video less than one second:
-----------------------------------------------------
if the video is having less than one second, media player seek bar never reaches the end position;
I have tested the video which is having less than 8 seconds with
AAC Encoded audio;QCELP Encoded audio,AMR Nb Encoded audio in a 3GP file;
I got the Same Error as follows:

For the video less than 1 seconds:
-----------------------------------
GetDuration : 7930000
End Stop value of Media Sample is : 7190001
7190001 / 7930000 = 0.90 So the Trackbar is not shown at the end of the media player




For Video > 1 seconds:
-------------------
GetDuration : 172400000
End Stop Value of Media Sample is : 172200001
172200001 /172400000 = 0.99 So the Error is not shown clearly in this large video;
The Track bar never reaches the end position of the media player;
So the Problem is with the Timestamp calculation;

No Time stamp has been set for this sample Error

I got the "No Time stamp has been set for this sample" while playing the 3gp file;
-----------------------------------------------------------------------------------
HRESULT FillBuffer()
{
HRESULT hr;
hr = GetMP4Sample (pSample);
if(SUCCEEDED(hr))
{
REFERENCE_TIME rtStart = 0, rtStop = 0;
hr = pSample->GetTime(&rtStart, &rtStop);
if(SUCCEEDED(hr))
{
wchar_t szMsg[MAX_PATH];
swprintf(szMsg,L"\n 0-vid,1- audio,TrackType = %d, Start = %ld, Stop : %ld",m_nTrakType,(LONG)rtStart,(LONG) rtStop);
OutputDebugString(szMsg);
}
}
return hr;

}



Solution:
===========
the above code displays the "No timestamp has been set for this sample " error;
Reason is
if GetTime() is failed, then that hr value will be returned from the
FillBuffer() fn; So I got this error; if I modified it as follows, then I wont get an error;

hr = GetMP4Sample (pSample);
if(SUCCEEDED(hr))
{
REFERENCE_TIME rtStart = 0, rtStop = 0;
HRESULT temphr = pSample->GetTime(&rtStart, &rtStop);
if(SUCCEEDED(temphr))
{
wchar_t szMsg[MAX_PATH];
swprintf(szMsg,L"\n 0-vid,1- audio,TrackType = %d, Start = %ld, Stop : %ld",m_nTrakType,(LONG)rtStart,(LONG) rtStop);
OutputDebugString(szMsg);
}
}

Record the video and audio using PIMG with desired video and audio encoder

Record the video and audio using PIMG with desired video and audio encoder:
----------------------------------------------------------------------------

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Pictures\Camera\OEM\AudioEncoderClassID as AAC Encoder's ClassID
\VideoProfile\1\AudioEncoderCLassID
\VideoProfile\2\AudioEncoderClassID
\VideoProfile\3\AudioEncoderClassID;
\VideoEncoderClassID
\MuxerClassID

{f0db0b53-53ff-49b9-8c51-4ed44cec6d46} - AAC Encoder
just copy our encoder DMO class ID at the above specified registry location;
The Pimg ( Microsoft's PIMG pictures and videos) record , encode and multiplex the video according to the OEM registry settings;
I have tested this behavior in Motorola; But some mobiles may not implement this behavior; Example : Asus;
By Default if it is recording wmv file means, those informations will be available in this registry location;

Friday, June 27, 2008

Performance of video rendering in Capture application

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)

Error while releasing filters:
-------------------------------
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

CLSID_VideoCapture Filter problem:
----------------------------------------
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 m_pPropertyBag;
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

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

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

winCE Camera Capture 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

ControlStream Function:
------------------------

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

I faced the problem in Video Capture application as follows:


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;

Saturday, May 31, 2008

Format Specifier ULONGLONG type

Format specifier for ULONGLONG type:
ULONGLONG t= 10292029202202LL;

%I64u
wchar_t szMsg[MAX_PATH];swprintf(szMsg,L"\n Value of t is : %I64u",t);
OutputDebugString(szMsg);

Thursday, May 22, 2008

Image Stride

When a video image is stored in memory, the memory buffer might contain extra padding bytes after each row of pixels. The padding bytes affect how the image is stored in memory, but do not affect how the image is displayed.

The stride is the number of bytes from one row of pixels in memory to the next row of pixels in memory. Stride is also called pitch. If padding bytes are present, the stride is wider than the width of the image, as shown in the following illustration.

Two buffers that contain video frames with equal dimensions can have two different strides. If you process a video image, you must take the stride into account.

In addition, there are two ways that an image can be arranged in memory. In a top-down image, the top row of pixels in the image appears first in memory. In a bottom-up image, the last row of pixels appears first in memory. The following illustration shows the difference between a top-down image and a bottom-up image.

A bottom-up image has a negative stride, because stride is defined as the number of bytes need to move down a row of pixels, relative to the displayed image. YUV images should always be top-down, and any image that is contained in a Direct3D surface must be top-down. RGB images in system memory are usually bottom-up.

Video transforms in particular need to handle buffers with mismatched strides, because the input buffer might not match the output buffer. For example, suppose that you want to convert a source image and write the result to a destination image. Assume that both images have the same width and height, but might not have the same pixel format or the same image stride.

The following example code shows a generalized approach for writing this kind of function. This is not a complete working example, because it abstracts many of the specific details.

Copy Code

void ProcessVideoImage(

BYTE* pDestScanLine0,

LONG lDestStride,

const BYTE* pSrcScanLine0,

LONG lSrcStride,

DWORD dwWidthInPixels,

DWORD dwHeightInPixels

)

{

for (DWORD y = 0; y < dwHeightInPixels; y++)

{

SOURCE_PIXEL_TYPE *pSrcPixel = (SOURCE_PIXEL_TYPE*)pDestScanLine0;

DEST_PIXEL_TYPE *pDestPixel = (DEST_PIXEL_TYPE*)pSrcScanLine0;



for (DWORD x = 0; x < dwWidthInPixels; x +=2)

{

pDestPixel[x] = TransformPixelValue(pSrcPixel[x]);

}

pDestScanLine0 += lDestStride;

pSrcScanLine0 += lSrcStride;

}

}

This function takes six parameters:

  • A pointer to the start of scan line 0 in the destination image.

  • The stride of the destination image.

  • A pointer to the start of scan line 0 in the source image.

  • The stride of the source image.

  • The width of the image in pixels.

  • The height of the image in pixels.

The general idea is to process one row at a time, iterating over each pixel in the row. Assume that SOURCE_PIXEL_TYPE and DEST_PIXEL_TYPE are structures representing the pixel layout for the source and destination images, respectively. (For example, 32-bit RGB uses the RGBQUAD structure. Not every pixel format has a pre-defined structure.) Casting the array pointer to the structure type enables you to access the RGB or YUV components of each pixel. At the start of each row, the function stores a pointer to the row. At the end of the row, it increments the pointer by the width of the image stride, which advances the pointer to the next row.

This example calls a hypothetical function named TransformPixelValue for each pixel. This could be any function that calculates a target pixel from a source pixel. Of course, the exact details will depend on the particular task. For example, if you have a planar YUV format, you must access the chroma planes independently from the luma plane; with interlaced video, you might need to process the fields separately; and so forth.

To give a more concrete example, the following code converts a 32-bit RGB image into an AYUV image. The RGB pixels are accessed using an RGBQUAD structure, and the AYUV pixels are accessed using a DXVA2_AYUVSample8 Structure structure.

Copy Code

//-------------------------------------------------------------------

// Name: RGB32_To_AYUV

// Description: Converts an image from RGB32 to AYUV

//-------------------------------------------------------------------

void RGB32_To_AYUV(

BYTE* pDest,

LONG lDestStride,

const BYTE* pSrc,

LONG lSrcStride,

DWORD dwWidthInPixels,

DWORD dwHeightInPixels

)

{

for (DWORD y = 0; y < dwHeightInPixels; y++)

{

RGBQUAD *pSrcPixel = (RGBQUAD*)pSrc;

DXVA2_AYUVSample8 *pDestPixel = (DXVA2_AYUVSample8*)pDest;

for (DWORD x = 0; x < dwWidthInPixels; x++)

{

pDestPixel[x].Alpha = 0x80;

pDestPixel[x].Y = RGBtoY(pSrcPixel[x]);

pDestPixel[x].Cb = RGBtoU(pSrcPixel[x]);

pDestPixel[x].Cr = RGBtoV(pSrcPixel[x]);

}

pDest += lDestStride;

pSrc += lSrcStride;

}

}

The next example converts a 32-bit RGB image to a YV12 image. This example shows how to handle a planar YUV format. (YV12 is a planar 4:2:0 format.) In this example, the function maintains three separate pointers for the three planes in the target image. However, the basic approach is the same as the previous example.

Copy Code

void RGB32_To_YV12(

BYTE* pDest,

LONG lDestStride,

const BYTE* pSrc,

LONG lSrcStride,

DWORD dwWidthInPixels,

DWORD dwHeightInPixels

)

{

assert(dwWidthInPixels % 2 == 0);

assert(dwHeightInPixels % 2 == 0);



const BYTE *pSrcRow = pSrc;

BYTE *pDestY = pDest;



// Calculate the offsets for the V and U planes.

// In YV12, each chroma plane has half the stride and half the height as the Y plane.

BYTE *pDestV = pDest + (lDestStride * dwHeightInPixels);

BYTE *pDestU = pDest + (lDestStride * dwHeightInPixels) + ( (lDestStride * dwHeightInPixels) / 4 );



// Convert the Y plane.

for (DWORD y = 0; y < dwHeightInPixels; y++)

{

RGBQUAD *pSrcPixel = (RGBQUAD*)pSrcRow;

for (DWORD x = 0; x < dwWidthInPixels; x++)

{

pDestY[x] = RGBtoY(pSrcPixel[x]); // Y0

}

pDestY += lDestStride;

pSrcRow += lSrcStride;

}



// Convert the V and U planes.

// YV12 is a 4:2:0 format, so each chroma sample is derived from four RGB pixels.

pSrcRow = pSrc;

for (DWORD y = 0; y < dwHeightInPixels; y += 2)

{

RGBQUAD *pSrcPixel = (RGBQUAD*)pSrcRow;

RGBQUAD *pNextSrcRow = (RGBQUAD*)(pSrcRow + lSrcStride);



BYTE *pbV = pDestV;

BYTE *pbU = pDestU;



for (DWORD x = 0; x < dwWidthInPixels; x += 2)

{

// Use a simple average to downsample the chroma.



*pbV++ = ( RGBtoV(pSrcPixel[x]) +

RGBtoV(pSrcPixel[x + 1]) +

RGBtoV(pNextSrcRow[x]) +

RGBtoV(pNextSrcRow[x + 1]) ) / 4;



*pbU++ = ( RGBtoU(pSrcPixel[x]) +

RGBtoU(pSrcPixel[x + 1]) +

RGBtoU(pNextSrcRow[x]) +

RGBtoU(pNextSrcRow[x + 1]) ) / 4;

}

pDestV += lDestStride / 2;

pDestU += lDestStride / 2;

// Skip two lines on the source image.

pSrcRow += (lSrcStride * 2);

}

}

In all of these examples, it is assumed that the application has already determined the image stride. You can sometimes get this information from the media buffer. Otherwise, you must calculate it based on the video format. For more information about calculating image stride and working with media buffers for video, see Uncompressed Video Buffers.