Esempio n. 1
0
bool VLCVideoWrapper::updateImage(void)
{
    //VLC wants the current frame to be displayed
    if(_NextFrameReady)
    {
        if(getImage() == NULL)
        {
            _NextFrameReady = false;
            ImageUnrecPtr NewImage(Image::create());
            setImage(NewImage);
            try
            {
                UInt32 Width(getWidth()),
                       Height(getHeight());

                _VideoMemContext._lock->acquire();
                getImage()->set(
#if BYTE_ORDER == LITTLE_ENDIAN
                                Image::OSG_BGR_PF,
#else
                                Image::OSG_RGB_PF,
#endif
                                Width,
                                Height,
                                1,1,1,0.0,
                                reinterpret_cast<const UInt8*>(_VideoMemContext._pixels),
                                Image::OSG_UINT8_IMAGEDATA);
                _VideoMemContext._lock->release();
            }
            catch(...)
            {
                SWARNING << "VLCVideoWrapper::updateImage(): Error updateing Image object." << std::endl;
                setImage(NULL);
                return false;
            }
        }
        else
        {
            getImage()->setData(reinterpret_cast<const UInt8*>(_VideoMemContext._pixels));		
        }
        libvlc_state_t currentState = libvlc_media_player_get_state(_MediaPlayer);
        checkVLCError("Getting player state");
        if(currentState == libvlc_Ended)
        {
            produceEnded();
        }
        getImage()->mirror(false,true);		
    }

    return true;
}
bool DirectShowVideoWrapper::updateImage(void)
{
    if (_VideoInitialized)
    {
        // Only need to do this once
        if (!_FrameBuffer)
        {
            // The Sample Grabber requires an arbitrary buffer
            // That we only know at runtime.
            // (width * height * 3) bytes will not work.
            HRESULT result;
            result = _pSampleGrabber->GetCurrentBuffer(&_BufferSize, NULL);
            if(FAILED(result))
            {
                return false;
            }

            if(_BufferSize<=0)
            {
                SWARNING << "_BufferSize<=0" << std::endl;
                return false;
            }
            if(_BufferSize>10000000)
            {
                SWARNING << "_BufferSize>10000000" << std::endl;
                return false;
            }
            _FrameBuffer = new long[_BufferSize];
        }
        
        _pSampleGrabber->GetCurrentBuffer(&_BufferSize, (long*)_FrameBuffer);
    
        if(getImage() == NULL ||
           getImage()->getWidth() != _VideoWidth ||
           getImage()->getHeight() != _VideoHeight)
		{
            ImageUnrecPtr NewImage(Image::create());
			setImage(NewImage);
            try
            {
			    getImage()->set(Image::OSG_BGR_PF,
                                _VideoWidth,
                                _VideoHeight,
                                1,1,1,0.0,
                                reinterpret_cast<const UInt8*>(_FrameBuffer),
                                Image::OSG_UINT8_IMAGEDATA);
            }
            catch(...)
            {
			    setImage(NULL);
                return false;
            }
		}
		else
		{
            getImage()->setData(reinterpret_cast<const UInt8*>(_FrameBuffer));		
		}
        if(!_ReachEndOnce && getPosition() == getDuration())
        {
            _ReachEndOnce = true;
            produceEnded();
        }

        return true;
    }

    return false;
}