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

File: Store the duration as an int64

parent 3a7129c0
......@@ -28,8 +28,11 @@ class IFile
virtual bool setName( const std::string& name ) = 0;
virtual AlbumTrackPtr albumTrack() = 0;
virtual bool setAlbumTrack(AlbumTrackPtr albumTrack ) = 0;
virtual unsigned int duration() const = 0;
virtual bool setDuration( unsigned int duration) = 0;
/**
* @brief duration Returns the file duration in ms
*/
virtual int64_t duration() const = 0;
virtual bool setDuration( int64_t duration ) = 0;
virtual std::shared_ptr<IShowEpisode> showEpisode() = 0;
virtual bool setShowEpisode( ShowEpisodePtr showEpisode ) = 0;
virtual int playCount() const = 0;
......
......@@ -25,7 +25,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
{
m_id = sqlite3_column_int( stmt, 0 );
m_type = (Type)sqlite3_column_int( stmt, 1 );
m_duration = sqlite3_column_int( stmt, 2 );
m_duration = sqlite::Traits<int64_t>::Load( stmt, 2 );
m_albumTrackId = sqlite3_column_int( stmt, 3 );
m_playCount = sqlite3_column_int( stmt, 4 );
m_showEpisodeId = sqlite3_column_int( stmt, 5 );
......@@ -41,7 +41,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
File::File( const fs::IFile* file, unsigned int folderId, const std::string& name, Type type )
: m_id( 0 )
, m_type( type )
, m_duration( 0 )
, m_duration( -1 )
, m_albumTrackId( 0 )
, m_playCount( 0 )
, m_showEpisodeId( 0 )
......@@ -88,12 +88,12 @@ bool File::setAlbumTrack( AlbumTrackPtr albumTrack )
return true;
}
unsigned int File::duration() const
int64_t File::duration() const
{
return m_duration;
}
bool File::setDuration( unsigned int duration )
bool File::setDuration( int64_t duration )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET duration = ? "
"WHERE id_file = ?";
......@@ -290,7 +290,7 @@ bool File::createTable( DBConnection connection )
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER,"
"duration UNSIGNED INTEGER,"
"duration INTEGER,"
"album_track_id UNSIGNED INTEGER,"
"play_count UNSIGNED INTEGER,"
"show_episode_id UNSIGNED INTEGER,"
......
......@@ -52,8 +52,8 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual bool setName( const std::string& name ) override;
virtual AlbumTrackPtr albumTrack();
virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual unsigned int duration() const;
virtual bool setDuration( unsigned int duration) override;
virtual int64_t duration() const;
virtual bool setDuration( int64_t duration) override;
virtual std::shared_ptr<IShowEpisode> showEpisode();
virtual bool setShowEpisode( ShowEpisodePtr showEpisode );
virtual bool addLabel( LabelPtr label );
......@@ -83,7 +83,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
// DB fields:
unsigned int m_id;
Type m_type;
unsigned int m_duration;
int64_t m_duration;
unsigned int m_albumTrackId;
unsigned int m_playCount;
unsigned int m_showEpisodeId;
......
......@@ -80,15 +80,18 @@ TEST_F( Files, LastModificationDate )
TEST_F( Files, Duration )
{
auto f = ml->addFile( "media.avi", nullptr );
ASSERT_EQ( f->duration(), 0u );
ASSERT_EQ( f->duration(), -1 );
f->setDuration( 123u );
ASSERT_EQ( f->duration(), 123u );
// Use a value that checks we're using a 64bits value
int64_t d = int64_t(1) << 40;
f->setDuration( d );
ASSERT_EQ( f->duration(), d );
Reload();
f = ml->file( "media.avi" );
ASSERT_EQ( f->duration(), 123u );
ASSERT_EQ( f->duration(), d );
}
TEST_F( Files, Snapshot )
......
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