Commit 310e2fd3 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

AudioTrack: Expose language & description

This fixes a contraint violation exception when trying to handle
multiple tracks, with the language as their only differences.
parent 8b19e109
......@@ -37,6 +37,8 @@ class IAudioTrack
virtual unsigned int bitrate() const = 0;
virtual unsigned int sampleRate() const = 0;
virtual unsigned int nbChannels() const = 0;
virtual const std::string& language() const = 0;
virtual const std::string& description() const = 0;
};
#endif // IAUDIOTRACK_H
......@@ -33,15 +33,20 @@ AudioTrack::AudioTrack( DBConnection dbConnection, sqlite::Row& row )
>> m_codec
>> m_bitrate
>> m_sampleRate
>> m_nbChannels;
>> m_nbChannels
>> m_language
>> m_description;
}
AudioTrack::AudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels )
AudioTrack::AudioTrack( const std::string& codec, unsigned int bitrate , unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc )
: m_id( 0 )
, m_codec( codec )
, m_bitrate( bitrate )
, m_sampleRate( sampleRate )
, m_nbChannels( nbChannels )
, m_language( language )
, m_description( desc )
{
}
......@@ -70,6 +75,16 @@ unsigned int AudioTrack::nbChannels() const
return m_nbChannels;
}
const std::string& AudioTrack::language() const
{
return m_language;
}
const std::string& AudioTrack::description() const
{
return m_description;
}
bool AudioTrack::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
......@@ -79,26 +94,31 @@ bool AudioTrack::createTable( DBConnection dbConnection )
"bitrate UNSIGNED INTEGER,"
"samplerate UNSIGNED INTEGER,"
"nb_channels UNSIGNED INTEGER,"
"UNIQUE ( codec, bitrate, samplerate, nb_channels ) ON CONFLICT FAIL"
"language TEXT,"
"description TEXT,"
"UNIQUE ( codec, bitrate, samplerate, nb_channels, language, description ) ON CONFLICT FAIL"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
}
std::shared_ptr<AudioTrack> AudioTrack::fetch(DBConnection dbConnection, const std::string& codec,
unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels )
unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc )
{
static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name
+ " WHERE codec = ? AND bitrate = ? AND samplerate = ? AND nb_channels = ?";
return AudioTrack::fetchOne( dbConnection, req, codec, bitrate, sampleRate, nbChannels );
+ " WHERE codec = ? AND bitrate = ? AND samplerate = ? AND nb_channels = ?"
" AND language = ? AND description = ?";
return AudioTrack::fetchOne( dbConnection, req, codec, bitrate, sampleRate, nbChannels, language, desc );
}
std::shared_ptr<AudioTrack> AudioTrack::create( DBConnection dbConnection, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels )
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc )
{
static const std::string req = "INSERT INTO " + policy::AudioTrackTable::Name
+ "(codec, bitrate, samplerate, nb_channels) VALUES(?, ?, ?, ?)";
auto track = std::make_shared<AudioTrack>( codec, bitrate, sampleRate, nbChannels );
if ( _Cache::insert( dbConnection, track, req, codec, bitrate, sampleRate, nbChannels ) == false )
+ "(codec, bitrate, samplerate, nb_channels, language, description) VALUES(?, ?, ?, ?, ?, ?)";
auto track = std::make_shared<AudioTrack>( codec, bitrate, sampleRate, nbChannels, language, desc );
if ( _Cache::insert( dbConnection, track, req, codec, bitrate, sampleRate, nbChannels, language, desc ) == false )
return nullptr;
track->m_dbConnection = dbConnection;
return track;
......
......@@ -43,18 +43,23 @@ class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, pol
{
public:
AudioTrack( DBConnection dbConnection, sqlite::Row& row );
AudioTrack( const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels );
AudioTrack( const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels, const std::string& language, const std::string& desc );
virtual unsigned int id() const override;
virtual const std::string&codec() const override;
virtual unsigned int bitrate() const override;
virtual unsigned int sampleRate() const override;
virtual unsigned int nbChannels() const override;
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AudioTrack> fetch( DBConnection dbConnection, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels );
static std::shared_ptr<AudioTrack> create(DBConnection dbConnection, const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc );
static std::shared_ptr<AudioTrack> create( DBConnection dbConnection, const std::string& codec,
unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc );
private:
DBConnection m_dbConnection;
......@@ -63,6 +68,8 @@ class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, pol
unsigned int m_bitrate;
unsigned int m_sampleRate;
unsigned int m_nbChannels;
std::string m_language;
std::string m_description;
private:
......
......@@ -219,14 +219,15 @@ std::vector<VideoTrackPtr> Media::videoTracks()
}
bool Media::addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels )
unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc )
{
static const std::string req = "INSERT INTO AudioTrackFileRelation VALUES(?, ?)";
auto track = AudioTrack::fetch( m_dbConnection, codec, bitrate, sampleRate, nbChannels );
auto track = AudioTrack::fetch( m_dbConnection, codec, bitrate, sampleRate, nbChannels, language, desc );
if ( track == nullptr )
{
track = AudioTrack::create( m_dbConnection, codec, bitrate, sampleRate, nbChannels );
track = AudioTrack::create( m_dbConnection, codec, bitrate, sampleRate, nbChannels, language, desc );
if ( track == nullptr )
return false;
}
......
......@@ -96,7 +96,8 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps );
virtual std::vector<VideoTrackPtr> videoTracks() override;
bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
bool addAudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc );
virtual std::vector<AudioTrackPtr> audioTracks() override;
virtual const std::string& snapshot() override;
bool setSnapshot( const std::string& snapshot );
......
......@@ -103,8 +103,8 @@ IMetadataService::Status VLCMetadataService::handleMediaMeta( std::shared_ptr<Me
}
else if ( track.type() == VLC::MediaTrack::Audio )
{
media->addAudioTrack( fcc, track.bitrate(), track.rate(),
track.channels() );
media->addAudioTrack( fcc, track.bitrate(), track.rate(), track.channels(),
track.language(), track.description() );
}
}
if ( isAudio == true )
......
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