Tag Parser  10.0.1
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, AbortableProgressFeedback &progress)
24 {
25  CPP_UTILITIES_UNUSED(progress)
26 
27  static const string context("parsing IVF header");
28  if (!m_istream) {
29  throw NoDataFoundException();
30  }
31 
32  // check signature and version
33  if (m_reader.readUInt32BE() != 0x444B4946u) {
34  diag.emplace_back(DiagLevel::Critical, "Signature not \"DKIF\".", context);
35  throw InvalidDataException();
36  }
37  const auto version = m_reader.readUInt16LE();
38  m_version = version;
39  if (version != 0) {
40  diag.emplace_back(DiagLevel::Warning, argsToString("Version ", version, " is not supported."), context);
41  }
42 
43  // read remaining header
44  m_headerLength = m_reader.readUInt16LE();
45  const auto formatId = m_reader.readUInt32BE();
46  m_formatId = interpretIntegerAsString(formatId);
47  m_pixelSize.setWidth(m_reader.readUInt16LE());
48  m_pixelSize.setHeight(m_reader.readUInt16LE());
49  m_fps = m_reader.readUInt32LE();
50  m_timeScale = m_reader.readUInt32LE();
51  m_sampleCount = m_reader.readUInt32LE();
52 
53  // compute further values
54  m_format = FourccIds::fourccToMediaFormat(formatId);
55  m_duration = TimeSpan::fromSeconds(static_cast<double>(m_sampleCount) / m_fps);
56 
57  // skip unused bytes
58  m_istream->seekg(4, ios_base::cur);
59 }
60 
61 void IvfStream::readFrame(Diagnostics &diag)
62 {
63  m_frames.emplace_back();
64  m_frames.back().parseHeader(m_reader, diag);
65 }
66 
67 } // namespace TagParser
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
The exception that is thrown when the data to be parsed or to be made seems invalid and therefore can...
Definition: exceptions.h:25
The exception that is thrown when the data to be parsed holds no parsable information (e....
Definition: exceptions.h:18
TAG_PARSER_EXPORT MediaFormat fourccToMediaFormat(std::uint32_t fourccId)
Definition: mp4ids.cpp:47
constexpr TAG_PARSER_EXPORT std::string_view version()
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10