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

Snapshot -> Thumbnail

parent ac6949de
......@@ -75,9 +75,12 @@ class IMedia
virtual std::vector<LabelPtr> labels() = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
// Returns the location of this file snapshot.
// This is likely to be used for album arts as well.
virtual const std::string& snapshot() = 0;
///
/// \brief thumbnail Returns the path of a thumbnail for this file
/// \return A path, relative to the thumbnailPath configured when initializing
/// The media library
///
virtual const std::string& thumbnail() = 0;
virtual unsigned int insertionDate() const = 0;
};
......
......@@ -79,7 +79,7 @@ class IMediaLibrary
/// \param dbPath Path to the database
/// \return true in case of success, false otherwise
///
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, IMediaLibraryCb* metadataCb ) = 0;
virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* metadataCb ) = 0;
virtual void setVerbosity( LogLevel v ) = 0;
/**
* Replaces the default filesystem factory
......@@ -110,7 +110,7 @@ class IMediaLibrary
* @brief ignoreFolder will blacklist a folder for discovery
*/
virtual bool ignoreFolder( const std::string& path ) = 0;
virtual const std::string& snapshotPath() const = 0;
virtual const std::string& thumbnailPath() const = 0;
virtual void setLogger( ILogger* logger ) = 0;
/**
* @brief pauseBackgroundOperations Will stop potentially CPU intensive background
......
......@@ -61,7 +61,7 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>> m_folderId
>> m_lastModificationDate
>> m_insertionDate
>> m_snapshot
>> m_thumbnail
>> m_isParsed
>> m_title
>> m_isPresent
......@@ -268,9 +268,9 @@ std::vector<AudioTrackPtr> Media::audioTracks()
return AudioTrack::fetchAll<IAudioTrack>( m_dbConnection, req, m_id );
}
const std::string &Media::snapshot()
const std::string &Media::thumbnail()
{
return m_snapshot;
return m_thumbnail;
}
unsigned int Media::insertionDate() const
......@@ -278,11 +278,11 @@ unsigned int Media::insertionDate() const
return m_insertionDate;
}
void Media::setSnapshot( const std::string& snapshot )
void Media::setThumbnail(const std::string& thumbnail )
{
if ( m_snapshot == snapshot )
if ( m_thumbnail == thumbnail )
return;
m_snapshot = snapshot;
m_thumbnail = thumbnail;
m_changed = true;
}
......@@ -290,7 +290,7 @@ bool Media::save()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"type = ?, duration = ?, play_count = ?, progress = ?, rating = ?, show_episode_id = ?,"
"artist = ?, movie_id = ?, last_modification_date = ?, snapshot = ?, parsed = ?,"
"artist = ?, movie_id = ?, last_modification_date = ?, thumbnail = ?, parsed = ?,"
"title = ? WHERE id_media = ?";
if ( m_changed == false )
return true;
......@@ -298,7 +298,7 @@ bool Media::save()
m_progress, m_rating,
sqlite::ForeignKey{ m_showEpisodeId }, m_artist,
sqlite::ForeignKey{ m_movieId }, m_lastModificationDate,
m_snapshot, m_isParsed, m_title, m_id ) == false )
m_thumbnail, m_isParsed, m_title, m_id ) == false )
{
return false;
}
......@@ -371,7 +371,7 @@ bool Media::createTable( DBConnection connection )
"folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"insertion_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"thumbnail TEXT,"
"parsed BOOLEAN NOT NULL DEFAULT 0,"
"title TEXT,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
......
......@@ -90,9 +90,9 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
bool addAudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc );
virtual std::vector<AudioTrackPtr> audioTracks() override;
virtual const std::string& snapshot() override;
virtual const std::string& thumbnail() override;
virtual unsigned int insertionDate() const override;
void setSnapshot( const std::string& snapshot );
void setThumbnail( const std::string& thumbnail );
bool save();
unsigned int lastModificationDate();
......@@ -120,7 +120,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
unsigned int m_folderId;
unsigned int m_lastModificationDate;
unsigned int m_insertionDate;
std::string m_snapshot;
std::string m_thumbnail;
bool m_isParsed;
std::string m_title;
bool m_isPresent;
......
......@@ -137,12 +137,12 @@ bool MediaLibrary::createAllTables()
return true;
}
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& snapshotPath, IMediaLibraryCb* mlCallback )
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback )
{
if ( m_fsFactory == nullptr )
m_fsFactory.reset( new factory::FileSystemFactory );
Folder::setFileSystemFactory( m_fsFactory );
m_snapshotPath = snapshotPath;
m_thumbnailPath = thumbnailPath;
m_callback = mlCallback;
m_dbConnection.reset( new SqliteConnection( dbPath ) );
......@@ -434,9 +434,9 @@ bool MediaLibrary::ignoreFolder( const std::string& path )
return Folder::blacklist( m_dbConnection.get(), path );
}
const std::string& MediaLibrary::snapshotPath() const
const std::string& MediaLibrary::thumbnailPath() const
{
return m_snapshotPath;
return m_thumbnailPath;
}
void MediaLibrary::setLogger( ILogger* logger )
......
......@@ -46,7 +46,7 @@ class MediaLibrary : public IMediaLibrary
public:
MediaLibrary();
~MediaLibrary();
virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, IMediaLibraryCb* metadataCb ) override;
virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* metadataCb ) override;
virtual void setVerbosity( LogLevel v ) override;
virtual void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory ) override;
......@@ -81,7 +81,7 @@ class MediaLibrary : public IMediaLibrary
virtual void discover( const std::string& entryPoint ) override;
bool ignoreFolder( const std::string& path ) override;
virtual const std::string& snapshotPath() const override;
virtual const std::string& thumbnailPath() const override;
virtual void setLogger( ILogger* logger ) override;
//Temporarily public, move back to private as soon as we start monitoring the FS
virtual void reload() override;
......@@ -106,7 +106,7 @@ class MediaLibrary : public IMediaLibrary
protected:
std::unique_ptr<SqliteConnection> m_dbConnection;
std::shared_ptr<factory::IFileSystem> m_fsFactory;
std::string m_snapshotPath;
std::string m_thumbnailPath;
IMediaLibraryCb* m_callback;
// This probably qualifies as a work around, but we need to keep the VLC::Instance
......
......@@ -187,7 +187,7 @@ bool VLCMetadataService::parseAudioFile( std::shared_ptr<Media> media, VLC::Medi
auto cover = vlcMedia.meta( libvlc_meta_ArtworkURL );
if ( cover.empty() == false )
media->setSnapshot( cover );
media->setThumbnail( cover );
auto artists = handleArtists( media, vlcMedia );
auto album = handleAlbum( media, vlcMedia, artists.first.get(), artists.second.get() );
......@@ -448,7 +448,7 @@ bool VLCMetadataService::link( std::shared_ptr<Media> media, std::shared_ptr<Alb
albumArtist = Artist::fetch( m_dbConn, medialibrary::UnknownArtistID );
}
// We might modify albumArtist later, hence handle snapshots before.
// We might modify albumArtist later, hence handle thumbnails before.
// If we have an albumArtist (meaning the track was properly tagged, we
// can assume this artist is a correct match. We can use the thumbnail from
// the current album for the albumArtist, if none has been set before.
......
......@@ -48,7 +48,7 @@ VLCThumbnailer::VLCThumbnailer(const VLC::Instance &vlc)
#ifdef WITH_EVAS
, m_canvas( nullptr, &evas_free )
#endif
, m_snapshotRequired( false )
, m_thumbnailRequired( false )
, m_width( 0 )
, m_height( 0 )
, m_prevSize( 0 )
......@@ -114,9 +114,9 @@ void VLCThumbnailer::run(std::shared_ptr<Media> file, void *data )
m_cb->done( file, Status::Success, data );
return;
}
else if ( file->snapshot().empty() == false )
else if ( file->thumbnail().empty() == false )
{
LOG_INFO(file->snapshot(), " already has a snapshot" );
LOG_INFO(file->thumbnail(), " already has a thumbnail" );
m_cb->done( file, Status::Success, data );
return;
}
......@@ -140,7 +140,7 @@ void VLCThumbnailer::run(std::shared_ptr<Media> file, void *data )
LOG_WARN( "Failed to generate ", file->mrl(), " thumbnail" );
return;
}
takeSnapshot( file, mp, data );
takeThumbnail( file, mp, data );
LOG_INFO( "Done generating ", file->mrl(), " thumbnail" );
}
......@@ -233,7 +233,7 @@ void VLCThumbnailer::setupVout( VLC::MediaPlayer& mp )
//unlock
[this](void*, void*const*) {
bool expected = true;
if ( m_snapshotRequired.compare_exchange_strong( expected, false ) )
if ( m_thumbnailRequired.compare_exchange_strong( expected, false ) )
{
m_cond.notify_all();
}
......@@ -244,15 +244,15 @@ void VLCThumbnailer::setupVout( VLC::MediaPlayer& mp )
);
}
bool VLCThumbnailer::takeSnapshot(std::shared_ptr<Media> file, VLC::MediaPlayer &mp, void *data)
bool VLCThumbnailer::takeThumbnail(std::shared_ptr<Media> file, VLC::MediaPlayer &mp, void *data)
{
// lock, signal that we want a snapshot, and wait.
// lock, signal that we want a thumbnail, and wait.
{
std::unique_lock<std::mutex> lock( m_mutex );
m_snapshotRequired = true;
m_thumbnailRequired = true;
bool success = m_cond.wait_for( lock, std::chrono::seconds( 3 ), [this]() {
// Keep waiting if the vmem thread hasn't restored m_snapshotRequired to false
return m_snapshotRequired == false;
// Keep waiting if the vmem thread hasn't restored m_thumbnailRequired to false
return m_thumbnailRequired == false;
});
if ( success == false )
{
......@@ -283,7 +283,7 @@ struct jpegError : public jpeg_error_mgr
bool VLCThumbnailer::compress( std::shared_ptr<Media> file, void *data )
{
auto path = m_ml->snapshotPath();
auto path = m_ml->thumbnailPath();
path += "/";
path += std::to_string( file->id() ) +
#ifdef WITH_EVAS
......@@ -301,7 +301,7 @@ bool VLCThumbnailer::compress( std::shared_ptr<Media> file, void *data )
auto fOut = std::unique_ptr<FILE, int(*)(FILE*)>( fopen( path.c_str(), "wb" ), &fclose );
if ( fOut == nullptr )
{
LOG_ERROR("Failed to open snapshot file ", path);
LOG_ERROR("Failed to open thumbnail file ", path);
m_cb->done( file, Status::Error, data );
return false;
}
......@@ -368,7 +368,7 @@ bool VLCThumbnailer::compress( std::shared_ptr<Media> file, void *data )
#error FIXME
#endif
file->setSnapshot( path );
file->setThumbnail( path );
if ( file->save() == false )
m_cb->done( file, Status::Error, data );
else
......
......@@ -55,7 +55,7 @@ private:
bool startPlayback( std::shared_ptr<Media> file, VLC::MediaPlayer& mp, void *data);
bool seekAhead(std::shared_ptr<Media> file, VLC::MediaPlayer &mp, void *data);
void setupVout(VLC::MediaPlayer &mp);
bool takeSnapshot(std::shared_ptr<Media> file, VLC::MediaPlayer &mp, void* data);
bool takeThumbnail(std::shared_ptr<Media> file, VLC::MediaPlayer &mp, void* data);
bool compress(std::shared_ptr<Media> file, void* data );
private:
......@@ -70,13 +70,13 @@ private:
MediaLibrary* m_ml;
std::mutex m_mutex;
std::condition_variable m_cond;
// Per snapshot variables
// Per thumbnail variables
#ifdef WITH_EVAS
std::unique_ptr<Evas, void(*)(Evas*)> m_canvas;
std::unique_ptr<uint8_t[]> m_cropBuffer;
#endif
std::unique_ptr<uint8_t[]> m_buff;
std::atomic_bool m_snapshotRequired;
std::atomic_bool m_thumbnailRequired;
uint32_t m_width;
uint32_t m_height;
uint32_t m_prevSize;
......
......@@ -127,7 +127,7 @@ void Tests::checkMedias(const rapidjson::Value& expectedMedias)
if ( expectedMedia.HasMember( "snapshotExpected" ) == true )
{
auto snapshotExpected = expectedMedia["snapshotExpected"].GetBool();
ASSERT_EQ( !snapshotExpected, media->snapshot().empty() );
ASSERT_EQ( !snapshotExpected, media->thumbnail().empty() );
}
}
}
......
......@@ -127,21 +127,21 @@ TEST_F( Medias, Artist )
ASSERT_EQ( f2->artist(), newArtist );
}
TEST_F( Medias, Snapshot )
TEST_F( Medias, Thumbnail )
{
auto f = ml->addFile( "media.avi" );
ASSERT_EQ( f->snapshot(), "" );
ASSERT_EQ( f->thumbnail(), "" );
std::string newSnapshot( "/path/to/snapshot" );
std::string newThumbnail( "/path/to/thumbnail" );
f->setSnapshot( newSnapshot );
f->setThumbnail( newThumbnail );
f->save();
ASSERT_EQ( f->snapshot(), newSnapshot );
ASSERT_EQ( f->thumbnail(), newThumbnail );
Reload();
auto f2 = ml->media( f->id() );
ASSERT_EQ( f2->snapshot(), newSnapshot );
ASSERT_EQ( f2->thumbnail(), newThumbnail );
}
TEST_F( Medias, PlayCount )
......
......@@ -152,9 +152,9 @@ TEST_F( Shows, SetEpisodeArtwork )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
bool res = e->setArtworkUrl( "path-to-snapshot" );
bool res = e->setArtworkUrl( "path-to-art" );
ASSERT_TRUE( res );
ASSERT_EQ( e->artworkUrl(), "path-to-snapshot" );
ASSERT_EQ( e->artworkUrl(), "path-to-art" );
Reload();
......
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