示例#1
0
static unsigned long pci_bios32_service_directory(unsigned long service)
{
  unsigned char return_code; /* %al */
  unsigned long address;     /* %ebx */
  unsigned long length;      /* %ecx */
  unsigned long entry;       /* %edx */
  unsigned long call_addr = (unsigned long)&pci_bios_entry;

  asm volatile(
    "lcall (%%edi)"
   :"=a" (return_code),
    "=b" (address),
    "=c" (length),
    "=d" (entry)
   :"0" (service),
    "1" (0),
    "D" (call_addr)
  );

  switch (return_code) {
  case 0:
    return address + entry;
  case 0x80: /* Not present */
    print_format("bios32_service(%d) : not present\n", service);
    return 0;
  default: /* Shouldn't happen */
    print_format("bios32_service(%d) : returned 0x%x\n",
    service, return_code);
    return 0;
  }
}
示例#2
0
文件: gpiodump.c 项目: 23ars/bbbtools
void *consumer(void *ptr)
{
	int32_t buffer_index;
	struct s_VcdFormatValues buffervalues;
	while (consumer_running)
	{
		pthread_mutex_lock(&shared_var_mutex);
		while (buffer_empty(&dataCapturedValues))
		{
			pthread_cond_wait(&cond_consumer, &shared_var_mutex);
		}
		/*Invalidate previous values from buffer*/
		memset(&buffervalues,0,sizeof(struct s_VcdFormatValues));
		if(fetch_beginning(&dataCapturedValues,&buffervalues)!=-1)
		{
			print_format(fd, buffervalues,cfgPins);
		}
		pthread_cond_signal(&cond_producer);
		pthread_mutex_unlock(&shared_var_mutex);
	}
	/*Flush buffer only if buffer is not empty, meaning that it still holds values but consumer thread was stopped*/
	while(!buffer_empty(&dataCapturedValues))
	{
		memset(&buffervalues,0,sizeof(struct s_VcdFormatValues));
		(void)fetch_beginning(&dataCapturedValues,&buffervalues);
		print_format(fd, buffervalues,cfgPins);
	}

	pthread_exit(0);
}
示例#3
0
static void print_modifiers(decl_modifiers_t const modifiers)
{
	if (modifiers == 0)
		return;

	static const struct {
		unsigned bit;
		const char *name;
	} modifiernames[] = {
		{ DM_NAKED,             "naked"             },
		{ DM_NOTHROW,           "nothrow"           },
		{ DM_NORETURN,          "noreturn"          },
		{ DM_NOINLINE,          "noinline"          },
		{ DM_NOALIAS,           "noalias"           },
		{ DM_TRANSPARENT_UNION, "transparent_union" },
		{ DM_CONST,             "const"             },
		{ DM_PURE,              "pure"              },
		{ DM_CONSTRUCTOR,       "constructor"       },
		{ DM_DESTRUCTOR,        "destructor"        },
		{ DM_UNUSED,            "unused"            },
		{ DM_USED,              "used"              },
		{ DM_RETURNS_TWICE,     "returns_twice"     },
		{ DM_MALLOC,            "malloc"            },
		{ DM_WEAK,              "weak"              },
		{ DM_LEAF,              "leaf"              },
		{ DM_PACKED,            "packed"            },
	};
	separator_t sep = { " __attribute__((", ", " };
	for (size_t i = 0; i < ARRAY_SIZE(modifiernames); ++i) {
		if (modifiers & modifiernames[i].bit)
			print_format("%s__%s__", sep_next(&sep), modifiernames[i].name);
	}
	if (!sep_at_first(&sep))
		print_string("))");
}
示例#4
0
/*****************************************************************************
 * AudioStreamSupportsDigital: Check i_stream_id for digital stream support.
 *****************************************************************************/
static int AudioStreamSupportsDigital( AudioStreamID i_stream_id )
{
    UInt32 i_param_size;
    AudioStreamBasicDescription *p_format_list = NULL;
    int i, i_formats, b_return = CONTROL_FALSE;

    /* Retrieve all the stream formats supported by each output stream. */
    i_param_size = GetGlobalAudioPropertyArray(i_stream_id,
                                               kAudioStreamPropertyPhysicalFormats,
                                               (void **)&p_format_list);

    if (!i_param_size) {
        ao_msg(MSGT_AO, MSGL_WARN, "Could not get number of stream formats.\n");
        return CONTROL_FALSE;
    }

    i_formats = i_param_size / sizeof(AudioStreamBasicDescription);

    for (i = 0; i < i_formats; ++i)
    {
        print_format(MSGL_V, "supported format:", &p_format_list[i]);

        if (p_format_list[i].mFormatID == 'IAC3' ||
                  p_format_list[i].mFormatID == kAudioFormat60958AC3)
            b_return = CONTROL_OK;
    }

    free(p_format_list);
    return b_return;
}
示例#5
0
文件: format.c 项目: FDOS/ramdisk
void print_newf(void)
{
  if (verbose > 1) {
    printf("New disk configuration:\n\n");
    print_format(&newf);
    puts("");
  }
}
示例#6
0
/** 
 * @brief  Begin reading audio data from a file.
 *
 * If listfile was specified in adin_sndfile_standby(), the next filename
 * will be read from the listfile.  Otherwise, the
 * filename will be obtained from stdin.  Then the file will be opened here.
 *
 * @param filename [in] file name to open or NULL for prompt
 * 
 * @return TRUE on success, FALSE on failure.
 */
boolean
adin_sndfile_begin(char *filename)
{
  boolean readp;

  if (filename != NULL) {
    if (adin_sndfile_open(filename) == FALSE) {
      jlog("Error: adin_sndfile: invalid format: \"%s\"\n", filename);
      print_format(&sinfo);
      return FALSE;
    }
    jlog("Stat: adin_sndfile: input speechfile: %s\n", filename);
    print_format(&sinfo);
    strcpy(speechfilename, filename);
    return TRUE;
  }

  /* ready to read next input */
  readp = FALSE;
  while(readp == FALSE) {
    if (from_file) {
      /* read file name from listfile */
      do {
	if (getl_fp(speechfilename, MAXPATHLEN, fp_list) == NULL) { /* end of input */
	  fclose(fp_list);
	  return(FALSE); /* end of input */
	}
      } while (speechfilename[0] == '#'); /* skip comment */
    } else {
      /* read file name from stdin */
      if (get_line_from_stdin(speechfilename, MAXPATHLEN, "enter filename->") == NULL) {
	return (FALSE);	/* end of input */
      }
    }
    if (adin_sndfile_open(speechfilename) == FALSE) {
      jlog("Error: adin_sndfile: invalid format: \"%s\"\n",speechfilename);
      print_format(&sinfo);
    } else {
      jlog("Stat: adin_sndfile: input speechfile: %s\n",speechfilename);
      print_format(&sinfo);
      readp = TRUE;
    }
  }
  return TRUE;
}
示例#7
0
void dsp_open_error(int errno)
{
  switch(errno) {
  case ERRNO_NOTEXIST:
    display_puts("Not found\n");
    break;
  case ERRNO_SCSI_NotReady:
    display_puts("Drive is not ready\n");
    break;
  default:
    print_format("Error(%d)\n",errno);
  }
}
示例#8
0
void		ft_printvar(char s[3][50], void *ptr, int line)
{
	char	buf[5];
	int		i;

	qprintf("\033[33m%s:%d %s %s\033[0m = \033[31m", s[2], line, s[0], s[1]);
	if (!(i = get_format(s[0], buf)))
		qprintf("NYI");
	else
		print_format(buf, ptr, i);
	qprintf("\033[0m;\n");
	return ;
}
示例#9
0
static void print_formats(struct nvme_id_ns *id, struct nvme_ns *ns)
{
	int i;

	printf("Blk device %d: LBA Format Support:\n", ns->devnum);

	for (i = 0; i < id->nlbaf; i++) {
		printf("\tLBA Foramt %d Support: ", i);
		if (i == ns->flbas)
			printf("(current)\n");
		else
			printf("\n");
		print_format(id->lbaf + i);
	}
}
示例#10
0
int cmd_stat(int ac, char **av)
{
  int rc;
  int handle;
  char type;
  char buf[sizeof(struct file_info)+CDFS_FULLPATH_MAXLENGTH];
  struct file_info *info=(void*)buf;

//display_puts("cdfs_open\n");
  handle = cdfs_open(av[0]);
  if(handle<0) {
    dsp_open_error(handle);
    goto EXITCMD;
  }

//display_puts("cdfs_stat\n");
  rc = cdfs_stat(handle,info,sizeof(buf));
  if(rc<0) {
    display_puts("rc=");
    sint2dec(rc,s);
    display_puts(s);
    goto EXITCMD;
  }


  if(info->attr & CDFS_ATTR_DIRECTORY)
    type='D';
  else
    type='F';

  unsigned char *datestr=info->mtime;
  print_format("type=%c(%02x) date=%d-%02d-%02d %02d:%02d:%02d size=%d\n",type,info->attr,1900+datestr[0],datestr[1],datestr[2],datestr[3],datestr[4],datestr[5],info->size);

EXITCMD:
  if(handle>0) {
//display_puts("cdfs_close\n");
    rc = cdfs_close(handle);
    if(rc<0) {
      display_puts("rc=");
      sint2dec(rc,s);
      display_puts(s);
    }
  }

  return 0;
}
示例#11
0
void print_allnodes(Node *root){
  int i,depth,pos,child;
  if (root==NULL)
    printf("EMPTY\n");
  else{
  for (depth=0; depth<HEIGHT; depth++) {
    cnt[depth]=0;
  }
  levels=0; 
  depth_first_search(root,0);
  print_format();
  for (depth=0; depth<=levels; depth++){
    pos=-1;
    for (i=0; i<cnt[depth]; i++)
      print_node(pointer[depth][i],depth,i,&pos,TRUE);
    printf("\n");
  } 
  }
}
示例#12
0
/*-----------------------------------------------------------------------
 *  Prints various information about the mode the camera is in
 *-----------------------------------------------------------------------*/
void of1394VideoGrabber::print_mode_info(dc1394video_mode_t mode )
{
    int j;
	
    printf("Mode: ");
    print_format(mode);
    printf("\n");
	
    dc1394framerates_t framerates;
    dc1394error_t err;
    err=dc1394_video_get_supported_framerates(camera,mode,&framerates);
    DC1394_ERR(err,"Could not get frame rates");
	
    printf("Frame Rates:\n");
    for( j = 0; j < framerates.num; j++ ) {
        dc1394framerate_t rate = framerates.framerates[j];
        float f_rate;
        dc1394_framerate_as_float(rate,&f_rate);
        printf("  [%d] rate = %f\n",j,f_rate );
    }
	
}
示例#13
0
/*****************************************************************************
 * AudioStreamChangeFormat: Change i_stream_id to change_format
 *****************************************************************************/
