/** * Reads data from the encoder (as much as available) and returns it * as a new #page object. */ static struct page * httpd_output_read_page(struct httpd_output *httpd) { size_t size = 0, nbytes; if (httpd->unflushed_input >= 65536) { /* we have fed a lot of input into the encoder, but it didn't give anything back yet - flush now to avoid buffer underruns */ encoder_flush(httpd->encoder, NULL); httpd->unflushed_input = 0; } do { nbytes = encoder_read(httpd->encoder, httpd->buffer + size, sizeof(httpd->buffer) - size); if (nbytes == 0) break; httpd->unflushed_input = 0; size += nbytes; } while (size < sizeof(httpd->buffer)); if (size == 0) return NULL; return page_new_copy(httpd->buffer, size); }
static void recorder_output_close(void *data) { struct recorder_output *recorder = data; /* flush the encoder and write the rest to the file */ if (encoder_flush(recorder->encoder, NULL)) recorder_output_encoder_to_file(recorder, NULL); /* now really close everything */ encoder_close(recorder->encoder); close(recorder->fd); }
int main(int argc, char**argv) { if (argc != 5) { printf("Error 4 arguments required\nProper Usage: ./server serverip controlport clientip dataport\n"); exit(0); } #if WRITEFILES == 1 int x; for (x = 1; x < 5; x++) { printf("arg %d = %s\n", x, argv[x]); } #endif pthread_t menuthread; pthread_t commandtcpsocket; struct rtlsdrstruct* rtlsdr; rtlsdr = malloc(sizeof(struct rtlsdrstruct)); struct liquidobjects* processingstruct; processingstruct = malloc(sizeof(struct liquidobjects)); struct udp_socket* transmitter_socket; transmitter_socket = malloc(sizeof(struct udp_socket)); #if MP3 == 0 struct encoder* mp3encoder; mp3encoder = malloc(sizeof(struct encoder)); #endif #if AUDIO == 0 struct audiostruct* audioobject; audioobject = malloc(sizeof(struct audiostruct)); #endif #if TESTSOCKET == 0 struct udp_socket* testsocket; testsocket = malloc(sizeof(struct udp_socket)); #endif struct tcp_socket* c2socket; c2socket = malloc(sizeof(struct tcp_socket)); //Initialize the control structure struct control* controlstruct; controlstruct = malloc(sizeof(struct control)); controlstruct->demodstruct = processingstruct; controlstruct->sdrstruct = rtlsdr; controlstruct->controlsocket = c2socket; tcp_setaddress(c2socket, argv[1]); tcp_setport(c2socket, atoi(argv[2])); tcp_createsocket(c2socket); udp_setaddress(transmitter_socket, argv[3]); udp_setport(transmitter_socket, atoi(argv[4])); udp_createsocket(transmitter_socket); if (pthread_mutex_init(&rtlsdr->sdrlock, NULL) != 0) { printf("ERROR: Unable to open sdrlock\n"); } rtlsdr->receiverexitflag = false; rtlsdr->sendaudio = true; initialize_dspobjects(processingstruct); #if AUDIO == 0 initializeaudio(audioobject); #endif #if WRITEFILES == 1 processingstruct->fid_demod = fopen("fmdemod_demod.bin", "wb"); processingstruct->filtered = fopen("filtered.bin", "wb"); #endif #if MP3 == 0 && WRITEFILES == 1 mp3encoder->outfile = fopen("mp3output.mp3", "wb"); #endif #if MP3 == 0 initialize_encoder(processingstruct, mp3encoder); #endif #if SDR_WRITE == 0 rtlsdr->filewrite = fopen("sdroutput.bin", "wb"); #endif #if TESTSOCKET == 0 udp_setaddress(testsocket, "127.0.0.1"); udp_setport(testsocket, 9999); udp_createsocket(testsocket); #endif if (opensdr(rtlsdr, processingstruct) == true) { if (pthread_create(&menuthread, NULL, menufunction, controlstruct) == 0) { if (pthread_create(&commandtcpsocket, NULL, c2_socketcontrol, controlstruct) == 0) { while (rtlsdr->receiverexitflag == false) { sdr_work(rtlsdr); #if TESTSOCKET == 0 udp_senddata_test(testsocket, rtlsdr); #endif pthread_mutex_lock(&rtlsdr->sdrlock); if (rtlsdr->sendaudio == true) { demod_work(rtlsdr, processingstruct); udp_senddata_float(transmitter_socket, processingstruct); } else { //send the raw IQ data udp_senddata_IQ(transmitter_socket, rtlsdr); } pthread_mutex_unlock(&rtlsdr->sdrlock); #if AUDIO == 0 playaudio(processingstruct, audioobject); #endif #if MP3 == 0 encoder_work(processingstruct, mp3encoder); #endif } #if MP3 == 0 encoder_flush(processingstruct, mp3encoder); #endif pthread_join(menuthread, NULL); pthread_join(commandtcpsocket, NULL); //TODO Update so that the user can enter the IP and Port through the GUI } else { printf("error unable to open tcpsocket thread\n"); } } else { printf("error unable to open menu thread\n"); } // } else { // printf("Unable to open UDP socket for transmitting the demodulated and encoded audio from the SDR\n"); // } } else { printf("Unable to connect to the TCP socket for receiving data from the SDR, program exiting\n"); exit(0); } //clean up closesdr(rtlsdr); demod_close(processingstruct); #if SDR_WRITE == 0 fclose(rtlsdr->filewrite); #endif #if WRITEFILES == 1 fclose(processingstruct->fid_demod); fclose(processingstruct->filtered); #endif #if MP3 == 0 && WRITEFILES == 1 fclose(mp3encoder->outfile); #endif #if MP3 == 0 close_encoderojects(mp3encoder); #endif closeudpsocket(transmitter_socket); #if AUDIO == 0 closeaudio(audioobject); free(audioobject); #endif pthread_mutex_destroy(&rtlsdr->sdrlock); free(controlstruct); free(rtlsdr); free(processingstruct); #if TESTSOCKET == 0 closeudpsocket(testsocket); free(testsocket); #endif #if MP3 == 0 free(mp3encoder); #endif free(transmitter_socket); return 0; }
int main(int argc, char **argv) { GError *error = NULL; struct audio_format audio_format; bool ret; const char *encoder_name; const struct encoder_plugin *plugin; struct encoder *encoder; struct config_param *param; static char buffer[32768]; ssize_t nbytes; /* parse command line */ if (argc > 3) { g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); return 1; } if (argc > 1) encoder_name = argv[1]; else encoder_name = "vorbis"; audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2); /* create the encoder */ plugin = encoder_plugin_get(encoder_name); if (plugin == NULL) { g_printerr("No such encoder: %s\n", encoder_name); return 1; } param = config_new_param(NULL, -1); config_add_block_param(param, "quality", "5.0", -1); encoder = encoder_init(plugin, param, &error); if (encoder == NULL) { g_printerr("Failed to initialize encoder: %s\n", error->message); g_error_free(error); return 1; } /* open the encoder */ if (argc > 2) { ret = audio_format_parse(&audio_format, argv[2], false, &error); if (!ret) { g_printerr("Failed to parse audio format: %s\n", error->message); g_error_free(error); return 1; } } ret = encoder_open(encoder, &audio_format, &error); if (encoder == NULL) { g_printerr("Failed to open encoder: %s\n", error->message); g_error_free(error); return 1; } /* do it */ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { ret = encoder_write(encoder, buffer, nbytes, &error); if (!ret) { g_printerr("encoder_write() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); } ret = encoder_flush(encoder, &error); if (!ret) { g_printerr("encoder_flush() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); }