video_hint.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_VIDEO_HINT_H
  21. #define AVUTIL_VIDEO_HINT_H
  22. #include <stddef.h>
  23. #include <stdint.h>
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/frame.h"
  26. typedef struct AVVideoRect {
  27. uint32_t x, y;
  28. uint32_t width, height;
  29. } AVVideoRect;
  30. typedef enum AVVideoHintType {
  31. /* rectangled delimit the constant areas (unchanged), default is changed */
  32. AV_VIDEO_HINT_TYPE_CONSTANT,
  33. /* rectangled delimit the constant areas (changed), default is not changed */
  34. AV_VIDEO_HINT_TYPE_CHANGED,
  35. } AVVideoHintType;
  36. typedef struct AVVideoHint {
  37. /**
  38. * Number of AVVideoRect present.
  39. *
  40. * May be 0, in which case no per-rectangle information is present. In this
  41. * case the values of rect_offset / rect_size are unspecified and should
  42. * not be accessed.
  43. */
  44. size_t nb_rects;
  45. /**
  46. * Offset in bytes from the beginning of this structure at which the array
  47. * of AVVideoRect starts.
  48. */
  49. size_t rect_offset;
  50. /**
  51. * Size in bytes of AVVideoRect.
  52. */
  53. size_t rect_size;
  54. AVVideoHintType type;
  55. } AVVideoHint;
  56. static av_always_inline AVVideoRect *
  57. av_video_hint_rects(const AVVideoHint *hints) {
  58. return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset);
  59. }
  60. static av_always_inline AVVideoRect *
  61. av_video_hint_get_rect(const AVVideoHint *hints, size_t idx) {
  62. return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset + idx * hints->rect_size);
  63. }
  64. /**
  65. * Allocate memory for the AVVideoHint struct along with an nb_rects-sized
  66. * arrays of AVVideoRect.
  67. *
  68. * The side data contains a list of rectangles for the portions of the frame
  69. * which changed from the last encoded one (and the remainder are assumed to be
  70. * changed), or, alternately (depending on the type parameter) the unchanged
  71. * ones (and the remanining ones are those which changed).
  72. * Macroblocks will thus be hinted either to be P_SKIP-ped or go through the
  73. * regular encoding procedure.
  74. *
  75. * It's responsibility of the caller to fill the AVRects accordingly, and to set
  76. * the proper AVVideoHintType field.
  77. *
  78. * @param out_size if non-NULL, the size in bytes of the resulting data array is
  79. * written here
  80. *
  81. * @return newly allocated AVVideoHint struct (must be freed by the caller using
  82. * av_free()) on success, NULL on memory allocation failure
  83. */
  84. AVVideoHint *av_video_hint_alloc(size_t nb_rects,
  85. size_t *out_size);
  86. /**
  87. * Same as av_video_hint_alloc(), except newly-allocated AVVideoHint is attached
  88. * as side data of type AV_FRAME_DATA_VIDEO_HINT_INFO to frame.
  89. */
  90. AVVideoHint *av_video_hint_create_side_data(AVFrame *frame,
  91. size_t nb_rects);
  92. #endif /* AVUTIL_VIDEO_HINT_H */