vimc-common.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * vimc-ccommon.h Virtual Media Controller Driver
  3. *
  4. * Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #ifndef _VIMC_COMMON_H_
  18. #define _VIMC_COMMON_H_
  19. #include <linux/slab.h>
  20. #include <media/media-device.h>
  21. #include <media/v4l2-device.h>
  22. /**
  23. * struct vimc_pix_map - maps media bus code with v4l2 pixel format
  24. *
  25. * @code: media bus format code defined by MEDIA_BUS_FMT_* macros
  26. * @bbp: number of bytes each pixel occupies
  27. * @pixelformat: pixel format devined by V4L2_PIX_FMT_* macros
  28. *
  29. * Struct which matches the MEDIA_BUS_FMT_* codes with the corresponding
  30. * V4L2_PIX_FMT_* fourcc pixelformat and its bytes per pixel (bpp)
  31. */
  32. struct vimc_pix_map {
  33. unsigned int code;
  34. unsigned int bpp;
  35. u32 pixelformat;
  36. };
  37. /**
  38. * struct vimc_ent_device - core struct that represents a node in the topology
  39. *
  40. * @ent: the pointer to struct media_entity for the node
  41. * @pads: the list of pads of the node
  42. * @destroy: callback to destroy the node
  43. * @process_frame: callback send a frame to that node
  44. *
  45. * Each node of the topology must create a vimc_ent_device struct. Depending on
  46. * the node it will be of an instance of v4l2_subdev or video_device struct
  47. * where both contains a struct media_entity.
  48. * Those structures should embedded the vimc_ent_device struct through
  49. * v4l2_set_subdevdata() and video_set_drvdata() respectivaly, allowing the
  50. * vimc_ent_device struct to be retrieved from the corresponding struct
  51. * media_entity
  52. */
  53. struct vimc_ent_device {
  54. struct media_entity *ent;
  55. struct media_pad *pads;
  56. void (*destroy)(struct vimc_ent_device *);
  57. void (*process_frame)(struct vimc_ent_device *ved,
  58. struct media_pad *sink, const void *frame);
  59. };
  60. /**
  61. * vimc_propagate_frame - propagate a frame through the topology
  62. *
  63. * @src: the source pad where the frame is being originated
  64. * @frame: the frame to be propagated
  65. *
  66. * This function will call the process_frame callback from the vimc_ent_device
  67. * struct of the nodes directly connected to the @src pad
  68. */
  69. int vimc_propagate_frame(struct media_pad *src, const void *frame);
  70. /**
  71. * vimc_pads_init - initialize pads
  72. *
  73. * @num_pads: number of pads to initialize
  74. * @pads_flags: flags to use in each pad
  75. *
  76. * Helper functions to allocate/initialize pads
  77. */
  78. struct media_pad *vimc_pads_init(u16 num_pads,
  79. const unsigned long *pads_flag);
  80. /**
  81. * vimc_pads_cleanup - free pads
  82. *
  83. * @pads: pointer to the pads
  84. *
  85. * Helper function to free the pads initialized with vimc_pads_init
  86. */
  87. static inline void vimc_pads_cleanup(struct media_pad *pads)
  88. {
  89. kfree(pads);
  90. }
  91. /**
  92. * vimc_pix_map_by_code - get vimc_pix_map struct by media bus code
  93. *
  94. * @code: media bus format code defined by MEDIA_BUS_FMT_* macros
  95. */
  96. const struct vimc_pix_map *vimc_pix_map_by_code(u32 code);
  97. /**
  98. * vimc_pix_map_by_pixelformat - get vimc_pix_map struct by v4l2 pixel format
  99. *
  100. * @pixelformat: pixel format devined by V4L2_PIX_FMT_* macros
  101. */
  102. const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat);
  103. #endif