Skip to content

Commit

Permalink
Updated some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
WolverinDEV committed Jul 5, 2019
1 parent 9bd30ca commit af7918a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions providers/ffmpeg/FFMpegProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ FFMpegProvider::FFMpegProvider(const shared_ptr<FFMpegProviderConfig>& cfg) : co
this->providerDescription = "FFMpeg playback support";

this->readerBase = event_base_new();
this->readerDispatch = new threads::Thread(THREAD_EXECUTE_LATER | THREAD_SAVE_OPERATIONS, [&](){
while(this->readerBase) {
event_base_dispatch(this->readerBase);
threads::self::sleep_for(milliseconds(10)); //Dont have somethink to do
}
this->readerDispatch = std::thread([&]{
while(this->readerBase)
event_base_loop(this->readerBase, EVLOOP_NO_EXIT_ON_EMPTY);
});
this->readerDispatch->name("FFMpeg IO").execute();

#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
pthread_t handle = this->readerDispatch.native_handle();
pthread_setname_np(handle, "FFMPeg IO Loop");
#endif
}

FFMpegProvider::~FFMpegProvider() {
Expand All @@ -297,11 +299,13 @@ FFMpegProvider::~FFMpegProvider() {
event_base_loopbreak(base);
event_base_loopexit(base, nullptr);

if(this->readerDispatch) {
if(!this->readerDispatch->join(system_clock::now() + seconds(3))) this->readerDispatch->detach();
delete this->readerDispatch;
this->readerDispatch = nullptr;
}
if(this->readerDispatch.joinable())
try {
this->readerDispatch.join();
} catch(std::system_error& ex) {
if(ex.code() != errc::invalid_argument) /* exception is not about that the thread isn't joinable anymore */
throw;
}

event_base_free(base);
}
Expand Down
2 changes: 1 addition & 1 deletion providers/ffmpeg/FFMpegProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace music {
std::vector<std::string> av_fmt;

event_base* readerBase = nullptr;
threads::Thread* readerDispatch = nullptr;
std::thread readerDispatch;

inline std::shared_ptr<FFMpegProviderConfig> configuration() { return this->config; }
private:
Expand Down

0 comments on commit af7918a

Please sign in to comment.