From 5aa5ccb6ebf18cf5788d51871c0b88d451fe6dc0 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 17 Aug 2017 18:47:42 +0200 Subject: [PATCH] Add method to generate short track description --- abstracttrack.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++ abstracttrack.h | 1 + 2 files changed, 53 insertions(+) diff --git a/abstracttrack.cpp b/abstracttrack.cpp index 87f342d..3ce5635 100644 --- a/abstracttrack.cpp +++ b/abstracttrack.cpp @@ -138,6 +138,58 @@ string AbstractTrack::label() const return ss.str(); } +/*! + * \brief Returns a short description about the track. + * + * The description contains the abbreviated format and further information depending on the media + * type (eg. display size in case of video, language in case of audio/text). It is intended to be joined + * with descriptions of other tracks to get a short technical description about the file. + * + * Examples (exact format might change in the future!): + * - H.264-720p + * - HE-AAC-6ch-eng + */ +string AbstractTrack::description() const +{ + // use abbreviated format + const char *format = m_format.shortAbbreviation(); + if(!format || !*format) { + // fall back to media type name if no abbreviation available + format = mediaTypeName(); + } + + // find additional info + const char *additionalInfo = nullptr; + switch(m_mediaType) { + case MediaType::Video: + if(!displaySize().isNull()) { + additionalInfo = displaySize().abbreviation(); + } else if(!pixelSize().isNull()) { + additionalInfo = pixelSize().abbreviation(); + } + break; + case MediaType::Audio: + case MediaType::Text: + if(channelCount()) { + if(!language().empty() && language() != "und") { + return argsToString(format, '-', channelCount(), "ch-", language()); + } else { + return argsToString(format, '-', channelCount(), 'c', 'h'); + } + } else if(!language().empty() && language() != "und") { + additionalInfo = language().data(); + } + break; + default: + ; + } + + if(additionalInfo) { + return argsToString(format, '-', additionalInfo); + } + return format; +} + /*! * \brief Parses technical information about the track from the header. * diff --git a/abstracttrack.h b/abstracttrack.h index 7d8f91b..d074736 100644 --- a/abstracttrack.h +++ b/abstracttrack.h @@ -107,6 +107,7 @@ public: uint32 colorSpace() const; const Margin &cropping() const; std::string label() const; + std::string description() const; void parseHeader(); bool isHeaderValid() const;