1 | // Copyright (C) 2024 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 QFFMPEGCODEC_P_H |
5 | #define QFFMPEGCODEC_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 <QtFFmpegMediaPluginImpl/private/qffmpegdefs_p.h> // Important: Must be included first |
19 | |
20 | #include <QtCore/qlatin1stringview.h> |
21 | #include <QtCore/qspan.h> |
22 | |
23 | #include <vector> |
24 | |
25 | extern "C" { |
26 | #include <libavcodec/codec.h> |
27 | } |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | namespace QFFmpeg { |
32 | |
33 | class Codec |
34 | { |
35 | public: |
36 | explicit Codec(const AVCodec *codec); |
37 | |
38 | [[nodiscard]] const AVCodec *get() const noexcept; |
39 | [[nodiscard]] AVCodecID id() const noexcept; |
40 | [[nodiscard]] QLatin1StringView name() const noexcept; |
41 | [[nodiscard]] AVMediaType type() const noexcept; |
42 | [[nodiscard]] int capabilities() const noexcept; |
43 | [[nodiscard]] bool isEncoder() const noexcept; |
44 | [[nodiscard]] bool isDecoder() const noexcept; |
45 | [[nodiscard]] bool isExperimental() const noexcept; |
46 | [[nodiscard]] QSpan<const AVPixelFormat> pixelFormats() const noexcept; |
47 | [[nodiscard]] QSpan<const AVSampleFormat> sampleFormats() const noexcept; |
48 | [[nodiscard]] QSpan<const int> sampleRates() const noexcept; |
49 | [[nodiscard]] QSpan<const ChannelLayoutT> channelLayouts() const noexcept; |
50 | [[nodiscard]] QSpan<const AVRational> frameRates() const noexcept; |
51 | [[nodiscard]] std::vector<const AVCodecHWConfig *> hwConfigs() const noexcept; |
52 | |
53 | private: |
54 | const AVCodec *m_codec = nullptr; |
55 | }; |
56 | |
57 | // Minimal iterator to support range-based for-loop |
58 | class CodecIterator |
59 | { |
60 | public: |
61 | // named constructors |
62 | static CodecIterator begin(); |
63 | static CodecIterator end(); |
64 | |
65 | CodecIterator &operator++() noexcept; |
66 | [[nodiscard]] Codec operator*() const noexcept; |
67 | [[nodiscard]] bool operator!=(const CodecIterator &other) const noexcept; |
68 | |
69 | private: |
70 | void *m_state = nullptr; |
71 | const AVCodec *m_codec = nullptr; |
72 | }; |
73 | |
74 | using CodecEnumerator = CodecIterator; |
75 | |
76 | // Helper function to wrap pixel formats inside a span |
77 | QSpan<const AVPixelFormat> makeSpan(const AVPixelFormat *values); |
78 | |
79 | } // namespace QFFmpeg |
80 | |
81 | QT_END_NAMESPACE |
82 | |
83 | #endif |
84 | |