From 19593d4c246a563c89b60da1efcd551a6869f21b Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 20 Feb 2016 01:42:01 +0100 Subject: [PATCH] added media format MPEG-4 Timed Text --- mediaformat.cpp | 1 + mediaformat.h | 21 +++++++++++---------- mp4/mp4ids.cpp | 2 ++ mp4/mp4ids.h | 1 + mp4/mp4track.cpp | 25 +++++++++++++++---------- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/mediaformat.cpp b/mediaformat.cpp index 1084bb5..d010c75 100644 --- a/mediaformat.cpp +++ b/mediaformat.cpp @@ -188,6 +188,7 @@ const char *MediaFormat::name() const case Mpeg4FineGranularityScalableProfile5: return "MPEG-4 Fine Granularity Scalable Profile L5"; default: return "MPEG-4 Visual"; } + case GeneralMediaFormat::Mpeg4TimedText: return "MPEG-4 Timed Text"; case GeneralMediaFormat::Mpc: return "Musepack SV8"; case GeneralMediaFormat::Pcm: switch(sub) { diff --git a/mediaformat.h b/mediaformat.h index 1448008..2aae79d 100644 --- a/mediaformat.h +++ b/mediaformat.h @@ -12,11 +12,11 @@ namespace Media { */ enum class MediaType { - Unknown, - Audio, - Video, - Text, - Hint + Unknown, /**< the type is unknown */ + Audio, /**< audio/sound */ + Video, /**< video */ + Text, /**< text/subtitle */ + Hint /**< hint */ }; /*! @@ -24,7 +24,7 @@ enum class MediaType */ enum class GeneralMediaFormat { - Unknown, + Unknown, /**< the format is unknown */ Aac, /**< Advanced Video Coding */ Ac3, /**< Dolby Digital */ Ac4, /**< AC-4 */ @@ -50,16 +50,17 @@ enum class GeneralMediaFormat InteractionStream, /**< Interaction Stream */ Jpeg, /**< JPEG */ OggKate, /**< Karaoke And Text Encapsulation */ - Opus = 64, /**< Opus */ - MicrosoftAudioCodecManager = 26, /**< Microsoft Audio Codec Manager (ACM) */ + Opus, /**< Opus */ + MicrosoftAudioCodecManager, /**< Microsoft Audio Codec Manager (ACM) */ MicrosoftMpeg4, /**< Microsoft MPEG-4 */ MicrosoftVideoCodecManager, /**< Microsoft Video Codec Manager (VCM) */ DolbyMlp, /** < Dolby MLP */ Mpeg1Audio, /**< MPEG-1 Audio */ Mpeg1Video, /**< MPEG-1 Vudio */ Mpeg2Audio, /**< MPEG-2 Audio */ - Mpeg2Video, /**< MPEG-2 Vudio */ - Mpeg4Video, /**< MPEG-4 */ + Mpeg2Video, /**< MPEG-2 Video */ + Mpeg4Video, /**< MPEG-4 Video */ + Mpeg4TimedText, /**< MPEG-4 Timed Text / Streaming text format / Part 17 */ Mpc, /**< Musepack */ Pcm, /**< Pulse Code Modulation */ Png, /**< PNG */ diff --git a/mp4/mp4ids.cpp b/mp4/mp4ids.cpp index 62795e3..b300ba1 100644 --- a/mp4/mp4ids.cpp +++ b/mp4/mp4ids.cpp @@ -51,6 +51,8 @@ MediaFormat fourccToMediaFormat(uint32 fourccId) return GeneralMediaFormat::Mpeg2Video; case Mpeg4Video: return GeneralMediaFormat::Mpeg4Video; + case Mpeg4TimedText: + return GeneralMediaFormat::Mpeg4TimedText; case Hevc1: case Hevc2: return MediaFormat(GeneralMediaFormat::Hevc); case Avc1: case Avc2: case Avc3: case Avc4: case H264Decoder1: case H264Decoder2: diff --git a/mp4/mp4ids.h b/mp4/mp4ids.h index 32436c7..f1ec712 100644 --- a/mp4/mp4ids.h +++ b/mp4/mp4ids.h @@ -318,6 +318,7 @@ enum KnownValue : uint32 { Mpeg4Decoder2 = 0x53454447, Mpeg4Decoder3 = 0x57563146, Mpeg4Sample = 0x6d703473, /**< MPEG-4 stream (other then video/audio) */ + Mpeg4TimedText = 0x74783367, /**< MPEG-4 Timed Text / Streaming text format / Part 17 */ Mpeg4Video = 0x6d703476, /**< MPEG-4 video */ MsMpeg4V1Decoder1 = 0x44495631, MsMpeg4V1Decoder2 = 0x64697631, diff --git a/mp4/mp4track.cpp b/mp4/mp4track.cpp index 8f149c4..47d44f8 100644 --- a/mp4/mp4track.cpp +++ b/mp4/mp4track.cpp @@ -1265,23 +1265,28 @@ void Mp4Track::internalParseHeader() buff[2] = ((rawLanguage & 0x001F) >> 0x0) + 0x60; m_language = string(buff, 3); // read hdlr atom - // track type - m_istream->seekg(m_hdlrAtom->startOffset() + 16); // seek to beg, skip size, name, version, flags and reserved bytes - string trackTypeStr = reader.readString(4); - if(trackTypeStr == "soun") { - m_mediaType = MediaType::Audio; - } else if(trackTypeStr == "vide") { + // -> seek to begin skipping size, name, version, flags and reserved bytes + m_istream->seekg(m_hdlrAtom->dataOffset() + 8); + // -> track type + switch(reader.readUInt32BE()) { + case 0x76696465: m_mediaType = MediaType::Video; - } else if(trackTypeStr == "hint") { + break; + case 0x736F756E: + m_mediaType = MediaType::Audio; + break; + case 0x68696E74: m_mediaType = MediaType::Hint; - } else if(trackTypeStr == "meta") { + break; + case 0x6D657461: case 0x74657874: m_mediaType = MediaType::Text; - } else { + break; + default: m_mediaType = MediaType::Unknown; } + // name m_istream->seekg(12, ios_base::cur); // skip reserved bytes - //name = reader.readString(hdlrAtom->size - 16 - 4 - 12); m_name = reader.readTerminatedString(m_hdlrAtom->totalSize() - 12 - 4 - 12, 0); // read stco atom (only chunk count) m_chunkOffsetSize = (m_stcoAtom->id() == Mp4AtomIds::ChunkOffset64) ? 8 : 4;