Support Multiple Frame Rates in One Frame Descriptor in a UVC Application – KBA228228

Version 5

    Author: RoyL_01           Version: **

     

    Translation - Japanese: UVC アプリケーションの1つのフレームディスクリプタで複数のフレームレートをサポートする - KBA228228 - Community Translated (JA)

     

    Note:

    This article shows how to support multiple frame rates in one descriptor in a UVC application.

     

    1.    Modify the corresponding frame descriptor. The following code snippet defines 30 fps and 60 fps with 1080p resolution.

     

    1.   0x22,                               /* Descriptor size */ 

    2.   CX3_CS_INTRFC_DESCR,                /* Descriptor type*/ 

    3.   0x05,                               /* Subtype:  frame interface*/ 

    4.   0x01,                               /* Frame Descriptor Index: 1 */ 

    5.   0x00,                               /* No Still image capture method supported */ 

    6.   0x80,0x07,                         /* Width in pixel:  1920 */ 

    7.   0x38,0x04,                         /* Height in pixel: 1080 */ 

    8.   0x00,0x80,0x53,0x3b,             /* Min bit rate (bits/s): 1920 x 1080 x 16 x 30 = 995328000 */ 

    9.   0x00,0x00,0xa7,0x76,             /* Max bit rate (bits/s): 1920 x 1080 x 16 x 30 = 0x76a70000 */ 

    10. 0x00,0x48,0x3f,0x00,             /* Maximum video or still frame size in bytes(Deprecated): 1920 x 1080 x 2 */ 

    11. 0x15,0x16,0x05,0x00,             /* Default frame interval (in 100ns units): (1/30)x10^7 */ 

    12. 0x02,                               /* Frame interval type : No of discrete intervals */ 

    13. 0x15,0x16,0x05,0x00,             /* 30 fps */ 

    14. 0x0a,0x8b,0x02,0x00,             /* 60 fps */ 

     

     

    2.    Modify the length filed of Class-specific Video Streaming Input Header Descriptor and CyCx3USBSSConfigDscr

     

    1.   0x56,0x00,                          /* Total size of Class specific VS descr */ 

    1.   0xe9,0x00,                         /* Length of this descriptor and all sub descriptors */ 

     

     

    3.    Create the probe structures for 30 fps and 60 fps.

     

    1.   /* UVC Probe Control Setting - 1080p_60fps*/   

    2.   uint8_t const gl1080pProbeCtrl_60fps[CX3_UVC_MAX_PROBE_SETTING] = {   

    3.       0x00, 0x00,                         /* bmHint : No fixed parameters */   

    4.       0x01,                               /* Use 1st Video format index */   

    5.       0x01,                               /* Use 1st Video frame index */   

    6.       0x0a,0x8b,0x02,0x00,             /* Desired frame interval in 100ns = (1/30)x10^7 */   

    7.       0x00, 0x00,                         /* Key frame rate in key frame/video frame units */   

    8.       0x00, 0x00,                         /* PFrame rate in PFrame / key frame units */   

    9.       0x00, 0x00,                         /* Compression quality control */   

    10.     0x00, 0x00,                         /* Window size for average bit rate */   

    11.     0x00, 0x00,                         /* Internal video streaming i/f latency in ms */   

    12.     0x00,0x48,0x3f,0x00,             /* Max video frame size in bytes = 1920 x 1080 x 2 */   

    13. #ifdef CX3_UVC_1_0_SUPPORT   

    14.     0x00, 0x90, 0x00, 0x00              /* No. of bytes device can rx in single payload: 36KB */   

    15. #else   

    16.     /* UVC 1.1 Probe Control has additional fields from UVC 1.0 */   

    17.     0x00, 0x90, 0x00, 0x00,             /* No. of bytes device can rx in single payload: 36KB */   

    18.     0x00, 0x60, 0xE3, 0x16,             /* Device Clock */   

    19.     0x00,                               /* Framing Information - Ignored for uncompressed format*/   

    20.     0x00,                               /* Preferred payload format version */   

    21.     0x00,                               /* Minimum payload format version */   

    22.     0x00                                /* Maximum payload format version */   

    23. #endif   

    24. };

    1.   /* UVC Probe Control Setting - 1080p_30fps*/   

    2.   uint8_t const gl1080pProbeCtrl_30fps[CX3_UVC_MAX_PROBE_SETTING] = {   

    3.       0x00, 0x00,                         /* bmHint : No fixed parameters */   

    4.       0x01,                               /* Use 1st Video format index */   

    5.       0x01,                               /* Use 1st Video frame index */   

    6.       0x15,0x16,0x05,0x00,             /* Desired frame interval in 100ns = (1/30)x10^7 */   

    7.       0x00, 0x00,                         /* Key frame rate in key frame/video frame units */   

    8.       0x00, 0x00,                         /* PFrame rate in PFrame / key frame units */   

    9.       0x00, 0x00,                         /* Compression quality control */   

    10.     0x00, 0x00,                         /* Window size for average bit rate */   

    11.     0x00, 0x00,                         /* Internal video streaming i/f latency in ms */   

    12.     0x00,0x48,0x3f,0x00,             /* Max video frame size in bytes = 1920 x 1080 x 2 */    

    13. #ifdef CX3_UVC_1_0_SUPPORT    

    14.     0x00, 0x90, 0x00, 0x00              /* No. of bytes device can rx in single payload: 36KB */   

    15. #else   

    16.     /* UVC 1.1 Probe Control has additional fields from UVC 1.0 */   

    17.     0x00, 0x90, 0x00, 0x00,             /* No. of bytes device can rx in single payload: 36KB */   

    18.     0x00, 0x60, 0xE3, 0x16,             /* Device Clock */   

    19.     0x00,                               /* Framing Information - Ignored for uncompressed format*/   

    20.     0x00,                               /* Preferred payload format version */   

    21.     0x00,                               /* Minimum payload format version */   

    22.     0x00                                /* Maximum payload format version */   

    23. #endif   

    24. };   

     

     

    4.    Modify the CyCx3UvcAppGetProbeControlData routine to return the corresponding probe structure.

     

    1.   /*Returns the pointer to the Probe Control structure for the corresponding frame index.*/   

    2.   uint8_t *   

    3.   CyCx3UvcAppGetProbeControlData (   

    4.           CyU3PUSBSpeed_t usbConType,   

    5.           uint8_t         frameIndex,   

    6.           uint32_t glCurrentFrameInterval   

    7.           )   

    8.   {   

    9.   uint32_t frame_fps = 10000000 / glCurrentFrameInterval;   

    10.     if (usbConType == CY_U3P_SUPER_SPEED)   

    11.     {   

    12.        if (frameIndex == 1)   

    13.         {   

    14.        if(frame_fps == 30)   

    15.        {   

    16.             /* 1920 x 1080 @30.0 fps */   

    17.        CyU3PDebugPrint(4,"\n Line:%d: Return 30 fps structure",__LINE__);   

    18.                return ((uint8_t *) gl1080pProbeCtrl_30fps);   

    19.        }   

    20.        else if(frame_fps == 60)   

    21.        {              /* 1920 x 1080 @60.0 fps */   

    22.        CyU3PDebugPrint(4,"\n Line:%d Return 60 fps structure",__LINE__);   

    23.                   return ((uint8_t *) gl1080pProbeCtrl_60fps);   

    24.        }   

    25.      }   

    26.     }   

    27.     else if (usbConType == CY_U3P_HIGH_SPEED)   

    28.     {   

    29.     }   

    30.     else   

    31.     {   

    32.        

    33.     }   

    34.     return NULL;   

    35. }   

     

     

    5.    Modify the CyCx3UvcAppHandleSetCurReq function to handle the set_cur command.

     

    1.     /* Set Probe Control */   

    2.       if (wValue == CX3_UVC_VS_PROBE_CONTROL)   

    3.       {   

    4.           glCurrentFrameIndex = glCommitCtrl[3];   

    5.   #ifdef Two_frame_rate   

    6.           glCurrentFrameInterval = ((uint32_t)glCommitCtrl[7] << 24) | ((uint32_t)glCommitCtrl[6] << 16) |   

    7.   ((uint32_t)glCommitCtrl[5] << 8) | ((uint32_t)glCommitCtrl[4] << 0);   

    8.           CyU3PDebugPrint(4,"\r\n Line:%d: glCurrentFrameInterval = 0x%x",__LINE__,glCurrentFrameInterval);   

    9.   #endif   

    10.     }   

     

     

    6.    Modify the CyCx3UvcAppImageSensorSetVideoResolution function.

     

    1.   /* Set the video resolution through this function. This function lists all the

    2.   *  supported resolutions in SuperSpeed and HighSpeed. The frame index of resolutions

    3.   *  supported in Still Capture can be different from the frame index of resolutions supported

    4.   *  in Video streaming.

    5.   */   

    6.   static void   

    7.   CyCx3UvcAppImageSensorSetVideoResolution(   

    8.           uint8_t resolution_index,   

    9.           uint32_t frame_Interval   

    10.         )   

    11. {   

    12. CyU3PReturnStatus_t status = CY_U3P_SUCCESS;   

    13. uint32_t frameRate= 10000000/frame_Interval;   

    14. switch (CyU3PUsbGetSpeed ())   

    15. {   

    16. case CY_U3P_SUPER_SPEED:   

    17. switch (resolution_index)   

    18. {   

    19. case 0x01:   

    20. {   

    21. if(frameRate == 30)   

    22. {   

    23. CyU3PDebugPrint(4,"\r\n Line:%d: Set 30 fps",__LINE__);   

    24. /* Write 1080pSettings */   

    25. #ifndef FX3_STREAMING   

    26. status = CyU3PMipicsiSetIntfParams (&OV5640_YUY2_1080p, CyFalse);   

    27. if (status != CY_U3P_SUCCESS)   

    28. {   

    29. CyU3PDebugPrint (4, "\n\rUSBStpCB:SetIntfParams SS1 Err = 0x%x", status);   

    30. }   

    31. #endif   

    32. CyCx3_ImageSensor_Set_1080p ();   

    33.    

    34.    

    35. }   

    36. else if (frameRate == 60)   

    37. {   

    38. CyU3PDebugPrint(4,"\r\n Line:%d: Set 60 fps",__LINE__);   

    39. /* Write 1080pSettings */   

    40. #ifndef FX3_STREAMING   

    41. status = CyU3PMipicsiSetIntfParams (&OV5640_YUY2_1080p, CyFalse);   

    42. if (status != CY_U3P_SUCCESS)   

    43. {   

    44. CyU3PDebugPrint (4, "\n\rUSBStpCB:SetIntfParams SS1 Err = 0x%x", status);   

    45. }   

    46. #endif   

    47. CyCx3_ImageSensor_Set_1080p ();   

    48.    

    49.    

    50. }   

    51.    

    52.    

    53. }   

    54. break;   

    55.    

    56.    

    57. }   

    58. break;   

    59.    

    60.    

    61. case CY_U3P_HIGH_SPEED:   

    62. switch (resolution_index)   

    63. {   

    64.    

    65.    

    66.    

    67.    

    68. }   

    69. break;   

    70. }   

    71. }   

     

     

    7.    Build the project and download the image file into UVC device for test.