Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) The FFmpeg developers | ||
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 | /** | ||
22 | * @file | ||
23 | * Internal utilities for text formatters. | ||
24 | */ | ||
25 | |||
26 | #ifndef FFTOOLS_TEXTFORMAT_TF_INTERNAL_H | ||
27 | #define FFTOOLS_TEXTFORMAT_TF_INTERNAL_H | ||
28 | |||
29 | #include "avtextformat.h" | ||
30 | |||
31 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
32 | static const AVClass name##_class = { \ | ||
33 | .class_name = #name, \ | ||
34 | .item_name = av_default_item_name, \ | ||
35 | .option = name##_options \ | ||
36 | } | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Safely validate and access a section at a given level | ||
41 | */ | ||
42 | 42376 | static inline const AVTextFormatSection *tf_get_section(AVTextFormatContext *tfc, int level) | |
43 | { | ||
44 |
4/8✓ Branch 0 taken 42376 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42376 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42376 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 42376 times.
|
42376 | if (!tfc || level < 0 || level >= SECTION_MAX_NB_LEVELS || !tfc->section[level]) { |
45 | ✗ | if (tfc) | |
46 | ✗ | av_log(tfc, AV_LOG_ERROR, "Invalid section access at level %d\n", level); | |
47 | ✗ | return NULL; | |
48 | } | ||
49 | 42376 | return tfc->section[level]; | |
50 | } | ||
51 | |||
52 | /** | ||
53 | * Safely access the parent section | ||
54 | */ | ||
55 | 14039 | static inline const AVTextFormatSection *tf_get_parent_section(AVTextFormatContext *tfc, int level) | |
56 | { | ||
57 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 13880 times.
|
14039 | if (level <= 0) |
58 | 159 | return NULL; | |
59 | |||
60 | 13880 | return tf_get_section(tfc, level - 1); | |
61 | } | ||
62 | |||
63 | 61066 | static inline void writer_w8(AVTextFormatContext *wctx, int b) | |
64 | { | ||
65 | 61066 | wctx->writer->writer->writer_w8(wctx->writer, b); | |
66 | 61066 | } | |
67 | |||
68 | 31474 | static inline void writer_put_str(AVTextFormatContext *wctx, const char *str) | |
69 | { | ||
70 | 31474 | wctx->writer->writer->writer_put_str(wctx->writer, str); | |
71 | 31474 | } | |
72 | |||
73 | 136393 | static inline void writer_printf(AVTextFormatContext *wctx, const char *fmt, ...) | |
74 | { | ||
75 | va_list args; | ||
76 | 136393 | va_start(args, fmt); | |
77 | 136393 | wctx->writer->writer->writer_vprintf(wctx->writer, fmt, args); | |
78 | 136393 | va_end(args); | |
79 | 136393 | } | |
80 | |||
81 | #endif /* FFTOOLS_TEXTFORMAT_TF_INTERNAL_H */ | ||
82 |