2 * DVD navigation block parser for FFmpeg
3 * Copyright (c) 2013 The FFmpeg Project
5 * This file is part of FFmpeg.
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.
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.
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
28 /* parser definition */
29 typedef struct DVDNavParseContext
{
31 uint8_t buffer
[PCI_SIZE
+DSI_SIZE
];
35 static av_cold
int dvd_nav_parse_init(AVCodecParserContext
*s
)
37 DVDNavParseContext
*pc
= s
->priv_data
;
44 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
)
49 DVDNavParseContext
*pc1
= s
->priv_data
;
53 s
->pict_type
= AV_PICTURE_TYPE_NONE
;
55 avctx
->time_base
.num
= 1;
56 avctx
->time_base
.den
= 90000;
58 if (buf
&& buf_size
) {
61 if (buf_size
== PCI_SIZE
) {
63 uint32_t lba
= AV_RB32(&buf
[0x01]);
64 uint32_t startpts
= AV_RB32(&buf
[0x0D]);
65 uint32_t endpts
= AV_RB32(&buf
[0x11]);
67 if (endpts
> startpts
) {
69 s
->pts
= (int64_t)startpts
;
70 s
->duration
= endpts
- startpts
;
72 memcpy(pc1
->buffer
, buf
, PCI_SIZE
);
73 pc1
->copied
= PCI_SIZE
;
80 if ((buf_size
== DSI_SIZE
) && (pc1
->copied
== PCI_SIZE
)) {
82 uint32_t lba
= AV_RB32(&buf
[0x05]);
84 if (lba
== pc1
->lba
) {
85 memcpy(pc1
->buffer
+ pc1
->copied
, buf
, DSI_SIZE
);
94 if (!valid
|| lastPacket
) {
96 pc1
->lba
= 0xFFFFFFFF;
100 *poutbuf
= pc1
->buffer
;
101 *poutbuf_size
= sizeof(pc1
->buffer
);
110 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
,