Tag Parser  9.1.2
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
ivfstream.cpp
Go to the documentation of this file.
1 #include "./ivfstream.h"
2 
3 #include "../mp4/mp4ids.h"
4 
5 #include "../exceptions.h"
6 
7 #include <c++utilities/conversion/stringbuilder.h>
8 #include <c++utilities/conversion/stringconversion.h>
9 
10 #include <string>
11 
12 using namespace std;
13 using namespace CppUtilities;
14 
15 namespace TagParser {
16 
23 void IvfStream::internalParseHeader(Diagnostics &diag)
24 {
25  static const string context("parsing IVF header");
26  if (!m_istream) {
27  throw NoDataFoundException();
28  }
29 
30  // check signature and version
31  if (m_reader.readUInt32BE() != 0x444B4946u) {
32  diag.emplace_back(DiagLevel::Critical, "Signature not \"DKIF\".", context);
33  throw InvalidDataException();
34  }
35  const auto version = m_reader.readUInt16LE();
36  m_version = version;
37  if (version != 0) {
38  diag.emplace_back(DiagLevel::Warning, argsToString("Version ", version, " is not supported."), context);
39  }
40 
41  // read remaining header
42  m_headerLength = m_reader.readUInt16LE();
43  const auto formatId = m_reader.readUInt32BE();
44  m_formatId = interpretIntegerAsString(formatId);
45  m_pixelSize.setWidth(m_reader.readUInt16LE());
46  m_pixelSize.setHeight(m_reader.readUInt16LE());
47  m_fps = m_reader.readUInt32LE();
48  m_timeScale = m_reader.readUInt32LE();
49  m_sampleCount = m_reader.readUInt32LE();
50 
51  // compute further values
52  m_format = FourccIds::fourccToMediaFormat(formatId);
53  m_duration = TimeSpan::fromSeconds(static_cast<double>(m_sampleCount) / m_fps);
54 
55  // skip unused bytes
56  m_istream->seekg(4, ios_base::cur);
57 }
58 
59 void IvfStream::readFrame(Diagnostics &diag)
60 {
61  m_frames.emplace_back();
62  m_frames.back().parseHeader(m_reader, diag);
63 }
64 
65 } // namespace TagParser
TagParser::VorbisCommentIds::version
constexpr const TAG_PARSER_EXPORT char * version()
Definition: vorbiscommentids.h:33
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
ivfstream.h
CppUtilities
Definition: abstractcontainer.h:15
TagParser::NoDataFoundException
The exception that is thrown when the data to be parsed holds no parsable information (e....
Definition: exceptions.h:18
TagParser::InvalidDataException
The exception that is thrown when the data to be parsed or to be made seems invalid and therefore can...
Definition: exceptions.h:25
TagParser::FourccIds::fourccToMediaFormat
TAG_PARSER_EXPORT MediaFormat fourccToMediaFormat(std::uint32_t fourccId)
Definition: mp4ids.cpp:46