Пример #1
0
void Webcam::open(int device)
{
	if(!use) return;
	_clear();
#ifdef USE_VIDEOINPUT
	m_device = device;
	VI.setupDevice(m_device);
#elif !defined(NO_WEBCAM)
	//Open the webcam with OpenCV
	m_VideoCap = new cv::VideoCapture(device);
	if(!m_VideoCap->isOpened())	
	{
		m_VideoCap->open(device);
		if(!m_VideoCap->isOpened())	
		{
			errlog << "Unable to open webcam " << device << endl;
			m_VideoCap->release();
			delete m_VideoCap;
			m_VideoCap = NULL;
		}
		else
			getNewFrame();	//Grab a new frame now while we're loading, because there seems to be a lag on getting the first frame
	}
	else
		getNewFrame();	//Grab a new frame now while we're loading, because there seems to be a lag on getting the first frame
#endif
}
Пример #2
0
bool ReplayRecorder::pushFrame()
{
    // we dont record the startphase ..
    assert( RaceManager::getWorld()->getPhase() != World::START_PHASE );
    assert( RaceManager::getWorld()->getNumKarts() == m_ReplayBuffers.getNumberKarts() );

    // make sure we're not under time-step-min 
    if( m_ReplayBuffers.getNumberFrames() )
    {
        ReplayFrame const *last_Frame = m_ReplayBuffers.getFrameAt( m_ReplayBuffers.getNumberFrames() - 1 );
        if( (RaceManager::getWorld()->getTime() - last_Frame->time) < REPLAY_TIME_STEP_MIN ) return true;
    }

    ReplayFrame *pFrame = getNewFrame();
    if( !pFrame ) return false;
    pFrame->time = RaceManager::getWorld()->getClock();

    Kart const *kart;
    int number_karts = RaceManager::getWorld()->getNumKarts();
    for( int kart_index = 0; kart_index < number_karts; ++kart_index )
    {
        kart = RaceManager::getKart( kart_index );
        sgCopyCoord( &( pFrame->p_kart_states[ kart_index ].position ), 
                     kart->getCoord() );
    }

    return true;
}
Пример #3
0
bool VideoInput::captureFrame()
{
    // Return true if capture could continue, false if must be stop

    if (not decoder_)
        return false;

    const auto ret = decoder_->decode(getNewFrame());

    switch (ret) {
        case MediaDecoder::Status::ReadError:
        case MediaDecoder::Status::DecodeError:
            return false;

        // End of streamed file
        case MediaDecoder::Status::EOFError:
            createDecoder();
            return static_cast<bool>(decoder_);

        case MediaDecoder::Status::FrameFinished:
            publishFrame();

        // continue decoding
        case MediaDecoder::Status::Success:
        default:
            return true;
    }
}
Пример #4
0
bool VideoInput::captureFrame()
{
    VideoPacket pkt;
    const auto ret = decoder_->decode(getNewFrame(), pkt);

    switch (ret) {
        case VideoDecoder::Status::FrameFinished:
            break;

        case VideoDecoder::Status::ReadError:
        case VideoDecoder::Status::DecodeError:
            loop_.stop();
            // fallthrough
        case VideoDecoder::Status::Success:
            return false;

            // Play in loop
        case VideoDecoder::Status::EOFError:
            deleteDecoder();
            createDecoder();
            return false;
    }

    publishFrame();
    return true;
}
Пример #5
0
int Object::changeFrame() {
	int frameNum = _frame;
	uint32 currentFrame = _vm->_events->getFrameCounter();

	if (_updateStartFrame <= currentFrame) {
		if (_numFrames > 0) {
			int v = 60 / _numFrames;
			_updateStartFrame = currentFrame + v;

			frameNum = getNewFrame();
		}
	}

	return frameNum;
}
Пример #6
0
void
VideoMixer::process()
{
    const auto now = std::chrono::system_clock::now();
    const auto diff = now - lastProcess_;
    const auto delay = FRAME_DURATION - diff;
    if (delay.count() > 0)
        std::this_thread::sleep_for(delay);
    lastProcess_ = now;

    VideoFrame& output = getNewFrame();
    try {
        output.reserve(VIDEO_PIXFMT_YUYV422, width_, height_);
    } catch (const std::bad_alloc& e) {
        RING_ERR("VideoFrame::allocBuffer() failed");
        return;
    }

    yuv422_clear_to_black(output);

    {
        auto lock(rwMutex_.read());

        int i = 0;
        for (const auto& x : sources_) {
            /* thread stop pending? */
            if (!loop_.isRunning())
                return;

            // make rendered frame temporarily unavailable for update()
            // to avoid concurrent access.
            std::unique_ptr<VideoFrame> input;
            x->atomic_swap_render(input);

            if (input)
                render_frame(output, *input, i);

            x->atomic_swap_render(input);
            ++i;
        }
    }

    publishFrame();
}
Пример #7
0
bool ReplayBuffers::loadReplayHumanReadable( FILE *fd, unsigned int number_karts )
{
    size_t frames;
    if( fscanf( fd, "frames: %u\n", &frames ) != 1 ) return false;

    if( !init( number_karts, frames ) ) return false;

    assert( m_number_karts );
    unsigned int frame_idx, kart_idx, tmp;
    ReplayFrame *frame;
    ReplayKartState *kart;
    for( frame_idx = 0; frame_idx < frames; ++frame_idx )
    {
        // if we are here, it cant fail, since enough objects have to be allocated above
        frame = getNewFrame();
        assert( frame );

        if( fscanf( fd, "frame %u  time %f\n", &tmp, &frame->time ) != 2 ) return false;

        for( kart_idx = 0; kart_idx < m_number_karts; ++kart_idx )
        {
            kart = frame->p_kart_states + kart_idx;

            if( fscanf( fd, "\tkart %u: %f,%f,%f,%f,%f,%f\n", &tmp, 
                     &kart->position.xyz[0], &kart->position.xyz[1], &kart->position.xyz[2],
                     &kart->position.hpr[0], &kart->position.hpr[1], &kart->position.hpr[2] ) != 7 ) return false;   
        }
    }

    assert( frames == getNumberFrames() );
    assert( m_BufferFrame.getNumberObjectsUsed() == getNumberFrames() );
    assert( m_BufferKartState.getNumberArraysUsed() == getNumberFrames() );

    // there should be no reallocation ..
    assert( m_BufferFrame.getNumberBlocks() == 1 );
    assert( m_BufferKartState.getNumberBlocks() == 1 );

    return true;
}