Ejemplo n.º 1
0
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);
	};
};