Beispiel #1
0
  void camera_extract(void *obj, char *func){
    return;
    //tCamera *camera = (tCamera *)obj;
    try {
      cout << func << endl;
      vector<string> elems = split(func, '_');
      /*
      cout << "size : " << elems.size() << endl;
      vector<string>::iterator it;
      cout << "elems contains:";
      for ( it=elems.begin() ; it < elems.end(); it++ )
	cout << " " << *it;
      cout << endl;
      */
      if(elems[0] == "start") cout << "START !" << endl;
      else if(elems[0] == "stop") cout << "STOP !" << endl;
      else cout << "F**K !" << endl;
      long toto = ygets_l(0);
      ypush_long(toto);
    } catch ( string msg ) {
      y_error(msg.c_str());
    }
    catch ( char const * msg ) {
      y_error(msg);
    }
  }
Beispiel #2
0
int
yarg_true(int iarg)
{
  Symbol *s = (iarg>=0)? sp - iarg : 0;
  int x = 0;
  if (s) {
    CheckStack(1);
    sp[1].ops = &intScalar;
    if (s->ops==&referenceSym) s = &globTab[s->index];
    if (s->ops != &dataBlockSym) sp[1].value = s->value;
    else sp[1].value.db = Ref(s->value.db);
    sp++;
    sp->ops = s->ops;
    sp->ops->True();
    x = (int)ygets_l(0);
    yarg_drop(1);
  }
  return x;
}
Beispiel #3
0
Datei: yusb.c Projekt: emmt/yusb
void Y_usb_control_transfer(int argc)
{
  ydev_instance_t* obj;
  int ret;
  int type, request, value, index, length;
  long size;
  unsigned char* data;
  unsigned int timeout;

  /* Get arguments. */
  if (argc != 8) {
    y_error("expecting exactly 8 arguments");
  }
  obj = get_device(7);
  type = ygets_i(6) & 0xff; /* uint8_t */
  request = ygets_i(5) & 0xff; /* uint8_t */
  value = ygets_i(4) & 0xffff; /* uint16_t */
  index = ygets_i(3) & 0xffff; /* uint16_t */
  data = (unsigned char*)get_data(2, &size);
  length = ygets_i(1) & 0xffff; /* uint16_t */
  timeout = (unsigned int)(ygets_l(0) & 0xffffffffL);
  if (length < 0) {
    y_error("invalid length");
  }
  if (length > size) {
    y_error("length must be at most the size of the data");
  }

  /* Apply operation. */
  ret = libusb_control_transfer(obj->handle, type, request, value,
                                index, data, length, timeout);
  if (ret < 0 && yarg_subroutine()) {
    failure(NULL, ret);
  }
  ypush_int(ret);
}
Beispiel #4
0
void
gy_value_set_iarg(GValue* pval, GITypeInfo * info, int iarg)
{
  GY_DEBUG("in gy_value_set_iarg\n");
  GITypeTag type = g_type_info_get_tag(info);
  GIBaseInfo * itrf;
  switch (type) {
  case GI_TYPE_TAG_BOOLEAN:
    g_value_set_boolean(pval, ygets_c(iarg));
    break;
  case GI_TYPE_TAG_INT8:
    g_value_set_schar(pval, ygets_c(iarg));
    break;
  case GI_TYPE_TAG_UINT8:
    g_value_set_uchar(pval, ygets_c(iarg));
    break;
  case GI_TYPE_TAG_INT16:
  case GI_TYPE_TAG_INT32:
    g_value_set_int(pval, ygets_i(iarg));
    break;
  case GI_TYPE_TAG_UINT16:
  case GI_TYPE_TAG_UINT32:
    g_value_set_uint(pval, ygets_i(iarg));
    break;
  case GI_TYPE_TAG_INT64:
    g_value_set_int64(pval, ygets_l(iarg));
    break;
  case GI_TYPE_TAG_UINT64:
    g_value_set_uint64(pval, ygets_l(iarg));
    break;
  case GI_TYPE_TAG_FLOAT:
    g_value_set_float(pval, ygets_f(iarg));
    break;
  case GI_TYPE_TAG_DOUBLE:
    g_value_set_double(pval, ygets_d(iarg));
    break;
  case GI_TYPE_TAG_GTYPE:
    g_value_set_gtype(pval, ygets_l(iarg));
    break;
  case GI_TYPE_TAG_UTF8:
  case GI_TYPE_TAG_FILENAME:
    g_value_set_static_string (pval, ygets_q(iarg));
    GY_DEBUG("GValue is string: \"%s\"\n", ygets_q(iarg));
    break;
    /* interface types */
  case GI_TYPE_TAG_INTERFACE:
    itrf = g_type_info_get_interface(info);
    switch(g_base_info_get_type (itrf)) {
    case GI_INFO_TYPE_ENUM:
      g_value_set_enum (pval, ygets_l(iarg));
      break;
    case GI_INFO_TYPE_OBJECT:
      g_value_set_object(pval, yget_gy_Object(iarg)->object);
      break;
    default:
      y_errorn("Unimplemented GValue interface type %ld",
	       g_base_info_get_type (itrf));
    }
    g_base_info_unref(itrf);
    break;
  case GI_TYPE_TAG_VOID:
  default:
    y_error("Unimplement property GValue type");
  }
  GY_DEBUG("out gy_iarg2gvalue\n");
}
Beispiel #5
0
Datei: yusb.c Projekt: emmt/yusb
 static void do_transfer(int argc,
                         int (*transfer)(struct libusb_device_handle* handle,
                                         unsigned char endpoint,
                                         unsigned char* data,
                                         int length,
                                         int* transferred,
                                         unsigned int timeout))
{
  ydev_instance_t* obj;
  int ret, iarg;
  int endpoint, length, transferred, offset;
  long size;
  unsigned char* data;
  unsigned int timeout;
  long transferred_index;

  /* Get arguments. */
  if (argc != 6 && argc != 7) {
    y_error("expecting 6 or 7 arguments");
  }
  iarg = argc;
  obj = get_device(--iarg);
  endpoint = ygets_i(--iarg) & 0xff; /* uint8_t */
  data = (unsigned char*)get_data(--iarg, &size);
  length = ygets_i(--iarg);
  if (length < 0) {
    y_error("invalid length");
  }
  if (length > size) {
    y_error("length must be at most the size of the data");
  }
  transferred_index = yget_ref(--iarg);
  if (transferred_index < 0L) {
    y_error("expecting a simple variable reference");
  }
  timeout = (unsigned int)(ygets_l(--iarg) & 0xffffffffL);
  if (iarg > 0) {
    offset = ygets_i(--iarg);
    if (offset < 0 || offset > length) {
      y_error("invalid offset");
    }
  } else {
    offset = 0;
  }

  /* Apply operation. */
  if (length > offset) {
    ret = transfer(obj->handle, endpoint, data + offset,
                   length - offset, &transferred, timeout);
    if (!(ret == 0 || (ret == LIBUSB_ERROR_TIMEOUT && transferred > 0))) {
      /* No data has been transferred. */
      transferred = 0;
      if (yarg_subroutine()) {
        /* Some error has occured. */
        failure(NULL, ret);
      }
    }
  } else {
    /* Nothing to do. */
    transferred = 0;
    ret = 0;
  }
  if (transferred_index >= 0L) {
    /* Store total number of transferred bytes so far. */
    ypush_int(offset + transferred);
    yput_global(transferred_index, 0);
  }
  ypush_int(ret);
}
Beispiel #6
0
void
Y_av_create(int argc)
{
  static long default_params[]=
    {YAV_BIT_RATE, YAV_FRAME_RATE, YAV_GOP_SIZE, YAV_MAX_B_FRAMES};
  long *params=default_params;

  // PARSE ARGUMENTS: SEPARATE KEYWORDS FROM POSITIONAL ARGUMENTS
  static char * knames[] = {
    "vcodec", "pix_fmt", "b", "r", "g", "bf", 0
  };
#define YAC_CREATE_NKW 6
  static long kglobs[YAC_CREATE_NKW+1];
  int kiargs[YAC_CREATE_NKW];
  int piargs[]={-1, -1};

  yarg_kw_init(knames, kglobs, kiargs);
  int iarg=argc-1, parg=0;
  while (iarg>=0) {
    iarg = yarg_kw(iarg, kglobs, kiargs);
    if (iarg>=0) {
      if (parg<2) piargs[parg++]=iarg--;
      else y_error("av_create takes at most 2 positional arguments");
    }
  }

  // INTERPRET POSITIONAL ARGUMENTS
  // filename (mandatory)
  if ((iarg=piargs[0])<0) y_error("FILENAME must be specified");
  char *filename = ygets_q(iarg);

  // params vector (optional)
  if (yav_arg_set(iarg=piargs[1])) {
    long ntot ;
    long dims[Y_DIMSIZE]={0,0};
    params = ygeta_l(iarg, &ntot, dims);
    if (dims[0]!=1 || dims[1]!=4)
      y_error("bad dimensions  for PARAMS vector");
    if (params[0]<0 || params[1]<0 || params[2]<0)
      y_error("bad values in PARAMS vector");
  }

  // INTERPRET KEYWORD ARGUMENTS
  char* vcodec = NULL, *pix_fmt = NULL;
  int k=0;
  if (yav_arg_set(iarg=kiargs[k++])) vcodec  = ygets_q(iarg); // vcodec
  if (yav_arg_set(iarg=kiargs[k++])) pix_fmt = ygets_q(iarg); // pix_fmt
  if (yav_arg_set(iarg=kiargs[k++])) params[0] = ygets_l(iarg); // b
  if (yav_arg_set(iarg=kiargs[k++])) params[1] = ygets_l(iarg); // r
  if (yav_arg_set(iarg=kiargs[k++])) params[2] = ygets_l(iarg); // g
  if (yav_arg_set(iarg=kiargs[k++])) params[3] = ygets_l(iarg); // bf

  // PUSH RETURN VALUE
  yav_ctxt * obj = ypush_av();

  /* allocate the output media context */
  obj->oc = avformat_alloc_context();
  if (!obj->oc) {
    y_error("Memory error");
  }

  /* auto detect the output format from the name. default is
     mpeg. */
  obj->oc->oformat = av_guess_format(NULL, filename, NULL);
  if (!obj->oc->oformat) {
    y_warn("Could not deduce output format from file extension: using MPEG.");
    obj->oc->oformat = av_guess_format("mpeg", NULL, NULL);
  }
  if (!obj->oc->oformat) {
    y_error("Could not find suitable output format.");
  }
  snprintf(obj->oc->filename, sizeof(obj->oc->filename), "%s", filename);

  /* add the audio and video streams using the default format codecs
     and initialize the codecs */
  obj->video_st = NULL;
  //  audio_st = NULL;
  if (obj->oc->oformat->video_codec != AV_CODEC_ID_NONE) {
    AVCodecContext *c;
    obj->video_st = avformat_new_stream(obj->oc, NULL);
    c = obj->video_st->codec;
    if (vcodec) {
      obj->codec = avcodec_find_encoder_by_name(vcodec);
      if (!obj->codec) y_error("can't find requested codec");
      c->codec_id = obj->codec->id;
    } else {
      c->codec_id = obj->oc->oformat->video_codec;
      obj->codec = avcodec_find_encoder(c->codec_id);
      if (!obj->codec) y_error("default codec not found");
    }
    c->codec_type = AVMEDIA_TYPE_VIDEO;

    avcodec_get_context_defaults3(c, obj->codec);
    if (c->codec_id == AV_CODEC_ID_NONE) c->codec_id = obj->codec->id;

    /* put sample parameters */
    c->width   = 0;
    c->height  = 0;
    c->pix_fmt = pix_fmt ? av_get_pix_fmt(pix_fmt) : YAV_PIX_FMT; 
    c->bit_rate      =  params[0]     ? params[0] : YAV_BIT_RATE;
    c->time_base.den =  params[1]     ? params[1] : YAV_FRAME_RATE;
    c->time_base.num =  1;
    c->gop_size      =  params[2]     ? params[2] : YAV_GOP_SIZE;
    c->max_b_frames  = (params[3]>=0) ? params[3] : YAV_MAX_B_FRAMES;
    if(obj->oc->oformat->flags & AVFMT_GLOBALHEADER)
        c->flags |= CODEC_FLAG_GLOBAL_HEADER;

    // codec-specific limitations
    switch (c->codec_id) {
    case AV_CODEC_ID_RAWVIDEO:
    case AV_CODEC_ID_GIF:
      if (!pix_fmt) c->pix_fmt = AV_PIX_FMT_RGB24;
      break;
    case AV_CODEC_ID_MSMPEG4V3:
    case AV_CODEC_ID_H263:
    case AV_CODEC_ID_H263P:
    case AV_CODEC_ID_RV10:
    case AV_CODEC_ID_RV20:
    case AV_CODEC_ID_FLV1:
    case AV_CODEC_ID_ASV1:
    case AV_CODEC_ID_ASV2:
      c->max_b_frames = 0;
      break;
    default:;
    }
  }

  if (!(obj->oc->oformat->flags & AVFMT_RAWPICTURE)) {
    obj->video_outbuf_size = 200000;
    obj->video_outbuf = av_malloc(obj->video_outbuf_size);
  }

}
Beispiel #7
0
  void camera_eval(void *obj, int argc) {
    tCamera *camera = (tCamera *)obj;
    try {
      ystring_t func = ygets_q(argc-1);
      if(strcmp(func, "start")==0){
	long packetSize=8228;
	if(argc >1)  packetSize = ygets_l(argc-2);
	cameraStart(camera, packetSize);
	cameraSnap(camera);
      } else if(strcmp(func, "stop")==0){
	cameraStop(camera);
      } else if(strcmp(func, "getROI")==0){
	long dims[2]={1, 4};
	long *result = ypush_l(dims);
	tPvUint32 ROI[4];
	cameraGetROI(camera, ROI);
	for(int i=0;i<4;i++)  result[i] = ROI[i];
      } else if(strcmp(func, "setROI")==0){
	long ntot, dims;
	long *result = ygeta_l(argc-2, &ntot, &dims);
	tPvUint32 ROI[4];
	for(int i=0;i<4;i++) ROI[i]=result[i];
	cameraSetROI(camera, ROI);	
      } else if(strcmp(func, "getExpo")==0){
	tPvUint32 expo;
	cameraGetExpo(camera, &expo);
	ypush_long(expo);
     } else if(strcmp(func, "setExpo")==0){
	long expo = ygets_l(argc-2);
	cameraSetExpo(camera, expo);
      } else if(strcmp(func, "fastsnap")==0){
	long param = ygets_l(argc-2);
	unsigned long width = camera->Frame.Width;              // Image width
	unsigned long height= camera->Frame.Height;             // Image height
	long dims[4]={3, width, height, param};
	if(param ==1) dims[0]=2;
	char resValue[16];
	cameraGetPixelFormat(camera, resValue, 16);
	tPvFrame *buff = cameraSnap(camera, param);

	if(strcmp(resValue, "Mono8")==0) {
	  short *frame = ypush_s(dims);
	  for(long pose=0; pose<param; pose++){
	    unsigned char *src = (unsigned char *)buff[pose].ImageBuffer;
	    short *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else if(strcmp(resValue, "Mono16")==0) {
	  int *frame = ypush_i(dims);
	  for(long pose=0; pose<param; pose++){
	    unsigned short *src = (unsigned short *)buff[pose].ImageBuffer;
	    int *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else cout << "bad ppixel size !" << endl;
      } else if(strcmp(func, "snap")==0){
	long param = ygets_l(argc-2);
	unsigned long width = camera->Frame.Width;              // Image width
	unsigned long height= camera->Frame.Height;             // Image height
	long dims[4]={3, width, height, param};
	if(param ==1) dims[0]=2;
	char resValue[16];
	cameraGetPixelFormat(camera, resValue, 16);
	
	if(strcmp(resValue, "Mono8")==0) {
	  short *frame = ypush_s(dims);
	  for(long pose=0; pose<param; pose++){
	    cameraSnap(camera);
	    unsigned char *src = (unsigned char *)camera->Frame.ImageBuffer;
	    short *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else if(strcmp(resValue, "Mono16")==0) {
	  int *frame = ypush_i(dims);
	  for(long pose=0; pose<param; pose++){
	    cameraSnap(camera);
	    unsigned short *src = (unsigned short *)camera->Frame.ImageBuffer;
	    int *dst = &frame[pose*height*width];
	    for(unsigned long i=0; i<width*height; i++) {
	      dst[i] = src[i];
	    }
	  }
	} else cout << "bad ppixel size !" << endl;
      } else cout << "F**K !" << endl;

    } catch ( string msg ) {
      y_error(msg.c_str());
    }
    catch ( char const * msg ) {
      y_error(msg);
    }
  }
Beispiel #8
0
void
Y_gy_debug(int argc)
{
  ypush_long(_gy_debug);
  if (argc && !yarg_nil(argc)) _gy_debug = ygets_l(argc);
}