| 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_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl) | |
| 60 | { | ||
| 61 | ✗ | BufferWriterContext *ctx = wctx->priv; | |
| 62 | |||
| 63 | ✗ | av_vbprintf(ctx->buffer, fmt, vl); | |
| 64 | ✗ | } | |
| 65 | |||
| 66 | |||
| 67 | const AVTextWriter avtextwriter_buffer = { | ||
| 68 | .name = WRITER_NAME, | ||
| 69 | .priv_size = sizeof(BufferWriterContext), | ||
| 70 | .priv_class = &bufferwriter_class, | ||
| 71 | .writer_put_str = buffer_put_str, | ||
| 72 | .writer_vprintf = buffer_vprintf, | ||
| 73 | .writer_w8 = buffer_w8 | ||
| 74 | }; | ||
| 75 | |||
| 76 | ✗ | int avtextwriter_create_buffer(AVTextWriterContext **pwctx, AVBPrint *buffer) | |
| 77 | { | ||
| 78 | BufferWriterContext *ctx; | ||
| 79 | int ret; | ||
| 80 | |||
| 81 | ✗ | ret = avtextwriter_context_open(pwctx, &avtextwriter_buffer); | |
| 82 | ✗ | if (ret < 0) | |
| 83 | ✗ | return ret; | |
| 84 | |||
| 85 | ✗ | ctx = (*pwctx)->priv; | |
| 86 | ✗ | ctx->buffer = buffer; | |
| 87 | |||
| 88 | ✗ | return ret; | |
| 89 | } | ||
| 90 |