FFmpeg
Loading...
Searching...
No Matches
tf_internal.h
Go to the documentation of this file.
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) \
32static 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 */
43{
45 if (tfc)
46 av_log(tfc, AV_LOG_ERROR, "Invalid section access at level %d\n", level);
47 return NULL;
48 }
49 return tfc->section[level];
50}
51
52/**
53 * Safely access the parent section
54 */
56{
57 if (level <= 0)
58 return NULL;
59
60 return tf_get_section(tfc, level - 1);
61}
62
63static inline void writer_w8(AVTextFormatContext *wctx, int b)
64{
65 wctx->writer->writer->writer_w8(wctx->writer, b);
66}
67
68static inline void writer_put_str(AVTextFormatContext *wctx, const char *str)
69{
70 wctx->writer->writer->writer_put_str(wctx->writer, str);
71}
72
73static inline void writer_printf(AVTextFormatContext *wctx, const char *fmt, ...)
74{
75 va_list args;
76 va_start(args, fmt);
77 wctx->writer->writer->writer_vprintf(wctx->writer, fmt, args);
78 va_end(args);
79}
80
81#endif /* FFTOOLS_TEXTFORMAT_TF_INTERNAL_H */
#define SECTION_MAX_NB_LEVELS
#define NULL
Definition coverity.c:32
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define b
Definition input.c:43
const AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
AVTextWriterContext * writer
the AVTextWriterContext
const AVTextWriter * writer
void(* writer_put_str)(AVTextWriterContext *wctx, const char *str)
void(* writer_w8)(AVTextWriterContext *wctx, int b)
void(* writer_vprintf)(AVTextWriterContext *wctx, const char *fmt, va_list vl)
uint8_t level
Definition svq3.c:208
#define av_log(a,...)
static const AVTextFormatSection * tf_get_section(AVTextFormatContext *tfc, int level)
Safely validate and access a section at a given level.
Definition tf_internal.h:42
static const AVTextFormatSection * tf_get_parent_section(AVTextFormatContext *tfc, int level)
Safely access the parent section.
Definition tf_internal.h:55
static void writer_w8(AVTextFormatContext *wctx, int b)
Definition tf_internal.h:63
static void writer_printf(AVTextFormatContext *wctx, const char *fmt,...)
Definition tf_internal.h:73
static void writer_put_str(AVTextFormatContext *wctx, const char *str)
Definition tf_internal.h:68