<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fooling Around &#187; VMR</title>
	<atom:link href="http://alax.info/blog/tag/vmr/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>// Software Production Line</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:49:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to use windowless Video Mixing Renderer Filter to show video fullscreen</title>
		<link>http://alax.info/blog/1082</link>
		<comments>http://alax.info/blog/1082#comments</comments>
		<pubDate>Fri, 09 Oct 2009 17:04:27 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[fullscreen]]></category>
		<category><![CDATA[IVideoWidow]]></category>
		<category><![CDATA[IVMRWindowlessControl]]></category>
		<category><![CDATA[renderer]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[VMR]]></category>
		<category><![CDATA[windowless]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1082</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1082" title="How to use windowless Video Mixing Renderer Filter to show video fullscreen"></a>The question is being asked from time to time. Everyone knows what is full screen video. Video renderers implement full screen capability since long ago through their IVideoWindow::put_FullScreenMode property, and even Filter Graph Manager exposes its own IVideoWindow interface to &#8230;<p class="read-more"><a href="http://alax.info/blog/1082">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1082" title="How to use windowless Video Mixing Renderer Filter to show video fullscreen"></a><p>The question is being asked from time to time. Everyone knows what is full screen video. Video renderers implement full screen capability since long ago through their <a href="http://msdn.microsoft.com/en-us/library/dd377320(VS.85).aspx">IVideoWindow::put_FullScreenMode</a> property, and even <a href="http://msdn.microsoft.com/en-us/library/dd375786(VS.85).aspx">Filter Graph Manager</a> exposes its own <a href="http://msdn.microsoft.com/en-us/library/dd377276%28VS.85%29.aspx">IVideoWindow</a> interface to forward calls to filter&#8217;s implementation of <a href="http://msdn.microsoft.com/en-us/library/dd377276%28VS.85%29.aspx">IVideoWindow</a> interface.</p>
<p>However, for Video Mixing Renderers, version <a href="http://msdn.microsoft.com/en-us/library/dd407343(VS.85).aspx">7</a> and <a href="http://msdn.microsoft.com/en-us/library/dd407344%28VS.85%29.aspx">9</a>, the preferred and recommended mode is windowless, where no IVideoWindow interface is available.</p>
<blockquote><p><strong>Note</strong> The <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/dd390536%28VS.85%29.aspx"><strong>IVMRWindowlessControl</strong></a> or <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/dd390537%28VS.85%29.aspx"><strong>IVMRWindowlessControl9</strong></a> interface is now preferred over <strong>IVideoWindow</strong>. For more information, see <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/dd407299%28VS.85%29.aspx">Using Windowless Mode</a>.</p></blockquote>
<p>So in order to implement full screen mode it takes the application to attach Video Mixing Renderer filter to a private frameless window, to its entire client area and expand the window to entire monitor area.</p>
<p>The sample project <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01">FullScreenWindowlessVmrSample01</a> is illustrating this technique.</p>
<p><img class="alignnone size-full wp-image-1083" title="FullScreenWindowlessVmrSample01 Main Dialog" src="http://alax.info/blog/wp-content/uploads/2009/10/09-Image001.png" alt="FullScreenWindowlessVmrSample01 Main Dialog" width="489" height="141" /></p>
<p><span id="more-1082"></span>Main application dialog owns a special window to host renderer, implemented by CRendererDialog class.</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;"><span style="color: #800000; font-weight: bold;">class</span> CRendererDialog <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CDialogImpl<span style="color: #800080;">&lt;</span>CRendererDialog<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>

    <span style="color: #800000; font-weight: bold;">enum</span> <span style="color: #800080;">{</span> IDD <span style="color: #808030;">=</span> IDD_RENDERER <span style="color: #800080;">}</span><span style="color: #800080;">;</span>

BEGIN_MSG_MAP_EX<span style="color: #808030;">(</span>CRendererDialog<span style="color: #808030;">)</span>
    MSG_WM_INITDIALOG<span style="color: #808030;">(</span>OnInitDialog<span style="color: #808030;">)</span>
    MSG_WM_DESTROY<span style="color: #808030;">(</span>OnDestroy<span style="color: #808030;">)</span>
    MSG_WM_ERASEBKGND<span style="color: #808030;">(</span><span style="color: #400000;">OnEraseBkgnd</span><span style="color: #808030;">)</span>
    MSG_WM_PAINT<span style="color: #808030;">(</span>OnPaint<span style="color: #808030;">)</span>
    MSG_WM_DISPLAYCHANGE<span style="color: #808030;">(</span>OnDisplayChange<span style="color: #808030;">)</span>
    MSG_WM_KEYDOWN<span style="color: #808030;">(</span>OnKeyDown<span style="color: #808030;">)</span>
    COMMAND_ID_HANDLER_EX<span style="color: #808030;">(</span>IDCANCEL<span style="color: #808030;">,</span> OnCancel<span style="color: #808030;">)</span>
END_MSG_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span>

<span style="color: #800000; font-weight: bold;">private</span><span style="color: #e34adc;">:</span>
    CMainDialog<span style="color: #808030;">&amp;</span> m_Owner<span style="color: #800080;">;</span>
<span style="color: #696969;">//...</span></pre>
</pre>
<p>The dialog template does not have a caption, it has no frame and has its window rectangle equal to client area. As a result, spanning the Video Mixing Renderer to the entire client area and proper positioning of the dialog window is showing video on the entire monitor.</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;">ATLVERIFY<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">.</span>Create<span style="color: #808030;">(</span>m_hWnd<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLVERIFY<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">.</span><span style="color: #400000;">MoveWindow</span><span style="color: #808030;">(</span>MonitorData<span style="color: #808030;">.</span>m_Position<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
m_RendererDialog<span style="color: #808030;">.</span><span style="color: #400000;">ShowWindow</span><span style="color: #808030;">(</span>SW_SHOWNORMAL<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// ...</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pVmrWindowlessControl<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>SetVideoClippingWindow<span style="color: #808030;">(</span>m_RendererDialog<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pVmrWindowlessControl<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>SetVideoPosition<span style="color: #808030;">(</span><span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> m_RendererDialog<span style="color: #808030;">.</span>GetVideoPosition<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
</pre>
<p>Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FullScreenWindowlessVmrSample01/Release/FullScreenWindowlessVmrSample01.exe?format=raw">included</a>. The project is using ATL and <a href="http://wtl.sourceforge.net/">WTL</a> libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1082/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)</title>
		<link>http://alax.info/blog/1044</link>
		<comments>http://alax.info/blog/1044#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:01:25 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[VMR]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1044</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1044" title="How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)"></a>A 100-lines code snippet which illustrates how a bitmap is overlaid over displayed video with Video Mixing Renderer 9 Filter using IVMRMixerBitmap9 interface. A video clip is played (default is Windows clock.avi, but you can replace it with your longer &#8230;<p class="read-more"><a href="http://alax.info/blog/1044">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1044" title="How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)"></a><p>A 100-lines code snippet which illustrates how a bitmap is overlaid over displayed video with <a href="http://msdn.microsoft.com/en-us/library/dd407344%28VS.85%29.aspx">Video Mixing Renderer 9 Filter</a> using <a href="http://msdn.microsoft.com/en-us/library/dd390449%28VS.85%29.aspx">IVMRMixerBitmap9</a> interface. A video clip is played (default is Windows clock.avi, but you can replace it with your longer one to see overlay is really in a loop).</p>
<p><a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/VmrMixerBitmapSample01/VmrMixerBitmapSample01.cpp#ln49">http://code.assembla.com/&#8230;/VmrMixerBitmapSample01/&#8230;</a></p>
<pre>VMR9AlphaBitmap AlphaBitmap<span style="color: #800080;">;</span>
<span style="color: #400000;">ZeroMemory</span><span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>AlphaBitmap<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> AlphaBitmap<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>dwFlags <span style="color: #808030;">=</span> VMR9AlphaBitmap_hDC<span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>hdc <span style="color: #808030;">=</span> Dc<span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>rSrc <span style="color: #808030;">=</span> <span style="color: #603000;">CRect</span><span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">32</span><span style="color: #808030;">,</span> <span style="color: #008c00;">32</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>rDest<span style="color: #808030;">.</span>left <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">FLOAT</span><span style="color: #808030;">)</span> <span style="color: #008000;">0.75</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>rDest<span style="color: #808030;">.</span>top <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">FLOAT</span><span style="color: #808030;">)</span> <span style="color: #008000;">0.75</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>rDest<span style="color: #808030;">.</span>right <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">FLOAT</span><span style="color: #808030;">)</span> <span style="color: #008000;">0.95</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>rDest<span style="color: #808030;">.</span>bottom <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">FLOAT</span><span style="color: #808030;">)</span> <span style="color: #008000;">0.95</span><span style="color: #800080;">;</span>
AlphaBitmap<span style="color: #808030;">.</span>fAlpha <span style="color: #808030;">=</span> <span style="color: #008000;">0.75</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> HRESULT nSetAlphaBitmapResult <span style="color: #808030;">=</span> pVmrMixerBitmap<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>SetAlphaBitmap<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>AlphaBitmap<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nSetAlphaBitmapResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>With a low FPS clip like clock.avi it is clear that the overlaid image is only updated with the next &#8220;main&#8221; video frame.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/09/21-image002.png"><img class="alignnone size-medium wp-image-1045" title="IVMRMixerBitmap9 Usage Sample" src="http://alax.info/blog/wp-content/uploads/2009/09/21-image002-320x272.png" alt="IVMRMixerBitmap9 Usage Sample" width="320" height="272" /></a></p>
<p>Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/VmrMixerBitmapSample01/">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/VmrMixerBitmapSample01/Release/VmrMixerBitmapSample01.exe?format=raw">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1044/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YV12, Extended Video Renderer Strides, Private DMO and more</title>
		<link>http://alax.info/blog/893</link>
		<comments>http://alax.info/blog/893#comments</comments>
		<pubDate>Wed, 01 Apr 2009 07:48:45 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[DMO]]></category>
		<category><![CDATA[stride]]></category>
		<category><![CDATA[VMR]]></category>
		<category><![CDATA[wrapper]]></category>
		<category><![CDATA[YV12]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=893</guid>
		<description><![CDATA[<a href="http://alax.info/blog/893" title="YV12, Extended Video Renderer Strides, Private DMO and more"></a>Recently it was the time to sort out an issue with a video DMO, which outputs YV12 video and in the same time is capable of supporting extended video strides in order to efficiently make a direct connection to Video &#8230;<p class="read-more"><a href="http://alax.info/blog/893">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/893" title="YV12, Extended Video Renderer Strides, Private DMO and more"></a><p>Recently it was the time to sort out an issue with a video <a href="http://msdn.microsoft.com/en-us/library/dd375512(VS.85).aspx">DMO</a>, which outputs <a href="http://fourcc.org/yuv.php#YV12">YV12</a> video and in the same time is capable of supporting <a href="http://msdn.microsoft.com/en-us/library/dd388799(VS.85).aspx">extended video strides</a> in order to efficiently make a direct connection to <a href="http://msdn.microsoft.com/en-us/library/dd407343(VS.85).aspx">Video Mixing Renderer Filters</a>.</p>
<p>From past experience, I already knew that some bugs are definitely involved but their effect was yet unexplored. For a testbed application, I took good old <a href="http://alax.info/blog/551">FrameRateSample02</a> application, which generates multiple video feeds and routes it to video renderers:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/04/01-image001.png"><img class="alignnone size-full wp-image-894" title="FrameRateSample02 Application with New Choices" src="http://alax.info/blog/wp-content/uploads/2009/04/01-image001.png" alt="FrameRateSample02 Application with New Choices" width="539" height="317" /></a></p>
<p>With new source video choices the application is capable of constructing filter graphs that use a private DMO (that is hosted inside the executable) wrapped with <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a>, with a graph topology shown below:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/04/01-image002.png"><img class="alignnone size-medium wp-image-895" title="Filter Graph with a Private DMO" src="http://alax.info/blog/wp-content/uploads/2009/04/01-image002-300x172.png" alt="Filter Graph with a Private DMO" width="300" height="172" /></a></p>
<p><span id="more-893"></span>The DMO does not do any processing, except support for extended strides while copying original data into buffer streamed to video renderer. Extended strides for a planar YUV format is a bit tricky. Are they supported at all? Yes, they are and video renderer might still request an extended stride and in which case origial MxN video needs to be copied into (M+P)xN buffer. Unlike packed pixel format, unused space is distributed in a bit different way but still very much similarly: output buffer is still a regular  (M+P)xN rectangle, where the effective picture of size MxN should be copied into top left corner.</p>
<p>The problem I was aware of from past experience showed up immediately once the filters connected. After a dynamic format change initiated by the VMR, the filters report different connection media types. <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a> still shows original connection time connection media type, while <a href="http://msdn.microsoft.com/en-us/library/dd407343(VS.85).aspx">Video Mixing Renderer Filter</a> shows media type it switched to.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/04/01-image003.png"><img class="alignnone size-medium wp-image-896" title="Media Type Mismatch" src="http://alax.info/blog/wp-content/uploads/2009/04/01-image003-300x241.png" alt="Media Type Mismatch" width="300" height="241" /></a></p>
<p>This looks like <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a> bug, but was yet to check if it still handles the new media type properly and passes the format change to the underlying DMO object. Taking into consideration the extent DMOs are used by <a href="http://microsoft.com">Microsoft</a>, it had to, thought I never met this in the <a href="http://msdn.microsoft.com">MSDN</a> documentation.</p>
<p>Further debugging revealed that <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a> does handle the media type change and forward it to the DMO through <a href="http://msdn.microsoft.com/en-us/library/dd406963(VS.85).aspx">IMediaObject::SetOutputType</a> method. This happens when DMO already received its first input, and immediately before following <a href="http://msdn.microsoft.com/en-us/library/dd406960(VS.85).aspx">IMediaObject::ProcessOutput</a> method call:</p>
<pre>rodmo.h(293) : CMediaObjectT&lt;class CVideoDmo&gt;::AllocateStreamingResources: ...
rodshow.h(2716) : CBaseFilterT&lt;class CMainDialog::CSourceFilter&gt;::Pause: ...
rodshow.h(2722) : CBaseFilterT&lt;class CMainDialog::CSourceFilter&gt;::Pause: m_State 0
rodshow.h(2730) : CBaseFilterT&lt;class CMainDialog::CSourceFilter&gt;::Pause: m_State 1
rodshow.h(2784) : CBaseFilterT&lt;class CMainDialog::CSourceFilter&gt;::GetState: nTimeout 0
rodmo.h(679) : CSimpleMediaObjectT&lt;class CVideoDmo,1&gt;::GetInputStatus: nInputStreamIndex 0
<span style="color: #ff0000;"><strong>rodmo.h(702) : CSimpleMediaObjectT&lt;class CVideoDmo,1&gt;::ProcessInput: nInputStreamIndex 0, nFlags 0x1
rodmo.h(527) : CSimpleMediaObjectT&lt;class CVideoDmo,1&gt;::SetOutputType: nOutputStreamIndex 0, nFlags 0x0</strong>
</span>rodmo.h(727) : CSimpleMediaObjectT&lt;class CVideoDmo,1&gt;::ProcessOutput: nFlags 0x1, nOutputBufferCount 1</pre>
<p>So, the media type change is handled and the problem is only limited to reporting wrong (original) media type off the wrapper filter output pin.</p>
<p>Investigation of filter connection however brought up another interesting fact, memory allocator properties:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/04/01-image004.png"><img class="alignnone size-medium wp-image-897" title="Memory Allocator Properties" src="http://alax.info/blog/wp-content/uploads/2009/04/01-image004-300x241.png" alt="Memory Allocator Properties" width="300" height="241" /></a></p>
<p>As the filters switched to a new media type, with extended strides, the memory allocator should obviously have been updated accordingly, in order to support larger buffer. However current <a href="http://msdn.microsoft.com/en-us/library/dd373419(VS.85).aspx">memory allocator properties</a> indicate old buffer size of 460,800 bytes, while new media type assumes 737,280 buffer size at the very least. The samples are however streamed fine, so the issue is also limited to incorrectly reported size.</p>
<p>This memory allocator is managed by the <a href="http://msdn.microsoft.com/en-us/library/dd407343(VS.85).aspx">Video Mixing Renderer Filter</a>, so the problem seems to be relating to it.</p>
<p>Good news however was that video was streamed and displayed correctly.</p>
<p>One thing that deserves special attention is making a DMO private. I <a href="http://alax.info/blog/674">already wrote another post on private DMOs</a> some time ago, and this time the sample shows even a better way in case one does not need the DMO available for <a href="http://msdn.microsoft.com/en-us/library/dd390342(VS.85).aspx">Intelligent Connect</a> (in which case <a href="http://msdn.microsoft.com/en-us/library/dd375491.aspx">DMORegister</a> call along with administrative privileges will be required),  just for a private instantiation. DMO is typically created by <a href="http://msdn.microsoft.com/en-us/library/ms686615.aspx">CoCreateInstance</a> from inside the <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a>, e.g. using <a href="http://msdn.microsoft.com/en-us/library/dd406849(VS.85).aspx">IDMOWrapperFilter::Init</a> method, so it is necessary to either register COM class, or&#8230; just register its class object for the process using <a href="http://msdn.microsoft.com/en-us/library/ms693407.aspx">CoRegisterClassObject</a>.</p>
<p>There is no need for direct usage of API since ATL already wrapped the calls and we are to take advantage of what is already available. First of all, the DMO class requires certain CLSID, because we don&#8217;t have one typically declared in IDL. A good place for attaching CLSID is class declaration and <a href="http://msdn.microsoft.com/en-us/library/dabb5z75.aspx">__declspec keyword</a>:</p>
<pre><span style="color: #800000; font-weight: bold;">class</span> <span style="color: #800000; font-weight: bold;">__declspec</span><span style="color: #808030;">(</span>uuid<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">88B976BE-EEE6-45b1-A21B-42A941DF8819</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span> ATL_NO_VTABLE CVideoDmo <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CComObjectRootEx<span style="color: #800080;">&lt;</span>CComMultiThreadModelNoCS<span style="color: #800080;">&gt;</span><span style="color: #808030;">,</span>
    <span style="color: #800000; font-weight: bold;">public</span> CComCoClass<span style="color: #800080;">&lt;</span>CVideoDmo<span style="color: #800080;">&gt;</span><span style="color: #808030;">,</span>
    <span style="color: #800000; font-weight: bold;">public</span> CSimpleMediaObjectT<span style="color: #800080;">&lt;</span>CVideoDmo<span style="color: #808030;">,</span> <span style="color: #008c00;">1</span><span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span></pre>
<p>Further a COM class is typically referenced into module&#8217;s object map byan <a href="http://msdn.microsoft.com/en-us/library/exx3wywe.aspx">OBJECT_ENTRY_AUTO</a> macro:</p>
<pre><span class="Comment"><span class="Comment">//</span>OBJECT_ENTRY_AUTO(__uuidof(VideoDmo), CVideoDmo</span>)</pre>
<p>But we don&#8217;t need this this time as we don&#8217;t need standard COM registration for the class. We will register its class object manually and temporarily, at the time of DMO initialization:</p>
<pre>CComQIPtr<span style="color: #800080;">&lt;</span>IBaseFilter<span style="color: #800080;">&gt;</span> pBaseFilter<span style="color: #800080;">;</span>
CVideoDmo<span style="color: #808030;">*</span> pVideoDmo<span style="color: #800080;">;</span>
<span style="color: #800080;">{</span>
    BEGIN_OBJECT_MAP<span style="color: #808030;">(</span>g_pObjectMap<span style="color: #808030;">)</span>
        OBJECT_ENTRY<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>CVideoDmo<span style="color: #808030;">)</span><span style="color: #808030;">,</span> CVideoDmo<span style="color: #808030;">)</span>
    END_OBJECT_MAP<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    ATLASSERT<span style="color: #808030;">(</span>DIM<span style="color: #808030;">(</span>g_pObjectMap<span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #008c00;">2</span> <span style="color: #808030;">&amp;</span><span style="color: #808030;">&amp;</span> <span style="color: #808030;">!</span>g_pObjectMap<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span><span style="color: #808030;">.</span>pclsid<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>g_pObjectMap<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #808030;">.</span>RegisterClassObject<span style="color: #808030;">(</span>CLSCTX_INPROC_SERVER<span style="color: #808030;">,</span> REGCLS_SINGLEUSE<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    _ATLTRY
    <span style="color: #800080;">{</span>
        CComPtr<span style="color: #800080;">&lt;</span>IDMOWrapperFilter<span style="color: #800080;">&gt;</span> pDmoWrapperFilter <span style="color: #808030;">=</span> ConstructDmoWrappedFilter<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>CVideoDmo<span style="color: #808030;">)</span><span style="color: #808030;">,</span> CVideoDmo<span style="color: #800080;">::</span>GetCategory<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        pBaseFilter <span style="color: #808030;">=</span> pDmoWrapperFilter<span style="color: #800080;">;</span>
        ATLENSURE_THROW<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">,</span> E_NOINTERFACE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        CComQIPtr<span style="color: #800080;">&lt;</span>IMediaObject<span style="color: #800080;">&gt;</span> pMediaObject <span style="color: #808030;">=</span> pDmoWrapperFilter<span style="color: #800080;">;</span>
        ATLENSURE_THROW<span style="color: #808030;">(</span>pMediaObject<span style="color: #808030;">,</span> E_NOINTERFACE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        pVideoDmo <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">static_cast</span><span style="color: #800080;">&lt;</span>CVideoDmo<span style="color: #808030;">*</span><span style="color: #800080;">&gt;</span><span style="color: #808030;">(</span><span style="color: #808030;">(</span>IMediaObject<span style="color: #808030;">*</span><span style="color: #808030;">)</span> pMediaObject<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span>
    _ATLCATCHALL<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        ATLVERIFY<span style="color: #808030;">(</span>SUCCEEDED<span style="color: #808030;">(</span>g_pObjectMap<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #808030;">.</span>RevokeClassObject<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        _ATLRETHROW<span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span>
    ATLVERIFY<span style="color: #808030;">(</span>SUCCEEDED<span style="color: #808030;">(</span>g_pObjectMap<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: #808030;">.</span>RevokeClassObject<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>
pVideoDmo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Initialize<span style="color: #808030;">(</span>CDmoMediaType<span style="color: #808030;">(</span>m_pMediaType<span style="color: #808030;">)</span><span style="color: #808030;">,</span> CopyYv12MediaBuffer<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pGraphBuilder<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>AddFilter<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">,</span> CStringW<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Pass-Through DMO</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pGraphBuilder<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Connect<span style="color: #808030;">(</span>pOutputPin<span style="color: #808030;">,</span> _FilterGraphHelper<span style="color: #800080;">::</span>GetFilterPin<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">,</span> PINDIR_INPUT<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pOutputPin <span style="color: #808030;">=</span> _FilterGraphHelper<span style="color: #800080;">::</span>GetFilterPin<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">,</span> PINDIR_OUTPUT<span style="color: #808030;">)</span></pre>
<p>What is being done in the code snippet above is:</p>
<ul>
<li>local object map with a single <a href="http://msdn.microsoft.com/en-us/library/0f31291x.aspx">OBJECT_ENTRY</a> item to have ATL manage class object registration/revokation for us</li>
<li>registration of a private class/CLSID</li>
<li>instantiation and initialization of a <a href="http://msdn.microsoft.com/en-us/library/dd375519(VS.85).aspx">DMO Wrapper Filter</a> which is to pick up our class</li>
<li>cast back to native C++ pointer for easy further access (a private interface would be more accurate here)</li>
<li>revokation for CLSID</li>
</ul>
<p>For information, the interfaces queried from the DMO:</p>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;">Find all <span style="color: #800000;">"</span><span style="color: #0000e6;">CVideoDmo::InternalQueryInterface</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> Hidden<span style="color: #808030;">,</span> Find Results <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> Current Document
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IMediaObject<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x00000000</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IDMOQualityControl<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IDMOVideoOutputOptimizations<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IMediaObject<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x00000000</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IWMGetSecureChannel<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMOpenProgress<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMDeviceRemoval<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IDirectVobSub<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IDirectVobSub<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IWMCodecAMVideoAccelerator<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IDirectVobSub<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IWMCodecAMVideoAccelerator<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IWMCodecAMVideoAccelerator<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IMediaSeeking<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IMediaPosition<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMFilterMiscFlags<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IVideoWindow<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IBasicAudio<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMFilterMiscFlags<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IKsPropertySet<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IReferenceClock<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IWMCodecAMVideoAccelerator<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMDeviceRemoval<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
CVideoDmo<span style="color: #800080;">::</span>InternalQueryInterface<span style="color: #800080;">:</span> Interface IAMOpenProgress<span style="color: #808030;">,</span> Result <span style="color: #008000;">0x80004002</span>
Matching lines<span style="color: #800080;">:</span> <span style="color: #008c00;">24</span></pre>
<p>A Visual C++ .NET 2008 source code <a rel="nofollow" href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FrameRateSample02">is available from SVN</a>. Additional files will be required to compile, but <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FrameRateSample02/Release/FrameRateSample02.exe?format=raw">binary</a> is also incuded.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/893/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Multiple Windowless Video Mixing Renderers (VMR9) Sample</title>
		<link>http://alax.info/blog/711</link>
		<comments>http://alax.info/blog/711#comments</comments>
		<pubDate>Wed, 19 Nov 2008 11:05:12 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[renderer]]></category>
		<category><![CDATA[VMR]]></category>
		<category><![CDATA[windowless]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=711</guid>
		<description><![CDATA[<a href="http://alax.info/blog/711" title="Multiple Windowless Video Mixing Renderers (VMR9) Sample"></a>This is a begged MFC code for multiple windowless video renderers. MFC project, two independent video renderers hosted by the same parent window (actually through owned controls but this makes no major difference), VMR9 in windowless mode. There are no &#8230;<p class="read-more"><a href="http://alax.info/blog/711">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/711" title="Multiple Windowless Video Mixing Renderers (VMR9) Sample"></a><p>This is a <a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=4129792&amp;SiteID=1">begged</a> MFC code for multiple windowless video renderers. MFC project, two independent video renderers hosted by the same parent window (actually through owned controls but this makes no major difference), VMR9 in windowless mode.</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2008/11/19-image001.png"><img class="alignnone size-medium wp-image-712" title="MFC Windowless Video Renderer" src="http://alax.info/blog/wp-content/uploads/2008/11/19-image001-300x218.png" alt="" width="300" height="218" /></a></p>
<p>There are no <a href="http://msdn.microsoft.com/en-us/library/ms534901(VS.85).aspx">WM_PAINT</a>/<a href="http://msdn.microsoft.com/en-us/library/ms648055(VS.85).aspx">WM_ERASEBKGND</a> handlers, <a href="http://msdn.microsoft.com/en-us/library/ms787156(VS.85).aspx">IVMRWindowlessControl9::RepaintVideo</a> calls and other basically required code, instead a minimalistic snippet to make video rendered the requested way.</p>
<p>A Visual C++ .NET 2008 source code <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/MfcWindowlessVideoRenderer01">is available from SVN</a>, release binary <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/MfcWindowlessVideoRenderer01/Release/MfcWindowlessVideoRenderer01.exe?format=raw">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/711/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To: Save image to BMP file from IBasicVideo or VMR windowless interface</title>
		<link>http://alax.info/blog/602</link>
		<comments>http://alax.info/blog/602#comments</comments>
		<pubDate>Sun, 24 Aug 2008 11:30:29 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[bmp]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[VMR]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=602</guid>
		<description><![CDATA[<a href="http://alax.info/blog/602" title="How To: Save image to BMP file from IBasicVideo or VMR windowless interface"></a>A simple question being asked all over again. Given IBasicVideo, IBasicVideo2, IVMRWindowlessControl or IVMRWindowlessControl9, how to save image to file? It is easy. It is a bit easier with IBasicVideo because it is possible to query this interface directly from &#8230;<p class="read-more"><a href="http://alax.info/blog/602">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/602" title="How To: Save image to BMP file from IBasicVideo or VMR windowless interface"></a><p>A simple question being asked all over again. Given <a href="http://msdn.microsoft.com/en-us/library/ms784633(VS.85).aspx">IBasicVideo</a>, <a href="http://msdn.microsoft.com/en-us/library/ms784613(VS.85).aspx">IBasicVideo2</a>, <a href="http://msdn.microsoft.com/en-us/library/ms787170(VS.85).aspx">IVMRWindowlessControl</a> or <a href="http://msdn.microsoft.com/en-us/library/ms787155(VS.85).aspx">IVMRWindowlessControl9</a>, how to save image to file? It is easy. It is a bit easier with <a href="http://msdn.microsoft.com/en-us/library/ms784633(VS.85).aspx">IBasicVideo</a> because it is possible to query this interface directly from graph&#8217;s interface, such as <a href="http://msdn.microsoft.com/en-us/library/ms785794(VS.85).aspx">IGraphBuilder</a>, and the call will be forwarded to video renderer. This code assumes internal bitmap format is non-paletted, which I believe is always the case.</p>
<pre><span style="color: #603000;">LONG</span> nBufferSize <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pBasicVideo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>GetCurrentImage<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>nBufferSize<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
CHeapPtr<span style="color: #800080;">&lt;</span><span style="color: #603000;">BITMAPINFO</span><span style="color: #800080;">&gt;</span> pBitmapInfo<span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pBitmapInfo<span style="color: #808030;">.</span>AllocateBytes<span style="color: #808030;">(</span>nBufferSize<span style="color: #808030;">)</span><span style="color: #808030;">,</span> E_OUTOFMEMORY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pBasicVideo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>GetCurrentImage<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>nBufferSize<span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #603000;">LONG</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #603000;">BITMAPINFO</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> pBitmapInfo<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BYTE</span><span style="color: #808030;">*</span> pnData <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BYTE</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader <span style="color: #808030;">+</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// NOTE: You might wish to handle &lt;=8 bpp bitmaps here</span>
ATLASSERT<span style="color: #808030;">(</span>pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biBitCount <span style="color: #808030;">&gt;</span> <span style="color: #008c00;">8</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLASSERT<span style="color: #808030;">(</span>pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biCompression <span style="color: #808030;">=</span><span style="color: #808030;">=</span> BI_RGB<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLASSERT<span style="color: #808030;">(</span>pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSizeImage<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #603000;">BITMAPFILEHEADER</span> BitmapFileHeader<span style="color: #800080;">;</span>
<span style="color: #400000;">ZeroMemory</span><span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>BitmapFileHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BitmapFileHeader<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
BitmapFileHeader<span style="color: #808030;">.</span>bfType <span style="color: #808030;">=</span> <span style="color: #0000e6;">'MB'</span><span style="color: #800080;">;</span>
BitmapFileHeader<span style="color: #808030;">.</span>bfSize <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">DWORD</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">(</span><span style="color: #603000;">BITMAPFILEHEADER</span><span style="color: #808030;">)</span> <span style="color: #808030;">+</span> pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSize <span style="color: #808030;">+</span> pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSizeImage<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
BitmapFileHeader<span style="color: #808030;">.</span>bfOffBits <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">DWORD</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">(</span><span style="color: #603000;">BITMAPFILEHEADER</span><span style="color: #808030;">)</span> <span style="color: #808030;">+</span> pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSize<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>File<span style="color: #808030;">.</span>Write<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>BitmapFileHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BitmapFileHeader<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>File<span style="color: #808030;">.</span>Write<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">,</span> pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSize<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>File<span style="color: #808030;">.</span>Write<span style="color: #808030;">(</span>pnData<span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #603000;">DWORD</span><span style="color: #808030;">)</span> pBitmapInfo<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>bmiHeader<span style="color: #808030;">.</span>biSizeImage<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/602/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

