Example #1
0
File: tpod.c Project: grafoo/tpod
int main(int argc, char **argv) {
  signal(SIGINT, signal_handler);

  if (sqlite3_open("tpod.db", &db) != SQLITE_OK) {
    printf("failed to open database: %s\n", sqlite3_errmsg(db));
    cleanup();
    return 1;
  }

  mpg123_init();

  ao_initialize();

  if (strcmp("-s", argv[1]) == 0) {
    struct mg_mgr mgr;
    struct mg_connection *con;

    mg_mgr_init(&mgr, NULL);
    con = mg_bind(&mgr, "8080", ev_handler);
    mg_set_protocol_http_websocket(con);
    mg_enable_multithreading(con);
    s_http_server_opts.document_root = "./static";

    while (srv) {
      mg_mgr_poll(&mgr, 1000);
    }

    mg_mgr_free(&mgr);
    cleanup();

    exit(130);
  } else {
    mode = 1;
    play_stream(argv[1]);
    cleanup();
  }

  return 0;
}
Example #2
0
THREAD(PlayStream, args){
    RADIO_STREAM *stream = (RADIO_STREAM*) args;
    play_stream(*stream);
}
Example #3
0
File: tpod.c Project: grafoo/tpod
static void handle_play(struct mg_connection *con, struct http_message *msg) {
  char stream_uri[200];
  mg_get_http_var(&msg->body, "streamURI", stream_uri, sizeof(stream_uri));
  mg_printf(con, "%s", "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n");
  play_stream(stream_uri);
}
Example #4
0
int main(int argc, char *argv[])
{
	struct play_s play;
	play.action = action_play;
	const char *val_str = NULL;
	int opt, option_index;

	struct option long_options[] = {
		{"info",		1, NULL, 'i'},
		{"wav",			1, NULL, 'a'},
		{"bmp",			1, NULL, 'b'},
		{"png",			1, NULL, 'p'},
		{"yuv4mpeg",		1, NULL, 'y'},
		{"yuv4mpegTV",		1, NULL, 'Y'},
		{"out",			1, NULL, 'o'},
		{"fps",			1, NULL, 'f'},
		{"resize",		1, NULL, 'r'},
		{"adjust",		1, NULL, 'g'},
		{"silence",		1, NULL, 'l'},
		{"alsa-device",		1, NULL, 'd'},
		{"streaming",		0, NULL, 't'},
		{"compressed",		1, NULL, 'c'},
		{"uncompressed",	1, NULL, 'u'},
		{"show",		1, NULL, 's'},
		{"verbosity",		1, NULL, 'v'},
		{"help",		0, NULL, 'h'},
		{"version",		0, NULL, 'V'},
		{0, 0, 0, 0}
	};
	option_index = 0;

	play.fps = 0;

	play.silence_threshold = 200000; /* 0.2 sec accuracy */
	play.alsa_playback_device = "default";

	/* don't scale by default */
	play.scale_factor = 1;
	play.scale_width = play.scale_height = 0;

	/* default buffer size is 10MiB */
	play.compressed_size = 10 * 1024 * 1024;
	play.uncompressed_size = 10 * 1024 * 1024;

	/* log to stderr */
	play.log_level = 0;
	play.info_level = 1;

	/* default export settings */
	play.interpolate = 1;
	play.export_filename_format = NULL; /* user has to specify */
	play.img_format = IMG_BMP;
	play.tv_levels = 0;

	/* global color correction */
	play.override_color_correction = 0;
	play.brightness = play.contrast = 0;
	play.red_gamma = 1.0;
	play.green_gamma = 1.0;
	play.blue_gamma = 1.0;

	while ((opt = getopt_long(argc, argv, "i:a:b:p:y:Y:o:f:r:g:l:td:c:u:s:v:hV",
				  long_options, &optind)) != -1) {
		switch (opt) {
		case 'i':
			play.info_level = atoi(optarg);
			if (play.info_level < 1)
				goto usage;
			play.action = action_info;
			break;
		case 'a':
			play.export_audio_id = atoi(optarg);
			if (play.export_audio_id < 1)
				goto usage;
			play.action = action_wav;
			break;
		case 'p':
			play.img_format = IMG_PNG;
		case 'b':
			play.export_video_id = atoi(optarg);
			if (play.export_video_id < 1)
				goto usage;
			play.action = action_img;
			break;
		case 'Y':
			play.tv_levels = 1;
		case 'y':
			play.export_video_id = atoi(optarg);
			if (play.export_video_id < 1)
				goto usage;
			play.action = action_yuv4mpeg;
			break;
		case 'f':
			play.fps = atof(optarg);
			if (play.fps <= 0)
				goto usage;
			break;
		case 'r':
			if (strstr(optarg, "x")) {
				sscanf(optarg, "%ux%u", &play.scale_width, &play.scale_height);
				if ((!play.scale_width) | (!play.scale_height))
					goto usage;
			} else {
				play.scale_factor = atof(optarg);
				if (play.scale_factor <= 0)
					goto usage;
			}
			break;
		case 'g':
			play.override_color_correction = 1;
			sscanf(optarg, "%f;%f;%f;%f;%f", &play.brightness, &play.contrast,
			       &play.red_gamma, &play.green_gamma, &play.blue_gamma);
			break;
		case 'l':
			/* glc_utime_t so always positive */
			play.silence_threshold = atof(optarg) * 1000000;
			break;
		case 'd':
			play.alsa_playback_device = optarg;
			break;
		case 'o':
			if (!strcmp(optarg, "-")) /** \todo fopen(1) ? */
				play.export_filename_format = "/dev/stdout";
			else
				play.export_filename_format = optarg;
			break;
		case 't':
			play.interpolate = 0;
			break;
		case 'c':
			play.compressed_size = atoi(optarg) * 1024 * 1024;
			if (play.compressed_size <= 0)
				goto usage;
			break;
		case 'u':
			play.uncompressed_size = atoi(optarg) * 1024 * 1024;
			if (play.uncompressed_size <= 0)
				goto usage;
			break;
		case 's':
			val_str = optarg;
			play.action = action_val;
			break;
		case 'v':
			play.log_level = atoi(optarg);
			if (play.log_level < 0)
				goto usage;
			break;
		case 'V':
			printf("glc version %s\n", glc_version());
			return EXIT_SUCCESS;
		case 'h':
		default:
			goto usage;
		}
	}

	/* stream file is mandatory */
	if (optind >= argc)
		goto usage;
	play.stream_file = argv[optind];

	/* same goes to output file */
	if (((play.action == action_img) |
	     (play.action == action_wav) |
	     (play.action == action_yuv4mpeg)) &&
	    (play.export_filename_format == NULL))
		goto usage;

	/* we do global initialization */
	glc_init(&play.glc);
	glc_log_set_level(&play.glc, play.log_level);
	glc_util_log_version(&play.glc);
	glc_state_init(&play.glc);

	/* open stream file */
	if (file_init(&play.file, &play.glc))
		return EXIT_FAILURE;
	if (file_open_source(play.file, play.stream_file))
		return EXIT_FAILURE;

	/* load information and check that the file is valid */
	if (file_read_info(play.file, &play.stream_info, &play.info_name, &play.info_date))
		return EXIT_FAILURE;

	/*
	 If the fps hasn't been specified read it from the
	 stream information.
	*/
	if (play.fps == 0)
		play.fps = play.stream_info.fps;

	switch (play.action) {
	case action_play:
		if (play_stream(&play))
			return EXIT_FAILURE;
		break;
	case action_wav:
		if (export_wav(&play))
			return EXIT_FAILURE;
		break;
	case action_yuv4mpeg:
		if (export_yuv4mpeg(&play))
			return EXIT_FAILURE;
		break;
	case action_img:
		if (export_img(&play))
			return EXIT_FAILURE;
		break;
	case action_info:
		if (stream_info(&play))
			return EXIT_FAILURE;
		break;
	case action_val:
		if (show_info_value(&play, val_str))
			return EXIT_FAILURE;
		break;
	}

	/* our cleanup */
	file_close_source(play.file);
	file_destroy(play.file);

	free(play.info_name);
	free(play.info_date);

	glc_state_destroy(&play.glc);
	glc_destroy(&play.glc);

	return EXIT_SUCCESS;

usage:
	printf("%s [file] [option]...\n", argv[0]);
	printf("  -i, --info=LEVEL         show stream information, LEVEL must be\n"
	       "                             greater than 0\n"
	       "  -a, --wav=NUM            save audio stream NUM in wav format\n"
	       "  -b, --bmp=NUM            save frames from stream NUM as bmp files\n"
	       "                             (use -o pic-%%010d.bmp f.ex.)\n"
	       "  -p, --png=NUM            save frames from stream NUM as png files\n"
	       "  -y, --yuv4mpeg=NUM       save video stream NUM in yuv4mpeg format\n"
	       "  -Y, --yuv4mpegTV=NUM     same as -y but outputs TV luma/chroma range\n"
	       "                             use this if -y increases contrast\n"
	       "  -o, --out=FILE           write to FILE\n"
	       "  -f, --fps=FPS            save images or video at FPS\n"
	       "  -r, --resize=VAL         resize pictures with scale factor VAL or WxH\n"
	       "  -g, --color=ADJUST       adjust colors\n"
	       "                             format is brightness;contrast;red;green;blue\n"
	       "  -l, --silence=SECONDS    audio silence threshold in seconds\n"
	       "                             default threshold is 0.2\n"
	       "  -d, --alsa-device=DEV    alsa playback device name\n"
	       "                             default is 'default'\n"
	       "  -t, --streaming          streaming mode (eg. don't interpolate data)\n"
	       "  -c, --compressed=SIZE    compressed stream buffer size in MiB\n"
	       "                             default is 10 MiB\n"
	       "  -u, --uncompressed=SIZE  uncompressed stream buffer size in MiB\n"
	       "                             default is 10 MiB\n"
	       "  -s, --show=VAL           show stream summary value, possible values are:\n"
	       "                             all, signature, version, flags, fps,\n"
	       "                             pid, name, date\n"
	       "  -v, --verbosity=LEVEL    verbosity level\n"
	       "  -h, --help               show help\n");

	return EXIT_FAILURE;
}