FFmpeg
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 
32 typedef struct BufferWriterContext {
33  const AVClass *class;
34  AVBPrint *buffer;
36 
37 static const char *bufferwriter_get_name(void *ctx)
38 {
39  return WRITER_NAME;
40 }
41 
42 static const AVClass bufferwriter_class = {
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 
71  .name = WRITER_NAME,
72  .priv_size = sizeof(BufferWriterContext),
73  .priv_class = &bufferwriter_class,
77 };
78 
80 {
82  int ret;
83 
85  if (ret < 0)
86  return ret;
87 
88  ctx = (*pwctx)->priv;
89  ctx->buffer = buffer;
90 
91  return ret;
92 }
opt.h
b
#define b
Definition: input.c:42
AVTextWriterContext
Definition: avtextwriters.h:47
AVTextWriterContext::priv
void * priv
private data for use by the writer
Definition: avtextwriters.h:51
buffer_w8
static void buffer_w8(AVTextWriterContext *wctx, int b)
Definition: tw_buffer.c:47
bufferwriter_class
static const AVClass bufferwriter_class
Definition: tw_buffer.c:42
ctx
AVFormatContext * ctx
Definition: movenc.c:49
limits.h
buffer_put_str
static void buffer_put_str(AVTextWriterContext *wctx, const char *str)
Definition: tw_buffer.c:53
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AVTextWriter::name
const char * name
Definition: avtextwriters.h:38
buffer_printf
static void buffer_printf(AVTextWriterContext *wctx, const char *fmt,...)
Definition: tw_buffer.c:59
writer_w8
#define writer_w8(wctx_, b_)
Definition: tf_compact.c:36
WRITER_NAME
#define WRITER_NAME
Definition: tw_buffer.c:30
avtextwriter_context_open
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
Definition: avtextformat.c:604
avtextwriter_create_buffer
int avtextwriter_create_buffer(AVTextWriterContext **pwctx, AVBPrint *buffer)
Definition: tw_buffer.c:79
AVTextWriter
Definition: avtextwriters.h:35
bprint.h
avtextwriter_buffer
const AVTextWriter avtextwriter_buffer
Definition: tw_buffer.c:70
writer_put_str
#define writer_put_str(wctx_, str_)
Definition: tf_compact.c:37
ret
ret
Definition: filter_design.txt:187
BufferWriterContext
Definition: tw_buffer.c:32
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
bufferwriter_get_name
static const char * bufferwriter_get_name(void *ctx)
Definition: tw_buffer.c:37
av_vbprintf
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
Definition: bprint.c:122
avtextwriters.h
writer_printf
#define writer_printf(wctx_, fmt_,...)
Definition: tf_compact.c:38
BufferWriterContext::buffer
AVBPrint * buffer
Definition: tw_buffer.c:34