下嘴唇发麻什么病兆| 减肥期间晚上可以吃什么| 硫黄和硫磺有什么区别| 熬夜伤什么| 脾胃有火是什么症状| 灰指甲是什么症状| 贵字五行属什么| 平滑肌是什么| 树叶为什么是绿色的| 结婚纪念日送什么礼物| total什么意思| 不为良相便为良医是什么意思| 父母宫代表什么| 一什么冰箱| 糖化血红蛋白高是什么原因| 脚脱皮什么原因| 血热吃什么| zro是什么牌子| 借鉴是什么意思| 血管紧张素是什么意思| 什么情况下做冠脉ct| 上单是什么意思| 命大是什么意思| hill什么意思| 相见恨晚是什么意思| 不什么为什么| 穿拖鞋脚臭是什么原因| 四月初八是什么日子| 脖子长小肉粒是什么原因| 牙齿发酸是什么病征兆| 检查头部挂什么科| lz什么意思| 不什么好什么| 不明原因腿疼挂什么科| 荞麦长什么样子| 丙磺舒是什么药| 白酒不能和什么一起吃| 宋朝后面是什么朝代| 甲状腺是什么功能| 嘴唇起泡用什么药| 乙肝核心抗体阳性说明什么| 仙草是什么草| 互为表里是什么意思| 母亲节买什么礼物| 月子里可以吃什么蔬菜| aids是什么意思| 本科生是什么意思| 3月28号是什么星座| 什么山色| 甲亢什么意思| 抵抗力差吃什么可以增强抵抗力| 什么叫化疗为什么要化疗| 柏拉图之恋是什么意思| 黄历修造是什么意思| 鹿的部首是什么| 武则天墓为什么不敢挖| 告别是什么意思| 经期上火了吃什么降火| 脾胃虚寒者有什么症状| 尿液泡沫多是什么原因| 卵巢囊性包块是什么意思| 梦见纸人是什么意思| 肺大泡有什么症状| 感冒了吃什么食物最好| 京畿是什么意思| 采阴补阳是什么意思| 歺是什么意思| 6月16日是什么日子| 脚臭是什么原因| 什么降压药副作用小且效果最好| 什么啤酒劲最大| 身体多病戴什么首饰| 女性吃什么改善更年期| 刘邦是汉什么帝| 口腔苔藓用什么药| 什么是豹子号| 226是什么意思| 什么头蛇尾| aaa是什么意思| 怀孕早期有什么症状| 龟头发红是什么原因| 钅读什么偏旁| rpr是什么检查项目| 吃米饭配什么菜好吃| 羽字属于五行属什么| 冰淇淋是什么做的| msgm是什么品牌| 入殓师是什么意思| 什么叫人工智能| 青梅煮酒什么意思| 不想睡觉是什么原因| 狗狗狂犬疫苗什么时候打| 艾特是什么意思| 腊月是什么生肖| 右肺疼是什么原因| 兆后面的单位是什么| 经常耳鸣是什么原因引起的| negative是什么意思| 治疗肺部气肿有什么方法| 鲨鱼为什么不吃海豚| 心电轴不偏是什么意思| 纹身纹什么招财好运| 粘胶是什么面料| 素心是什么意思| dha中文叫什么| 烂嘴是什么原因| 肺结节吃什么药最好| 九死一生什么意思| 胆固醇为什么会高| 梦见两个小男孩是什么意思| 喝什么助眠| 拔完智齿第三天可以吃什么| 距骨在什么位置| 心肌受损会出现什么症状| 低血压平时要注意什么| 甲鱼喜欢吃什么| 九层塔是什么| 男人艾灸什么地方壮阳| 金字旁成是什么字| 移植是什么意思| crs是什么| 请问支气管炎吃什么药最有效| dunk是什么意思| 手足口一般擦什么药膏| 肠道功能紊乱吃什么药效果好| 辣椒什么时候种| 梦到被蛇咬是什么意思周公解梦| 肺气虚吃什么中成药| 肚子疼看什么科| 6度醋与9度有什么区别| 增生是什么| 血常规什么颜色的管子| 308什么意思| 村姑是什么意思| 肠胃不好能吃什么水果| 什么叫生理需求| 一代明君功千秋是什么生肖| lg手机是什么牌子| 肛门坠胀吃什么药最好| 卧底归来大结局是什么| 酸奶对人体有什么好处| 智商100属于什么水平| 时过境迁什么意思| 榴莲跟什么不能一起吃| 疑难杂症是什么意思| 瑞夫泰格手表什么档次| 双侧卵巢多卵泡是什么意思| 高反吃什么药| 小壁虎的尾巴有什么作用| 珊瑚虫属于什么动物| 英雄难过美人关是什么意思| 疳积有什么症状| 毛囊炎用什么药膏最好| 朱红色是什么颜色| 人为什么会中暑| 三十三天都是什么天| 婴儿胎毛什么时候剃最好| 小孩子为什么会得抽动症| 牙疼用什么药| 水怡是什么| 一个夸一个瓜念什么| 中性粒细胞低吃什么药| 1955年属什么| 清道夫鱼有什么作用| t1w1高信号代表什么| 小儿消化不良吃什么药最好| 被舔下面什么感觉| 情绪不稳定易怒烦躁是什么症状| 马冲什么生肖| 龟头炎用什么药膏好| 耐受性是什么意思| 纵隔是什么意思| 高同型半胱氨酸血症是什么病| 血糖低吃什么补的最快| 梦见被猪咬是什么意思| 彪子是什么意思| 一直流口水是什么原因| 肚子大腿细是什么原因| 什么是禽流感| 二道贩子是什么意思| 石足念什么| 梦见摘枣吃枣是什么意思| 什么食物含钾多| 冬瓜有什么功效| 皮革是什么材质| 右手大拇指发麻是什么原因| 去肝火喝什么茶好| 什么驴技穷成语| 黑上衣配什么颜色裤子男| 5201314是什么意思| a和ab型生的孩子是什么血型| 乳腺增生1类什么意思| 白头翁代表什么生肖| 什么叫桑拿| 乳酸菌是什么| 绣球花什么时候修剪| 甲功能5项检查是查的什么| 呕吐挂什么科| 回南天是什么时候| 河字五行属什么| 弱视是什么| 血瘀是什么原因造成的| 好马不吃回头草什么意思| 做梦吃酒席什么预兆| 姓许的女孩取什么名字好听| 汗毛长的女人代表什么| 手臂酸痛是什么原因| 南昌有什么好玩的| 茶叶里面含有什么成分| 命悬一线的意思是什么| 痛风吃什么药效果好| 乳房看什么科| 漂流穿什么衣服| 肩膀痛应该挂什么科| 广西北海有什么好玩的地方| r的平方是什么意思| homme是什么意思| 双鱼座和什么星座最配| 唯我独尊是什么意思| 拔鼻毛有什么危害| 抗凝药是什么意思| 嫦娥住的宫殿叫什么| chevy是什么车| 胸口痛是什么原因| 1.30是什么星座| 1987年属什么今年多大| 妇科检查清洁度3度什么意思| 拿的起放的下是什么意思| 甲状腺结节对身体有什么影响| 戛然而止是什么意思| 西铁城是什么档次的表| 男人额头有痣代表什么| 天月二德是什么意思| 什么是肾癌| 粽子的叶子是什么叶| 磁共振是检查什么| 勃不起来吃什么药| 歌字五行属什么| 心服口服是什么意思| 益禾堂什么好喝| 肚脐眼大代表什么| 澳门使用什么货币| 胆的作用和功能是什么| 天蝎后面是什么星座| 鸟飞到头上什么预兆| 身旺是什么意思| 煮花生放什么调料好吃| 肾结石挂什么科| 闪购是什么意思| 减肥吃什么食物| 打喷嚏预示什么| 口干舌燥吃点什么药| 好强的女人是什么性格| 经常做噩梦是什么原因| 滚去掉三点水念什么| 艳阳高照是什么生肖| 气血是什么| 氯硝西泮片是什么药| 血沉低是什么意思| 公务员是干什么工作的| 低密度脂蛋白高吃什么药| 哥们是什么意思| 鲨鱼为什么不吃海豚| 什么叫甲沟炎| 百度

