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 #include "host-common/VpxPingInfoParser.h"
16
17 #define VPX_DEBUG 0
18
19 #if VPX_DEBUG
20 #define RED "\x1B[31m"
21 #define GRN "\x1B[32m"
22 #define YEL "\x1B[33m"
23 #define BLU "\x1B[34m"
24 #define MAG "\x1B[35m"
25 #define CYN "\x1B[36m"
26 #define WHT "\x1B[37m"
27 #define RESET "\x1B[0m"
28 #define VPX_PRINT(color, fmt, ...) \
29 fprintf(stderr, color "VpxPingInfoParser: %s:%d " fmt "\n" RESET, \
30 __func__, __LINE__, ##__VA_ARGS__);
31 #else
32 #define VPX_PRINT(fmt, ...)
33 #endif
34
35 #define VPX_INFO(fmt, ...) VPX_PRINT(RESET, fmt, ##__VA_ARGS__);
36 #define VPX_WARN(fmt, ...) VPX_PRINT(YEL, fmt, ##__VA_ARGS__);
37 #define VPX_ERROR(fmt, ...) VPX_PRINT(RED, fmt, ##__VA_ARGS__);
38
39 namespace android {
40 namespace emulation {
41
parseVersion(void * ptr)42 uint32_t VpxPingInfoParser::parseVersion(void* ptr) {
43 uint8_t* xptr = (uint8_t*)ptr;
44 uint32_t version = *(uint32_t*)(xptr + 1 * 8);
45 return version;
46 }
47
parseId(void * ptr)48 uint64_t VpxPingInfoParser::parseId(void* ptr) {
49 if (nullptr == ptr)
50 return 0;
51 uint64_t key = (*reinterpret_cast<uint64_t*>(ptr));
52 return key;
53 }
54
getReturnAddress(void * ptr)55 void* VpxPingInfoParser::getReturnAddress(void* ptr) {
56 uint8_t* xptr = (uint8_t*)ptr;
57 void* pint = (void*)(xptr + 256);
58 return pint;
59 }
60
parseInitContextParams(void * ptr,InitContextParam & param)61 void VpxPingInfoParser::parseInitContextParams(void* ptr,
62 InitContextParam& param) {
63 param.id = parseId(ptr);
64 param.version = parseVersion(ptr);
65 }
66
parseDecodeFrameParams(void * ptr,DecodeFrameParam & param)67 void VpxPingInfoParser::parseDecodeFrameParams(void* ptr,
68 DecodeFrameParam& param) {
69 param.id = parseId(ptr);
70 uint8_t* xptr = (uint8_t*)ptr;
71 uint64_t offset = *(uint64_t*)(xptr + 1 * 8);
72 param.p_data = xptr + offset;
73 param.size = *(size_t*)(xptr + 2 * 8);
74 param.user_priv = *(uint64_t*)(xptr + 3 * 8);
75 }
76
parseGetImageParams(void * ptr,GetImageParam & param)77 void VpxPingInfoParser::parseGetImageParams(void* ptr, GetImageParam& param) {
78 param.id = parseId(ptr);
79 uint8_t* xptr = (uint8_t*)ptr;
80 param.outputBufferWidth = *(size_t*)(xptr + 1 * 8);
81 param.outputBufferHeight = *(size_t*)(xptr + 2 * 8);
82 param.width = *(size_t*)(xptr + 3 * 8);
83 param.height = *(size_t*)(xptr + 4 * 8);
84 param.bpp = *(size_t*)(xptr + 5 * 8);
85 if (mVersion == 100) {
86 param.hostColorBufferId = -1;
87 } else if (mVersion == 200) {
88 param.hostColorBufferId = *(int32_t*)(xptr + 6 * 8);
89 }
90 uint64_t offset = *(uint64_t*)(xptr + 7 * 8);
91 param.p_dst = (uint8_t*)ptr + offset;
92
93 // return
94 uint8_t* retptr = (uint8_t*)getReturnAddress(ptr);
95 param.p_error = (int*)(retptr);
96 param.p_fmt = (uint32_t*)(retptr + 1 * 8);
97 param.p_d_w = (uint32_t*)(retptr + 2 * 8);
98 param.p_d_h = (uint32_t*)(retptr + 3 * 8);
99 param.p_user_priv = (uint64_t*)(retptr + 4 * 8);
100 }
101
parseDestroyParams(void * ptr,DestroyParam & param)102 void VpxPingInfoParser::parseDestroyParams(void* ptr, DestroyParam& param) {
103 param.id = parseId(ptr);
104 }
105
parseFlushParams(void * ptr,FlushParam & param)106 void VpxPingInfoParser::parseFlushParams(void* ptr, FlushParam& param) {
107 param.id = parseId(ptr);
108 }
109
VpxPingInfoParser(void * ptr)110 VpxPingInfoParser::VpxPingInfoParser(void* ptr) {
111 mVersion = parseVersion(ptr);
112 }
113
VpxPingInfoParser(uint32_t version)114 VpxPingInfoParser::VpxPingInfoParser(uint32_t version) {
115 mVersion = version;
116 }
117
118 } // namespace emulation
119 } // namespace android
120