csi_camera_frame.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <stdlib.h>
  10. #define LOG_LEVEL 2
  11. #define LOG_PREFIX "camera_meta"
  12. #include <syslog.h>
  13. #include <csi_camera_frame.h>
  14. int csi_camera_frame_alloc_meta(csi_camera_meta_s **meta, int meta_count, size_t *meta_data_size)
  15. {
  16. size_t malloc_size;
  17. if (meta_count <= 0) {
  18. LOG_E("meta_count=%d\n", meta_count);
  19. *meta_data_size = 0;
  20. return -1;
  21. }
  22. malloc_size = sizeof(csi_camera_meta_s) + sizeof(csi_camera_meta_unit_s) * meta_count;
  23. LOG_D("malloc_size=(%zd+%zd)=%zd\n", sizeof(csi_camera_meta_s), sizeof(csi_camera_meta_unit_s) * meta_count, malloc_size);
  24. *meta = malloc(malloc_size);
  25. if (*meta == NULL) {
  26. LOG_E("malloc *meta(%zu) failed\n", malloc_size);
  27. return -1;
  28. }
  29. memset(*meta, 0, malloc_size);
  30. (*meta)->count = meta_count;
  31. (*meta)->size = sizeof(csi_camera_meta_unit_s) * meta_count;
  32. (*meta)->units = (csi_camera_meta_unit_s *)((char*)(*meta) + sizeof(csi_camera_meta_s));
  33. LOG_D("*meta=%p, (*meta)->units=%p\n", *meta, (*meta)->units);
  34. *meta_data_size = malloc_size;
  35. return 0;
  36. }
  37. int csi_camera_frame_free_meta(csi_camera_meta_s *meta)
  38. {
  39. if (meta == NULL) {
  40. LOG_E("[%s:%d] meta = NULL\n", __func__, __LINE__);
  41. return -1;
  42. }
  43. free(meta);
  44. return 0;
  45. }
  46. int csi_camera_frame_get_meta_unit(csi_camera_meta_unit_s *meta_unit,
  47. csi_camera_meta_s *meta_data,
  48. csi_camera_meta_id_e meta_field)
  49. {
  50. int i;
  51. LOG_D("meta_data->count=%d\n", meta_data->count);
  52. for (i = 0; i < meta_data->count; i++) {
  53. if (meta_data->units[i].id == meta_field) {
  54. *meta_unit = meta_data->units[i];
  55. return 0;
  56. }
  57. }
  58. return -1;
  59. }