locked
Duplicate entry while enumerating Camera Stream Properties Using Win RT

    Question

  • I am trying to develop C++ version of this java script code
    Infect this code is not there in the above link.I have added this code to enumerate format suported by camera (My case embedded camera Dell Lattitute) and I haven't missed anything from java script code.    
    auto res = mediaCaptureMgr->VideoDeviceController->GetAvailableMediaStreamProperties(                                                                                               MediaStreamType::VideoRecord);
     auto itr = res->First();  
     if (itr == nullptr) return;
     
     do
     {
    // adding items in to combo
     cmbFormat->Items->Append(itr->Current->Subtype);
     } while( itr->MoveNext()) ;    
    This code is working fine but the problem is I am getting duplicate entry.
    I have tested this code with embedded camera in my dell laptop and USB Camera.In both the cases I am getting Duplicate entry.
    Embedded Camera: I am Getting value YUY2 and MPEJ both duplicated 14 times.
    Am I missing something or this is desired behaviour of API.


    • Edited by chris_vr Monday, November 14, 2011 6:32 PM formatted the Text
    Monday, November 14, 2011 6:29 PM

All replies

  • The list of formats you are seeing is the number of setting combinations supported by the  device your mediaCaptureMgr was initialized on. For example my built-in laptop camera supports 16 setting combinations where my external USB camera supports 46 setting combinations. Here is a snippet in C# that will list the capabilities for each camera connected.

            async private void Button1_Click(object sender, RoutedEventArgs e)
            {
                string sCameraName;
                //find the number of cameras
                var interfaces = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
                TextBlock1.Text = interfaces.Count + " device interface(s) found\n\n";
                //List the formats per camera
                foreach (DeviceInformation deviceInterface in interfaces)
                {
                    sCameraName = deviceInterface.Name.ToString();
                    MediaCaptureInitializationSettings captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                    captureInitSettings.VideoDeviceId = deviceInterface.Id;
    
                    //enumerate each camera for supported configurations
                    MediaCapture mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
                    await mediaCaptureMgr.InitializeAsync(captureInitSettings);
                    System.Collections.Generic.IReadOnlyList<IMediaEncodingProperties> res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord);
                   
                    //if no settings available, bail
                    if (res.Count < 1) return;
                  
                    //list the number of setting combinations for the device
                    string sCount = sCameraName + ": " + res.Count.ToString();
                    ComboBox1.Items.Add(sCount);
                    //list the different format settings
                    for (int i = 0; i < res.Count; i++)
                    {
                        VideoEncodingProperties vp = (VideoEncodingProperties)res[i];
                        string s = (sCameraName + " " + vp.Width.ToString());
                        s = s + " x " + vp.Height.ToString();
                        s = s + " " + vp.Bitrate.ToString();
                        ComboBox1.Items.Add(s);
                    } 
    
              
                }
                ComboBox1.SelectedIndex = 0;
            }
    


    Thanks,

    -David

     

    Wednesday, November 16, 2011 3:00 AM
    Moderator
  • Thanks David for Code Example It helped me a lot!.However I am Still Getting Duplicate Entry.All the Values are correct but duplicated.

    I did Same in C++

     

     

            cmbFormat->Items->Clear();

     auto res = mediaCaptureMgr->VideoDeviceController->                  GetAvailableMediaStreamProperties ( MediaStreamType::VideoRecord);

      

      if (res->Size<1) return;

     int i = 0;

      

     int ncoutn = res->Size;

     

     for (i = 0; i < res->Size; i++)

         {

     VideoEncodingProperties^ vp = (VideoEncodingProperties^) res->GetAt(i);

     

     String^ strType =  vp->Subtype;        // Ex: YUY2,RGB24 ..etc

     String^ strHeight = vp->Height.ToString();

     String^ strWidth = vp->Width.ToString();

     

     float n = vp->FrameRate->Numerator/vp->FrameRate->Denominator;

     String^ strFrameRate = n.ToString();

     

     String^ str4 = strType+" "+strHeight+"x"+strWidth+" "+strFrameRate;

    cmbResolution->Items->Append(str4); 

     

     

     

    Output:This is Output for Embedded Camera In Dell Laptop.

     

    It Supports two Format YUY2 and MJPEG

    YUY2 480x640 30

    YUY2 480x640 30

    YUY2 288x352 30

    YUY2 288x352 30

    YUY2 240x320 30

    YUY2 240x320 30

    YUY2 144x176 30

    YUY2 144x176 30

    YUY2 120x160 30

    YUY2 120x160 30

    YUY2 720x1280 10

    YUY2 720x1280 10

    YUY2 1080x1920 5

    YUY2 1080x1920 5

    Similar Duplication for MJPG Also..

    1. Why I getting these duplication.

    2. YUY2 480x640 supports 6 Different Frame Rate (5,10,15,24,30) but here the code list only one i.e. 30.I checked it in Windows 7 Machine using different Application.

    3.One More point I want to add here is, Resolution is Normally Dependent on Format and

    Frame Rate Depends on both format and Resolution.

    I wondering how can we Get Different Resolution And Frame Rate based on different Format.

     

     

     

     





    • Edited by chris_vr Wednesday, November 16, 2011 12:47 PM
    Wednesday, November 16, 2011 11:42 AM
  • Hi Chris,

    1. The duplication of formats is due to the driver exposing two identical formats one with videoinforheader structure and the other for videoinfoheader2 structure.

    2. looks like a bug that we are investigating

    3. The camera exposes only a certain number of formats, you can only set the format on the camera to one of the exposed formats. However, you can record  to other frame rates/formats and resolutions. If there are the necessary inbox components to perform the necessary resizing/frame rate conversion/format conversion, these are automatically pulled in so the camera format is converted to the required record format.

    So mediaCaptureMgr->VideoDeviceController-> GetAvailableMediaStreamProperties ( MediaStreamType::VideoRecord); lists all the formats the camera exposes for its record stream

    mediaCaptureMgr->VideoDeviceController->SetMediaStreamPropertiesAsync( MediaStreamType::VideoRecord, mediaEncodingProperties); allows you to set the format of the camera's record stream. The format has to be one of those enumerated by GetAvailableMediaStreamProperties

    The following APIs let you set up the record sink. These are exposed off of MediaCapture. The encodingProfile in the APIs below is what the developer chooses and is not limited to whatever is exposed by the camera. As an example the camera could expose only 640x480 YUY2, yet you could choose to record 320x240 H264 in which case a resizer and encoder and pulled into the pipeline.

    StartRecordOperation^ StartRecordToStorageFileAsync(
      MediaEncodingProfile^ encodingProfile,
      StorageFile^ file
    );

     

    StartRecordOperation^ StartRecordToStreamAsync(
    MediaEncodingProfile^ encodingProfile,
    IRandomAccessStream^ stream
    );

    StartRecordOperation^ StartRecordToCustomSinkAsync(
      MediaEncodingProfile^ encodingProfile,
      IMediaExtension^ customMediaSink
    );


    StartRecordOperation^ StartRecordToCustomSinkAsync(
      MediaEncodingProfile^ encodingProfile,
      String^ customSinkActivationId,
      IPropertySet^ customSinkSettings
    );



     

    Wednesday, January 04, 2012 2:01 AM
  • Hi Chris,

    1. The duplication of formats is due to the driver exposing two identical formats one with videoinforheader structure and the other for videoinfoheader2 structure.

    2. looks like a bug that we are investigating

    3. The camera exposes only a certain number of formats, you can only set the format on the camera to one of the exposed formats. However, you can record  to other frame rates/formats and resolutions. If there are the necessary inbox components to perform the necessary resizing/frame rate conversion/format conversion, these are automatically pulled in so the camera format is converted to the required record format.

    So mediaCaptureMgr->VideoDeviceController-> GetAvailableMediaStreamProperties ( MediaStreamType::VideoRecord); lists all the formats the camera exposes for its record stream

    mediaCaptureMgr->VideoDeviceController->SetMediaStreamPropertiesAsync( MediaStreamType::VideoRecord, mediaEncodingProperties); allows you to set the format of the camera's record stream. The format has to be one of those enumerated by GetAvailableMediaStreamProperties

    The following APIs let you set up the record sink. These are exposed off of MediaCapture. The encodingProfile in the APIs below is what the developer chooses and is not limited to whatever is exposed by the camera. As an example the camera could expose only 640x480 YUY2, yet you could choose to record 320x240 H264 in which case a resizer and encoder and pulled into the pipeline.

    StartRecordOperation^ StartRecordToStorageFileAsync(
      MediaEncodingProfile^ encodingProfile,
      StorageFile^ file
    );

     

    StartRecordOperation^ StartRecordToStreamAsync(
    MediaEncodingProfile^ encodingProfile,
    IRandomAccessStream^ stream
    );

    StartRecordOperation^ StartRecordToCustomSinkAsync(
      MediaEncodingProfile^ encodingProfile,
      IMediaExtension^ customMediaSink
    );


    StartRecordOperation^ StartRecordToCustomSinkAsync(
      MediaEncodingProfile^ encodingProfile,
      String^ customSinkActivationId,
      IPropertySet^ customSinkSettings
    );



     

    Hi Radhika,

    Thanks for help

    3. See I have already Enumerated the Camera Format using DierctX SDK Direct Show to enumerate the format and Pixel Size for windows 7.I haven't used any sink here

    In windows 7 it showing YUY2, MJPG,RB24,I420 and H264.

    for YUY2 320x180 I am Getting frame rate 5,7,10,15,20,24,30.

    For other format also I am getting more than one frame rates

    Windows 8 using Media Capture I am only getting only two format YuY2 and MJPG.

    In addition to this I am getting Only One frame rate per format.

    Thursday, January 05, 2012 6:44 AM
  • Hi Chris,

    Could you look at the driver on the WIN8 machine and on the Win7 machine and see if they are different.

     

    Thanks

    Radhika

    Saturday, January 14, 2012 2:03 AM
  • I have installed Windows 7 and Windows 8 on same machine.
    Monday, January 23, 2012 10:09 AM
  • Hi Chris,

    Could you look at the driver on the WIN8 machine and on the Win7 machine and see if they are different.

    Thanks

    Radhika


    Did You Figured it out why I am getting duplicate entry
    Wednesday, May 02, 2012 1:40 PM
  • Hi Chris,

    Could you look at the driver on the WIN8 machine and on the Win7 machine and see if they are different.

    Thanks

    Radhika



    Did You Figured it out why I am getting duplicate entry
    Wednesday, May 02, 2012 2:05 PM
  • I faced the similar problem. Have you found any solution ?


    maujy

    Friday, October 12, 2012 4:29 AM
  • I faced the similar problem. Have you found any solution ?


    maujy

    No maujy...It seems thats the  functionality...we have to put our logic to separate it. 

    Chris V R

    Monday, November 12, 2012 9:50 PM