女人脸肿是什么原因引起的| 天德是什么意思| 血蛋白低是什么原因| 孩子咬手指甲是什么原因| 女人胯骨疼是什么原因| 8月29日什么星座| 亦或是什么意思| 什么情况下会流前列腺液| 富察氏是什么旗| 知否知否应是绿肥红瘦什么意思| 羊蝎子是什么肉| 不完全性右束支阻滞是什么意思| 为什么来月经会头疼| 双顶径是什么意思| 农历六月六是什么节日| 车仔面为什么叫车仔面| 鼻涕倒流吃什么药效果好| 性生活后尿路感染是什么原因| 晚上7点到9点是什么时辰| 喝什么养胃| 右腹疼是什么原因| 八月二十六是什么星座| 舌头发紫是什么原因| 反流性食管炎b级是什么意思| 女生适合做什么工作| 七一年属什么| 精神小伙什么意思| 鼻屎多是什么原因| 腰上有痣代表什么| 阎王爷姓什么| 血稠吃什么食物好得快| 梦见开车是什么意思| 绿壳鸡蛋是什么鸡生的| 开车穿什么鞋最好| 换床有什么讲究| 嚼槟榔为什么上瘾| 强扭的瓜不甜什么意思| 做b超憋尿要憋到什么程度| 无药可救是什么意思| 一龙一什么填十二生肖| 阴囊湿疹用什么药膏效果最好| 服化道什么意思| 槊是什么意思| 肠胃紊乱吃什么药| 湿疹用什么药膏| 六亲不认是什么生肖| 放任是什么意思| 铁锚是什么意思| 7月13日是什么节日| 守岁是什么意思| 维生素ad和维生素d有什么区别| 头发没有光泽是什么原因| 减肥吃什么肉类| 敖是什么意思| 为什么会长痘痘| 胆固醇高吃什么食物好| 做肉丸用什么淀粉最佳| 映景是什么意思| 梦见狗咬我是什么意思| 尿频尿急用什么药| 友友是什么意思| 紫色和蓝色混合是什么颜色| 头痒用什么东西洗头最好| 三班倒是什么意思| 丑拒是什么意思| 为什么不建议打卧蚕呢| 胃痉挛是什么| 大便黑色什么原因| 胆碱酯酶偏高说明什么| 枸杞泡茶有什么功效| 台甫是什么意思| 去胎毒吃什么最好| 七夕节什么时候| 胃反酸吃点什么能缓解| ad是补什么的| 直接胆红素是什么| beryl是什么意思| 苦瓜干泡水喝有什么功效| 鼠的守护神是什么菩萨| 什么时候血压最高| 肾不好会出现什么症状| 骨髓捐赠对自己有什么影响没有| 摩西摩西是什么意思| 上海月薪三万什么水平| 2001属什么| 胃溃疡吃什么水果| 杨梅有什么好处| 发际线是什么| 巴宝莉是什么牌子| 火字旁跟什么有关| 什么是肠痉挛| 早泄吃什么药| 什么的糯米| 口疮是什么原因引起的| 月经喝酒有什么影响| 扎马步有什么好处| 量贩式ktv是什么意思| 自勉是什么意思| sheep什么意思| 嘴苦口臭是什么原因造成的| 夜黑风高什么意思| 扁桃体发炎吃什么药好得快| 佝偻病是什么意思| 3f是什么意思| 病史是什么意思| 做梦梦见牛是什么意思| romantic什么意思| 胸前出汗多是什么原因| 铁皮石斛有什么作用| 9月12是什么星座| 生理期肚子疼吃什么药| 双侧卵巢多囊样改变是什么意思| 为什么肚子越来越大| 六六无穷是什么意思| 痔疮的克星是什么| 嘴唇上火起泡是什么原因| 阳春三月指什么生肖| 乙基麦芽酚是什么东西| 皮疹用什么药| 忠于自己是什么意思| 满目苍夷是什么意思| 破釜沉舟是什么生肖| 子宫囊肿是什么原因引起的| 怀孕一个星期有什么症状| 生物科学是什么专业| 一直不来月经是什么原因| 乳头瘤病毒是什么病| 什么是零重力座椅| 脑梗的人适合吃什么食物| 肝阳虚吃什么中成药| 美丽的邂逅是什么意思| 东京热是什么| 美的e3是什么故障| aurora是什么牌子| 求购是什么意思| 手掌横纹代表什么意思| 高血糖喝什么茶好| 白细胞3个加号是什么意思| 日加个立念什么| 谁的尾巴有什么作用| 吃了螃蟹不能吃什么| 什么时候最容易受孕| 坐北朝南是什么意思| 吃什么食物快速降糖| 什么动物是站着睡觉的| 健脾去湿吃什么药| 耳鸣是什么原因引起的| 廷字五行属什么| mpa什么意思| amy什么意思| 农历是什么生肖| 黄体功能不全是什么意思| 泌尿系统感染吃什么消炎药| 7月17号是什么星座| 女生考什么证书最实用| 脸上发麻是什么原因| 孕晚期缺铁对胎儿有什么影响| 2009年是什么生肖年| 生育酚是什么| 夏天哈尔滨有什么好玩的地方| 用什么方法可以戒酒| 晚上睡觉睡不着是什么原因| 师范类是什么意思| 爱新觉罗是什么民族| 血液是什么组织| 流浪猫吃什么| 内急是什么意思| 理性是什么意思| 大便失禁是什么原因造成的| 梦见被熊追是什么意思| 人绒毛膜促性腺激素是查什么的| 什么是流水| 学生吃什么补脑子增强记忆力最快| 大饼脸适合什么发型| 雪松香是什么味道| 抑郁到什么程度要吃氟西汀| 使用年限是什么意思| 广州立冬吃什么| 什么是g点| 熠字五行属什么| 嘴发酸是什么原因引起| crc是什么职业| 慎重是什么意思| 十九朵玫瑰花代表什么意思| 舌苔白腻是什么原因| 口腔溃疡长什么样| 综合内科是看什么病| 精神障碍是什么病| 什么症状需要做肠镜| 马太效应是什么意思| 舌苔发白厚吃什么药| 黄柏的功效与作用是什么| 缺钙吃什么补得最快| 中国第一个不平等条约是什么| 聚精会神的看是什么词语| 圆脸适合什么短发| 抗生素是什么意思| 九头身什么意思| 浅蓝色裙子配什么颜色上衣好看| 枫叶的花语是什么| 1928年属什么生肖| 胃热是什么原因| 换手率什么意思| 战狼三什么时候上映| 男生下体痒是什么原因| 拿手机手抖是什么原因| 房产税什么时候开始征收| 9.21是什么星座| 红皮鸡蛋和白皮鸡蛋有什么区别| 香菇和什么不能一起吃| 红景天是什么| 今年什么时候进入伏天| allin什么意思| 心境情感障碍是什么病| 如来佛祖叫什么名字| 肉碱是什么| 什么是薪级工资| 孕酮低什么原因造成的| 伴侣是什么意思| 脚麻是什么原因造成的| 舅舅的孙子叫我什么| 土加亥念什么| 梦见好多羊是什么意思| 杜建英是宗庆后什么人| 于是什么意思| 补充蛋白质吃什么食物| 取环后月经量少是什么原因| 学生早餐吃什么方便又营养| 大红袍适合什么季节喝| 清创是什么意思| 湫是什么意思| girls是什么意思| 日语为什么| 五月11号是什么星座| 嗓子疼喝什么茶最有效| 乳头瘤病毒是什么病| 猪八戒的武器叫什么| 芃字五行属什么| 什么是肿瘤| 背部毛孔粗大是什么原因| 什么食物含维生素k最多| 隐翅虫长什么样| 雷尼替丁主要治什么胃病| 鹅梨帐中香是什么| 10周年结婚是什么婚| 明前茶和明后茶有什么区别| 易举易泄是什么原因| 丹凤朝阳什么意思| 原生家庭什么意思| 牙龈肿痛吃什么药好得快| 肌肉紧张是什么症状| 梦见吃水饺是什么预兆| 一起共勉是什么意思| 水乳是什么| 今年25岁属什么生肖的| 5.3什么星座| 绛紫色是什么颜色| 股票roe是什么意思| 火葬场是什么生肖| 耳鸣是什么原因| 连长是什么级别| 感染艾滋病有什么症状| 丹参滴丸和丹参片有什么区别| 什么是力量训练| 百度

