FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/textformat/tw_buffer.c
Date: 2025-04-25 22:50:00
Exec Total Coverage
Lines: 0 23 0.0%
Functions: 0 5 0.0%
Branches: 0 2 0.0%

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 #include <limits.h>
22 #include <stdarg.h>
23
24 #include "avtextwriters.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/bprint.h"
27
28 /* Buffer Writer */
29
30 # define WRITER_NAME "bufferwriter"
31
32 typedef struct BufferWriterContext {
33 const AVClass *class;
34 AVBPrint *buffer;
35 } BufferWriterContext;
36
37 static const char *bufferwriter_get_name(void *ctx)
38 {
39 return WRITER_NAME;
40 }
41
42 static const AVClass bufferwriter_class = {
43 .class_name = WRITER_NAME,
44 .item_name = bufferwriter_get_name,
45 };
46
47 static void buffer_w8(AVTextWriterContext *wctx, int b)
48 {
49 BufferWriterContext *ctx = wctx->priv;
50 av_bprintf(ctx->buffer, "%c", b);
51 }
52
53 static void buffer_put_str(AVTextWriterContext *wctx, const char *str)
54 {
55 BufferWriterContext *ctx = wctx->priv;
56 av_bprintf(ctx->buffer, "%s", str);
57 }
58
59 static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, ...)
60 {
61 BufferWriterContext *ctx = wctx->priv;
62
63 va_list vargs;
64 va_start(vargs, fmt);
65 av_vbprintf(ctx->buffer, fmt, vargs);
66 va_end(vargs);
67 }
68
69
70 const AVTextWriter avtextwriter_buffer = {
71 .name = WRITER_NAME,
72 .priv_size = sizeof(BufferWriterContext),
73 .priv_class = &bufferwriter_class,
74 .writer_put_str = buffer_put_str,
75 .writer_printf = buffer_printf,
76 .writer_w8 = buffer_w8
77 };
78
79 int avtextwriter_create_buffer(AVTextWriterContext **pwctx, AVBPrint *buffer)
80 {
81 BufferWriterContext *ctx;
82 int ret;
83
84 ret = avtextwriter_context_open(pwctx, &avtextwriter_buffer);
85 if (ret < 0)
86 return ret;
87
88 ctx = (*pwctx)->priv;
89 ctx->buffer = buffer;
90
91 return ret;
92 }
93