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

IThumbnail: Pass the destination as 3rd parameter

This enforces our naming scheme for thumbnails, including when an
external thumbnailer is used
Fix #83
parent 54d97a15
......@@ -35,12 +35,14 @@ public:
* @brief request Generate a thumbnail for the provided media
* @param media The media to generate a thumbnail for
* @param mrl The mrl to the main file for this media
* @param destination The path in which to save the thumbnail
*
* This method is expected to be blocking until the generation is successful
* If successful, the implementation must call IMedia::setThumbnail and pass
* the mrl to the generated thumbnail.
* This method is expected to be blocking until the generation is successful.
* Upon successful return, the <destination> path must contain the generated
* thumbnail
*/
virtual bool generate( MediaPtr media, const std::string& mrl ) = 0;
virtual bool generate( MediaPtr media, const std::string& mrl,
const std::string& destination ) = 0;
};
}
......@@ -42,7 +42,8 @@ CoreThumbnailer::CoreThumbnailer( MediaLibraryPtr ml )
{
}
bool CoreThumbnailer::generate( medialibrary::MediaPtr media, const std::string& mrl )
bool CoreThumbnailer::generate( medialibrary::MediaPtr media,
const std::string& mrl, const std::string& dest )
{
VLC::Media vlcMedia{ VLCInstance::get(), mrl, VLC::Media::FromType::FromLocation };
auto em = vlcMedia.eventManager();
......@@ -71,11 +72,8 @@ bool CoreThumbnailer::generate( medialibrary::MediaPtr media, const std::string&
}
if ( thumbnail.isValid() == false )
return false;
auto path = m_ml->thumbnailPath() + "/" + std::to_string( media->id() ) + ".jpg";
if ( thumbnail.save( path ) == false )
return false;
auto m = static_cast<Media*>( media.get() );
return m->setThumbnail( path, Thumbnail::Origin::Media, true );
return thumbnail.save( dest );
}
}
......@@ -34,7 +34,8 @@ class CoreThumbnailer : public IThumbnailer
public:
CoreThumbnailer( MediaLibraryPtr ml );
virtual bool generate( MediaPtr media, const std::string& mrl ) override;
virtual bool generate( MediaPtr media, const std::string& mrl,
const std::string& dest) override;
private:
MediaLibraryPtr m_ml;
};
......
......@@ -163,7 +163,10 @@ bool ThumbnailerWorker::generateThumbnail( MediaPtr media )
}
LOG_INFO( "Generating ", mrl, " thumbnail..." );
if ( m_generator->generate( media, mrl ) == false )
auto dest = m_ml->thumbnailPath() + "/" + std::to_string( media->id() ) + ".jpg";
auto m = static_cast<Media*>( media.get() );
if ( m_generator->generate( media, mrl, dest ) == false ||
m->setThumbnail( dest, Thumbnail::Origin::Media, true ) == false )
return false;
m_ml->getNotifier()->notifyMediaModification( media );
......
......@@ -48,7 +48,8 @@ VmemThumbnailer::VmemThumbnailer( MediaLibraryPtr ml )
#endif
}
bool VmemThumbnailer::generate( MediaPtr media, const std::string& mrl )
bool VmemThumbnailer::generate( MediaPtr media, const std::string& mrl,
const std::string& dest )
{
VLC::Media vlcMedia = VLC::Media( VLCInstance::get(), mrl,
VLC::Media::FromType::FromLocation );
......@@ -90,7 +91,7 @@ bool VmemThumbnailer::generate( MediaPtr media, const std::string& mrl )
return false;
}
}
return takeThumbnail( task );
return takeThumbnail( task, dest );
}
bool VmemThumbnailer::seekAhead( Task& task )
......@@ -167,7 +168,7 @@ void VmemThumbnailer::setupVout( Task& task )
);
}
bool VmemThumbnailer::takeThumbnail( Task& task )
bool VmemThumbnailer::takeThumbnail( Task& task, const std::string& dest )
{
// lock, signal that we want a thumbnail, and wait.
{
......@@ -184,25 +185,16 @@ bool VmemThumbnailer::takeThumbnail( Task& task )
}
}
task.mp.stop();
return compress( task );
return compress( task, dest );
}
bool VmemThumbnailer::compress( Task& task )
bool VmemThumbnailer::compress( Task& task, const std::string& dest )
{
auto path = m_ml->thumbnailPath();
path += "/";
path += std::to_string( task.media->id() ) + "." + m_compressor->extension();
auto hOffset = task.width > DesiredWidth ? ( task.width - DesiredWidth ) / 2 : 0;
auto vOffset = task.height > DesiredHeight ? ( task.height - DesiredHeight ) / 2 : 0;
if ( m_compressor->compress( m_buff.get(), path, task.width, task.height,
DesiredWidth, DesiredHeight, hOffset, vOffset ) == false )
return false;
auto media = static_cast<Media*>( task.media.get() );
media->setThumbnail( path, Thumbnail::Origin::Media, true );
return true;
return m_compressor->compress( m_buff.get(), dest, task.width, task.height,
DesiredWidth, DesiredHeight, hOffset, vOffset );
}
VmemThumbnailer::Task::Task( MediaPtr m, std::string mrl )
......
......@@ -53,11 +53,12 @@ class VmemThumbnailer : public IThumbnailer
public:
VmemThumbnailer( MediaLibraryPtr ml );
virtual bool generate( MediaPtr media, const std::string& mrl ) override;
virtual bool generate( MediaPtr media, const std::string& mrl,
const std::string& dest ) override;
bool seekAhead( Task& task );
void setupVout( Task& task );
bool takeThumbnail( Task& task );
bool compress( Task& task );
bool takeThumbnail( Task& task, const std::string& dest );
bool compress( Task& task, const std::string& dest );
private:
// Force a base width, let height be computed depending on A/R
......
......@@ -200,10 +200,6 @@ void ModificationNotifier::run()
void ModificationNotifier::removeMediaThumbnail( int64_t mediaId )
{
// FIXME: This is making an unwarranted assumption about the thumbnail naming
// scheme. We need to enforce this naming internally, and provide the output
// path to the various thumbnailers.
// See https://code.videolan.org/videolan/medialibrary/issues/83
auto path = m_ml->thumbnailPath() + std::to_string( mediaId ) + ".jpg";
utils::fs::remove( path );
}
......
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