Commit ffa5e52c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

metadata: Common: Don't rely on parser types

parent 58fb5d56
......@@ -30,9 +30,7 @@
namespace medialibrary
{
medialibrary::parser::Task::Status
medialibrary::MetadataCommon::startPlayback( parser::Task& task,
VLC::MediaPlayer& mp )
bool medialibrary::MetadataCommon::startPlayback( VLC::Media& media, VLC::MediaPlayer& mp )
{
// Use a copy of the event manager to automatically unregister all events as soon
// as we leave this method.
......@@ -59,14 +57,14 @@ medialibrary::MetadataCommon::startPlayback( parser::Task& task,
bool metaArtworkChanged = false;
bool watchForArtworkChange = false;
auto mem = task.vlcMedia.eventManager();
if ( utils::file::schemeIs( "attachment", task.vlcMedia.meta( libvlc_meta_ArtworkURL ) ) == true )
auto mem = media.eventManager();
if ( utils::file::schemeIs( "attachment", media.meta( libvlc_meta_ArtworkURL ) ) == true )
{
watchForArtworkChange = true;
mem.onMetaChanged([&mutex, &cond, &metaArtworkChanged, &task]( libvlc_meta_t meta ) {
mem.onMetaChanged([&mutex, &cond, &metaArtworkChanged, &media]( libvlc_meta_t meta ) {
if ( meta != libvlc_meta_ArtworkURL
|| metaArtworkChanged == true
|| utils::file::schemeIs( "attachment", task.vlcMedia.meta( libvlc_meta_ArtworkURL ) ) == true )
|| utils::file::schemeIs( "attachment", media.meta( libvlc_meta_ArtworkURL ) ) == true )
return;
std::lock_guard<compat::Mutex> lock( mutex );
metaArtworkChanged = true;
......@@ -83,7 +81,7 @@ medialibrary::MetadataCommon::startPlayback( parser::Task& task,
// In case the playback failed, we probably won't fetch anything interesting anyway.
if ( failedToStart == true || success == false )
return parser::Task::Status::Fatal;
return false;
// If we have any kind of track, but not a video track, we don't have to wait long, tracks are usually
// being discovered together.
......@@ -104,7 +102,7 @@ medialibrary::MetadataCommon::startPlayback( parser::Task& task,
}
}
return parser::Task::Status::Success;
return true;
}
......
......@@ -30,7 +30,7 @@ namespace medialibrary
struct MetadataCommon
{
static parser::Task::Status startPlayback( parser::Task& task, VLC::MediaPlayer& mp );
static bool startPlayback( VLC::Media& media, VLC::MediaPlayer& mp );
};
}
......@@ -80,9 +80,9 @@ parser::Task::Status VLCMetadataService::run( parser::Task& task )
if ( tracks.size() == 0 && task.vlcMedia.subitems()->count() == 0 )
LOG_WARN( "Failed to fetch any tracks for ", mrl, ". Falling back to playback" );
VLC::MediaPlayer mp( task.vlcMedia );
auto res = MetadataCommon::startPlayback( task, mp );
if ( res != parser::Task::Status::Success )
return res;
auto res = MetadataCommon::startPlayback( task.vlcMedia, mp );
if ( res == false )
return parser::Task::Status::Fatal;
}
// Don't save the file parsing step yet, since all data are just in memory. Just mark
// the extraction as done.
......
......@@ -105,24 +105,23 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
setupVout( mp );
auto res = MetadataCommon::startPlayback( task, mp );
if ( res != parser::Task::Status::Success )
if ( MetadataCommon::startPlayback( task.vlcMedia, mp ) == false )
{
LOG_WARN( "Failed to generate ", file->mrl(), " thumbnail: Can't start playback" );
return res;
return parser::Task::Status::Fatal;
}
if ( duration <= 0 )
{
// Seek ahead to have a significant preview
res = seekAhead( mp );
auto res = seekAhead( mp );
if ( res != parser::Task::Status::Success )
{
LOG_WARN( "Failed to generate ", file->mrl(), " thumbnail: Failed to seek ahead" );
return res;
}
}
res = takeThumbnail( media, file, mp );
auto res = takeThumbnail( media, file, mp );
if ( res != parser::Task::Status::Success )
return res;
......
Markdown is supported
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