c# - DirectShowNet - Error when recreating graph for webcam after unplug/replug back in -
i've spent 4 hours trying figure out solution issue. basically, writing application in c# using directshownet shows video webcam, allows take snapshots, , change resolution of webcam. have device manager detects when webcam unplugged, replugged in. however, i'm having difficultly recreating graph after device has been plugged in.
the first thing create filtergraph object , cast ifiltergraph3. then, make call:
graphbuilder.addsourcefilterformoniker(devicemoniker, null, devicename, out sourcefilter)
this call works when launch application, , if dispose of graph , create new one. however, time doesn't work when trying create graph after device plugged in.
on 1 machine (win8 x64), receiving error:
regdb_e_classnotreg - 0x80040154 - class not registered
on machine (win7 x64), receiving error:
regdb_e_iidnotreg - 0x80040155 - interface not registered
i have tested both building code any cpu , x86. also, have tested on other machines, independent of os, still interface not registered error. have tried using both logitech c920 , microsoft lifecam studio. both result in same error. have tried alternative, using imoniker method:
devicemoniker.bindtoobject(null, null, ref basefilterid, out source);
same error occurs. feel there may lingering after device disconnected not cleaning allow graph grab source (webcam filter) properly. ideas appreciated.
general hresult error codes can found here: com error codes (generic)
so, basically, woke 1 morning, got work, , stared @ code , went, "wait, know why isn't working...". threading issue. initial graphs creating on different thread graphs trying create later. that's why happens when recreate graphs.
i having problem ivideowindow's put_owner
method when device plugged in after application has started. in case, device wasn't unplugged while executing, , put_owner freeze/deadlock trying method.
overall, have thread detecting when device unplugged/plugged in using dsdevice.getdevicesofcat(filtercategory.videoinputdevice)
. so, when go create these graphs, not on main ui thread other graphs created. solve this, have class handling devices take in action<action> invoker
allows provide method wrapper. in case, pass control.invoke
of winforms form calls on device monitoring thread wrapped invoker method within ui thread. solved graph creation issues.
i highly surprised no 1 else ran before. couldn't find else mentioning threading when discussing issues related error. strange.
Comments
Post a Comment