int kr_streamer_destroy (kr_streamer_t **streamer) { int c; if ((streamer == NULL) || (*streamer == NULL)) { return -1; } krad_vpx_encoder_destroy (&(*streamer)->vpx_enc); kr_mkv_destroy (&(*streamer)->mkv); kr_audioport_disconnect((*streamer)->audioport); kr_audioport_destroy ((*streamer)->audioport); kr_videoport_deactivate ((*streamer)->videoport); kr_videoport_destroy ((*streamer)->videoport); kr_client_destroy (&(*streamer)->client); krad_vorbis_encoder_destroy (&(*streamer)->vorbis_enc); for (c = 0; c < (*streamer)->params->channels; c++) { krad_ringbuffer_free ((*streamer)->audio_ring[c]); } krad_ringbuffer_free ((*streamer)->frame_ring); krad_framepool_destroy (&(*streamer)->framepool); free (*streamer); *streamer = NULL; return 0; }
int main (int argc, char *argv[]) { int i; int ret; kr_client_t *client; kr_audioport_t *audioport; krad_mixer_portgroup_direction_t direction; uint32_t sample_rate; ret = 0; direction = INPUT; if (argc != 2) { if (argc > 2) { fprintf (stderr, "Only takes station argument.\n"); } else { fprintf (stderr, "No station specified.\n"); } return 1; } client = kr_client_create ("krad audioport 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_mixer_get_info_wait (client, &sample_rate, NULL) != 1) { fprintf (stderr, "Could not get mixer info!\n"); kr_client_destroy (&client); return 1; } if (direction == INPUT) { krad_tone = krad_tone_create (sample_rate); krad_tone_add_preset (krad_tone, "3"); krad_tone2 = krad_tone_create (sample_rate); krad_tone_add_preset (krad_tone2, "3"); } audioport = kr_audioport_create (client, direction); if (audioport == NULL) { fprintf (stderr, "Could not make audioport.\n"); kr_client_destroy (&client); return 1; } else { printf ("Working!\n"); } kr_audioport_set_callback (audioport, audioport_process, audioport); signal (SIGINT, signal_recv); signal (SIGTERM, signal_recv); kr_audioport_activate (audioport); for (i = 0; i < 40; i++) { usleep (30000); if (destroy == 1) { printf ("Got signal!\n"); break; } if (kr_audioport_error (audioport)) { printf ("Error: %s\n", "Audioport Error"); ret = 1; break; } } kr_audioport_deactivate (audioport); kr_audioport_destroy (audioport); if (direction == INPUT) { krad_tone_destroy (krad_tone); krad_tone_destroy (krad_tone2); } kr_client_destroy (&client); if (ret == 0) { printf ("Worked!\n"); } return ret; }