int VideoStreamTheoraplayer::get_pending_frame_count() const {

	if (!clip)
		return 0;

	if (!frame.empty())
		return 1;

	TheoraVideoFrame* f = clip->getNextFrame();
	if (!f)
		return 0;

	float w=clip->getWidth(),h=clip->getHeight();
    int imgsize = w * h * f->mBpp;

	int size = f->getStride() * f->getHeight() * f->mBpp;
	DVector<uint8_t> data;
	data.resize(imgsize);
	DVector<uint8_t>::Write wr = data.write();
    uint8_t* ptr = wr.ptr();
    copymem(ptr, f->getBuffer(), imgsize);
    /*
    for (int i=0; i<h; i++) {
        int dstofs = i * w * f->mBpp;
        int srcofs = i * f->getStride() * f->mBpp;
        copymem(ptr + dstofs, f->getBuffer() + dstofs, w * f->mBpp);
    };
     */
	frame = Image();
	frame.create(w, h, 0, f->mBpp == 3 ? Image::FORMAT_RGB : Image::FORMAT_RGBA, data);

	clip->popFrame();

	return 1;
};
TheoraVideoFrame* TheoraFrameQueue::createFrameInstance(TheoraVideoClip* clip)
{
	TheoraVideoFrame* frame = new TheoraVideoFrame(clip);
	if (frame->getBuffer() == NULL) // This can happen if you run out of memory
	{
		delete frame;
		return NULL;
	}
	return frame;
}
void VideoStreamTheoraplayer::pop_frame(Ref<ImageTexture> p_tex) {

	if (!clip)
		return;

	TheoraVideoFrame* f = clip->getNextFrame();
	if (!f) {
		return;
	};

	float w=clip->getWidth(),h=clip->getHeight();
	int imgsize = w * h * f->mBpp;

	int size = f->getStride() * f->getHeight() * f->mBpp;
	data.resize(imgsize);
	{
		DVector<uint8_t>::Write wr = data.write();
		uint8_t* ptr = wr.ptr();
		copymem(ptr, f->getBuffer(), imgsize);
	}
    /*
    for (int i=0; i<h; i++) {
        int dstofs = i * w * f->mBpp;
        int srcofs = i * f->getStride() * f->mBpp;
        copymem(ptr + dstofs, f->getBuffer() + dstofs, w * f->mBpp);
    };
     */
	Image frame = Image();
	frame.create(w, h, 0, f->mBpp == 3 ? Image::FORMAT_RGB : Image::FORMAT_RGBA, data);

	clip->popFrame();

	if (p_tex->get_width() == 0) {
		p_tex->create(frame.get_width(),frame.get_height(),frame.get_format(),Texture::FLAG_VIDEO_SURFACE|Texture::FLAG_FILTER);
		p_tex->set_data(frame);
	} else {

		p_tex->set_data(frame);
	};
};
Example #4
0
bool TheoraVideoClip_FFmpeg::decodeNextFrame()
{
	TheoraVideoFrame* frame = mFrameQueue->requestEmptyFrame();
	if (!frame) return 0;

	AVPacket packet;
	int frameFinished;
	
	while (av_read_frame(mFormatContext, &packet) >= 0)
	{
		if (packet.stream_index == mVideoStreamIndex)
		{
			avcodec_decode_video2(mCodecContext, mFrame, &frameFinished, &packet);
			
			if (frameFinished)
			{
				TheoraPixelTransform t;
				memset(&t, 0, sizeof(TheoraPixelTransform));

				t.y = mFrame->data[0]; t.yStride = mFrame->linesize[0];
				t.u = mFrame->data[1]; t.uStride = mFrame->linesize[1];
				t.v = mFrame->data[2]; t.vStride = mFrame->linesize[2];
				
				frame->decode(&t);
				frame->mTimeToDisplay = mFrameNumber / mFPS;
				frame->mIteration = mIteration;
				frame->_setFrameNumber(mFrameNumber++);

				av_free_packet(&packet);
				break;
			}
		}
		av_free_packet(&packet);
	}
	return 1;
}