int usbprn_attach( int minor )
{
	struct usblp *usblp = usblp_table[minor];
	int i1284 = NUM_OF_1284_PORT + usblp->dev->ttport;
	char *tmp;

//ZOT716u2	armond_printf("usblp attach\n");

	if( PortIO[i1284].base == 0 )
	{
		// we only attach one printer per port
		PortIO[i1284].base = minor + 1;
		PortIO[i1284].HasGetDeviceID = 1;
		PortIO[i1284].PrnMode = PRN_USB_PRINTER;
		PortIO[i1284].PrnReadBackMode = PRN_USB_PRINTER;

		tmp = malloc( LENGTH_OF_DEVICE_ID );
		if( tmp )
		{
			memcpy( tmp, usblp->device_id_string, LENGTH_OF_DEVICE_ID );
			parse_device_id( i1284, &tmp[2] );
			free( tmp );
		}
	
		return 1;
	}
	return 0;
}
Exemplo n.º 2
0
static gboolean
device_select (GstOSXVideoSrc * src)
{
  Str63 pstr;
  ComponentResult err;
  gchar *sgname;
  int inputIndex;

  /* if there's no device id set, attempt to select default device */
  if (!src->device_id && !device_set_default (src))
    return FALSE;

  if (!parse_device_id (src->device_id, &sgname, &inputIndex)) {
    GST_ERROR_OBJECT (src, "unable to parse device id: [%s]", src->device_id);
    return FALSE;
  }

  c2pstrcpy (pstr, sgname);
  g_free (sgname);

  err = SGSetChannelDevice (src->video_chan, (StringPtr) & pstr);
  if (err != noErr) {
    GST_ERROR_OBJECT (src, "SGSetChannelDevice returned %d", (int) err);
    return FALSE;
  }

  err = SGSetChannelDeviceInput (src->video_chan, inputIndex);
  if (err != noErr) {
    GST_ERROR_OBJECT (src, "SGSetChannelDeviceInput returned %d", (int) err);
    return FALSE;
  }

  return TRUE;
}
Exemplo n.º 3
0
/** Parse the argv for command line parameters. */
void parse_options( int argc, char* argv[] )
{
	char *cmd;
	arg_tok( argv+1, 0 );
	while (cmd = arg_tok(0,":="))
	{
		if (str_in( cmd, "l", "ls", "list", 0 ))
			action = List;
		else if (str_in( cmd, "r", "rd", "read", 0 ))
			action = Read;
		else if (str_in( cmd, "h", "help", 0 ))
			action = Help;
		else if (str_in( cmd, "d", "dev", "device", 0 ))
			parse_device_id( arg_tok(0,"") );
		else
			errorf( "#### Unknown command: %s", cmd );
	}
}
Exemplo n.º 4
0
/** Parse the argv for command line parameters. */
void parse_options( int argc, char* argv[] )
{
	char *cmd;
	arg_tok( argv+1, 0 );
	while (cmd = arg_tok(0,":="))
	{
		cmd += strspn( cmd, "-/" );
		if (str_in( cmd, "l", "ls", "list", 0 ))
			action = List;
		else if (str_in( cmd, "r", "rd", "read", 0 ))
			action = Read;
		else if (str_in( cmd, "h", "help", 0 ))
			action = Help;
		else if (str_in( cmd, "d", "dev", "device", 0 ))
			parse_device_id( arg_tok(0,"") );
		else if (str_in( cmd, "c", "ch", "chan", "channel", 0 ))
			parse_channel_list( arg_tok(0,"") );
		else if (str_in( cmd, "f", "fmt", "format", 0 ))
			parse_format( arg_tok(0,"") );
		else
			errorf( "#### Unknown command: %s", cmd );
	}
}
Exemplo n.º 5
0
static int android_read_header(AVFormatContext *avctx)
{
    int ret = AVERROR(EIO);
    int android_pix_fmt,android_sample_fmt;
    struct android_camera_ctx * ctx;
    ctx = avctx->priv_data;

	debug = ctx->debug;
    if (!ctx->list_devices && !parse_device_name(avctx)) {
        av_log(avctx, AV_LOG_ERROR, "Malformed android_camera input string.\n");
        return ret;
    }
    ctx->video_codec_id = avctx->video_codec_id ? avctx->video_codec_id
                                                : AV_CODEC_ID_RAWVIDEO;
    /*
     *  如果有点格式但是不等于AV_CODEC_ID_RAWVIDEO返回错误
     */
    if (ctx->pixel_format != AV_PIX_FMT_NONE) {
        if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) {
            av_log(avctx, AV_LOG_ERROR, "Pixel format may only be set when "
                    "video codec is not set or set to rawvideo\n");
            ret = AVERROR(EINVAL);
            return ret;
        }
    }
    if (ctx->framerate) {
        ret = av_parse_video_rate(&ctx->requested_framerate, ctx->framerate);
        if (ret < 0) {
            av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate);
            return ret;
        }
    }
    /*
     * 枚举设备
     */
    if (ctx->list_devices) {
        av_log(avctx, AV_LOG_INFO, "Android camera devices (some may be both video and audio devices)\n");
        android_cycle_devices(avctx, VideoDevice);
        av_log(avctx, AV_LOG_INFO, "Android audio devices\n");
        android_cycle_devices(avctx, AudioDevice);
        ret = AVERROR_EXIT;
        return ret;
    }
    /*
     * 枚举设备参数
     */
    if (ctx->list_options) {
        if (ctx->device_name[VideoDevice])
        if ((ret = android_list_device_options(avctx, VideoDevice))) {
            return ret;
        }
        if (ctx->device_name[AudioDevice]) {
            if (android_list_device_options(avctx, AudioDevice)) {
                /* show audio options from combined video+audio sources as fallback */
                if ((ret = android_list_device_options(avctx, AudioDevice))) {
                    return ret;
                }
            }
        }
        ret = AVERROR_EXIT;
        return ret;
    }
    /*
     * 打开android摄像头设备和录音设备
     */
    int iDevice = parse_device_id(ctx->device_name[VideoDevice]);
    if(iDevice>=0) {
        android_setDemuxerCallback(android_grab_buffer);
		
		DEBUG("android_read_header android_openDemuxer:oes=%d,dev=%d,w=%d,h=%d,pixfmt=%d,fps=%d,ch=%d,bits=%d,rate=%d",
               ctx->oes_texture, iDevice, ctx->requested_width,
               ctx->requested_height,
               ctx->pixel_format, av_q2d(ctx->requested_framerate),
               ctx->channels, 16, ctx->sample_rate);
			   
        android_pix_fmt = android_pixfmt2av(ctx->pixel_format);
        android_sample_fmt = 16;
        
        int result = android_openDemuxer(ctx->oes_texture, iDevice, ctx->requested_width,
                                         ctx->requested_height,
                                         android_pix_fmt, av_q2d(ctx->requested_framerate),
                                         ctx->channels, android_sample_fmt, ctx->sample_rate);
        if(result){
            av_log(avctx, AV_LOG_ERROR, "android_openDemuxer return %d\n",result);
            return ret;
        }
        if( ctx->oes_texture >= -1 ) {
            ret = add_device(avctx, VideoDevice);
            if (ret < 0) {
                av_log(avctx, AV_LOG_ERROR, "add_device VideoDevice return %d\n", ret);
                return ret;
            }
        }
        if( ctx->channels > 0 ) {
            ret = add_device(avctx, AudioDevice);
            if (ret < 0) {
                av_log(avctx, AV_LOG_ERROR, "add_device AudioDevice return %d\n", ret);
                return ret;
            }
        }
        if(pthread_mutex_init(&ctx->mutex,NULL)){
            av_log(avctx, AV_LOG_ERROR, "pthread_mutex_init non-zero");
            return ret;
        }
        if(pthread_cond_init(&ctx->cond,NULL)){
            av_log(avctx, AV_LOG_ERROR, "pthread_cond_init non-zero");
            return ret;
        }
        /*
         * 一次只能打开一个俘获android设备
         */
        _avctx = avctx;
        ctx->bufsize = 0;
        ret = 0;
    }else{
        av_log(avctx, AV_LOG_ERROR, "android_read_header videoDevice = %s\n",ctx->device_name[VideoDevice]);
    }
	DEBUG("android_read_header return %d",ret);
    return ret;
}
Exemplo n.º 6
0
static int
android_list_device_options(AVFormatContext *avctx,enum androidDeviceType devtype)
{
    struct android_camera_ctx *ctx = avctx->priv_data;
    const char *device_name = ctx->device_name[devtype];
    int deviceId;
    int n,i,off1,off2,s,fps,k;
    int * pinfo;
    int j,w,h;
    const char *formatName;
    double min_fps,max_fps;

    if(devtype==VideoDevice){
        deviceId = parse_device_id(device_name);
        if(deviceId<0){
            av_log(avctx, AV_LOG_ERROR, "android_list_device_options device name:%s\n", deviceId);
            return AVERROR(EIO);
        }
        n = android_getNumberOfCameras();
        pinfo = malloc(MAXCAPS*sizeof(int));
        for(i=0;i<n;i++) {
            if(i==deviceId) {
                int ncount = android_getCameraCapabilityInteger(deviceId, pinfo, MAXCAPS);
                if (ncount > 0) {
                    av_log(avctx, AV_LOG_INFO, "face : %s\n", pinfo[0]==1?"front":"back");
                    av_log(avctx, AV_LOG_INFO, "orientation : %d\n", pinfo[1]);
                    off1 = pinfo[2]*2+2+1;
                    off2 = off1+pinfo[off1]+1;
                    min_fps = 100;
                    max_fps = 0;
                    /*
                     * 摄像头支持的帧率
                     */
                    for(s=0;s<pinfo[off2];s++){
                        fps =  pinfo[off2+s+1];
                        av_log(avctx, AV_LOG_INFO,"   framerate: %d \n",fps);
                        if( min_fps > fps )
                            min_fps = fps;
                        if( max_fps < fps )
                            max_fps = fps;
                    }
                    /*
                     * 摄像头支持的格式,FLEX_RGBA_8888,FLEX_RGB_888,JPEG,NV16,YUV_420_888,YUV_422_888
                     * YUV_444_888,YUY2,YV12,RGB_565,RAW10,RAW12,NV21
                     */
                    for(k=0;k<pinfo[off1];k++){
                        formatName = android_2pixfmt_name( pinfo[k+off1+1] );
                        /*
                         * 格式和尺寸的组合
                         */
                        for(j=0;j<pinfo[2];j++){
                            w = pinfo[3+2*j];
                            h = pinfo[3+2*j+1];
                            if(formatName)
                                av_log(avctx, AV_LOG_INFO,"  pixel_format=%s\n",formatName);
                            else
                                av_log(avctx, AV_LOG_INFO,"  pixel_format=UNKNOW\n");
                            av_log(avctx, AV_LOG_INFO, "  min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n",
                                   w,h,min_fps,w,h,max_fps);
                        }
                    }
                } else {
                    av_log(avctx, AV_LOG_ERROR,
                           "android_getCameraCapabilityInteger(%d) return %d\n", i, ncount);
                    return AVERROR(EIO);
                }
            }
        }
        free(pinfo);
    }
    else if(devtype==AudioDevice){
        /*
         * 固定的参数
         */
        av_log(avctx, AV_LOG_INFO, "  min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
               1,8,22050,2,16,44100);
    }
    else{
        return AVERROR(EIO);
    }
    return 0;
}