xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/video/vktDemuxer.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTDEMUXER_HPP
2 #define _VKTDEMUXER_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2024 The Khronos Group Inc.
8  * Copyright (c) 2024 Igalia S. L
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23 /*!
24  * \file
25  * \brief Elementary stream demuxers
26  */
27 /*--------------------------------------------------------------------*/
28 
29 #include <vector>
30 #include <memory>
31 
32 #include "deDefs.h"
33 
34 #include "vkDefs.hpp"
35 
36 #include "vktBufferedReader.hpp"
37 
38 namespace vkt
39 {
40 namespace video
41 {
42 enum class ElementaryStreamFraming
43 {
44     IVF,
45     H26X_BYTE_STREAM,
46     AV1_ANNEXB,
47 
48     UNKNOWN
49 };
50 
51 class Demuxer
52 {
53 public:
~Demuxer()54     virtual ~Demuxer()
55     {
56     }
57 
58     struct Params
59     {
60         std::unique_ptr<BufferedReader> data;
61         vk::VkVideoCodecOperationFlagBitsKHR codecOperation;
62         ElementaryStreamFraming framing;
63     };
64 
65     static std::shared_ptr<Demuxer> create(Params &&params);
66 
codecOperation() const67     vk::VkVideoCodecOperationFlagBitsKHR codecOperation() const
68     {
69         return m_params.codecOperation;
70     };
framing() const71     ElementaryStreamFraming framing() const
72     {
73         return m_params.framing;
74     }
75 
76     virtual std::vector<uint8_t> nextPacket() = 0;
77 
78 protected:
79     Demuxer(Params &&params);
80     Params m_params;
81 };
82 
83 class H26XAnnexBDemuxer final : public Demuxer
84 {
85 public:
86     H26XAnnexBDemuxer(Params &&params);
87 
88     virtual std::vector<uint8_t> nextPacket() override;
89 
90 private:
91     void readToNextStartCode(std::vector<uint8_t> *payload);
92 };
93 
94 class DuckIVFDemuxer final : public Demuxer
95 {
96 public:
97     DuckIVFDemuxer(Params &&params);
98     virtual std::vector<uint8_t> nextPacket() override;
99 
100     DE_PACKED(Header {
101         uint32_t signature;           // bytes 0-3    signature: 'DKIF'
102         uint16_t version;             // bytes 4-5    version (should be 0)
103         uint16_t hdrLength;           // bytes 6-7    length of header in bytes
104         uint32_t fourcc;              // bytes 8-11    codec FourCC (e.g., 'VP80')
105         uint16_t widthInPixels;       // bytes 12-13    width in pixels
106         uint16_t heightInPixels;      // bytes 14-15    height in pixels
107         uint32_t timeBaseDenominator; // bytes 16-19    time base denominator
108         uint32_t timeBaseNumerator;   // bytes 20-23    time base numerator
109         uint32_t framesInFile;        // bytes 24-27    number of frames in file
110         uint32_t padding;
111     } Header);
112 
113 private:
114     void readHeader();
115 
116     Header m_hdr;
117 
118     int32_t m_frameNumber{-1};
119     uint32_t m_numFrames{0};
120 };
121 
122 class AV1AnnexBDemuxer final : public Demuxer
123 {
124 public:
125     AV1AnnexBDemuxer(Params &&params);
126 
127     virtual std::vector<uint8_t> nextPacket() override;
128 
129 private:
130     size_t m_remainingBytesInTemporalUnit{0};
131     int32_t m_frameNumber{-1};
132 
133     uint32_t getUleb128(uint32_t *numBytes);
134 };
135 
136 } // namespace video
137 } // namespace vkt
138 
139 #endif // _VKTDEMUXER_HPP
140