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

IVideoTrack: Store & expose fps as a fraction

parent 0a63c716
......@@ -36,6 +36,8 @@ public:
virtual unsigned int width() const = 0;
virtual unsigned int height() const = 0;
virtual float fps() const = 0;
virtual uint32_t fpsNum() const = 0;
virtual uint32_t fpsDen() const = 0;
virtual const std::string& description() const = 0;
virtual const std::string& language() const = 0;
};
......
......@@ -245,10 +245,12 @@ void Media::setMovie(MoviePtr movie)
m_changed = true;
}
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps,
const std::string& language, const std::string& description )
bool Media::addVideoTrack( const std::string& codec, unsigned int width, unsigned int height,
uint32_t fpsNum, uint32_t fpsDen, const std::string& language,
const std::string& description )
{
return VideoTrack::create( m_ml, codec, width, height, fps, m_id, language, description ) != nullptr;
return VideoTrack::create( m_ml, codec, width, height, fpsNum, fpsDen, m_id,
language, description ) != nullptr;
}
Query<IVideoTrack> Media::videoTracks() const
......
......@@ -98,8 +98,10 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual const std::string& fileName() 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, const std::string& language, const std::string& description );
bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, uint32_t fpsNum,
uint32_t fpsDen, const std::string& language,
const std::string& description );
virtual Query<IVideoTrack> videoTracks() const override;
bool addAudioTrack( const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc );
......
......@@ -40,19 +40,23 @@ VideoTrack::VideoTrack( MediaLibraryPtr, sqlite::Row& row )
>> m_codec
>> m_width
>> m_height
>> m_fps
>> m_fpsNum
>> m_fpsDen
>> m_mediaId
>> m_language
>> m_description;
}
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 )
VideoTrack::VideoTrack(MediaLibraryPtr, const std::string& codec, unsigned int width,
unsigned int height, uint32_t fpsNum, uint32_t fpsDen,
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_fpsNum( fpsNum )
, m_fpsDen( fpsDen )
, m_mediaId( mediaId )
, m_language( language )
, m_description( description )
......@@ -81,7 +85,17 @@ unsigned int VideoTrack::height() const
float VideoTrack::fps() const
{
return m_fps;
return static_cast<float>( m_fpsNum ) / static_cast<float>( m_fpsDen );
}
uint32_t VideoTrack::fpsNum() const
{
return m_fpsNum;
}
uint32_t VideoTrack::fpsDen() const
{
return m_fpsDen;
}
const std::string& VideoTrack::language() const
......@@ -95,13 +109,13 @@ const std::string& VideoTrack::description() const
}
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, uint32_t fpsNum, uint32_t fpsDen, 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, 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 )
+ "(codec, width, height, fps_num, fps_den, media_id, language, description) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
auto track = std::make_shared<VideoTrack>( ml, codec, width, height, fpsNum, fpsDen, mediaId, language, description );
if ( insert( ml, track, req, codec, width, height, fpsNum, fpsDen, mediaId, language, description ) == false )
return nullptr;
return track;
}
......@@ -114,7 +128,8 @@ void VideoTrack::createTable( sqlite::Connection* dbConnection )
"codec TEXT,"
"width UNSIGNED INTEGER,"
"height UNSIGNED INTEGER,"
"fps FLOAT,"
"fps_num UNSIGNED INTEGER,"
"fps_den UNSIGNED INTEGER,"
"media_id UNSIGNED INT,"
"language TEXT,"
"description TEXT,"
......
......@@ -48,28 +48,33 @@ 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,
const std::string& language, const std::string& description );
unsigned int width, unsigned int height, uint32_t fpsNum,
uint32_t fpsDen, 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 uint32_t fpsNum() const override;
virtual uint32_t fpsDen() const override;
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static void createTable( sqlite::Connection* dbConnection );
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 );
unsigned int width, unsigned int height, uint32_t fpsNum,
uint32_t fpsDen, int64_t mediaId, const std::string& language,
const std::string& description );
private:
int64_t m_id;
std::string m_codec;
unsigned int m_width;
unsigned int m_height;
float m_fps;
uint32_t m_fpsNum;
uint32_t m_fpsDen;
int64_t m_mediaId;
std::string m_language;
std::string m_description;
......
......@@ -189,8 +189,7 @@ Status MetadataAnalyzer::run( IItem& item )
if ( track.type == IItem::Track::Type::Video )
{
media->addVideoTrack( track.codec, track.v.width, track.v.height,
static_cast<float>( track.v.fpsNum ) /
static_cast<float>( track.v.fpsDen ),
track.v.fpsNum, track.v.fpsDen,
track.language, track.description );
isAudio = false;
}
......
......@@ -36,15 +36,15 @@ class VideoTracks : public Tests
TEST_F( VideoTracks, AddTrack )
{
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.avi" ) );
bool res = f->addVideoTrack( "H264", 1920, 1080, 29.97, "language", "description" );
bool res = f->addVideoTrack( "H264", 1920, 1080, 3000, 1001, "language", "description" );
ASSERT_TRUE( res );
}
TEST_F( VideoTracks, FetchTracks )
{
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.avi" ) );
f->addVideoTrack( "H264", 1920, 1080, 29.97, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 29.97, "l2", "d2" );
f->addVideoTrack( "H264", 1920, 1080, 3000, 100, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 3000, 100, "l2", "d2" );
// Testing fetch from initially created instance:
auto ts = f->videoTracks()->all();
......@@ -53,7 +53,9 @@ TEST_F( VideoTracks, FetchTracks )
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920u );
ASSERT_EQ( t2->height(), 1080u );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->fps(), 30.0f );
ASSERT_EQ( t2->fpsNum(), 3000u );
ASSERT_EQ( t2->fpsDen(), 100u );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
......@@ -68,7 +70,9 @@ TEST_F( VideoTracks, FetchTracks )
ASSERT_EQ( t2->codec(), "H264" );
ASSERT_EQ( t2->width(), 1920u );
ASSERT_EQ( t2->height(), 1080u );
ASSERT_EQ( t2->fps(), 29.97f );
ASSERT_EQ( t2->fps(), 30.0f );
ASSERT_EQ( t2->fpsNum(), 3000u );
ASSERT_EQ( t2->fpsDen(), 100u );
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