FFmpeg coverage


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