PDA

View Full Version : My openGL video render freezes after 5 seconds



SirPaulMuaddib
07-11-2010, 04:34 PM
here in a nutshell is the core code...
(note, even faking it, with 2 static images flipping back and forth, it will freeze after 5 seconds)



void GLRender(void)
{
RenderVideoToTexture(pathToFile); // this calls CMoviePlayer::DisplayFrame below
}


void CMoviePlayer::DisplayFrame(AVFrame *pFrame, int width, int height, float quadWidth, float quadHeight)
{
glBindTexture(GL_TEXTURE_2D, textureID); //A texture you have already created with glTexImage2D
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)pFrame->data[0]);

glBegin(GL_POLYGON);
glTexCoord2f(0.0f,1.0f); glVertex3f (-quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,1.0f); glVertex3f ( quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,0.0f); glVertex3f ( quadWidth, quadHeight, 0.0);
glTexCoord2f(0.0f,0.0f); glVertex3f (-quadWidth, quadHeight, 0.0);
glEnd();

glutSwapBuffers();
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1024,768);
int m_window = glutCreateWindow("2D Image Texture Test");
//glutKeyboardFunc(&processNormalKeys);
//glutEnterGameMode(); //set glut to fullscreen using the

glutDisplayFunc(&GLRender);

glutMainLoop();
return 0;
}



What I'm doing:
1) I decode frames of video
2) I call DisplayFrame
3) It works fine, but after 5 seconds the image freezes.

The app does not crash, if I break, the display function does keep getting called with new frames.

I tried a test where I faked it.
I displayed 2 frames from 2 bmp files. I display each for 1 second then change and display the 2nd image, back and forth.

Even this faked version freezes after 5 seconds....


Note: My GLRender function is not a true render function, is this part of the problem? It really just calls my functions which deals with all the rendering.

Also, freaky enough, I discovered by accident, that if I start the app, and click on another window (that is I remove the focus from the opengl app/window), it works fine 100% of the time.

SirPaulMuaddib
07-17-2010, 05:53 PM
here is the stripped down project...

you can download it from here
http://www.mediafire.com/file/yrzhclv1z985kql/freeze.zip

When you run it, it will flip/flop an image, after a few seconds it will freeze.

Why does it freeze? I can't see anything wrong being done in code.

Dark Photon
07-18-2010, 02:39 PM
http://www.mediafire.com/file/yrzhclv1z985kql/freeze.zip
Hacked the MSWindowisms out of it, and tried it on Linux with NVidia GTX285 and 256.25 drivers.

No freeze here.

Suspect Windows ;) You got that Aero thingie turned off?

Nice and consistent frame rate, even if I rip sync-to-vblank off. Looks like you're just rendering the same image upside down, then rightside up, and repeating.

Zarniwoop
07-18-2010, 03:13 PM
> You got that Aero thingie turned off?

I haven't tried SirPaulMuaddib's project, but for what it's worth, the compositing Desktop on Linux (compiz, I haven't tried kwin) seems to work great with accelerated GL apps. It's sort of impressive, dragging a desktop cube around while a 3D app runs on one of the desktops still doing its thing. I've been using it as my main dev environment and have so far not had any reason to switch off compositing.

SirPaulMuaddib
07-19-2010, 10:45 AM
http://www.mediafire.com/file/yrzhclv1z985kql/freeze.zip
Hacked the MSWindowisms out of it, and tried it on Linux with NVidia GTX285 and 256.25 drivers.

No freeze here.

Suspect Windows ;) You got that Aero thingie turned off?

Nice and consistent frame rate, even if I rip sync-to-vblank off. Looks like you're just rendering the same image upside down, then rightside up, and repeating.


Maybe I need to get a new pc, the one I have is about 5 years old, and while the video card is good, it too, is about 5 years old. It's a 64bit WinXP, with an nVidea video card (forget which one off hand).

Yes, I'm just flipping an image upside down and right side up.
The real app, gets frames from video. I had problems, and in the process of backstepping, stripped out all the video code and faked it, as it turned out, even the faked version freezes on my box, it freezes exactly after 5 seconds.

Will try it on another pc, and see if I have same problem.

ZbuffeR
07-19-2010, 02:45 PM
.exe Crashes here after 10 flip up-flip down (about 10 seconds?)
Vista 64 sp2 with aero, nvidia GTX275, driver 191.07

EDIT: From looking at the code, it appears you continuously create textures form image files, 10*60 = 600 textures and never release them. What about using only a few, and glTexSubImage2D the data only ?