长沙回收名牌包包 回收MichaelKors迈克科尔斯包包


Directory: ../../../ffmpeg/
File: src/libavformat/cafdec.c
Date: 2025-08-05 11:35:17
Exec Total Coverage
Lines: 173 299 57.9%
Functions: 7 8 87.5%
Branches: 99 217 45.6%

Line Branch Exec Source
1 /*
2 * Core Audio Format demuxer
3 * Copyright (c) 2007 Justin Ruggles
4 * Copyright (c) 2009 Peter Ross
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Core Audio Format demuxer
26 */
27
28 #include <inttypes.h>
29
30 #include "avformat.h"
31 #include "demux.h"
32 #include "internal.h"
33 #include "isom.h"
34 #include "mov_chan.h"
35 #include "libavcodec/flac.h"
36 #include "libavutil/intreadwrite.h"
37 #include "libavutil/intfloat.h"
38 #include "libavutil/dict.h"
39 #include "libavutil/mem.h"
40 #include "caf.h"
41
42 typedef struct CafContext {
43 int bytes_per_packet; ///< bytes in a packet, or 0 if variable
44 int frames_per_packet; ///< frames in a packet, or 0 if variable
45 int64_t num_bytes; ///< total number of bytes in stream
46
47 int64_t packet_cnt; ///< packet counter
48 int64_t frame_cnt; ///< frame counter
49
50 int64_t data_start; ///< data start position, in bytes
51 int64_t data_size; ///< raw data size, in bytes
52 } CafContext;
53
54 7252 static int probe(const AVProbeData *p)
55 {
56
2/2
✓ Branch 0 taken 7243 times.
✓ Branch 1 taken 9 times.
7252 if (AV_RB32(p->buf) != MKBETAG('c','a','f','f'))
57 7243 return 0;
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (AV_RB16(&p->buf[4]) != 1)
59 return 0;
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (AV_RB32(p->buf + 8) != MKBETAG('d','e','s','c'))
61 return 0;
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (AV_RB64(p->buf + 12) != 32)
63 return 0;
64 9 return AVPROBE_SCORE_MAX;
65 }
66
67 /** Read audio description chunk */
68 9 static int read_desc_chunk(AVFormatContext *s)
69 {
70 9 AVIOContext *pb = s->pb;
71 9 CafContext *caf = s->priv_data;
72 AVStream *st;
73 int flags;
74
75 /* new audio stream */
76 9 st = avformat_new_stream(s, NULL);
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!st)
78 return AVERROR(ENOMEM);
79
80 /* parse format description */
81 9 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
82 9 st->codecpar->sample_rate = av_clipd(av_int2double(avio_rb64(pb)), 0, INT_MAX);
83 9 st->codecpar->codec_tag = avio_rl32(pb);
84 9 flags = avio_rb32(pb);
85 9 caf->bytes_per_packet = avio_rb32(pb);
86 9 st->codecpar->block_align = caf->bytes_per_packet;
87 9 caf->frames_per_packet = avio_rb32(pb);
88 9 st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
89 9 st->codecpar->bits_per_coded_sample = avio_rb32(pb);
90
91
3/6
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
9 if (caf->bytes_per_packet < 0 || caf->frames_per_packet < 0 || st->codecpar->ch_layout.nb_channels < 0)
92 return AVERROR_INVALIDDATA;
93
94 /* calculate bit rate for constant size packets */
95
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 3 times.
9 if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) {
96 6 st->codecpar->bit_rate = (uint64_t)st->codecpar->sample_rate * (uint64_t)caf->bytes_per_packet * 8
97 6 / (uint64_t)caf->frames_per_packet;
98 } else {
99 3 st->codecpar->bit_rate = 0;
100 }
101
102 /* determine codec */
103
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
9 if (st->codecpar->codec_tag == MKTAG('l','p','c','m'))
104 4 st->codecpar->codec_id = ff_mov_get_lpcm_codec_id(st->codecpar->bits_per_coded_sample, (flags ^ 0x2) | 0x4);
105 else
106 5 st->codecpar->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codecpar->codec_tag);
107 9 return 0;
108 }
109
110 /** Read magic cookie chunk */
111 4 static int read_kuki_chunk(AVFormatContext *s, int64_t size)
112 {
113 4 AVIOContext *pb = s->pb;
114 4 AVStream *st = s->streams[0];
115 int ret;
116
117
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
118 return -1;
119
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
121 /* The magic cookie format for AAC is an mp4 esds atom.
122 The lavc AAC decoder requires the data from the codec specific
123 description as extradata input. */
124 int strt, skip;
125
126 strt = avio_tell(pb);
127 ff_mov_read_esds(s, pb);
128 skip = size - (avio_tell(pb) - strt);
129 if (skip < 0 || !st->codecpar->extradata ||
130 st->codecpar->codec_id != AV_CODEC_ID_AAC) {
131 av_log(s, AV_LOG_ERROR, "invalid AAC magic cookie\n");
132 return AVERROR_INVALIDDATA;
133 }
134 avio_skip(pb, skip);
135
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 } else if (st->codecpar->codec_id == AV_CODEC_ID_ALAC) {
136 #define ALAC_PREAMBLE 12
137 #define ALAC_HEADER 36
138 #define ALAC_NEW_KUKI 24
139 uint8_t preamble[12];
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (size < ALAC_NEW_KUKI) {
141 av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n");
142 avio_skip(pb, size);
143 return AVERROR_INVALIDDATA;
144 }
145
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (avio_read(pb, preamble, ALAC_PREAMBLE) != ALAC_PREAMBLE) {
146 av_log(s, AV_LOG_ERROR, "failed to read preamble\n");
147 return AVERROR_INVALIDDATA;
148 }
149
150
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if ((ret = ff_alloc_extradata(st->codecpar, ALAC_HEADER)) < 0)
151 return ret;
152
153 /* For the old style cookie, we skip 12 bytes, then read 36 bytes.
154 * The new style cookie only contains the last 24 bytes of what was
155 * 36 bytes in the old style cookie, so we fabricate the first 12 bytes
156 * in that case to maintain compatibility. */
157
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!memcmp(&preamble[4], "frmaalac", 8)) {
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (size < ALAC_PREAMBLE + ALAC_HEADER) {
159 av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n");
160 av_freep(&st->codecpar->extradata);
161 return AVERROR_INVALIDDATA;
162 }
163
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (avio_read(pb, st->codecpar->extradata, ALAC_HEADER) != ALAC_HEADER) {
164 av_log(s, AV_LOG_ERROR, "failed to read kuki header\n");
165 av_freep(&st->codecpar->extradata);
166 return AVERROR_INVALIDDATA;
167 }
168 2 avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER);
169 } else {
170 AV_WB32(st->codecpar->extradata, 36);
171 memcpy(&st->codecpar->extradata[4], "alac", 4);
172 AV_WB32(&st->codecpar->extradata[8], 0);
173 memcpy(&st->codecpar->extradata[12], preamble, 12);
174 if (avio_read(pb, &st->codecpar->extradata[24], ALAC_NEW_KUKI - 12) != ALAC_NEW_KUKI - 12) {
175 av_log(s, AV_LOG_ERROR, "failed to read new kuki header\n");
176 av_freep(&st->codecpar->extradata);
177 return AVERROR_INVALIDDATA;
178 }
179 avio_skip(pb, size - ALAC_NEW_KUKI);
180 }
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
182 int last, type, flac_metadata_size;
183 uint8_t buf[4];
184 /* The magic cookie format for FLAC consists mostly of an mp4 dfLa atom. */
185 if (size < (16 + FLAC_STREAMINFO_SIZE)) {
186 av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
187 return AVERROR_INVALIDDATA;
188 }
189 /* Check cookie version. */
190 if (avio_r8(pb) != 0) {
191 av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n");
192 return AVERROR_INVALIDDATA;
193 }
194 avio_rb24(pb); /* Flags */
195 /* read dfLa fourcc */
196 if (avio_read(pb, buf, 4) != 4) {
197 av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n");
198 return pb->error < 0 ? pb->error : AVERROR_INVALIDDATA;
199 }
200 if (memcmp(buf, "dfLa", 4)) {
201 av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
202 return AVERROR_INVALIDDATA;
203 }
204 /* Check dfLa version. */
205 if (avio_r8(pb) != 0) {
206 av_log(s, AV_LOG_ERROR, "unknown dfLa version\n");
207 return AVERROR_INVALIDDATA;
208 }
209 avio_rb24(pb); /* Flags */
210 if (avio_read(pb, buf, sizeof(buf)) != sizeof(buf)) {
211 av_log(s, AV_LOG_ERROR, "failed to read FLAC metadata block header\n");
212 return pb->error < 0 ? pb->error : AVERROR_INVALIDDATA;
213 }
214 flac_parse_block_header(buf, &last, &type, &flac_metadata_size);
215 if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != FLAC_STREAMINFO_SIZE) {
216 av_log(s, AV_LOG_ERROR, "STREAMINFO must be first FLACMetadataBlock\n");
217 return AVERROR_INVALIDDATA;
218 }
219 ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE);
220 if (ret < 0)
221 return ret;
222 if (!last)
223 av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) ignored\n");
224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
225 // The data layout for Opus is currently unknown, so we do not export
226 // extradata at all. Multichannel streams are not supported.
227 if (st->codecpar->ch_layout.nb_channels > 2) {
228 avpriv_request_sample(s, "multichannel Opus in CAF");
229 return AVERROR_PATCHWELCOME;
230 }
231 avio_skip(pb, size);
232
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 } else if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0) {
233 return ret;
234 }
235
236 4 return 0;
237 }
238
239 /** Read packet table chunk */
240 3 static int read_pakt_chunk(AVFormatContext *s, int64_t size)
241 {
242 3 AVIOContext *pb = s->pb;
243 3 AVStream *st = s->streams[0];
244 3 CafContext *caf = s->priv_data;
245 3 int64_t pos = 0, ccount, num_packets;
246 int i;
247 int ret;
248
249 3 ccount = avio_tell(pb);
250
251 3 num_packets = avio_rb64(pb);
252
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (num_packets < 0 || INT32_MAX / sizeof(AVIndexEntry) < num_packets)
253 return AVERROR_INVALIDDATA;
254
255 3 st->nb_frames = avio_rb64(pb); /* valid frames */
256 3 st->nb_frames += avio_rb32(pb); /* priming frames */
257 3 st->nb_frames += avio_rb32(pb); /* remainder frames */
258
259
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
260 st->duration = caf->frames_per_packet * num_packets;
261 pos = caf-> bytes_per_packet * num_packets;
262 } else {
263 3 st->duration = 0;
264
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 3 times.
543 for (i = 0; i < num_packets; i++) {
265
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 540 times.
540 if (avio_feof(pb))
266 return AVERROR_INVALIDDATA;
267 540 ret = av_add_index_entry(s->streams[0], pos, st->duration, 0, 0, AVINDEX_KEYFRAME);
268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 540 times.
540 if (ret < 0)
269 return ret;
270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 540 times.
540 pos += caf->bytes_per_packet ? caf->bytes_per_packet : ff_mp4_read_descr_len(pb);
271
1/2
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
540 st->duration += caf->frames_per_packet ? caf->frames_per_packet : ff_mp4_read_descr_len(pb);
272 }
273 }
274
275
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 if (avio_tell(pb) - ccount > size || size > INT64_MAX - ccount) {
276 av_log(s, AV_LOG_ERROR, "error reading packet table\n");
277 return AVERROR_INVALIDDATA;
278 }
279 3 avio_seek(pb, ccount + size, SEEK_SET);
280
281 3 caf->num_bytes = pos;
282 3 return 0;
283 }
284
285 /** Read information chunk */
286 3 static void read_info_chunk(AVFormatContext *s, int64_t size)
287 {
288 3 AVIOContext *pb = s->pb;
289 unsigned int i;
290 3 unsigned int nb_entries = avio_rb32(pb);
291
3/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
30 for (i = 0; i < nb_entries && !avio_feof(pb); i++) {
292 char key[32];
293 char value[1024];
294 27 avio_get_str(pb, INT_MAX, key, sizeof(key));
295 27 avio_get_str(pb, INT_MAX, value, sizeof(value));
296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (!*key)
297 continue;
298 27 av_dict_set(&s->metadata, key, value, 0);
299 }
300 3 }
301
302 9 static int read_header(AVFormatContext *s)
303 {
304 9 AVIOContext *pb = s->pb;
305 9 CafContext *caf = s->priv_data;
306 AVStream *st;
307 9 uint32_t tag = 0;
308 int found_data, ret;
309 int64_t size, pos;
310
311 9 avio_skip(pb, 8); /* magic, version, file flags */
312
313 /* audio description chunk */
314
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (avio_rb32(pb) != MKBETAG('d','e','s','c')) {
315 av_log(s, AV_LOG_ERROR, "desc chunk not present\n");
316 return AVERROR_INVALIDDATA;
317 }
318 9 size = avio_rb64(pb);
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (size != 32)
320 return AVERROR_INVALIDDATA;
321
322 9 ret = read_desc_chunk(s);
323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret)
324 return ret;
325 9 st = s->streams[0];
326
327 /* parse each chunk */
328 9 found_data = 0;
329
1/2
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
37 while (!avio_feof(pb)) {
330
331 /* stop at data chunk if seeking is not supported or
332 data chunk size is unknown */
333
4/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
37 if (found_data && (caf->data_size < 0 || !(pb->seekable & AVIO_SEEKABLE_NORMAL)))
334 break;
335
336 37 tag = avio_rb32(pb);
337 37 size = avio_rb64(pb);
338 37 pos = avio_tell(pb);
339
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 28 times.
37 if (avio_feof(pb))
340 9 break;
341
342
6/7
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
28 switch (tag) {
343 9 case MKBETAG('d','a','t','a'):
344 9 avio_skip(pb, 4); /* edit count */
345 9 caf->data_start = avio_tell(pb);
346
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 caf->data_size = size < 0 ? -1 : size - 4;
347
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (caf->data_start < 0 || caf->data_size > INT64_MAX - caf->data_start)
348 return AVERROR_INVALIDDATA;
349
350
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if (caf->data_size > 0 && (pb->seekable & AVIO_SEEKABLE_NORMAL))
351 9 avio_skip(pb, caf->data_size);
352 9 found_data = 1;
353 9 break;
354
355 8 case MKBETAG('c','h','a','n'):
356
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if ((ret = ff_mov_read_chan(s, s->pb, st, size)) < 0)
357 return ret;
358 8 break;
359
360 /* magic cookie chunk */
361 4 case MKBETAG('k','u','k','i'):
362
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (read_kuki_chunk(s, size))
363 return AVERROR_INVALIDDATA;
364 4 break;
365
366 /* packet table chunk */
367 3 case MKBETAG('p','a','k','t'):
368
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (read_pakt_chunk(s, size))
369 return AVERROR_INVALIDDATA;
370 3 break;
371
372 3 case MKBETAG('i','n','f','o'):
373 3 read_info_chunk(s, size);
374 3 break;
375
376 default:
377 av_log(s, AV_LOG_WARNING,
378 "skipping CAF chunk: %08"PRIX32" (%s), size %"PRId64"\n",
379 tag, av_fourcc2str(av_bswap32(tag)), size);
380 1 case MKBETAG('f','r','e','e'):
381
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if (size < 0 && found_data)
382 goto found_data;
383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (size < 0)
384 return AVERROR_INVALIDDATA;
385 1 break;
386 }
387
388
2/4
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
28 if (size > 0 && (pb->seekable & AVIO_SEEKABLE_NORMAL)) {
389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (pos > INT64_MAX - size)
390 return AVERROR_INVALIDDATA;
391 28 avio_seek(pb, pos + size, SEEK_SET);
392 }
393 }
394
395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!found_data)
396 return AVERROR_INVALIDDATA;
397
398 9 found_data:
399
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
9 if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
400
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (caf->data_size > 0 && caf->data_size / caf->bytes_per_packet < INT64_MAX / caf->frames_per_packet)
401 6 st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
402
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 } else if (ffstream(st)->nb_index_entries && st->duration > 0) {
403
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) {
404 av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n",
405 st->codecpar->sample_rate, caf->data_size / st->duration);
406 return AVERROR_INVALIDDATA;
407 }
408 3 st->codecpar->bit_rate = st->codecpar->sample_rate * 8LL *
409 3 (caf->data_size / st->duration);
410 } else {
411 av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when "
412 "block size or frame size are variable.\n");
413 return AVERROR_INVALIDDATA;
414 }
415
416 9 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
417 9 st->start_time = 0;
418
419 /* position the stream at the start of data */
420
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (caf->data_size >= 0)
421 9 avio_seek(pb, caf->data_start, SEEK_SET);
422
423 9 return 0;
424 }
425
426 #define CAF_MAX_PKT_SIZE 4096
427
428 125 static int read_packet(AVFormatContext *s, AVPacket *pkt)
429 {
430 125 AVIOContext *pb = s->pb;
431 125 AVStream *st = s->streams[0];
432 125 FFStream *const sti = ffstream(st);
433 125 CafContext *caf = s->priv_data;
434 125 int res, pkt_size = 0, pkt_frames = 0;
435 125 int64_t left = CAF_MAX_PKT_SIZE;
436
437
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 125 times.
125 if (avio_feof(pb))
438 return AVERROR_EOF;
439
440 /* don't read past end of data chunk */
441
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 if (caf->data_size > 0) {
442 125 left = (caf->data_start + caf->data_size) - avio_tell(pb);
443
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 123 times.
125 if (!left)
444 2 return AVERROR_EOF;
445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 123 times.
123 if (left < 0)
446 return AVERROR(EIO);
447 }
448
449 123 pkt_frames = caf->frames_per_packet;
450 123 pkt_size = caf->bytes_per_packet;
451
452
4/4
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 23 times.
123 if (pkt_size > 0 && pkt_frames == 1) {
453 71 pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size;
454 71 pkt_size = FFMIN(pkt_size, left);
455 71 pkt_frames = pkt_size / caf->bytes_per_packet;
456
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 23 times.
52 } else if (sti->nb_index_entries) {
457
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (caf->packet_cnt < sti->nb_index_entries - 1) {
458 29 pkt_size = sti->index_entries[caf->packet_cnt + 1].pos - sti->index_entries[caf->packet_cnt].pos;
459 29 pkt_frames = sti->index_entries[caf->packet_cnt + 1].timestamp - sti->index_entries[caf->packet_cnt].timestamp;
460 } else if (caf->packet_cnt == sti->nb_index_entries - 1) {
461 pkt_size = caf->num_bytes - sti->index_entries[caf->packet_cnt].pos;
462 pkt_frames = st->duration - sti->index_entries[caf->packet_cnt].timestamp;
463 } else {
464 return AVERROR(EIO);
465 }
466 }
467
468
3/6
✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 123 times.
123 if (pkt_size == 0 || pkt_frames == 0 || pkt_size > left)
469 return AVERROR(EIO);
470
471 123 res = av_get_packet(pb, pkt, pkt_size);
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 123 times.
123 if (res < 0)
473 return res;
474
475 123 pkt->size = res;
476 123 pkt->stream_index = 0;
477 123 pkt->dts = pkt->pts = caf->frame_cnt;
478
479 123 caf->packet_cnt++;
480 123 caf->frame_cnt += pkt_frames;
481
482 123 return 0;
483 }
484
485 static int read_seek(AVFormatContext *s, int stream_index,
486 int64_t timestamp, int flags)
487 {
488 AVStream *st = s->streams[0];
489 FFStream *const sti = ffstream(st);
490 CafContext *caf = s->priv_data;
491 int64_t pos, packet_cnt, frame_cnt;
492
493 timestamp = FFMAX(timestamp, 0);
494
495 if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) {
496 /* calculate new byte position based on target frame position */
497 pos = caf->bytes_per_packet * (timestamp / caf->frames_per_packet);
498 if (caf->data_size > 0)
499 pos = FFMIN(pos, caf->data_size);
500 packet_cnt = pos / caf->bytes_per_packet;
501 frame_cnt = caf->frames_per_packet * packet_cnt;
502 } else if (sti->nb_index_entries) {
503 packet_cnt = av_index_search_timestamp(st, timestamp, flags);
504 frame_cnt = sti->index_entries[packet_cnt].timestamp;
505 pos = sti->index_entries[packet_cnt].pos;
506 } else {
507 return -1;
508 }
509
510 if (avio_seek(s->pb, pos + caf->data_start, SEEK_SET) < 0)
511 return -1;
512
513 caf->packet_cnt = packet_cnt;
514 caf->frame_cnt = frame_cnt;
515
516 return 0;
517 }
518
519 const FFInputFormat ff_caf_demuxer = {
520 .p.name = "caf",
521 .p.long_name = NULL_IF_CONFIG_SMALL("Apple CAF (Core Audio Format)"),
522 .p.codec_tag = ff_caf_codec_tags_list,
523 .priv_data_size = sizeof(CafContext),
524 .read_probe = probe,
525 .read_header = read_header,
526 .read_packet = read_packet,
527 .read_seek = read_seek,
528 };
529

