Improve subtitle format names and media types

This commit is contained in:
Martchus 2016-07-11 20:58:12 +02:00
parent 80f65f3cc1
commit 58411bc8c5
5 changed files with 73 additions and 52 deletions

View File

@ -85,27 +85,6 @@ AbstractTrack::AbstractTrack(std::iostream &stream, uint64 startOffset) :
AbstractTrack::~AbstractTrack()
{}
/*!
* \brief Returns the media type as string.
*/
const char *AbstractTrack::mediaTypeName() const
{
switch(m_mediaType) {
case MediaType::Audio:
return "Audio";
case MediaType::Video:
return "Video";
case MediaType::Text:
return "Subititle";
case MediaType::Hint:
return "Hint";
case MediaType::Unknown:
return "Other";
default:
return "";
}
}
/*!
* \brief Returns a string with the channel configuration if available; otherwise returns nullptr.
*/

View File

@ -18,8 +18,6 @@
namespace Media {
enum class MediaType;
enum class GeneralMediaFormat;
class MpegAudioFrameStream;
class WaveAudioStream;
class Mp4Track;
@ -295,6 +293,14 @@ inline MediaType AbstractTrack::mediaType() const
return m_mediaType;
}
/*!
* \brief Returns the string representation of the media type of the track.
*/
inline const char *AbstractTrack::mediaTypeName() const
{
return ::Media::mediaTypeName(m_mediaType);
}
/*!
* \brief Returns the size in bytes if known; otherwise returns 0.
*/

View File

