{"id":494,"date":"2008-07-26T15:14:47","date_gmt":"2008-07-26T13:14:47","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=494"},"modified":"2009-03-24T11:52:29","modified_gmt":"2009-03-24T09:52:29","slug":"how-to-implement-directshow-filter-using-directx-media-object-dmo-part-5-in-place-processing","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/494","title":{"rendered":"How To: Implement DirectShow Filter using DirectX Media Object DMO (Part 5: In-Place Processing)"},"content":{"rendered":"<p>Previously on the topic:<\/p>\n<ul>\n<li><a href=\"https:\/\/alax.info\/blog\/402\">Part 1: Starting the Project<\/a><\/li>\n<li><a href=\"https:\/\/alax.info\/blog\/412\">Part 2: Video Processing<\/a><\/li>\n<li><a href=\"https:\/\/alax.info\/blog\/433\">Part 3: Persistence, Automation and Property Pages<\/a><\/li>\n<li><a href=\"https:\/\/alax.info\/blog\/481\">Part 4: Merit<\/a><\/li>\n<\/ul>\n<p>Due to the nature of the brightness and constract correction processing, it would make sense to combine and simplify processing to apply correction &#8220;in-place&#8221;, that is without copying data from input to output buffer, but instead processing the same buffer before it is passed further downstream.<\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms783356(VS.85).aspx\">DMO API<\/a> offers additional optional <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785945(VS.85).aspx\">IMediaObjectInPlace<\/a> interface to be implemented on the DMO which the hosting object might prefer to regular <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785947(VS.85).aspx\">IMediaObject<\/a>.<\/p>\n<p>The interface itself is simple with basically the only Process method to actually handle the processing:<\/p>\n<pre>\/\/ IMediaObjectInPlace\r\n\tSTDMETHOD(Process)(ULONG nSize, BYTE* pnData, REFERENCE_TIME nStartTime, DWORD nFlags)\r\n\tSTDMETHOD(Clone)(IMediaObjectInPlace** ppMediaObject)\r\n\tSTDMETHOD(GetLatency)(REFERENCE_TIME* pnLatencyTime)<\/pre>\n<p><!--more--><\/p>\n<p>Still the interest in <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms786499(VS.85).aspx\">in-place processing in DMO<\/a> is more abstract because current <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms783389(VS.85).aspx\">DMO Wrapper Filter<\/a> implementation does not take advantage of in-place processing and chooses to always work through  <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785947(VS.85).aspx\">IMediaObject<\/a>.<\/p>\n<p>However if the object is hosted directly, in-place processing might make sense and be important.<\/p>\n<p>To support in-place processing in the DMO it is required to inherit from interface and add it to the COM map:<\/p>\n<pre>class ATL_NO_VTABLE CBrightnessContrastObject :\r\n\tpublic CComObjectRootEx&lt;CComMultiThreadModel&gt;,\r\n\t...\r\n<strong>\tpublic IMediaObjectInPlace\r\n<\/strong>...\r\nBEGIN_COM_MAP(CBrightnessContrastObject)\r\n\t...\r\n<strong>\tCOM_INTERFACE_ENTRY(IMediaObjectInPlace)\r\n<\/strong>END_COM_MAP()<\/pre>\n<p>And implement the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785945(VS.85).aspx\">IMediaObjectInPlace<\/a> methods, of which <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785946(VS.85).aspx\">IMediaObjectInPlace::Process<\/a> is the essential.<\/p>\n<p>Source code: <a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/dmobrightnesscontrastsample05.zip\">DmoBrightnessContrastSample.05.zip<\/a><a href=\"..\/wp-content\/uploads\/2008\/07\/dmobrightnesscontrastsample03.zip\"><\/a> (note that Release build binary is included)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously on the topic: Part 1: Starting the Project Part 2: Video Processing Part 3: Persistence, Automation and Property Pages Part 4: Merit Due to the nature of the brightness and constract correction processing, it would make sense to combine and simplify processing to apply correction &#8220;in-place&#8221;, that is without copying data from input to&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/494\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,10,20],"tags":[487,78,83,47,489],"class_list":["post-494","post","type-post","status-publish","format-standard","hentry","category-atl","category-source","category-video","category-wtl","tag-atl","tag-directshow","tag-dmo","tag-howto","tag-wtl"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=494"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/494\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}