鼠标cpi是什么意思 落红的血是什么样子的 局级干部是什么级别 四件套包括什么 咽喉炎吃什么药管用
眼色是什么意思 孕妇吃什么鱼 肺结节吃什么药 咽颊炎吃什么药 梦见砍竹子是什么意思
包皮嵌顿是什么 睡觉被口水呛醒是什么原因 女人的排卵期是什么时候 女性排卵有什么症状或感觉 卜卜脆是什么意思
no.是什么意思 买什么保险最好最划算 项羽姓什么 阿胶是什么做的 大便不正常是什么原因造成的
成也萧何败也萧何什么意思hcv8jop7ns0r.cn 彩色相片什么时候出现96micro.com 什么叫佛hcv8jop6ns5r.cn 云仓是什么hcv8jop7ns3r.cn 点灯是什么意思hcv7jop4ns8r.cn
例假期间吃什么食物好hcv7jop7ns2r.cn fourone是什么牌子luyiluode.com 尿素测定是查什么hcv9jop0ns5r.cn 在什么什么前面hcv7jop5ns3r.cn 十字架代表什么意思hcv9jop0ns4r.cn
拉肚子可以喝什么饮料hcv9jop7ns5r.cn 中焦不通吃什么药jingluanji.com 河粉为什么叫河粉hcv8jop9ns6r.cn 巨石强森是什么人种hcv8jop4ns3r.cn 昆仑雪菊有什么作用hcv8jop0ns3r.cn
暴龙眼镜什么档次hcv9jop4ns4r.cn 什么样的水果hcv7jop7ns0r.cn 伛偻是什么意思luyiluode.com 看见蛇过马路什么征兆hcv8jop8ns2r.cn 舌头有问题看什么科hcv8jop1ns3r.cn
百度