Black preview screen working with Expression.Encoder and webcam

1.1k Views Asked by At

I wrote some C# code interface with a Logitech webcam using Expression.Encoder. The code was pretty easy to set it and works beautifully on my machine and my tester's machine. Unfortunately out in the field the preview screen for the camera shows a black screen. I've confirmed the camera displays a feed in both Logitech's app and also MS's Expression application. Windows Media Player and DirectX 11 are installed. The problem seems to be in the preview window creation that someone is not working.

// create the camera feed with just a video
currentJob = new LiveJob();
currentDeviceSource = currentJob.AddDeviceSource(currentVideoDevice, null);

System.Drawing.Size size = new System.Drawing.Size(250, 275);
currentDeviceSource.PickBestVideoFormat(size, (long)15);

SourceProperties sp = currentDeviceSource.SourcePropertiesSnapshot();
pnlCameraPreview.Size = new System.Drawing.Size(sp.Size.Width, sp.Size.Height);

currentJob.OutputFormat.VideoProfile.Size = new System.Drawing.Size(sp.Size.Width, sp.Size.Height);

// attach to the preview panel
currentDeviceSource.PreviewWindow = new PreviewWindow(new HandleRef(pnlCameraPreview, hwndPreviewPanel));
currentJob.ActivateSource(currentDeviceSource);

The Panel in question (pnlCameraPreview) is a windows forms panel hosting inside of wpf. Any thoughts on why this isn't working would be appreciated!

1

There are 1 best solutions below

0
On

We use the approach in production. It works all the time but the problem in question can be reproduced on a fresh box when no native video card drivers are installed. Perhaps the root of the problem is with painting video over the panel. BTW while the problem with the code similar to the posted one is observed Skype and Encoder's preview displays webcam pics all right.

Preview panel starts show pics and the code starts to work properly after all the adapters's drivers are installed.