isp_venc_shake_hal.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2021-2022 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <stdint.h>
  18. #include <malloc.h>
  19. #include <fcntl.h>
  20. #include <unistd.h>
  21. #include "isp_venc_shake_driver.h"
  22. #include "isp_venc_shake_hal.h"
  23. #include <sys/ioctl.h>
  24. #ifndef NULL
  25. #define NULL ((void *)0)
  26. #endif
  27. #ifndef IVS_MODULE_PATH
  28. #define IVS_MODULE_PATH "/dev/shake"
  29. #endif
  30. typedef struct _IspVencShake
  31. {
  32. unsigned int fd;
  33. struct ivs_parameter params;
  34. } IspVencShake;
  35. IvsStatus createIspVencShake(void **ivs)
  36. {
  37. IvsStatus status = IVS_STATUS_OK;
  38. IspVencShake *shake = NULL;
  39. unsigned int fd;
  40. shake = (IspVencShake *)malloc(sizeof(IspVencShake));
  41. if (NULL == shake)
  42. return IVS_STATUS_ERROR;
  43. fd = open("/dev/shake", O_RDONLY);
  44. if (fd == -1)
  45. {
  46. free(shake);
  47. return IVS_STATUS_ERROR;
  48. }
  49. shake->fd = fd;
  50. *ivs = shake;
  51. return status;
  52. }
  53. IvsStatus configIspVencShake(void *ivs, IvsConfig *config)
  54. {
  55. IvsStatus status = IVS_STATUS_OK;
  56. IspVencShake *shake = (IspVencShake *)ivs;
  57. struct ivs_parameter *params = NULL;
  58. unsigned int buffer_height;
  59. if (ivs == NULL || config == NULL)
  60. return IVS_STATUS_ERROR;
  61. params = &shake->params;
  62. buffer_height = config->mode = IVS_BUFFER_MODE_SLICE ?
  63. config->buffer_height : config->pic_height * 3 / 2;
  64. params->pic_width = config->pic_width;
  65. params->pic_height = config->pic_height;
  66. params->encode_width = config->encode_width;
  67. params->encode_height = config->encode_height;
  68. params->wid_y = 1;
  69. params->wid_uv = 2;
  70. params->sram_size = config->pic_width * buffer_height;
  71. params->encode_n = config->encode == IVS_ENCODER_FORMAT_H264 ? 16 : 64;
  72. params->stride_y = config->stride_y;
  73. params->stride_uv = config->stride_uv;
  74. params->encode_x = config->encode_x;
  75. params->encode_y = config->encode_y;
  76. params->int_mask = 0;
  77. if (ioctl(shake->fd, THEAD_IOCH_CONFIG_IVS, params) == -1)
  78. {
  79. status = IVS_STATUS_ERROR;
  80. }
  81. return status;
  82. }
  83. IvsStatus startIspVencShake(void *ivs)
  84. {
  85. IvsStatus status = IVS_STATUS_OK;
  86. IspVencShake *shake = (IspVencShake *)ivs;
  87. if (ivs == NULL)
  88. return IVS_STATUS_ERROR;
  89. if (ioctl(shake->fd, THEAD_IOCH_START_IVS, NULL) == -1)
  90. {
  91. status = IVS_STATUS_ERROR;
  92. }
  93. return status;
  94. }
  95. IvsStatus resetIspVencShake(void *ivs)
  96. {
  97. IvsStatus status = IVS_STATUS_OK;
  98. IspVencShake *shake = (IspVencShake *)ivs;
  99. if (ivs == NULL)
  100. return IVS_STATUS_ERROR;
  101. if (ioctl(shake->fd, THEAD_IOCH_RESET_IVS, NULL) == -1)
  102. {
  103. status = IVS_STATUS_ERROR;
  104. }
  105. return status;
  106. }
  107. IvsStatus getIspVencShakeState(void *ivs, int *state)
  108. {
  109. IvsStatus status = IVS_STATUS_OK;
  110. IspVencShake *shake = (IspVencShake *)ivs;
  111. if (ivs == NULL || state == NULL)
  112. return IVS_STATUS_ERROR;
  113. if (ioctl(shake->fd, THEAD_IOCH_GET_STATE, state) == -1)
  114. {
  115. status = IVS_STATUS_ERROR;
  116. }
  117. return status;
  118. }
  119. void destroyIspVencShake(void *ivs)
  120. {
  121. IspVencShake *shake = (IspVencShake *)ivs;
  122. if (NULL == ivs)
  123. return;
  124. if (shake->fd != -1)
  125. close(shake->fd);
  126. free(ivs);
  127. }