FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/video_hint.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 0 28 0.0%
Functions: 0 2 0.0%
Branches: 0 10 0.0%

Line Branch Exec Source
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 #include <string.h>
22
23 #include "avstring.h"
24 #include "frame.h"
25 #include "macros.h"
26 #include "mem.h"
27 #include "video_hint.h"
28
29 AVVideoHint *av_video_hint_alloc(size_t nb_rects,
30 size_t *out_size)
31 {
32 struct TestStruct {
33 AVVideoHint hint;
34 AVVideoRect rect;
35 };
36 const size_t rect_offset = offsetof(struct TestStruct, rect);
37 size_t size = rect_offset;
38 AVVideoHint *hint;
39
40 *out_size = 0;
41 if (nb_rects > (SIZE_MAX - size) / sizeof(AVVideoRect))
42 return NULL;
43 size += sizeof(AVVideoRect) * nb_rects;
44
45 hint = av_mallocz(size);
46 if (!hint)
47 return NULL;
48
49 hint->nb_rects = nb_rects;
50 hint->rect_offset = rect_offset;
51 hint->rect_size = sizeof(AVVideoRect);
52
53 *out_size = size;
54
55 return hint;
56 }
57
58 AVVideoHint *av_video_hint_create_side_data(AVFrame *frame,
59 size_t nb_rects)
60 {
61 AVVideoHint *hint;
62 AVBufferRef *buf;
63 size_t size = 0;
64
65 hint = av_video_hint_alloc(nb_rects, &size);
66 if (!hint)
67 return NULL;
68
69 buf = av_buffer_create((uint8_t *)hint, size, NULL, NULL, 0);
70 if (!buf) {
71 av_freep(&hint);
72 return NULL;
73 }
74
75 if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_HINT, buf)) {
76 av_buffer_unref(&buf);
77 return NULL;
78 }
79
80 return hint;
81 }
82