2 * Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVUTIL_VIDEO_HINT_H
22 #define AVUTIL_VIDEO_HINT_H
26 #include "libavutil/avassert.h"
27 #include "libavutil/frame.h"
29 typedef struct AVVideoRect {
31 uint32_t width, height;
34 typedef enum AVVideoHintType {
35 /* rectangled delimit the constant areas (unchanged), default is changed */
36 AV_VIDEO_HINT_TYPE_CONSTANT,
38 /* rectangled delimit the constant areas (changed), default is not changed */
39 AV_VIDEO_HINT_TYPE_CHANGED,
42 typedef struct AVVideoHint {
44 * Number of AVVideoRect present.
46 * May be 0, in which case no per-rectangle information is present. In this
47 * case the values of rect_offset / rect_size are unspecified and should
53 * Offset in bytes from the beginning of this structure at which the array
54 * of AVVideoRect starts.
59 * Size in bytes of AVVideoRect.
66 static av_always_inline AVVideoRect *
67 av_video_hint_rects(const AVVideoHint *hints) {
68 return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset);
71 static av_always_inline AVVideoRect *
72 av_video_hint_get_rect(const AVVideoHint *hints, size_t idx) {
73 return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset + idx * hints->rect_size);
77 * Allocate memory for the AVVideoHint struct along with an nb_rects-sized
78 * arrays of AVVideoRect.
80 * The side data contains a list of rectangles for the portions of the frame
81 * which changed from the last encoded one (and the remainder are assumed to be
82 * changed), or, alternately (depending on the type parameter) the unchanged
83 * ones (and the remanining ones are those which changed).
84 * Macroblocks will thus be hinted either to be P_SKIP-ped or go through the
85 * regular encoding procedure.
87 * It's responsibility of the caller to fill the AVRects accordingly, and to set
88 * the proper AVVideoHintType field.
90 * @param out_size if non-NULL, the size in bytes of the resulting data array is
93 * @return newly allocated AVVideoHint struct (must be freed by the caller using
94 * av_free()) on success, NULL on memory allocation failure
96 AVVideoHint *av_video_hint_alloc(size_t nb_rects,
100 * Same as av_video_hint_alloc(), except newly-allocated AVVideoHint is attached
101 * as side data of type AV_FRAME_DATA_VIDEO_HINT_INFO to frame.
103 AVVideoHint *av_video_hint_create_side_data(AVFrame *frame,
107 #endif /* AVUTIL_VIDEO_HINT_H */