static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format )
{
    OSStatus err = noErr;
    int i;
    AudioObjectPropertyAddress property_address;

    static volatile int stream_format_changed;
    stream_format_changed = 0;

    print_format(MSGL_V, "setting stream format:", &change_format);

    /* Install the callback. */
    property_address.mSelector = kAudioStreamPropertyPhysicalFormat;
    property_address.mScope    = kAudioObjectPropertyScopeGlobal;
    property_address.mElement  = kAudioObjectPropertyElementMaster;

    err = AudioObjectAddPropertyListener(i_stream_id,
                                         &property_address,
                                         StreamListener,
                                         (void *)&stream_format_changed);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    /* Change the format. */
    err = SetAudioProperty(i_stream_id,
                           kAudioStreamPropertyPhysicalFormat,
                           sizeof(AudioStreamBasicDescription), &change_format);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "could not set the stream format: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    /* The AudioStreamSetProperty is not only asynchronious,
     * it is also not Atomic, in its behaviour.
     * Therefore we check 5 times before we really give up.
     * FIXME: failing isn't actually implemented yet. */
    for (i = 0; i < 5; ++i)
    {
        AudioStreamBasicDescription actual_format;
        int j;
        for (j = 0; !stream_format_changed && j < 50; ++j)
            usec_sleep(10000);
        if (stream_format_changed)
            stream_format_changed = 0;
        else
            ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" );

        err = GetAudioProperty(i_stream_id,
                               kAudioStreamPropertyPhysicalFormat,
                               sizeof(AudioStreamBasicDescription), &actual_format);

        print_format(MSGL_V, "actual format in use:", &actual_format);
        if (actual_format.mSampleRate == change_format.mSampleRate &&
            actual_format.mFormatID == change_format.mFormatID &&
            actual_format.mFramesPerPacket == change_format.mFramesPerPacket)
        {
            /* The right format is now active. */
            break;
        }
        /* We need to check again. */
    }

    /* Removing the property listener. */
    err = AudioObjectRemovePropertyListener(i_stream_id,
                                            &property_address,
                                            StreamListener,
                                            (void *)&stream_format_changed);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamRemovePropertyListener failed: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    return CONTROL_TRUE;
}
示例#14
0
int main(int argc, char *argv[])
{
	int error;
	char *sample;
	int sample_size;
	Mix_Music *music;
	SDL_RWops *rw;
	FILE *fp;

	if (argc != 2)
	{
		printf("usage: %s modfile\n", argv[0]);
		return 1;
	}

	/* initialize SDL */
	error = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER);
	if (error != 0)
	{
		printf("SDL_GetError returned: %s\n", SDL_GetError());
		return 0;
	}

	atexit(SDL_Quit);

	/* initialize SDL_mixer */
	if (Mix_OpenAudio(44100, AUDIO_S16, 2, 512) < 0) 
	{
		printf("Couldn't open audio: %s\n", SDL_GetError());
		return 0;
	}

	print_format();

	/* load entire module to memory
	 *
	 * this is recommended since MikMod makes many many calls
 	 * to fread(), and it is quite slow with ps2client over IP
	 */
	printf("loading module '%s'..\n", argv[1]);
	fp = fopen(argv[1], "rb");
	if (fp == NULL)
	{
		printf("failed to open module %s\n", argv[1]);
		return 0;
	}

	fseek(fp, 0, SEEK_END);
	sample_size = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	sample = (char *)malloc(sample_size);
	sample_size = fread(sample, 1, sample_size, fp);
	fclose(fp);

	printf("File loaded into memory\n");

	rw = SDL_RWFromMem(sample, sample_size);

	/* load and play music */
	music = Mix_LoadMUS_RW(rw);
	if (music == NULL)
	{
		printf("LoadMUS failed\n");
		return 0;
	}

	/* set a callback when module completes */
	playing = 1;
	Mix_HookMusicFinished(music_finished);

	/* play song once */
	Mix_PlayMusic(music, 0);

	printf("playing for 10 seconds\n");
	SDL_Delay(10*1000);

	printf("\n");
	printf("module ended\n");

        Mix_FreeMusic(music);
	return 0;
}
示例#15
0
文件: main.c 项目: gerpayt/camshot
int main(int argc, char **argv)
{
    int shmid;
    int i,j;
    char in_str[16];

	process_arguments(argc, argv);

    /* open the camera device */
	if( (camera_fd = open(psz_video_dev, O_RDWR)) < 0 )
	{
        char error_buf[256];
        sprintf(error_buf, "open() %s", psz_video_dev);
		perror(error_buf);
		exit(-1);
	}

    get_caps();
    get_format();

	if( b_verbose ) printf("Device opened.\n");

	if( b_verbose )
	{
		printf("Video device:\t\t%s\n", psz_video_dev);
		print_caps();
        print_format();
		printf("Ouput directory:\t%s\n", psz_output_dir);
		printf("Image format:\t\t%s\n",str_formats[e_outfmt]);
		printf("\n");
		printf("Opening device %s\n", psz_video_dev);
        if( b_named_filename )
        {
            printf("Ouput filename:\t%s\n", psz_output_filename);
        }
        else if( b_named_pipe )
        {
            printf("Using named pipe %s\n", psz_named_pipe);
        }
        if( b_shared_mem )
            printf("Using shared memory. key = %i\n", shared_mem_key);
	}

    if( b_printinfo )
    {
        printf("Device info:\n");
        print_caps();
        print_format();
        close(camera_fd);
        exit(EXIT_SUCCESS);    
    }

    (void)signal(SIGINT, exit_program);

    if( b_shared_mem && b_named_pipe )
    {
        printf("WARNING: shared memory and named pipe can't be used together. Use more instances of camshot. Defaulting to named pipe.\n");
        b_shared_mem = 0;
    }

    if( b_named_pipe )
    {
        int ret_val = mkfifo(psz_named_pipe, 0666);

        if ((ret_val == -1) && (errno != EEXIST)) {
            perror("Error creating the named pipe");
            exit(EXIT_FAILURE);
        }
        
    }

    if( req_width && req_height )
    {
        if( b_verbose )
            printf("Trying to set resolution to %ux%u.\n", req_width, req_height);

        if( set_width_height(req_width,req_height) == -1 )
            printf("Unable to set the desired resolution.\n");
        else
            if( b_verbose )
                printf("Resolution set to %ux%u\n", req_width, req_height);
    } else {
        get_format();
        req_width = camera_format.fmt.pix.width;
        req_height = camera_format.fmt.pix.height;
    }

    if( b_shared_mem )
    {
        if((shmid = shmget(shared_mem_key, req_width*req_height*3, IPC_CREAT | 0666)) < 0) {
            perror("Error getting shared memory id");
            exit(EXIT_FAILURE);
        }

        if((p_shm = (uint8_t *)shmat(shmid, NULL, 0)) == (void *) -1) {
            perror("Error getting shared memory ptr");
            exit(EXIT_FAILURE);
        }       

        shm_sem = semget((key_t)shared_mem_key, 1, IPC_CREAT | 0666);

        sem_set(&shm_sem);

        if( b_verbose )
            printf("Shared memory ID: %i\nSemaphore ID: %i\n", shmid, shm_sem);
    }

	total_buffers = req_mmap_buffers(2);

	/* start the capture */
	streaming_on();

    /* let the camera self adjust by 'ignoring' 200 complete buffer queues */
    printf("Letting the camera automaticaly adjust the picture:");
    
    for(i=0; i<AUTO_ADJUST_TURNS; i++)
    {
        for(j=0; j<total_buffers; j++)
        {
            int ready_buf = dequeue_buffer();
            /* don't queue the last buffers */
            if( i<AUTO_ADJUST_TURNS-1 )
                queue_buffer(ready_buf);
        }

        printf(".");
        fflush(stdout);
    }

    printf("Done.\n");

    if( b_shared_mem || b_named_pipe )
    {
        pthread_create(&stream_thread, NULL, &stream_func, NULL);
        while(1)
        {
            pthread_join(stream_thread, NULL);
        }
    }
    else
    {
        pthread_create(&capture_thread, NULL, &capture_func, NULL);
    }

    if( b_named_filename )
    {
        usleep(200000);
        pthread_mutex_lock(&cond_mutex);
        pthread_cond_signal(&condition);
        pthread_mutex_unlock(&cond_mutex);
        usleep(200000);
        exit_program(SIGINT);
        fflush(stdout);
        return 0;
    }

    while( in_str[0] != 'q' )
    {
        
        printf("Command (h for help): ");
        fflush(stdout);

        if( fgets(in_str, 16, stdin) == NULL )
        {
            printf("Got NULL! Try again.\n");
            continue;
        }

        switch(in_str[0])
        {
            case 'x':
                pthread_mutex_lock(&cond_mutex);
                pthread_cond_signal(&condition);
                pthread_mutex_unlock(&cond_mutex);
                break;
            case 'h':
                printf("\nCommands:\n");
                printf("\tx\tCapture a picture from camera.\n");
                printf("\th\tPrints this help.\n");
                printf("\tq\tQuits the program.\n");
                printf("\n");
                break;
            case 'q':
            case '\n':
                break;
            default:
                fprintf(stderr, "Unknown command %c\n", in_str[0]);
                break;
        }
    }

	/* Clean up */
    exit_program(SIGINT);
	return 0;
}
示例#16
0
void Video_out::Run()
{
	if(verbose) printf("Thread started: %s\n", this->devName.c_str());
	int running = 1;
	pthread_mutex_lock(&this->lock);
	this->stopped = 0;
	pthread_mutex_unlock(&this->lock);

	this->fdwr = open(this->devName.c_str(), O_RDWR);
	assert(fdwr >= 0);

	struct v4l2_capability vid_caps;
	int ret_code = ioctl(this->fdwr, VIDIOC_QUERYCAP, &vid_caps);
	assert(ret_code != -1);
	
	struct v4l2_format vid_format;
	memset(&vid_format, 0, sizeof(vid_format));

	ret_code = ioctl(this->fdwr, VIDIOC_G_FMT, &vid_format);
	if(verbose)print_format(&vid_format);

	int lw = 0;
	int fw = 0;
	if(strcmp(this->outputPxFmt.c_str(), "YVU420")==0)
	{
		lw = this->outputWidth; /* ??? */
		fw = ROUND_UP_4 (this->outputWidth) * ROUND_UP_2 (this->outputHeight);
		fw += 2 * ((ROUND_UP_8 (this->outputWidth) / 2) * (ROUND_UP_2 (this->outputHeight) / 2));
	}

	if(strcmp(this->outputPxFmt.c_str(), "YUYV")==0 
		|| strcmp(this->outputPxFmt.c_str(), "UYVY")==0 )
	{
		lw = (ROUND_UP_2 (this->outputWidth) * 2);
		fw = lw * this->outputHeight;
	}

	vid_format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	vid_format.fmt.pix.width = this->outputWidth;
	vid_format.fmt.pix.height = this->outputHeight;
	vid_format.fmt.pix.pixelformat = 0;
	if(strcmp(this->outputPxFmt.c_str(), "YUYV")==0)
		vid_format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
	if(strcmp(this->outputPxFmt.c_str(), "UYVY")==0)
		vid_format.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
	if(strcmp(this->outputPxFmt.c_str(), "YVU420")==0)
		vid_format.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;
	if(strcmp(this->outputPxFmt.c_str(), "RGB24")==0)
		vid_format.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;

	vid_format.fmt.pix.sizeimage = lw;
	vid_format.fmt.pix.field = V4L2_FIELD_NONE;
	vid_format.fmt.pix.bytesperline = fw;
	vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;

	if(verbose)print_format(&vid_format);

	ret_code = ioctl(this->fdwr, VIDIOC_S_FMT, &vid_format);

	assert(ret_code != -1);

	this->framesize = vid_format.fmt.pix.sizeimage;
	int linewidth = vid_format.fmt.pix.bytesperline;
	if(verbose)printf("frame: format=%s\tsize=%d\n", this->outputPxFmt.c_str(), framesize);

	try
	{
	while(running)
	{
		usleep(1000);

		this->SendFrameInternal();

		pthread_mutex_lock(&this->lock);
		try
		{
			running = !this->stop;
		}
		catch(std::exception &err)
		{
			if(verbose) printf("An exception has occured: %s\n", err.what());
			running = 0;
		}
		pthread_mutex_unlock(&this->lock);
	}
	}
	catch(std::exception &err)
	{
		if(verbose) printf("An exception has occured: %s\n", err.what());
	}

	if(verbose) printf("Thread stopping\n");
	pthread_mutex_lock(&this->lock);
	this->stopped = 1;
	pthread_mutex_unlock(&this->lock);
}
示例#17
0
int cmd_dir(int ac, char **av)
{
  int handle=0;
  int rc;
  char filter=0;
  char paging=0;
  char all_list=0;

//display_puts("av[2]=");
//display_puts(av[0]);

  for(;;) {
    if(strncmp(av[0],"-d",3)==0) {
      filter = 'D';
    }
    else if(strncmp(av[0],"-p",3)==0) {
      paging = 1;
    }
    else if(strncmp(av[0],"-a",3)==0) {
      all_list = 1;
    }
    else {
      break;
    }

    av++;
    ac--;
    if(ac<1) {
      usage();
      return 0;
    }

  }

//display_puts("cdfs_open directory=");
//display_puts(av[0]);

//display_puts("all_list=");
//sint2dec(all_list,s);
//display_puts(s);

//display_puts("\n");

  handle = cdfs_open(av[0]);
  if(handle<0) {
    dsp_open_error(handle);
    goto EXITCMD;
  }

//  int i;
//  for(i=0;i<3;i++) {
  char linecnt=0;
  for(;;) {
    int rc;
    char type;
    char buf[sizeof(struct file_info)+CDFS_FULLPATH_MAXLENGTH];
    struct file_info *info=(void*)buf;
    rc = cdfs_readdir(handle,info,sizeof(buf));
    if(rc<0)
      break;
    if(info->attr & CDFS_ATTR_DIRECTORY)
      type='D';
    else
      type=' ';

    if((!(info->attr & CDFS_ATTR_HIDDEN)) || all_list) {
      if(filter==0 || filter==type) {
        print_format("%c %9d %s\n",type,info->size,info->name);
        linecnt++;
//syscall_wait(10);
      }
    }
    if(linecnt>20) {
      linecnt=0;
      if(paging) {
        char key;
        display_puts("--page(q=quit)--\n");
        key=keyboard_getcode();
        if(key=='q')
          break;
      }
    }
  }

EXITCMD:
  if(handle>0) {
//display_puts("cdfs_close\n");
    rc = cdfs_close(handle);
    if(rc<0) {
      display_puts("rc=");
      sint2dec(rc,s);
      display_puts(s);
    }
  }

  return 0;
}
示例#18
0
文件: alert.c 项目: grpascal/GEO
int main(int argc, char **argv)
{
	int ret;
	int counter=0;
	int count=0;
	video_format_t fmt;
	int ch_count = 0, channel;
	uint16_t hight;
	int framerate = 0;
	int goplen = 0;
	video_channel_info_t info;
	int audio_threshold = 70;
	int current_audio_intensity = 0;
	int reg_id;	/* region number; used when alert is generated */
	int x_offt;	/* starting x offset */
	int y_offt;	/* starting y offset */
	int width;	/* width of region */
	int height;	/* height of region */
	int sensitivity;	/* threshold for motion detection for a macroblock */
	int trigger_percentage;	/* % of macroblocks to be in motion for alert to be generated */
	char adata;
	char mdata;
	
	//initialize audio part **************************
	ret = mxuvc_audio_init("alsa","device = MAX64380");
	if(ret<0)
		goto error;

	ret = mxuvc_audio_register_cb(AUD_CH2, audio_cb, NULL);
	if(ret < 0)
		goto error;
	
	//TBD
	ret = mxuvc_audio_set_format(AUD_CH2, AUD_FORMAT_AAC_RAW);
	if(ret < 0)
		goto error;
	
	ret = mxuvc_audio_set_samplerate(AUD_CH2, SAMP_FREQ);
	if(ret < 0)
		goto error;

	mxuvc_audio_set_volume(100);

	//initialize video part **************************
	ret = mxuvc_video_init("v4l2","dev_offset=0");

	if(ret < 0)
		return 1;

	/* Register callback functions */
	ret = mxuvc_video_register_cb(CH1, ch_cb, (void*)CH1);
	if(ret < 0)
		goto error;
	
	printf("\n");
	//get channel count of MUX channel
	ret = mxuvc_video_get_channel_count(&ch_count);
	printf("Total Channel count: %d\n",ch_count);
	//remove raw channel from count
	ch_count = ch_count - 1;

	for(channel=CH2 ; channel<ch_count; channel++)
	{
		ret = mxuvc_video_register_cb(channel, ch_cb, (void*)channel);
		if(ret < 0)
			goto error;
	}

	/*** enquire every channel capabilities ****/
	for(channel=CH1; channel<ch_count ; channel++)
	{
		mxuvc_video_get_channel_info(channel, &info);
		printf("\nCH%d Channel Config:\n",channel+1);
		print_format(info.format);
		printf("width %d height %d\n",info.width,info.height);
		printf("framerate %dfps\n",info.framerate);
		
		if(info.format == VID_FORMAT_H264_RAW || 
				info.format == VID_FORMAT_H264_TS)
		{
			printf("gop length %d\n",info.goplen);	
			printf("setting gop length to 30\n");
			ret = mxuvc_video_set_goplen(channel, 30);
			if(ret < 0)
				goto error;
			ret = mxuvc_video_get_goplen(channel, &goplen);
			if(ret < 0)
				goto error;
			printf("gop length %d\n",goplen);
			printf("profile %d\n",info.profile);
			printf("bitrate %d\n",info.bitrate);
		}
	
	}

	printf("\n");
	video_profile_t profile;
	ret = mxuvc_video_get_profile(CH1, &profile);
	if(ret < 0)
		goto error;
	printf("CH1 profile %d\n",profile);
	ret = mxuvc_video_set_profile(CH1, PROFILE_BASELINE);
	if(ret < 0)
		goto error;
	printf("changed profile to PROFILE_BASELINE\n");
	ret = mxuvc_video_get_profile(CH1, &profile);
	if(ret < 0)
		goto error;
	printf("CH1 profile %d\n",profile);
	
	/***** Start audio  streaming ************/
	ret = mxuvc_audio_start(AUD_CH2);
	if(ret < 0)
		goto error;
	/***** Start video streaming ************/
	for(channel=CH1; channel<ch_count ; channel++){
		/* Start streaming */
		ret = mxuvc_video_start(channel);
		if(ret < 0)
			goto error;
	}

	/***** alert ************/
	if (audio_threshold > 0){
		//init audio alarm 
		ret = mxuvc_alert_init();
		if(ret < 0)
			goto error;
		ret = mxuvc_alert_audio_enable(	aalarm_callback, (void *)&adata);

		if (ret){
			printf("mxuvc_alert_audio_enable() failed\n");
			goto error;
		}
		//motion alert
		ret = mxuvc_alert_motion_enable(malarm_callback, (void *)&mdata);
		if (ret){
			printf("mxuvc_alert_motion_enable() failed\n");
			goto error;
		}
		//set region
		reg_id = 0;
		x_offt = 0;
		y_offt = 0;
		width = 80;
		height = 45;
		sensitivity = 50;
		trigger_percentage = 100;
		ret = mxuvc_alert_motion_add_region(reg_id, x_offt, y_offt, width, 
						height);
		if (ret){
			printf("mxuvc_alert_motion_add_region() failed\n");
			goto error;
		}
		ret =  mxuvc_alert_motion_sensitivity_and_level(reg_id,sensitivity,
		        trigger_percentage);
		if (ret){
		    printf("mxuvc_alert_motion_sensitivity_and_level() failed\n");
		    goto error;
		}

		//enable audio alert again to test
		ret = mxuvc_alert_audio_set_threshold(50);

		if (ret){
		    printf("mxuvc_alert_audio_set_threshold() failed\n");
		    goto error;
		}
	}
	
	//sleep
	usleep(50000);

	/* Main 'loop' */
	if (argc > 1){
		counter = atoi(argv[1]);
	} else
		counter = 15;

	while(counter--) {
		if (!mxuvc_audio_alive() || !mxuvc_video_alive())
			goto error;
		printf("\r%i secs left", counter+1);

		//video_testing(counter);
		//get current audio intensity
		ret = mxuvc_get_current_audio_intensity(&current_audio_intensity);
		if(ret){
			printf("mxuvc_get_current_audio_intensity() failed\n");
			goto error;
		}else
			printf("Current audio intensity %ddB\n",current_audio_intensity);

		if(counter == 10){
			mxuvc_alert_audio_disable();
		}
		if(counter == 9)
			mxuvc_alert_motion_disable();

		if(counter == 8){
			ret = mxuvc_alert_audio_set_threshold(audio_threshold);
			if (ret){
			    printf("mxuvc_alert_audio_set_threshold() failed\n");
			    goto error;
			}
			ret = mxuvc_alert_audio_enable(	aalarm_callback, (void *)&adata);

			if (ret){
			    printf("mxuvc_alert_audio_enable() failed\n");
			    goto error;
			}
		}
		if(counter == 7){
			ret = mxuvc_alert_motion_enable(malarm_callback, (void *)&mdata);
			if (ret){
				printf("mxuvc_alert_motion_enable() failed\n");
				goto error;
			}
		}
		fflush(stdout);
		sleep(1);
	}	

	if (audio_threshold > 0){
		ret = mxuvc_alert_motion_remove_region(reg_id);
		if (ret){
			printf("mxuvc_alert_motion_remove_region() failed\n");
			goto error;
		}
		mxuvc_alert_audio_disable();
		mxuvc_alert_motion_disable();
		sleep(1);
	}
	mxuvc_alert_deinit();

	/* Stop audio streaming */
	ret = mxuvc_audio_stop(AUD_CH2);
	if(ret < 0)
		goto error;

	mxuvc_audio_deinit();
	
	/* Stop video streaming */
	for(channel=CH1; channel<ch_count ; channel++)
	{	
		/* Stop streaming */
		ret = mxuvc_video_stop(channel);
		if(ret < 0)
			goto error;
	}
	/* Deinitialize and exit */
	mxuvc_video_deinit();
	
	close_fds();
	
	return 0;

error:
	mxuvc_audio_deinit();

	close_fds();	

	printf("Failed\n");
	return 1;
}
int main(int argc, char **argv)
{
	int ret;
	int i, counter=0;
	int count=0;
	video_format_t fmt;
	int ch_count = 0;
	long channel;
	uint16_t hight;
	int framerate = 0;
	int goplen = 0;
	video_channel_info_t info;
        int timer = 0;
        int frame_num = 0;
	char adata;
	char mdata;
	char *file = NULL;
	int font_size;
        time_t curtime;
        struct tm *loc_time;
        char szDate[16] = {0};

        if ( argc < 2 ){
                printf("USAGE: sudo overlay_text <path to font file> <size of font> [enable timer 0/1(default 0)] [enable frame numbering 0/1(default 0)\n");
                return 0;
        }

	//initialize video part **************************
	ret = mxuvc_video_init("v4l2","dev_offset=0");

	if(ret < 0)
		return 1;
	/* Main 'loop' */
	if (argc > 1){
		file = argv[1];
	}

	if (argc > 2){
		font_size = atoi(argv[2]);	
	} else
		font_size = 8;
	

	if (argc > 3){
		timer = atoi(argv[3]);	
	} else
		timer = 0;

	if (argc > 4){
		frame_num = atoi(argv[4]);	
	} else
		frame_num = 0;

        printf("YOUR CONFIGURATION timer %d and frame number %d\n",timer,frame_num);

        curtime = time (NULL);
        loc_time = localtime (&curtime); 
        printf("%s", asctime (loc_time));

	snprintf(szDate, 11, "%04d-%02d-%02d ", (loc_time->tm_year+1900), (loc_time->tm_mon+1), loc_time->tm_mday);
	printf("Date = %s\n", szDate);

	ret = mxuvc_overlay_init();

    /* Register callback functions */
	ret = mxuvc_video_register_cb(CH1, ch_cb, (void*)CH1);
	if(ret < 0)
		goto error;
	
	printf("\n");
	//get channel count of MUX channel
	ret = mxuvc_video_get_channel_count(&ch_count);
	printf("Total Channel count: %d\n",ch_count);
	//remove raw channel from count
	ch_count = ch_count - 1;

	for(channel=CH2 ; channel<ch_count; channel++)
	{
		ret = mxuvc_video_register_cb(channel, ch_cb, (void*)channel);
		if(ret < 0)
			goto error;
	}
	for(channel=CH1; channel<ch_count ; channel++)
    { 
    	ret = mxuvc_overlay_load_font(channel, font_size, file);	
		if(ret < 0)
	  		return 1;
		printf("overlay init done for ch %ld\n", channel);
	}

	/*** enquire every channel capabilities ****/
	for(channel=CH1; channel<ch_count ; channel++)
	{
		mxuvc_video_get_channel_info(channel, &info);
		printf("\nCH%ld Channel Config:\n",channel+1);
		print_format(info.format);
		printf("width %d height %d\n",info.width,info.height);
		printf("framerate %dfps\n",info.framerate);
		
		if(info.format == VID_FORMAT_H264_RAW || 
				info.format == VID_FORMAT_H264_TS)
		{
			//printf("gop length %d\n",info.goplen);	
			//printf("setting gop length to 30\n");
			ret = mxuvc_video_set_goplen(channel, 30);
			if(ret < 0)
				goto error;
			ret = mxuvc_video_get_goplen(channel, &goplen);
			if(ret < 0)
				goto error;
			//printf("gop length %d\n",goplen);
			//printf("profile %d\n",info.profile);
			//printf("bitrate %d\n",info.bitrate);
		}
	
	}

	printf("\n");
	video_profile_t profile;
	ret = mxuvc_video_get_profile(CH1, &profile);
	if(ret < 0)
		goto error;
	printf("CH1 profile %d\n",profile);
	ret = mxuvc_video_set_profile(CH1, PROFILE_BASELINE);
	if(ret < 0)
		goto error;
	printf("changed profile to PROFILE_BASELINE\n");
	ret = mxuvc_video_get_profile(CH1, &profile);
	if(ret < 0)
		goto error;
	printf("CH1 profile %d\n",profile);

	/***** Start video streaming ************/
	for(channel=CH1; channel<ch_count ; channel++){
		/* Start streaming */
		ret = mxuvc_video_start(channel);
		if(ret < 0)
			goto error;
	}

	//sleep
	usleep(5000);
	counter = 20;
	overlay_text_params_t ovtext[NUM_MUX_VID_CHANNELS][NUM_OVERLAY_TEXT_IDX];
	overlay_text_params_t ovtime;
	overlay_time_t btime;

	for(i = 0; i < sizeof(ovtext)/sizeof(overlay_text_params_t); i++) {
		memset(&ovtext[0][i], 0x00, sizeof(overlay_text_params_t));
	}

	memset(&ovtime, 0x00, sizeof(overlay_text_params_t));

	while(counter--) {
		if (!mxuvc_video_alive())
			goto error;
		printf("%i secs left\n", counter+1);

		if(counter == 18)
		{
                
			for(channel=CH1; channel < ch_count; channel++)
			{
				int ch = channel;

				memset(&btime,   0x00, sizeof(overlay_time_t));

				ovtext[ch][0].xoff = 0;
				ovtext[ch][0].yoff = 0;
				ovtext[ch][0].idx = 0;
				ret = mxuvc_overlay_add_text(channel, &ovtext[ch][0], szText0, strlen(szText0));
					if(ret < 0)
						goto error;

				ovtext[ch][1].xoff = 0;
				ovtext[ch][1].yoff = 100; 
				ovtext[ch][1].idx = 1;
				ret = mxuvc_overlay_add_text(channel, &ovtext[ch][1], szText1, strlen(szText1));
					if(ret < 0)
						goto error;

				ovtext[ch][2].xoff = 0;
				ovtext[ch][2].yoff = 200;
				ovtext[ch][2].idx = 2;

				ret = mxuvc_overlay_add_text(channel, &ovtext[ch][2], szDate, strlen(szDate));
					if(ret < 0)
						goto error;

				ovtext[ch][3].xoff = 0;
				ovtext[ch][3].yoff = 300;
				ovtext[ch][3].idx = 3;

				ret = mxuvc_overlay_add_text(channel, &ovtext[ch][3], szText2, strlen(szText2));
					if(ret < 0)
						goto error;

				ovtext[ch][4].xoff = 0;
				ovtext[ch][4].yoff = 400;
				ovtext[ch][4].idx = 4;

				ret = mxuvc_overlay_add_text(channel, &ovtext[ch][4], szText2, strlen(szText2));
					if(ret < 0)
						goto error;

			}
		}

		if(counter == 15 && timer == 1 )
		{
		
			for(channel=CH1; channel < ch_count; channel++)
			{
				int ch = channel;
			
				ovtime.xoff = 0;
				ovtime.yoff = 500;

				btime.hh = loc_time->tm_hour;
				btime.mm = loc_time->tm_min;
				btime.ss = loc_time->tm_sec;
				btime.frame_num_enable = frame_num;

				ret = mxuvc_overlay_set_time(channel, &ovtime, &btime);
				if(ret < 0)
					goto error;
				ret = mxuvc_overlay_show_time(channel);
				if(ret < 0)
					goto error;
			}
		}


		if(counter == 5)
		{
			printf("Removing text\n");

			for(channel=CH1; channel<ch_count ; channel++)
			{

				int ch = channel;		
				printf("from ch: %d\n",ch);
				ret = mxuvc_overlay_remove_text(channel, ovtext[ch][0].idx);
				if(ret < 0)
					goto error;

				ret = mxuvc_overlay_remove_text(channel, ovtext[ch][1].idx);
				if(ret < 0)
					goto error;

				ret = mxuvc_overlay_remove_text(channel, ovtext[ch][2].idx);
				if(ret < 0)
					goto error;

				ret = mxuvc_overlay_remove_text(channel, ovtext[ch][3].idx);
				if(ret < 0)
					goto error;

				ret = mxuvc_overlay_remove_text(channel, ovtext[ch][4].idx);
				if(ret < 0)
					goto error;

				ret = mxuvc_overlay_hide_time(channel);
				if(ret < 0)
					goto error;
			}
		}

		fflush(stdout);
		sleep(1);
	}	
	ret = mxuvc_overlay_deinit();	
	if(ret < 0)
		goto error;

	/* Stop video streaming */
	for(channel=CH1; channel<ch_count ; channel++)
	{	
		/* Stop streaming */
		ret = mxuvc_video_stop(channel);
		if(ret < 0)
			goto error;
	}
	/* Deinitialize and exit */
	mxuvc_video_deinit();
	
	close_fds();
	
	return 0;

error:
	//mxuvc_audio_deinit();
	mxuvc_video_deinit();

	close_fds();	

	printf("Failed\n");
	return 1;
}
示例#20
0
ssize_t xb_snd_mixer_write(struct file *file,
		const char __user *buffer,
		size_t count,
		loff_t *ppos,
		struct snd_dev_data *ddata)
{
	char buf_byte;
	char buf_vol[3];
	int volume = 0;
	unsigned long fmt_in = 0;
	unsigned long fmt_out = 0;
	unsigned int channels_in = 0;
	unsigned int  channels_out = 0;
	unsigned long rate_in = 0;
	unsigned long rate_out = 0;
	unsigned hp_state = 0;
	unsigned long devices = 0;
	//int mode = 3;
	if (copy_from_user((void *)&buf_byte, buffer, 1)) {
		printk("JZ MIX: copy_from_user failed !\n");
		return -EFAULT;
	}

