Exemplo n.º 1
0
JNIEXPORT jlong JNICALL Java_com_ssb_droidsound_plugins_SC68Plugin_N_1load(JNIEnv *env, jobject obj, jbyteArray bArray, jint size)
{

	sc68_init_t init68;
	
	memset(&init68, 0, sizeof(init68));

	char * argv[1];
	argv[0] = "sc68";
	
	init68.msg_handler = (sc68_msg_t)write_debug;
	init68.debug_set_mask = -1;
	init68.argc = 1;
	init68.argv = argv;
	
	
	if (sc68_init(&init68) != 0) {
		__android_log_print(ANDROID_LOG_VERBOSE, "SC68Plugin", "Init failed");
		return 0;
	}
	__android_log_print(ANDROID_LOG_VERBOSE, "SC68Plugin", "Init Passed");
	/* Init resets all paths */
	//rsc68_set_share(data_dir);
	rsc68_set_user(data_dir);


    sc68_t *sc68 = sc68_create(NULL);
    if (! sc68) {
        __android_log_print(ANDROID_LOG_VERBOSE, "SC68Plugin", "Create failed");
        return 0;
    }


	int alen = env->GetArrayLength(bArray);
	if (size > alen) {
		__android_log_print(ANDROID_LOG_VERBOSE, "SC68Plugin", "Rejected song input, out of bounds");
		return 0;
	}

	jbyte *ptr = env->GetByteArrayElements(bArray, NULL);
	int res = sc68_load_mem(sc68, ptr, size);
	env->ReleaseByteArrayElements(bArray, ptr, 0);
	
	if (res)
	{
		__android_log_print(ANDROID_LOG_VERBOSE, "SC68Plugin", "Rejected song input, load_mem failed");
		sc68_destroy(sc68);
		sc68_shutdown();
		return 0;
	}
    
	PlayData *pd = (PlayData*)malloc(sizeof(PlayData));
    pd->sc68 = sc68;
    
	pd->finished = false;
	return (long) pd;
}
Exemplo n.º 2
0
int file68_init(int argc, char **argv)
{
  char tmp[1024];
  option68_t * opt;

  if (init) {
    const int i = init & 3;
    const char *message[4] = {
      "clean","initialized","shutdowning","initializing"
    };
    error68("file68: init error -- *%s*", message[i]);
    argc = -1;
    goto out_no_init;
  }
  init = 3;

  /* Options */
  option68_init();

  /* Zlib */
  istream68_z_init();

  /* Curl */
  istream68_curl_init();

  /* Xiph AO */
  istream68_ao_init();

  /* Init resource */
  rsc68_init();

  /* Loader */
  file68_loader_init();

  option68_append(opts,sizeof(opts)/sizeof(*opts));
  argc = option68_parse(argc, argv, 1);

  /* Check for --sc68-no-debug */
  opt = option68_get("no-debug", 1);
  if (opt && opt->val.num) {
    /* Remove all debug messages whatsoever. */
    msg68_set_handler(0);
  }

  /* Check for --sc68-asid=off|safe|force */
  if (opt = option68_get("asid",1), opt) {
    if (!strcmp68(opt->val.str,"no"))
      aSIDify = 0;
    else if (!strcmp68(opt->val.str,"safe"))
      aSIDify = 1;
    else if (!strcmp68(opt->val.str,"force"))
      aSIDify = 2;
    else
      msg68_notice("file68: ignore invalid mode for --sc68-asid -- *%s*\n", opt->val.str);
  }

  /* Check for --sc68-debug= */

  /* postpone: at this point most debug features have not been created
     yet. it is pretty much useless to set the mask right now. It will
     be done after all inits.
  */
#if 0
  opt = option68_get("debug", 1);
  if (op) {
    debugmsg68_mask = opt->val.num;
  }
#endif

  /* Get share path from registry */
  opt = option68_get("data", 0);
  if (opt) {

    /* Get data path from registry */
    if (!option68_isset(opt)) {
      char * e;
      const char path[] = "Resources";
      e = get_reg_path(registry68_rootkey(REGISTRY68_LMK),
                       "SOFTWARE/sashipa/sc68/Install_Dir",
                       tmp, sizeof(tmp));
      if (e && (e+sizeof(path) < tmp+sizeof(tmp))) {
        memcpy(e, path, sizeof(path));
        option68_set(opt,tmp);
      }
    }

    /* Setup new data path */
    if (option68_isset(opt)) {
      rsc68_set_share(opt->val.str);
#if 0 /* not needed anynore since option68 properly alloc strings */
      if (opt->val.str == tmp)
        option68_unset(opt);    /* Must release tmp ! */
#endif
    }

  }

  /* Get user path  */
  opt = option68_get("home", 0);
  if (opt) {

    /* Get user path from HOME */
    if (!option68_isset(opt)) {
      const char path[] = "/.sc68";
      const char * env = mygetenv("HOME");
      if(env && strlen(env)+sizeof(path) < sizeof(tmp)) {
        strncpy(tmp,env,sizeof(tmp));
        strcat68(tmp,path,sizeof(tmp));
        /* $$$ We should test if this directory actually exists */
        option68_set(opt,tmp);
      }
    }


    /* Get user path from registry */
    if (!option68_isset(opt)) {
      char * e;
      const char path[] = "sc68";
      e = get_reg_path(registry68_rootkey(REGISTRY68_CUK),
                       "Volatile Environment/APPDATA",
                       tmp, sizeof(tmp));
      if (e && (e+sizeof(path) < tmp+sizeof(tmp))) {
        memcpy(e, path, sizeof(path));
        option68_set(opt,tmp);
      }
    }


    /* Setup new user path */
    if (option68_isset(opt)) {
      rsc68_set_user(opt->val.str);
      if (opt->val.str == tmp)
        option68_unset(opt);    /* Must release tmp ! */
    }

  }

  /* Setup new music path */
  opt = option68_get("music", 1);
  if (opt) {
    rsc68_set_music(opt->val.str);
  }

  /* Setup new remote path */
  opt = option68_get("remote", 1);
  if (opt) {
    rsc68_set_remote_music(opt->val.str);
  }

  init = 1;
out_no_init:
  return argc;
}