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

parser: Store the tracks in the track item

parent 92be3f0c
......@@ -173,7 +173,7 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
return parser::Task::Status::Success;
}
const auto& tracks = task.vlcMedia.tracks();
const auto& tracks = task.item().tracks();
if ( tracks.empty() == true )
return parser::Task::Status::Fatal;
......@@ -185,19 +185,20 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
auto t = m_ml->getConn()->newTransaction();
for ( const auto& track : tracks )
{
auto codec = track.codec();
std::string fcc( reinterpret_cast<const char*>( &codec ), 4 );
if ( track.type() == VLC::MediaTrack::Type::Video )
if ( track.type == parser::Task::Item::Track::Type::Video )
{
task.media->addVideoTrack( fcc, track.width(), track.height(),
static_cast<float>( track.fpsNum() ) / static_cast<float>( track.fpsDen() ),
track.language(), track.description() );
task.media->addVideoTrack( track.codec, track.v.width, track.v.height,
static_cast<float>( track.v.fpsNum ) /
static_cast<float>( track.v.fpsDen ),
track.language, track.description );
isAudio = false;
}
else if ( track.type() == VLC::MediaTrack::Type::Audio )
else
{
task.media->addAudioTrack( fcc, track.bitrate(), track.rate(), track.channels(),
track.language(), track.description() );
assert( track.type == parser::Task::Item::Track::Type::Audio );
task.media->addAudioTrack( track.codec, track.bitrate,
track.a.rate, track.a.nbChannels,
track.language, track.description );
}
}
task.media->setDuration( task.item().duration() );
......
......@@ -150,6 +150,40 @@ void VLCMetadataService::mediaToItem( VLC::Media& media, parser::Task::Item& ite
media.meta( libvlc_meta_DiscTotal ) );
item.setDuration( media.duration() );
auto tracks = media.tracks();
for ( const auto& track : tracks )
{
parser::Task::Item::Track t;
if ( track.type() == VLC::MediaTrack::Type::Audio )
{
t.type = parser::Task::Item::Track::Type::Audio;
t.a.nbChannels = track.channels();
t.a.rate = track.rate();
}
else if ( track.type() == VLC::MediaTrack::Type::Video )
{
t.type = parser::Task::Item::Track::Type::Video;
t.v.fpsNum = track.fpsNum();
t.v.fpsDen = track.fpsDen();
t.v.width = track.width();
t.v.height = track.height();
t.v.sarNum = track.sarNum();
t.v.sarDen = track.sarDen();
}
else
continue;
auto codec = track.codec();
std::string fcc( reinterpret_cast<const char*>( &codec ), 4 );
t.codec = std::move( fcc );
t.bitrate = track.bitrate();
t.language = track.language();
t.description = track.description();
item.addTrack( std::move( t ) );
}
auto subItems = media.subitems();
if ( subItems != nullptr )
{
......
......@@ -180,6 +180,16 @@ void Task::Item::setDuration( int64_t duration )
m_duration = duration;
}
const std::vector<Task::Item::Track>& Task::Item::tracks() const
{
return m_tracks;
}
void Task::Item::addTrack(Task::Item::Track t)
{
m_tracks.emplace_back( std::move( t ) );
}
bool Task::restoreLinkedEntities()
{
LOG_INFO("Restoring linked entities of task ", m_id);
......
......@@ -109,6 +109,41 @@ public:
DiscNumber,
DiscTotal,
};
struct Track
{
enum class Type : uint8_t
{
Video,
Audio,
};
std::string codec;
Type type;
uint32_t bitrate;
std::string language;
std::string description;
// Audio
union
{
struct
{
uint32_t nbChannels;
uint32_t rate;
} a;
struct
{
// Video
uint32_t height;
uint32_t width;
uint32_t sarNum;
uint32_t sarDen;
uint32_t fpsNum;
uint32_t fpsDen;
} v;
};
};
std::string meta( Metadata type ) const;
void setMeta( Metadata type, std::string value );
......@@ -120,10 +155,14 @@ public:
int64_t duration() const;
void setDuration( int64_t duration );
const std::vector<Track>& tracks() const;
void addTrack( Track t );
private:
std::string m_mrl;
std::unordered_map<Metadata, std::string> m_metadata;
std::vector<Item> m_subItems;
std::vector<Track> m_tracks;
int64_t m_duration;
};
......
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