video_hint.h (3586B)
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 21 #ifndef AVUTIL_VIDEO_HINT_H 22 #define AVUTIL_VIDEO_HINT_H 23 24 #include <stddef.h> 25 #include <stdint.h> 26 #include "libavutil/avassert.h" 27 #include "libavutil/frame.h" 28 29 typedef struct AVVideoRect { 30 uint32_t x, y; 31 uint32_t width, height; 32 } AVVideoRect; 33 34 typedef enum AVVideoHintType { 35 /* rectangled delimit the constant areas (unchanged), default is changed */ 36 AV_VIDEO_HINT_TYPE_CONSTANT, 37 38 /* rectangled delimit the constant areas (changed), default is not changed */ 39 AV_VIDEO_HINT_TYPE_CHANGED, 40 } AVVideoHintType; 41 42 typedef struct AVVideoHint { 43 /** 44 * Number of AVVideoRect present. 45 * 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 48 * not be accessed. 49 */ 50 size_t nb_rects; 51 52 /** 53 * Offset in bytes from the beginning of this structure at which the array 54 * of AVVideoRect starts. 55 */ 56 size_t rect_offset; 57 58 /** 59 * Size in bytes of AVVideoRect. 60 */ 61 size_t rect_size; 62 63 AVVideoHintType type; 64 } AVVideoHint; 65 66 static av_always_inline AVVideoRect * 67 av_video_hint_rects(const AVVideoHint *hints) { 68 return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset); 69 } 70 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); 74 } 75 76 /** 77 * Allocate memory for the AVVideoHint struct along with an nb_rects-sized 78 * arrays of AVVideoRect. 79 * 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. 86 * 87 * It's responsibility of the caller to fill the AVRects accordingly, and to set 88 * the proper AVVideoHintType field. 89 * 90 * @param out_size if non-NULL, the size in bytes of the resulting data array is 91 * written here 92 * 93 * @return newly allocated AVVideoHint struct (must be freed by the caller using 94 * av_free()) on success, NULL on memory allocation failure 95 */ 96 AVVideoHint *av_video_hint_alloc(size_t nb_rects, 97 size_t *out_size); 98 99 /** 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. 102 */ 103 AVVideoHint *av_video_hint_create_side_data(AVFrame *frame, 104 size_t nb_rects); 105 106 107 #endif /* AVUTIL_VIDEO_HINT_H */