예제 #1
0
	/**
	 * @brief   Scroll vertically a section of the screen.
	 * @note    Optional.
	 * @note    If x,y + cx,cy is off the screen, the result is undefined.
	 * @note    If lines is >= cy, it is equivelent to a area fill with bgcolor.
	 *
	 * @param[in] x, y     The start of the area to be scrolled
	 * @param[in] cx, cy   The size of the area to be scrolled
	 * @param[in] lines    The number of lines to scroll (Can be positive or negative)
	 * @param[in] bgcolor  The color to fill the newly exposed area.
	 *
	 * @notapi
	 */
	void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
		/* This is marked as "TODO: Test this" in the original GLCD driver.
		 * For now we just leave the GDISP_HARDWARE_SCROLL off.
		 */
		static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
		coord_t row0, row1;
		unsigned i, gap, abslines;

		#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
			if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
			if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
			if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
			if (x+cx > GDISP.clipx1)	cx = GDISP.clipx1 - x;
			if (y+cy > GDISP.clipy1)	cy = GDISP.clipy1 - y;
		#endif

		abslines = lines < 0 ? -lines : lines;

		acquire_bus();
		if (abslines >= cy) {
			abslines = cy;
			gap = 0;
		} else {
			gap = cy - abslines;
			for(i = 0; i < gap; i++) {
				if(lines > 0) {
					row0 = y + i + lines;
					row1 = y + i;
				} else {
					row0 = (y - i - 1) + lines;
					row1 = (y - i - 1);
				}

				/* read row0 into the buffer and then write at row1*/
				set_viewport(x, row0, cx, 1);
				lld_lcdReadStreamStart();
				lld_lcdReadStream(buf, cx);
				lld_lcdReadStreamStop();

				set_viewport(x, row1, cx, 1);
				stream_start();
				write_data(buf, cx);
				stream_stop();
			}
		}

		/* fill the remaining gap */
		set_viewport(x, lines > 0 ? (y+gap) : y, cx, abslines);
		stream_start();
		gap = cx*abslines;
		for(i = 0; i < gap; i++) write_data(bgcolor);
		stream_stop();
		reset_viewport();
		release_bus();
	}
예제 #2
0
	/**
	 * @brief   Scroll vertically a section of the screen.
	 * @note    Optional.
	 * @note    If x,y + cx,cy is off the screen, the result is undefined.
	 * @note    If lines is >= cy, it is equivelent to a area fill with bgcolor.
	 *
	 * @param[in] x, y     The start of the area to be scrolled
	 * @param[in] cx, cy   The size of the area to be scrolled
	 * @param[in] lines    The number of lines to scroll (Can be positive or negative)
	 * @param[in] bgcolor  The color to fill the newly exposed area.
	 *
	 * @notapi
	 */
	void lld_gdisp_vertical_scroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
		static color_t buf[((GDISP_SCREEN_HEIGHT > GDISP_SCREEN_WIDTH ) ? GDISP_SCREEN_HEIGHT : GDISP_SCREEN_WIDTH)];
		coord_t row0, row1;
		unsigned i, gap, abslines, j;

		#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
			if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
			if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
			if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
			if (x+cx > GDISP.clipx1)	cx = GDISP.clipx1 - x;
			if (y+cy > GDISP.clipy1)	cy = GDISP.clipy1 - y;
		#endif

		abslines = lines < 0 ? -lines : lines;

		acquire_bus();
		if (abslines >= cy) {
			abslines = cy;
			gap = 0;
		} else {
			gap = cy - abslines;
			for(i = 0; i < gap; i++) {
				if(lines > 0) {
					row0 = y + i + lines;
					row1 = y + i;
				} else {
					row0 = (y - i - 1) + lines;
					row1 = (y - i - 1);
				}

				/* read row0 into the buffer and then write at row1*/
				set_viewport(x, row0, cx, 1);
				stream_start();
				j = read_data();			// dummy read
				for (j = 0; j < cx; j++)
					buf[j] = read_data();
				stream_stop();

				set_viewport(x, row1, cx, 1);
				stream_start();
				for (j = 0; j < cx; j++)
					write_data(buf[j]);
				stream_stop();
			}
		}

		/* fill the remaining gap */
		set_viewport(x, lines > 0 ? (y+gap) : y, cx, abslines);
		stream_start();
		gap = cx*abslines;
		for(i = 0; i < gap; i++) write_data(bgcolor);
		stream_stop();
		release_bus();
	}
