Windows Phone 8 : Working with the Camera (part 2) - Raw Hardware Access

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Raw Hardware Access

The Windows Phone SDK includes a couple of key classes that support low-level access to the camera and microphone hardware. Although it is much easier to use the PhotoCamera class, if you need to capture video and/or audio and manipulate it in real time, these APIs are the best tool for the job.

The starting point to the raw camera API is the CaptureSource class. The CaptureSource class enables you to have access to video input on the phone. Like the PhotoCamera class, you can use the CaptureSource class as the source for a VideoBrush. This way, you can show the raw input from the camera in your application:

CaptureSource _src = new CaptureSource();

protected override void OnNavigatedTo(NavigationEventArgs e)
  // Show the preview

To enable the video, you need to enable the CaptureSource by using the Start method:

private void camButton_Click(object sender, RoutedEventArgs e)

Silverlight Developers

Unlike desktop Silverlight, you can start the CaptureSource without asking for permission with the CaptureDeviceConfiguration class.

At this point, you have only the camera showing up in your own application. To deal with live input from the camera and microphone, you have to create special classes called sinks. To retrieve video you need a VideoSink class; for audio you need an AudioSink class. These are abstract classes from which you must derive in order to retrieve real-time data from the hardware. They have a small number of abstract methods (that you have to override). A skeleton VideoSink derived class would look like this:

public class MyVideoSink : VideoSink
  protected override void OnSample(long
    long frameDurationInHundredNanoseconds,
    byte[] sampleData)
    // Encode or Save the stream

  protected override void OnCaptureStarted()
    // Handle Startup of Capture

  protected override void OnCaptureStopped()
    // Cleanup After Capture

  VideoFormat _format = null;

  protected override void OnFormatChange(VideoFormat videoFormat)
     // Store the Video Format
    _format = videoFormat;

Here are the abstract methods you must override.

OnCaptureStarted: This is where you can do any initialization necessary to prepare for data capture.

OnCaptureStopped: This is where you can clean up or save after a capture is complete.

OnFormatChange: This is where you would store the current format to determine how to consume the capture samples.

OnSample: This is where most of the real work is accomplished in the sink. This is called periodically with a set of samples from the hardware.

After you have a sink, you can specify the CaptureSource of the sink before you start capturing:

protected override void OnNavigatedTo(NavigationEventArgs e)
  // Show the preview

  // Capture the video
  _sink.CaptureSource = _src;

When you specify the CaptureSource, your sink will be notified because the CaptureSource is manipulated by the user. In this way, you can have more than one audio and video sink per CaptureSource.

Because the raw camera API originated from Silverlight, it enables you to specify the camera on the device you want. The CaptureDeviceConfiguration class allows you to enumerate the different audio and video capture devices. In this way, you can specify the capture device for the CaptureSource to use, like so:

ICollection<VideoCaptureDevice> devices =

// Pick the first device
_src.VideoCaptureDevice = devices.First();

The API supports multiple devices so that, in the future, if there are multiple video devices (for example, a front-facing camera), your code will be able to pick which device to use. By default, the CaptureSource uses the “primary device,” which is usually the standard camera, so working with this API isn’t necessary with the current crop of phones.

  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 6) - Building a Web Signal - Unsubscribing from a Subscription
  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 5) - Building a Web Signal - Requesting the Status of a Subscription
  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 4) - Building a Web Signal - Pushing Data to Subscribers
  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 3) - Building a Web Signal - Web Signal Domains, Web Signal Subscriber Registration
  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 2) - Signing Up for Web Signals
  •  BlackBerry Development : Pushing Data to External Users - Web Signals (part 1) - How Web Signals Work
  •  Holiday Gift Guide – Smartphones – Aug 2013
  •  Holiday Gift Guide – Tablets – Aug 2013
  •  Wacom Cintiq 13HD - A Space-Saving Pen Display For Designers (Part 2)
  •  Wacom Cintiq 13HD - A Space-Saving Pen Display For Designers (Part 1)
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us