Exemplo n.º 1
0
int main()
{

    measure_memory();
//    measure_read_file();

    return;

    pid_t pid = fork();
    if (pid==0) // start receiver for child
    {
        printf("starting receiver");
        start_receiver();
    }else if (pid<0)
    {
        printf("failed to fork");
        exit(1);
    }else
    {
        sleep(2);
        measure_signalling();
        //	measure_kernel_call();
        //      measure_read_file();
    }
    return 0;
}
Exemplo n.º 2
0
void
exit_receiver (FL_OBJECT *ob, long data)
{
	FILE *fp;
	
	fp = fopen ("receiver_no_start", "w");
	fprintf (fp, "No Start\n");
	fclose (fp);
	
	start_receiver (NULL, 0);
}
Exemplo n.º 3
0
int main() {

    fprintf(stderr, "Starting audio_receiver test...\n");

    // Open files to write audio
    if ((F_audio1 = fopen(name_audio1, "wb")) == NULL) {
        perror(name_audio1);
        exit(errno);
    }
    if ((F_audio2 = fopen(name_audio2, "wb")) == NULL) {
        perror(name_audio2);
        exit(errno);
    }

    // General pourpouse variables.
    time_t start, stop;
    audio_frame2 *audio_frame;

    // Receiver configuration
    stream_list_t *video_stream_list = init_stream_list(); // Not used
    stream_list_t *audio_stream_list = init_stream_list();
    receiver_t *receiver = init_receiver(video_stream_list, audio_stream_list, 5004, 5006);

    // First stream and participant configuration
    participant_data_t *p1 = init_participant(1, INPUT, NULL, 0);
    stream_data_t *stream1 = init_stream(AUDIO, INPUT, rand(), I_AWAIT, 25.0, "Stream1");
    add_participant_stream(stream1, p1);
    add_stream(receiver->audio_stream_list, stream1);
    fprintf(stderr, " ·Stream1 configuration: 1 bps, 32000Hz, 1 channel, mulaw\n");
    ap_config(stream1->audio, 1, 32000, 1, AC_MULAW);
    ap_worker_start(stream1->audio);

    // Second stream and participant configuration
    participant_data_t *p2 = init_participant(2, INPUT, NULL, 0);
    stream_data_t *stream2 = init_stream(AUDIO, INPUT, rand(), I_AWAIT, 25.0, "Stream2");
    add_participant_stream(stream2, p2);
    add_stream(receiver->audio_stream_list, stream2);
    fprintf(stderr, " ·Stream2 configuration: 1 bps, 8000Hz, 1 channel, mulaw\n");
    ap_config(stream2->audio, 1, 8000, 1, AC_MULAW);
    ap_worker_start(stream2->audio);

    if (start_receiver(receiver)) {
        fprintf(stderr, " ·Receiver started!\n");

#ifdef STREAM1
        // STREAM1 recording block
        fprintf(stderr, "  ·Waiting for audio_frame2 data\n");
        while (stream1->audio->decoded_cq->level == CIRCULAR_QUEUE_EMPTY) {
#ifdef QUEUE_PRINT
            print_cq_status(stream1->audio->decoded_cq, "wait stream1");
#endif
        }
#ifdef QUEUE_PRINT
        print_cq_status(stream1->audio->decoded_cq, "continue stream1");
#endif

        fprintf(stderr, "   ·Copying to file... ");
        start = time(NULL);
        stop = start + RECORD_TIME;
        while (time(NULL) < stop) { // RECORD_TIME seconds loop
            audio_frame = cq_get_front(stream1->audio->decoded_cq);
            if (audio_frame != NULL) {
                fwrite(audio_frame->data[0], audio_frame->data_len[0], 1, F_audio1);
                cq_remove_bag(stream1->audio->decoded_cq);
            }
        }
        fprintf(stderr, "Done!\n");
#endif //STREAM1

#ifdef STREAM2
        // STREAM2 recording block
        fprintf(stderr, "  ·Waiting for audio_frame2 data\n");
        while (stream2->audio->decoded_cq->level == CIRCULAR_QUEUE_EMPTY) {
#ifdef QUEUE_PRINT
            print_cq_status(stream2->audio->decoded_cq, "wait stream2");
#endif
        }
#ifdef QUEUE_PRINT
        print_cq_status(stream2->audio->decoded_cq, "continue stream2");
#endif
        fprintf(stderr, "   ·Copying to file... ");
        start = time(NULL);
        stop = start + RECORD_TIME;
        while (time(NULL) < stop) { // RECORD_TIME seconds loop
            audio_frame = cq_get_front(stream2->audio->decoded_cq);
            if (audio_frame != NULL) {
                fwrite(audio_frame->data[0], audio_frame->data_len[0], 1, F_audio2);
                cq_remove_bag(stream2->audio->decoded_cq);
            }
        }
        fprintf(stderr, "Done!\n");
#endif //STREAM2

        // Finish and destroy objects
        stop_receiver(receiver);
        destroy_receiver(receiver);
        fprintf(stderr, " ·Receiver stopped\n");
        destroy_stream_list(video_stream_list);
        destroy_stream_list(audio_stream_list);
    }

    if (fclose(F_audio1) != 0) {
        perror(name_audio1);
        exit(-1);
    }
    if (fclose(F_audio2) != 0) {
        perror(name_audio2);
        exit(-1);
    }
    fprintf(stderr, "Finished\n");
}
Exemplo n.º 4
0
int main()
{
    fprintf(stderr,
            "Starting audio_rec_trans test (max %i seconds)\n",
            LIVE_TIME);
    fprintf(stderr,
            "Issue kill -10 %i to dinamically add a couple of streams.\n",
            getpid()); 

    // Attach the handlers to the signals and prepare block stuff.
    signal(SIGINT, finish_handler);
    signal(SIGALRM, finish_handler);
    signal(SIGUSR1, action_handler);

    // Start live time alarm
    alarm(LIVE_TIME);

    // Receiver startup
    fprintf(stderr,
            " ·Configuring receiver (listen at %i)\n",
            RECEIVER_AUDIO_PORT);
    receiver = init_receiver(init_stream_list(),
            init_stream_list(),
            RECEIVER_VIDEO_PORT,
            RECEIVER_AUDIO_PORT);
    start_receiver(receiver);
    add_receiver_entity();

    // Transmitter startup
    fprintf(stderr, " ·Configuring transmitter\n");
    transmitter = init_transmitter(init_stream_list(),
            init_stream_list(),
            25.0);
    start_transmitter(transmitter);
    add_transmitter_entity(TRANSMITTER_IP_1, TRANSMITTER_PORT_1);

    // Temporal variables and initializations
    stream_data_t *in_stream_couple1,
                  *out_stream_couple1,
                  *in_stream_couple2,
                  *out_stream_couple2;
    bool cross = false;
    bool verbose = true;
    time_t lap_time = time(NULL) + SWITCH_TIME;

    // Main loop
    fprintf(stderr,
            " ·Forwarding audio and switching the streams every %i seconds...\n",
            SWITCH_TIME);
    while(!stop) {

        // Lap time control
        if (time(NULL) > lap_time) {
            lap_time = time(NULL) + SWITCH_TIME;
            cross = !cross;
            verbose = true;
            fprintf(stderr, "Done!\n");
        }

        // Cross sending control
        if (!cross) {
            in_stream_couple1 = receiver->audio_stream_list->first;
            out_stream_couple1 = transmitter->audio_stream_list->first;
            in_stream_couple2 = in_stream_couple1->next;
            out_stream_couple2 = out_stream_couple1->next;
        }
        else {
            in_stream_couple1 = receiver->audio_stream_list->first;
            out_stream_couple1 = transmitter->audio_stream_list->last;
            in_stream_couple2 = in_stream_couple1->next;
            out_stream_couple2 = out_stream_couple1->prev;
        }

        // Forward audio from receiver to transmitter
        if (in_stream_couple2 == NULL || out_stream_couple2 == NULL) {
            // One couple case (first to first).
            if (verbose) {
                sprintf(msg, "  ·Sending %s -> %s ",
                        in_stream_couple1->stream_name,
                        out_stream_couple1->stream_name);
            }
            audio_frame_forward(in_stream_couple1, out_stream_couple1);
        }
        else {
            // Two couples case (first to first, next to next).
            if (verbose) {
                sprintf(msg, "  ·Sending %s -> %s and %s -> %s ",
                        in_stream_couple1->stream_name,
                        out_stream_couple1->stream_name,
                        in_stream_couple2->stream_name,
                        out_stream_couple2->stream_name);
            }
            audio_frame_forward(in_stream_couple1, out_stream_couple1);
            audio_frame_forward(in_stream_couple2, out_stream_couple2);
        }

        // Print information message
        if (verbose) {
            fprintf(stderr, "%s", msg);
            verbose = false;
        }

        //Try to not send all the audio suddently.
        usleep(SEND_TIME);
    }
    fprintf(stderr, "Done!\n");

    // Finish and destroy receiver objects
    stop_receiver(receiver);
    destroy_stream_list(receiver->video_stream_list);
    destroy_stream_list(receiver->audio_stream_list);
    destroy_receiver(receiver);
    fprintf(stderr, " ·Receiver stopped\n");

    // Finish and destroy transmitter objects
    stop_transmitter(transmitter);
    destroy_stream_list(transmitter->video_stream_list);
    destroy_stream_list(transmitter->audio_stream_list);
    destroy_transmitter(transmitter);
    fprintf(stderr, " ·Transmitter stopped\n");

    fprintf(stderr, "Finished\n");
}