composer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __COMPOSER_H__
  2. #define __COMPOSER_H__
  3. #include <stdint.h>
  4. typedef struct Composer Composer;
  5. Composer *composer_create(int output_width, int output_height,
  6. int num_streams, int y_off);
  7. void composer_destroy(Composer *comp);
  8. /* Drop every cached RGA buffer handle (imported dmabufs). Call after
  9. * decoder teardowns if fd churn is expected; the cache also self-evicts
  10. * via LRU when full. */
  11. void composer_invalidate_all(Composer *comp);
  12. int composer_compose(Composer *comp,
  13. int *src_fds, int *src_widths, int *src_heights,
  14. int *src_strides, int *src_vstrides, int num_src,
  15. int dst_fd, int dst_stride);
  16. /* Override tile rectangles (pixel coordinates). n must be <= the tile
  17. * capacity (MAX_TILES). Used for PLC-driven dynamic layouts. */
  18. int composer_set_tiles(Composer *comp, const int *x, const int *y,
  19. const int *w, const int *h, int n);
  20. /* Enable/disable aspect-ratio-preserving scaling (letterbox). When enabled
  21. * each source is scaled to fit inside its tile with black bars instead of
  22. * being stretched. Default is disabled. */
  23. void composer_set_letterbox(Composer *comp, int enable);
  24. /* Compute the standard grid tile rectangles for n tiles on an
  25. * out_w x out_h canvas (same division as composer_create). The top
  26. * y_off pixels are reserved (e.g. title bar): tiles are laid out in
  27. * the area below and the last row extends to the bottom edge. */
  28. int composer_grid_rects(int out_w, int out_h, int n,
  29. int *xs, int *ys, int *ws, int *hs, int y_off);
  30. /* Row-aware layout: each row may hold a different number of equal-width cells.
  31. * Row height is proportional to the number of cells in that row (so a 5-cell
  32. * row is taller than a 3-cell row). Cells within a row are equal width. The
  33. * total cell count = sum(row_cols). Returns total cells or -1 on bad input. */
  34. int composer_flow_rects(int out_w, int out_h, const int *row_cols, int nrows,
  35. int *xs, int *ys, int *ws, int *hs, int y_off);
  36. /* Region (merged-cell) layout. The grid has nrows rows, row_cols[r] cells per
  37. * row, laid out in row-major order in `cells`. Cells holding the same label
  38. * (>=0) are merged into their bounding rectangle; label -1 is an empty cell.
  39. * Row heights follow inverse-of-cell-count weighting and always fill the
  40. * canvas. Returns the number of regions, filling region_x/y/w/h and
  41. * region_sid with the region's label (which equals the camera id). */
  42. int composer_region_rects(int out_w, int out_h, const int *row_cols, int nrows,
  43. const int *cells, int *region_x, int *region_y,
  44. int *region_w, int *region_h, int *region_sid,
  45. int y_off);
  46. /* Split layout: fixed top row + adaptive centered bottom row.
  47. * top_ids[]: camera IDs for the top row (always shown).
  48. * top_n: number of top-row cameras (e.g. 5).
  49. * top_ratio: top row height as fraction of usable area (0.0-1.0, e.g. 0.3).
  50. * bottom_ids[]: camera IDs for the bottom row (1-3 cameras, -1=empty).
  51. * bottom_n: number of valid entries in bottom_ids (max count, may include -1).
  52. * actual_bottom: how many bottom cameras to actually show (1 to bottom_n).
  53. * Writes rects into xs/ys/ws/hs/sid arrays, returns total regions. */
  54. int composer_split_rects(int out_w, int out_h, int y_off,
  55. const int *top_ids, int top_n, double top_ratio,
  56. const int *bottom_ids, int bottom_n,
  57. int actual_bottom,
  58. int *xs, int *ys, int *ws, int *hs, int *sid);
  59. void composer_get_tile_layout(Composer *comp, int stream_idx,
  60. int *x, int *y, int *w, int *h);
  61. /* Dump per-tile compose health counters to stderr (diagnoses flicker: a tile
  62. * with import/improcess failures periodically shows a black frame). */
  63. void composer_dump_stats(const Composer *comp);
  64. #endif