	switch (buf_byte) {
		case '1' :
			printk(" \"1\" command :print codec and aic register.\n");
			if(ddata->dev_ioctl)
				ddata->dev_ioctl(SND_MIXER_DUMP_REG,0);
			else if(ddata->dev_ioctl_2)
				ddata->dev_ioctl_2(ddata, SND_MIXER_DUMP_REG,0);

			break;
		case '2':
			printk(" \"2\" command :print audio hp and speaker gpio state.\n");
			if(ddata->dev_ioctl)
				ddata->dev_ioctl(SND_MIXER_DUMP_GPIO,0);
			else if(ddata->dev_ioctl_2)
				ddata->dev_ioctl_2(ddata, SND_MIXER_DUMP_GPIO,0);
			break;
		case '3':
			printk(" \"3\" command :print current format channels and rate.\n");
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_GET_RECORD_FMT, (unsigned long)&fmt_in);
				ddata->dev_ioctl(SND_DSP_GET_REPLAY_FMT, (unsigned long)&fmt_out);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_GET_RECORD_FMT, (unsigned long)&fmt_in);
				ddata->dev_ioctl_2(ddata, SND_DSP_GET_REPLAY_FMT, (unsigned long)&fmt_out);
			}
			printk("record format : ");
			print_format(fmt_in);
			printk("replay format : ");
			print_format(fmt_out);
			if(ddata->dev_ioctl) {
			ddata->dev_ioctl(SND_DSP_GET_RECORD_CHANNELS,(unsigned long)&channels_in);
			ddata->dev_ioctl(SND_DSP_GET_REPLAY_CHANNELS,(unsigned long)&channels_out);
			//printk("record channels : %d.\n", channels_in);
			//printk("replay channels : %d.\n", channels_out);
			ddata->dev_ioctl(SND_DSP_GET_RECORD_RATE,(unsigned long)&rate_in);
			ddata->dev_ioctl(SND_DSP_GET_REPLAY_RATE,(unsigned long)&rate_out);
			//printk("record samplerate : %ld.\n", rate_in);
			//printk("replay samplerate : %ld.\n", rate_out);
			} else if(ddata->dev_ioctl_2) {
			ddata->dev_ioctl_2(ddata, SND_DSP_GET_RECORD_CHANNELS,(unsigned long)&channels_in);
			ddata->dev_ioctl_2(ddata, SND_DSP_GET_REPLAY_CHANNELS,(unsigned long)&channels_out);
			//printk("record channels : %d.\n", channels_in);
			//printk("replay channels : %d.\n", channels_out);
			ddata->dev_ioctl_2(ddata, SND_DSP_GET_RECORD_RATE,(unsigned long)&rate_in);
			ddata->dev_ioctl_2(ddata, SND_DSP_GET_REPLAY_RATE,(unsigned long)&rate_out);
			//printk("record samplerate : %ld.\n", rate_in);
			//printk("replay samplerate : %ld.\n", rate_out);

			}
			break;
		case '4':
			printk(" \"4\" command:print headphone detect state.\n");
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_GET_HP_DETECT,(unsigned long)&hp_state);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_GET_HP_DETECT,(unsigned long)&hp_state);
			}
			printk("headphone state : %d.\n ",hp_state);
			break;
		case '5':
			printk(" \"5\" set headphone route.\n");
			devices = SND_DEVICE_HEADSET;
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_SET_DEVICE,(unsigned long)&devices);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_SET_DEVICE,(unsigned long)&devices);
			}
			break;
		case '6':
			printk(" \"6\" set speaker route.\n");
			devices = SND_DEVICE_SPEAKER;
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_SET_DEVICE,(unsigned long)&devices);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_SET_DEVICE,(unsigned long)&devices);
			}
			break;
		case '7':
			printk(" \"7\" set loop test route for phone.\n");
			devices = SND_DEVICE_LOOP_TEST;
			//ddata->dev_ioctl(SND_DSP_SET_DEVICE,(unsigned long)&devices);
			break;
		case '8':
			printk(" \"8\" set linein/buildmic route.\n");
			devices = SND_DEVICE_BUILDIN_MIC;
			//ddata->dev_ioctl(SND_DSP_SET_DEVICE,(unsigned long)&devices);
			break;
		case 'c':
			/*printk(" \"c\" clear rount 1 CODEC_RMODE ,2 CODEC_WMODE ,3 CODEC_RWMODE\n");
			if(copy_from_user((void *)buf_vol, buffer, 2)) {
				return -EFAULT;
			}
			mode = (buf_vol[1] - '0');
			printk("audio clear %s route.\n",mode == CODEC_RMODE ? "read" :
					mode == CODEC_WMODE ? "write" : "all");
			mode = 3;
			ddata->dev_ioctl(SND_DSP_SET_MIC_VOL,(unsigned long)mode);*/
			break;
		case 'L':
			printk(" \"l\" set line in route\n");
			if(copy_from_user((void *)buf_vol, buffer, 3)) {
				return -EFAULT;
			}
			devices = SND_DEVICE_LINEIN_RECORD;
			if(buf_vol[1] == '1') {
				printk("set linein route :%c\n", buf_vol[1]);
				devices = SND_DEVICE_LINEIN1_RECORD;
			} else if(buf_vol[1] == '2') {
				printk("set linein route :%c\n", buf_vol[1]);
				devices = SND_DEVICE_LINEIN2_RECORD;
			} else {
				printk("line in route not support:%c, default to linein 0\n", buf_vol[1]);
				devices = SND_DEVICE_LINEIN_RECORD;
			}

			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_SET_DEVICE,(unsigned long)&devices);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_SET_DEVICE,(unsigned long)&devices);
			}
			break;
		case 'm':
			printk(" \"m\" set mic volume 0 ~ 20db\n");
			if(copy_from_user((void *)buf_vol, buffer, 3)) {
				return -EFAULT;
			}
			volume = (buf_vol[1] - '0') * 10 + (buf_vol[2] - '0');
			printk("mic volume is %d.\n",volume);
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_SET_MIC_VOL,(unsigned long)&volume);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_SET_MIC_VOL,(unsigned long)&volume);
			}
			printk("mic volume is %d.\n",volume);
			break;
		case 'v':
			printk(" \"v\" set record adc  volume 0 ~ 23db\n");
			if(copy_from_user((void *)buf_vol, buffer, 3)) {
				return -EFAULT;
			}
			volume = (buf_vol[1] - '0') * 10 + (buf_vol[2] - '0');
			if(ddata->dev_ioctl) {
				ddata->dev_ioctl(SND_DSP_SET_RECORD_VOL,(unsigned long)&volume);
			} else if(ddata->dev_ioctl_2) {
				ddata->dev_ioctl_2(ddata, SND_DSP_SET_RECORD_VOL,(unsigned long)&volume);
			}
			printk("record volume is %d.\n",volume);
			break;
		case 'd':
			printk("\"d\" misc debug\n");
			if(copy_from_user((void *)buf_vol, buffer, 2)) {
				printk("audio misc debug default opreation\n");
				if(ddata->dev_ioctl)
					ddata->dev_ioctl(SND_DSP_DEBUG,0);
				else if(ddata->dev_ioctl_2)
					ddata->dev_ioctl_2(ddata, SND_DSP_DEBUG,0);


			} else {
				printk("audio misc debug interface NO %c\n",buf_vol[1]);
				if(ddata->dev_ioctl)
					ddata->dev_ioctl(SND_DSP_DEBUG,(unsigned long)buf_vol[1]);
				else if(ddata->dev_ioctl_2)
					ddata->dev_ioctl_2(ddata, SND_DSP_DEBUG,(unsigned long)buf_vol[1]);
			}
			break;
		default:
			printk("undefine debug interface \"%c\".\n", buf_byte);
			printk(" \"1\" command :print codec and aic register.\n");
			printk(" \"2\" command :print audio hp and speaker gpio state.\n");
			printk(" \"3\" command :print current format channels and rate.\n");
			printk(" \"4\" command:print headphone detect state.\n");
			printk(" \"5\" set headphone route.\n");
			printk(" \"6\" set speaker route.\n");
			printk(" \"7\" set loop test route for phone.\n");
			printk(" \"c\" clear rount 1 CODEC_RMODE ,2 CODEC_WMODE ,3 CODEC_RWMODE\n");
			printk(" \"m[db]\" set mic volume (db = 0 ~ 20)\n");
			printk(" \"v[db]\" set record adc volume (db = 0 ~ 23)\n");
			printk(" \"d[debug interface No]\" misc debug\n");
	}
	return count;
}
示例#21
0
int main(int argc,char ** argv){
	formula *current,*old;
	parserResult *result;
	wwb* wwb,* oldWwb;
	wwbList* list;
	wwbListIterator it;
	char *out;
	int verifiable=0,carry=0;
	char *example="((A0*A1*-A2)+(A0*A3*-A1*A2)+(A0*-A0*A3*A2)+(A0*-A3*A2)+(A0*A4*-A5))";//"(A0*(A0>(A1+A3))*((A0*A3)>A1)*(-A1+A2)*(-A1+-A2))";

	if( argc == 1 ){
		printf("Benutzung: %s <formel>\n",argv[0]);
		result=string_to_formula_parser(example);
	}else{
		// testen des ersten Arguments
		result=string_to_formula_parser(argv[1]);
	}
	if( result->error || *(result->rest) != 0 ){
		// es ist keine Formel!
		int pos=result->rest-argv[1];
		printf("Nein, falsches Zeichen an Position %d: %s\n",pos,result->rest);
		free(result);
		return 1;
	}
	// es ist eine Formel
	printf("Ja!\n");

	old=result->formula;

	current=remove_abbreviations(old);
	free(old);
	printf("Ohne Abkürzungen: ");
	print_format(current);
	printf("\n");
	old=current;

	current=nnf(old);
	printf("NNF: ");
	print_format(current);
	printf("\n");
	free_formula(current);

/*	current=dnf(old);
	printf("DNF: ");
	print_format(current);
	printf("\n");
	free_formula(current);

	current=knf(old);
	printf("KNF: ");
	print_format(current);
	printf("\n");
	free_formula(current);*/

	wwb=wwb_from_formula(old);

	list=is_verifiable_bf(old,wwb);
	it=wwb_list_iterator_get(list);

	out=(char *) malloc(sizeof(char)*100);
	wwb_to_row_head_string(wwb,out);
	printf("\n%s\n",out);
	free(out);

	while( wwb_list_iterator_valid(it) ){
		out=(char *) malloc(sizeof(char)*100);
		wwb_to_row_string(wwb_list_iterator_wbb(it),out);
		printf("%s\n",out);
		free(out);
		it=wwb_list_iterator_next(it);
	}

	wwb=new_wwb();

	verifiable=formula_is_verifiable_dpll(old,wwb);
	if( verifiable ){
		printf("Wahr für:\n");
		print_wwb(wwb);
	}else{
		printf("Widerspruch\n");
	}

	oldWwb=wwb;
	wwb=wwb_from_formula(old);
	wwb_copy_to(oldWwb,wwb);

	out=(char *) malloc(sizeof(char)*100);
	wwb_to_row_head_string(wwb,out);
	printf("\n%s\n",out);
	free(out);

	while( !carry ){
		oldWwb=wwb;
		if( formula_evaluate(old,wwb) ){
			out=(char *) malloc(sizeof(char)*100);
			wwb_to_row_string(wwb,out);
			printf("%s\n",out);
			free(out);
		}
		wwb=wwb_successor(oldWwb,&carry);
		free_wwb(oldWwb);
	}
	free_wwb(wwb);

	free(result);

	return 0;
}
示例#22
0
int
start_linux(void)
{
    void (*theKernel)(uint32_t zero, uint32_t arch, uint32_t *params);
    uint32_t i = 0, j = 0,ret;
    load_addr = (uint32_t) ZIMAGE_LOAD_ADDRESS;
    uint32_t *exec_at =  ZIMAGE_LOAD_ADDRESS;
    uint32_t *parm_at = (uint32_t *)( DRAM_BASE + 0x100) ;  // 256 bytes away from the base address of DRAM
    uint32_t machine_type;

   // debug_print("about to copy linux image to load address: ");
   //     uart_print_address(exec_at);
   //	ret = load_image((uint32_t)ZIMAGE_START_BLOCK_NUMBER,(uint32_t*)exec_at,(uint16_t)2666);    /* copy image into RAM */

   // debug_print("done copying linux image ...\n\r");

//    debug_print("about to copy ramdisk image ...");

//    load_image((uint32_t*) INITRD_LOAD_ADDRESS, INITRD_LOAD_END_ADDRESS);/* copy initial ramdisk image into RAM */

//    debug_print("done copying ramdisk image ...");


    theKernel = (void (*)(uint32_t, uint32_t, uint32_t*))exec_at; /* set the kernel address */
    
	
	

	print_format("Setting up timers next ...\n\r");
	init_system_timer();	
	init_timer();
//	uint32_t start_time = get_timer(0);
//
//	while(1){
//		print_format("time difference in ms is %d\n\r",start_time - get_timer(0));
//		udelay(1000000);
//	}
	print_format("fetching kernel ... \n\r");
	net_loop(TFTPGET);
//	net_loop(ARP);
	print_format("kernel loaded to RAM ...\n\r");
    	debug_print("setting up ATAGS ...\n\r");

    	setup_tags(parm_at);                    /* sets up parameters */

    	machine_type = 3466;	              /* get machine type */

	debug_print("jumping to the kernel ... brace yourself!\n\r\0");
 
	asm("mrc p15, 0, r1, c1, c0, 0"); /* Read Control Register configuration data*/
	asm("bic r1, r1, #(0x1 << 12)");  /* Disable I Cache*/
	asm("bic r1, r1, #(0x1 << 2)");   /* Disable D Cache*/
	asm("mcr p15, 0, r1, c1, c0, 0"); /* Write Control Register configuration data*/

	theKernel(0, machine_type, parm_at);    /* jump to kernel with registers set */

//	uint32_t start_time = get_timer(0);

//	while(1){
//		print_format("time difference in ms is %d\n\r",get_timer(start_time));
//		udelay(1000000);
//	}

    return 0;
}
示例#23
0
/*****************************************************************************
 * Setup a encoded digital stream (SPDIF)
 *****************************************************************************/
