1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef GOLDFISH_HEVC_HELPER_H_
18 #define GOLDFISH_HEVC_HELPER_H_
19 
20 #include <inttypes.h>
21 #include "ihevc_typedefs.h"
22 #include "ihevcd_cxa.h"
23 
24 
25 namespace android {
26 
27 // this class is just to provide some functions to decode header
28 // so that we know w/h of each sps
29 class GoldfishHevcHelper {
30   public:
31     GoldfishHevcHelper(int w, int h);
32     ~GoldfishHevcHelper();
33 
34     // check whether the frame is vps; typical hevc will have
35     // a frame that is vps/sps/pps together
36     static bool isVpsFrame(const uint8_t* frame, int inSize);
37   public:
38     // return true if decoding finds out w/h changed;
39     // otherwise false
40    bool decodeHeader(const uint8_t *frame, int inSize, bool &status);
getWidth()41    int getWidth() const { return mWidth; }
getHeight()42    int getHeight() const { return mHeight; }
43 
44   private:
45     void createDecoder();
46     void destroyDecoder();
47     void resetDecoder();
48     void setNumCores();
49     void setParams(size_t stride, IVD_VIDEO_DECODE_MODE_T dec_mode);
50     bool setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
51                        ivd_video_decode_op_t *ps_decode_op,
52                        const uint8_t *inBuffer, uint32_t displayStride,
53                        size_t inOffset, size_t inSize, uint32_t tsMarker);
54 
55   private:
56     iv_obj_t *mDecHandle = nullptr;
57     int mWidth = 320;
58     int mHeight = 240;
59     int mNumCores = 1;
60     int mStride = 16;
61     int mOutputDelay = 8; // default
62     IV_COLOR_FORMAT_T mIvColorformat = IV_YUV_420P;
63 };
64 
65 } // namespace android
66 #endif
67