예제 #3
0
파일: audio.c 프로젝트: mralexgray/baresip
/**
 * Start the audio playback and recording
 *
 * @param a Audio object
 *
 * @return 0 if success, otherwise errorcode
 */
int audio_start(struct audio *a)
{
	int err;

	if (!a)
		return EINVAL;

	err = stream_start(a->strm);
	if (err)
		return err;

	/* Audio filter */
	if (!a->filtl.head && !list_isempty(aufilt_list())) {
		err = aufilt_setup(a);
		if (err)
			return err;
	}

	/* configurable order of play/src start */
	if (a->cfg.src_first) {
		err |= start_source(&a->tx, a);
		err |= start_player(&a->rx, a);
	}
	else {
		err |= start_player(&a->rx, a);
		err |= start_source(&a->tx, a);
	}

	return err;
}
예제 #4
0
	/**
	 * @brief   Fill an area with a bitmap.
	 * @note    Optional - The high level driver can emulate using software.
	 *
	 * @param[in] x, y     The start filled area
	 * @param[in] cx, cy   The width and height to be filled
	 * @param[in] srcx, srcy   The bitmap position to start the fill from
	 * @param[in] srccx    The width of a line in the bitmap.
	 * @param[in] buffer   The pixels to use to fill the area.
	 *
	 * @notapi
	 */
	void GDISP_LLD(blitareaex)(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
		coord_t endx, endy;
		unsigned lg;

		#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
			if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; }
			if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; }
			if (srcx+cx > srccx)		cx = srccx - srcx;
			if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
			if (x+cx > GDISP.clipx1)	cx = GDISP.clipx1 - x;
			if (y+cy > GDISP.clipy1)	cy = GDISP.clipy1 - y;
		#endif

		acquire_bus();
		set_viewport(x, y, cx, cy);
		stream_start();

		endx = srcx + cx;
		endy = y + cy;
		lg = srccx - cx;
		buffer += srcx + srcy * srccx;
		for(; y < endy; y++, buffer += lg)
			for(x=srcx; x < endx; x++)
				write_data(*buffer++);
		stream_stop();
		reset_viewport();
		release_bus();
	}
예제 #5
0
파일: gdisp_lld.c 프로젝트: omgmog/olvfw
/**
 * @brief   Fill an area with a color.
 * @note    Optional - The high level driver can emulate using software.
 *
 * @param[in] x, y     The start filled area
 * @param[in] cx, cy   The width and height to be filled
 * @param[in] color    The color of the fill
 *
 * @notapi
 */
