FFmpeg
Loading...
Searching...
No Matches
tw_buffer.c
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#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
32typedef struct BufferWriterContext {
33 const AVClass *class;
34 AVBPrint *buffer;
36
37static const char *bufferwriter_get_name(void *ctx)
38{
39 return WRITER_NAME;
40}
41
43 .class_name = WRITER_NAME,
44 .item_name = bufferwriter_get_name,
45};
46
47static void buffer_w8(AVTextWriterContext *wctx, int b)
48{
50 av_bprintf(ctx->buffer, "%c", b);
51}
52
53static void buffer_put_str(AVTextWriterContext *wctx, const char *str)
54{
56 av_bprintf(ctx->buffer, "%s", str);
57}
58
59static void buffer_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
60{
62
63 av_vbprintf(ctx->buffer, fmt, vl);
64}
65
66
68 .name = WRITER_NAME,
69 .priv_size = sizeof(BufferWriterContext),
70 .priv_class = &bufferwriter_class,
72 .writer_vprintf = buffer_vprintf,
74};
75
77{
79 int ret;
80
82 if (ret < 0)
83 return ret;
84
85 ctx = (*pwctx)->priv;
86 ctx->buffer = buffer;
87
88 return ret;
89}
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:122
AVBPrint public header.
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
Definition bprint.c:99
#define b
Definition input.c:43
AVOptions.
Describe the class of an AVClass context structure.
Definition log.h:76
void * priv
private data for use by the writer
AVBPrint * buffer
Definition tw_buffer.c:34
static AVFormatContext * ctx
Definition movenc.c:49
static char buffer[20]
Definition seek.c:32
static void writer_w8(AVTextFormatContext *wctx, int b)
Definition tf_internal.h:63
static void writer_put_str(AVTextFormatContext *wctx, const char *str)
Definition tf_internal.h:68
#define WRITER_NAME
Definition tw_avio.c:32
const AVTextWriter avtextwriter_buffer
Definition tw_buffer.c:67
static void buffer_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
Definition tw_buffer.c:59
static const AVClass bufferwriter_class
Definition tw_buffer.c:42
static const char * bufferwriter_get_name(void *ctx)
Definition tw_buffer.c:37
int avtextwriter_create_buffer(AVTextWriterContext **pwctx, AVBPrint *buffer)
Definition tw_buffer.c:76
static void buffer_put_str(AVTextWriterContext *wctx, const char *str)
Definition tw_buffer.c:53
static void buffer_w8(AVTextWriterContext *wctx, int b)
Definition tw_buffer.c:47