Ejemplo n.º 1
0
int main()
{
	ct_print_header("text/html", NULL);

	const gchar *path  = ct_get_path_info();
	const gchar *query = ct_get_query_string();

	GList *thumbs = gen_thumbs(read_dir("large"));

	if (!path || g_str_equal(path, "/"))
		frame_index();
	else if (g_str_equal(path, "/head"))
		frame_head();
	else if (g_str_equal(path, "/nav"))
		frame_nav(FALSE, thumbs);
	else if (g_str_equal(path, "/noframe"))
		frame_nav(TRUE, thumbs);
	else if (g_str_equal(path, "/show_small"))
		frame_show("small", "show_large", query);
	else if (g_str_equal(path, "/show_large"))
		frame_show("large", "show_small", query);
}
Ejemplo n.º 2
0
static int frame_command_filter(char *id, int argc, char **argv)
{
  frame_t *frame;
  char *class_id;
  GList *options = NULL;
  filter_t *filter;
  int argx;

  if ( id == NULL ) {
    frame_command_filter_show_classes();
    return 0;
  }

  /* Retrieve frame descriptor */
  if ( (frame = frame_command_get_frame(id)) == NULL )
    return -1;

  if ( argc < 1 ) {
    error(NULL, "Missing filter class specification");
    frame_command_filter_show_classes();
    return -1;
  }
  class_id = argv[0];

  /* Parse command arguments */
  for (argx = 1; argx < argc; argx++) {
    char *str = argv[argx];
    options = g_list_append(options, str);
  }

  /* Alloc filter */
  filter = filter_alloc(class_id, options);

  g_list_free(options);

  if ( filter == NULL ) {
    frame_command_filter_show_classes();
    return -1;
  }

  /* Add item to the filter chain */
  frame_add_filter(frame, filter);

  /* Show frame with its new filter list */
  frame_show(frame, log_hdr_(FRAME_TAG));

  /* Refresh frame for applying filters */
  frame_update_all(frame);

  return 0;
}
Ejemplo n.º 3
0
static int frame_command_show(char *id)
{
  char *hdr = log_hdr_(FRAME_TAG);

  if ( id != NULL ) {
    frame_t *frame = frame_command_get_frame(id);

    if ( frame == NULL )
      return -1;

    frame_show(frame, hdr);
  }
  else {
    g_list_foreach(frame_command_display->root->children, (GFunc) frame_show_tree, hdr);
  }

  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char** argv)
{
	AVFormatContext* avfmt_ctx = NULL;
	int video_stream;
	enum AVCodecID video_codec;

	if (argc < 2)
	{
		fprintf(stderr, "Usage: %s filename\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	char *filename = argv[1];

	av_register_all();

	if (avformat_open_input(&avfmt_ctx, filename, NULL, NULL) < 0)
	{
		fprintf(stderr, "Could not open source file %s\n", filename);
		exit(1);
	}

	if (avformat_find_stream_info(avfmt_ctx, NULL) < 0)
	{
		fprintf(stderr, "Could not find stream information\n");
		avformat_close_input(&avfmt_ctx);
		exit(1);
	}

	video_stream = av_find_best_stream(avfmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
	if (video_stream < 0)
	{
		fprintf(stderr, "Could not find video stream in input file\n");
		avformat_close_input(&avfmt_ctx);
		exit(1);
	}

	video_codec = avfmt_ctx->streams[video_stream]->codec->codec_id;

	if (video_codec != AV_CODEC_ID_MPEG1VIDEO && video_codec != AV_CODEC_ID_MPEG2VIDEO)
	{
		fprintf(stderr, "Can't handle codec %s\n", avcodec_get_name(video_codec));
		avformat_close_input(&avfmt_ctx);
		exit(1);
	}

	AVPacket pkt;
	av_init_packet(&pkt);
	pkt.data = NULL;
	pkt.size = 0;

	struct mpeg_t mpeg;
	memset(&mpeg, 0, sizeof(mpeg));
	if (video_codec == AV_CODEC_ID_MPEG1VIDEO)
		mpeg.type = MPEG1;
	else
		mpeg.type = MPEG2;

	if (!ve_open())
		err(EXIT_FAILURE, "Can't open VE");

	struct frame_buffers_t frame_buffers = { NULL, NULL, NULL };

	unsigned int disp_frame = 0, gop_offset = 0, gop_frames = 0, last_gop = 0;
	struct frame_t *frames[RING_BUFFER_SIZE];
	memset(frames, 0, sizeof(frames));

	// activate MPEG engine
	writel(ve_get_regs() + 0x00, 0x00130000);

	printf("Playing now... press Enter for next frame!\n");

	while (av_read_frame(avfmt_ctx, &pkt) >= 0)
	{
		mpeg.data = pkt.data;
		mpeg.len = pkt.size;
		mpeg.pos = 0;

		if (pkt.stream_index == video_stream && parse_mpeg(&mpeg))
		{
			// create output buffer
			frame_buffers.output = frame_new(mpeg.width, mpeg.height, COLOR_YUV420);
			if (!frame_buffers.backward)
				frame_buffers.backward = frame_ref(frame_buffers.output);
			if (!frame_buffers.forward)
				frame_buffers.forward = frame_ref(frame_buffers.output);

			// decode frame
			decode_mpeg(&frame_buffers, &mpeg);

			// simple frame reordering (not safe, only for testing)
			// count frames
			if (mpeg.gop > last_gop)
			{
				last_gop = mpeg.gop;
				gop_offset += gop_frames;
				gop_frames = 0;
			}
			gop_frames++;

			// save frame in ringbuffer
			if (frames[(gop_offset + mpeg.temporal_reference) % RING_BUFFER_SIZE] != NULL)
			{
				printf("Buffer overrun!\n");
				frame_unref(frames[(gop_offset + mpeg.temporal_reference) % RING_BUFFER_SIZE]);
			}
			frames[(gop_offset + mpeg.temporal_reference) % RING_BUFFER_SIZE] = frame_buffers.output;

			// if we decoded a displayable frame, show it
			if (frames[disp_frame % RING_BUFFER_SIZE] != NULL)
			{
				frame_show(frames[disp_frame % RING_BUFFER_SIZE]);
				frame_unref(frames[(disp_frame - 2) % RING_BUFFER_SIZE]);
				frames[(disp_frame - 2) % RING_BUFFER_SIZE] = NULL;
				disp_frame++;
				getchar();
			}

		}
		av_free_packet(&pkt);
	}

	// stop MPEG engine
	writel(ve_get_regs() + 0x0, 0x00130007);

	// show left over frames
	while (disp_frame < gop_offset + gop_frames && frames[disp_frame % RING_BUFFER_SIZE] != NULL)
	{
		frame_show(frames[disp_frame % RING_BUFFER_SIZE]);
		frame_unref(frames[(disp_frame - 2) % RING_BUFFER_SIZE]);
		frames[(disp_frame - 2) % RING_BUFFER_SIZE] = NULL;
		disp_frame++;
		getchar();
	}

	disp_close();

	frame_unref(frames[(disp_frame - 2) % RING_BUFFER_SIZE]);
	frame_unref(frames[(disp_frame - 1) % RING_BUFFER_SIZE]);

	frame_unref(frame_buffers.forward);
	frame_unref(frame_buffers.backward);

	ve_close();

	avformat_close_input(&avfmt_ctx);

	return 0;
}
Ejemplo n.º 5
0
static int frame_command_add(char *id, int argc, char **argv)
{
  frame_t *parent = NULL;
  frame_geometry_t g = FRAME_GEOMETRY_NULL;
  unsigned int flags = 0;
  frame_t *frame;
  int argx;

  /* Parse command arguments */
  for (argx = 0; argx < argc; argx++) {
    char *str = argv[argx];
    char *eq = strchr(str, '=');

    if ( eq != NULL ) {
      *(eq++) = '\0';

      if ( strcmp(str, "frame") == 0 ) {
	if ( eq[0] != '\0' ) {
	  if ( (parent = frame_command_get_frame(eq)) == NULL )
	    return -1;
	}
      }
      else if ( strcmp(str, "window") == 0 ) {
	if ( frame_geometry_parse(eq, &g) ) {
	  error(NULL, "Syntax error in window geometry specification");
	  return -1;
	}
      }
      else {
	error(NULL, "Unknown option '%s'", str);
	return -1;
      }
    }
    else {
      if ( strcmp(str, "lazy") == 0 ) {
	flags |= FRAME_REFRESH_LAZY;
      }
      else {
	error(NULL, "Illegal argument '%s'", str);
	return -1;
      }
    }
  }

  /* Delete already existing frame */
  frame = frame_get_child_by_id(frame_command_display->root, id);
  if ( frame != NULL ) {
    frame_command_remove_guts(frame, NULL);
    frame = NULL;
  }

  /* Use root frame as default parent frame */
  if ( parent == NULL )
    parent = frame_command_display->root;

  /* Alloc new frame */
  frame = frame_alloc_child(id, parent, &g);
  if ( frame == NULL )
    return -1;
  frame->refresh_flags = flags;

  /* Show newly created frame */
  frame_show(frame, log_hdr_(FRAME_TAG));

  /* Refresh frame */
  frame_update_all(frame);

  /* Add newly created frame to the Display Tool */
  frame_display_frame_add(frame_command_display, frame);

  return 0;
}