Blame src/devtools/bdj_test.c

Packit 5e46da
/*
Packit 5e46da
 * This file is part of libbluray
Packit 5e46da
 * Copyright (C) 2010  William Hahne
Packit 5e46da
 * Copyright (C) 2011-2017  Petri Hintukainen <phintuka@users.sourceforge.net>
Packit 5e46da
 *
Packit 5e46da
 * This program is free software; you can redistribute it and/or
Packit 5e46da
 * modify it under the terms of the GNU General Public License
Packit 5e46da
 * as published by the Free Software Foundation; either version 2
Packit 5e46da
 * of the License, or (at your option) any later version.
Packit 5e46da
 *
Packit 5e46da
 * This program is distributed in the hope that it will be useful,
Packit 5e46da
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5e46da
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 5e46da
 * GNU General Public License for more details.
Packit 5e46da
 *
Packit 5e46da
 * You should have received a copy of the GNU General Public License
Packit 5e46da
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 5e46da
 *
Packit 5e46da
 * In addition, as a special exception, the copyright holders of libbluray
Packit 5e46da
 * gives permission to link the code of its release of libbluray with the
Packit 5e46da
 * OpenSSL project's "OpenSSL" library (or with modified versions of it
Packit 5e46da
 * that use the same license as the "OpenSSL" library), and distribute
Packit 5e46da
 * the linked executables.  You must obey the GNU General Public License
Packit 5e46da
 * in all respects for all of the code used other than "OpenSSL".  If you
Packit 5e46da
 * modify this file, you may extend this exception to your version of the
Packit 5e46da
 * file, but you are not obligated to do so.  If you do not wish to do
Packit 5e46da
 * so, delete this exception statement from your version.
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
#include <stdio.h>
Packit 5e46da
#include <stdlib.h>
Packit 5e46da
#include <unistd.h>
Packit 5e46da
#include <assert.h>
Packit 5e46da
Packit 5e46da
#include "bluray.h"
Packit 5e46da
Packit 5e46da
#if defined(_WIN32)
Packit 5e46da
#include <windows.h>
Packit 5e46da
#define sleep(x) Sleep(x)
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
static void _usage(void) {
Packit 5e46da
    printf("Usage: [path to disc] [starting object]\n");
Packit 5e46da
}
Packit 5e46da
Packit 5e46da
int main(int argc, char** argv)
Packit 5e46da
{
Packit 5e46da
    int major, minor, micro;
Packit 5e46da
    const BLURAY_DISC_INFO *di;
Packit 5e46da
    BLURAY *bd;
Packit 5e46da
Packit 5e46da
    bd_get_version(&major, &minor, µ);
Packit 5e46da
    printf("Using libbluray version %d.%d.%d\n", major, minor, micro);
Packit 5e46da
Packit 5e46da
    if (argc < 3) {
Packit 5e46da
        _usage();
Packit 5e46da
        return 0;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    printf("Strating BD-J object %s from %s\n", argv[2], argv[1]);
Packit 5e46da
Packit 5e46da
    bd = bd_init();
Packit 5e46da
    if (!bd) {
Packit 5e46da
        return -1;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    /* disable persistent storage */
Packit 5e46da
    bd_set_player_setting(bd, BLURAY_PLAYER_SETTING_PERSISTENT_STORAGE, 0);
Packit 5e46da
Packit 5e46da
    /* initialize event queue */
Packit 5e46da
    bd_get_event(bd, NULL);
Packit 5e46da
Packit 5e46da
    /* check BD-J config */
Packit 5e46da
Packit 5e46da
    di = bd_get_disc_info(bd);
Packit 5e46da
    assert(di != NULL);
Packit 5e46da
Packit 5e46da
    if (!di->libjvm_detected) {
Packit 5e46da
        fprintf(stderr, "JVM not found\n");
Packit 5e46da
        goto fail;
Packit 5e46da
    }
Packit 5e46da
    if (!di->bdj_handled) {
Packit 5e46da
        fprintf(stderr, "libbluray.jar not found\n");
Packit 5e46da
        goto fail;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    /* open disc */
Packit 5e46da
Packit 5e46da
    if (!bd_open_disc(bd, argv[1], NULL)) {
Packit 5e46da
      fprintf(stderr, "bd_open_disc() failed\n");
Packit 5e46da
      return -1;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    bd_get_titles(bd, TITLES_ALL, 0);
Packit 5e46da
Packit 5e46da
    if (!bd_start_bdj(bd, argv[2])) {
Packit 5e46da
        printf("Failed to start BD-J application.\n");
Packit 5e46da
        goto fail;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    while (1) {
Packit 5e46da
        BD_EVENT ev;
Packit 5e46da
        while (bd_get_event(bd, &ev)) {
Packit 5e46da
        }
Packit 5e46da
        sleep(20);
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    bd_stop_bdj(bd);
Packit 5e46da
    bd_close(bd);
Packit 5e46da
Packit 5e46da
    return 0;
Packit 5e46da
Packit 5e46da
 fail:
Packit 5e46da
    bd_close(bd);
Packit 5e46da
    return -1;
Packit 5e46da
}