コード例 #1
0
// Same as Faad.decode (Faad.Mp4.read_sample) but more efficient. Share code?
CAMLprim value ocaml_faad_mp4_decode(value m, value track, value sample, value dh)
{
  CAMLparam4(m, track, sample, dh);
  CAMLlocal1(outbuf);
  mp4_t *mp = Mp4_val(m);
  int t = Int_val(track);
  int s = Int_val(sample);
  NeAACDecHandle dec = Dec_val(dh);
  NeAACDecFrameInfo frameInfo;
  unsigned char *inbuf = NULL;
  unsigned int inbuflen = 0;
  float *data;
  int c, i, ret;

  caml_enter_blocking_section();
  ret = mp4ff_read_sample(mp->ff, t, s, &inbuf, &inbuflen);
  caml_leave_blocking_section();

  check_err(ret);

  caml_enter_blocking_section();
  data = NeAACDecDecode(dec, &frameInfo, inbuf, inbuflen);
  caml_leave_blocking_section();

  free(inbuf);

  if (!data)
    caml_raise_constant(*caml_named_value("ocaml_faad_exn_failed"));
  if (frameInfo.error != 0)
    caml_raise_with_arg(*caml_named_value("ocaml_faad_exn_error"), Val_int(frameInfo.error));

  outbuf = caml_alloc_tuple(frameInfo.channels);
  for(c = 0; c < frameInfo.channels; c++)
    Store_field(outbuf, c, caml_alloc(frameInfo.samples / frameInfo.channels * Double_wosize, Double_array_tag));
  for(i = 0; i < frameInfo.samples; i++)
    Store_double_field(Field(outbuf, i % frameInfo.channels), i / frameInfo.channels, data[i]);

  CAMLreturn(outbuf);
}
コード例 #2
0
CAMLprim value ocaml_faad_decode(value _dh, value _inbuf, value _inbufofs, value _inbuflen)
{
  CAMLparam2(_dh,_inbuf);
  CAMLlocal2(ans, outbuf);
  NeAACDecFrameInfo frameInfo;
  int inbufofs = Int_val(_inbufofs);
  int inbuflen = Int_val(_inbuflen);
  unsigned char *inbuf = malloc(inbuflen);
  float *data;
  int c, i;

  memcpy(inbuf, String_val(_inbuf)+inbufofs, inbuflen);

  NeAACDecHandle dh = Dec_val(_dh);

  caml_enter_blocking_section();
  data = NeAACDecDecode(dh, &frameInfo, inbuf, inbuflen);
  caml_leave_blocking_section();

  free(inbuf);

  if (frameInfo.error > 0)
    caml_raise_with_arg(*caml_named_value("ocaml_faad_exn_error"), Val_int(frameInfo.error));
  if (!data)
    caml_raise_constant(*caml_named_value("ocaml_faad_exn_failed"));

  outbuf = caml_alloc_tuple(frameInfo.channels);
  for(c = 0; c < frameInfo.channels; c++)
    Store_field(outbuf, c, caml_alloc(frameInfo.samples / frameInfo.channels * Double_wosize, Double_array_tag));
  for(i = 0; i < frameInfo.samples; i++)
    Store_double_field(Field(outbuf, i % frameInfo.channels), i / frameInfo.channels, data[i]);

  ans = caml_alloc_tuple(2);
  Store_field(ans, 0, Val_int(frameInfo.bytesconsumed));
  Store_field(ans, 1, outbuf);

  CAMLreturn(ans);
}
コード例 #3
0
ファイル: ssl_stubs.c プロジェクト: marcolinoas/libres3
CAMLprim value ocaml_ssl_read(value socket, value buffer, value start, value length)
{
  CAMLparam2(socket, buffer);
  int ret, err;
  int buflen = Int_val(length);
  char *buf = malloc(buflen);
  SSL *ssl = SSL_val(socket);

  if (Int_val(start) + Int_val(length) > caml_string_length(buffer))
    caml_invalid_argument("Buffer too short.");

  caml_enter_blocking_section();
  ERR_clear_error();
  ret = SSL_read(ssl, buf, buflen);
  err = SSL_get_error(ssl, ret);
  caml_leave_blocking_section();
  memmove(((char*)String_val(buffer)) + Int_val(start), buf, buflen);
  free(buf);

  if (err != SSL_ERROR_NONE)
    caml_raise_with_arg(*caml_named_value("ssl_exn_read_error"), Val_int(err));

  CAMLreturn(Val_int(ret));
}
コード例 #4
0
ファイル: smf_stubs.c プロジェクト: aplusbi/smf
static int smf_err(int i)
{
    caml_raise_with_arg(*caml_named_value("smf_exn_error"), Val_int(i));
}
コード例 #5
0
ファイル: pcre_stubs.c プロジェクト: mmottl/pcre-ocaml
static inline void raise_pcre_error(value v_arg)
{ caml_raise_with_arg(*pcre_exc_Error, v_arg); }
コード例 #6
0
ファイル: fail.c プロジェクト: crackleware/ocamlcc
CAMLexport void caml_raise_sys_error(value msg)
{
  caml_raise_with_arg(Field(caml_global_data, SYS_ERROR_EXN), msg);
}
コード例 #7
0
ファイル: fail.c プロジェクト: dhil/ocaml-multicore
void caml_raise_sys_error(value msg)
{
  caml_raise_with_arg((value) caml_exn_Sys_error, msg);
}
コード例 #8
0
ファイル: fail.c プロジェクト: dhil/ocaml-multicore
void caml_invalid_argument_value (value msg)
{
  caml_raise_with_arg((value) caml_exn_Invalid_argument, msg);
}
コード例 #9
0
ファイル: fail.c プロジェクト: dhil/ocaml-multicore
void caml_failwith_value (value msg)
{
  caml_raise_with_arg((value) caml_exn_Failure, msg);
}
コード例 #10
0
ファイル: lwt_unix_stubs.c プロジェクト: acieroid/lwt
void lwt_unix_not_available(char const *feature)
{
  caml_raise_with_arg(*caml_named_value("lwt:not-available"), caml_copy_string(feature));
}
コード例 #11
0
ファイル: fail.c プロジェクト: retired-camels/ocaml
void caml_raise_with_string(value tag, char const *msg)
{
  caml_raise_with_arg(tag, caml_copy_string(msg));
}
コード例 #12
0
static void failn(int n) {
    caml_raise_with_arg(*caml_named_value("Llvm_loader_fail"), Val_int(n));
}