Exemplo n.º 1
0
int send_video_pkt(void *channel, int stream_id, void *pkt_p)
{
    AVPacket *av_pkt = (AVPacket *) pkt_p;

    xrdpvr_send_video_data(channel, stream_id, av_pkt->size, av_pkt->data);
    av_free_packet(av_pkt);
    free(av_pkt);
}
Exemplo n.º 2
0
int xrdpvr_play_frame(void *channel, int stream_id, int *videoTimeout, int *audioTimeout)
{
    AVPacket av_pkt;
    double   dts;
    int      delay_in_us;

    if (av_read_frame(g_psi.p_format_ctx, &av_pkt) < 0)
    {
        printf("xrdpvr_play_frame: av_read_frame failed\n");
        return -1;
    }

    if (av_pkt.stream_index == g_audio_index)
    {
        xrdpvr_send_audio_data(channel, stream_id, av_pkt.size, av_pkt.data);

        dts = av_pkt.dts;
        dts *= av_q2d(g_psi.p_format_ctx->streams[g_audio_index]->time_base);

        *audioTimeout = (int) ((dts - g_psi.audioTimeout) * 1000000);
        *videoTimeout = -1;

        if (g_psi.audioTimeout > dts)
        {
            g_psi.audioTimeout = dts;
            delay_in_us = 1000 * 40;
        }
        else
        {
            delay_in_us = (int) ((dts - g_psi.audioTimeout) * 1000000);
            g_psi.audioTimeout = dts;
        }

        //printf("audio delay: %d\n", delay_in_us);
        usleep(delay_in_us);
        //usleep(1000 * 1);
    }
    else if (av_pkt.stream_index == g_video_index)
    {
        xrdpvr_send_video_data(channel, stream_id, av_pkt.size, av_pkt.data);

        dts = av_pkt.dts;
        dts *= av_q2d(g_psi.p_format_ctx->streams[g_video_index]->time_base);

        //printf("xrdpvr_play_frame:video: saved=%f dts=%f\n", g_psi.videoTimeout, dts);

        *videoTimeout = (int) ((dts - g_psi.videoTimeout) * 1000000);
        *audioTimeout = -1;

        if (g_psi.videoTimeout > dts)
        {
            g_psi.videoTimeout = dts;
            delay_in_us = 1000 * 40;
            //printf("xrdpvr_play_frame:video1: saved=%f dts=%f delay_in_us=%d\n", g_psi.videoTimeout, dts, delay_in_us);
        }
        else
        {
            delay_in_us = (int) ((dts - g_psi.videoTimeout) * 1000000);
            g_psi.videoTimeout = dts;
            //printf("xrdpvr_play_frame:video2: saved=%f dts=%f delay_in_us=%d\n", g_psi.videoTimeout, dts, delay_in_us);
        }

        //printf("video delay: %d\n", delay_in_us);
        usleep(delay_in_us);
    }

    av_free_packet(&av_pkt);
    return 0;
}
Exemplo n.º 3
0
int
xrdpvr_play_frame(void *channel, int stream_id, int *videoTimeout,
                  int *audioTimeout)
{
    AVPacket                  av_pkt;
    double                    dts;
    int                       delay_in_us;
    int                       error;
    AVBitStreamFilterContext *bsfc;
    AVPacket                  new_pkt;

    //printf("xrdpvr_play_frame:\n");

    if (av_read_frame(g_psi.p_format_ctx, &av_pkt) < 0)
    {
        printf("xrdpvr_play_frame: av_read_frame failed\n");
        return -1;
    }

    if (av_pkt.stream_index == g_audio_index)
    {
        xrdpvr_send_audio_data(channel, stream_id, av_pkt.size, av_pkt.data);

        dts = av_pkt.dts;
        dts *= av_q2d(g_psi.p_format_ctx->streams[g_audio_index]->time_base);

        *audioTimeout = (int) ((dts - g_psi.audioTimeout) * 1000000);
        *videoTimeout = -1;

        if (g_psi.audioTimeout > dts)
        {
            g_psi.audioTimeout = dts;
            delay_in_us = 1000 * 40;
        }
        else
        {
            delay_in_us = (int) ((dts - g_psi.audioTimeout) * 1000000);
            g_psi.audioTimeout = dts;
        }

        printf("audio delay: %d\n", delay_in_us);
        usleep(delay_in_us);
        //usleep(1000 * 1);
    }
    else if (av_pkt.stream_index == g_video_index)
    {
        bsfc = g_psi.bsfc;
        while (bsfc != 0)
        {
            new_pkt= av_pkt;
            error = av_bitstream_filter_filter(bsfc, g_psi.p_video_codec_ctx, 0,
                                               &new_pkt.data, &new_pkt.size,
                                               av_pkt.data, av_pkt.size,
                                               av_pkt.flags & PKT_FLAG_KEY);
            if (error > 0)
            {
                av_free_packet(&av_pkt);
                new_pkt.destruct = av_destruct_packet;
            }
            else if (error < 0)
            {
                printf("bitstream filter error\n");
            }
            av_pkt = new_pkt;
            bsfc = bsfc->next;
        }

        xrdpvr_send_video_data(channel, stream_id, av_pkt.size, av_pkt.data);

        dts = av_pkt.dts;
        dts *= av_q2d(g_psi.p_format_ctx->streams[g_video_index]->time_base);

        *videoTimeout = (int) ((dts - g_psi.videoTimeout) * 1000000);
        *audioTimeout = -1;

        if (g_psi.videoTimeout > dts)
        {
            g_psi.videoTimeout = dts;
            delay_in_us = 1000 * 40;
        }
        else
        {
            delay_in_us = (int) ((dts - g_psi.videoTimeout) * 1000000);
            g_psi.videoTimeout = dts;
        }

        printf("video delay: %d\n", delay_in_us);
        usleep(delay_in_us);
    }

    av_free_packet(&av_pkt);
    return 0;
}