Beispiel #1
0
void print_friendlist(Tox *m)
{
    new_lines("[i] Friend List:");

    char name[TOX_MAX_NAME_LENGTH + 1];
    uint8_t fraddr_bin[TOX_FRIEND_ADDRESS_SIZE];
    char fraddr_str[FRADDR_TOSTR_BUFSIZE];

    /* account for the longest name and the longest "base" string and number (int) and id_str */
    char fstring[TOX_MAX_NAME_LENGTH + strlen(ptrn_friend) + 21 + id_str_len];

    uint32_t i = 0;

    while (getfriendname_terminated(m, i, name) != -1) {
        if (!tox_get_client_id(m, i, fraddr_bin))
            fraddr_to_str(fraddr_bin, fraddr_str);
        else
            sprintf(fraddr_str, "???");

        if (strlen(name) <= 0) {
            sprintf(fstring, ptrn_friend, i, "No name?", fraddr_str);
        } else {
            sprintf(fstring, ptrn_friend, i, (uint8_t *)name, fraddr_str);
        }

        i++;
        new_lines(fstring);
    }

    if (i == 0)
        new_lines("+ no friends! D:");
}
Beispiel #2
0
void get_id(Tox *m, char *data)
{
    sprintf(data, "[i] ID: ");
    int offset = strlen(data);
    uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
    tox_get_address(m, address);
    fraddr_to_str(address, data + offset);
}
Beispiel #3
0
void toxDumpAddr(uint8_t* addr)
{
    char buf[200] = {0};
    int off = 0;

    off = sprintf(buf, "[ID]: ");
    fraddr_to_str(addr, buf + off);

    printf("%s", buf);
    printf("\n");
    return;
}
Beispiel #4
0
av_session_t *av_init_session()
{
    av_session_t *_retu = malloc(sizeof(av_session_t));

    /* Initialize our mutex */
    pthread_mutex_init ( &_retu->_mutex, NULL );

    _retu->_messenger = tox_new(1);

    if ( !_retu->_messenger ) {
        fprintf ( stderr, "tox_new() failed!\n" );
        return NULL;
    }

    _retu->_friends = NULL;


    const ALchar *_device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
    int i = 0;
    const ALchar *device_names[20];

    if ( _device_list ) {
        INFO("\nAvailable Capture Devices are:");

        while (*_device_list ) {
            device_names[i] = _device_list;
            INFO("%d) %s", i, device_names[i]);
            _device_list += strlen( _device_list ) + 1;
            ++i;
        }
    }

    INFO("Enter capture device number");

    char dev[2];
    char *left;
    char *warned_ = fgets(dev, 2, stdin);
    (void)warned_;
    long selection = strtol(dev, &left, 10);

    if ( *left ) {
        printf("'%s' is not a number!", dev);
        fflush(stdout);
        exit(EXIT_FAILURE);
    } else {
        INFO("Selected: %d ( %s )", selection, device_names[selection]);
    }

    _retu->audio_capture_device =
        (struct ALCdevice *)alcCaptureOpenDevice(
            device_names[selection], AUDIO_SAMPLE_RATE, AL_FORMAT_MONO16, AUDIO_FRAME_SIZE * 4);


    if (alcGetError((ALCdevice *)_retu->audio_capture_device) != AL_NO_ERROR) {
        printf("Could not start capture device! %d\n", alcGetError((ALCdevice *)_retu->audio_capture_device));
        return 0;
    }

    uint16_t height = 0, width = 0;
#ifdef TOX_FFMPEG
    avdevice_register_all();
    avcodec_register_all();
    av_register_all();

    _retu->video_input_format = av_find_input_format(VIDEO_DRIVER);

    if (avformat_open_input(&_retu->video_format_ctx, DEFAULT_WEBCAM, _retu->video_input_format, NULL) != 0) {
        fprintf(stderr, "Opening video_input_format failed!\n");
        //return -1;
        goto failed_init_ffmpeg;
    }

    avformat_find_stream_info(_retu->video_format_ctx, NULL);
    av_dump_format(_retu->video_format_ctx, 0, DEFAULT_WEBCAM, 0);

    for (i = 0; i < _retu->video_format_ctx->nb_streams; ++i) {
        if (_retu->video_format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
            _retu->video_stream = i;
            break;
        }
    }

    _retu->webcam_decoder_ctx = _retu->video_format_ctx->streams[_retu->video_stream]->codec;
    _retu->webcam_decoder = avcodec_find_decoder(_retu->webcam_decoder_ctx->codec_id);

    if (_retu->webcam_decoder == NULL) {
        fprintf(stderr, "Unsupported codec!\n");
        //return -1;
        goto failed_init_ffmpeg;
    }

    if (_retu->webcam_decoder_ctx == NULL) {
        fprintf(stderr, "Init webcam_decoder_ctx failed!\n");
        //return -1;
        goto failed_init_ffmpeg;
    }

    if (avcodec_open2(_retu->webcam_decoder_ctx, _retu->webcam_decoder, NULL) < 0) {
        fprintf(stderr, "Opening webcam decoder failed!\n");
        //return -1;
        goto failed_init_ffmpeg;
    }

    width = _retu->webcam_decoder_ctx->width;
    height = _retu->webcam_decoder_ctx->height;

failed_init_ffmpeg: ;
#endif
    uint8_t _byte_address[TOX_FRIEND_ADDRESS_SIZE];
    tox_get_address(_retu->_messenger, _byte_address );
    fraddr_to_str( _byte_address, _retu->_my_public_id );


    _retu->av = toxav_new(_retu->_messenger, width, height);

    /* ------------------ */

    toxav_register_callstate_callback(callback_call_started, av_OnStart, _retu->av);
    toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, _retu->av);
    toxav_register_callstate_callback(callback_call_rejected, av_OnReject, _retu->av);
    toxav_register_callstate_callback(callback_call_ended, av_OnEnd, _retu->av);
    toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, _retu->av);

    toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, _retu->av);
    toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, _retu->av);
    toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, _retu->av);

    toxav_register_callstate_callback(callback_recv_error, av_OnError, _retu->av);
    toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, _retu->av);

    /* ------------------ */

    return _retu;
}