static int OpenSPDIF(void)
{
    OSStatus                    err = noErr;
    UInt32                      i_param_size, b_mix = 0;
    Boolean                     b_writeable = 0;
    AudioStreamID               *p_streams = NULL;
    int                         i, i_streams = 0;
    AudioObjectPropertyAddress  property_address;

    /* Start doing the SPDIF setup process. */
    ao->b_digital = 1;

    /* Hog the device. */
    ao->i_hog_pid = getpid() ;

    err = SetAudioProperty(ao->i_selected_dev,
                           kAudioDevicePropertyHogMode,
                           sizeof(ao->i_hog_pid), &ao->i_hog_pid);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "failed to set hogmode: [%4.4s]\n", (char *)&err);
        ao->i_hog_pid = -1;
        goto err_out;
    }

    /* Set mixable to false if we are allowed to. */
    err = IsAudioPropertySettable(ao->i_selected_dev,
                                  kAudioDevicePropertySupportsMixing,
                                  &b_writeable);
    err = GetAudioProperty(ao->i_selected_dev,
                           kAudioDevicePropertySupportsMixing,
                           sizeof(UInt32), &b_mix);
    if (err != noErr && b_writeable)
    {
        b_mix = 0;
        err = SetAudioProperty(ao->i_selected_dev,
                               kAudioDevicePropertySupportsMixing,
                               sizeof(UInt32), &b_mix);
        ao->b_changed_mixing = 1;
    }
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n", (char *)&err);
        goto err_out;
    }

    /* Get a list of all the streams on this device. */
    i_param_size = GetAudioPropertyArray(ao->i_selected_dev,
                                         kAudioDevicePropertyStreams,
                                         kAudioDevicePropertyScopeOutput,
                                         (void **)&p_streams);

    if (!i_param_size) {
        ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streams.\n");
        goto err_out;
    }

    i_streams = i_param_size / sizeof(AudioStreamID);

    ao_msg(MSGT_AO, MSGL_V, "current device stream number: %d\n", i_streams);

    for (i = 0; i < i_streams && ao->i_stream_index < 0; ++i)
    {
        /* Find a stream with a cac3 stream. */
        AudioStreamBasicDescription *p_format_list = NULL;
        int i_formats = 0, j = 0, b_digital = 0;

        i_param_size = GetGlobalAudioPropertyArray(p_streams[i],
                                                   kAudioStreamPropertyPhysicalFormats,
                                                   (void **)&p_format_list);

        if (!i_param_size) {
            ao_msg(MSGT_AO, MSGL_WARN,
                   "Could not get number of stream formats.\n");
            continue;
        }

        i_formats = i_param_size / sizeof(AudioStreamBasicDescription);

        /* Check if one of the supported formats is a digital format. */
        for (j = 0; j < i_formats; ++j)
        {
            if (p_format_list[j].mFormatID == 'IAC3' ||
                  p_format_list[j].mFormatID == kAudioFormat60958AC3)
            {
                b_digital = 1;
                break;
            }
        }

        if (b_digital)
        {
            /* If this stream supports a digital (cac3) format, then set it. */
            int i_requested_rate_format = -1;
            int i_current_rate_format = -1;
            int i_backup_rate_format = -1;

            ao->i_stream_id = p_streams[i];
            ao->i_stream_index = i;

            if (ao->b_revert == 0)
            {
                /* Retrieve the original format of this stream first if not done so already. */
                err = GetAudioProperty(ao->i_stream_id,
                                       kAudioStreamPropertyPhysicalFormat,
                                       sizeof(ao->sfmt_revert), &ao->sfmt_revert);
                if (err != noErr)
                {
                    ao_msg(MSGT_AO, MSGL_WARN,
                           "Could not retrieve the original stream format: [%4.4s]\n",
                           (char *)&err);
                    if (p_format_list) free(p_format_list);
                    continue;
                }
                ao->b_revert = 1;
            }

            for (j = 0; j < i_formats; ++j)
                if (p_format_list[j].mFormatID == 'IAC3' ||
                      p_format_list[j].mFormatID == kAudioFormat60958AC3)
                {
                    if (p_format_list[j].mSampleRate == ao->stream_format.mSampleRate)
                    {
                        i_requested_rate_format = j;
                        break;
                    }
                    if (p_format_list[j].mSampleRate == ao->sfmt_revert.mSampleRate)
                        i_current_rate_format = j;
                    else if (i_backup_rate_format < 0 || p_format_list[j].mSampleRate > p_format_list[i_backup_rate_format].mSampleRate)
                        i_backup_rate_format = j;
                }

            if (i_requested_rate_format >= 0) /* We prefer to output at the samplerate of the original audio. */
                ao->stream_format = p_format_list[i_requested_rate_format];
            else if (i_current_rate_format >= 0) /* If not possible, we will try to use the current samplerate of the device. */
                ao->stream_format = p_format_list[i_current_rate_format];
            else ao->stream_format = p_format_list[i_backup_rate_format]; /* And if we have to, any digital format will be just fine (highest rate possible). */
        }
        if (p_format_list) free(p_format_list);
    }
    if (p_streams) free(p_streams);

    if (ao->i_stream_index < 0)
    {
        ao_msg(MSGT_AO, MSGL_WARN,
               "Cannot find any digital output stream format when OpenSPDIF().\n");
        goto err_out;
    }

    print_format(MSGL_V, "original stream format:", &ao->sfmt_revert);

    if (!AudioStreamChangeFormat(ao->i_stream_id, ao->stream_format))
        goto err_out;

    property_address.mSelector = kAudioDevicePropertyDeviceHasChanged;
    property_address.mScope    = kAudioObjectPropertyScopeGlobal;
    property_address.mElement  = kAudioObjectPropertyElementMaster;

    err = AudioObjectAddPropertyListener(ao->i_selected_dev,
                                         &property_address,
                                         DeviceListener,
                                         NULL);
    if (err != noErr)
        ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceAddPropertyListener for kAudioDevicePropertyDeviceHasChanged failed: [%4.4s]\n", (char *)&err);


    /* FIXME: If output stream is not native byte-order, we need change endian somewhere. */
    /*        Although there's no such case reported.                                     */
