x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)

{

    struct x11_grab *s = s1->priv_data;

    Display *dpy = s->dpy;

    XImage *image = s->image;

    int x_off = s->x_off;

    int y_off = s->y_off;



    int64_t curtime, delay;

    struct timespec ts;



    /* Calculate the time of the next frame */

    s->time_frame += INT64_C(1000000);



    /* wait based on the frame rate */

    for(;;) {

        curtime = av_gettime();

        delay = s->time_frame * av_q2d(s->time_base) - curtime;

        if (delay <= 0) {

            if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {

                s->time_frame += INT64_C(1000000);

            }

            break;

        }

        ts.tv_sec = delay / 1000000;

        ts.tv_nsec = (delay % 1000000) * 1000;

        nanosleep(&ts, NULL);

    }



    av_init_packet(pkt);

    pkt->data = image->data;

    pkt->size = s->frame_size;

    pkt->pts = curtime;



    if(s->use_shm) {

        if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) {

            av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");

        }

    } else {

        if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {

            av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");

        }

    }



    if(!s->nomouse){

        paint_mouse_pointer(image, s);

    }



    return s->frame_size;

}

x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)

{

    struct x11_grab *s = s1->priv_data;

    Display *dpy = s->dpy;

    XImage *image = s->image;

    int x_off = s->x_off;

    int y_off = s->y_off;



    int64_t curtime, delay;

    struct timespec ts;



    

    s->time_frame += INT64_C(1000000);



    

    for(;;) {

        curtime = av_gettime();

        delay = s->time_frame * av_q2d(s->time_base) - curtime;

        if (delay <= 0) {

            if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {

                s->time_frame += INT64_C(1000000);

            }

            break;

        }

        ts.tv_sec = delay / 1000000;

        ts.tv_nsec = (delay % 1000000) * 1000;

        nanosleep(&ts, NULL);

    }



    av_init_packet(pkt);

    pkt->data = image->data;

    pkt->size = s->frame_size;

    pkt->pts = curtime;



    if(s->use_shm) {

        if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) {

            av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");

        }

    } else {

        if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {

            av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");

        }

    }



    if(!s->nomouse){

        paint_mouse_pointer(image, s);

    }



    return s->frame_size;

}

FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    struct x11_grab *VAR_2 = VAR_0->priv_data;

    Display *dpy = VAR_2->dpy;

    XImage *image = VAR_2->image;

    int VAR_3 = VAR_2->VAR_3;

    int VAR_4 = VAR_2->VAR_4;



    int64_t curtime, delay;

    struct timespec VAR_5;



    

    VAR_2->time_frame += INT64_C(1000000);



    

    for(;;) {

        curtime = av_gettime();

        delay = VAR_2->time_frame * av_q2d(VAR_2->time_base) - curtime;

        if (delay <= 0) {

            if (delay < INT64_C(-1000000) * av_q2d(VAR_2->time_base)) {

                VAR_2->time_frame += INT64_C(1000000);

            }

            break;

        }

        VAR_5.tv_sec = delay / 1000000;

        VAR_5.tv_nsec = (delay % 1000000) * 1000;

        nanosleep(&VAR_5, NULL);

    }



    av_init_packet(VAR_1);

    VAR_1->data = image->data;

    VAR_1->size = VAR_2->frame_size;

    VAR_1->pts = curtime;



    if(VAR_2->use_shm) {

        if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, VAR_3, VAR_4, AllPlanes)) {

            av_log (VAR_0, AV_LOG_INFO, "XShmGetImage() failed\n");

        }

    } else {

        if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, VAR_3, VAR_4)) {

            av_log (VAR_0, AV_LOG_INFO, "XGetZPixmap() failed\n");

        }

    }



    if(!VAR_2->nomouse){

        paint_mouse_pointer(image, VAR_2);

    }



    return VAR_2->frame_size;

}

FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ struct x11_grab *VAR_2 = VAR_0->priv_data; Display *dpy = VAR_2->dpy; XImage *image = VAR_2->image; int VAR_3 = VAR_2->VAR_3; int VAR_4 = VAR_2->VAR_4; int64_t curtime, delay; struct timespec VAR_5; VAR_2->time_frame += INT64_C(1000000); for(;;) { curtime = av_gettime(); delay = VAR_2->time_frame * av_q2d(VAR_2->time_base) - curtime; if (delay <= 0) { if (delay < INT64_C(-1000000) * av_q2d(VAR_2->time_base)) { VAR_2->time_frame += INT64_C(1000000); } break; } VAR_5.tv_sec = delay / 1000000; VAR_5.tv_nsec = (delay % 1000000) * 1000; nanosleep(&VAR_5, NULL); } av_init_packet(VAR_1); VAR_1->data = image->data; VAR_1->size = VAR_2->frame_size; VAR_1->pts = curtime; if(VAR_2->use_shm) { if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, VAR_3, VAR_4, AllPlanes)) { av_log (VAR_0, AV_LOG_INFO, "XShmGetImage() failed\n"); } } else { if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, VAR_3, VAR_4)) { av_log (VAR_0, AV_LOG_INFO, "XGetZPixmap() failed\n"); } } if(!VAR_2->nomouse){ paint_mouse_pointer(image, VAR_2); } return VAR_2->frame_size; }