carback.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "carback.h"
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <pthread.h>
  8. #include <unistd.h>
  9. #include <sys/ioctl.h>
  10. #include <QDebug>
  11. #include "ark_api.h"
  12. #define CARBACK_IOCTL_BASE 0x9A
  13. #define CARBACK_IOCTL_SET_APP_READY _IO(CARBACK_IOCTL_BASE, 0)
  14. #define CARBACK_IOCTL_APP_ENTER_DONE _IO(CARBACK_IOCTL_BASE, 1)
  15. #define CARBACK_IOCTL_APP_EXIT_DONE _IO(CARBACK_IOCTL_BASE, 2)
  16. #define CARBACK_IOCTL_GET_STATUS _IOR(CARBACK_IOCTL_BASE, 3, int)
  17. #define CARBACK_IOCTL_DETECT_SIGNAL _IOR(CARBACK_IOCTL_BASE, 4, int)
  18. #define ARK_DVR_IOC_MAGIC 'n'
  19. #define VIN_UPDATE_WINDOW _IOWR(ARK_DVR_IOC_MAGIC,50, struct vin_screen)
  20. Carback::Carback(QObject *parent) : QObject(parent)
  21. {
  22. exitThread = 1;
  23. carbackFd = -1;
  24. }
  25. Carback::~Carback()
  26. {
  27. exitThread = -1;
  28. carbackFd = -1;
  29. }
  30. void *Carback::readCarbckStatus(void *arg)
  31. {
  32. Carback *pThis = (Carback *)arg;
  33. unsigned char data;
  34. int video0Fd = -1;
  35. struct vin_screen vin_para;
  36. video0Fd = open("/dev/video0",O_RDWR);
  37. if( video0Fd < 0 ) {
  38. qDebug("open /dev/video0 fail.");
  39. }
  40. vin_para.disp_x = 654;
  41. vin_para.disp_y = 214;
  42. vin_para.disp_width = 616;
  43. vin_para.disp_height = 436;
  44. while (pThis->exitThread) {
  45. if (1 == read(pThis->carbackFd, &data, 1)) {
  46. if (data == CBS_On) {
  47. arkapi_enter_carback();
  48. if (0 != ioctl(pThis->carbackFd, CARBACK_IOCTL_APP_ENTER_DONE)) {
  49. qDebug("ioctl CARBACK_IOCTL_APP_ENTER_DONE fail.");
  50. }
  51. if (0!=ioctl(video0Fd, VIN_UPDATE_WINDOW, &vin_para)) {
  52. qDebug("ioctl VIN_UPDATE_WINDOW fail.");
  53. }
  54. pThis->CarbackStatusChange(CBS_On);
  55. } else if (data == CBS_Off) {
  56. arkapi_exit_carback();
  57. if (0 != ioctl(pThis->carbackFd, CARBACK_IOCTL_APP_EXIT_DONE)) {
  58. qDebug("ioctl CARBACK_IOCTL_APP_ENTER_DONE fail.");
  59. }
  60. pThis->CarbackStatusChange(CBS_Off);
  61. }
  62. } else {
  63. qDebug("read /dev/carback fail.");
  64. }
  65. }
  66. }
  67. void Carback::initialize()
  68. {
  69. pthread_t pthead;
  70. int ret = -1;
  71. carbackFd = open("/dev/carback", O_RDONLY);
  72. if (carbackFd < 0) {
  73. qDebug("open /dev/carback fail.");
  74. return;
  75. }
  76. if (0 != ioctl(carbackFd, CARBACK_IOCTL_SET_APP_READY)) {
  77. qDebug("ioctl CARBACK_IOCTL_SET_APP_READY fail.");
  78. return;
  79. }
  80. ret = pthread_create(&pthead, NULL, readCarbckStatus, this);
  81. if(ret != 0) {
  82. printf("pthread_create failed!\n");
  83. }
  84. }