Exemplo n.º 1
0
int main (int argc, char *argv[]) {

	kr_client_t *kr;
	kr_videoport_t *kr_videoport;

	if (argc != 2) {
		if (argc > 2) {
			fprintf (stderr, "Only takes station argument.\n");
		} else {
			fprintf (stderr, "No station specified.\n");
		}
		return 1;
	}
		
	kr = kr_connect (argv[1]);
	
	if (kr == NULL) {
		fprintf (stderr, "Could not connect to %s krad radio daemon.\n", argv[1]);
		return 1;
	}	

	kr_videoport = kr_videoport_create (kr);

	if (kr_videoport != NULL) {
		printf ("i worked real good\n");
	}
	
	kr_videoport_set_callback (kr_videoport, videoport_process, NULL);
	
	kr_videoport_activate (kr_videoport);
	
	usleep (8000000);
	
	kr_videoport_deactivate (kr_videoport);
	
	kr_videoport_destroy (kr_videoport);

	kr_disconnect (kr);

	return 0;
	
}
Exemplo n.º 2
0
kr_streamer_t *kr_streamer_create (kr_streamer_params_t *params) {

  kr_streamer_t *streamer;
  uint32_t c;

  streamer = calloc (1, sizeof(kr_streamer_t));

  streamer->params = params;

  streamer->params->channels = 2;
  streamer->params->sample_rate = 48000;

  streamer->client = kr_client_create ("krad streamer client");

  if (streamer->client == NULL) {
    fprintf (stderr, "Could not create KR client.\n");
    exit (1);
  }

  kr_connect (streamer->client, streamer->params->station);

  if (!kr_connected (streamer->client)) {
    fprintf (stderr, "Could not connect to %s krad radio daemon.\n",
             streamer->params->station);
    kr_client_destroy (&streamer->client);
    exit (1);
  }

  if (kr_compositor_get_info_wait (streamer->client,
                                   &streamer->width, &streamer->height,
                                   &streamer->fps_numerator, &streamer->fps_denominator) != 1) {
    fprintf (stderr, "Could not get compositor info!\n");
    kr_client_destroy (&streamer->client);
    exit (1);
  }

  streamer->frame_size = streamer->width * streamer->height * 4;
  //FIXME
  streamer->videoport = kr_videoport_create (streamer->client, 0);

  if (streamer->videoport == NULL) {
    fprintf (stderr, "Could not make videoport.\n");
    kr_client_destroy (&streamer->client);
    exit (1);
  } else {
    printf ("Working!\n");
  }

  kr_videoport_set_callback (streamer->videoport, new_frame, streamer);

  for (c = 0; c < streamer->params->channels; c++) {
    streamer->audio_ring[c] = krad_ringbuffer_create (2200000);
  }

  if (params->file != NULL) {
    streamer->mkv = kr_mkv_create_file (params->file);
  } else {
    streamer->mkv = kr_mkv_create_stream (streamer->params->host,
                                      streamer->params->port,
                                      streamer->params->mount,
                                      streamer->params->password);
  }

  if (streamer->mkv == NULL) {
    fprintf (stderr, "failed to stream :/ \n");
    exit (1);
  }

  streamer->vpx_enc = krad_vpx_encoder_create (streamer->params->width,
                                           streamer->params->height,
                                           streamer->fps_numerator,
                                           streamer->fps_denominator,
                                           streamer->params->video_bitrate);

  if (params->file != NULL) {
    krad_vpx_encoder_set_kf_max_dist (streamer->vpx_enc, 600);
  }

  kr_mkv_add_video_track (streamer->mkv, VP8,
                          streamer->fps_numerator,
                          streamer->fps_denominator,
                          streamer->params->width,
                          streamer->params->height);

  if (kr_mixer_get_info_wait (streamer->client, &streamer->params->sample_rate, NULL) != 1) {
    fprintf (stderr, "Could not get mixer info!\n");
    kr_client_destroy (&streamer->client);
    exit (1);
  }

  streamer->vorbis_enc = krad_vorbis_encoder_create (streamer->params->channels,
                                                     streamer->params->sample_rate,
                                                     streamer->params->audio_quality);

  kr_mkv_add_audio_track (streamer->mkv, VORBIS, streamer->params->sample_rate,
                          streamer->params->channels,
                          streamer->vorbis_enc->hdrdata,
                          3 +
                          streamer->vorbis_enc->header.sz[0] +
                          streamer->vorbis_enc->header.sz[1] +
                          streamer->vorbis_enc->header.sz[2]);
  //FIXME
  streamer->audioport = kr_audioport_create (streamer->client, "streamer2",
   0);
  kr_audioport_set_callback (streamer->audioport, audioport_process, streamer);

  streamer->frame_ring = krad_ringbuffer_create (90 * sizeof(krad_frame_t *));

  streamer->framepool = krad_framepool_create (streamer->width,
                                               streamer->height,
                                               8);

  return streamer;
}
Exemplo n.º 3
0
int main (int argc, char *argv[]) {

  int ret;
	uint32_t width;
	uint32_t height;
	kr_client_t *client;
	kr_videoport_t *videoport;
  kr_udp_recvr_t *udp_recvr;
  int port;
  
  port = 3777;
  ret = 0;

	if (argc < 2) {
		if (argc > 2) {
			fprintf (stderr, "Only takes station argument.\n");
		} else {
			fprintf (stderr, "No station specified.\n");
		}
		return 1;
	}
	
	if (argc > 2) {
	  port = atoi (argv[2]);
	}	
	
	client = kr_client_create ("krad videoport client");

	if (client == NULL) {
		fprintf (stderr, "Could not create KR client.\n");
		return 1;
	}	

  kr_connect (client, argv[1]);
  
  if (!kr_connected (client)) {
		fprintf (stderr, "Could not connect to %s krad radio daemon.\n", argv[1]);
	  kr_client_destroy (&client);
	  return 1;
  }
	
  if (kr_compositor_get_info_wait (client, &width, &height, NULL, NULL) != 1) {
	  kr_client_destroy (&client);
	  return 1;
  }
  
  if (kr_compositor_get_info_wait (client, &width, &height, NULL, NULL) != 1) {
    fprintf (stderr, "Could not get compositor info!\n");
	  kr_client_destroy (&client);
	  return 1;
  }

	videoport = kr_videoport_create (client, INPUT);

	if (videoport == NULL) {
		fprintf (stderr, "Could not make videoport.\n");
	  kr_client_destroy (&client);
	  return 1;
	} else {
		printf ("Working!\n");
	}

  udp_recvr = calloc (1, sizeof (kr_udp_recvr_t));
  
  udp_recvr->width = width;
  udp_recvr->height = height;
	
	udp_recvr->client = client;
	udp_recvr->videoport = videoport;
	
	kr_videoport_set_callback (videoport, videoport_process, udp_recvr);
	
  signal (SIGINT, signal_recv);
  signal (SIGTERM, signal_recv);	
	
	kr_videoport_activate (videoport);
	
  kr_udp_recvr (udp_recvr, port);	
	
	kr_videoport_deactivate (videoport);
	
	kr_videoport_destroy (videoport);

	kr_client_destroy (&client);

	if (udp_recvr->frames > 0) {
		printf ("Rendered %d frames!\n", udp_recvr->frames);
	}

  free (udp_recvr);

	if (ret == 0) {
		printf ("Worked!\n");
	}

	return ret;	
}