#if HAVE_BIGENDIAN
    if (!(ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian))
#else
    if (ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
#endif
        ao_msg(MSGT_AO, MSGL_WARN,
               "Output stream has non-native byte order, digital output may fail.\n");

    /* For ac3/dts, just use packet size 6144 bytes as chunk size. */
    ao->chunk_size = ao->stream_format.mBytesPerPacket;

    ao_data.samplerate = ao->stream_format.mSampleRate;
    ao_data.channels = ao->stream_format.mChannelsPerFrame;
    ao_data.bps = ao_data.samplerate * (ao->stream_format.mBytesPerPacket/ao->stream_format.mFramesPerPacket);
    ao_data.outburst = ao->chunk_size;
    ao_data.buffersize = ao_data.bps;

    ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
    ao->buffer_len = ao->num_chunks * ao->chunk_size;
    ao->buffer = av_fifo_alloc(ao->buffer_len);

    ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);


    /* Create IOProc callback. */
    err = AudioDeviceCreateIOProcID(ao->i_selected_dev,
                                    (AudioDeviceIOProc)RenderCallbackSPDIF,
                                    (void *)ao,
                                    &ao->renderCallback);

    if (err != noErr || ao->renderCallback == NULL)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceAddIOProc failed: [%4.4s]\n", (char *)&err);
        goto err_out1;
    }

    reset();

    return CONTROL_TRUE;

