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 vpx 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 
22 #include <cstdint>
23 #include <string>
24 
25 namespace android {
26 namespace emulation {
27 
28 class VpxPingInfoParser {
29 public:
30     struct InitContextParam {
31         // input
32         uint64_t id;       // unique id > 0
33         uint32_t version;  // 100 or 200
34     };
35 
36     struct FlushParam {
37         uint64_t id;
38     };
39 
40     struct DestroyParam {
41         uint64_t id;
42     };
43 
44     struct DecodeFrameParam {
45         // input
46         uint64_t id;
47         uint8_t* p_data;  // host address
48         size_t size;
49         uint64_t user_priv;
50     };
51 
52     struct GetImageParam {
53         // input
54         uint64_t id;
55         size_t outputBufferWidth;
56         size_t outputBufferHeight;
57         size_t width;
58         size_t height;
59         size_t bpp;
60         int32_t hostColorBufferId;
61         uint8_t* p_dst;  // host address to copy decoded frame into
62 
63         int* p_error;
64         uint32_t* p_fmt;
65         uint32_t* p_d_w;
66         uint32_t* p_d_h;
67         uint64_t* p_user_priv;
68     };
69 
70 public:
71     // get the decoder id on the host side that
72     // is requested to do the work by the guest
73     static uint32_t parseVersion(void* ptr);
74     static uint64_t parseId(void* ptr);
75 
76     void parseInitContextParams(void* ptr, InitContextParam& param);
77     void parseDecodeFrameParams(void* ptr, DecodeFrameParam& param);
78     void parseGetImageParams(void* ptr, GetImageParam& param);
79     void parseDestroyParams(void* ptr, DestroyParam& param);
80     void parseFlushParams(void* ptr, FlushParam& param);
81     void parseMetadataParams(void* ptr, MetadataParam& param);
82 
83 public:
84     explicit VpxPingInfoParser(void* ptr);
85     VpxPingInfoParser(uint32_t version);
86     ~VpxPingInfoParser() = default;
87 
version()88     uint32_t version() const { return mVersion; }
89 
90 private:
91     void* getReturnAddress(void* ptr);
92     uint32_t mVersion = 100;
93 };
94 
95 }  // namespace emulation
96 }  // namespace android
97