哆啦a梦的口袋叫什么| 今年9岁属什么| 立冬吃什么| josiny是什么牌子| 什么病可以请长假| 云字属于五行属什么| 辩证什么意思| 孙悟空姓什么| 口腔溃疡反复发作是什么原因| 腋臭手术挂什么科| 碘伏和络合碘有什么区别| 牙龈萎缩是什么原因引起的| 细胞骨架是由什么构成| 手关节黑是什么原因| 疮痈是什么意思| 什么不生四字成语| 邹去掉耳朵旁读什么| 钥匙代表什么生肖| 伪骨科是什么意思| vc什么意思| 18k金是什么金| pocky是什么意思| 小孩走路迟是什么原因| 阴囊瘙痒挂什么科室| 空调健康模式是什么意思| 梦见吃红薯是什么意思| 头发干枯毛躁是什么原因| 抗体阳性说明什么| 脚趾麻是什么原因| 两个克念什么| 人为什么会做噩梦| 爱放屁什么原因| 乘字五行属什么| 护肝养肝吃什么药最好| 善字五行属什么| 扁平比是什么意思| 五月二十四号是什么星座| 吃什么补心| 君子兰叶子发黄是什么原因| 毛细血管扩张是什么原因引起的| vd是什么| 早上口干口苦是什么原因| 喉咙细菌感染吃什么药| 女生读什么技校好| 11月1日是什么星座| 三叉戟是什么意思| 93年鸡五行属什么| 湖水蓝是什么颜色| 男性前列腺炎有什么症状| 深水炸弹什么意思| 考验是什么意思| 吃开心果有什么好处和坏处| 遥望是什么意思| 煎牛排用什么锅| 啄木鸟为什么不会脑震荡| 来姨妈能吃什么水果| 开门是什么意思| 下过海是什么意思| 尿道炎用什么药治疗最好| 过氧化氢弱阳性什么意思| 颈椎痛吃什么药| 小五行属性是什么| 带状疱疹后遗神经痛用什么药| 身体抱恙是什么意思| 莲子有什么功效| 酱油是什么做的| md是什么牌子| 益生菌有什么好处| 自怨自艾什么意思| 肥猪拱门是什么生肖| 马蹄铁什么时候发明的| 胃酸反酸水吃什么药| 土鳖是什么意思| 梦见自己掉头发是什么征兆| 嗔心是什么意思| pdn是什么意思| 大腿根部痒用什么药膏| 9价疫苗适合什么年龄人打| 左下眼皮跳是什么预兆| 李商隐号什么| 玉仁玫白膏有什么功效| 泌乳素高有什么影响| 肝郁化火吃什么中成药| 嘴唇下面长痘痘是什么原因| 气短吃什么药| 想吐头晕是什么原因| 绩效工资是什么| 冒冷汗是什么原因| 不慎是什么意思| 9月10号什么星座| 味甘是什么意思| 摸鱼是什么意思| 脚趾头麻木是什么原因| 手脚麻木吃什么药最管用| 谷氨酰转肽酶是指什么| 蒸鱼豉油什么时候放| 指甲凹凸不平是什么原因| 指责的意思是什么| 煤油对人体有什么危害| 烫伤抹什么药| 前列腺吃什么药效果好| 什么是丙肝| 舌头溃疡吃什么药| 罗贯中和施耐庵是什么关系| 睾丸炎用什么药| 中性人是什么意思| 为什么北极没有企鹅| 斜视是什么原因导致的| 大堤是什么意思| 宝宝咳嗽挂什么科| 为什么生理期不能拔牙| 心肌梗塞有什么症状| 前列腺增生吃什么药最好| 尿素偏高是什么意思| 斜视是什么症状| 喝酒对胃有什么伤害| 河豚是什么| 打喷嚏是什么预兆| 和可以组什么词| 欣赏是什么意思| 思想感情是什么意思| 验孕棒什么时候测最准确| 牙齿打桩是什么意思| 上焦湿热吃什么中成药| 血糖高喝酒有什么影响| 胸部b超挂什么科| 霸王别姬是什么意思| 常态是什么意思| 常喝蜂蜜水有什么好处和坏处| 貌不惊人是什么意思| 装可以组什么词| 坐月子可以吃什么水果| 乐果农药适合杀什么虫| 五行木是什么颜色| 怂人是什么意思| 残局是什么意思| 什么名字好听男生| 睡觉张嘴是什么原因| 吃荆芥有什么好处| 阑尾炎可以吃什么水果| 众里寻他千百度是什么意思| 抄手是什么食物| 户口迁移需要什么手续| 吃什么补筋和韧带最快| 宁波有什么特产| 周杰伦什么时候出道| 上吐下泻吃什么食物好| 拿什么东西不用手| 克拉霉素主治什么病| 克苏鲁是什么| 收到是什么意思| 蔷薇色是什么颜色| 伤寒是什么病| 什么人不适合种植牙| 重庆古代叫什么| 白砂糖是什么糖| 粥米是什么米| 尿胆素1十是什么意思| 跟腱炎吃什么药效果好| 厍是什么意思| 茅台为什么这么贵| 不外乎是什么意思| 脾胃不好能吃什么水果| 现在是什么时间| 尿ph值高是什么意思| 岗位等级是什么意思| 肝风内动是什么意思| 咳嗽可以吃什么食物| 子女宫是什么意思| 榨菜是什么菜做的| 羊肉馅饺子放什么菜| 沁人心扉什么意思| 肩周炎属于什么科室| 寄生虫吃什么药可以杀死| 大姨妈来了吃什么好| 排骨炖什么补血补气| 结婚证需要什么资料| 心代表什么生肖| 不射精是什么原因| 治疗脚气用什么药| 布朗是什么水果| 仙人掌能治什么病| 男生下面长什么样| 幻觉幻听是什么症状| 上吐下泻吃什么食物好| 什么水果败火| 肾囊肿有什么症状表现| 生肖羊生什么生肖最好| 油菜籽什么时间种| 脑缺血吃什么药| 胸口有痣代表什么意思| 什么是法西斯主义| 1989年五行属什么| 侧记是什么意思| a9什么意思| 祖庭是什么意思| 命大是什么意思| 啼笑皆非的意思是什么| 清热利湿吃什么药| 尿多是什么回事| 月寸读什么| 手指甲变黑是什么原因| 区块链是什么| 雪中送炭是什么意思| anello是什么牌子| 心绪不宁的意思是什么| 老公的爸爸称谓是什么| 为什么感冒药吃了想睡觉| 女生右手中指戴戒指什么意思| 追悔莫及什么意思| naco是什么牌子| 高铁上什么东西不能带| 利多卡因是什么| 燕麦片热量高为什么还能减肥| 85年属牛是什么命| 墨蓝色是什么颜色| 非赘生性囊肿什么意思| 什么地发现| 有骨气是什么意思| 新疆有什么水果| 梦见刷牙是什么预兆| 为什么不能空腹喝牛奶| 什么是元气| 天然气什么味道| 买车置换是什么意思| 乙肝是什么病| 梦见僵尸是什么预兆| 百字五行属什么| 飞蚊症用什么药物治疗最好| 感冒输液用什么药| 黑色的裤子配什么颜色的上衣| 陆地上最重的动物是什么| 来月经小腹痛是什么原因| 胃结石有什么症状表现| 诺言背叛诺言是什么歌| 盖世英雄是什么意思| 心脏下边是什么器官| 穿青人是什么民族| 脚背疼是什么原因| 胃胀吃什么药效果最好| 宫颈肥大是什么原因| 心脏早搏有什么危害| naomi什么意思| 蟋蟀吃什么| 胸椎退行性变什么意思| co2是什么意思| 不易是什么意思| 植物神经是什么| 脸上长藓用什么药| 发烧吃什么消炎药| 化疗中的病人应该吃什么| 做梦梦见捡钱是什么意思| 梦见打碎碗是什么预兆| 扁食是什么| 右下腹痛挂什么科| 森林里有什么| 什么时候不容易怀孕| 医保定点是什么意思| 右侧卵巢囊性回声什么意思| 变色龙指什么样的人| 拉肚子呕吐吃什么药| 史努比是什么品牌| 明心见性是什么意思| 胆结石挂什么科| 百度

