[libbluray-devel] Factorize bdmv file header and version check to bdmv_parse_header()

hpi1 git at videolan.org
Wed Aug 30 09:07:37 CEST 2017


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Aug 30 09:55:22 2017 +0300| [ecd27d3300d9d1533140174dfdae54553d2b6686] | committer: hpi1

Factorize bdmv file header and version check to bdmv_parse_header()

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=ecd27d3300d9d1533140174dfdae54553d2b6686
---

 Makefile.am                      |  2 ++
 src/libbluray/bdnav/bdmv_parse.c | 75 ++++++++++++++++++++++++++++++++++++++++
 src/libbluray/bdnav/bdmv_parse.h | 34 ++++++++++++++++++
 3 files changed, 111 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 33813b07..1a410d08 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,6 +57,8 @@ libbluray_la_SOURCES = \
 	src/libbluray/register.c \
 	src/libbluray/bdnav/bdid_parse.h \
 	src/libbluray/bdnav/bdid_parse.c \
+	src/libbluray/bdnav/bdmv_parse.h \
+	src/libbluray/bdnav/bdmv_parse.c \
 	src/libbluray/bdnav/bdparse.h \
 	src/libbluray/bdnav/clpi_parse.c \
 	src/libbluray/bdnav/clpi_parse.h \
diff --git a/src/libbluray/bdnav/bdmv_parse.c b/src/libbluray/bdnav/bdmv_parse.c
new file mode 100644
index 00000000..e298ca3b
--- /dev/null
+++ b/src/libbluray/bdnav/bdmv_parse.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2017  Petri Hintukainen <phintuka at users.sourceforge.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "bdmv_parse.h"
+
+#include "util/bits.h"
+#include "util/logging.h"
+
+#include <stdint.h>
+
+
+#define U32CHARS(u) (char)((u) >> 24), (char)((u) >> 16), (char)((u) >> 8), (char)(u)
+
+int bdmv_parse_header(BITSTREAM *bs, uint32_t type, uint32_t *version)
+{
+    uint32_t tag, ver;
+
+    if (bs_seek_byte(bs, 0) < 0) {
+        BD_DEBUG(DBG_NAV | DBG_CRIT, "bdmv_parse_header(%c%c%c%c): seek failed\n", U32CHARS(type));
+        return 0;
+    }
+
+    /* read and verify magic bytes and version code */
+
+    if (bs_avail(bs)/8 < 8) {
+        BD_DEBUG(DBG_NAV | DBG_CRIT, "bdmv_parse_header(%c%c%c%c): unexpected EOF\n", U32CHARS(type));
+        return 0;
+    }
+
+    tag = bs_read(bs, 32);
+    ver = bs_read(bs, 32);
+
+    if (tag != type) {
+        BD_DEBUG(DBG_NAV | DBG_CRIT, "bdmv_parse_header(%c%c%c%c): invalid signature %c%c%c%c\n",
+                 U32CHARS(type), U32CHARS(tag));
+        return 0;
+    }
+
+    switch (ver) {
+        case BDMV_VERSION_0100:
+        case BDMV_VERSION_0200:
+        case BDMV_VERSION_0300:
+            break;
+        default:
+            BD_DEBUG(DBG_NAV | DBG_CRIT, "bdmv_parse_header(%c%c%c%c): unsupported file version %c%c%c%c\n",
+                     U32CHARS(type), U32CHARS(ver));
+            return 0;
+    }
+
+    if (version) {
+        *version = ver;
+    }
+
+    return 1;
+}
diff --git a/src/libbluray/bdnav/bdmv_parse.h b/src/libbluray/bdnav/bdmv_parse.h
new file mode 100644
index 00000000..8f953a3d
--- /dev/null
+++ b/src/libbluray/bdnav/bdmv_parse.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2017  Petri Hintukainen <phintuka at users.sourceforge.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined(_BDMV_PARSE_H_)
+#define _BDMV_PARSE_H_
+
+#include "util/attributes.h"
+#include "util/bits.h"
+
+#include <stdint.h>
+
+#define BDMV_VERSION_0100 ('0' << 24 | '1' << 16 | '0' << 8 | '0')
+#define BDMV_VERSION_0200 ('0' << 24 | '2' << 16 | '0' << 8 | '0')
+#define BDMV_VERSION_0300 ('0' << 24 | '3' << 16 | '0' << 8 | '0')
+
+BD_PRIVATE int bdmv_parse_header(BITSTREAM *bs, uint32_t type, uint32_t *version);
+
+#endif // _BDMV_PARSE_H_



More information about the libbluray-devel mailing list