Exemple #1
0
void PlayVideo::play()
{
    MediaPacket *pkt;
    int now_time;
    int sleep_time;
    int last_display_time;

    last_display_time = 0;
    while (1)
    {
        sendMutex->lock();
        if (videoQueue->isEmpty())
        {
            sendMutex->unlock();
            usleep(10 * 1000);
            continue;
        }
        pkt = videoQueue->dequeue();
        send_video_pkt(channel, stream_id, pkt->av_pkt);
        sendMutex->unlock();
        now_time = get_mstime();
        sleep_time = now_time - last_display_time;
        if (sleep_time > (1000 / fps))
        {
            sleep_time = (1000 / fps);
        }
        if (sleep_time > 0)
        {
            usleep(sleep_time * 1000);
        }
        last_display_time = now_time;
        delete pkt;
    }
}
Exemple #2
0
void PlayVideo::play()
{
    MediaPacket *pkt;
    int usl;

    while (1)
    {
        vcrMutex.lock();
        switch (vcrFlag)
        {
            case VCR_PLAY:
                vcrFlag = 0;
                vcrMutex.unlock();
                if (pausedTime)
                {
                    elapsedTime = av_gettime() - pausedTime;
                    pausedTime = 0;
                }
                isStopped = false;
                continue;
                break;

            case VCR_PAUSE:
                vcrMutex.unlock();
                if (!pausedTime)
                {
                    /* save amount of video played so far */
                    pausedTime = av_gettime() - elapsedTime;
                }
                usleep(1000 * 100);
                isStopped = false;
                continue;
                break;

            case VCR_STOP:
                vcrMutex.unlock();
                if (isStopped)
                {
                    usleep(1000 * 100);
                    continue;
                }
                clearVideoQ();
                elapsedTime = 0;
                pausedTime = 0;
                la_seekPos = -1;
                xrdpvr_seek_media(0, 0);
                isStopped = true;
                continue;
                break;

            default:
                vcrMutex.unlock();
                goto label1;
                break;
        }

label1:

        if (videoQueue->isEmpty())
        {
            continue;
        }
        pkt = videoQueue->dequeue();
        sendMutex->lock();
        send_video_pkt(channel, stream_id, pkt->av_pkt);
        sendMutex->unlock();
        usl = pkt->delay_in_us;
        if (usl < 0)
        {
            usl = 0;
        }
        if (usl > 100 * 1000)
        {
            usl = 100 * 1000;
        }
        usleep(usl);
        delete pkt;
        updateMediaPos();
        if (elapsedTime == 0)
            elapsedTime = av_gettime();

        /* time elapsed in 1/100th sec units since play started */
        emit onElapsedtime((av_gettime() - elapsedTime) / 10000);
    }
}