void GDISP_LLD(fillarea)(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
    unsigned i, area;

#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
    if (x < GDISP.clipx0) {
        cx -= GDISP.clipx0 - x;
        x = GDISP.clipx0;
    }
    if (y < GDISP.clipy0) {
        cy -= GDISP.clipy0 - y;
        y = GDISP.clipy0;
    }
    if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return;
    if (x+cx > GDISP.clipx1)	cx = GDISP.clipx1 - x;
    if (y+cy > GDISP.clipy1)	cy = GDISP.clipy1 - y;
#endif

    area = cx*cy;
    acquire_bus();
    set_viewport(x, y, cx, cy);
    stream_start();
    for(i = 0; i < area; i++)
        write_data(color);
    stream_stop();
    reset_viewport();
    release_bus();
}
예제 #6
0
static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
{
	int bytes_per_sample, bpp, ret, i;
	int index = substream->number;
	struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
	struct snd_pcm_runtime *runtime = substream->runtime;

	debug("%s(%p)\n", __func__, substream);

	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
		dev->period_out_count[index] = BYTES_PER_SAMPLE + 1;
		dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
	} else {
		int in_pos = (dev->spec.data_alignment == 2) ? 0 : 2;
		dev->period_in_count[index] = BYTES_PER_SAMPLE + in_pos;
		dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE + in_pos;
	}

	if (dev->streaming)
		return 0;

	/* the first client that opens a stream defines the sample rate
	 * setting for all subsequent calls, until the last client closed. */
	for (i=0; i < ARRAY_SIZE(rates); i++)
		if (runtime->rate == rates[i])
			dev->pcm_info.rates = 1 << i;

	snd_pcm_limit_hw_rates(runtime);

	bytes_per_sample = BYTES_PER_SAMPLE;
	if (dev->spec.data_alignment == 2)
		bytes_per_sample++;

	bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
		* bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;

	if (bpp > MAX_ENDPOINT_SIZE)
		bpp = MAX_ENDPOINT_SIZE;

	ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate,
					     runtime->sample_bits, bpp);
	if (ret)
		return ret;

	ret = stream_start(dev);
	if (ret)
		return ret;

	dev->output_running = 0;
	wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ);
	if (!dev->output_running) {
		stream_stop(dev);
		return -EPIPE;
	}

	return 0;
}
void test_iostream_iterator() {
  vector<string> text;
  istream_iterator<string> stream_start(cin);
  istream_iterator<string> eof;

  copy(stream_start, eof, back_inserter(text));
  sort(text.begin(), text.end());

  ostream_iterator<string> out_stream(cout, " ");
  copy(text.begin(), text.end(), out_stream);
}
예제 #8
0
파일: pulse.c 프로젝트: rbavishi/vlc-2.2.1
static void stream_latency_cb(pa_stream *s, void *userdata)
{
    audio_output_t *aout = userdata;
    aout_sys_t *sys = aout->sys;

    /* This callback is _never_ called while paused. */
    if (sys->first_pts == VLC_TS_INVALID)
        return; /* nothing to do if buffers are (still) empty */
    if (pa_stream_is_corked(s) > 0)
        stream_start(s, aout);
}
예제 #9
0
	/**
	 * @brief   Clear the display.
	 * @note    Optional - The high level driver can emulate using software.
	 *
	 * @param[in] color    The color of the pixel
	 *
	 * @notapi
	 */
	void lld_gdisp_clear(color_t color) {
		unsigned i;

		acquire_bus();
		reset_viewport();
		set_cursor(0, 0);
		stream_start();
		for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
			write_data(color);
		stream_stop();
		release_bus();
	}
예제 #10
0
	/**
	 * @brief   Clear the display.
	 * @note    Optional - The high level driver can emulate using software.
	 *
	 * @param[in] color    The color of the pixel
	 *
	 * @notapi
	 */
	void GDISP_LLD(clear)(color_t color) {
	    unsigned i;

		acquire_bus();
	    set_cursor(0, 0);
	    stream_start();

	    for(i = 0; i < GDISP_SCREEN_WIDTH * GDISP_SCREEN_HEIGHT; i++)
	    	write_data(color);

	    stream_stop();
		release_bus();
	}
예제 #11
0
	/**
	 * @brief   Get the color of a particular pixel.
	 * @note    Optional.
	 * @note    If x,y is off the screen, the result is undefined.
	 *
	 * @param[in] x, y     The pixel to be read
	 *
	 * @notapi
	 */
	color_t lld_gdisp_get_pixel_color(coord_t x, coord_t y) {
		color_t color;

		#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
			if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
		#endif

		acquire_bus();
		set_cursor(x, y);
		stream_start();
		color = read_data();			// dummy read
		color = read_data();
		stream_stop();
		release_bus();

		return color;
	}
예제 #12
0
static void services_start(const char *logdir)
{
    char buf[STREAM_DEV_STR_SIZE];
    onboard_sensors_start();
    ms4525do_publisher_start(&I2C_CONN, "/sensors/ms4525do");
    analog_start();

    parameter_string_get(&sumd_in_uart, buf, sizeof(buf));
    sumd_input_start(get_base_seq_stream_device_from_str(buf));

    parameter_string_get(&hott_tm_uart, buf, sizeof(buf));
    hott_tm_start(&bus, get_base_seq_stream_device_from_str(buf));

    sdlog_start(&bus, logdir);

    parameter_string_get(&datagram_message_port, buf, sizeof(buf));
    datagram_message_start(get_base_seq_stream_device_from_str(buf));
    stream_start(get_base_seq_stream_device_from_str(buf));

    run_attitude_determination();
}
예제 #13
0
	/**
	 * @brief   Get the color of a particular pixel.
	 * @note    Optional.
	 * @note    If x,y is off the screen, the result is undefined.
	 *
	 * @param[in] x, y     The start of the text
	 *
	 * @notapi
	 */
	color_t GDISP_LLD(getpixelcolor)(coord_t x, coord_t y) {
		/* This routine is marked "DO NOT USE" in the original
		 *  GLCD driver. We just keep our GDISP_HARDWARE_READPIXEL
		 *  turned off for now.
		 */
		color_t color;

		#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
			if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0;
		#endif

		aquire_bus();
		set_cursor(x, y);
		stream_start();

		color = lld_lcdReadData();
		color = lld_lcdReadData();

		stream_stop();
		release_bus();

		return color;
	}