李宁公司2017财报发布:年收入增长11%,毛利上升13%


Directory: ../../../ffmpeg/
File: src/libavdevice/lavfi.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 194 256 75.8%
Functions: 6 6 100.0%
Branches: 97 148 65.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2011 Stefano Sabatini
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 /**
22 * @file
23 * libavfilter virtual input device
24 */
25
26 /* #define DEBUG */
27
28 #include <float.h> /* DBL_MIN, DBL_MAX */
29
30 #include "libavutil/bprint.h"
31 #include "libavutil/channel_layout.h"
32 #include "libavutil/file.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/log.h"
36 #include "libavutil/mem.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/pixdesc.h"
40 #include "libavfilter/avfilter.h"
41 #include "libavfilter/buffersink.h"
42 #include "libavformat/demux.h"
43 #include "libavformat/internal.h"
44 #include "avdevice.h"
45
46 typedef struct {
47 AVClass *class; ///< class for private options
48 char *graph_str;
49 char *graph_filename;
50 char *dump_graph;
51 AVFilterGraph *graph;
52 AVFilterContext **sinks;
53 int *sink_stream_map;
54 int *sink_eof;
55 int *stream_sink_map;
56 int *sink_stream_subcc_map;
57 int nb_sinks;
58 AVPacket subcc_packet;
59 } LavfiContext;
60
61 48 av_cold static int lavfi_read_close(AVFormatContext *avctx)
62 {
63 48 LavfiContext *lavfi = avctx->priv_data;
64
65 48 av_freep(&lavfi->sink_stream_map);
66 48 av_freep(&lavfi->sink_eof);
67 48 av_freep(&lavfi->stream_sink_map);
68 48 av_freep(&lavfi->sink_stream_subcc_map);
69 48 av_freep(&lavfi->sinks);
70 48 avfilter_graph_free(&lavfi->graph);
71
72 48 return 0;
73 }
74
75 48 static int create_subcc_streams(AVFormatContext *avctx)
76 {
77 48 LavfiContext *lavfi = avctx->priv_data;
78 AVStream *st;
79 int stream_idx, sink_idx;
80 AVRational *time_base;
81
82
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (stream_idx = 0; stream_idx < lavfi->nb_sinks; stream_idx++) {
83 51 sink_idx = lavfi->stream_sink_map[stream_idx];
84
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 46 times.
51 if (lavfi->sink_stream_subcc_map[sink_idx]) {
85 5 lavfi->sink_stream_subcc_map[sink_idx] = avctx->nb_streams;
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
5 if (!(st = avformat_new_stream(avctx, NULL)))
87 return AVERROR(ENOMEM);
88 5 st->codecpar->codec_id = AV_CODEC_ID_EIA_608;
89 5 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
90 5 time_base = &avctx->streams[stream_idx]->time_base;
91 5 st->time_base.num = time_base->num;
92 5 st->time_base.den = time_base->den;
93 } else {
94 46 lavfi->sink_stream_subcc_map[sink_idx] = -1;
95 }
96 }
97 48 return 0;
98 }
99
100 48 av_cold static int lavfi_read_header(AVFormatContext *avctx)
101 {
102 48 LavfiContext *lavfi = avctx->priv_data;
103 48 AVFilterInOut *input_links = NULL, *output_links = NULL, *inout;
104 const AVFilter *buffersink, *abuffersink;
105 enum AVMediaType type;
106 48 int ret = 0, i, n;
107
108 #define FAIL(ERR) { ret = ERR; goto end; }
109
110 48 buffersink = avfilter_get_by_name("buffersink");
111 48 abuffersink = avfilter_get_by_name("abuffersink");
112
113
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
48 if (lavfi->graph_filename && lavfi->graph_str) {
114 av_log(avctx, AV_LOG_ERROR,
115 "Only one of the graph or graph_file options must be specified\n");
116 FAIL(AVERROR(EINVAL));
117 }
118
119
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 47 times.
48 if (lavfi->graph_filename) {
120 AVBPrint graph_file_pb;
121 1 AVIOContext *avio = NULL;
122 1 AVDictionary *options = NULL;
123
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 if (avctx->protocol_whitelist && (ret = av_dict_set(&options, "protocol_whitelist", avctx->protocol_whitelist, 0)) < 0)
124 goto end;
125 1 ret = avio_open2(&avio, lavfi->graph_filename, AVIO_FLAG_READ, &avctx->interrupt_callback, &options);
126 1 av_dict_free(&options);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
128 goto end;
129 1 av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
130 1 ret = avio_read_to_bprint(avio, &graph_file_pb, INT_MAX);
131 1 avio_closep(&avio);
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret) {
133 av_bprint_finalize(&graph_file_pb, NULL);
134 goto end;
135 }
136
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if ((ret = av_bprint_finalize(&graph_file_pb, &lavfi->graph_str)))
137 goto end;
138 }
139
140
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if (!lavfi->graph_str)
141 46 lavfi->graph_str = av_strdup(avctx->url);
142
143 /* parse the graph, create a stream for each open output */
144
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if (!(lavfi->graph = avfilter_graph_alloc()))
145 FAIL(AVERROR(ENOMEM));
146
147
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if ((ret = avfilter_graph_parse_ptr(lavfi->graph, lavfi->graph_str,
148 &input_links, &output_links, avctx)) < 0)
149 goto end;
150
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (input_links) {
152 av_log(avctx, AV_LOG_ERROR,
153 "Open inputs in the filtergraph are not acceptable\n");
154 FAIL(AVERROR(EINVAL));
155 }
156
157 /* count the outputs */
158
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (n = 0, inout = output_links; inout; n++, inout = inout->next);
159 48 lavfi->nb_sinks = n;
160
161
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n)))
162 FAIL(AVERROR(ENOMEM));
163
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if (!(lavfi->sink_eof = av_mallocz(sizeof(int) * n)))
164 FAIL(AVERROR(ENOMEM));
165
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n)))
166 FAIL(AVERROR(ENOMEM));
167
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if (!(lavfi->sink_stream_subcc_map = av_malloc(sizeof(int) * n)))
168 FAIL(AVERROR(ENOMEM));
169
170
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (i = 0; i < n; i++)
171 51 lavfi->stream_sink_map[i] = -1;
172
173 /* parse the output link names - they need to be of the form out0, out1, ...
174 * create a mapping between them and the streams */
175
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
176 51 int stream_idx = 0, suffix = 0, use_subcc = 0;
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (!inout->name) {
178 av_log(avctx, AV_LOG_ERROR, "Missing %d outpad name\n", i);
179 FAIL(AVERROR(EINVAL));
180 }
181 51 sscanf(inout->name, "out%n%d%n", &suffix, &stream_idx, &suffix);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (!suffix) {
183 av_log(avctx, AV_LOG_ERROR,
184 "Invalid outpad name '%s'\n", inout->name);
185 FAIL(AVERROR(EINVAL));
186 }
187
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 46 times.
51 if (inout->name[suffix]) {
188
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (!strcmp(inout->name + suffix, "+subcc")) {
189 5 use_subcc = 1;
190 } else {
191 av_log(avctx, AV_LOG_ERROR,
192 "Invalid outpad suffix '%s'\n", inout->name);
193 FAIL(AVERROR(EINVAL));
194 }
195 }
196
197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if ((unsigned)stream_idx >= n) {
198 av_log(avctx, AV_LOG_ERROR,
199 "Invalid index was specified in output '%s', "
200 "must be a non-negative value < %d\n",
201 inout->name, n);
202 FAIL(AVERROR(EINVAL));
203 }
204
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (lavfi->stream_sink_map[stream_idx] != -1) {
206 av_log(avctx, AV_LOG_ERROR,
207 "An output with stream index %d was already specified\n",
208 stream_idx);
209 FAIL(AVERROR(EINVAL));
210 }
211 51 lavfi->sink_stream_map[i] = stream_idx;
212 51 lavfi->stream_sink_map[stream_idx] = i;
213 51 lavfi->sink_stream_subcc_map[i] = !!use_subcc;
214 }
215
216 /* for each open output create a corresponding stream */
217
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
218 AVStream *st;
219
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
51 if (!(st = avformat_new_stream(avctx, NULL)))
220 FAIL(AVERROR(ENOMEM));
221 51 st->id = i;
222 }
223
224 /* create a sink for each output and connect them to the graph */
225 48 lavfi->sinks = av_malloc_array(lavfi->nb_sinks, sizeof(AVFilterContext *));
226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (!lavfi->sinks)
227 FAIL(AVERROR(ENOMEM));
228
229
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
230 AVFilterContext *sink;
231
232 51 type = avfilter_pad_get_type(inout->filter_ctx->output_pads, inout->pad_idx);
233
234
5/6
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26 times.
✓ Branch 5 taken 25 times.
51 if (type == AVMEDIA_TYPE_VIDEO && ! buffersink ||
235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 type == AVMEDIA_TYPE_AUDIO && ! abuffersink) {
236 av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n");
237 FAIL(AVERROR_FILTER_NOT_FOUND);
238 }
239
240
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 26 times.
51 if (type == AVMEDIA_TYPE_VIDEO) {
241 25 ret = avfilter_graph_create_filter(&sink, buffersink,
242 25 inout->name, NULL,
243 NULL, lavfi->graph);
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (ret < 0)
245 goto end;
246
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 } else if (type == AVMEDIA_TYPE_AUDIO) {
247 static const enum AVSampleFormat sample_fmts[] = {
248 AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
249 AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL,
250 };
251
252 26 sink = avfilter_graph_alloc_filter(lavfi->graph, abuffersink, inout->name);
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (!sink) {
254 ret = AVERROR(ENOMEM);
255 goto end;
256 }
257
258 26 ret = av_opt_set_bin(sink, "sample_fmts", (const uint8_t*)sample_fmts,
259 sizeof(sample_fmts), AV_OPT_SEARCH_CHILDREN);
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0)
261 goto end;
262 26 ret = av_opt_set_int(sink, "all_channel_counts", 1,
263 AV_OPT_SEARCH_CHILDREN);
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0)
265 goto end;
266
267 26 ret = avfilter_init_dict(sink, NULL);
268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0)
269 goto end;
270 } else {
271 av_log(avctx, AV_LOG_ERROR,
272 "Output '%s' is not a video or audio output, not yet supported\n", inout->name);
273 FAIL(AVERROR(EINVAL));
274 }
275
276 51 lavfi->sinks[i] = sink;
277
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
51 if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0)
278 goto end;
279 }
280
281 /* configure the graph */
282
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
48 if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0)
283 goto end;
284
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (lavfi->dump_graph) {
286 char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph);
287 if (dump != NULL) {
288 fputs(dump, stderr);
289 fflush(stderr);
290 av_free(dump);
291 } else {
292 FAIL(AVERROR(ENOMEM));
293 }
294 }
295
296 /* fill each stream with the information in the corresponding sink */
297
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 48 times.
99 for (i = 0; i < lavfi->nb_sinks; i++) {
298 51 AVFilterContext *sink = lavfi->sinks[lavfi->stream_sink_map[i]];
299 51 AVRational time_base = av_buffersink_get_time_base(sink);
300 51 AVRational frame_rate = av_buffersink_get_frame_rate(sink);
301 51 AVStream *st = avctx->streams[i];
302 51 AVCodecParameters *const par = st->codecpar;
303 51 avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
304 51 par->codec_type = av_buffersink_get_type(sink);
305
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 26 times.
51 if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
306 25 par->codec_id = AV_CODEC_ID_WRAPPED_AVFRAME;
307 25 par->format = av_buffersink_get_format(sink);
308 25 par->width = av_buffersink_get_w(sink);
309 25 par->height = av_buffersink_get_h(sink);
310 25 avctx->probesize = FFMAX(avctx->probesize, sizeof(AVFrame) * 30);
311 25 st ->sample_aspect_ratio =
312 25 par->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink);
313
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
25 if (frame_rate.num > 0 && frame_rate.den > 0) {
314 25 st->avg_frame_rate = frame_rate;
315 25 st->r_frame_rate = frame_rate;
316 }
317
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
318 26 par->sample_rate = av_buffersink_get_sample_rate(sink);
319 26 ret = av_buffersink_get_ch_layout(sink, &par->ch_layout);
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0)
321 goto end;
322 26 par->format = av_buffersink_get_format(sink);
323 26 par->codec_id = av_get_pcm_codec(par->format, -1);
324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (par->codec_id == AV_CODEC_ID_NONE)
325 av_log(avctx, AV_LOG_ERROR,
326 "Could not find PCM codec for sample format %s.\n",
327 av_get_sample_fmt_name(par->format));
328 }
329 }
330
331
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 if ((ret = create_subcc_streams(avctx)) < 0)
332 goto end;
333
334 48 end:
335 48 avfilter_inout_free(&input_links);
336 48 avfilter_inout_free(&output_links);
337 48 return ret;
338 }
339
340 11315 static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame,
341 int sink_idx)
342 {
343 11315 LavfiContext *lavfi = avctx->priv_data;
344 AVFrameSideData *sd;
345 int stream_idx, ret;
346
347
2/2
✓ Branch 0 taken 10573 times.
✓ Branch 1 taken 742 times.
11315 if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0)
348 10573 return 0;
349
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 742 times.
742 if (!(sd = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC)))
350 return 0;
351
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 742 times.
742 if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0)
352 return ret;
353 742 memcpy(lavfi->subcc_packet.data, sd->data, sd->size);
354 742 lavfi->subcc_packet.stream_index = stream_idx;
355 742 lavfi->subcc_packet.pts = frame->pts;
356 742 return 0;
357 }
358
359 1876 static void lavfi_free_frame(void *opaque, uint8_t *data)
360 {
361 1876 AVFrame *frame = (AVFrame*)data;
362 1876 av_frame_free(&frame);
363 1876 }
364
365 12101 static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
366 {
367 12101 LavfiContext *lavfi = avctx->priv_data;
368 12101 double min_pts = DBL_MAX;
369 12101 int stream_idx, min_pts_sink_idx = 0;
370 AVFrame *frame, *frame_to_free;
371 AVDictionary *frame_metadata;
372 int ret, i;
373 AVStream *st;
374
375
2/2
✓ Branch 0 taken 742 times.
✓ Branch 1 taken 11359 times.
12101 if (lavfi->subcc_packet.size) {
376 742 av_packet_move_ref(pkt, &lavfi->subcc_packet);
377 742 return pkt->size;
378 }
379
380 11359 frame = av_frame_alloc();
381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11359 times.
11359 if (!frame)
382 return AVERROR(ENOMEM);
383 11359 frame_to_free = frame;
384
385 /* iterate through all the graph sinks. Select the sink with the
386 * minimum PTS */
387
2/2
✓ Branch 0 taken 11416 times.
✓ Branch 1 taken 11359 times.
22775 for (i = 0; i < lavfi->nb_sinks; i++) {
388 11416 AVRational tb = av_buffersink_get_time_base(lavfi->sinks[i]);
389 double d;
390
391
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 11386 times.
11416 if (lavfi->sink_eof[i])
392 76 continue;
393
394 11386 ret = av_buffersink_get_frame_flags(lavfi->sinks[i], frame,
395 AV_BUFFERSINK_FLAG_PEEK);
396
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 11340 times.
11386 if (ret == AVERROR_EOF) {
397 ff_dlog(avctx, "EOF sink_idx:%d\n", i);
398 46 lavfi->sink_eof[i] = 1;
399 46 continue;
400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11340 times.
11340 } else if (ret < 0)
401 goto fail;
402 11340 d = av_rescale_q_rnd(frame->pts, tb, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
403 ff_dlog(avctx, "sink_idx:%d time:%f\n", i, d);
404 11340 av_frame_unref(frame);
405
406
2/2
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 19 times.
11340 if (d < min_pts) {
407 11321 min_pts = d;
408 11321 min_pts_sink_idx = i;
409 }
410 }
411
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11315 times.
11359 if (min_pts == DBL_MAX) {
412 44 ret = AVERROR_EOF;
413 44 goto fail;
414 }
415
416 ff_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx);
417
418 11315 av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0);
419 11315 stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];
420 11315 st = avctx->streams[stream_idx];
421
422
2/2
✓ Branch 0 taken 1876 times.
✓ Branch 1 taken 9439 times.
11315 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
423 1876 pkt->buf = av_buffer_create((uint8_t*)frame, sizeof(*frame),
424 &lavfi_free_frame, NULL, 0);
425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1876 times.
1876 if (!pkt->buf) {
426 ret = AVERROR(ENOMEM);
427 goto fail;
428 }
429 1876 frame_to_free = NULL;
430
431 1876 pkt->data = pkt->buf->data;
432 1876 pkt->size = pkt->buf->size;
433 1876 pkt->flags |= AV_PKT_FLAG_TRUSTED;
434
1/2
✓ Branch 0 taken 9439 times.
✗ Branch 1 not taken.
9439 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
435 9439 int size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
436 9439 frame->ch_layout.nb_channels;
437
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9439 times.
9439 if ((ret = av_new_packet(pkt, size)) < 0)
438 goto fail;
439 9439 memcpy(pkt->data, frame->data[0], size);
440 }
441
442 11315 frame_metadata = frame->metadata;
443
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 10851 times.
11315 if (frame_metadata) {
444 size_t size;
445 464 uint8_t *metadata = av_packet_pack_dictionary(frame_metadata, &size);
446
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 464 times.
464 if (!metadata) {
448 ret = AVERROR(ENOMEM);
449 goto fail;
450 }
451
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 464 times.
464 if ((ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
452 metadata, size)) < 0) {
453 av_freep(&metadata);
454 goto fail;
455 }
456 }
457
458
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11315 times.
11315 if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {
459 goto fail;
460 }
461
462 11315 pkt->stream_index = stream_idx;
463 11315 pkt->pts = frame->pts;
464
465 11315 av_frame_free(&frame_to_free);
466
467 11315 return pkt->size;
468 44 fail:
469 44 av_frame_free(&frame_to_free);
470 44 return ret;
471
472 }
473
474 #define OFFSET(x) offsetof(LavfiContext, x)
475
476 #define DEC AV_OPT_FLAG_DECODING_PARAM
477
478 static const AVOption options[] = {
479 { "graph", "set libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
480 { "graph_file","set libavfilter graph filename", OFFSET(graph_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
481 { "dumpgraph", "dump graph to stderr", OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
482 { NULL },
483 };
484
485 static const AVClass lavfi_class = {
486 .class_name = "lavfi indev",
487 .item_name = av_default_item_name,
488 .option = options,
489 .version = LIBAVUTIL_VERSION_INT,
490 .category = AV_CLASS_CATEGORY_DEVICE_INPUT,
491 };
492
493 const FFInputFormat ff_lavfi_demuxer = {
494 .p.name = "lavfi",
495 .p.long_name = NULL_IF_CONFIG_SMALL("Libavfilter virtual input device"),
496 .p.flags = AVFMT_NOFILE,
497 .p.priv_class = &lavfi_class,
498 .priv_data_size = sizeof(LavfiContext),
499 .read_header = lavfi_read_header,
500 .read_packet = lavfi_read_packet,
501 .read_close = lavfi_read_close,
502 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
503 };
504

hpv感染是什么病 胃酸分泌过多吃什么药 阿咖酚散是什么 便秘吃什么药 强扭的瓜不甜什么意思
hcg下降是什么原因 ctc是什么意思 一个王一个八念什么 天干地支是什么意思 ed什么意思
长命百岁是什么意思 过敏期间不能吃什么东西 摔纹皮是什么皮 嗓子疼吃什么消炎药 凉薄是什么意思
1.8是什么星座 日本桑是什么意思 须知是什么意思 谜底是什么意思 菲拉格慕属于什么档次
嫉妒是什么意思bfb118.com 瓜婆娘四川话是什么意思hcv9jop5ns4r.cn 大便陶土色是什么颜色hcv7jop9ns3r.cn 喝什么茶能降血压hcv9jop4ns3r.cn 腮腺炎是什么原因引起的hcv9jop8ns1r.cn
血小板压积偏低是什么意思hcv9jop3ns2r.cn 为什么新生儿有胎记hcv8jop6ns4r.cn 梦见鼻子出血是什么意思hcv8jop5ns3r.cn 什么水越洗越脏hcv7jop6ns9r.cn 梦到两条蛇预示着什么96micro.com
农历闰六月有什么讲究hcv8jop6ns4r.cn 没有奶水怎么办吃什么能下奶hcv7jop4ns6r.cn 阴道痛什么原因adwl56.com 什么是it行业hcv8jop1ns9r.cn 喉咙痛不能吃什么东西liaochangning.com
喝什么补肾cj623037.com 猜疑是什么意思hcv7jop7ns2r.cn 灰棕色是什么颜色hcv7jop7ns0r.cn 物以类聚人以群分什么意思hcv9jop2ns1r.cn 小孩经常肚子疼是什么原因hcv8jop6ns3r.cn
百度