Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
2d41b640
Commit
2d41b640
authored
Jan 28, 2016
by
Hugo Beauzée-Luyssen
Browse files
Move VLC instance initialization into a separate class
parent
112ca834
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
2d41b640
...
...
@@ -84,6 +84,7 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
discoverer/DiscovererWorker.cpp
utils/Filename.cpp
utils/VLCInstance.cpp
database/SqliteConnection.cpp
database/SqliteTransaction.cpp
...
...
src/MediaLibrary.cpp
View file @
2d41b640
...
...
@@ -449,24 +449,9 @@ void MediaLibrary::startParser()
{
m_parser
.
reset
(
new
Parser
(
m_dbConnection
.
get
(),
this
,
m_callback
)
);
const
char
*
args
[]
=
{
"-vv"
,
};
m_vlcInstance
=
VLC
::
Instance
(
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
args
);
m_vlcInstance
.
logSet
([
this
](
int
lvl
,
const
libvlc_log_t
*
,
std
::
string
msg
)
{
if
(
m_verbosity
!=
LogLevel
::
Verbose
)
return
;
if
(
lvl
==
LIBVLC_ERROR
)
Log
::
Error
(
msg
);
else
if
(
lvl
==
LIBVLC_WARNING
)
Log
::
Warning
(
msg
);
else
Log
::
Info
(
msg
);
});
auto
vlcService
=
std
::
unique_ptr
<
VLCMetadataService
>
(
new
VLCMetadataService
(
m_vlcInstance
)
);
auto
vlcService
=
std
::
unique_ptr
<
VLCMetadataService
>
(
new
VLCMetadataService
);
auto
metadataService
=
std
::
unique_ptr
<
MetadataParser
>
(
new
MetadataParser
(
m_dbConnection
.
get
()
)
);
auto
thumbnailerService
=
std
::
unique_ptr
<
VLCThumbnailer
>
(
new
VLCThumbnailer
(
m_vlcInstance
)
);
auto
thumbnailerService
=
std
::
unique_ptr
<
VLCThumbnailer
>
(
new
VLCThumbnailer
);
m_parser
->
addService
(
std
::
move
(
vlcService
)
);
m_parser
->
addService
(
std
::
move
(
metadataService
)
);
m_parser
->
addService
(
std
::
move
(
thumbnailerService
)
);
...
...
src/MediaLibrary.h
View file @
2d41b640
...
...
@@ -31,7 +31,6 @@ class SqliteConnection;
#include
"IMediaLibrary.h"
#include
"IDiscoverer.h"
#include
"logging/Logger.h"
#include
"vlcpp/vlc.hpp"
#include
"Settings.h"
class
Album
;
...
...
@@ -132,10 +131,6 @@ class MediaLibrary : public IMediaLibrary
std
::
string
m_thumbnailPath
;
IMediaLibraryCb
*
m_callback
;
// This probably qualifies as a work around, but we need to keep the VLC::Instance
// alive to be able to use the logging wrapper lambda
VLC
::
Instance
m_vlcInstance
;
// Keep the parser as last field.
// The parser holds a (raw) pointer to the media library. When MediaLibrary's destructor gets called
// it might still finish a few operations before exiting the parser thread. Those operations are
...
...
src/logging/Logger.h
View file @
2d41b640
...
...
@@ -99,6 +99,11 @@ public:
s_logLevel
.
store
(
level
,
std
::
memory_order_relaxed
);
}
static
LogLevel
logLevel
()
{
return
s_logLevel
.
load
(
std
::
memory_order_relaxed
);
}
template
<
typename
...
Args
>
static
void
Error
(
Args
...
args
)
{
...
...
src/metadata_services/vlc/VLCMetadataService.cpp
View file @
2d41b640
...
...
@@ -24,9 +24,10 @@
#include
"VLCMetadataService.h"
#include
"Media.h"
#include
"utils/VLCInstance.h"
VLCMetadataService
::
VLCMetadataService
(
const
VLC
::
Instance
&
vlc
)
:
m_instance
(
vlc
)
VLCMetadataService
::
VLCMetadataService
()
:
m_instance
(
VLCInstance
::
get
()
)
{
}
...
...
src/metadata_services/vlc/VLCMetadataService.h
View file @
2d41b640
...
...
@@ -33,7 +33,7 @@
class
VLCMetadataService
:
public
ParserService
{
public:
explicit
VLCMetadataService
(
const
VLC
::
Instance
&
vlc
);
explicit
VLCMetadataService
();
private:
virtual
parser
::
Task
::
Status
run
(
parser
::
Task
&
task
)
override
;
...
...
src/metadata_services/vlc/VLCThumbnailer.cpp
View file @
2d41b640
...
...
@@ -41,9 +41,10 @@
#include
"File.h"
#include
"logging/Logger.h"
#include
"MediaLibrary.h"
#include
"utils/VLCInstance.h"
VLCThumbnailer
::
VLCThumbnailer
(
const
VLC
::
Instance
&
vlc
)
:
m_instance
(
vlc
)
VLCThumbnailer
::
VLCThumbnailer
()
:
m_instance
(
VLCInstance
::
get
()
)
,
m_ml
(
nullptr
)
#ifdef WITH_EVAS
,
m_canvas
(
nullptr
,
&
evas_free
)
...
...
src/metadata_services/vlc/VLCThumbnailer.h
View file @
2d41b640
...
...
@@ -45,7 +45,7 @@
class
VLCThumbnailer
:
public
ParserService
{
public:
explicit
VLCThumbnailer
(
const
VLC
::
Instance
&
vlc
);
explicit
VLCThumbnailer
();
virtual
~
VLCThumbnailer
();
virtual
parser
::
Task
::
Status
run
(
parser
::
Task
&
task
)
override
;
virtual
bool
initialize
()
override
;
...
...
src/utils/VLCInstance.cpp
0 → 100644
View file @
2d41b640
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.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.
*****************************************************************************/
#include
"VLCInstance.h"
#include
"logging/Logger.h"
#include
"vlcpp/vlc.hpp"
namespace
{
// Define this in the .cpp file to avoid including libvlcpp from the header.
struct
Init
{
Init
()
{
const
char
*
args
[]
=
{
"-vv"
,
};
instance
=
VLC
::
Instance
(
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
args
);
instance
.
logSet
([
this
](
int
lvl
,
const
libvlc_log_t
*
,
std
::
string
msg
)
{
if
(
Log
::
logLevel
()
!=
LogLevel
::
Verbose
)
return
;
if
(
lvl
==
LIBVLC_ERROR
)
Log
::
Error
(
msg
);
else
if
(
lvl
==
LIBVLC_WARNING
)
Log
::
Warning
(
msg
);
else
Log
::
Info
(
msg
);
});
}
VLC
::
Instance
instance
;
};
}
VLC
::
Instance
&
VLCInstance
::
get
()
{
// Instanciate the wrapper only once, and run initialization in its constructor.
static
Init
wrapper
;
return
wrapper
.
instance
;
}
src/utils/VLCInstance.h
0 → 100644
View file @
2d41b640
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.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.
*****************************************************************************/
#pragma once
namespace
VLC
{
class
Instance
;
}
class
VLCInstance
{
public:
static
VLC
::
Instance
&
get
();
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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