FFmpeg coverage


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