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