Do not use exceptions when scan file error occurs

This commit is contained in:
emeric
2015-09-02 20:56:12 +02:00
parent f58a277053
commit 14481d1e77
8 changed files with 133 additions and 134 deletions
+1
View File
@@ -14,6 +14,7 @@
- handle access rights problems (instead of aborting)
- add a global play counter for tracks. This will help people to spot most popular files
- rework the exception process in av/metadata/updater in case of bad files
- Use the WServer::post method to notify the end of the database scan? (with results?)
[Metadata]
- OGG metadata -> properly handle metadata nested in the audio stream
+6 -3
View File
@@ -87,14 +87,17 @@ InputFormatContext::getBestStreamIdx(AVMediaType type, Stream::Idx& index)
}
}
void
bool
InputFormatContext::findStreamInfo(void)
{
AvError err = avformat_find_stream_info(native(), NULL);
if (err) {
if (err)
{
LMS_LOG(MOD_AV, SEV_ERROR) << "Couldn't find stream information: " << err;
throw std::runtime_error("av_find_stream_info failed!");
return false;
}
return true;
}
+1 -1
View File
@@ -47,7 +47,7 @@ class InputFormatContext : public FormatContext
Dictionary getMetadata(void); // metadata access
// Scan file
void findStreamInfo();
bool findStreamInfo();
// Get attached pictures
+3 -1
View File
@@ -386,7 +386,9 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
}
MetaData::Items items;
_metadataParser.parse(file, items);
if (!_metadataParser.parse(file, items))
return;
// We estimate this is a audio file if:
// - we found a least one audio stream
+5 -13
View File
@@ -32,14 +32,14 @@
namespace MetaData
{
void
bool
AvFormat::parse(const boost::filesystem::path& p, Items& items)
{
try {
Av::InputFormatContext input(p);
input.findStreamInfo(); // needed by input.getDurationSecs
if (!input.findStreamInfo())
return false;
std::map<std::string, std::string> metadata;
input.getMetadata().get(metadata);
@@ -169,17 +169,9 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
{
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, string_trim( string_to_utf8(it->second)) ));
}
/* else
LMS_LOG(MOD_METADATA, SEV_DEBUG) << "key = " << it->first << ", value = " << it->second;
*/
}
}
catch(std::exception &e)
{
LMS_LOG(MOD_METADATA, SEV_ERROR) << "Parsing of '" << p << "' failed!";
}
return true;
}
} // namespace MetaData
+1 -1
View File
@@ -30,7 +30,7 @@ class AvFormat : public Parser
{
public:
void parse(const boost::filesystem::path& p, Items& items);
bool parse(const boost::filesystem::path& p, Items& items);
private:
+1 -1
View File
@@ -71,7 +71,7 @@ namespace MetaData
typedef std::shared_ptr<Parser> pointer;
virtual void parse(const boost::filesystem::path& p, Items& items) = 0;
virtual bool parse(const boost::filesystem::path& p, Items& items) = 0;
};
+6 -5
View File
@@ -19,7 +19,6 @@
#include <list>
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
@@ -47,7 +46,9 @@ InputMediaFile::InputMediaFile(const boost::filesystem::path& p)
: _path(p)
{
Av::InputFormatContext input(_path);
input.findStreamInfo();
if (!input.findStreamInfo())
throw std::runtime_error("Cannot find stream info in file: " + p.string());
// Calculate estimated duration
if (input.getDurationSecs())
@@ -83,7 +84,7 @@ InputMediaFile::InputMediaFile(const boost::filesystem::path& p)
avMediaTypes.unique();
// Scan for best streams
BOOST_FOREACH(enum AVMediaType type, avMediaTypes)
for (enum AVMediaType type : avMediaTypes)
{
Av::Stream::Idx index;
@@ -102,7 +103,7 @@ std::vector<Stream>
InputMediaFile::getStreams(Stream::Type type) const
{
std::vector<Stream> res;
BOOST_FOREACH(const Stream& stream, _streams)
for (const Stream& stream : _streams)
{
if (stream.getType() == type)
res.push_back(stream);
@@ -113,7 +114,7 @@ InputMediaFile::getStreams(Stream::Type type) const
const Stream&
InputMediaFile::getStream(Stream::Id index) const
{
BOOST_FOREACH(const Stream& stream, _streams)
for (const Stream& stream : _streams)
{
if (stream.getId() == index)
return stream;