Commit 39317320 authored by Alexandre Fernandez's avatar Alexandre Fernandez Committed by Hugo Beauzée-Luyssen

Parsers: Moved enum class ParserStep from File to Task

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 885131b4
......@@ -80,6 +80,7 @@ libmedialibrary_la_SOURCES = \
src/metadata_services/vlc/VLCThumbnailer.cpp \
src/parser/Parser.cpp \
src/parser/ParserService.cpp \
src/parser/Task.cpp \
src/utils/Filename.cpp \
src/utils/ModificationsNotifier.cpp \
src/utils/Url.cpp \
......
......@@ -65,7 +65,7 @@ File::File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, Type type,
, m_type( type )
, m_lastModificationDate( file.lastModificationDate() )
, m_size( file.size() )
, m_parserSteps( ParserStep::None )
, m_parserSteps( parser::Task::ParserStep::None )
, m_folderId( folderId )
, m_isPresent( true )
, m_isRemovable( isRemovable )
......@@ -83,7 +83,7 @@ File::File(MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, IFile::Type
, m_type( type )
, m_lastModificationDate( 0 )
, m_size( 0 )
, m_parserSteps( ParserStep::Completed )
, m_parserSteps( parser::Task::ParserStep::Completed )
, m_folderId( 0 )
, m_isPresent( true )
, m_isRemovable( false )
......@@ -133,15 +133,15 @@ bool File::isExternal() const
return m_isExternal;
}
void File::markStepCompleted( ParserStep step )
void File::markStepCompleted( parser::Task::ParserStep step )
{
m_parserSteps = static_cast<ParserStep>( static_cast<uint8_t>( m_parserSteps ) |
m_parserSteps = static_cast<parser::Task::ParserStep>( static_cast<uint8_t>( m_parserSteps ) |
static_cast<uint8_t>( step ) );
}
void File::markStepUncompleted(File::ParserStep step)
void File::markStepUncompleted(parser::Task::ParserStep step)
{
m_parserSteps = static_cast<ParserStep>( static_cast<uint8_t>( m_parserSteps ) &
m_parserSteps = static_cast<parser::Task::ParserStep>( static_cast<uint8_t>( m_parserSteps ) &
( ~ static_cast<uint8_t>( step ) ) );
}
......@@ -154,7 +154,7 @@ bool File::saveParserStep()
return true;
}
File::ParserStep File::parserStep() const
parser::Task::ParserStep File::parserStep() const
{
return m_parserSteps;
}
......@@ -320,14 +320,14 @@ std::vector<std::shared_ptr<File>> File::fetchUnparsed( MediaLibraryPtr ml )
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL AND parser_retries < 3";
return File::fetchAll<File>( ml, req, File::ParserStep::Completed );
return File::fetchAll<File>( ml, req, parser::Task::ParserStep::Completed );
}
void File::resetRetryCount( MediaLibraryPtr ml )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET "
"parser_retries = 0 WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL";
sqlite::Tools::executeUpdate( ml->getConn(), req, ParserStep::Completed );
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Task::ParserStep::Completed );
}
}
......@@ -48,15 +48,6 @@ struct FileTable
class File : public IFile, public DatabaseHelpers<File, policy::FileTable>
{
public:
enum class ParserStep : uint8_t
{
None = 0,
MetadataExtraction = 1,
MetadataAnalysis = 2,
Thumbnailer = 4,
Completed = 1 | 2 | 4,
};
File( MediaLibraryPtr ml, sqlite::Row& row );
File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, Type type, const fs::IFile& file, int64_t folderId, bool isRemovable );
......@@ -74,10 +65,10 @@ public:
* extracted, in case we were to restart the parsing, we would need to
* extract the same information again
*/
void markStepCompleted( ParserStep step );
void markStepUncompleted( ParserStep step );
void markStepCompleted( parser::Task::ParserStep step );
void markStepUncompleted( parser::Task::ParserStep step );
bool saveParserStep();
ParserStep parserStep() const;
parser::Task::ParserStep parserStep() const;
/**
* @brief startParserStep Do some internal book keeping to avoid restarting a step too many time
*/
......@@ -134,7 +125,7 @@ private:
Type m_type;
std::time_t m_lastModificationDate;
unsigned int m_size;
ParserStep m_parserSteps;
parser::Task::ParserStep m_parserSteps;
int64_t m_folderId;
bool m_isPresent;
bool m_isRemovable;
......
......@@ -85,7 +85,7 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
// thumbnailer execution, coming back here, and delegating again to the thumbnailer
// over and over again. We need to ensure the thumbnailer will run, even partially, up to
// the point the playback started.
task.file->markStepUncompleted( File::ParserStep::Thumbnailer );
task.markStepUncompleted( parser::Task::ParserStep::Thumbnailer );
LOG_INFO( "Skipping metadata parsing for file with unknown type: ", task.file->mrl() );
return parser::Task::Status::Success;
}
......@@ -133,11 +133,11 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
if ( task.file->isDeleted() == true || task.media->isDeleted() == true )
return parser::Task::Status::Fatal;
task.file->markStepCompleted( File::ParserStep::MetadataAnalysis );
task.markStepCompleted( parser::Task::ParserStep::MetadataAnalysis );
// Save ourselves from the useless processing of a thumbnail later if
// we're analyzing an audio file
if ( isAudio == true && utils::file::schemeIs( "attachment://", task.media->thumbnail() ) == false )
task.file->markStepCompleted( File::ParserStep::Thumbnailer );
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
if ( task.file->saveParserStep() == false )
return parser::Task::Status::Fatal;
m_notifier->notifyMediaCreation( task.media );
......@@ -531,7 +531,7 @@ bool MetadataParser::isCompleted( const parser::Task& task ) const
{
// We always need to run this task if the metadata extraction isn't completed
return ( static_cast<uint8_t>( task.file->parserStep() ) &
static_cast<uint8_t>( File::ParserStep::MetadataAnalysis ) ) != 0;
static_cast<uint8_t>( parser::Task::ParserStep::MetadataAnalysis ) ) != 0;
}
}
......@@ -76,7 +76,7 @@ parser::Task::Status VLCMetadataService::run( parser::Task& task )
LOG_WARN( "Failed to fetch any tracks for ", file->mrl() );
// Don't save the file parsing step yet, since all data are just in memory. Just mark
// the extraction as done.
task.file->markStepCompleted( File::ParserStep::MetadataExtraction );
task.markStepCompleted( parser::Task::ParserStep::MetadataExtraction );
return parser::Task::Status::Success;
}
......
......@@ -68,7 +68,7 @@ bool VLCThumbnailer::initialize()
bool VLCThumbnailer::isCompleted( const parser::Task& task ) const
{
return ( static_cast<uint8_t>( task.file->parserStep() ) &
static_cast<uint8_t>( File::ParserStep::Thumbnailer ) ) != 0;
static_cast<uint8_t>( parser::Task::ParserStep::Thumbnailer ) ) != 0;
}
parser::Task::Status VLCThumbnailer::run( parser::Task& task )
......@@ -108,7 +108,7 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
// If the media became an audio file, it's not an error
if ( media->type() == Media::Type::Audio )
{
file->markStepCompleted( File::ParserStep::Thumbnailer );
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
file->saveParserStep();
LOG_INFO( file->mrl(), " type has changed to Audio. Skipping thumbnail generation" );
return parser::Task::Status::Success;
......@@ -123,7 +123,7 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
// we do need to run the metadata extraction again.
if ( media->type() == Media::Type::Unknown && media->thumbnail().empty() == false )
{
file->markStepCompleted( File::ParserStep::Thumbnailer );
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
// startPlayback will return an error in case the media is an audio file
media->setType( IMedia::Type::Video );
// And now let the metadata extraction run again
......@@ -148,7 +148,7 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
if ( task.file->isDeleted() == true || task.media->isDeleted() == true )
return parser::Task::Status::Fatal;
file->markStepCompleted( File::ParserStep::Thumbnailer );
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
m_notifier->notifyMediaModification( task.media );
auto t = m_ml->getConn()->newTransaction();
......
......@@ -147,7 +147,7 @@ void Parser::done( std::unique_ptr<parser::Task> t, parser::Task::Status status
if ( status == parser::Task::Status::TemporaryUnavailable ||
status == parser::Task::Status::Fatal ||
t->file->parserStep() == File::ParserStep::Completed )
t->file->parserStep() == parser::Task::ParserStep::Completed )
{
if ( serviceIdx < m_services.size() )
{
......
......@@ -25,8 +25,8 @@
#include <memory>
#include <queue>
#include "File.h"
#include "Task.h"
#include "File.h"
namespace medialibrary
{
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 - 2017 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
* Alexandre Fernandez <nerf@boboop.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "Task.h"
#include <utility>
#include "filesystem/IFile.h"
#include "File.h"
namespace medialibrary
{
namespace parser
{
Task::Task( std::shared_ptr<Media> media, std::shared_ptr<File> file )
: media( std::move( media ) )
, file( std::move( file ) )
, currentService( 0 )
{
}
Task::Task( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs)
: fileFs( std::move( fileFs ) )
, parentFolder( std::move( parentFolder ) )
, parentFolderFs( std::move( parentFolderFs ) )
, currentService( 0 )
{
}
void Task::markStepCompleted( ParserStep stepCompleted )
{
step = static_cast<ParserStep>( static_cast<uint8_t>( step ) | static_cast<uint8_t>( stepCompleted ) );
if ( file != nullptr )
file->markStepCompleted( stepCompleted );
}
void Task::markStepUncompleted( ParserStep stepUncompleted )
{
step = static_cast<ParserStep>( static_cast<uint8_t>( step ) & ( ~ static_cast<uint8_t>( stepUncompleted ) ) );
if ( file != nullptr )
file->markStepUncompleted( stepUncompleted );
}
}
}
......@@ -4,6 +4,7 @@
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
* Alexandre Fernandez <nerf@boboop.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
......@@ -60,22 +61,23 @@ struct Task
Fatal
};
Task( std::shared_ptr<Media> media, std::shared_ptr<File> file )
: media( std::move( media ) )
, file( std::move( file ) )
, currentService( 0 )
enum class ParserStep : uint8_t
{
}
None = 0,
MetadataExtraction = 1,
MetadataAnalysis = 2,
Thumbnailer = 4,
Completed = 1 | 2 | 4,
};
Task( std::shared_ptr<Media> media, std::shared_ptr<File> file );
Task( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs)
: fileFs( std::move( fileFs ) )
, parentFolder( std::move( parentFolder ) )
, parentFolderFs( std::move ( parentFolderFs ) )
, currentService( 0 )
{
}
std::shared_ptr<fs::IDirectory> parentFolderFs );
void markStepCompleted( ParserStep stepCompleted );
void markStepUncompleted( ParserStep stepUncompleted );
std::shared_ptr<Media> media;
std::shared_ptr<File> file;
......@@ -85,6 +87,7 @@ struct Task
std::string mrl;
VLC::Media vlcMedia;
unsigned int currentService;
ParserStep step;
};
}
......
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