1 #ifndef _EXTESEXTRACTOR_HPP
2 #define _EXTESEXTRACTOR_HPP
3 /*
4 * Copyright (C) 2023 Igalia, S.L.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *    http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 
19 #include "esextractor.h"
20 #include "tcuTestLog.hpp"
21 
22 class ESEDemuxer {
23     ESExtractor *extractor{};
24     ESEPacket* pkt{};
25     ESEVideoCodec eVideoCodec{ESE_VIDEO_CODEC_UNKNOWN};
26 
27     tcu::TestLog& log;
28 
29 public:
ESEDemuxer(const std::string& filePath, tcu::TestLog& log_)30     ESEDemuxer(const std::string& filePath, tcu::TestLog& log_)
31 		: extractor(es_extractor_new(filePath.c_str(), "Alignment:NAL"))
32 		, log(log_)
33 	{
34         eVideoCodec = es_extractor_video_codec(extractor);
35         log << tcu::TestLog::Message << "ESEDemuxer found video codec: " << eVideoCodec << tcu::TestLog::EndMessage;
36     }
37 
~ESEDemuxer()38     ~ESEDemuxer()
39 	{
40         if (pkt) {
41             es_extractor_clear_packet(pkt);
42         }
43         es_extractor_teardown(extractor);
44     }
45 
GetVideoCodec()46     ESEVideoCodec GetVideoCodec() {
47         if (!extractor) {
48             return ESE_VIDEO_CODEC_UNKNOWN;
49         }
50         return eVideoCodec;
51     }
52 
Demux(deUint8 **ppVideo, deInt64 *pnVideoBytes)53     bool Demux(deUint8 **ppVideo, deInt64 *pnVideoBytes) {
54         if (!extractor) {
55             return false;
56         }
57 
58         *pnVideoBytes = 0;
59 
60         if (pkt) {
61             es_extractor_clear_packet(pkt);
62             pkt = nullptr;
63         }
64 
65         int e = 0;
66         e = es_extractor_read_packet(extractor, &pkt);
67 
68         if (e > ESE_RESULT_LAST_PACKET) {
69             return false;
70         }
71 
72         *ppVideo = pkt->data;
73         *pnVideoBytes = static_cast<int>(pkt->data_size);
74 
75         return true;
76     }
77 };
78 
EXExtractor2NvCodecId(ESEVideoCodec id)79 inline vk::VkVideoCodecOperationFlagBitsKHR EXExtractor2NvCodecId(ESEVideoCodec id) {
80     switch (id) {
81         case ESE_VIDEO_CODEC_H264       : return vk::VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR;
82         case ESE_VIDEO_CODEC_H265       : return vk::VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR;
83         default                     : /* assert(false); */ return vk::VkVideoCodecOperationFlagBitsKHR(0);
84     }
85 }
86 #endif // _EXTESEXTRACTOR_HPP
87