Click here to Skip to main content
Click here to Skip to main content

Capturing audio/video in Silverlight 4: a surprising fact about CaptureSource

, 21 Jun 2010
Rate this:
Please Sign up or sign in to vote.
How to avoid performance problems when capturing audio only (or video only)
I created a simple sound-recording application in SL4, but the performance of my application was really poor. It took a while to me to find the reason of the problem - my webcam was activated each time the application started recording sound. Although the video input was not used by my application, the webcam was active and it decreased the performance of my application (not speaking about the fact that it took several seconds to turn the camera on/off, since my USB webcam is really, really slow).
 
That was not what I expected, since I only initialized the "AudioCaptureDevice" property of the "CaptureSource" class.
 
My code looked like this:
var audioDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
_captureSource = new CaptureSource() { AudioCaptureDevice = audioDevice };
 
I used Red Gate's .NET Reflector to disassemble the CaptureSource constructor and I found something like this:
public CaptureSource() {
    this.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
    this.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
}
 
Gotcha! Would you expect that? If you only want to capture audio, you must explicitly say that you don't want to capture video (and vice-versa). I changed my code to the following and it works without problems:
// This CaptureSource will record audio only...
_captureSource = new CaptureSource() { VideoCaptureDevice = null }
 
This is IMO where Silverlight library designers made a huge mistake... Well, we all are only humans. I hope this article helped you to improve the performance of your SL application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kubajzz
Student
Czech Republic Czech Republic
That's all folks!

Comments and Discussions

 
GeneralReason for my vote of 5 precise PinmemberMQT10-Mar-11 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 21 Jun 2010
Article Copyright 2010 by Kubajzz
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid