aliakseis / FFmpegPlayer

Simple FFmpeg video player
MIT License
151 stars 44 forks source link

Why you using boost? #4

Closed topilski closed 6 years ago

topilski commented 6 years ago

Hi @aliakseis , i don't understand why you using boost, if the same functionality exists in std C++11 or higher.

aliakseis commented 6 years ago

Good question! Practically there is one reason: boost::thread::interrupt usage, but it came really handy. And, there are other boost libraries used in the project as well.

topilski commented 6 years ago

Can you show in your code where you using boost::thread::interrupt mechanism? And describe why it helpful?

aliakseis commented 6 years ago

Here it is:

inline void Shutdown(const std::unique_ptr& th) { if (th) { th->interrupt(); th->join(); } }

Basically it is described here how it is helpful: http://www.boost.org/doc/libs/1_66_0/doc/html/thread/thread_management.html#thread.thread_management.tutorial.interruption

In two words, it greatly simplifies thread termination. Due to this, it turned out to be easier just to restart threads during movie rewinding.

aliakseis commented 6 years ago

Sorry, there is another place where interrupt is used: in bool FFmpegDecoder::resetDecoding(...)

topilski commented 6 years ago

In any way if you call interrupt function you don't know how to stop your working thread from another thread? but it is wrong way, you should know lifetime of your thread and should know how to stop thread properly (may be stop flag, may be condition_variable notification or something else), or i something misunderstand?

topilski commented 6 years ago

In this line you have infinite loop, https://github.com/aliakseis/FFmpegPlayer/blob/6e6daeffb32b8d44dada4180505026e7e0752a0f/video/videoparserunnable.cpp#L65 but may be better have stop flag, than interrupt functionality?

aliakseis commented 6 years ago

boost::thread::interrupt gives more than a flag functionality http://www.boost.org/doc/libs/1_66_0/doc/html/thread/thread_management.html#thread.thread_management.tutorial.interruption.predefined_interruption_points If a thread stays waiting on one of these points, it will be terminated automatically right away.

topilski commented 6 years ago

cool, thank you for description!