Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
08eea9cc
Commit
08eea9cc
authored
Oct 22, 2015
by
Hugo Beauzée-Luyssen
Browse files
Parser: Restart the parsing process where we left off
parent
dc8e4f44
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/MediaLibrary.cpp
View file @
08eea9cc
...
...
@@ -72,8 +72,7 @@ const std::vector<std::string> MediaLibrary::supportedAudioExtensions {
};
MediaLibrary
::
MediaLibrary
()
:
m_parser
(
new
Parser
)
,
m_discoverer
(
new
DiscovererWorker
)
:
m_discoverer
(
new
DiscovererWorker
)
{
}
...
...
@@ -115,6 +114,8 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
m_snapshotPath
=
snapshotPath
;
m_callback
=
mlCallback
;
m_dbConnection
.
reset
(
new
SqliteConnection
(
dbPath
)
);
m_parser
.
reset
(
new
Parser
(
m_dbConnection
.
get
()
)
);
if
(
mlCallback
!=
nullptr
)
{
...
...
src/Parser.cpp
View file @
08eea9cc
...
...
@@ -26,9 +26,10 @@
#include "IMedia.h"
Parser
::
Parser
()
Parser
::
Parser
(
DBConnection
dbConnection
)
:
m_thread
(
&
Parser
::
run
,
this
)
,
m_stopParser
(
false
)
,
m_dbConnection
(
dbConnection
)
{
}
...
...
@@ -58,19 +59,21 @@ void Parser::addService(std::unique_ptr<IMetadataService> service)
});
}
void
Parser
::
parse
(
std
::
shared_ptr
<
Media
>
file
,
IMediaLibraryCb
*
cb
)
void
Parser
::
parse
(
std
::
shared_ptr
<
Media
>
file
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
m_lock
);
if
(
m_services
.
size
()
==
0
)
return
;
m_tasks
.
push
(
new
Task
(
file
,
m_services
,
cb
)
);
m_tasks
.
push
(
new
Task
(
file
,
m_services
,
m_callback
)
);
m_cond
.
notify_all
();
}
void
Parser
::
run
()
{
LOG_INFO
(
"Starting Parser thread"
);
restore
();
while
(
m_stopParser
==
false
)
{
Task
*
task
=
nullptr
;
...
...
@@ -92,6 +95,21 @@ void Parser::run()
LOG_INFO
(
"Exiting Parser thread"
);
}
void
Parser
::
restore
()
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
MediaTable
::
Name
+
" WHERE parsed = 0"
;
auto
media
=
Media
::
fetchAll
(
m_dbConnection
,
req
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
m_lock
);
for
(
auto
&
it
:
media
)
{
auto
m
=
std
::
static_pointer_cast
<
Media
>
(
it
);
//FIXME: No callback here
m_tasks
.
push
(
new
Task
(
m
,
m_services
,
nullptr
)
);
}
}
Parser
::
Task
::
Task
(
std
::
shared_ptr
<
Media
>
file
,
Parser
::
ServiceList
&
serviceList
,
IMediaLibraryCb
*
metadataCb
)
:
file
(
file
)
...
...
src/Parser.h
View file @
08eea9cc
...
...
@@ -36,7 +36,7 @@
class
Parser
:
public
IMetadataServiceCb
{
public:
Parser
();
Parser
(
DBConnection
dbConnection
);
~
Parser
();
void
addService
(
std
::
unique_ptr
<
IMetadataService
>
service
);
void
parse
(
std
::
shared_ptr
<
Media
>
file
,
IMediaLibraryCb
*
cb
);
...
...
@@ -44,6 +44,8 @@ class Parser : public IMetadataServiceCb
private:
virtual
void
done
(
std
::
shared_ptr
<
Media
>
file
,
IMetadataService
::
Status
status
,
void
*
data
)
override
;
void
run
();
// Queues all unparsed files for parsing.
void
restore
();
private:
typedef
std
::
unique_ptr
<
IMetadataService
>
ServicePtr
;
...
...
@@ -64,6 +66,7 @@ class Parser : public IMetadataServiceCb
std
::
mutex
m_lock
;
std
::
condition_variable
m_cond
;
std
::
atomic_bool
m_stopParser
;
DBConnection
m_dbConnection
;
};
#endif // PARSER_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment