FFmpeg
Loading...
Searching...
No Matches
side_data.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 * Side data bitstream filter -- remove side data from packets and from the
22 * stream, or select packets by their side data.
23 */
24
25#include "libavcodec/bsf.h"
28
29#include "libavutil/opt.h"
30
31typedef struct SideDataContext {
32 const AVClass *class;
33
34 int *remove;
35 unsigned nb_remove;
36 int *select;
37 unsigned nb_select;
39
41{
42 SideDataContext *s = ctx->priv_data;
43
44 for (unsigned i = 0; i < s->nb_remove; i++)
45 av_packet_side_data_remove(ctx->par_out->coded_side_data,
46 &ctx->par_out->nb_coded_side_data,
47 s->remove[i]);
48
49 return 0;
50}
51
52static int is_selected(const SideDataContext *s, const AVPacket *pkt)
53{
54 if (!s->nb_select)
55 return 1;
56
57 for (unsigned i = 0; i < s->nb_select; i++)
58 if (av_packet_side_data_get(pkt->side_data, pkt->side_data_elems,
59 s->select[i]))
60 return 1;
61
62 return 0;
63}
64
66{
67 SideDataContext *s = ctx->priv_data;
69
70 if (ret < 0)
71 return ret;
72
73 if (!is_selected(s, pkt)) {
75 return AVERROR(EAGAIN);
76 }
77
78 for (unsigned i = 0; i < s->nb_remove; i++)
79 av_packet_side_data_remove(pkt->side_data, &pkt->side_data_elems,
80 s->remove[i]);
81
82 return 0;
83}
84
85static const AVOptionArrayDef types_def = { .sep = '+' };
86
87#define OFFSET(x) offsetof(SideDataContext, x)
88#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_BSF_PARAM)
89#define TYPE_CONST(type, handle) \
90 { handle, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_PKT_DATA_ ## type }, .flags = FLAGS, .unit = "type" },
91static const AVOption options[] = {
92 { "remove", "side data types to remove, joined with '+'", OFFSET(remove), AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &types_def }, 0, AV_PKT_DATA_NB - 1, FLAGS, .unit = "type" },
93 { "select", "side data types of the packets to keep, joined with '+'", OFFSET(select), AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &types_def }, 0, AV_PKT_DATA_NB - 1, FLAGS, .unit = "type" },
95 { NULL },
96};
97
98static const AVClass side_data_class = {
99 .class_name = "side_data bsf",
100 .item_name = av_default_item_name,
101 .option = options,
102 .version = LIBAVUTIL_VERSION_INT,
103};
104
106 .p.name = "side_data",
107 .p.priv_class = &side_data_class,
108 .priv_data_size = sizeof(SideDataContext),
111};
static AVFormatContext * ctx
const FFBitStreamFilter ff_side_data_bsf
Definition side_data.c:105
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition bsf.c:254
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:596
#define NULL
Definition coverity.c:32
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
int ret
Definition ffplay.c:391
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition opt.h:345
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
void av_packet_side_data_remove(AVPacketSideData *sd, int *pnb_sd, enum AVPacketSideDataType type)
Remove side data of the given type from a side data array.
Definition packet.c:643
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition packet.c:571
@ AV_PKT_DATA_NB
The number of side data types.
Definition packet.h:401
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
#define AVERROR(e)
Definition error.h:45
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static int is_selected(const SideDataContext *s, const AVPacket *pkt)
Definition side_data.c:52
#define TYPE_CONST(type, handle)
Definition side_data.c:89
static const AVClass side_data_class
Definition side_data.c:98
static int side_data_init(AVBSFContext *ctx)
Definition side_data.c:40
static int side_data_filter(AVBSFContext *ctx, AVPacket *pkt)
Definition side_data.c:65
#define OFFSET(x)
Definition side_data.c:87
static const AVOptionArrayDef types_def
Definition side_data.c:85
#define FF_PACKET_SIDE_DATA_HANDLES(HANDLE)
The handle of each side data type: a short, stable name made of lower case letters,...
AVOptions.
The bitstream filter state.
Definition bsf.h:68
Describe the class of an AVClass context structure.
Definition log.h:76
May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
Definition opt.h:394
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
unsigned nb_remove
Definition side_data.c:35
unsigned nb_select
Definition side_data.c:37
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29