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

IVideoTrack: Add missing language() & description() methods

parent 8cd806fd
......@@ -37,6 +37,8 @@ class IVideoTrack
virtual unsigned int width() const = 0;
virtual unsigned int height() const = 0;
virtual float fps() const = 0;
virtual const std::string& description() const = 0;
virtual const std::string& language() const = 0;
};
}
......
......@@ -260,9 +260,10 @@ void Media::setMovie(MoviePtr movie)
m_changed = true;
}
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps)
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps,
const std::string& language, const std::string& description )
{
return VideoTrack::create( m_ml, codec, width, height, fps, m_id ) != nullptr;
return VideoTrack::create( m_ml, codec, width, height, fps, m_id, language, description ) != nullptr;
}
std::vector<VideoTrackPtr> Media::videoTracks()
......
......@@ -91,8 +91,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual const std::vector<FilePtr>& files() const override;
virtual MoviePtr movie() const override;
void setMovie( MoviePtr movie );
bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps );
bool addVideoTrack( const std::string& codec, unsigned int width, unsigned int height,
float fps, const std::string& language, const std::string& description );
virtual std::vector<VideoTrackPtr> videoTracks() override;
bool addAudioTrack( const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc );
......
......@@ -37,16 +37,21 @@ VideoTrack::VideoTrack( MediaLibraryPtr, sqlite::Row& row )
>> m_width
>> m_height
>> m_fps
>> m_mediaId;
>> m_mediaId
>> m_language
>> m_description;
}
VideoTrack::VideoTrack( MediaLibraryPtr, const std::string& codec, unsigned int width, unsigned int height, float fps, int64_t mediaId )
VideoTrack::VideoTrack( MediaLibraryPtr, const std::string& codec, unsigned int width, unsigned int height,
float fps, int64_t mediaId, const std::string& language, const std::string& description )
: m_id( 0 )
, m_codec( codec )
, m_width( width )
, m_height( height )
, m_fps( fps )
, m_mediaId( mediaId )
, m_language( language )
, m_description( description )
{
}
......@@ -75,13 +80,24 @@ float VideoTrack::fps() const
return m_fps;
}
const std::string& VideoTrack::language() const
{
return m_language;
}
const std::string& VideoTrack::description() const
{
return m_description;
}
std::shared_ptr<VideoTrack> VideoTrack::create( MediaLibraryPtr ml, const std::string &codec, unsigned int width,
unsigned int height, float fps, int64_t mediaId )
unsigned int height, float fps, int64_t mediaId,
const std::string& language, const std::string& description )
{
static const std::string req = "INSERT INTO " + policy::VideoTrackTable::Name
+ "(codec, width, height, fps, media_id) VALUES(?, ?, ?, ?, ?)";
auto track = std::make_shared<VideoTrack>( ml, codec, width, height, fps, mediaId );
if ( insert( ml, track, req, codec, width, height, fps, mediaId ) == false )
+ "(codec, width, height, fps, media_id, language, description) VALUES(?, ?, ?, ?, ?, ?, ?)";
auto track = std::make_shared<VideoTrack>( ml, codec, width, height, fps, mediaId, language, description );
if ( insert( ml, track, req, codec, width, height, fps, mediaId, language, description ) == false )
return nullptr;
return track;
}
......@@ -96,6 +112,8 @@ bool VideoTrack::createTable( DBConnection dbConnection )
"height UNSIGNED INTEGER,"
"fps FLOAT,"
"media_id UNSIGNED INT,"
"language TEXT,"
"description TEXT,"
"FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name +
"(id_media) ON DELETE CASCADE"
")";
......
......@@ -48,17 +48,21 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
public:
VideoTrack( MediaLibraryPtr, sqlite::Row& row );
VideoTrack( MediaLibraryPtr, const std::string& codec,
unsigned int width, unsigned int height, float fps, int64_t mediaId );
unsigned int width, unsigned int height, float fps, int64_t mediaId,
const std::string& language, const std::string& description );
virtual int64_t id() const override;
virtual const std::string& codec() const override;
virtual unsigned int width() const override;
virtual unsigned int height() const override;
virtual float fps() 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<VideoTrack> create(MediaLibraryPtr ml, const std::string& codec,
unsigned int width, unsigned int height, float fps, int64_t mediaId );
static std::shared_ptr<VideoTrack> create( MediaLibraryPtr ml, const std::string& codec,
unsigned int width, unsigned int height, float fps, int64_t mediaId,
const std::string& language, const std::string& description );
private:
int64_t m_id;
......@@ -67,6 +71,8 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
unsigned int m_height;
float m_fps;
int64_t m_mediaId;
std::string m_language;
std::string m_description;
private:
friend struct policy::VideoTrackTable;
......
......@@ -52,7 +52,7 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
bool isAudio = task.videoTracks.empty();
for ( const auto& t : task.videoTracks )
{
media->addVideoTrack( t.fcc, t.width, t.height, t.fps );
media->addVideoTrack( t.fcc, t.width, t.height, t.fps, t.language, t.description );
}
for ( const auto& t : task.audioTracks )
{
......
......@@ -84,7 +84,8 @@ parser::Task::Status VLCMetadataService::run( parser::Task& task )
if ( track.type() == VLC::MediaTrack::Video )
{
auto fps = static_cast<float>( track.fpsNum() ) / static_cast<float>( track.fpsDen() );
task.videoTracks.emplace_back( fcc, fps, track.width(), track.height() );
task.videoTracks.emplace_back( fcc, fps, track.width(), track.height(), track.language(),
track.description() );
}
else if ( track.type() == VLC::MediaTrack::Audio )
{
......
......@@ -68,8 +68,10 @@ struct Task
struct VideoTrackInfo
{
VideoTrackInfo( const std::string& fcc, float fps, unsigned int width, unsigned int height )
VideoTrackInfo( const std::string& fcc, float fps, unsigned int width, unsigned int height,
const std::string& language, const std::string& description )
: fcc( fcc ), fps( fps ), width( width ), height( height )
, language( language ), description( description )
{
}
......@@ -77,6 +79,8 @@ struct Task
float fps;
unsigned int width;
unsigned int height;
std::string language;
std::string description;
};
struct AudioTrackInfo
......
......@@ -32,17 +32,40 @@ class VideoTracks : public Tests
TEST_F( VideoTracks, AddTrack )
{
auto f = std::static_pointer_cast<Media>( ml->addFile( "file.avi" ) );
bool res = f->addVideoTrack( "H264", 1920, 1080, 29.97 );
bool res = f->addVideoTrack( "H264", 1920, 1080, 29.97, "language", "description" );
ASSERT_TRUE( res );
}
TEST_F( VideoTracks, FetchTracks )
{
auto f = std::static_pointer_cast<Media>( ml->addFile( "file.avi" ) );
f->addVideoTrack( "H264", 1920, 1080, 29.97 );
f->addVideoTrack( "VP80", 640, 480, 29.97 );
f->addVideoTrack( "H264", 1920, 1080, 29.97, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 29.97, "l2", "d2" );
// Testing fetch from initially created instance:
auto ts = f->videoTracks();
ASSERT_EQ( ts.size(), 2u );
auto t2 = ts[0];
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920 );
ASSERT_EQ( t2->height(), 1080 );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
// Reload from DB
Reload();
auto m = ml->media( "file.avi" );
ts = m->videoTracks();
ASSERT_EQ( ts.size(), 2u );
t2 = ts[0];
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920 );
ASSERT_EQ( t2->height(), 1080 );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
}
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