예제 #14
0
파일: audio.c 프로젝트: soramimi/qSIP
/**
 * Start the audio playback and recording
 *
 * @param a Audio object
 *
 * @return 0 if success, otherwise errorcode
 */
int audio_start(struct audio *a, struct user_extra_data_t *user_data)
{
	int err;

	if (!a) return EINVAL;

	err = stream_start(a->strm);
	if (err) return err;

	/* Audio filter */
	if (!list_isempty(aufilt_list())) {
		err = aufilt_setup(a);
		if (err) return err;
	}

	/* configurable order of play/src start */
	if (a->cfg.src_first) {
		err  = start_source(&a->tx, a, user_data);
		err |= start_player(&a->rx, a, user_data);
	}
	else {
		err  = start_player(&a->rx, a, user_data);
		err |= start_source(&a->tx, a, user_data);
	}
	if (err)
		return err;

	if (a->tx.ac && a->rx.ac) {
		if (!a->started) {
			re_printf("%H%H", autx_print_pipeline, &a->tx, aurx_print_pipeline, &a->rx);
		}
		a->started = true;
	}

	return err;
}
예제 #15
0
파일: stream.c 프로젝트: ermine/jru
int stream_process (stream_t* strm, account_t* account, extension_t* ext) {
  if (strm == NULL)
    fatal ("stream_start: strm is null");
  if (account == NULL)
    fatal ("stream_start: account is null");


  int err = 0;
  
  switch (strm->state) {
  case STREAM_STATE_NONE:
    fatal ("stream_process: strm->state is STREAM_STATE_NONE");
    
  case STREAM_STATE_START: {
    if (ext->type != EXTENSION_TYPE_STREAM_START) return ERR_BAD_PROTOCOL;
  
    struct stream_start_t* s = (struct stream_start_t*) ext->data;
    if (s->fVersion != NULL && strcmp (s->fVersion, "1.0") != 0) return ERR_XMPP_VERSION;
    stream_start_free (ext->data);
    strm->state = STREAM_STATE_WANT_FEATURES;
    break;
  }

  case STREAM_STATE_WANT_FEATURES: {
    if (ext->type != EXTENSION_TYPE_STREAM_FEATURES) return ERR_BAD_PROTOCOL;

    struct stream_features_data_t* stream_data = strm->userdata;
    stream_data->features = ext->data;

    uint8_t i = 0;
    for (i = stream_data->iterator; i < knownfeatures_len; i++ ) {
      extension_t* feature = array_find (stream_data->features, knownfeatures[i]->extension_type);
      if (feature == NULL) {
        if (knownfeatures[i]->is_mandatory(strm))
          return ERR_FEATURE_IS_REQUIRED;
        else
          continue;
      }
      strm->state = STREAM_STATE_NEGOTATE;
      stream_data->iterator = i;
      err = knownfeatures[i]->negotate (strm, account, &stream_data->data, feature);
      if (err == 1) return 0;
      if (err != 0) return err;
      return 0;
    }
    stream_features_free (stream_data->features);
    free (strm->userdata);
    strm->userdata = NULL;
    strm->state = STREAM_STATE_ESTABLISHED;
    break;
  }

  case STREAM_STATE_NEGOTATE: {
    struct stream_features_data_t* stream_data = strm->userdata;
    err = knownfeatures[stream_data->iterator]->negotate (strm, account, &stream_data->data, ext);
    xstream_extension_free (ext);
    if (err == 1) return 0;
    if (err != 0) return err;
    
    if (knownfeatures[stream_data->iterator]->need_to_restart()) {
      stream_features_free (stream_data->features);
      xmlreader_reset (&strm->reader);
      xmlwriter_reset (&strm->writer);
      int err = xmlwriter_set_prefix (&strm->writer, NULL, strm->content_namespace);
      if (err != 0)
        fatal ("stream_new: cannot set default namespace");
      stream_data->iterator++;
      strm->state = STREAM_STATE_NONE;
      return stream_start (strm, account);
    }

    stream_data->iterator++;

    uint8_t i = 0;
    for (i = stream_data->iterator; i < knownfeatures_len; i++) {
      extension_t* feature = array_find (stream_data->features, knownfeatures[i]->extension_type);
      if (feature == NULL) {
        if (knownfeatures[i]->is_mandatory(strm))
          return ERR_FEATURE_IS_REQUIRED;
        else
          continue;
      }
      strm->state = STREAM_STATE_NEGOTATE;
      stream_data->iterator = i;
      err = knownfeatures[i]->negotate (strm, account, &stream_data->data, feature);
      if (err == 1) return 0;
      if (err != 0) return err;
      break;
    }

    stream_features_free (stream_data->features);
    free (strm->userdata);
    strm->userdata = NULL;
    strm->state = STREAM_STATE_ESTABLISHED;
    return 0;
  }
    
  case STREAM_STATE_ESTABLISHED:
    if (strm->session_handler != NULL)
      strm->session_handler (strm, account, ext);
    xstream_extension_free (ext);
    // break;
    
  default:
    fatal ("Unknown stream state");
  }
  return 0;
}
예제 #16
0
파일: uvcenc.cpp 프로젝트: lenver/usbvideo
int main(int argc, char *argv[])
{
	int idx, tus;
	unsigned long ss;
	struct timeval ts, te;
	char cappath[128];

	if(argc >= 2) {
		strcpy(cappath, argv[1]);
	} else {
		strcpy(cappath, dev_cap);
	}

	signal(SIGQUIT, exit_signal);
	signal(SIGINT,  exit_signal);
	signal(SIGPIPE, SIG_IGN);

	if(enc_init(CAP_WIDTH, CAP_HEIGHT, FPS_VIDEO, VPU_V_AVC) < 0) {
		printf("enc_init error\n");
		return -1;
	}

	if ((fd_cap = open(cappath, O_RDWR)) < 0) {
		printf("Unable to open [%s]\n", cappath);
		goto err;
	}

	if (setup_cap() < 0) {
		printf("Unable to setup capture\n");
		goto err0;
	}

	printf("capture device setup done\n");

	if(display_init(dev_out) < 0) {
		printf("display_init err\n");
		goto err0;
	}

	if (map_buffers() < 0) {
		printf("Unable to map v4l2 memory\n");
		goto err1;
	}

	printf("buffers mapping done\n");

	if (stream_start() < 0) {
		printf("Unable to start stream\n");
		goto err2;
	}

	printf("Stream starting... with fps=%d\n", FPS_VIDEO);

	static int xxx = 0;

	gettimeofday(&ts, 0);

	fd_enc = open("myenc.h264", O_RDWR | O_CREAT | O_TRUNC, 0666);

	do {
		idx = frame_get();
		frame_render(idx);
		frame_put(idx);
		gettimeofday(&te, 0);
		tus = (te.tv_sec - ts.tv_sec) * 1000000 + (te.tv_usec - ts.tv_usec);

		if(tus <= FRAME_DURATION) {
			if(!exitflag) usleep(FRAME_DURATION - tus);
		} else {
			printf("rander a frame with %.3fms\n", tus / 1000.0);
		}
		// printf("rander a frame with %.3fms\n", tus / 1000.0);

		gettimeofday(&ts, 0);

	} while(!exitflag);

	close(fd_enc);

	printf("Stopping stream...\n");

	stream_stop();
err2:
	umap_buffers();
err1:
	display_exit();
err0:
	close(fd_cap);
err:
	enc_exit();

	return 0;
}
예제 #17
0
파일: uvcdec.cpp 프로젝트: lenver/usbvideo
int main(int argc, char *argv[])
{
	int idx, tus, fsize;
	char capdev_str[128];
	unsigned long ss;
	struct timeval ts, te;

	if(argc > 1) {
		// printf("  Usage : %s [file_path]\n", argv[0]);
		strcpy(capdev_str, argv[1]);
	} else {
		strcpy(capdev_str, dev_cap);
	}

	signal(SIGQUIT, exit_signal);
	signal(SIGINT,  exit_signal);
	signal(SIGPIPE, SIG_IGN);

	if(display_init() < 0) {
		printf("display init error\n");
		return 0;
	}

	if(dec_init(CAP_WIDTH, CAP_HEIGHT, VPU_V_MJPG) < 0) {
		printf("decodec init error\n");
		goto err;
	}

	if ((fd_cap = open(capdev_str, O_RDWR)) < 0) {
		printf("Unable to open [%s]\n", capdev_str);
		goto err0;
	}

	if (setup_cap() < 0) {
		printf("Unable to setup capture\n");
		goto err1;
	}

	printf("capture device setup done\n");

	if (map_buffers() < 0) {
		printf("Unable to map I/O memory\n");
		goto err1;
	}

	printf("buffers mapping done\n");

	if (stream_start() < 0) {
		printf("Unable to start stream\n");
		goto err2;
	}

	printf("Stream starting... with fps=%d\n", FPS_VIDEO);

	gettimeofday(&ts, 0);

	do {
		idx = frame_get(&fsize);
		frame_render(idx, fsize);
		frame_put(idx);
		gettimeofday(&te, 0);
		tus = (te.tv_sec - ts.tv_sec) * 1000000 + (te.tv_usec - ts.tv_usec);
		if(tus <= FRAME_DURATION) {
			if(!exitflag) usleep(FRAME_DURATION - tus);
		} else {
			// printf("rander a frame with %.3fms\n", tus / 1000.0);
		}

		printf("Rander a frame sz = %d, takes %.3fms\n", fsize, tus / 1000.0);

		gettimeofday(&ts, 0);

	} while(!exitflag);

	printf("Stopping stream...\n");

	stream_stop();
err2:
	umap_buffers();
err1:
	close(fd_cap);
err0:
	dec_exit();
err:
	display_exit();

	return 0;
}
예제 #18
0
/* Call this function as a thread to handle playback. Playback will 
   stop and this thread will return when you call sndmp3_shutdown(). */
