FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/vplayerdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 34 37 91.9%
Functions: 3 3 100.0%
Branches: 13 24 54.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2012 Clément Bœsch
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 /**
22 * @file
23 * VPlayer subtitles format demuxer
24 */
25
26 #include "avformat.h"
27 #include "demux.h"
28 #include "internal.h"
29 #include "subtitles.h"
30
31 typedef struct {
32 FFDemuxSubtitlesQueue q;
33 } VPlayerContext;
34
35 7186 static int vplayer_probe(const AVProbeData *p)
36 {
37 char c;
38 7186 const unsigned char *ptr = p->buf;
39
40
2/2
✓ Branch 0 taken 7185 times.
✓ Branch 1 taken 1 times.
7186 if ((sscanf(ptr, "%*3d:%*2d:%*2d.%*2d%c", &c) == 1 ||
41
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7185 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
7186 sscanf(ptr, "%*3d:%*2d:%*2d%c", &c) == 1) && strchr(": =", c))
42 1 return AVPROBE_SCORE_MAX;
43 7185 return 0;
44 }
45
46 3 static int64_t read_ts(char **line)
47 {
48 char c;
49 int hh, mm, ss, ms, n, len;
50
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (((n = sscanf(*line, "%d:%d:%d.%d%c%n", &hh, &mm, &ss, &ms, &c, &len)) >= 5 ||
52
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 (n = sscanf(*line, "%d:%d:%d%c%n", &hh, &mm, &ss, &c, &len)) >= 4) && strchr(": =", c)) {
53 3 *line += len;
54
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 return (hh*3600LL + mm*60LL + ss) * 100LL + (n < 5 ? 0 : ms);
55 }
56 return AV_NOPTS_VALUE;
57 }
58
59 1 static int vplayer_read_header(AVFormatContext *s)
60 {
61 1 VPlayerContext *vplayer = s->priv_data;
62 1 AVStream *st = avformat_new_stream(s, NULL);
63
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
65 return AVERROR(ENOMEM);
66 1 avpriv_set_pts_info(st, 64, 1, 100);
67 1 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
68 1 st->codecpar->codec_id = AV_CODEC_ID_VPLAYER;
69
70
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 while (!avio_feof(s->pb)) {
71 char line[4096];
72 4 char *p = line;
73 4 const int64_t pos = avio_tell(s->pb);
74 4 int len = ff_get_line(s->pb, line, sizeof(line));
75 int64_t pts_start;
76
77
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (!len)
78 1 break;
79
80 3 line[strcspn(line, "\r\n")] = 0;
81
82 3 pts_start = read_ts(&p);
83
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (pts_start != AV_NOPTS_VALUE) {
84 AVPacket *sub;
85
86 3 sub = ff_subtitles_queue_insert(&vplayer->q, p, strlen(p), 0);
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!sub)
88 return AVERROR(ENOMEM);
89 3 sub->pos = pos;
90 3 sub->pts = pts_start;
91 3 sub->duration = -1;
92 }
93 }
94
95 1 ff_subtitles_queue_finalize(s, &vplayer->q);
96 1 return 0;
97 }
98
99 const FFInputFormat ff_vplayer_demuxer = {
100 .p.name = "vplayer",
101 .p.long_name = NULL_IF_CONFIG_SMALL("VPlayer subtitles"),
102 .p.extensions = "txt",
103 .priv_data_size = sizeof(VPlayerContext),
104 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
105 .read_probe = vplayer_probe,
106 .read_header = vplayer_read_header,
107 .read_packet = ff_subtitles_read_packet,
108 .read_seek2 = ff_subtitles_read_seek,
109 .read_close = ff_subtitles_read_close,
110 };
111