bangnoise / ofxHapPlayer

A Hap player for OpenFrameworks
Other
147 stars 46 forks source link

libavformat branch: player still doing work when paused #28

Open tobiasebsen opened 7 years ago

tobiasebsen commented 7 years ago

It looks like the new player is still working in the background when it is paused. I discovered this because I migrated a project to the new libavformat-player, where I pre-load 10 video files. Only one file is playing at a time, but every time the previous file is stopped and a new file starts playing, the frame rate drops increasingly. I tried to only call update() on the current player, but not luck.

bangnoise commented 7 years ago

Do the movies have audio?

tobiasebsen commented 7 years ago

No. Only video track.

bangnoise commented 7 years ago

Cheers - can you pull and try now?

tobiasebsen commented 7 years ago

Didn't help. The strange thing is that it's not increasing CPU usage. The frame rate of my entire ofApp just drops increasingly for each time i start the next player. I will try to narrow it down further...

bangnoise commented 7 years ago

I can't reproduce this based on your description. One way to narrow it down would be to start with a new project and make it produce the same effect - you could then attach the project to this issue.

tobiasebsen commented 7 years ago

So here is what I found out....

But, why the PacketCache cannot find the packet, I don't know. Should it even be fetching when it is paused?

tobiasebsen commented 7 years ago

It seems that the PacketCache does not contain any packet for the requested vidPosition. Maybe the Demuxer gets out of alignment with the Clock when pausing the playback? And perhaps my case is particularly prone to this condition because my videos run at 12fps ??

bangnoise commented 7 years ago

Many thanks for the detailed investigation. 0.25 seconds of video should be read after load (which should be fine at 12 fps). I'll see if I can recreate the problem with a 12 fps video, and avoid having a player churn away indefinitely if there isn't a frame for any reason.

tobiasebsen commented 7 years ago

Just to clarify: videos that have been loaded (but is not playing) does not have this problem. The missing frame occurs when the video playback is paused - perhaps at a point in time where no frame is available (in-between frames).

tobiasebsen commented 7 years ago

One more thing: the packet-timeout also occur while playing - at the end of a looping video.

bangnoise commented 7 years ago

Okay - your movies sound a little unusual, as generally one encodes an unbroken stream without gaps between frame times, but I will make changes so players only wait for the timeout when they can reasonably expect a frame may arrive.

bangnoise commented 7 years ago

If you're able to share a small problematic movie, or give instructions to create one, then that would help me test.

tobiasebsen commented 7 years ago

Here is one of the files: https://we.tl/jMYR1tckmN

The problem may be a combination of having multiple players - and running at low frame rate. At 12fps it buffers only 3 frames, which seems to under-run the cache at some frames. But I'm not sure - it's very difficult to debug this asynchronous stuff.

bangnoise commented 7 years ago

As well as the noted problem with the timeout on the main thread, this example eats CPU cycles as the audio thread spins hoping for missing audio samples.

tobiasebsen commented 7 years ago

It looks like the timeout happens on the first few frames right after the video loops. This tells me that there is something wrong with the way the demuxer is told to read future frames at the end of the video. It could be a problem with time ranges or perhaps the order of the demuxers actions (read/seek). Still looking further into this...

bangnoise commented 7 years ago

The original problem is fixed, still to do, related to this issue/test clip:

tobiasebsen commented 7 years ago

Wow. Two lines of code was all it took. I've spent hours trying to find the problem. Looking forward to having the last two issues fixed. Thanks!