FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/cdg.c
Date: 2024-02-29 09:57:37
Exec Total Coverage
Lines: 29 31 93.5%
Functions: 3 3 100.0%
Branches: 17 20 85.0%

Line Branch Exec Source
1 /*
2 * CD Graphics Demuxer
3 * Copyright (c) 2009 Michael Tison
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 "avformat.h"
23 #include "internal.h"
24
25 #define CDG_PACKET_SIZE 24
26 #define CDG_COMMAND 0x09
27 #define CDG_MASK 0x3F
28
29 7056 static int read_probe(const AVProbeData *p)
30 {
31 7056 const int cnt = p->buf_size / CDG_PACKET_SIZE;
32 7056 int score = 0;
33
34
2/2
✓ Branch 0 taken 86275 times.
✓ Branch 1 taken 23 times.
86298 for (int i = 0; i < cnt; i++) {
35 86275 const int x = p->buf[i * CDG_PACKET_SIZE] & CDG_MASK;
36
37 86275 score += x == CDG_COMMAND;
38
4/4
✓ Branch 0 taken 86118 times.
✓ Branch 1 taken 157 times.
✓ Branch 2 taken 7033 times.
✓ Branch 3 taken 79085 times.
86275 if (x != CDG_COMMAND && x != 0)
39 7033 return 0;
40 }
41
42 23 return FFMIN(score, AVPROBE_SCORE_MAX);
43 }
44
45 1 static int read_header(AVFormatContext *s)
46 {
47 AVStream *vst;
48 int ret;
49
50 1 vst = avformat_new_stream(s, NULL);
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!vst)
52 return AVERROR(ENOMEM);
53
54 1 vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
55 1 vst->codecpar->codec_id = AV_CODEC_ID_CDGRAPHICS;
56
57 /// 75 sectors/sec * 4 packets/sector = 300 packets/sec
58 1 avpriv_set_pts_info(vst, 32, 1, 300);
59
60 1 ret = avio_size(s->pb);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
62 av_log(s, AV_LOG_WARNING, "Cannot calculate duration as file size cannot be determined\n");
63 } else
64 1 vst->duration = (ret * (int64_t)vst->time_base.den) / (CDG_PACKET_SIZE * 300);
65
66 1 return 0;
67 }
68
69 324 static int read_packet(AVFormatContext *s, AVPacket *pkt)
70 {
71 int ret;
72
73 324 ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
74 324 pkt->stream_index = 0;
75 324 pkt->dts=
76 324 pkt->pts= pkt->pos / CDG_PACKET_SIZE;
77
78
3/4
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
324 if (!pkt->pos || (ret > 5 &&
79
2/2
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 96 times.
323 (pkt->data[0] & CDG_MASK) == CDG_COMMAND &&
80
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 211 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 15 times.
227 (pkt->data[1] & CDG_MASK) == 1 && !(pkt->data[2+2+1] & 0x0F))) {
81 2 pkt->flags = AV_PKT_FLAG_KEY;
82 }
83 324 return ret;
84 }
85
86 const AVInputFormat ff_cdg_demuxer = {
87 .name = "cdg",
88 .long_name = NULL_IF_CONFIG_SMALL("CD Graphics"),
89 .read_probe = read_probe,
90 .read_header = read_header,
91 .read_packet = read_packet,
92 .flags = AVFMT_GENERIC_INDEX,
93 .extensions = "cdg",
94 };
95