FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tw_avio.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 #include <string.h>
24 
25 #include "avtextwriters.h"
26 #include "libavutil/avassert.h"
27 
28 #include "libavutil/error.h"
29 
30 /* AVIO Writer */
31 
32 # define WRITER_NAME "aviowriter"
33 
34 typedef struct IOWriterContext {
35  const AVClass *class;
39 
41 {
42  IOWriterContext *ctx = wctx->priv;
43  int ret = 0;
44 
45  if (ctx->close_on_uninit)
46  ret = avio_closep(&ctx->avio_context);
47  return ret;
48 }
49 
50 static void io_w8(AVTextWriterContext *wctx, int b)
51 {
52  IOWriterContext *ctx = wctx->priv;
53  avio_w8(ctx->avio_context, b);
54 }
55 
56 static void io_put_str(AVTextWriterContext *wctx, const char *str)
57 {
58  IOWriterContext *ctx = wctx->priv;
59  avio_write(ctx->avio_context, (const unsigned char *)str, (int)strlen(str));
60 }
61 
62 static void io_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
63 {
64  IOWriterContext *ctx = wctx->priv;
65 
66  avio_vprintf(ctx->avio_context, fmt, vl);
67 }
68 
69 
71  .name = WRITER_NAME,
72  .priv_size = sizeof(IOWriterContext),
75  .writer_vprintf = io_vprintf,
76  .writer_w8 = io_w8
77 };
78 
80 {
82  int ret;
83 
84  if (!output_filename || !output_filename[0]) {
85  av_log(NULL, AV_LOG_ERROR, "The output_filename cannot be NULL or empty\n");
86  return AVERROR(EINVAL);
87  }
88 
90  if (ret < 0)
91  return ret;
92 
93  ctx = (*pwctx)->priv;
94 
95  if ((ret = avio_open(&ctx->avio_context, output_filename, AVIO_FLAG_WRITE)) < 0) {
97  "Failed to open output '%s' with error: %s\n", output_filename, av_err2str(ret));
99  return ret;
100  }
101 
102  ctx->close_on_uninit = 1;
103 
104  return ret;
105 }
106 
107 
108 int avtextwriter_create_avio(AVTextWriterContext **pwctx, AVIOContext *avio_ctx, int close_on_uninit)
109 {
111  int ret;
112 
113  av_assert0(avio_ctx);
114 
116  if (ret < 0)
117  return ret;
118 
119  ctx = (*pwctx)->priv;
120  ctx->avio_context = avio_ctx;
121  ctx->close_on_uninit = close_on_uninit;
122 
123  return ret;
124 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
io_w8
static void io_w8(AVTextWriterContext *wctx, int b)
Definition: tw_avio.c:50
b
#define b
Definition: input.c:42
avio_open
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: avio.c:497
AVTextWriterContext
Definition: avtextwriters.h:42
io_put_str
static void io_put_str(AVTextWriterContext *wctx, const char *str)
Definition: tw_avio.c:56
AVTextWriterContext::priv
void * priv
private data for use by the writer
Definition: avtextwriters.h:46
output_filename
static const char * output_filename
Definition: ffprobe.c:327
WRITER_NAME
#define WRITER_NAME
Definition: tw_avio.c:32
iowriter_uninit
static av_cold int iowriter_uninit(AVTextWriterContext *wctx)
Definition: tw_avio.c:40
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
av_cold
#define av_cold
Definition: attributes.h:90
IOWriterContext::close_on_uninit
int close_on_uninit
Definition: tw_avio.c:37
io_vprintf
static void io_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
Definition: tw_avio.c:62
avtextwriter_context_close
int avtextwriter_context_close(AVTextWriterContext **pwctx)
Definition: avtextformat.c:620
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
IOWriterContext
Definition: tw_avio.c:34
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
ctx
AVFormatContext * ctx
Definition: movenc.c:49
limits.h
avtextwriter_create_avio
int avtextwriter_create_avio(AVTextWriterContext **pwctx, AVIOContext *avio_ctx, int close_on_uninit)
Definition: tw_avio.c:108
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
writer_w8
static void writer_w8(AVTextFormatContext *wctx, int b)
Definition: tf_internal.h:63
AVTextWriter::name
const char * name
Definition: avtextwriters.h:33
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:179
error.h
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
avtextwriter_context_open
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
Definition: avtextformat.c:640
AVTextWriter
Definition: avtextwriters.h:30
avtextwriter_create_file
int avtextwriter_create_file(AVTextWriterContext **pwctx, const char *output_filename)
Definition: tw_avio.c:79
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
writer_put_str
static void writer_put_str(AVTextFormatContext *wctx, const char *str)
Definition: tf_internal.h:68
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
ret
ret
Definition: filter_design.txt:187
avio_vprintf
int avio_vprintf(AVIOContext *s, const char *fmt, va_list ap)
Writes a formatted string to the context taking a va_list.
Definition: aviobuf.c:1191
avtextwriters.h
avtextwriter_avio
const AVTextWriter avtextwriter_avio
Definition: tw_avio.c:70
IOWriterContext::avio_context
AVIOContext * avio_context
Definition: tw_avio.c:36
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: avio.c:649
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27