FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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) \
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  */
43 {
44  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  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 
63 static inline void writer_w8(AVTextFormatContext *wctx, int b)
64 {
65  wctx->writer->writer->writer_w8(wctx->writer, b);
66 }
67 
68 static inline void writer_put_str(AVTextFormatContext *wctx, const char *str)
69 {
70  wctx->writer->writer->writer_put_str(wctx->writer, str);
71 }
72 
73 static 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 */
level
uint8_t level
Definition: svq3.c:208
writer_printf
static void writer_printf(AVTextFormatContext *wctx, const char *fmt,...)
Definition: tf_internal.h:73
b
#define b
Definition: input.c:42
avtextformat.h
AVTextFormatContext
Definition: avtextformat.h:112
AVTextWriter::writer_put_str
void(* writer_put_str)(AVTextWriterContext *wctx, const char *str)
Definition: avtextwriters.h:38
AVTextFormatContext::writer
AVTextWriterContext * writer
the AVTextWriterContext
Definition: avtextformat.h:115
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AVTextFormatSection
Definition: avtextformat.h:41
NULL
#define NULL
Definition: coverity.c:32
AVTextFormatContext::section
const AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:130
writer_w8
static void writer_w8(AVTextFormatContext *wctx, int b)
Definition: tf_internal.h:63
tf_get_parent_section
static const AVTextFormatSection * tf_get_parent_section(AVTextFormatContext *tfc, int level)
Safely access the parent section.
Definition: tf_internal.h:55
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:109
AVTextWriterContext::writer
const AVTextWriter * writer
Definition: avtextwriters.h:44
AVTextWriter::writer_vprintf
void(* writer_vprintf)(AVTextWriterContext *wctx, const char *fmt, va_list vl)
Definition: avtextwriters.h:39
writer_put_str
static void writer_put_str(AVTextFormatContext *wctx, const char *str)
Definition: tf_internal.h:68
AVTextWriter::writer_w8
void(* writer_w8)(AVTextWriterContext *wctx, int b)
Definition: avtextwriters.h:37
tf_get_section
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
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27