err_out1:
    if (ao->b_revert)
        AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert);
err_out:
    if (ao->b_changed_mixing && ao->sfmt_revert.mFormatID != kAudioFormat60958AC3)
    {
        int b_mix = 1;
        err = SetAudioProperty(ao->i_selected_dev,
                               kAudioDevicePropertySupportsMixing,
                               sizeof(int), &b_mix);
        if (err != noErr)
            ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n",
                   (char *)&err);
    }
    if (ao->i_hog_pid == getpid())
    {
        ao->i_hog_pid = -1;
        err = SetAudioProperty(ao->i_selected_dev,
                               kAudioDevicePropertyHogMode,
                               sizeof(ao->i_hog_pid), &ao->i_hog_pid);
        if (err != noErr)
            ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n",
                   (char *)&err);
    }
    av_fifo_free(ao->buffer);
    free(ao);
    ao = NULL;
    return CONTROL_FALSE;
}
示例#24
0
static int init(int rate,int channels,int format,int flags)
{
AudioStreamBasicDescription inDesc;
ComponentDescription desc;
Component comp;
AURenderCallbackStruct renderCallback;
OSStatus err;
UInt32 size, maxFrames, b_alive;
char *psz_name;
AudioDeviceID devid_def = 0;
int device_id, display_help = 0;

    const opt_t subopts[] = {
        {"device_id", OPT_ARG_INT,  &device_id,    NULL},
        {"help",      OPT_ARG_BOOL, &display_help, NULL},
        {NULL}
    };

    // set defaults
    device_id = 0;

    if (subopt_parse(ao_subdevice, subopts) != 0 || display_help) {
        print_help();
        if (!display_help)
            return 0;
    }

    ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n", rate, channels, af_fmt2str_short(format), flags);

    ao = calloc(1, sizeof(ao_coreaudio_t));

    ao->i_selected_dev = 0;
    ao->b_supports_digital = 0;
    ao->b_digital = 0;
    ao->b_muted = 0;
    ao->b_stream_format_changed = 0;
    ao->i_hog_pid = -1;
    ao->i_stream_id = 0;
    ao->i_stream_index = -1;
    ao->b_revert = 0;
    ao->b_changed_mixing = 0;

    if (device_id == 0) {
        /* Find the ID of the default Device. */
        err = GetAudioProperty(kAudioObjectSystemObject,
                               kAudioHardwarePropertyDefaultOutputDevice,
                               sizeof(UInt32), &devid_def);
        if (err != noErr)
        {
            ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device: [%4.4s]\n", (char *)&err);
            goto err_out;
        }
    } else {
        devid_def = device_id;
    }

    /* Retrieve the name of the device. */
    err = GetAudioPropertyString(devid_def,
                                 kAudioObjectPropertyName,
                                 &psz_name);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device name: [%4.4s]\n", (char *)&err);
        goto err_out;
    }

    ao_msg(MSGT_AO,MSGL_V, "got audio output device ID: %"PRIu32" Name: %s\n", devid_def, psz_name );

    /* Probe whether device support S/PDIF stream output if input is AC3 stream. */
    if (AF_FORMAT_IS_AC3(format)) {
        if (AudioDeviceSupportsDigital(devid_def))
        {
            ao->b_supports_digital = 1;
        }
        ao_msg(MSGT_AO, MSGL_V,
               "probe default audio output device about support for digital s/pdif output: %d\n",
               ao->b_supports_digital );
    }

    free(psz_name);

    // Save selected device id
    ao->i_selected_dev = devid_def;

	// Build Description for the input format
	inDesc.mSampleRate=rate;
	inDesc.mFormatID=ao->b_supports_digital ? kAudioFormat60958AC3 : kAudioFormatLinearPCM;
	inDesc.mChannelsPerFrame=channels;
	inDesc.mBitsPerChannel=af_fmt2bits(format);

    if((format&AF_FORMAT_POINT_MASK)==AF_FORMAT_F) {
	// float
		inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked;
    }
    else if((format&AF_FORMAT_SIGN_MASK)==AF_FORMAT_SI) {
	// signed int
		inDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
    }
    else {
	// unsigned int
		inDesc.mFormatFlags = kAudioFormatFlagIsPacked;
    }
    if ((format & AF_FORMAT_END_MASK) == AF_FORMAT_BE)
        inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian;

    inDesc.mFramesPerPacket = 1;
    ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame = inDesc.mFramesPerPacket*channels*(inDesc.mBitsPerChannel/8);
    print_format(MSGL_V, "source:",&inDesc);

    if (ao->b_supports_digital)
    {
        b_alive = 1;
        err = GetAudioProperty(ao->i_selected_dev,
                               kAudioDevicePropertyDeviceIsAlive,
                               sizeof(UInt32), &b_alive);
        if (err != noErr)
            ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is alive: [%4.4s]\n", (char *)&err);
        if (!b_alive)
            ao_msg(MSGT_AO, MSGL_WARN, "device is not alive\n" );

        /* S/PDIF output need device in HogMode. */
        err = GetAudioProperty(ao->i_selected_dev,
                               kAudioDevicePropertyHogMode,
                               sizeof(pid_t), &ao->i_hog_pid);
        if (err != noErr)
        {
            /* This is not a fatal error. Some drivers simply don't support this property. */
            ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is hogged: [%4.4s]\n",
                     (char *)&err);
            ao->i_hog_pid = -1;
        }

        if (ao->i_hog_pid != -1 && ao->i_hog_pid != getpid())
        {
            ao_msg(MSGT_AO, MSGL_WARN, "Selected audio device is exclusively in use by another program.\n" );
            goto err_out;
        }
        ao->stream_format = inDesc;
        return OpenSPDIF();
    }

	/* original analog output code */
	desc.componentType = kAudioUnitType_Output;
	desc.componentSubType = (device_id == 0) ? kAudioUnitSubType_DefaultOutput : kAudioUnitSubType_HALOutput;
	desc.componentManufacturer = kAudioUnitManufacturer_Apple;
	desc.componentFlags = 0;
	desc.componentFlagsMask = 0;

	comp = FindNextComponent(NULL, &desc);  //Finds an component that meets the desc spec's
	if (comp == NULL) {
		ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
		goto err_out;
	}

	err = OpenAComponent(comp, &(ao->theOutputUnit));  //gains access to the services provided by the component
	if (err) {
		ao_msg(MSGT_AO, MSGL_WARN, "Unable to open Output Unit component: [%4.4s]\n", (char *)&err);
		goto err_out;
	}

	// Initialize AudioUnit
	err = AudioUnitInitialize(ao->theOutputUnit);
	if (err) {
		ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component: [%4.4s]\n", (char *)&err);
		goto err_out1;
	}

	size =  sizeof(AudioStreamBasicDescription);
	err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);

	if (err) {
		ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format: [%4.4s]\n", (char *)&err);
		goto err_out2;
	}

	size = sizeof(UInt32);
	err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);

	if (err)
	{
		ao_msg(MSGT_AO,MSGL_WARN, "AudioUnitGetProperty returned [%4.4s] when getting kAudioDevicePropertyBufferSize\n", (char *)&err);
		goto err_out2;
	}

	//Set the Current Device to the Default Output Unit.
    err = AudioUnitSetProperty(ao->theOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &ao->i_selected_dev, sizeof(ao->i_selected_dev));

	ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;

	ao_data.samplerate = inDesc.mSampleRate;
	ao_data.channels = inDesc.mChannelsPerFrame;
    ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame;
    ao_data.outburst = ao->chunk_size;
	ao_data.buffersize = ao_data.bps;

	ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
    ao->buffer_len = ao->num_chunks * ao->chunk_size;
    ao->buffer = av_fifo_alloc(ao->buffer_len);

	ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);

    renderCallback.inputProc = theRenderProc;
    renderCallback.inputProcRefCon = 0;
    err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct));
	if (err) {
		ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback: [%4.4s]\n", (char *)&err);
		goto err_out2;
	}

	reset();

    return CONTROL_OK;

err_out2:
    AudioUnitUninitialize(ao->theOutputUnit);
