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

Version 2

    Community Translated by  NaMo_1534561   Version: **

     

    Translation - English: Support Multiple Frame Rates in One Frame Descriptor in a UVC Application – KBA228228

     

    注意:

    この記事では、UVCアプリケーションの1つのディスクリプタで複数のフレームレートをサポートする方法を示します。

     

    1.対応するフレーム記述子を変更します。 次のコードスニペットは、解像度1080pで30 fpsおよび60 fpsを定義しています。

     

        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.Class-specific Video Streaming Input Header DescriptorとCyCx3USBSSConfigDscrのlength filedを変更します。

     

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

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

     

    3. 30fpsおよび60fpsのプローブ構造体を作成します。

     

        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.対応するプローブ構造体を返すように、「CyCx3UvcAppGetProbeControlData」ルーチンを変更します。

     

        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. CyCx3UvcAppHandleSetCurReq関数を変更して、set_curコマンドを処理します。

     

        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) | ((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. CyCx3UvcAppImageSensorSetVideoResolution関数を変更します。

     

    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.プロジェクトをビルドし、テストのためにイメージファイルをUVCデバイスにダウンロードします。