Пример #1
0
    /*
     * Call with audio and video on both sides. Alice calls Bob.
     */
    CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
        /* Both send */
        toxav_send_audio(status_control.Alice.av, sample_payload, 10);
        toxav_send_video(status_control.Alice.av, sample_image);

        toxav_send_audio(status_control.Bob.av, sample_payload, 10);
        toxav_send_video(status_control.Bob.av, sample_image);

        /* Both receive */
        int16_t storage[10];
        vpx_image_t *video_storage;
        int recved;

        /* Payload from Bob */
        recved = toxav_recv_audio(status_control.Alice.av, 10, storage);

        if ( recved ) {
            /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
            memset(storage, 0, 10);
        }

        /* Video payload */
        toxav_recv_video(status_control.Alice.av, &video_storage);

        if ( video_storage ) {
            /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || 
            memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || 
            memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Bob is invalid");*/
        }




        /* Payload from Alice */
        recved = toxav_recv_audio(status_control.Bob.av, 10, storage);

        if ( recved ) {
            /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
        }

        /* Video payload */
        toxav_recv_video(status_control.Bob.av, &video_storage);

        if ( video_storage ) {
            /*ck_assert_msg( memcmp(video_storage->planes[VPX_PLANE_Y], sample_payload, 10) == 0 || 
            memcmp(video_storage->planes[VPX_PLANE_U], sample_payload, 10) == 0 || 
            memcmp(video_storage->planes[VPX_PLANE_V], sample_payload, 10) == 0 , "Payload from Alice is invalid");*/
        }


        if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
            step++; /* This terminates the loop */
            toxav_kill_transmission(status_control.Alice.av);
            toxav_kill_transmission(status_control.Bob.av);

            /* Call over Alice hangs up */
            toxav_hangup(status_control.Alice.av);
        }
    }
Пример #2
0
void *decode_video_thread(void *arg)
{
    INFO("Started decode video thread!");
    av_session_t *_phone = arg;
    _phone->running_decvid = 1;

    //CodecState *cs = get_cs_temp(_phone->av);
    //cs->video_stream = 0;

    //int recved_size;
    //uint8_t dest[RTP_PAYLOAD_SIZE];

    //int dec_frame_finished;
    //AVFrame *r_video_frame;
    //r_video_frame = avcodec_alloc_frame();
    //AVPacket dec_video_packet;
    //av_new_packet (&dec_video_packet, 65536);
    int width = 0;
    int height = 0;

    while (_phone->running_decvid) {
        //recved_size = toxav_recv_rtp_payload(_phone->av, TypeVideo, dest);
        //if (recved_size) {
        vpx_image_t *image;

        if (toxav_recv_video(_phone->av, &image) == 0) {
            //memcpy(dec_video_packet.data, dest, recved_size);
            //dec_video_packet.size = recved_size;

            //avcodec_decode_video2(cs->video_decoder_ctx, r_video_frame, &dec_frame_finished, &dec_video_packet);

            //if (dec_frame_finished) {

            /* Check if size has changed */
            if (image->d_w != width || image->d_h != height) {

                width = image->d_w;
                height = image->d_h;

                printf("w: %d h: %d \n", width, height);

                screen = SDL_SetVideoMode(width, height, 0, 0);

                //if (_phone->video_picture.bmp)
                //   SDL_FreeYUVOverlay(_phone->video_picture.bmp);

                //_phone->video_picture.bmp = SDL_CreateYUVOverlay(width, height, SDL_YV12_OVERLAY, screen);
                // _phone->sws_SDL_r_ctx = sws_getContext(width, height, cs->video_decoder_ctx->pix_fmt, width, height, PIX_FMT_YUV420P,
                //                                      SWS_BILINEAR, NULL, NULL, NULL);
            }

            uint8_t *rgb_image = malloc(width * height * 3);
            convert_to_rgb(image, rgb_image);
            SDL_Surface *img_surface = SDL_CreateRGBSurfaceFrom(rgb_image, width, height, 24, width * 3, mask32(0), mask32(1),
                                       mask32(2), 0);

            if (SDL_BlitSurface(img_surface, NULL, screen, NULL) == 0)
                SDL_UpdateRect(screen, 0, 0, 0, 0);

            /*
            SDL_LockYUVOverlay(_phone->video_picture.bmp);
            memcpy(_phone->video_picture.bmp->pixels[0], image->planes[VPX_PLANE_Y], _phone->video_picture.bmp->pitches[0] * height);
            memcpy(_phone->video_picture.bmp->pixels[1], image->planes[VPX_PLANE_V], _phone->video_picture.bmp->pitches[1] * height / 2);
            memcpy(_phone->video_picture.bmp->pixels[2], image->planes[VPX_PLANE_U], _phone->video_picture.bmp->pitches[2] * height / 2);

            SDL_Rect rect;
            rect.x = 0;
            rect.y = 0;
            rect.w = width;
            rect.h = height;
            SDL_DisplayYUVOverlay(_phone->video_picture.bmp, &rect);*/
            free(rgb_image);
            //display_received_frame(_phone, image);

        } //else {

        /* TODO: request the sender to create a new i-frame immediatly */
        //printf("Bad video packet\n");
        //}
        //}

        usleep(1000);
    }

    /* clean up codecs */
    //av_free(r_video_frame);

    //pthread_mutex_lock(&cs->ctrl_mutex);
    //avcodec_close(cs->video_decoder_ctx);
    //pthread_mutex_unlock(&cs->ctrl_mutex);

    _phone->running_decvid = -1;

    pthread_exit ( NULL );
}