{"id":481,"date":"2008-07-26T00:44:46","date_gmt":"2008-07-25T22:44:46","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=481"},"modified":"2017-08-22T08:20:58","modified_gmt":"2017-08-22T06:20:58","slug":"how-to-implement-directshow-filter-using-directx-media-object-dmo-part-4-merit","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/481","title":{"rendered":"How To: Implement DirectShow Filter using DirectX Media Object DMO (Part 4: Merit)"},"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<\/ul>\n<p>The implemented so far filter\/DMO shown a problem related to its unexpectedly high &#8220;importance&#8221; in the system with the symptom of &#8220;auto-insertion&#8221; the filter when it is not necessary. For example, let us render an AVI file through <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms786496(VS.85).aspx\">Infinite Tee Pin Filter<\/a>:<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image011.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-482\" title=\"Rendering AVI file through Infinite Tee Pin Filter\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image011-300x78.png\" alt=\"\" width=\"300\" height=\"78\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image011-300x78.png 300w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image011.png 995w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The problem is that DirectShow auto-inserts our Brightness\/Contrast filter into the graph while it is obviously not expected, wanted or necessary:<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image012.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-483\" title=\"Auto-inserted Brightness\/Contrast filter\/DMO\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image012-300x65.png\" alt=\"\" width=\"300\" height=\"65\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image012-300x65.png 300w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image012.png 1186w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The problem is high filter\/DMO <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa920889.aspx\">merit<\/a> value and a popular <a href=\"http:\/\/fourcc.org\/yuv.php#YUY2\">YUY2<\/a> video format the filter is advertised to accept on input during DMO registration.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image013.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-484\" title=\"Brightness\/Contrast filter\/DMO merit\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image013-253x300.png\" alt=\"\" width=\"253\" height=\"300\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image013-253x300.png 253w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/image013.png 450w\" sizes=\"auto, (max-width: 253px) 100vw, 253px\" \/><\/a><\/p>\n<p>The merit is <strong>0x00600800<\/strong> and defined values are:<\/p>\n<pre>enum\r\n{\r\n    MERIT_PREFERRED     = 0x800000,\r\n<strong>    MERIT_NORMAL        = 0x600000,\r\n<\/strong>    MERIT_UNLIKELY      = 0x400000,\r\n    MERIT_DO_NOT_USE    = 0x200000,\r\n    MERIT_SW_COMPRESSOR = 0x100000,\r\n    MERIT_HW_COMPRESSOR = 0x100050\r\n};<\/pre>\n<p>So the filter&#8217;s merit is <strong>MERIT_NORMAL<\/strong> plus <strong>0x800<\/strong> DMO API adds to give DMOs an advantage over regular filters. If we followed merit choice guidelines (&#8220;<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa920889.aspx\"><em>A filter that should never be considered for ordinary playback should have a  merit of MERIT_DO_NOT_USE or less<\/em><\/a>&#8220;), we would have taken <strong>MERIT_DO_NOT_USE<\/strong> value or <strong>MERIT_UNLIKELY<\/strong> at the very most, because the nature of this filter is to provide additional processing feature when it is explicitly requested by the graph creator.<\/p>\n<p>So in order to resolve the problem we need to override DMO&#8217;s default merit and review the registration step. To provide our own merit value for the filter, we need to create a <strong>REG_DWORD<\/strong> Merit value in advance under coclass registry key in <strong>HKEY_CLASSES_ROOT<\/strong>:<\/p>\n<pre>OLECHAR pszClassIdentifier[64] = { 0 };\r\nATLVERIFY(StringFromGUID2(GetObjectCLSID(), pszClassIdentifier, _countof(pszClassIdentifier)));\r\nCRegKey Key;\r\nCString sKeyName;\r\nsKeyName.Format(_T(\"CLSID\\\\%ls\"), pszClassIdentifier);\r\n__C(HRESULT_FROM_WIN32(Key.Create(HKEY_CLASSES_ROOT, sKeyName)));\r\nstatic const DWORD g_nMerit = MERIT_DO_NOT_USE;\r\n__C(HRESULT_FROM_WIN32(Key.SetDWORDValue(_T(\"Merit\"), g_nMerit)));<\/pre>\n<p>Note that another (even easier) way to pre-create this registry value is putting it into .RGS registration script file (MERIT_DO_NOT_USE = 0x00200000 = 2097152):<\/p>\n<pre>HKCR\r\n{\r\n\t...\r\n\tNoRemove CLSID\r\n\t{\r\n\t\tForceRemove {334BE85B-9DE4-4405-8EEE-9CBB2650F83D} = s 'BrightnessContrastObject Class'\r\n\t\t{\r\n\t\t\t...\r\n<strong>\t\t\tval Merit = d '2097152'\r\n<\/strong><\/pre>\n<p>Source code: <a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2008\/07\/dmobrightnesscontrastsample04.rename-to-zip\">DmoBrightnessContrastSample.04.zip<\/a> (note that Release build binary is included)<\/p>\n<p>See also:<\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms787559(VS.85).aspx\">Registering a DMO<\/a><\/li>\n<\/ul>\n<p>Continued by:<\/p>\n<ul>\n<li><a href=\"494\">Part 5: In-Place Processing<br \/>\n<\/a><\/li>\n<\/ul>\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 The implemented so far filter\/DMO shown a problem related to its unexpectedly high &#8220;importance&#8221; in the system with the symptom of &#8220;auto-insertion&#8221; the filter when it is not necessary. For example, let us render an&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/481\">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,91,489],"class_list":["post-481","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-merit","tag-wtl"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/481","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=481"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/481\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}