Commit 62d22ff9 authored by Will07c5's avatar Will07c5

Inital commit for BDJ. Currently will load and execute BDJ programs but

they will not work until some necessary functionality is implemented.
Also modified bb_seek in src/util/bits.h since it was seeking
incorrectly. The build system was updated, although BDJ is turned off by
default and must be enabled with --enable-bdjava. Ant is currently
needed for building the java files but this should hopefully be changed
to using autotools at some point in the future.
parent 30d043bd
......@@ -2,6 +2,7 @@
AC_INIT([libbluray],[0.1], [http://bd.videolan.org/])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE([foreign])
AM_CONFIG_HEADER(config.h)
......@@ -18,6 +19,12 @@ AC_ARG_WITH([dlopen],
[use_dlopen=$withval],
[use_dlopen=auto])
AC_ARG_WITH([java],
[AS_HELP_STRING([--with-java],
[set the path to the java home (use if $JAVA_HOME is not set)])],
[with_java=$withval],
[])
AC_ARG_ENABLE([werror],
[AS_HELP_STRING([--enable-werror],
[set warnings as errors via -Werror (default is no)])],
......@@ -42,6 +49,12 @@ AC_ARG_ENABLE([debug],
[use_debug=$enableval],
[use_debug=yes])
AC_ARG_ENABLE([bdjava],
[AS_HELP_STRING([--enable-bdjava],
[enable BD-Java support (default is no)])],
[use_bdjava=$enableval],
[use_bdjava=no])
# required programs
AC_PROG_CC
AC_PROG_LIBTOOL
......@@ -150,6 +163,48 @@ if [[ $use_debug = "yes" ]]; then
SET_DEBUG_OPTS="$SET_DEBUG_OPTS -g"
fi
# use bdjava
if [[ $use_bdjava = "yes" ]]; then
if [[ -z $with_java ]]; then
if [[ -z $JAVA_HOME ]]; then
AC_MSG_ERROR([ No JAVA_HOME and --with-java not set. ])
else
java_path=$JAVA_HOME
fi
else
java_path=$with_java
fi
case $target_cpu in
x86_64) java_arch=amd64 ;;
i?86) java_arch=i386 ;;
*) java_arch=$target_cpu ;;
esac
case $target_os in
linux*) java_os=linux ;;
win*) java_os=win32 ;;
*) java_os=$target_os ;;
esac
BDJAVA_CFLAGS="-I$java_path/include -I$java_path/include/$java_os"
BDJAVA_LDFLAGS="-L$java_path/jre/lib/$java_arch -L$java_path/jre/lib/$java_arch/server"
temp_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$BDJAVA_CFLAGS $CPPFLAGS"
AC_CHECK_HEADERS([jni.h], [], [AC_MSG_ERROR("Coudln't find jni.h")])
CPPFLAGS=$temp_CPPFLAGS
temp_LDFLAGS=$LDFLAGS
LDFLAGS="$BDJAVA_LDFLAGS $LDFLAGS"
AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [], [AC_MSG_ERROR("Coudn't find jvm library.")])
LDFLAGS=$temp_LDFLAGS
AC_DEFINE([USING_BDJAVA], [1], ["Define to 1 if using BD-Java"])
AC_SUBST(BDJAVA_CFLAGS)
AC_SUBST(BDJAVA_LDFLAGS)
fi
AM_CONDITIONAL([USING_BDJAVA], [ test $use_bdjava = "yes" ])
# generate output files
AC_SUBST(DLOPEN_LDFLAGS)
AC_SUBST(SET_WARNINGS)
......
......@@ -23,6 +23,12 @@ DLOPEN_SOURCES=file/dl.h \
file/dl_posix.c
endif
SOURCES_bdj = libbluray/bdj/bdj.h \
libbluray/bdj/bdj.c \
libbluray/bdj/bdjo_parser.h \
libbluray/bdj/bdjo_parser.c \
libbluray/bdj/common.h
lib_LTLIBRARIES=libbluray.la
libbluray_ladir= $(includedir)/libbluray
libbluray_la_SOURCES=libbluray/bluray.h \
......@@ -60,5 +66,14 @@ libbluray_la_SOURCES=libbluray/bluray.h \
libbluray_la_HEADERS= libbluray/bluray.h
libbluray_la_LDFLAGS= -version-info $(LIB_VERSION_INFO) $(LIBBLURAY_LDFLAGS)
if USING_BDJAVA
libbluray_la_SOURCES+=$(SOURCES_bdj)
libbluray_la_LDFLAGS+=@BDJAVA_LDFLAGS@
AM_CFLAGS+=@BDJAVA_CFLAGS@
all-local:
ant -f libbluray/bdj/build.xml
endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libbluray.pc
......@@ -52,3 +52,9 @@ list_titles_SOURCES = \
list_titles.c
list_titles_LDADD = $(BLURAY_LIB)
if USING_BDJAVA
noinst_PROGRAMS+= bdj_test
bdj_test_SOURCES = bdj_test.c
bdj_test_LDADD = $(BLURAY_LIB)
endif
/*
* This file is part of libbluray
* Copyright (C) 2010 William Hahne
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders of libbluray
* gives permission to link the code of its release of libbluray with the
* OpenSSL project's "OpenSSL" library (or with modified versions of it
* that use the same license as the "OpenSSL" library), and distribute
* the linked executables. You must obey the GNU General Public License
* in all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of the
* file, but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version.
*/
#include <stdio.h>
#include <stdlib.h>
#include "libbluray/bluray.h"
void usage(void) {
printf("Usage: [path to disc] [starting object]\n");
}
int main(int argc, char** argv) {
printf("%s %s", argv[1], argv[2]);
if (argc < 3) {
usage();
return 0;
}
BLURAY* bd = bd_open(argv[1], NULL);
if (bd_start_bdj(bd, argv[2]))
printf("Failed to start BD-J application.\n");
else
bd_stop_bdj(bd);
return 0;
}
/*
* This file is part of libbluray
* Copyright (C) 2010 William Hahne
*
* 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.s
*
* 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 "bdj.h"
#include "bdjo_parser.h"
#include "common.h"
#include <jni.h>
#include <stdlib.h>
#include <string.h>
int start_xlet(JNIEnv* env, BDJO_APP_INFO* info);
BDJAVA* bdj_open(const char *path, const char* start)
{
BDJAVA* bdjava = malloc(sizeof(BDJAVA));
bdjava->start = malloc(strlen(start) + 1);
bdjava->path = malloc(strlen(path) + 1);
strcpy(bdjava->start, start);
strcpy(bdjava->path, path);
// determine path of bdjo file to load
char* bdjo_path = malloc(strlen(path) + strlen(BDJ_BDJO_PATH) + strlen(start) + 7);
sprintf(bdjo_path, "%s%s/%s.bdjo", path, BDJ_BDJO_PATH, start);
BDJO* bdjo = bdjo_read(bdjo_path);
free(bdjo_path);
if (bdjo != NULL && bdjo->app_info_count > 0) {
// for now just pick the first application in the bdjo
BDJO_APP_INFO app_info = bdjo->app_info_entries[0];
JavaVMInitArgs args;
// check if overriding the classpath
const char* classpath = getenv("LIBBLURAY_CP");
if (strlen(classpath) == 0)
classpath = BDJ_CLASSPATH;
// determine classpath
char* classpath_opt = malloc(strlen(path)*2 + strlen(BDJ_BDJO_PATH) +
strlen(app_info.base_directory) + strlen(BDJ_JAR_PATH) +
strlen(app_info.classpath_extension) + strlen(classpath) + 30);
sprintf(classpath_opt, "-Djava.class.path=%s:%s%s/%s.jar:%s%s%s.jar", classpath, path, BDJ_JAR_PATH,
app_info.base_directory, path, BDJ_JAR_PATH, app_info.classpath_extension);
JavaVMOption* option = malloc(sizeof(JavaVMOption)*1);
option[0].optionString = classpath_opt;
args.version = JNI_VERSION_1_6;
args.nOptions = 1;
args.options = option;
args.ignoreUnrecognized = JNI_FALSE; // don't ignore unrecognized options
int result = JNI_CreateJavaVM((JavaVM**)&bdjava->jvm, &bdjava->env, &args);
free(option);
free(classpath_opt);
if (result != JNI_OK || start_xlet(bdjava->env, &app_info) == BDJ_ERROR) {
goto error;
}
return bdjava;
}
error:
free(bdjava->path);
free(bdjava->start);
free(bdjava);
return NULL;
}
void bdj_close(BDJAVA *bdjava)
{
JNIEnv* env = bdjava->env;
JavaVM* jvm = bdjava->jvm;
jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
jmethodID shutdown_id = (*env)->GetStaticMethodID(env, init_class, "Shutdown", "()V");
(*env)->CallStaticVoidMethod(env, init_class, shutdown_id);
(*jvm)->DestroyJavaVM(jvm);
free(bdjava->path);
free(bdjava->start);
}
int start_xlet(JNIEnv* env, BDJO_APP_INFO* info)
{
jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
if (init_class == NULL) {
(*env)->ExceptionDescribe(env);
return BDJ_ERROR;
}
jmethodID load_id = (*env)->GetStaticMethodID(env, init_class, "Load", "(Ljava/lang/String;[Ljava/lang/String;)V");
if (load_id == NULL) {
(*env)->ExceptionDescribe(env);
return BDJ_ERROR;
}
jstring param_init_class = (*env)->NewStringUTF(env, info->initial_class);
jclass str_class = (*env)->FindClass(env, "java/lang/String");
jobjectArray param_params = (*env)->NewObjectArray(env, info->param_count, str_class, NULL);
int i;
for (i = 0; i < info->param_count; i++) {
jstring value = (*env)->NewStringUTF(env, info->params[i]);
(*env)->SetObjectArrayElement(env, param_params, i, value);
}
(*env)->CallStaticVoidMethod(env, init_class, load_id, param_init_class, param_params);
return BDJ_SUCCESS;
}
/*
* This file is part of libbluray
* Copyright (C) 2010 William Hahne
*
* 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/>.
*/
#ifndef BDJ_H_
#define BDJ_H_
#include "common.h"
typedef struct {
char *path;
char *start;
// JNI
void *jvm;
void *env;
} BDJAVA;
BDJAVA* bdj_open(const char *path, const char *start);
void bdj_close(BDJAVA *bdjava);
#endif
/*
* This file is part of libbluray
* Copyright (C) 2010 William Hahne
*
* 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 "bdjo_parser.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util/bits.h"
/* Documentation: HD Cookbook
* https://hdcookbook.dev.java.net/
*/
int get_version(const uint8_t* str)
{
if (strcmp((const char*) str, "0100") != 0)
return 100;
else if (strcmp((const char*) str, "0200") != 0)
return 200;
else
return BDJ_ERROR;
}
// use when string is already allocated, out should be length + 1
void get_string(BITBUFFER* buf, char* out, uint32_t length)
{
bb_read_bytes(buf, (uint8_t*)out, length);
out[length] = 0; // add null termination
}
void make_string(BITBUFFER* buf, char** out, uint32_t length)
{
*out = malloc(length + 1);
bb_read_bytes(buf, (uint8_t*)*out, length);
(*out)[length] = 0; // add null termination
}
int parse_terminal_info(BITBUFFER* buf, BDJO_TERMINAL_INFO* info)
{
// skip length specifier
bb_seek(buf, 32, SEEK_CUR);