<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Alex Mogurenko`s Blog</title>
	<atom:link href="http://alexmogurenko.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexmogurenko.com/blog</link>
	<description>Blog about site, programming and life</description>
	<pubDate>Thu, 19 Jan 2012 05:33:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>MPEG 1 Layer 2 multi bitrate audio encoder</title>
		<link>http://alexmogurenko.com/blog/uncategorized/mpeg-1-layer-2-multi-bitrate-audio-encoder/</link>
		<comments>http://alexmogurenko.com/blog/uncategorized/mpeg-1-layer-2-multi-bitrate-audio-encoder/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 14:13:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=28</guid>
		<description><![CDATA[Couple months ago I worked on audio conference project&#8230;
On first view everything looks pretty easy (what you need just capture video/audio compress it and send to destination + all encoders/decoders already implemented), but when firs beta was ready we found million underwater stones, even if my connection is fast enough it doesnt mean that connection [...]]]></description>
			<content:encoded><![CDATA[<p>Couple months ago I worked on audio conference project&#8230;<br />
On first view everything looks pretty easy (what you need just capture video/audio compress it and send to destination + all encoders/decoders already implemented), but when firs beta was ready we found million underwater stones, even if my connection is fast enough it doesnt mean that connection same fast on the other side <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>so as solution we decided to encode audio with different bitrates (bitrate depends on receiver connection speed) seems might be ok, but its quite expensive to run 3 or more encoders in the same time even on desktop (and almost impossible on mobile platforms).. after couple weeks fighting with this problem i decided to go different way, the most expensive part of all MPEG audio encoders is Psycho acoustic  model, but it not much depends on destination bitrate&#8230; as result I did implement multi bitrate MPEG 1 Layer 2 audio encoder that can encode in up 10 different bitrates in the same time with cpu usage pretty similar to single bitrate encoder.</p>
<p>I was not surprised that it works pretty well on Desktop (Windows/Linux) and mobile platforms (Windows CE/Android)</p>
<p>this post is kinda announcement of new project that i start i`m sure that that kind of encoder will be pretty useful for audio conference software or for online radio stations for example</p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/uncategorized/mpeg-1-layer-2-multi-bitrate-audio-encoder/feed/</wfw:commentRss>
		</item>
		<item>
		<title>max word value SSE2</title>
		<link>http://alexmogurenko.com/blog/programming/max-word-value-sse2/</link>
		<comments>http://alexmogurenko.com/blog/programming/max-word-value-sse2/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 08:12:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Optimization]]></category>

		<category><![CDATA[SIMD]]></category>

		<category><![CDATA[SSE]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=27</guid>
		<description><![CDATA[Not sure about everyone, but lots of programmers from time to time got task that on one of stage require to find maximum from unsorted array/memory/&#8230; of data. And the best
i was working on detecting microphone sound level. So i received buffer of 16 bit samples and to detect level i had to find max [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure about everyone, but lots of programmers from time to time got task that on one of stage require to find maximum from unsorted array/memory/&#8230; of data. And the best</p>
<p>i was working on detecting microphone sound level. So i received buffer of 16 bit samples and to detect level i had to find max absolute value. The simplest way just go through buffer and found max value:</p>
<pre class="brush: cpp">
__int16 find_abs_max(__int16 * data, unsigned size)
{
__int16 max = 0;
for (unsigned i = 0; i &amp;lt; size; ++i)
{
if (abs(data[i]) &amp;gt; max)
max = abs(data[i]);
}
return max;
}
</pre>
<p>what can we do to increase performance? sure we can sort data and we will have max value, but sometimes especially when we have huge array of data fast sort algorithm wont help for example some sort algorithms require one more additional buffer with same size. if algorithm does not require additional buffer can happen that we cannot modify current data buffer as it should be passed somewhere as in my case&#8230;</p>
<p>So if you not satisfied performance you could try SIMD as I did.</p>
<pre class="brush: cpp">
__int16 find_abs_max_sse(void * data, unsigned size)
{
__declspec(align(16)) __int16 return_buf[8];
__int16 * dst = &amp;amp;return_buf[0];

__int32 _size = size &amp;gt;&amp;gt; 4;

__asm
{
mov ecx, _size
mov esi, data
mov edi, dst

pxor xmm0, xmm0
pxor xmm6, xmm6
pxor xmm7, xmm7

NEXT:
movupd xmm1, [esi]
pmaxsw xmm6, xmm1
pminsw xmm7, xmm1

add esi, 16
dec ecx
or ecx, ecx
jnz NEXT

psubw xmm0, xmm7
pmaxsw xmm6, xmm7

movdqa [edi], xmm6
};

__int16 max = 0;
for (unsigned char i = 0; i &amp;lt; 8; ++i)
{
if (return_buf[i] &amp;gt; max)
max = return_buf[i];
}

return max;
}
</pre>
<p>measurement showed that SSE implementation 20 times faster (!!!) <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> if we dont need max by absolute value it should twice faster!</p>
<p>P.S. my SSE implementation work 100% correct only if buffer size in bytes dividable by 16 if its not true then we skip couple samples at the end, but its not difficult to fix.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/max-word-value-sse2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>HTCCamera v.1.0</title>
		<link>http://alexmogurenko.com/blog/uncategorized/htccamera-v10/</link>
		<comments>http://alexmogurenko.com/blog/uncategorized/htccamera-v10/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 12:28:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=26</guid>
		<description><![CDATA[HTC provides the simpliest DirectShow driver, that does not allow to chose resolution of frame that we want to grab&#8230; does not allow to control flash or autofocus and other available settings that default application allows&#8230;
Here is first version of HTCCamera class that works directly with driver as result we can choose resolution of grabbing [...]]]></description>
			<content:encoded><![CDATA[<p>HTC provides the simpliest DirectShow driver, that does not allow to chose resolution of frame that we want to grab&#8230; does not allow to control flash or autofocus and other available settings that default application allows&#8230;</p>
<p>Here is first version of HTCCamera class that works directly with driver as result we can choose resolution of grabbing frame, we can grab frames to memory without saving to storage. also it allows to control flash and autofocus!</p>
<p>In future it will allow to control brightness, saturation, hue, whiteballance so on&#8230;</p>
<p>First vesion you can <a href="http://alexmogurenko.com/DirectShowNETCF/HTCCamera.rar"title="HTCCamera"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/HTCCamera.rar');">download here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/uncategorized/htccamera-v10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to get focused/targeted image?</title>
		<link>http://alexmogurenko.com/blog/uncategorized/how-to-get-focusedtargeted-image/</link>
		<comments>http://alexmogurenko.com/blog/uncategorized/how-to-get-focusedtargeted-image/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 20:22:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=25</guid>
		<description><![CDATA[After i added functionality to draw target/rectangle on preview, i received some emails with question how to grab part that exactly in rectagnle.
Ok you dont need anything special and any lib, for example you draw target with

Rect _rect

then to grab that part you need:
1. Grab full image

Bitmap bmp = new Bitmap(width, height);
System.Drawing.Imaging.BitmapData data = bmp.LockBits(new [...]]]></description>
			<content:encoded><![CDATA[<p>After i added functionality to draw target/rectangle on preview, i received some emails with question how to grab part that exactly in rectagnle.</p>
<p>Ok you dont need anything special and any lib, for example you draw target with</p>
<pre class="brush: csharp">
Rect _rect
</pre>
<p>then to grab that part you need:</p>
<p>1. Grab full image</p>
<pre class="brush: csharp">
Bitmap bmp = new Bitmap(width, height);
System.Drawing.Imaging.BitmapData data = bmp.LockBits(new Rectangle(0, 0, width, height),
System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);

bFlag = cam_.getRgb565(data.Scan0);
bmp.UnlockBits(data);
</pre>
<p>2. Create 2nd bitmap</p>
<pre class="brush: csharp">
Bitmap bmp2 = new Bitmap(_rect.Right - _rect.Left, _rect.Bottom - _rect.Top);
</pre>
<p>3. Using Graphics cut required part</p>
<pre class="brush: csharp">
gr.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height),
new Rectangle(_rect.Left, _rect.Top, bmp2.Width, bmp2.Height), GraphicsUnit.Pixel);
</pre>
<p>bmp2 - result bitmap and its exactly what you need</p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/uncategorized/how-to-get-focusedtargeted-image/feed/</wfw:commentRss>
		</item>
		<item>
		<title>More samplegrabber chages</title>
		<link>http://alexmogurenko.com/blog/programming/more-samplegrabber-chages/</link>
		<comments>http://alexmogurenko.com/blog/programming/more-samplegrabber-chages/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 10:46:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=24</guid>
		<description><![CDATA[Made some changes in samplegrabber and IGetFrame interface now you can define target position and target type, so new IGetFrame:

[ComVisible(true), ComImport,
Guid(&#34;2B21644A-D405-4E27-A51C-A4812bE0CE4C&#34;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);

[PreserveSig]
int getFrameParams(
[Out] out int width,
[Out] out int height,
[Out] out RawFrameFormat format);

[PreserveSig]
int drawText(
[In] IntPtr ptr,
[In] int height,
[In] int width);

[PreserveSig]
int stopDraw();

[PreserveSig]
int getGrayScale(IntPtr ptr);

[PreserveSig]
int getRgb(IntPtr ptr);

[PreserveSig]
int drawTarget(Rect rect, int type);

[PreserveSig]
int [...]]]></description>
			<content:encoded><![CDATA[<p>Made some changes in samplegrabber and IGetFrame interface now you can define target position and target type, so new IGetFrame:</p>
<pre class="brush: csharp">
[ComVisible(true), ComImport,
Guid(&quot;2B21644A-D405-4E27-A51C-A4812bE0CE4C&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);

[PreserveSig]
int getFrameParams(
[Out] out int width,
[Out] out int height,
[Out] out RawFrameFormat format);

[PreserveSig]
int drawText(
[In] IntPtr ptr,
[In] int height,
[In] int width);

[PreserveSig]
int stopDraw();

[PreserveSig]
int getGrayScale(IntPtr ptr);

[PreserveSig]
int getRgb(IntPtr ptr);

[PreserveSig]
int drawTarget(Rect rect, int type);

[PreserveSig]
int stopDrawTarget();
}
</pre>
<p>P.S. dont forget that rect depends of frame size, not control size.</p>
<p><a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">Link to new library version</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/more-samplegrabber-chages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Samplegrabber Changes</title>
		<link>http://alexmogurenko.com/blog/programming/samplegrabber-changes/</link>
		<comments>http://alexmogurenko.com/blog/programming/samplegrabber-changes/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 12:11:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=23</guid>
		<description><![CDATA[I made some changes in native part of library (Samplegrabber) now we can use up to 3 samplegrabbers in the same time and now you can PIvoke for samplegrabber like in bellow code:

[DllImport(&#34;DirectShowNETCF.Native.dll&#34;)]
private static extern IntPtr GetBaseFilter(int index);

[DllImport(&#34;DirectShowNETCF.Native.dll&#34;)]
private static extern void DeleteBaseFilter(int index);

also interface IBaseFrame has been changed:

[ComVisible(true), ComImport,
Guid(&#34;2B21644A-D405-4E27-A51C-A4812bE0CE4C&#34;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out [...]]]></description>
			<content:encoded><![CDATA[<p>I made some changes in native part of library (Samplegrabber) now we can use up to 3 samplegrabbers in the same time and now you can PIvoke for samplegrabber like in bellow code:</p>
<pre class="brush: csharp">
[DllImport(&quot;DirectShowNETCF.Native.dll&quot;)]
private static extern IntPtr GetBaseFilter(int index);

[DllImport(&quot;DirectShowNETCF.Native.dll&quot;)]
private static extern void DeleteBaseFilter(int index);
</pre>
<p>also interface IBaseFrame has been changed:</p>
<pre class="brush: csharp">
[ComVisible(true), ComImport,
Guid(&quot;2B21644A-D405-4E27-A51C-A4812bE0CE4C&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);

[PreserveSig]
int getFrameParams(
[Out] out int width,
[Out] out int height,
[Out] out RawFrameFormat format);

[PreserveSig]
int drawText(
[In] IntPtr ptr,
[In] int height,
[In] int width);

[PreserveSig]
int stopDraw();

[PreserveSig]
int getGrayScale(IntPtr ptr);

[PreserveSig]
int getRgb(IntPtr ptr);

[PreserveSig]
int drawTarget();

[PreserveSig]
int stopDrawTarget();
}
</pre>
<p>all this changes was made for new functionality (grabbing rgb or grayscale frames for RGB565 or YV12 fromats, drawing target on preview, using more then 1 sample grabber in 1 application)</p>
<p>You can check updated AMCamera example from <a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">DirectShowNETCF</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/samplegrabber-changes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[Windows Mobile]Draw Text on preview or SampleGrabber and DirectShow.NETCF</title>
		<link>http://alexmogurenko.com/blog/programming/windows-mobiledraw-text-on-preview-or-samplegrabber-and-directshownetcf/</link>
		<comments>http://alexmogurenko.com/blog/programming/windows-mobiledraw-text-on-preview-or-samplegrabber-and-directshownetcf/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 14:23:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[.net compact framework]]></category>

		<category><![CDATA[C Sharp]]></category>

		<category><![CDATA[camera]]></category>

		<category><![CDATA[camera capture]]></category>

		<category><![CDATA[camera preview]]></category>

		<category><![CDATA[directshow]]></category>

		<category><![CDATA[Directshow .NET CF]]></category>

		<category><![CDATA[draw text on video]]></category>

		<category><![CDATA[sample grabber]]></category>

		<category><![CDATA[samplegrabber]]></category>

		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=20</guid>
		<description><![CDATA[If you ever used DirectShow under windows then you know that if you want draw text on preview you can use VMRRenderer, but windows mobile dont provide any way to draw text on preview  
I see there only 1 way to solve it - Draw text directly on stream, so we need SampleGrabber to [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever used DirectShow under windows then you know that if you want draw text on preview you can use VMRRenderer, but windows mobile dont provide any way to draw text on preview <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I see there only 1 way to solve it - Draw text directly on stream, so we need SampleGrabber to got access to raw stream, also we need to create our own font (thats the main problem). i made small demo that allows draw text on preview.</p>
<p>So IGetFrame was modified:</p>
<pre class="brush: csharp">
[ComVisible(true), ComImport,
Guid(&quot;2B21644A-D405-4E27-A51C-A4812bE0CE4C&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);

[PreserveSig]
int getFrameParams(
[Out] out int width,
[Out] out int height,
[Out] out RawFrameFormat format);

[PreserveSig]
int drawText(
[In] IntPtr ptr,
[In] int height,
[In] int width);

[PreserveSig]
int stopDraw();
}
</pre>
<p>As you can see we got new method: drawText([In] IntPtr ptr, [In] int height, [In] int width);<br />
where ptr - is our text in special format&#8230;<br />
how to conver text to IntPtr?<br />
there added extra class: CABC, here is example how to draw text:</p>
<pre class="brush: csharp">
CABC abc = new CABC(&quot;abcd dabc cdab bcda&quot;);
frmGrabber.drawText(abc.getText(), abc.Height, abc.Width);
abc.Dispose();
abc = null;
</pre>
<p>Also you can check AMCamera example from <a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">DirectShowNETCF</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/windows-mobiledraw-text-on-preview-or-samplegrabber-and-directshownetcf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[Windows Mobile] Capturing Raw Frames or SampleGrabber and DirectShow.NETCF</title>
		<link>http://alexmogurenko.com/blog/programming/windows-mobile-capturing-raw-frames-or-samplegrabber-and-directshownetcf/</link>
		<comments>http://alexmogurenko.com/blog/programming/windows-mobile-capturing-raw-frames-or-samplegrabber-and-directshownetcf/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 15:47:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C Sharp]]></category>

		<category><![CDATA[camera]]></category>

		<category><![CDATA[directshow]]></category>

		<category><![CDATA[directshownetcf]]></category>

		<category><![CDATA[grabbing raw frames]]></category>

		<category><![CDATA[samplegrabber]]></category>

		<category><![CDATA[still image]]></category>

		<category><![CDATA[video preview]]></category>

		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=19</guid>
		<description><![CDATA[What is SampleGrabber? this is filter (as a rule Transform or TransInPlace) that goes after filter which samples we are going to grab.
Why do we need SampleGrabber?
1. In windows mobile this is the fastest way to still images, more than that we still uncompressed images (so we dont loose time for encoding/decoding)
2. We can use [...]]]></description>
			<content:encoded><![CDATA[<p>What is SampleGrabber? this is filter (as a rule Transform or TransInPlace) that goes after filter which samples we are going to grab.</p>
<p>Why do we need SampleGrabber?<br />
1. In windows mobile this is the fastest way to still images, more than that we still uncompressed images (so we dont loose time for encoding/decoding)<br />
2. We can use SampleGrabber to draw text or images on received stream<br />
3. We grab images to memory.</p>
<p>I Think this is enough to say that sample grabber is useful.<br />
The problem is that windows already have sample grabber and we dont need to make any extra moves to use it, but Windows Mobile knows nothing about sample grabber <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>On <a href="http://alexmogurenko.com/blog/wp-content/plugins/wp-noexternallinks/goto.php?www.codeproject.com"title="CodeProject"  >www.codeproject.com</a> you can find some articles that explain how to implement SampleGrabber. But there tons limits and problems in every case, so i decided to implement my own.</p>
<p>The main question was &#8220;Is it possible to implement SampleGrabber that not need to registered?&#8221;. I meant that if i programming on C++ i can use unit (class) that contain samplegrabber code, i if i programming on any other language i can use this unit compiled to dll. Yes its possible (!!!!) we dont need resvrCE and anything else, just unit or dll <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was going to use developed SampleGrabber for barcode reader, but samples that i receive were too blurred to be recognized even by human (may be this is my cam dieing? O,o). anyway that was reason i decided to stop work on it, so here is what i got for this time:</p>
<p>DirectShowNETCF.Native.dll that contain SampleGrabber. How to use it?</p>
<pre class="brush: csharp">
[DllImport(&quot;DirectShowNETCF.Native.dll&quot;)]
private static extern IntPtr GetBaseFilter();
</pre>
<p>this is method returns IntPtr that equal to IBaseFilter*</p>
<p>how to get IBaseFilter?</p>
<pre class="brush: csharp">
IntPtr grabber_ = GetBaseFilter();
IBaseFilter grabber = (IBaseFilter)Marshal.GetTypedObjectForIUnknown(grabber_, typeof(IBaseFilter));
</pre>
<p>To grab raw frame you have to call<br />
1. getSize(out long size)<br />
2. alloc memory (use DirectShowNETCF.PInvoke.LocalAlloc(0&#215;40, size))<br />
3. call getFrame(IntPtr pBuff)</p>
<pre class="brush: csharp">
[ComVisible(true), ComImport,
Guid(&quot;2B21644A-D405-4E27-A51C-A4812bE0CE4C&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGetFrame
{
[PreserveSig]
int getFrame(IntPtr pBuff);

[PreserveSig]
int getSize([Out] out long size);
}

//example of grabbing frame
public IntPtr grabFrame(ref long bufSize)
{
IntPtr res_ = IntPtr.Zero;
long size = 0;
frmGrabber.getSize(out size);
bufSize = size;
res_ = PInvoke.LocalAlloc(0x40, (int)size);
frmGrabber.getFrame(res_);
return res_;
}
</pre>
<p>last version of DirectShowNETCF you can download <a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/windows-mobile-capturing-raw-frames-or-samplegrabber-and-directshownetcf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[Windows Mobile] Changing still image resolution or DirectShow.NETCF part IV</title>
		<link>http://alexmogurenko.com/blog/programming/windows-mobile-changing-still-image-resolution-or-directshownetcf-part-iv/</link>
		<comments>http://alexmogurenko.com/blog/programming/windows-mobile-changing-still-image-resolution-or-directshownetcf-part-iv/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 12:24:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C Sharp]]></category>

		<category><![CDATA[camera]]></category>

		<category><![CDATA[directshow]]></category>

		<category><![CDATA[directshownetcf]]></category>

		<category><![CDATA[resolution]]></category>

		<category><![CDATA[still image]]></category>

		<category><![CDATA[video preview]]></category>

		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=18</guid>
		<description><![CDATA[Most of us who was trying to use DirectShowNETCF found that resolution of stilled image smaller that it could be, for example my device (Samsung i710) got default resolution on still pin 320&#215;240, but i know that it supports resolutions up to 2Mpx. So that should be fixed  
What do we need to change [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us who was trying to use DirectShowNETCF found that resolution of stilled image smaller that it could be, for example my device (Samsung i710) got default resolution on still pin 320&#215;240, but i know that it supports resolutions up to 2Mpx. So that should be fixed <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What do we need to change resolution?<br />
1. We need Enum supported:</p>
<ul>
<li>Find STILL pin</li>
<li>using <a href="http://alexmogurenko.com/blog/wp-content/plugins/wp-noexternallinks/goto.php?msdn.microsoft.com%2Fen-us%2Flibrary%2Fdd376600%28VS.85%29.aspx"title="MSDN"  >IEnumMediatypes</a> enumerate supported mediatypes</li>
</ul>
<p>2. Using <a href="http://alexmogurenko.com/blog/wp-content/plugins/wp-noexternallinks/goto.php?msdn.microsoft.com%2Fen-us%2Flibrary%2Fdd319784%28VS.85%29.aspx"title="MSDN"  >IAMStreamConfig</a> set required mediatype to required pin (STILL pin in our case)</p>
<p>here is interfaces:</p>
<pre class="brush: csharp">
[ComVisible(true), ComImport,
Guid(&quot;89C31040-846B-11CE-97D3-00AA0055595A&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumMediaTypes
{
[PreserveSig]
int Next(
[In] int cMediaTypes,
[Out] out IntPtr ppMediaTypes,
[Out] out int pcFetched
);

[PreserveSig]
int Skip([In] int cMediaTypes);

[PreserveSig]
int Reset();

[PreserveSig]
int Clone([Out] out IEnumMediaTypes ppEnum);
}

[ComVisible(true), ComImport,
Guid(&quot;C6E13340-30AC-11D0-A18C-00A0C9118956&quot;),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAMStreamConfig
{
[PreserveSig]
int SetFormat([In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType pmt);

[PreserveSig]
int GetFormat([Out] out IntPtr pmt);

[PreserveSig]
int GetNumberOfCapabilities(
[Out] out int piCount,
[Out] out int piSize);

[PreserveSig]
int GetStreamCaps(
[In] int iIndex,
[Out] out IntPtr ppmt,
[In] IntPtr pSCC
);
}
</pre>
<p>Also was created useful class CEnumMediatypes (as in DSPack)</p>
<pre class="brush: csharp">
public class CEnumMediaTypes
{
private List&amp;lt;AMMediaType&amp;gt; FList;
private IEnumMediaTypes EnumMediaTypes;
private IntPtr Mt;
public void Free()
{
Clear();
}

public CEnumMediaTypes()
{
FList = new List&amp;lt;AMMediaType&amp;gt;();
}

private void Clear()
{
for (int i = 0; i &amp;lt; FList.Count; i++)
{
DirectShowEx.FreeMediaType(FList[i]);
FList[0] = null;
FList.RemoveAt(0);
}

FList.Clear();
}

public int Count
{
get
{
return FList.Count;
}
}

public void Assign(ICaptureGraphBuilder2 capGraph, IBaseFilter filter, Guid category)
{
Clear();

IPin pin_ = null;
CGuid guid = new CGuid(category);
CGuid guid2 = new CGuid(CLSID_.MEDIATYPE_Video);
int res = capGraph.FindPin(filter, PinDirection.Output, guid, guid2, true, 0, out pin_);

if (res &amp;gt; -1)
{
pin_.EnumMediaTypes(out EnumMediaTypes);
if (EnumMediaTypes == null)
{
return;
}

int fetched = 0;

int hr = EnumMediaTypes.Next(1, out Mt, out fetched);
while (hr == 0)
{
fetched = 0;
hr = EnumMediaTypes.Next(1, out Mt, out fetced);
AMMediaType mt = (AMMediaType)Marshal.PtrToStructure(Mt, typeof(AMMediaType));
FList.Add(mt);
}

Marshal.ReleaseComObject(EnumMediaTypes);
Marshal.ReleaseComObject(pin_);
}
}

private string getFourCC(int value)
{
IntPtr ptr = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(ptr, value);
byte[] bt = new byte[4];
Marshal.Copy(ptr, bt, 0, 4);
Marshal.FreeHGlobal(ptr);
char[] ch = new char[4];
for (int i = 0; i &amp;lt; 4; i++)
{
ch[i] = (char)bt[i];
}
bt = null;
return new string(ch);
}

public string GetMediaDescription(int index)
{
string result = &quot;&quot;;

AMMediaType tempType = FList[index];
if (tempType.formatType == CLSID_.VideoInfo)
{
result += ((VideoInfoHeader)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader))).BmiHeader.Width.ToString();
result += &#039;X&#039;;
result += ((VideoInfoHeader)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader))).BmiHeader.Height.ToString();
}
else
{
if (tempType.formatType == CLSID_.VideoInfo2)
{
result += ((VideoInfoHeader2)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader2))).BmiHeader.Width.ToString();
result += &#039;X&#039;;
result += ((VideoInfoHeader2)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader2))).BmiHeader.Height.ToString();
}
}

tempType = null;
return result;
}

public AMMediaType this[int index]
{
get
{
return FList[index];
}
}

}
</pre>
<p>Exaple how to set/change resolution is <a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/windows-mobile-changing-still-image-resolution-or-directshownetcf-part-iv/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[Windows Mobile]Stilling images from Camera C# or DirectShow .NETCF part III</title>
		<link>http://alexmogurenko.com/blog/programming/windows-mobilestilling-images-from-camera-c-or-directshow-netcf-part-iii/</link>
		<comments>http://alexmogurenko.com/blog/programming/windows-mobilestilling-images-from-camera-c-or-directshow-netcf-part-iii/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 20:30:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C Sharp]]></category>

		<category><![CDATA[camera]]></category>

		<category><![CDATA[directshow]]></category>

		<category><![CDATA[directshownetcf]]></category>

		<category><![CDATA[still image]]></category>

		<category><![CDATA[video preview]]></category>

		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://alexmogurenko.com/blog/?p=16</guid>
		<description><![CDATA[Ok, most popular question for last week was: &#8220;How to still images from windows mobile camera?&#8221;
I finished my project little bit earlier that i was planing, so i have free time again and looking for job too  
So what do we need? tons extra com interfaces (Ipin, IEnumPins, IEnumFilters, IFileSinkFilter, IAMVideoControl and so on).
Also [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, most popular question for last week was: &#8220;How to still images from windows mobile camera?&#8221;<br />
I finished my project little bit earlier that i was planing, so i have free time again and looking for job too <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So what do we need? tons extra com interfaces (Ipin, IEnumPins, IEnumFilters, IFileSinkFilter, IAMVideoControl and so on).</p>
<p>Also i implemented 2 useful classes (as for me) CPinList and CFilterList (the same as in DSPack).</p>
<pre class="brush: csharp">
public class CFilterList
{
private List&amp;lt;IBaseFilter&amp;gt; Filters;
private IEnumFilters enumFilters = null;
public CFilterList()
{
Filters = new List&amp;lt;IBaseFilter&amp;gt;();
}
~CFilterList()
{
Free();
Filters = null;
}
public void Assign(IGraphBuilder fg)
{
Clear();
fg.EnumFilters(out enumFilters);
IBaseFilter Filter;
int fetched = 0;

while (enumFilters.Next(1, out Filter, out fetched) == 0)
{
Filters.Add(Filter);
}

Marshal.ReleaseComObject(enumFilters);
enumFilters = null;
}
public int Count
{
get
{
return Filters.Count;
}
}
public IBaseFilter this[int index]
{
get
{
return Filters[index];
}
}
public void Free()
{
Clear();
}
private void Clear()
{
while (Filters.Count &amp;gt; 0)
{
Marshal.ReleaseComObject(Filters[0]);
Filters[0] = null;
Filters.RemoveAt(0);
}

Filters.Clear();
}
}

public class CPinList
{
private List&amp;lt;IPin&amp;gt; Pins = null;
private IEnumPins enumPins = null;

public CPinList()
{
Pins = new List&amp;lt;IPin&amp;gt;();
}

~CPinList()
{
Free();
Pins = null;
}

public int Count
{
get
{
return Pins.Count;
}
}

public IPin this[int index]
{
get
{
return Pins[index];
}
}

public void Assign(IBaseFilter filter)
{
Clear();
filter.EnumPins(out enumPins);

IPin pin;
int fetched = 0;

while (enumPins.Next(1, out pin, out fetched) == 0)
{
Pins.Add(pin);
}

Marshal.ReleaseComObject(enumPins);
enumPins = null;

}

private void Clear()
{
while (Pins.Count &amp;gt; 0)
{
Marshal.ReleaseComObject(Pins[0]);
Pins[0] = null;
Pins.RemoveAt(0);
}
Pins.Clear();
}

public void Free()
{
Clear();
}
}
</pre>
<p>so now stilling images works, btw in the same time with preview, but there some bad news (if we can call it so):<br />
a) it takes like 15 seconds to build graph <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
b) when i still image preview hangs for like 2 seconds.</p>
<p>good news:<br />
a) we can implement samplegrabber filter and do not wait when stilling images and building graph<br />
b) filter of video capture device has 3 output pins (on my device), i`m not sure, but seems like: preview, still image and probably still video <img src='http://alexmogurenko.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> will try to check it soon</p>
<p>And last one perhaps preview and stilling images wont work on some devices in the same time so you will need to choose what exactly you need (but this is only unconfirmed &#8220;perhaps&#8221;)</p>
<p><a href="http://alexmogurenko.com/DirectShowNETCF/DirectShowNETCF.zip"title="DirectShowNETCF"  onclick="javascript:urchinTracker('/downloads/DirectShowNETCF/DirectShowNETCF.zip');">Almost forgot</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alexmogurenko.com/blog/programming/windows-mobilestilling-images-from-camera-c-or-directshow-netcf-part-iii/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

