FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/luodatdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 5 61 8.2%
Functions: 1 3 33.3%
Branches: 3 30 10.0%

Line Branch Exec Source
1 /*
2 * CCTV DAT demuxer
3 *
4 * Copyright (c) 2020 Paul B Mahol
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 #include "libavutil/intreadwrite.h"
24 #include "avio_internal.h"
25 #include "avformat.h"
26 #include "demux.h"
27 #include "internal.h"
28
29 7186 static int dat_probe(const AVProbeData *p)
30 {
31
2/2
✓ Branch 0 taken 4715 times.
✓ Branch 1 taken 2471 times.
7186 if (p->buf_size < 0x2080)
32 4715 return 0;
33
34
1/2
✓ Branch 0 taken 2471 times.
✗ Branch 1 not taken.
2471 if (memcmp(p->buf, "luo ", 4))
35 2471 return 0;
36
37 if (memcmp(p->buf + 0x1ffc, " oulliu ", 8))
38 return 0;
39
40 if (!AV_RL32(p->buf + 0x2004))
41 return 0;
42
43 if (memcmp(p->buf + 0x207c, " uil", 4))
44 return 0;
45
46 return AVPROBE_SCORE_MAX;
47 }
48
49 static int dat_read_header(AVFormatContext *s)
50 {
51 s->ctx_flags |= AVFMTCTX_NOHEADER;
52
53 avio_seek(s->pb, 0x2000, SEEK_SET);
54
55 return 0;
56 }
57
58 static int dat_read_packet(AVFormatContext *s, AVPacket *pkt)
59 {
60 AVIOContext *pb = s->pb;
61 int index, ret, key, stream_id, stream_index, width, height, fps, pkt_size;
62 int64_t pts, pos = avio_tell(pb);
63
64 if (avio_feof(pb))
65 return AVERROR_EOF;
66
67 if (avio_rb32(pb) != MKBETAG('l', 'i', 'u', ' '))
68 return AVERROR_INVALIDDATA;
69 stream_id = avio_rl32(pb);
70 width = avio_rl32(pb);
71 height = avio_rl32(pb);
72 fps = avio_rl32(pb);
73 avio_skip(pb, 16);
74 key = avio_rl32(pb) == 1;
75 avio_skip(pb, 4);
76 index = avio_rl32(pb);
77 avio_skip(pb, 4);
78 pts = avio_rl64(pb);
79 pkt_size = avio_rl32(pb);
80 avio_skip(pb, 64);
81
82 if (pkt_size == 0)
83 return AVERROR_EOF;
84
85 for (stream_index = 0; stream_index < s->nb_streams; stream_index++) {
86 if (s->streams[stream_index]->id == stream_id)
87 break;
88 }
89
90 if (stream_index == s->nb_streams) {
91 AVStream *st = avformat_new_stream(s, NULL);
92
93 if (!st)
94 return AVERROR(ENOMEM);
95
96 st->id = stream_id;
97 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
98 st->codecpar->codec_id = AV_CODEC_ID_H264;
99 st->codecpar->width = width;
100 st->codecpar->height = height;
101 avpriv_set_pts_info(st, 64, 1, fps);
102 }
103
104 if (index >= s->nb_streams)
105 av_log(s, AV_LOG_WARNING, "Stream index out of range.\n");
106
107 ret = av_get_packet(pb, pkt, pkt_size);
108 if (ret < 0)
109 return ret;
110 pkt->pos = pos;
111 pkt->pts = pts;
112 pkt->stream_index = stream_index;
113 if (key)
114 pkt->flags |= AV_PKT_FLAG_KEY;
115
116 return ret;
117 }
118
119 const FFInputFormat ff_luodat_demuxer = {
120 .p.name = "luodat",
121 .p.long_name = NULL_IF_CONFIG_SMALL("Video CCTV DAT"),
122 .p.extensions = "dat",
123 .p.flags = AVFMT_GENERIC_INDEX,
124 .read_probe = dat_probe,
125 .read_header = dat_read_header,
126 .read_packet = dat_read_packet,
127 };
128