SirPaulMuaddib
07-19-2010, 04:31 PM
My question as posted in first post is how I really do it, and that is by using "glTexSubImage2D"


In my demo app (the link you can download), I don't do that, I will modify demo to do that, and see if it changes problem.

I only create the texture(s) once.

In original post, I use glTexSubImage2D, in my demo app I flip / flop back and forth between the images like this
(every 30 frames I flip / flop between the 2 images)


void CMoviePlayer::DisplayFrame(BYTE *pFrame, int width, int height, float quadWidth, float quadHeight)
{
static float sf = 1.0;

static bool b = true;
static int i = 0;

if (i++%30 == 0)
b=!b;

if (b)
glBindTexture(GL_TEXTURE_2D, tex1); //A texture you have already created with glTexImage2D
else
glBindTexture(GL_TEXTURE_2D, tex2); //A texture you have already created with glTexImage2D


glScalef(sf, sf, sf);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f,1.0f); glVertex3f (-quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,1.0f); glVertex3f ( quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,0.0f); glVertex3f ( quadWidth, quadHeight, 0.0);
glTexCoord2f(0.0f,0.0f); glVertex3f (-quadWidth, quadHeight, 0.0);
glEnd();

//sf +=0.0000001f;

glutSwapBuffers();
}

SirPaulMuaddib
07-19-2010, 04:33 PM
.exe Crashes here after 10 flip up-flip down (about 10 seconds?)
Vista 64 sp2 with aero, nvidia GTX275, driver 191.07

EDIT: From looking at the code, it appears you continuously create textures form image files, 10*60 = 600 textures and never release them. What about using only a few, and glTexSubImage2D the data only ?

I'm glad it's not happening just on my box, as I said, I only create the image(s) just once.

After 10 flip / flops, if your fps is 30, then yes, it will happen after 10 seconds.

For me it's always the same, it crashes after 5 seconds.

SirPaulMuaddib
07-19-2010, 05:15 PM
Try this test (for those that downloaded demo of problem).

Build and/or Run app

IMMEDIATELY click on another window.

If I do so, the app does not freeze, you see the image flip/flop back and forth.

When I say "freeze" I do not mean the app crashes, I mean it will freeze frame on whatever the last image that was displayed is.

SirPaulMuaddib
07-20-2010, 07:24 AM
ack...in demo project I just noticed, in solution view, the movieplayer.cpp file is in Header Files filter folder.

That is where relevant code is.

Open that up, to open up the movieplayer.cpp file

ZbuffeR
07-20-2010, 01:29 PM
Indeed I misread the code, textures are loaded only once each.


glutDisplayFunc(&GLRender);
...
void CMoviePlayer::ReadFrames(int w, int h, float quadWidth, float quadHeight )
{
while (true)
{
DisplayFrame(NULL, w, h, quadWidth, quadHeight);
}
}
mmmh, not certain about it but this is bad practice, glut display func should render only one frame, and use glutPostRedisplay() to trigger the next rendering.
I bet Dark Photon built your project using freeglut instead of the Mark's original glut, and message handling may be better with freeglut, especially with a pathological use case like yours.

SirPaulMuaddib
07-20-2010, 01:41 PM
The real code for ReadFrames, decodes video etc....

Decoding video does not lend itself to this design


Video GetNextFrame()
{
Decode Video-----> frame
return frame;
}





this way is more natural


void GetNextFrame()
{
while (!endOfVideo)
{
Decode Video-----> frame
DisplayFrame(frame)
}

}


I may be forced to re-work it, to fit first way.

Is there any way to get it to work, doing it like second example?

ZbuffeR
07-20-2010, 01:49 PM
Try replacing glut by freeglut, it may "just work".
But you are wrong, decoding video can work with any design.

And never reading the OS/windowing messages is not good.

If you really prefer the second method, GLFW is more suited.
http://gpwiki.org/index.php/GLFW:Tutorials:Basics

SirPaulMuaddib
07-20-2010, 04:12 PM
The GLFW looks perfectly suited for how I want to do it, will check that out.



GLFW is a free, Open Source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time. It is intended to be simple to integrate into existing applications and does not lay claim to the main loop.

Sound perfect...

SirPaulMuaddib
07-23-2010, 07:00 AM
The GLFW based version works great, no freezing issues.

I have to revamp the aspect ratio stuff though...

I had the displayed image (video frame in reality), displayed in the aspect ratio of the movie, in original version of code, it got "broken" in GLFW version, I got it almost fixed...will post it in day or so.

I may need some help with it....