Code Monkey home page Code Monkey logo

Comments (1)

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024 1

Hey @luthfiampas

You are on the right track. What is the best way to 'trigger' an event to present the frame... There is a lot of space to answer this question. How am I doing it in Flyleaf...

I've the Screamer thread for this reason. It is similar to the one that you have above with one exception.... It waits to fire both video/audio/subs in a single thread.... and most importantly it doesn't spins until the time comes... but it sleeps (min time required to present video frame, or audio/subs frame). Thread.Sleep will calm down the CPU and will allow other threads to run. What is the best way? Not sure, but if you look at the most common open source players out there you will see similarities.

Let's take ffplay as another reference:

You will see the read_thread that it does what my demuxer/decoder threads doing. Then you will see refresh_loop_wait_event / video_refresh / video_display which is the similar with my Screamer and PresentFrame. refresh_loop_wait_event is mainly what you are asking, which is uses av_usleep((int64_t)(remaining_time * 1000000.0)); which is defined here

In .NET/windows and with SharpDX I've decided currently to use that way. Might have space for better performance though. It's very important when you write a player to be accurate with the FPS, so you can't avoid a) TimeBeginPeriod(1) to ensure that Thread.Sleep(1) will sleep always 1ms and not more than that... and b) to 'spin/thread.sleep(until pts)' to present the frame accurately. One more consideration on this 'loop' is to ensure that you don't waste a lot of time in every loop so you can present also next frames in time. That's the reason you need to have a solution to drop frames in a case like that. (Imagine if you demux/decode/present frames within the same context/thread, you are probably going to come up with a lot of dropped frames)

Feel free to ask any more clarifications ;)

from flyleaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.