| 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 | 43618 | static inline const AVTextFormatSection *tf_get_section(AVTextFormatContext *tfc, int level) | |
| 43 | { | ||
| 44 |
4/8✓ Branch 0 taken 43618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43618 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43618 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 43618 times.
|
43618 | 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 | 43618 | return tfc->section[level]; | |
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Safely access the parent section | ||
| 54 | */ | ||
| 55 | 14457 | static inline const AVTextFormatSection *tf_get_parent_section(AVTextFormatContext *tfc, int level) | |
| 56 | { | ||
| 57 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 14286 times.
|
14457 | if (level <= 0) |
| 58 | 171 | return NULL; | |
| 59 | |||
| 60 | 14286 | return tf_get_section(tfc, level - 1); | |
| 61 | } | ||
| 62 | |||
| 63 | 61730 | static inline void writer_w8(AVTextFormatContext *wctx, int b) | |
| 64 | { | ||
| 65 | 61730 | wctx->writer->writer->writer_w8(wctx->writer, b); | |
| 66 | 61730 | } | |
| 67 | |||
| 68 | 31899 | static inline void writer_put_str(AVTextFormatContext *wctx, const char *str) | |
| 69 | { | ||
| 70 | 31899 | wctx->writer->writer->writer_put_str(wctx->writer, str); | |
| 71 | 31899 | } | |
| 72 | |||
| 73 | 139656 | static inline void writer_printf(AVTextFormatContext *wctx, const char *fmt, ...) | |
| 74 | { | ||
| 75 | va_list args; | ||
| 76 | 139656 | va_start(args, fmt); | |
| 77 | 139656 | wctx->writer->writer->writer_vprintf(wctx->writer, fmt, args); | |
| 78 | 139656 | va_end(args); | |
| 79 | 139656 | } | |
| 80 | |||
| 81 | #endif /* FFTOOLS_TEXTFORMAT_TF_INTERNAL_H */ | ||
| 82 |