@ -170,13 +170,15 @@ MediaFormat MatroskaTrack::codecIdToMediaFormat(const string &codecId)
} else if(part1 == "S_TEXT") {
fmt.general = GeneralMediaFormat::TextSubtitle;
if(part2 == "UTF8") {
fmt.sub = SubFormats::TextSubBasicUtf8;
fmt.sub = SubFormats::PlainUtf8Subtitle;
} else if(part2 == "SSA") {
fmt.sub = SubFormats::TextSubSubtitlesFormat;
fmt.sub = SubFormats::SubStationAlpha;
} else if(part2 == "ASS") {
fmt.sub = SubFormats::TextSubAdvancedSubtitlesFormat;
fmt.sub = SubFormats::AdvancedSubStationAlpha;
} else if(part2 == "USF") {
fmt.sub = SubFormats::TextSubUniversalSubtitleFormat;
fmt.sub = SubFormats::UniversalSubtitleFormat;
} else if(part2 == "WEBVTT") {
fmt.sub = SubFormats::WebVideoTextTracksFormat;
}
} else if(part1 == "S_IMAGE") {
fmt.general = GeneralMediaFormat::ImageSubtitle;
@ -200,7 +202,7 @@ void MatroskaTrack::internalParseHeader()
static const string context("parsing header of Matroska track");
try {
m_trackElement->parse();
} catch(Failure &) {
} catch(const Failure &) {
addNotification(NotificationType::Critical, "Unable to parse track element.", context);
throw;
}
@ -208,7 +210,7 @@ void MatroskaTrack::internalParseHeader()
for(EbmlElement *trackInfoElement = m_trackElement->firstChild(), *subElement = nullptr; trackInfoElement; trackInfoElement = trackInfoElement->nextSibling()) {
try {
trackInfoElement->parse();
} catch (Failure &) {
} catch(const Failure &) {
addNotification(NotificationType::Critical, "Unable to parse track information element.", context);
break;
}
@ -225,16 +227,21 @@ void MatroskaTrack::internalParseHeader()
case MatroskaTrackType::Subtitle:
m_mediaType = MediaType::Text;
break;
case MatroskaTrackType::Buttons:
m_mediaType = MediaType::Buttons;
break;
case MatroskaTrackType::Control:
m_mediaType = MediaType::Control;
break;
default:
m_mediaType = MediaType::Unknown;
}
break;
case MatroskaIds::TrackVideo:
subElement = trackInfoElement->firstChild();
while(subElement) {
for(subElement = trackInfoElement->firstChild(); subElement; subElement = subElement->nextSibling()) {
try {
subElement->parse();
} catch (Failure &) {
} catch(const Failure &) {
addNotification(NotificationType::Critical, "Unable to parse video track element.", context);
break;
}
@ -275,15 +282,13 @@ void MatroskaTrack::internalParseHeader()
default:
;
}
subElement = subElement->nextSibling();
}
break;
case MatroskaIds::TrackAudio:
subElement = trackInfoElement->firstChild();
while(subElement) {
for(subElement = trackInfoElement->firstChild(); subElement; subElement = subElement->nextSibling()) {
try {
subElement->parse();
} catch (Failure &) {
} catch(const Failure &) {
addNotification(NotificationType::Critical, "Unable to parse audio track element.", context);
break;
}
@ -307,7 +312,6 @@ void MatroskaTrack::internalParseHeader()
default:
;
}
subElement = subElement->nextSibling();
}
break;
case MatroskaIds::TrackNumber:
@ -350,7 +354,7 @@ void MatroskaTrack::internalParseHeader()
}
switch(m_mediaType) {
case MediaType::Video:
if(m_fps == 0 && defaultDuration != 0) {
if(!m_fps && defaultDuration) {
m_fps = 1000000000.0 / static_cast<double>(defaultDuration);
}
break;

View File

@ -215,10 +215,11 @@ const char *MediaFormat::name() const
}
case GeneralMediaFormat::TextSubtitle:
switch(sub) {
case SubFormats::TextSubBasicUtf8: return "UTF-8 Plain Text subtitles";
case SubFormats::TextSubSubtitlesFormat: return "Subtitles Format";
case SubFormats::TextSubAdvancedSubtitlesFormat: return "Advanced Subtitles Format";
case SubFormats::TextSubUniversalSubtitleFormat: return "Universal Subtitle Format";
case SubFormats::PlainUtf8Subtitle: return "plain UTF-8 subtitle";
case SubFormats::SubStationAlpha: return "SubStation Alpha";
case SubFormats::AdvancedSubStationAlpha: return "Advanced SubStation Alpha";
case SubFormats::UniversalSubtitleFormat: return "Universal Subtitle Format";
case SubFormats::WebVideoTextTracksFormat: return "Web Video Text Tracks Format";
default: return "Text subtitle";
}
case GeneralMediaFormat::Theora: return "Theora";
@ -388,11 +389,12 @@ const char *MediaFormat::abbreviation() const
}
case GeneralMediaFormat::TextSubtitle:
switch(sub) {
case SubFormats::TextSubBasicUtf8: return "UTF-8 Sub";
case SubFormats::TextSubSubtitlesFormat: return "SSA";
case SubFormats::TextSubAdvancedSubtitlesFormat: return "ASS";
case SubFormats::TextSubUniversalSubtitleFormat: return "USF";
default: return "Text subtitle";
case SubFormats::PlainUtf8Subtitle: return "";
case SubFormats::SubStationAlpha: return "SSA";
case SubFormats::AdvancedSubStationAlpha: return "ASS";
case SubFormats::UniversalSubtitleFormat: return "USF";
case SubFormats::WebVideoTextTracksFormat: return "WebVTT";
default: return "";
}
case GeneralMediaFormat::Theora: return "Theora";
case GeneralMediaFormat::Tiff: return "TIFF";
@ -426,7 +428,7 @@ const char *MediaFormat::extensionName() const
case SpectralBandReplication:
return "Spectral Band Replication / HE-AAC";
case ParametricStereo:
return "Parametric Stereo / HE-AAC v2"; // PS never comes alone?
return "Parametric Stereo / HE-AAC v2"; // PS always implies SBR?
case (SpectralBandReplication | ParametricStereo):
return "Spectral Band Replication and Parametric Stereo / HE-AAC v2";
default:
@ -439,4 +441,29 @@ const char *MediaFormat::extensionName() const
return "";
}
/*!
* \brief Returns the string representation for the specified \a mediaType.
*/
const char *mediaTypeName(MediaType mediaType)
{
switch(mediaType) {
case MediaType::Audio:
return "Audio";
case MediaType::Video:
return "Video";
case MediaType::Text:
return "Subititle";
case MediaType::Hint:
return "Hint";
case MediaType::Buttons:
return "Buttons";
case MediaType::Control:
return "Control";
case MediaType::Unknown:
return "Other";
default:
return "";
}
}
}

View File

@ -16,9 +16,13 @@ enum class MediaType
Audio, /**< audio/sound */
Video, /**< video */
Text, /**< text/subtitle */
Buttons, /**< buttons */
Control, /**< control */
Hint /**< hint */
};
extern const char *LIB_EXPORT mediaTypeName(MediaType mediaType);
/*!
* \brief The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...).
*/
@ -226,10 +230,11 @@ enum PcmVersion : unsigned char {
};
enum TextSubtitle : unsigned char {
TextSubBasicUtf8 = 1,
TextSubSubtitlesFormat,
TextSubAdvancedSubtitlesFormat,
TextSubUniversalSubtitleFormat
PlainUtf8Subtitle = 1,
SubStationAlpha,
AdvancedSubStationAlpha,
UniversalSubtitleFormat,
WebVideoTextTracksFormat
};
enum ImageSubtitle : unsigned char {