用车你的热车方法是不是真的正确?看自己有木


Directory: ../../../ffmpeg/
File: src/libavformat/subtitles.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 225 276 81.5%
Functions: 26 26 100.0%
Branches: 152 240 63.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2012-2013 Clément B?sch <u pkh me>
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 "avformat.h"
22 #include "subtitles.h"
23 #include "avio_internal.h"
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/mem.h"
27
28 43465 void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
29 {
30 int i;
31 43465 r->pb = pb;
32 43465 r->buf_pos = r->buf_len = 0;
33 43465 r->type = FF_UTF_8;
34
2/2
✓ Branch 0 taken 86930 times.
✓ Branch 1 taken 43465 times.
130395 for (i = 0; i < 2; i++)
35 86930 r->buf[r->buf_len++] = avio_r8(r->pb);
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43465 times.
43465 if (strncmp("\xFF\xFE", r->buf, 2) == 0) {
37 r->type = FF_UTF16LE;
38 r->buf_pos += 2;
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43465 times.
43465 } else if (strncmp("\xFE\xFF", r->buf, 2) == 0) {
40 r->type = FF_UTF16BE;
41 r->buf_pos += 2;
42 } else {
43 43465 r->buf[r->buf_len++] = avio_r8(r->pb);
44
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 43403 times.
43465 if (strncmp("\xEF\xBB\xBF", r->buf, 3) == 0) {
45 // UTF8
46 62 r->buf_pos += 3;
47 }
48 }
49
4/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 43446 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
43465 if (s && (r->type == FF_UTF16LE || r->type == FF_UTF16BE))
50 av_log(s, AV_LOG_INFO,
51 "UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
52 43465 }
53
54 43446 void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size)
55 {
56 43446 ffio_init_read_context(&r->buf_pb, buf, size);
57 43446 ff_text_init_avio(NULL, r, &r->buf_pb.pub);
58 43446 }
59
60 5583 int64_t ff_text_pos(FFTextReader *r)
61 {
62 5583 return avio_tell(r->pb) - r->buf_len + r->buf_pos;
63 }
64
65 790974 int ff_text_r8(FFTextReader *r)
66 {
67 uint32_t val;
68 uint8_t tmp;
69
2/2
✓ Branch 0 taken 133590 times.
✓ Branch 1 taken 657384 times.
790974 if (r->buf_pos < r->buf_len)
70 133590 return r->buf[r->buf_pos++];
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 657384 times.
657384 if (r->type == FF_UTF16LE) {
72 GET_UTF16(val, avio_rl16(r->pb), return 0;)
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 657384 times.
657384 } else if (r->type == FF_UTF16BE) {
74 GET_UTF16(val, avio_rb16(r->pb), return 0;)
75 } else {
76 657384 return avio_r8(r->pb);
77 }
78 if (!val)
79 return 0;
80 r->buf_pos = 0;
81 r->buf_len = 0;
82 PUT_UTF8(val, tmp, r->buf[r->buf_len++] = tmp;)
83 return r->buf[r->buf_pos++]; // buf_len is at least 1
84 }
85
86 36205 void ff_text_read(FFTextReader *r, char *buf, size_t size)
87 {
88
2/2
✓ Branch 0 taken 521352 times.
✓ Branch 1 taken 36205 times.
557557 for ( ; size > 0; size--)
89 521352 *buf++ = ff_text_r8(r);
90 36205 }
91
92 10711 int ff_text_eof(FFTextReader *r)
93 {
94
4/4
✓ Branch 0 taken 8998 times.
✓ Branch 1 taken 1713 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 8971 times.
10711 return r->buf_pos >= r->buf_len && avio_feof(r->pb);
95 }
96
97 71722 int ff_text_peek_r8(FFTextReader *r)
98 {
99 int c;
100
2/2
✓ Branch 0 taken 63739 times.
✓ Branch 1 taken 7983 times.
71722 if (r->buf_pos < r->buf_len)
101 63739 return r->buf[r->buf_pos];
102 7983 c = ff_text_r8(r);
103
1/2
✓ Branch 1 taken 7983 times.
✗ Branch 2 not taken.
7983 if (!avio_feof(r->pb)) {
104 7983 r->buf_pos = 0;
105 7983 r->buf_len = 1;
106 7983 r->buf[0] = c;
107 }
108 7983 return c;
109 }
110
111 2652 AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
112 const uint8_t *event, size_t len, int merge)
113 {
114 AVPacket **subs, *sub;
115
116 av_assert1(event || len == 0);
117
118
4/4
✓ Branch 0 taken 949 times.
✓ Branch 1 taken 1703 times.
✓ Branch 2 taken 948 times.
✓ Branch 3 taken 1 times.
3600 if (merge && q->nb_subs > 0) {
119 /* merge with previous event */
120
121 int old_len;
122 948 sub = q->subs[q->nb_subs - 1];
123 948 old_len = sub->size;
124
1/2
✓ Branch 0 taken 948 times.
✗ Branch 1 not taken.
948 if (event) {
125
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 948 times.
948 if (av_grow_packet(sub, len) < 0)
126 return NULL;
127 948 memcpy(sub->data + old_len, event, len);
128 }
129 } else {
130 /* new event */
131
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1704 times.
1704 if (q->nb_subs >= INT_MAX/sizeof(*q->subs) - 1)
133 return NULL;
134 1704 subs = av_fast_realloc(q->subs, &q->allocated_size,
135 1704 (q->nb_subs + 1) * sizeof(*q->subs));
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1704 times.
1704 if (!subs)
137 return NULL;
138 1704 q->subs = subs;
139 1704 sub = av_packet_alloc();
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1704 times.
1704 if (!sub)
141 return NULL;
142
1/2
✓ Branch 0 taken 1704 times.
✗ Branch 1 not taken.
1704 if (event) {
143
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1704 times.
1704 if (av_new_packet(sub, len) < 0) {
144 av_packet_free(&sub);
145 return NULL;
146 }
147 1704 memcpy(sub->data, event, len);
148 }
149 1704 sub->flags |= AV_PKT_FLAG_KEY;
150 1704 sub->pts = sub->dts = 0;
151 1704 subs[q->nb_subs++] = sub;
152 }
153 2652 return sub;
154 }
155
156 1839 AVPacket *ff_subtitles_queue_insert_bprint(FFDemuxSubtitlesQueue *q,
157 const AVBPrint *event, int merge)
158 {
159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1839 times.
1839 if (!av_bprint_is_complete(event))
160 return NULL;
161 1839 return ff_subtitles_queue_insert(q, event->str, event->len, merge);
162 }
163
164 5144 static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
165 {
166 5144 const AVPacket *s1 = *(const AVPacket **)a;
167 5144 const AVPacket *s2 = *(const AVPacket **)b;
168
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 4979 times.
5144 if (s1->pts == s2->pts)
169 165 return FFDIFFSIGN(s1->pos, s2->pos);
170 4979 return FFDIFFSIGN(s1->pts , s2->pts);
171 }
172
173 369 static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
174 {
175 369 const AVPacket *s1 = *(const AVPacket **)a;
176 369 const AVPacket *s2 = *(const AVPacket **)b;
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 369 times.
369 if (s1->pos == s2->pos) {
178 if (s1->pts == s2->pts)
179 return 0;
180 return s1->pts > s2->pts ? 1 : -1;
181 }
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 369 times.
369 return s1->pos > s2->pos ? 1 : -1;
183 }
184
185 35 static void drop_dups(void *log_ctx, FFDemuxSubtitlesQueue *q)
186 {
187 35 int i, drop = 0;
188
189
2/2
✓ Branch 0 taken 1477 times.
✓ Branch 1 taken 35 times.
1512 for (i = 1; i < q->nb_subs; i++) {
190 1477 const int last_id = i - 1 - drop;
191 1477 const AVPacket *last = q->subs[last_id];
192
193
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 1348 times.
1477 if (q->subs[i]->pts == last->pts &&
194
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 84 times.
129 q->subs[i]->duration == last->duration &&
195
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 q->subs[i]->stream_index == last->stream_index &&
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 !strcmp(q->subs[i]->data, last->data)) {
197
198 av_packet_free(&q->subs[i]);
199 drop++;
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1477 times.
1477 } else if (drop) {
201 q->subs[last_id + 1] = q->subs[i];
202 q->subs[i] = NULL;
203 }
204 }
205
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (drop) {
207 q->nb_subs -= drop;
208 av_log(log_ctx, AV_LOG_WARNING, "Dropping %d duplicated subtitle events\n", drop);
209 }
210 35 }
211
212 41 void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
213 {
214 int i;
215
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (!q->nb_subs)
217 return;
218
219 41 qsort(q->subs, q->nb_subs, sizeof(*q->subs),
220
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3 times.
41 q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
221 : cmp_pkt_sub_pos_ts);
222
2/2
✓ Branch 0 taken 1704 times.
✓ Branch 1 taken 41 times.
1745 for (i = 0; i < q->nb_subs; i++)
223
5/6
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 1475 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 222 times.
✗ Branch 5 not taken.
1704 if (q->subs[i]->duration < 0 && i < q->nb_subs - 1 && q->subs[i + 1]->pts - (uint64_t)q->subs[i]->pts <= INT64_MAX)
224 222 q->subs[i]->duration = q->subs[i + 1]->pts - q->subs[i]->pts;
225
226
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 6 times.
41 if (!q->keep_duplicates)
227 35 drop_dups(log_ctx, q);
228 }
229
230 1726 int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
231 {
232 AVPacket *sub;
233 int ret;
234
235
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 1688 times.
1726 if (q->current_sub_idx == q->nb_subs)
236 38 return AVERROR_EOF;
237 1688 sub = q->subs[q->current_sub_idx];
238
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1688 times.
1688 if ((ret = av_packet_ref(pkt, sub)) < 0) {
239 return ret;
240 }
241
242 1688 pkt->dts = pkt->pts;
243 1688 q->current_sub_idx++;
244 1688 return 0;
245 }
246
247 2 static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
248 {
249 2 int s1 = 0, s2 = q->nb_subs - 1;
250
251
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (s2 < s1)
252 return AVERROR(ERANGE);
253
254 12 for (;;) {
255 int mid;
256
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (s1 == s2)
258 return s1;
259
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
14 if (s1 == s2 - 1)
260
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return q->subs[s1]->pts <= q->subs[s2]->pts ? s1 : s2;
261 12 mid = (s1 + s2) / 2;
262
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
12 if (q->subs[mid]->pts <= ts)
263 3 s1 = mid;
264 else
265 9 s2 = mid;
266 }
267 }
268
269 2 int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index,
270 int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
271 {
272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (flags & AVSEEK_FLAG_BYTE) {
273 return AVERROR(ENOSYS);
274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (flags & AVSEEK_FLAG_FRAME) {
275 if (ts < 0 || ts >= q->nb_subs)
276 return AVERROR(ERANGE);
277 q->current_sub_idx = ts;
278 } else {
279 2 int i, idx = search_sub_ts(q, ts);
280 int64_t ts_selected;
281
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (idx < 0)
283 return idx;
284
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 for (i = idx; i < q->nb_subs && q->subs[i]->pts < min_ts; i++)
285 if (stream_index == -1 || q->subs[i]->stream_index == stream_index)
286 idx = i;
287
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
2 for (i = idx; i > 0 && q->subs[i]->pts > max_ts; i--)
288 if (stream_index == -1 || q->subs[i]->stream_index == stream_index)
289 idx = i;
290
291 2 ts_selected = q->subs[idx]->pts;
292
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (ts_selected < min_ts || ts_selected > max_ts)
293 1 return AVERROR(ERANGE);
294
295 /* look back in the latest subtitles for overlapping subtitles */
296
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 for (i = idx - 1; i >= 0; i--) {
297 1 int64_t pts = q->subs[i]->pts;
298
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (q->subs[i]->duration <= 0 ||
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 (stream_index != -1 && q->subs[i]->stream_index != stream_index))
300 continue;
301
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (pts >= min_ts && pts > ts_selected - q->subs[i]->duration)
302 idx = i;
303 else
304 break;
305 }
306
307 /* If the queue is used to store multiple subtitles streams (like with
308 * VobSub) and the stream index is not specified, we need to make sure
309 * to focus on the smallest file position offset for a same timestamp;
310 * queue is ordered by pts and then filepos, so we can take the first
311 * entry for a given timestamp. */
312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (stream_index == -1)
313 while (idx > 0 && q->subs[idx - 1]->pts == q->subs[idx]->pts)
314 idx--;
315
316 1 q->current_sub_idx = idx;
317 }
318 1 return 0;
319 }
320
321 41 void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
322 {
323 int i;
324
325
2/2
✓ Branch 0 taken 1704 times.
✓ Branch 1 taken 41 times.
1745 for (i = 0; i < q->nb_subs; i++)
326 1704 av_packet_free(&q->subs[i]);
327 41 av_freep(&q->subs);
328 41 q->nb_subs = q->allocated_size = q->current_sub_idx = 0;
329 41 }
330
331 1433 int ff_subtitles_read_packet(AVFormatContext *s, AVPacket *pkt)
332 {
333 1433 FFDemuxSubtitlesQueue *q = s->priv_data;
334 1433 return ff_subtitles_queue_read_packet(q, pkt);
335 }
336
337 1 int ff_subtitles_read_seek(AVFormatContext *s, int stream_index,
338 int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
339 {
340 1 FFDemuxSubtitlesQueue *q = s->priv_data;
341 1 return ff_subtitles_queue_seek(q, s, stream_index,
342 min_ts, ts, max_ts, flags);
343 }
344
345 31 int ff_subtitles_read_close(AVFormatContext *s)
346 {
347 31 FFDemuxSubtitlesQueue *q = s->priv_data;
348 31 ff_subtitles_queue_clean(q);
349 31 return 0;
350 }
351
352 1111 int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
353 {
354 1111 int i = 0;
355 char end_chr;
356
357
2/2
✓ Branch 0 taken 683 times.
✓ Branch 1 taken 428 times.
1111 if (!*c) // cached char?
358 683 *c = ff_text_r8(tr);
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1111 times.
1111 if (!*c)
360 return 0;
361
362
2/2
✓ Branch 0 taken 682 times.
✓ Branch 1 taken 429 times.
1111 end_chr = *c == '<' ? '>' : '<';
363 do {
364 14499 av_bprint_chars(buf, *c, 1);
365 14499 *c = ff_text_r8(tr);
366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14499 times.
14499 if (i == INT_MAX)
367 return AVERROR_INVALIDDATA;
368 14499 i++;
369
4/4
✓ Branch 0 taken 13389 times.
✓ Branch 1 taken 1110 times.
✓ Branch 2 taken 13388 times.
✓ Branch 3 taken 1 times.
14499 } while (*c != end_chr && *c);
370
2/2
✓ Branch 0 taken 682 times.
✓ Branch 1 taken 429 times.
1111 if (end_chr == '>') {
371 682 av_bprint_chars(buf, '>', 1);
372 682 *c = 0;
373 }
374
1/2
✓ Branch 1 taken 1111 times.
✗ Branch 2 not taken.
1111 return av_bprint_is_complete(buf) ? i : AVERROR(ENOMEM);
375 }
376
377 176 const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
378 {
379 176 int in_quotes = 0;
380 176 const size_t len = strlen(attr);
381
382
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 3 times.
185 while (*s) {
383
2/2
✓ Branch 0 taken 1142 times.
✓ Branch 1 taken 3 times.
1145 while (*s) {
384
4/4
✓ Branch 0 taken 1110 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 179 times.
✓ Branch 3 taken 931 times.
1142 if (!in_quotes && av_isspace(*s))
385 179 break;
386 963 in_quotes ^= *s == '"'; // XXX: support escaping?
387 963 s++;
388 }
389
2/2
✓ Branch 0 taken 179 times.
✓ Branch 1 taken 182 times.
361 while (av_isspace(*s))
390 179 s++;
391
3/4
✓ Branch 1 taken 173 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 173 times.
✗ Branch 4 not taken.
182 if (!av_strncasecmp(s, attr, len) && s[len] == '=')
392 173 return s + len + 1 + (s[len + 1] == '"');
393 }
394 3 return NULL;
395 }
396
397 5315 static inline int is_eol(char c)
398 {
399
4/4
✓ Branch 0 taken 5303 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 223 times.
✓ Branch 3 taken 5080 times.
5315 return c == '\r' || c == '\n';
400 }
401
402 73 int ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf)
403 {
404 73 char eol_buf[5], last_was_cr = 0;
405 73 int n = 0, i = 0, nb_eol = 0;
406
407 73 av_bprint_clear(buf);
408
409 5180 for (;;) {
410 5253 char c = ff_text_r8(tr);
411
412
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5245 times.
5253 if (!c)
413 8 break;
414
415 /* ignore all initial line breaks */
416
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 5175 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 70 times.
5245 if (n == 0 && is_eol(c))
417 continue;
418
419 /* line break buffering: we don't want to add the trailing \r\n */
420
2/2
✓ Branch 1 taken 235 times.
✓ Branch 2 taken 5010 times.
5245 if (is_eol(c)) {
421
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 223 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
235 nb_eol += c == '\n' || last_was_cr;
422
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 170 times.
235 if (nb_eol == 2)
423 65 break;
424 170 eol_buf[i++] = c;
425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 170 times.
170 if (i == sizeof(eol_buf) - 1)
426 break;
427 170 last_was_cr = c == '\r';
428 170 continue;
429 }
430
431 /* only one line break followed by data: we flush the line breaks
432 * buffer */
433
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 4921 times.
5010 if (i) {
434 89 eol_buf[i] = 0;
435 89 av_bprintf(buf, "%s", eol_buf);
436 89 i = nb_eol = 0;
437 }
438
439 5010 av_bprint_chars(buf, c, 1);
440 5010 n++;
441 }
442
1/2
✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
73 return av_bprint_is_complete(buf) ? 0 : AVERROR(ENOMEM);
443 }
444
445 73 int ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
446 {
447 FFTextReader tr;
448 73 tr.buf_pos = tr.buf_len = 0;
449 73 tr.type = 0;
450 73 tr.pb = pb;
451 73 return ff_subtitles_read_text_chunk(&tr, buf);
452 }
453
454 11512 ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
455 {
456 11512 size_t cur = 0;
457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11512 times.
11512 if (!size)
458 return 0;
459 11512 buf[0] = '\0';
460
2/2
✓ Branch 0 taken 218216 times.
✓ Branch 1 taken 235 times.
218451 while (cur + 1 < size) {
461 218216 unsigned char c = ff_text_r8(tr);
462
2/2
✓ Branch 0 taken 5694 times.
✓ Branch 1 taken 212522 times.
218216 if (!c)
463
2/2
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 5681 times.
5694 return ff_text_eof(tr) ? cur : AVERROR_INVALIDDATA;
464
4/4
✓ Branch 0 taken 207819 times.
✓ Branch 1 taken 4703 times.
✓ Branch 2 taken 206939 times.
✓ Branch 3 taken 880 times.
212522 if (c == '\r' || c == '\n')
465 break;
466 206939 buf[cur++] = c;
467 206939 buf[cur] = '\0';
468 }
469
2/2
✓ Branch 1 taken 2118 times.
✓ Branch 2 taken 5818 times.
7936 while (ff_text_peek_r8(tr) == '\r')
470 2118 ff_text_r8(tr);
471
2/2
✓ Branch 1 taken 4277 times.
✓ Branch 2 taken 1541 times.
5818 if (ff_text_peek_r8(tr) == '\n')
472 4277 ff_text_r8(tr);
473 5818 return cur;
474 }
475

什么都不放的冬瓜清汤 血糖高早饭吃什么最好 什么植物和动物像鸡 mt是什么 农历10月是什么月
勇敢地什么 心衰什么症状 智齿是什么牙 冰丝和天丝有什么区别 肌酐测定低是什么意思
攒局什么意思 金黄金黄的什么填空 长期喝豆浆有什么好处和坏处 风油精有什么作用 更年期看什么科
msgm是什么品牌 万事顺意是什么意思 cinderella是什么意思 魏丑夫和芈月什么关系 dlco是医学上什么意思
宽带m是什么意思onlinewuye.com 兔子吃什么hcv9jop2ns0r.cn 清白是什么意思hcv9jop6ns7r.cn 囊肿有什么症状hcv9jop4ns7r.cn 哈西奈德溶液治什么病hcv9jop0ns0r.cn
九层塔是什么菜hcv9jop1ns2r.cn 血脂高不能吃什么食物baiqunet.com 报考军校需要什么条件yanzhenzixun.com 植物油是什么油hcv8jop9ns8r.cn 甲亢与甲减有什么区别hcv7jop6ns6r.cn
国防部长什么级别hcv8jop6ns4r.cn 尿酸高是什么hcv8jop4ns0r.cn 梦见骨灰盒是什么征兆hcv9jop7ns5r.cn 萎缩性胃炎吃什么水果好wmyky.com 梦见打官司预示着什么hcv8jop4ns2r.cn
黄晓明和杨颖什么时候结婚的96micro.com 梦见小猪仔什么意思hcv8jop7ns7r.cn 盆底肌松弛有什么症状hcv9jop2ns3r.cn 痱子是什么hcv8jop3ns0r.cn 放疗和化疗有什么区别hcv8jop7ns2r.cn
百度