Commit 58862629 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

VLCMetadataService: Process meta from the parser thread

This allows us not to create a new SQLite connection from a potentially
different VLC thread for each media
parent 5be89430
...@@ -70,25 +70,26 @@ void VLCMetadataService::run( std::shared_ptr<Media> file, void* data ) ...@@ -70,25 +70,26 @@ void VLCMetadataService::run( std::shared_ptr<Media> file, void* data )
ctx->media = VLC::Media( m_instance, file->mrl(), VLC::Media::FromPath ); ctx->media = VLC::Media( m_instance, file->mrl(), VLC::Media::FromPath );
std::unique_lock<std::mutex> lock( m_mutex ); std::unique_lock<std::mutex> lock( m_mutex );
std::atomic<Status> status( Status::Unknown ); bool done = false;
ctx->media.eventManager().onParsedChanged([this, ctx, &status, &chrono](bool parsed) { ctx->media.eventManager().onParsedChanged([this, ctx, &done, &chrono](bool parsed) {
if ( parsed == false ) if ( parsed == false )
return; return;
auto duration = std::chrono::steady_clock::now() - chrono; auto duration = std::chrono::steady_clock::now() - chrono;
LOG_DEBUG("VLC parsing done in ", std::chrono::duration_cast<std::chrono::microseconds>( duration ).count(), "µs" ); LOG_DEBUG("VLC parsing done in ", std::chrono::duration_cast<std::chrono::microseconds>( duration ).count(), "µs" );
auto s = handleMediaMeta( ctx->file, ctx->media ); std::lock_guard<std::mutex> lock( m_mutex );
auto expected = Status::Unknown; done = true;
while ( status.compare_exchange_weak( expected, s ) == false )
;
m_cond.notify_all(); m_cond.notify_all();
}); });
ctx->media.parseAsync(); ctx->media.parseAsync();
auto success = m_cond.wait_for( lock, std::chrono::seconds( 5 ), [&status]() { return status != Status::Unknown; } ); auto success = m_cond.wait_for( lock, std::chrono::seconds( 5 ), [&done]() { return done == true; } );
if ( success == false ) if ( success == false )
m_cb->done( ctx->file, Status::Fatal, data ); m_cb->done( ctx->file, Status::Fatal, data );
else else
{
auto status = handleMediaMeta( ctx->file, ctx->media );
m_cb->done( ctx->file, status, data ); m_cb->done( ctx->file, status, data );
}
auto duration = std::chrono::steady_clock::now() - chrono; auto duration = std::chrono::steady_clock::now() - chrono;
LOG_DEBUG( "Parsed ", file->mrl(), " in ", std::chrono::duration_cast<std::chrono::milliseconds>( duration ).count(), "ms" ); LOG_DEBUG( "Parsed ", file->mrl(), " in ", std::chrono::duration_cast<std::chrono::milliseconds>( duration ).count(), "ms" );
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment