1 // Copyright (C) 2020 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // A parser for H.264 ping info from guest. It will know where to extract 16 // the specified data. 17 18 #pragma once 19 20 #include "host-common/GoldfishMediaDefs.h" 21 #include "host-common/MediaH264Decoder.h" 22 23 #include <cstdint> 24 #include <string> 25 26 namespace android { 27 namespace emulation { 28 29 class H264PingInfoParser { 30 public: 31 using PixelFormat = MediaH264Decoder::PixelFormat; 32 33 struct InitContextParam { 34 // input 35 uint32_t version; 36 unsigned int width; 37 unsigned int height; 38 unsigned int outputWidth; 39 unsigned int outputHeight; 40 PixelFormat outputPixelFormat; 41 // output 42 uint64_t* pHostDecoderId; 43 }; 44 45 struct DecodeFrameParam { 46 // input 47 uint64_t hostDecoderId; 48 uint8_t* pData; 49 size_t size; 50 uint64_t pts; 51 // output 52 size_t* pConsumedBytes; 53 int32_t* pDecoderErrorCode; 54 }; 55 56 struct ResetParam { 57 // input 58 uint64_t hostDecoderId; 59 unsigned int width; 60 unsigned int height; 61 unsigned int outputWidth; 62 unsigned int outputHeight; 63 PixelFormat outputPixelFormat; 64 }; 65 66 struct GetImageParam { 67 // input 68 uint64_t hostDecoderId; 69 int32_t hostColorBufferId; 70 71 // output 72 int32_t* pDecoderErrorCode; 73 uint32_t* pRetWidth; 74 uint32_t* pRetHeight; 75 uint64_t* pRetPts; 76 uint32_t* pRetColorPrimaries; 77 uint32_t* pRetColorRange; 78 uint32_t* pRetColorTransfer; 79 uint32_t* pRetColorSpace; 80 uint8_t* pDecodedFrame; 81 }; 82 83 public: 84 // get the decoder id on the host side that 85 // is requested to do the work by the guest 86 static uint32_t parseVersion(void* ptr); 87 static uint64_t parseHostDecoderId(void* ptr); 88 89 void parseInitContextParams(void* ptr, InitContextParam& param); 90 void parseDecodeFrameParams(void* ptr, DecodeFrameParam& param); 91 void parseGetImageParams(void* ptr, GetImageParam& param); 92 void parseResetParams(void* ptr, ResetParam& param); 93 void parseMetadataParams(void* ptr, MetadataParam& param); 94 95 public: 96 explicit H264PingInfoParser(void* ptr); 97 H264PingInfoParser(uint32_t version); 98 ~H264PingInfoParser() = default; 99 version()100 uint32_t version() const { return mVersion; } 101 102 private: 103 int32_t parseHostColorBufferId(void* ptr); 104 void* getReturnAddress(void* ptr); 105 uint32_t mVersion = 100; 106 }; 107 108 } // namespace emulation 109 } // namespace android 110