[libbluray-devel] bdmv extension data parsing

hpi1 git at videolan.org
Fri Aug 31 21:39:06 CEST 2012


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Aug 31 22:09:22 2012 +0300| [c90dfda72eeccbba43211102da58c79da3abce20] | committer: hpi1

bdmv extension data parsing

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

 src/Makefile.am                     |    2 ++
 src/libbluray/bdnav/extdata_parse.c |   65 +++++++++++++++++++++++++++++++++++
 src/libbluray/bdnav/extdata_parse.h |   33 ++++++++++++++++++
 3 files changed, 100 insertions(+)

diff --git a/src/Makefile.am b/src/Makefile.am
index 58d71c2..39d8a63 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,8 @@ libbluray_la_SOURCES=libbluray/bluray.h \
 	libbluray/bdnav/meta_data.h \
 	libbluray/bdnav/meta_parse.c \
 	libbluray/bdnav/meta_parse.h \
+	libbluray/bdnav/extdata_parse.h \
+	libbluray/bdnav/extdata_parse.c \
 	libbluray/bdnav/bdid_parse.h \
 	libbluray/bdnav/bdid_parse.c \
 	libbluray/decoders \
diff --git a/src/libbluray/bdnav/extdata_parse.c b/src/libbluray/bdnav/extdata_parse.c
new file mode 100644
index 0000000..9987108
--- /dev/null
+++ b/src/libbluray/bdnav/extdata_parse.c
@@ -0,0 +1,65 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2012  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/>.
+ */
+
+
+#include "util/bits.h"
+#include "extdata_parse.h"
+
+#include <stdint.h>
+
+int bdmv_parse_extension_data(BITSTREAM *bits,
+                              int start_address,
+                              int (*handler)(BITSTREAM*, int, int, void*),
+                              void *handle)
+{
+    off_t length;
+    int num_entries, n;
+
+    if (start_address < 1) return 0;
+    if (start_address > bits->end - 12) return 0;
+
+    bs_seek_byte(bits, start_address);
+
+    length      = bs_read(bits, 32); /* length of extension data block */
+    if (length < 1) return 0;
+    bs_skip(bits, 32); /* relative start address of extension data */
+    bs_skip(bits, 24); /* padding */
+    num_entries = bs_read(bits, 8);
+
+    if (start_address > bits->end - 12 - num_entries * 12) return 0;
+
+    for (n = 0; n < num_entries; n++) {
+        uint16_t id1       = bs_read(bits, 16);
+        uint16_t id2       = bs_read(bits, 16);
+        off_t    ext_start = bs_read(bits, 32);
+        off_t    ext_len   = bs_read(bits, 32);
+
+        off_t    saved_pos = bs_pos(bits) >> 3;
+
+        if (ext_start + start_address + ext_len > bits->end) return 0;
+
+        bs_seek_byte(bits, start_address + ext_start);
+
+        (handler)(bits, id1, id2, handle);
+
+        bs_seek_byte(bits, saved_pos);
+    }
+
+    return 1;
+}
diff --git a/src/libbluray/bdnav/extdata_parse.h b/src/libbluray/bdnav/extdata_parse.h
new file mode 100644
index 0000000..d4b7dde
--- /dev/null
+++ b/src/libbluray/bdnav/extdata_parse.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2012  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(_EXTDATA_PARSE_H_)
+#define _EXTDATA_PARSE_H_
+
+#include "util/attributes.h"
+#include "util/bits.h"
+
+#include <stdint.h>
+
+BD_PRIVATE int bdmv_parse_extension_data(BITSTREAM *bits,
+                                         int start_address,
+                                         int (*handler)(BITSTREAM*, int, int, void*),
+                                         void *handle);
+
+#endif // _EXTDATA_PARSE_H_



More information about the libbluray-devel mailing list