FFmpeg
Loading...
Searching...
No Matches
sink.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * Packet sink. Heavily based on libavfilter/buffersink.c
22 */
23
24#include "libavutil/avassert.h"
25#include "libavutil/opt.h"
26
27#include "libavcodec/bsf.h"
29#include "libavcodec/packet.h"
31
32typedef struct BufferSinkContext {
33 const AVClass *class;
34 unsigned warning_limit;
35
38
40{
42 buf->peeked_pkt = in;
43 return av_packet_ref(out, in);
44 } else {
45 buf->peeked_pkt = NULL;
47 av_packet_free(&in);
48 return 0;
49 }
50}
51
53{
54 BufferSinkContext *buf = ctx->priv_data;
55 AVBitStreamFilterLink *inlink = ctx->inputs[0];
57 int status, ret;
58 AVPacket *cur_pkt;
60 int buffersrc_empty = 0;
61
62 if (buf->peeked_pkt)
63 return return_or_keep_packet(buf, pkt, buf->peeked_pkt, flags);
64
65 while (1) {
66 ret = ff_bsf_inlink_consume_packet(inlink, &cur_pkt);
67 if (ret < 0) {
68 return ret;
69 } else if (ret) {
70 return return_or_keep_packet(buf, pkt, cur_pkt, flags);
71 } else if (ff_bsf_inlink_acknowledge_status(inlink, &status, &pts)) {
72 return status;
73 } else if ((flags & AV_BSF_SINK_FLAG_NO_REQUEST)) {
74 return AVERROR(EAGAIN);
75 } else if (li->packet_wanted_out) {
76 ret = ff_bsf_graph_run_once(ctx->graph);
77 if (ret == FFERROR_SOURCE_EMPTY) {
78 buffersrc_empty = 1;
79 } else if (ret == AVERROR(EAGAIN)) {
80 if (buffersrc_empty)
81 return ret;
83 } else if (ret < 0) {
84 return ret;
85 }
86 } else {
88 }
89 }
90}
91
93{
94 BufferSinkContext *s = ctx->priv_data;
95
96 s->warning_limit = 100;
97
98 return 0;
99}
100
102{
103 BufferSinkContext *buf = ctx->priv_data;
104
106}
107
109{
110 BufferSinkContext *buf = ctx->priv_data;
111 BitStreamFilterLinkInternal * const li = ff_link_internal(ctx->inputs[0]);
112
113 if (buf->warning_limit &&
116 "%d buffers queued in %s, something may be wrong.\n",
117 buf->warning_limit,
118 (char *)av_x_if_null(ctx->name, ctx->filter->name));
119 buf->warning_limit *= 10;
120 }
121
122 /* The packet is queued, the rest is up to av_bsf_sink_get_packet */
123 return 0;
124}
125
127{
128 av_assert0(ff_bsf(ctx->filter)->activate == activate);
129 return ctx->inputs[0]->time_base;
130}
131
133{
134 av_assert0(ff_bsf(ctx->filter)->activate == activate);
135 return ctx->inputs[0]->par;
136}
137
139
141 .p.name = "sink",
142 .p.priv_class = &sink_class,
143 .priv_data_size = sizeof(BufferSinkContext),
144 .init2 = init,
145 .uninit = uninit,
148};
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
const FFBitStreamFilter ff_sink_bsf
Definition sink.c:140
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **rpkt)
const AVBitStreamFilterPad ff_default_bsf_pad[1]
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
int ff_bsf_graph_run_once(AVBitStreamFilterGraph *graph)
Run one round of processing on a filter graph.
Definition bsfgraph.c:361
static av_always_inline const FFBitStreamFilter * ff_bsf(const AVBitStreamFilter *bsf)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
size_t av_container_fifo_can_read(const AVContainerFifo *cf)
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
int attribute_align_arg av_bsf_sink_get_packet(AVBitStreamFilterContext *ctx, AVPacket *pkt, int flags)
Get a packet with filtered data from sink and put it in packet.
Definition sink.c:52
const AVCodecParameters * av_bsf_sink_get_parameters(const AVBitStreamFilterContext *ctx)
Definition sink.c:132
AVRational av_bsf_sink_get_time_base(const AVBitStreamFilterContext *ctx)
Definition sink.c:126
@ AV_BSF_SINK_FLAG_PEEK
Tell av_buffersink_get_buffer_ref() to read video/samples buffer reference, but not remove it from th...
Definition bsf.h:670
@ AV_BSF_SINK_FLAG_NO_REQUEST
Tell av_bsf_sink_get_packet() not to request a packet from its input.
Definition bsf.h:677
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition packet.c:491
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition packet.c:442
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition avutil.h:311
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define BSFILTER_INPUTS(array)
Definition filters.h:145
#define FFERROR_SOURCE_EMPTY
Definition filters.h:33
#define BSF_DEFINE_CLASS_EXT(name, desc, options)
Definition filters.h:150
#define attribute_align_arg
Definition internal.h:50
AVOptions.
static void uninit(AVBitStreamFilterContext *ctx)
Definition sink.c:101
static int activate(AVBitStreamFilterContext *ctx)
Definition sink.c:108
static int return_or_keep_packet(BufferSinkContext *buf, AVPacket *out, AVPacket *in, int flags)
Definition sink.c:39
An instance of a filter.
Definition bsf.h:347
Describe the class of an AVClass context structure.
Definition log.h:76
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
This structure stores compressed data.
Definition packet.h:580
Rational number (pair of numerator and denominator).
Definition rational.h:58
int packet_wanted_out
True if a packet is currently wanted on the output of this filter.
AVContainerFifo * fifo
Queue of packets waiting to be filtered.
AVPacket * peeked_pkt
Definition sink.c:36
unsigned warning_limit
Definition sink.c:34
int(* activate)(AVBitStreamFilterContext *ctx)
Filter activation function.
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static int64_t pts