frame_demo2.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <sys/stat.h>
  16. #include <sys/ioctl.h>
  17. #include <sys/mman.h>
  18. #include <sys/time.h>
  19. #include <sys/wait.h>
  20. #include <sys/socket.h>
  21. #define LOG_LEVEL 2
  22. #define LOG_PREFIX "master"
  23. #include <syslog.h>
  24. #include <ion.h>
  25. #include <csi_frame.h>
  26. #include <csi_camera_frame.h>
  27. #include "frame_demo_common.h"
  28. const char *img_name = "../resource/yuv420_1280x720_csky2016.yuv";
  29. csi_img_format_t img_format = {
  30. .width = 1280,
  31. .height = 720,
  32. .pix_fmt = CSI_PIX_FMT_I420,
  33. };
  34. extern int producer_process(int socket_fd);
  35. extern int consumer_process(int socket_fd);
  36. int main(int argc, char *argv[])
  37. {
  38. int ret;
  39. int socket_pair[2]; /* sockpair() */
  40. pid_t producer_pid;
  41. pid_t consumer_pid;
  42. int process_status; /* the status of child process */
  43. char str_sockfd[10]; /* store the string format */
  44. /* Create socket pare */
  45. if (socketpair(AF_LOCAL, SOCK_STREAM, 0,
  46. socket_pair) == -1) { /* must be AF_LOCAL or AF_UNIX !!!!*/
  47. LOG_E("create socketpair error(%d), %s\n", errno, strerror(errno));
  48. exit(1);
  49. }
  50. LOG_I("Create socketpair OK:{%d, %d}\n", socket_pair[0], socket_pair[1]);
  51. /* run producer process, using socket_pair[0] */
  52. if ((producer_pid = fork()) == 0) {
  53. /* child process2: producer_process */
  54. LOG_D("producer process starting ...\n");
  55. close(socket_pair[1]); // producer only use socket_pair[0]
  56. producer_process(socket_pair[0]);
  57. LOG_D("producer process exiting ...\n");
  58. exit(0);
  59. }
  60. /* run consumer process, using socket_pair[1] */
  61. if ((consumer_pid = fork()) == 0) {
  62. /* child process1: consumer_process */
  63. LOG_D("consumer process starting...\n");
  64. close(socket_pair[0]); // producer only use socket_pair[1]
  65. consumer_process(socket_pair[1]);
  66. LOG_D("consumer process exiting...\n");
  67. exit(0);
  68. }
  69. /* wait the children process end */
  70. waitpid(producer_pid, &process_status, 0);
  71. if (WIFEXITED(process_status) == 0) {
  72. LOG_E("producer exit abnormal\n");
  73. }
  74. waitpid(consumer_pid, &process_status, 0);
  75. if (WIFEXITED(process_status) == 0) {
  76. LOG_E("consumer eixt abnormal\n");
  77. }
  78. /* close the socket_pair */
  79. ret = close(socket_pair[0]);
  80. LOG_D("close(socket_pair[0]) ret=%d, %s\n", errno, strerror(errno));
  81. ret = close(socket_pair[1]);
  82. LOG_D("close(socket_pair[1]) ret=%d, %s\n", errno, strerror(errno));
  83. LOG_D("Exit master\n");
  84. return 0;
  85. }