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
23b75331
Commit
23b75331
authored
Oct 20, 2015
by
Hugo Beauzée-Luyssen
Browse files
Remove ServiceStatus from the global namespace
And make it an enum class
parent
744638ee
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/IMetadataService.h
View file @
23b75331
...
...
@@ -28,20 +28,39 @@
class
MediaLibrary
;
class
IMetadataServiceCb
{
public:
virtual
~
IMetadataServiceCb
()
=
default
;
virtual
void
done
(
std
::
shared_ptr
<
Media
>
file
,
ServiceStatus
status
,
void
*
data
)
=
0
;
};
class
IMetadataServiceCb
;
class
IMetadataService
{
public:
enum
class
Status
{
/// Default value.
/// Also, having success = 0 is not the best idea ever.
Unknown
,
/// All good
Success
,
/// Something failed, but it's not critical (For instance, no internet connection for a
/// module that uses an online database)
Error
,
/// We can't compute this file for now (for instance the file was on a network drive which
/// isn't connected anymore)
TemporaryUnavailable
,
/// Something failed and we won't continue
Fatal
};
virtual
~
IMetadataService
()
=
default
;
virtual
bool
initialize
(
IMetadataServiceCb
*
callback
,
MediaLibrary
*
ml
)
=
0
;
virtual
unsigned
int
priority
()
const
=
0
;
virtual
void
run
(
std
::
shared_ptr
<
Media
>
file
,
void
*
data
)
=
0
;
};
class
IMetadataServiceCb
{
public:
virtual
~
IMetadataServiceCb
()
=
default
;
virtual
void
done
(
std
::
shared_ptr
<
Media
>
file
,
IMetadataService
::
Status
status
,
void
*
data
)
=
0
;
};
#endif // IMETADATASERVICE_H
include/Types.h
View file @
23b75331
...
...
@@ -55,21 +55,4 @@ typedef std::shared_ptr<IArtist> ArtistPtr;
typedef
SqliteConnection
*
DBConnection
;
enum
ServiceStatus
{
/// Default value.
/// Also, having success = 0 is not the best idea ever.
StatusUnknown
,
/// All good
StatusSuccess
,
/// Something failed, but it's not critical (For instance, no internet connection for a
/// module that uses an online database)
StatusError
,
/// We can't compute this file for now (for instance the file was on a network drive which
/// isn't connected anymore)
StatusTemporaryUnavailable
,
/// Something failed and we won't continue
StatusFatal
};
#endif // TYPES_H
src/Parser.cpp
View file @
23b75331
...
...
@@ -105,15 +105,16 @@ Parser::Task::Task(std::shared_ptr<Media> file, Parser::ServiceList& serviceList
}
void
Parser
::
done
(
std
::
shared_ptr
<
Media
>
file
,
ServiceStatus
status
,
void
*
data
)
void
Parser
::
done
(
std
::
shared_ptr
<
Media
>
file
,
IMetadata
Service
::
Status
status
,
void
*
data
)
{
Task
*
t
=
reinterpret_cast
<
Task
*>
(
data
);
if
(
status
==
StatusTemporaryUnavailable
||
status
==
StatusFatal
)
if
(
status
==
IMetadataService
::
Status
::
TemporaryUnavailable
||
status
==
IMetadataService
::
Status
::
Fatal
)
{
delete
t
;
return
;
}
else
if
(
status
==
StatusSuccess
)
else
if
(
status
==
IMetadataService
::
Status
::
Success
)
{
t
->
cb
->
onFileUpdated
(
file
);
}
...
...
src/Parser.h
View file @
23b75331
...
...
@@ -42,7 +42,7 @@ class Parser : public IMetadataServiceCb
void
parse
(
std
::
shared_ptr
<
Media
>
file
,
IMediaLibraryCb
*
cb
);
private:
virtual
void
done
(
std
::
shared_ptr
<
Media
>
file
,
ServiceStatus
status
,
void
*
data
)
override
;
virtual
void
done
(
std
::
shared_ptr
<
Media
>
file
,
IMetadata
Service
::
Status
status
,
void
*
data
)
override
;
void
run
();
private:
...
...
src/metadata_services/vlc/VLCMetadataService.cpp
View file @
23b75331
...
...
@@ -60,7 +60,7 @@ void VLCMetadataService::run( std::shared_ptr<Media> file, void* data )
ctx
->
media
=
VLC
::
Media
(
m_instance
,
file
->
mrl
(),
VLC
::
Media
::
FromPath
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_mutex
);
auto
status
=
StatusUnknown
;
auto
status
=
Status
::
Unknown
;
ctx
->
media
.
eventManager
().
onParsedChanged
([
this
,
ctx
,
&
status
](
bool
parsed
)
mutable
{
if
(
parsed
==
false
)
...
...
@@ -75,20 +75,20 @@ void VLCMetadataService::run( std::shared_ptr<Media> file, void* data )
m_cond
.
notify_all
();
});
ctx
->
media
.
parseAsync
();
auto
success
=
m_cond
.
wait_for
(
lock
,
std
::
chrono
::
seconds
(
5
),
[
&
status
]()
{
return
status
!=
StatusUnknown
;
}
);
auto
success
=
m_cond
.
wait_for
(
lock
,
std
::
chrono
::
seconds
(
5
),
[
&
status
]()
{
return
status
!=
Status
::
Unknown
;
}
);
if
(
success
==
false
)
m_cb
->
done
(
ctx
->
file
,
StatusFatal
,
data
);
m_cb
->
done
(
ctx
->
file
,
Status
::
Fatal
,
data
);
else
m_cb
->
done
(
ctx
->
file
,
status
,
data
);
}
ServiceStatus
VLCMetadataService
::
handleMediaMeta
(
std
::
shared_ptr
<
Media
>
file
,
VLC
::
Media
&
media
)
const
IMetadata
Service
::
Status
VLCMetadataService
::
handleMediaMeta
(
std
::
shared_ptr
<
Media
>
file
,
VLC
::
Media
&
media
)
const
{
auto
tracks
=
media
.
tracks
();
if
(
tracks
.
size
()
==
0
)
{
LOG_ERROR
(
"Failed to fetch tracks"
);
return
StatusFatal
;
return
Status
::
Fatal
;
}
bool
isAudio
=
true
;
for
(
auto
&
track
:
tracks
)
...
...
@@ -112,14 +112,14 @@ ServiceStatus VLCMetadataService::handleMediaMeta( std::shared_ptr<Media> file,
if
(
isAudio
==
true
)
{
if
(
parseAudioFile
(
file
,
media
)
==
false
)
return
StatusFatal
;
return
Status
::
Fatal
;
}
else
{
if
(
parseVideoFile
(
file
,
media
)
==
false
)
return
StatusFatal
;
return
Status
::
Fatal
;
}
return
StatusSuccess
;
return
Status
::
Success
;
}
bool
VLCMetadataService
::
parseAudioFile
(
std
::
shared_ptr
<
Media
>
media
,
VLC
::
Media
&
vlcMedia
)
const
...
...
src/metadata_services/vlc/VLCMetadataService.h
View file @
23b75331
...
...
@@ -51,7 +51,7 @@ class VLCMetadataService : public IMetadataService
virtual
void
run
(
std
::
shared_ptr
<
Media
>
file
,
void
*
data
)
override
;
private:
Service
Status
handleMediaMeta
(
std
::
shared_ptr
<
Media
>
file
,
VLC
::
Media
&
media
)
const
;
Status
handleMediaMeta
(
std
::
shared_ptr
<
Media
>
file
,
VLC
::
Media
&
media
)
const
;
bool
parseAudioFile
(
std
::
shared_ptr
<
Media
>
media
,
VLC
::
Media
&
vlcMedia
)
const
;
bool
parseVideoFile
(
std
::
shared_ptr
<
Media
>
file
,
VLC
::
Media
&
media
)
const
;
bool
handleArtist
(
std
::
shared_ptr
<
Album
>
album
,
std
::
shared_ptr
<
Media
>
media
,
VLC
::
Media
&
vlcMedia
,
bool
newAlbum
)
const
;
...
...
src/metadata_services/vlc/VLCThumbnailer.cpp
View file @
23b75331
...
...
@@ -57,13 +57,13 @@ void VLCThumbnailer::run(std::shared_ptr<Media> file, void *data )
// If we don't know the file type yet, it actually looks more like a bug
// since this should run after file type deduction, and not run in case
// that step fails.
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
;
}
else
if
(
file
->
type
()
!=
IMedia
::
Type
::
VideoType
)
{
// There's no point in generating a thumbnail for a non-video file.
m_cb
->
done
(
file
,
StatusSuccess
,
data
);
m_cb
->
done
(
file
,
Status
::
Success
,
data
);
return
;
}
...
...
@@ -105,7 +105,7 @@ bool VLCThumbnailer::startPlayback(std::shared_ptr<Media> file, VLC::MediaPlayer
if
(
success
==
false
||
failed
==
true
)
{
// In case of timeout or error, don't go any further
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
false
;
}
return
true
;
...
...
@@ -128,7 +128,7 @@ bool VLCThumbnailer::seekAhead(std::shared_ptr<Media> file, VLC::MediaPlayer& mp
event
->
unregister
();
if
(
success
==
false
)
{
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
false
;
}
return
true
;
...
...
@@ -190,7 +190,7 @@ bool VLCThumbnailer::takeSnapshot(std::shared_ptr<Media> file, VLC::MediaPlayer
});
if
(
success
==
false
)
{
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
false
;
}
// Prevent the vmem from screwing our snapshot over.
...
...
@@ -232,7 +232,7 @@ bool VLCThumbnailer::compress(uint8_t* buff, std::shared_ptr<Media> file, void *
if
(
fOut
==
nullptr
)
{
LOG_ERROR
(
"Failed to open snapshot file "
,
path
);
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
false
;
}
...
...
@@ -250,7 +250,7 @@ bool VLCThumbnailer::compress(uint8_t* buff, std::shared_ptr<Media> file, void *
{
LOG_ERROR
(
"JPEG failure: "
,
err
.
message
);
jpeg_destroy_compress
(
&
compInfo
);
m_cb
->
done
(
file
,
StatusError
,
data
);
m_cb
->
done
(
file
,
Status
::
Error
,
data
);
return
false
;
}
...
...
@@ -284,6 +284,6 @@ bool VLCThumbnailer::compress(uint8_t* buff, std::shared_ptr<Media> file, void *
#endif
file
->
setSnapshot
(
path
);
m_cb
->
done
(
file
,
StatusSuccess
,
data
);
m_cb
->
done
(
file
,
Status
::
Success
,
data
);
return
true
;
}
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