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

VideoTrack: Add bitrate

parent d3797787
......@@ -38,6 +38,7 @@ public:
virtual float fps() const = 0;
virtual uint32_t fpsNum() const = 0;
virtual uint32_t fpsDen() const = 0;
virtual uint32_t bitrate() const = 0;
virtual const std::string& description() const = 0;
virtual const std::string& language() const = 0;
};
......
......@@ -246,11 +246,11 @@ void Media::setMovie(MoviePtr movie)
}
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 )
uint32_t fpsNum, uint32_t fpsDen, uint32_t bitrate,
const std::string& language, const std::string& description )
{
return VideoTrack::create( m_ml, codec, width, height, fpsNum, fpsDen, m_id,
language, description ) != nullptr;
return VideoTrack::create( m_ml, codec, width, height, fpsNum, fpsDen,
bitrate, m_id, language, description ) != nullptr;
}
Query<IVideoTrack> Media::videoTracks() const
......
......@@ -100,7 +100,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
void setMovie( MoviePtr movie );
bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, uint32_t fpsNum,
uint32_t fpsDen, const std::string& language,
uint32_t fpsDen, uint32_t bitrate, 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,
......
......@@ -42,6 +42,7 @@ VideoTrack::VideoTrack( MediaLibraryPtr, sqlite::Row& row )
>> m_height
>> m_fpsNum
>> m_fpsDen
>> m_bitrate
>> m_mediaId
>> m_language
>> m_description;
......@@ -49,7 +50,7 @@ VideoTrack::VideoTrack( MediaLibraryPtr, sqlite::Row& row )
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,
uint32_t bitrate, int64_t mediaId, const std::string& language,
const std::string& description )
: m_id( 0 )
, m_codec( codec )
......@@ -57,6 +58,7 @@ VideoTrack::VideoTrack(MediaLibraryPtr, const std::string& codec, unsigned int w
, m_height( height )
, m_fpsNum( fpsNum )
, m_fpsDen( fpsDen )
, m_bitrate( bitrate )
, m_mediaId( mediaId )
, m_language( language )
, m_description( description )
......@@ -98,6 +100,11 @@ uint32_t VideoTrack::fpsDen() const
return m_fpsDen;
}
uint32_t VideoTrack::bitrate() const
{
return m_bitrate;
}
const std::string& VideoTrack::language() const
{
return m_language;
......@@ -109,13 +116,17 @@ const std::string& VideoTrack::description() const
}
std::shared_ptr<VideoTrack> VideoTrack::create( MediaLibraryPtr ml, const std::string& codec, unsigned int width,
unsigned int height, uint32_t fpsNum, uint32_t fpsDen, int64_t mediaId,
unsigned int height, uint32_t fpsNum, uint32_t fpsDen,
uint32_t bitrate, 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_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 )
+ "(codec, width, height, fps_num, fps_den, bitrate, media_id, language,"
" description) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
auto track = std::make_shared<VideoTrack>( ml, codec, width, height, fpsNum,
fpsDen, bitrate, mediaId, language, description );
if ( insert( ml, track, req, codec, width, height, fpsNum, fpsDen, bitrate,
mediaId, language, description ) == false )
return nullptr;
return track;
}
......@@ -130,6 +141,7 @@ void VideoTrack::createTable( sqlite::Connection* dbConnection )
"height UNSIGNED INTEGER,"
"fps_num UNSIGNED INTEGER,"
"fps_den UNSIGNED INTEGER,"
"bitrate UNSIGNED INTEGER,"
"media_id UNSIGNED INT,"
"language TEXT,"
"description TEXT,"
......
......@@ -47,9 +47,9 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
{
public:
VideoTrack( MediaLibraryPtr, sqlite::Row& row );
VideoTrack( MediaLibraryPtr, const std::string& codec,
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,
uint32_t fpsDen, uint32_t bitrate, int64_t mediaId, const std::string& language,
const std::string& description );
virtual int64_t id() const override;
......@@ -59,13 +59,14 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
virtual float fps() const override;
virtual uint32_t fpsNum() const override;
virtual uint32_t fpsDen() const override;
virtual uint32_t bitrate() 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,
static std::shared_ptr<VideoTrack> create(MediaLibraryPtr ml, const std::string& codec,
unsigned int width, unsigned int height, uint32_t fpsNum,
uint32_t fpsDen, int64_t mediaId, const std::string& language,
uint32_t fpsDen, uint32_t bitrate, int64_t mediaId, const std::string& language,
const std::string& description );
private:
......@@ -75,6 +76,7 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
unsigned int m_height;
uint32_t m_fpsNum;
uint32_t m_fpsDen;
uint32_t m_bitrate;
int64_t m_mediaId;
std::string m_language;
std::string m_description;
......
......@@ -189,7 +189,7 @@ Status MetadataAnalyzer::run( IItem& item )
if ( track.type == IItem::Track::Type::Video )
{
media->addVideoTrack( track.codec, track.v.width, track.v.height,
track.v.fpsNum, track.v.fpsDen,
track.v.fpsNum, track.v.fpsDen, track.bitrate,
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, 3000, 1001, "language", "description" );
bool res = f->addVideoTrack( "H264", 1920, 1080, 3000, 1001, 1234, "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, 3000, 100, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 3000, 100, "l2", "d2" );
f->addVideoTrack( "H264", 1920, 1080, 3000, 100, 5678, "l1", "d1" );
f->addVideoTrack( "VP80", 640, 480, 3000, 100, 9876, "l2", "d2" );
// Testing fetch from initially created instance:
auto ts = f->videoTracks()->all();
......@@ -56,6 +56,7 @@ TEST_F( VideoTracks, FetchTracks )
ASSERT_EQ( t2->fps(), 30.0f );
ASSERT_EQ( t2->fpsNum(), 3000u );
ASSERT_EQ( t2->fpsDen(), 100u );
ASSERT_EQ( t2->bitrate(), 5678u );
ASSERT_EQ( t2->language(), "l1" );
ASSERT_EQ( t2->description(), "d1" );
......@@ -73,6 +74,7 @@ TEST_F( VideoTracks, FetchTracks )
ASSERT_EQ( t2->fps(), 30.0f );
ASSERT_EQ( t2->fpsNum(), 3000u );
ASSERT_EQ( t2->fpsDen(), 100u );
ASSERT_EQ( t2->bitrate(), 5678u );
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