static void sndmp3_thread() {
	int sj;
	
	/* Main command loop */
	while(sndmp3_status != STATUS_QUIT) {
		switch(sndmp3_status) {
			case STATUS_INIT:
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_READY:
				printf("sndserver: waiting on semaphore\r\n");
				sem_wait(sndmp3_halt_sem);
				printf("sndserver: released from semaphore\r\n");
				break;
			case STATUS_STARTING:
				/* Initialize streaming driver */
				if (stream_init(mpglib_callback) < 0) {
					sndmp3_status = STATUS_READY;
				} else {
					/* stream_start(decinfo.samprate, decinfo.channels - 1); */
					stream_start(44100, 1);
					sndmp3_status = STATUS_PLAYING;
				}
				break;
			case STATUS_REINIT:
				/* Re-initialize streaming driver */
				stream_init(NULL);
				sndmp3_status = STATUS_READY;
				break;
			case STATUS_PLAYING: {
				sj = jiffies;
				if (stream_poll() < 0) {
					if (sndmp3_loop) {
						printf("sndserver: restarting '%s'\r\n", mp3_last_fn);
						if (mpglib_init(mp3_last_fn) < 0) {
							sndmp3_status = STATUS_STOPPING;
							mp3_last_fn[0] = 0;
						}
					} else {
						printf("sndserver: not restarting\r\n");
						stream_stop();
						sndmp3_status = STATUS_READY;
						mp3_last_fn[0] = 0;
					}
					// stream_start();
				}
				if (sj == jiffies)
					thd_pass();
				break;
			}
			case STATUS_STOPPING:
				stream_stop();
				sndmp3_status = STATUS_READY;
				break;
		}
	}
	
	/* Done: clean up */
	mpglib_shutdown();
	stream_shutdown();

	sndmp3_status = STATUS_ZOMBIE;
}