err_out1:
    CloseComponent(ao->theOutputUnit);
err_out:
    av_fifo_free(ao->buffer);
    free(ao);
    ao = NULL;
    return CONTROL_FALSE;
}
示例#25
0
int main(int argc, char**argv)
{
    struct v4l2_capability vid_caps;
    struct v4l2_format vid_format;

    size_t framesize;
    size_t linewidth;

    __u8*buffer;
    __u8*check_buffer;

    const char*video_device=VIDEO_DEVICE;
    int fdwr = 0;
    int ret_code = 0;

    int i;

    if(argc>1) {
        video_device=argv[1];
        printf("using output device: %s\n", video_device);
    }

    fdwr = open(video_device, O_RDWR);
    assert(fdwr >= 0);

    ret_code = ioctl(fdwr, VIDIOC_QUERYCAP, &vid_caps);
    assert(ret_code != -1);

    memset(&vid_format, 0, sizeof(vid_format));

    ret_code = ioctl(fdwr, VIDIOC_G_FMT, &vid_format);
    if(debug)print_format(&vid_format);

    vid_format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    vid_format.fmt.pix.width = FRAME_WIDTH;
    vid_format.fmt.pix.height = FRAME_HEIGHT;
    vid_format.fmt.pix.pixelformat = FRAME_FORMAT;
    vid_format.fmt.pix.sizeimage = framesize;
    vid_format.fmt.pix.field = V4L2_FIELD_NONE;
    vid_format.fmt.pix.bytesperline = linewidth;
    vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;

    if(debug)print_format(&vid_format);
    ret_code = ioctl(fdwr, VIDIOC_S_FMT, &vid_format);

    assert(ret_code != -1);

    if(debug)printf("frame: format=%d\tsize=%d\n", FRAME_FORMAT, framesize);
    print_format(&vid_format);

    if(!format_properties(vid_format.fmt.pix.pixelformat,
                          vid_format.fmt.pix.width, vid_format.fmt.pix.height,
                          &linewidth,
                          &framesize)) {
        printf("unable to guess correct settings for format '%d'\n", FRAME_FORMAT);
    }
    buffer=(__u8*)malloc(sizeof(__u8)*framesize);
    check_buffer=(__u8*)malloc(sizeof(__u8)*framesize);

    memset(buffer, 0, framesize);
    memset(check_buffer, 0, framesize);
    for (i = 0; i < framesize; ++i) {
        //buffer[i] = i % 2;
        check_buffer[i] = 0;
    }





    write(fdwr, buffer, framesize);

#ifdef CHECK_REREAD
    do {
        /* check if we get the same data on output */
        int fdr = open(video_device, O_RDONLY);
        read(fdr, check_buffer, framesize);
        for (i = 0; i < framesize; ++i) {
            if (buffer[i] != check_buffer[i])
                assert(0);
        }
        close(fdr);
    } while(0);
#endif

    pause();

    close(fdwr);

    free(buffer);
    free(check_buffer);

    return 0;
}
示例#26
0
文件: test.c 项目: ybma/v4l2display
int main(int argc, char**argv){

	//--- create variables and initialize them. init()
	char* video_device = VIDEO_DEVICE;
	// 1) -------- 打开设备 /dev/video*: --------
	printf("--------------------------------------\n");
	printf("Step 1: Open devide using V4L2.\n");
	if(argc>1) {
		video_device=argv[1];
		printf("        Select: %s\n", video_device);
	}
	// create a handler for /dev/video* device:
	// 采用阻塞模式打开;若为非阻塞模式:O_RDWR | O_NONBLOCK
	int fdwr = 0;  // for /dev/video* handler
	if(NON_BLOCK_VIDEO){
		fdwr = open(video_device, O_RDWR | O_NONBLOCK);
		printf("        Open: %s using NON_BLOCK mode\n", video_device);
	} else{
		fdwr = open(video_device, O_RDWR);
		printf("        Open: %s using BLOCK mode\n", video_device);
	}
	assert(fdwr >= 0);
	printf("--------------------------------------\n");

	// 2) -------- 查询设备属性 --------
	printf("Step 2: v4l2_capacity check:\n");
	struct v4l2_capability vid_caps;
	memset(&vid_caps, 0, sizeof(vid_caps));
	int ret_code = 0; // for checking the V4L2 ioctl() method return status. 
	ret_code = ioctl(fdwr, VIDIOC_QUERYCAP, &vid_caps);
	assert(ret_code != -1);
	if(debug==1) 
		print_cap(&vid_caps);

	// 3) 设置视频的制式和帧格式:
	printf("Step 3: v4l2_format check/set:\n");
	struct v4l2_format vid_format;
	memset(&vid_format, 0, sizeof(vid_format));
//	ret_code = ioctl(fdwr, VIDIOC_G_FMT, &vid_format);

	if(V4L2_BUF_TYPE == CAPTURE){
		vid_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	} else{
		vid_format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	}
	
	vid_format.fmt.pix.width = FRAME_WIDTH;
	vid_format.fmt.pix.height = FRAME_HEIGHT;
	vid_format.fmt.pix.pixelformat = FRAME_FORMAT;

//	size_t framesize;
//	size_t linewidth;
	__u32 framesize;
	__u32 linewidth;
	if(!format_properties(vid_format.fmt.pix.pixelformat, vid_format.fmt.pix.width, 
						vid_format.fmt.pix.height, &linewidth, &framesize)) {
		printf("unable to guess correct settings for format '%d'\n", FRAME_FORMAT);
	} else{
//		printf("FrameSize = %d\n", framesize);
//		printf("linewidth = %d\n", linewidth);
	}

	// check: http://lxr.free-electrons.com/source/include/uapi/linux/videodev2.h#L87
	vid_format.fmt.pix.field = V4L2_FIELD_NONE; // V4L2_FIELD_ANY

	// check: http://lxr.free-electrons.com/source/include/uapi/linux/videodev2.h#L185
	vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
//	vid_format.fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;

	vid_format.fmt.pix.sizeimage = framesize;
	vid_format.fmt.pix.bytesperline = linewidth;

	if(debug==1)
		print_format(&vid_format);

	ret_code = ioctl(fdwr, VIDIOC_S_FMT, &vid_format);
	assert(ret_code != -1);
/*
	// After set v4l2_format, read it back for double check. 
	// Just to make sure that there is no mis-set and the sys 'secretly' 
	// set the parameters to some 'default' value. 
	if(debug == 1){
		ret_code = ioctl(fdwr, VIDIOC_G_FMT, &vid_format);
		assert(ret_code != -1);
		printf("after set, get it back to double check:\n");
		print_format(&vid_format);
	}
*/	

/*
	struct v4l2_fmtdesc vid_desc;
	vid_desc.index = 0;
	if(debug==1)
		print_desc(fdwr,&vid_desc);
*/

	// 4) Check the video standard:
	// in general the standard is either PAL(720*576) for asian; or NTSC (720*480) for EU.
	// in our virtual camera scenario, the "v4l2_standard" does not matter much. 
	// 4.1) get the current video standard:
	printf("Step 4: check the video standard.\n");
	//struct v4l2_std_id vid_std_id;  // 64 bit length var.
	struct v4l2_standard vid_std;
	v4l2_std_id std_id;

	ret_code = ioctl(fdwr, VIDIOC_G_STD, &std_id);
	if(ret_code == -1){
		printf("        Acquire video standard ERROR:%d\n",ret_code);
	} else{
		memset(&vid_std, 0, sizeof(vid_std));
		vid_std.index = 0; // emun from the first one:
		while(0 == ioctl(fdwr, VIDIOC_ENUMSTD, &vid_std)){
			if(vid_std.id & std_id){
				printf("Current video standard: %s\n", vid_std.name);
			}
			vid_std.index++;
		}
	}

	struct v4l2_streamparm parm;
    memset(&parm, 0, sizeof(parm));
    parm.type =vid_format.type;
    ret_code = ioctl(fdwr,VIDIOC_G_PARM,&parm);
    if(ret_code == -1)
    	printf("get parameter failed.");
    parm.parm.output.timeperframe.numerator = 1000;
    parm.parm.output.timeperframe.denominator = FPS * parm.parm.output.timeperframe.numerator;
    if(ioctl(fdwr,VIDIOC_S_PARM,&parm)==0){
    	struct v4l2_fract *tf = &parm.parm.output.timeperframe;
    	if(!tf->denominator || !tf->numerator)
    		printf("invalid frame rate\n");
    	else
    		printf("        Frame Rate                     =%.3f fps\n", 
    			                            1.0 * tf->denominator/tf->numerator);
    }
//    printf("        v4l2_streamparm set/check:\n");
    printf("        parm.type(capture=1/output=2)  =%d\n", parm.type);
    printf("        parm.parm.output.capability    =0x%4x\n", parm.parm.output.capability);
	printf("--------------------------------------\n");

// 5) request buffer:
	printf("Step 5: Request video buffers\n");
	struct v4l2_requestbuffers req;
	req.count = NUM_BUFFER;
	req.memory = V4L2_MEMORY_MMAP;
    req.type = vid_format.type;  // V4L2_BUF_TYPE_VIDEO_OUTPUT = 2;

	ret_code = ioctl(fdwr, VIDIOC_REQBUFS, &req);
	if(debug == 1){
		print_requestbuffers(&req);
	}
    
  	tp_buffers *data;
    // malloc() + memset (p, 0, size);
    data= (struct buffer*) calloc(req.count, sizeof( tp_buffers));
    //data=(tp_buffers*) calloc(req.count,sizeof (tp_buffers));
	if(!data){
		printf ("Out of memory/n");
		exit (EXIT_FAILURE);
	}

	int index = 0;
	// set the parameter for every buffer in the buf_arr[], 
	// to make sure they are the same as thos in the 'req'. 
    for(index=0; index<req.count; index++){
        memset(&buf_arr[index], 0, sizeof(buf_arr[index]));
        buf_arr[index].index = index;
        buf_arr[index].type = vid_format.type;
        buf_arr[index].memory = req.memory; // should be V4L2_MEMORY_MMAP;

        // 查询序号为i 的缓冲区,得到其起始物理地址和大小
		if(-1 == ioctl (fdwr, VIDIOC_QUERYBUF, &buf_arr[index]))
			exit(-1);
		
		data[index].length = buf_arr[index].length;
		// 映射内存
		data[index].start = mmap(NULL, buf_arr[index].length, PROT_READ | PROT_WRITE, 
						MAP_SHARED, fdwr, buf_arr[index].m.offset);

		if(MAP_FAILED == data[index].start)
			exit(-1);

//		printf("        data[%d].start = 0x%08x", index, data[index].start);
		printf("        data[%d].length                     = %d\n", index, data[index].length);
//		printf("buf.length = %d, framesize = %d ,buf.m.offset = %d\n",
//					buf_arr[index].length,(int)framesize,buf_arr[index].m.offset);   
    }

    // 6) assign buffers to the queue.
	printf("step 6: assign buffers to the queue.\n");

	// Queue buffers:
    for(index = 0; index < req.count; index++){
    	ioctl(fdwr, VIDIOC_QBUF, &buf_arr[index]);
    }

    // STREAM-ON
    enum v4l2_buf_type type = vid_format.type;
    ret_code = ioctl(fdwr, VIDIOC_STREAMON, &type);
    assert(ret_code != -1);

    // image streaming testing. 
    // need to convert from RGBA format to YUYV format, 
    // and then QBUF to the buffer array. 
    int color = 128;
	// write AVOS mFrame image to buffers[ind]:
	const int BENCH = 255;

	FILE * bmp_fd = NULL;
	BYTE bmp_header[128];
	int bmp_width;
	int bmp_height;
	int bmp_header_len;
	BYTE * rgb = NULL;
	BYTE * yuv = NULL;
	char *pic[4]={"1.bmp","2.bmp","3.bmp","4.bmp"}; 		
// 	char *pic[4]={"5.bmp","5.bmp","5.bmp","5.bmp"}; 		
	while(1){
	/*
	// set image/
		if(color >= BENCH)
			color = color % BENCH;
		else
			color++;

		for(index=0; index < req.count; index++){
//			memset(data[index].start, color,1179648);
			memset(data[index].start, 128,1024);
			memset(data[index].start+1024, 255,vid_format.fmt.pix.sizeimage-1024);
		}*/
		for(index=0; index < req.count; index++){
	//		printf("%s\n",pic[index]);
			bmp_fd = fopen(pic[index],"rb");
			if(!bmp_fd)
			{
				fprintf(stderr,"open bmp file failed!\n");
				exit(1);
			}
			fgets(bmp_header,sizeof(bmp_header),bmp_fd);
			bmp_header_len = get_long_value(&bmp_header[10]);
			bmp_width = get_long_value(&bmp_header[18]);
			bmp_height = get_long_value(&bmp_header[22]);
			fclose(bmp_fd);
	//		printf("hearder_len:%d\n",bmp_header_len);	
		//	printf("image :%d*%d\n",bmp_width,bmp_height);
		//	printf("width*height*2:%d\n",bmp_width*bmp_height*2);
	//		printf("sizeimage:%d\n",vid_format.fmt.pix.sizeimage);
			rgb = malloc(bmp_width*bmp_height*sizeof(RGBTRIPLE)+bmp_header_len);
			if(!rgb)
			{
				fprintf(stderr,"rgb malloc failed\n");
			}
			yuv = malloc(bmp_width*bmp_height*sizeof(YUVTRIPLE));
			if(!yuv)
			{
				fprintf(stderr,"yuv malloc failed\n");
			}
//			fread(rgb,bmp_width*bmp_height*3+bmp_header_len,1,bmp_fd);
			bmp_fd = fopen(pic[index],"rb");
			fread(rgb,bmp_width*bmp_height*sizeof(RGBTRIPLE)+bmp_header_len,1,bmp_fd);
			bgr2yuv(yuv,(RGBTRIPLE *)(rgb+bmp_header_len),bmp_width,bmp_height);	
			memcpy(data[index].start, yuv,vid_format.fmt.pix.sizeimage);
			if(rgb)
			{
			free(rgb);
			}
			if(yuv)
			{
				free(yuv);
			}
			fclose(bmp_fd);
		}
		for(index = 0; index < req.count; index++){
		//buf_arr[index].m.offset = 0;
	//		usleep(40000);
			sleep(1);
			ioctl(fdwr, VIDIOC_QBUF, &buf_arr[index]);
		}

<<<<<<< HEAD
//		usleep(1/FPS * 1000 * 1000);
		usleep(40000);
=======
	//	usleep(40000);
>>>>>>> d1308ed6e339365aa9876a4e3f265d74eb880e0a
示例#27
0
int main(int argc, char *argv[])
{
  int rate;
  int channels;            /* number of channels */
  int bits;                /* sample size */
  int blocksize;           /* block size */
  int min_rate, max_rate;  /* min and max sampling rates */
  char *device;            /* name of device to report on */
  int fd;                  /* file descriptor for device */
  int status;              /* return value from ioctl */
#if SOUND_VERSION >= 301
  int formats;             /* data formats */
  int caps;                /* capabilities */
  int deffmt;              /* default format */
#endif

  /* get device name from command line or use default */  
  if (argc == 2)
    device = argv[1];
  else
    device = "/dev/dsp";

  /* try to open device */
  fd = open(device, O_RDWR);
  if (fd == -1) {
    fprintf(stderr, "%s: unable to open `%s', ", argv[0], device);
    perror("");
    return 1;
  }
  
  status = ioctl(fd, SOUND_PCM_READ_RATE, &rate);
  if (status ==  -1)
    perror("SOUND_PCM_READ_RATE ioctl failed");
  status = ioctl(fd, SOUND_PCM_READ_CHANNELS, &channels);
  if (status ==  -1)
    perror("SOUND_PCM_READ_CHANNELS ioctl failed");
  status = ioctl(fd, SOUND_PCM_READ_BITS, &bits);
  if (status ==  -1)
    perror("SOUND_PCM_READ_BITS ioctl failed");
  status = ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
  if (status ==  -1)
    perror("SNFCTL_DSP_GETBLKSIZE ioctl failed");
  
  printf(
	 "Information on %s:\n\n"
	 "Defaults:\n"
	 "  sampling rate: %d Hz\n"
	 "  channels: %d\n"
	 "  sample size: %d bits\n"
	 "  block size: %d bytes\n",
	 device, rate, channels, bits, blocksize
	 );

#if SOUND_VERSION >= 301
  printf("\nSupported Formats:\n");
  deffmt = AFMT_QUERY;
  status = ioctl(fd, SOUND_PCM_SETFMT, &deffmt);
  if (status ==  -1)
    perror("SOUND_PCM_SETFMT ioctl failed");
  status = ioctl(fd, SOUND_PCM_GETFMTS, &formats);
  if (status ==  -1)
    perror("SOUND_PCM_GETFMTS ioctl failed");
  print_format(formats, AFMT_MU_LAW, deffmt, "mu-law");
  print_format(formats, AFMT_A_LAW, deffmt, "A-law");
  print_format(formats, AFMT_IMA_ADPCM, deffmt, "IMA ADPCM");
  print_format(formats, AFMT_U8, deffmt, "unsigned 8-bit");
  print_format(formats, AFMT_S8, deffmt, "signed 8-bit");
  print_format(formats, AFMT_S16_LE, deffmt, "signed 16-bit little-endian");
  print_format(formats, AFMT_S16_BE, deffmt, "signed 16-bit big-endian");
  print_format(formats, AFMT_U16_LE, deffmt, "unsigned 16-bit little-endian");
  print_format(formats, AFMT_U16_BE, deffmt, "unsigned 16-bit big-endian");
  print_format(formats, AFMT_MPEG, deffmt, "MPEG-2");
  
  printf("\nCapabilities:\n");
  status = ioctl(fd, SNDCTL_DSP_GETCAPS, &caps);
  if (status ==  -1)
    perror("SNDCTL_DSP_GETCAPS ioctl failed");
  printf(
	 "  revision: %d\n"
	 "  full duplex: %s\n"
	 "  real-time: %s\n"
	 "  batch: %s\n"
	 "  coprocessor: %s\n" 
	 "  trigger: %s\n"
	 "  mmap: %s\n",
	 caps & DSP_CAP_REVISION,
	 yes_no(caps & DSP_CAP_DUPLEX),
	 yes_no(caps & DSP_CAP_REALTIME),
	 yes_no(caps & DSP_CAP_BATCH),
	 yes_no(caps & DSP_CAP_COPROC),
	 yes_no(caps & DSP_CAP_TRIGGER),
	 yes_no(caps & DSP_CAP_MMAP));

#endif /* SOUND_VERSION >= 301 */
  
  /* display table heading */
  printf(
	 "\nModes and Limits:\n"
	 "Device    Sample    Minimum   Maximum\n"
	 "Channels  Size      Rate      Rate\n"
	 "--------  --------  --------  --------\n"
	 );
  
  /* do mono and stereo */  
  for (channels = 1; channels <= 2 ; channels++) {
    /* do 8 and 16 bits */
    for (bits = 8; bits <= 16 ; bits += 8) {
      /* To find the minimum and maximum sampling rates we rely on
	 the fact that the kernel sound driver will round them to
	 the closest legal value. */
      min_rate = 1;
      if (set_dsp_params(fd, channels, bits, &min_rate) == -1)
	continue;
      max_rate = 100000;
      if (set_dsp_params(fd, channels, bits, &max_rate) == -1)
	continue;
      /* display the results */
      printf("%8d  %8d  %8d  %8d\n", channels, bits, min_rate, max_rate);
    }
  }
  close(fd);
  return 0;
}
示例#28
0
文件: ps.c 项目: vocho/openqnx
int main(int argc, char **argv) {
    int show_other = 0;		/* processes outside my session */
    int show_leader = 1;	/* process group leaders */
    int show_interactive = 1;	/* processes associated with terminals */
    int show_daemon = 0;	/* processes with no associated terminal */
    char *match_pid = 0;	/* process id to match */
    char *match_pgrp = 0;	/* group id to match */
    char *match_sid = 0;	/* session id to match */
    char *match_state = 0;	/* process state to match */
    char *match_tty = 0;	/* terminal id to match */
    char *match_uid = 0;	/* user id to match */
    char *format = 0;		/* output format string */
    char detail[132];		/* detail line buffer */
    time_t boot;		/* boot time (kludge for image modules) */
    long nid;
    int euid = geteuid();
    int ch;

    time(&utc);
    progname = basename(argv[0]);
    while ((ch = getopt(argc, argv, "aAdF:g:p:s:t:u:**efjln:S:x")) != EOF) {
	switch (ch) {
	  case 'a': /* all processes associated with terminals except pgrp leaders */
	    show_other = 1;
	    show_leader = 0;
	    show_interactive = 1;
	    show_daemon = 0;
	    break;
	  case 'A': /* all accessible processes */
	  case 'f':
	  case 'x':
	    show_other = 1;
	    show_leader = 1;
	    show_interactive = 1;
	    show_daemon = 1;
	    break;
	  case 'd': /* all processes except pgrp leaders */
	    show_other = 1;
	    show_leader = 0;
	    show_interactive = 1;
	    show_daemon = 1;
	    break;
	  case 'F': /* specify output format */
	    if (format)
		message("more than one format string?");
	    format = optarg;
	    break;
	  case 'g': /* processes whose group ID numbers match */
	    show_other = 1;
	    match_pgrp = optarg;
	    break;
	  case 'p': /* processes whose process ID numbers match */
	    show_other = 1;
	    match_pid = optarg;
	    break;
	  case 's': /* sessions whose session ID numbers match */
	    show_other = 1;
	    match_sid = optarg;
	    break;
	  case 't': /* processes whose terminal names match */
	    show_other = 1;
	    match_tty = optarg;
	    break;
	  case 'u': /* processes whose user names/IDs match */
	    show_other = 1;
	    match_uid = optarg;
	    break;
	  case 'e':
	    format = FMT_ELAPSED;
	    break;
	  case 'l':
	    format = FMT_LONG;
	    break;
	  case 'j':
	    format = FMT_JOBS;
	    break;
	  case 'n':
	    nid = strtonid(optarg, 0);
	    if (nid == -1 || nid == 0) {
		message("invalid node specified (-n %s)\n", optarg);
		return EXIT_FAILURE;
	    }
	    if ((pm = qnx_vc_attach(nid, PROC_PID, sizeof ps, 1)) == -1) {
		message("unable to connect to node %s. (%s)\n", 
			nidtostr(nid, 0, 0), strerror(errno));
		return EXIT_FAILURE;
	    }
	    break;
	  case 'S':
	    match_state = optarg;
	    break;
	}
    }

    setpwent();
    if (format == 0) format = getenv("POSIX_STRICT") ? FMT_POSIX : FMT_QNX;
    scan_format(format, detail);
    print_format(detail);
    for (ps.pid = PROC_PID; qnx_psinfo(pm, ps.pid, &ps, 0, 0) >= 0; ps.pid++) {
	/* skip proxies and virtual circuits */
	if ((ps.flags & _PPF_MID) || (ps.flags & _PPF_VID)) continue;
	/* save start time of Proc */
	if (ps.pid == PROC_PID) boot = ps.un.proc.start_time;
	/* skip other users' processes */
	if (!show_other && ps.euid != euid)		    continue;
	/* skip process group leaders */
	if (!show_leader && ps.pid == ps.pgrp)		    continue;
	/* check for specific processes */
	if (match_state  && !match(match_state, procstate)) continue;
	if (match_pid    && !match(match_pid, procpid))	    continue;
	if (match_pgrp   && !match(match_pgrp, procgrp))    continue;
	if (match_sid    && !match(match_sid, procsid))	    continue;
	if (match_tty    && !match(match_tty, proctty))	    continue;
	if (match_uid    && !match(match_uid, procuser))    continue;
	/* kludge start time for image modules */
	if (ps.un.proc.start_time == 0) ps.un.proc.start_time = boot;
	print_format(detail);
    }
    return EXIT_SUCCESS;
}