| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "formatutils_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | std::set<QMediaFormat::VideoCodec> allVideoCodecs(bool includeUnspecified) |
| 9 | { |
| 10 | using VideoCodec = QMediaFormat::VideoCodec; |
| 11 | std::set<VideoCodec> codecs; |
| 12 | |
| 13 | const int firstCodec = qToUnderlying(e: VideoCodec::Unspecified) + (includeUnspecified ? 0 : 1); |
| 14 | constexpr int lastCodec = qToUnderlying(e: VideoCodec::LastVideoCodec); |
| 15 | |
| 16 | for (int i = firstCodec; i <= lastCodec; ++i) |
| 17 | codecs.insert(x: static_cast<VideoCodec>(i)); |
| 18 | |
| 19 | return codecs; |
| 20 | } |
| 21 | |
| 22 | std::set<QMediaFormat::AudioCodec> allAudioCodecs(bool includeUnspecified) |
| 23 | { |
| 24 | using AudioCodec = QMediaFormat::AudioCodec; |
| 25 | std::set<AudioCodec> codecs; |
| 26 | |
| 27 | const int firstCodec = qToUnderlying(e: AudioCodec::Unspecified) + (includeUnspecified ? 0 : 1); |
| 28 | constexpr int lastCodec = qToUnderlying(e: AudioCodec::LastAudioCodec); |
| 29 | |
| 30 | for (int i = firstCodec; i <= lastCodec; ++i) |
| 31 | codecs.insert(x: static_cast<AudioCodec>(i)); |
| 32 | |
| 33 | return codecs; |
| 34 | } |
| 35 | |
| 36 | std::set<QMediaFormat::FileFormat> allFileFormats(bool includeUnspecified) |
| 37 | { |
| 38 | using FileFormat = QMediaFormat::FileFormat; |
| 39 | |
| 40 | std::set<FileFormat> videoFormats; |
| 41 | const int firstFormat = FileFormat::UnspecifiedFormat + (includeUnspecified ? 0 : 1); |
| 42 | for (int i = firstFormat; i <= FileFormat::LastFileFormat; ++i) { |
| 43 | const FileFormat format = static_cast<FileFormat>(i); |
| 44 | videoFormats.insert(x: format); |
| 45 | } |
| 46 | return videoFormats; |
| 47 | } |
| 48 | |
| 49 | std::vector<QMediaFormat> allMediaFormats(bool includeUnspecified) |
| 50 | { |
| 51 | std::vector<QMediaFormat> formats; |
| 52 | for (const auto &fileFormat : allFileFormats(includeUnspecified)) { |
| 53 | for (const auto &audioCodec : allAudioCodecs(includeUnspecified)) { |
| 54 | for (const auto &videoCodec : allVideoCodecs(includeUnspecified)) { |
| 55 | QMediaFormat format{ fileFormat }; |
| 56 | format.setAudioCodec(audioCodec); |
| 57 | format.setVideoCodec(videoCodec); |
| 58 | formats.push_back(x: format); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | return formats; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | QT_END_NAMESPACE |
| 67 |
