FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/pcm.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 25 30 83.3%
Functions: 2 2 100.0%
Branches: 13 20 65.0%

Line Branch Exec Source
1 /*
2 * PCM common functions
3 * Copyright (c) 2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/mathematics.h"
23 #include "avformat.h"
24 #include "internal.h"
25 #include "pcm.h"
26
27 #define RAW_SAMPLES 1024
28
29 5668 int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
30 {
31 5668 AVCodecParameters *par = s->streams[0]->codecpar;
32 int ret, size;
33
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5668 times.
5668 if (par->block_align <= 0)
35 return AVERROR(EINVAL);
36
37 /*
38 * Compute read size to complete a read every 62ms.
39 * Clamp to RAW_SAMPLES if larger.
40 */
41
1/2
✓ Branch 0 taken 5668 times.
✗ Branch 1 not taken.
5668 size = FFMAX(par->sample_rate/25, 1);
42
1/2
✓ Branch 0 taken 5668 times.
✗ Branch 1 not taken.
5668 if (par->block_align <= INT_MAX / RAW_SAMPLES) {
43 5668 size = FFMIN(size, RAW_SAMPLES) * par->block_align;
44 } else {
45 size = par->block_align;
46 }
47
48 5668 ret = av_get_packet(s->pb, pkt, size);
49
50 5668 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
51 5668 pkt->stream_index = 0;
52
53 5668 return ret;
54 }
55
56 616 int ff_pcm_read_seek(AVFormatContext *s,
57 int stream_index, int64_t timestamp, int flags)
58 {
59 AVStream *st;
60 int block_align, byte_rate;
61 int64_t pos, ret;
62
63 616 st = s->streams[0];
64
65
1/2
✓ Branch 0 taken 616 times.
✗ Branch 1 not taken.
616 block_align = st->codecpar->block_align ? st->codecpar->block_align :
66 (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->ch_layout.nb_channels) >> 3;
67
1/2
✓ Branch 0 taken 616 times.
✗ Branch 1 not taken.
616 byte_rate = st->codecpar->bit_rate ? st->codecpar->bit_rate >> 3 :
68 block_align * st->codecpar->sample_rate;
69
70
2/4
✓ Branch 0 taken 616 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 616 times.
616 if (block_align <= 0 || byte_rate <= 0)
71 return -1;
72
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 432 times.
616 if (timestamp < 0) timestamp = 0;
73
74 /* compute the position by aligning it to block_align */
75 616 pos = av_rescale_rnd(timestamp * byte_rate,
76 616 st->time_base.num,
77 616 st->time_base.den * (int64_t)block_align,
78
2/2
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 299 times.
616 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
79 616 pos *= block_align;
80
81 /* recompute exact position */
82 616 ffstream(st)->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
83
2/2
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 602 times.
616 if ((ret = avio_seek(s->pb, pos + ffformatcontext(s)->data_offset, SEEK_SET)) < 0)
84 14 return ret;
85 602 return 0;
86 }
87