FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dvd_nav_parser.c
Date: 2026-01-14 03:33:33
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 2 2 100.0%
Branches: 18 23 78.3%

Line Branch Exec Source
1 /*
2 * DVD navigation block parser for FFmpeg
3 * Copyright (c) 2013 The FFmpeg Project
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 "avcodec.h"
23 #include "parser_internal.h"
24 #include "libavutil/intreadwrite.h"
25
26 #define PCI_SIZE 980
27 #define DSI_SIZE 1018
28
29 /* parser definition */
30 typedef struct DVDNavParseContext {
31 uint32_t lba;
32 uint8_t buffer[PCI_SIZE+DSI_SIZE];
33 int copied;
34 } DVDNavParseContext;
35
36 3 static av_cold int dvd_nav_parse_init(AVCodecParserContext *s)
37 {
38 3 DVDNavParseContext *pc = s->priv_data;
39
40 3 pc->lba = 0xFFFFFFFF;
41 3 pc->copied = 0;
42 3 return 0;
43 }
44
45 23 static int dvd_nav_parse(AVCodecParserContext *s,
46 AVCodecContext *avctx,
47 const uint8_t **poutbuf, int *poutbuf_size,
48 const uint8_t *buf, int buf_size)
49 {
50 23 DVDNavParseContext *pc1 = s->priv_data;
51 23 int lastPacket = 0;
52 23 int valid = 0;
53
54 23 s->pict_type = AV_PICTURE_TYPE_NONE;
55
56 23 avctx->time_base.num = 1;
57 23 avctx->time_base.den = 90000;
58
59
3/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1 times.
23 if (buf && buf_size) {
60
2/3
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
22 switch(buf[0]) {
61 21 case 0x00:
62
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 10 times.
21 if (buf_size == PCI_SIZE) {
63 /* PCI */
64 11 uint32_t lba = AV_RB32(&buf[0x01]);
65 11 uint32_t startpts = AV_RB32(&buf[0x0D]);
66 11 uint32_t endpts = AV_RB32(&buf[0x11]);
67
68
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (endpts > startpts) {
69 1 pc1->lba = lba;
70 1 s->pts = (int64_t)startpts;
71 1 s->duration = endpts - startpts;
72
73 1 memcpy(pc1->buffer, buf, PCI_SIZE);
74 1 pc1->copied = PCI_SIZE;
75 1 valid = 1;
76 }
77 }
78 21 break;
79
80 1 case 0x01:
81
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if ((buf_size == DSI_SIZE) && (pc1->copied == PCI_SIZE)) {
82 /* DSI */
83 1 uint32_t lba = AV_RB32(&buf[0x05]);
84
85
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (lba == pc1->lba) {
86 1 memcpy(pc1->buffer + pc1->copied, buf, DSI_SIZE);
87 1 lastPacket = 1;
88 1 valid = 1;
89 }
90 }
91 1 break;
92 }
93 }
94
95
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
23 if (!valid || lastPacket) {
96 22 pc1->copied = 0;
97 22 pc1->lba = 0xFFFFFFFF;
98 }
99
100
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 22 times.
23 if (lastPacket) {
101 1 *poutbuf = pc1->buffer;
102 1 *poutbuf_size = sizeof(pc1->buffer);
103 } else {
104 22 *poutbuf = NULL;
105 22 *poutbuf_size = 0;
106 }
107
108 23 return buf_size;
109 }
110
111 const FFCodecParser ff_dvd_nav_parser = {
112 PARSER_CODEC_LIST(AV_CODEC_ID_DVD_NAV),
113 .priv_data_size = sizeof(DVDNavParseContext),
114 .init = dvd_nav_parse_init,
115 .parse = dvd_nav_parse,
116 };
117