Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaudio_parsing_support_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QAUDIO_PARSING_SUPPORT_P_H
5#define QAUDIO_PARSING_SUPPORT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/qtmultimediaglobal.h>
19#include <QtCore/qspan.h>
20
21#include <optional>
22
23QT_BEGIN_NAMESPACE
24
26
27// Audio codecs that can be identified from the first bytes of a stream.
37
38// The sample rate and channel count from the identification packet of the
39// first page of an Ogg stream.
46
47// The parts of a FLAC STREAMINFO metadata block that describe the stream format.
49{
50 int sampleRate = 0;
51 int numChannels = 0;
52 // Total samples per channel. 0 when the encoder did not record it.
54};
55
56// Identifies the codec from the leading bytes of a stream. At least 4 bytes are
57// needed. Anything shorter or unrecognized returns AudioCodec::Unknown.
58Q_MULTIMEDIA_EXPORT AudioCodec sniffCodec(QSpan<const std::byte> header);
59
60// Returns true for codecs whose individual frame sizes can be computed from the
61// frame header, i.e. the codecs mpegFrameSize()/adtsFrameSize() understand.
63
64// Parses the FLAC STREAMINFO metadata block at the beginning of a FLAC stream.
66
67// Parses the identification packet on the first page of an Ogg stream, which
68// says whether the stream is Vorbis or Opus and carries its format. Returns
69// std::nullopt if the data is too short or is not a recognized Ogg audio
70// stream. For Opus the rate is the encoder's input rate. Opus itself always
71// decodes at 48000 Hz, so callers must not treat it as the decoded rate.
73
74// Returns the byte offset of the first FLAC audio frame in data, i.e. the
75// position just past the "fLaC" marker and all metadata blocks. The result is
76// always within data, so callers can use it as a slice position directly.
77// std::nullopt covers a metadata block whose declared length runs past the
78// end of the data.
80
81// Scans data[from..] for the first valid FLAC frame header: the 14-bit sync
82// code, header fields that are not reserved values, and a matching header
83// CRC-8. FLAC frames carry no length field, so a frame spans from one frame
84// header to the next, or to the end of the stream for the final frame.
86 qsizetype from = 0);
87
88// Returns the byte length of the MPEG Layer III frame whose 4-byte header starts
89// at data[offset], or 0 if the header is invalid or out of bounds.
90Q_MULTIMEDIA_EXPORT qsizetype mpegFrameSize(QSpan<const std::byte> data, qsizetype offset = 0);
91
92// Scans data[from..] for the first valid MPEG Layer III sync word + header.
94 qsizetype from = 0);
95
96// Returns the byte length of the ADTS AAC frame (including header) starting at
97// data[offset], or 0 if the header is invalid or out of bounds.
98Q_MULTIMEDIA_EXPORT qsizetype adtsFrameSize(QSpan<const std::byte> data, qsizetype offset = 0);
99
100// Scans data[from..] for the first valid ADTS AAC sync word + header.
102 qsizetype from = 0);
103
104} // namespace QtMultimediaPrivate::ParsingSupport
105
106QT_END_NAMESPACE
107
108#endif // QAUDIO_PARSING_SUPPORT_P_H
Combined button and popup list for selecting options.
std::optional< qsizetype > findAdtsSync(QSpan< const std::byte > data, qsizetype from)
std::optional< OggStreamInfo > oggStreamInfo(QSpan< const std::byte > data)
std::optional< qsizetype > findFlacSync(QSpan< const std::byte > data, qsizetype from)
AudioCodec sniffCodec(QSpan< const std::byte > header)
std::optional< qsizetype > findMpegSync(QSpan< const std::byte > data, qsizetype from)
qsizetype adtsFrameSize(QSpan< const std::byte > data, qsizetype offset)
std::optional< FlacStreamInfo > flacStreamInfo(QSpan< const std::byte > data)
std::optional< qsizetype > flacAudioOffset(QSpan< const std::byte > data)
qsizetype mpegFrameSize(QSpan< const std::byte > data, qsizetype offset)