blob: 75111fc271b7ceff2386f1ad17f3b4442face4ba [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright (C) 2018 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 ANDROID_C2_SOFT_HEVC_DEC_H_
18#define ANDROID_C2_SOFT_HEVC_DEC_H_
19
20#include <media/stagefright/foundation/ColorUtils.h>
21
22#include <SimpleC2Component.h>
23
24#include "ihevc_typedefs.h"
25#include "iv.h"
26#include "ivd.h"
27
28namespace android {
29
30#define ivdec_api_function ihevcd_cxa_api_function
31#define ivdext_create_ip_t ihevcd_cxa_create_ip_t
32#define ivdext_create_op_t ihevcd_cxa_create_op_t
33#define ivdext_delete_ip_t ihevcd_cxa_delete_ip_t
34#define ivdext_delete_op_t ihevcd_cxa_delete_op_t
35#define ivdext_ctl_set_num_cores_ip_t ihevcd_cxa_ctl_set_num_cores_ip_t
36#define ivdext_ctl_set_num_cores_op_t ihevcd_cxa_ctl_set_num_cores_op_t
37#define ivdext_ctl_get_vui_params_ip_t ihevcd_cxa_ctl_get_vui_params_ip_t
38#define ivdext_ctl_get_vui_params_op_t ihevcd_cxa_ctl_get_vui_params_op_t
39#define ALIGN64(x) ((((x) + 63) >> 6) << 6)
40#define MAX_NUM_CORES 4
41#define IVDEXT_CMD_CTL_SET_NUM_CORES \
42 (IVD_CONTROL_API_COMMAND_TYPE_T)IHEVCD_CXA_CMD_CTL_SET_NUM_CORES
43#define MIN(a, b) (((a) < (b)) ? (a) : (b))
44#define GETTIME(a, b) gettimeofday(a, b);
45#define TIME_DIFF(start, end, diff) \
46 diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
47 ((end).tv_usec - (start).tv_usec);
48
49
50struct C2SoftHevcDec : public SimpleC2Component {
51 class IntfImpl;
52
53 C2SoftHevcDec(const char* name, c2_node_id_t id,
54 const std::shared_ptr<IntfImpl>& intfImpl);
55 virtual ~C2SoftHevcDec();
56
57 // From SimpleC2Component
58 c2_status_t onInit() override;
59 c2_status_t onStop() override;
60 void onReset() override;
61 void onRelease() override;
62 c2_status_t onFlush_sm() override;
63 void process(
64 const std::unique_ptr<C2Work> &work,
65 const std::shared_ptr<C2BlockPool> &pool) override;
66 c2_status_t drain(
67 uint32_t drainMode,
68 const std::shared_ptr<C2BlockPool> &pool) override;
69 private:
70 status_t createDecoder();
71 status_t setNumCores();
72 status_t setParams(size_t stride, IVD_VIDEO_DECODE_MODE_T dec_mode);
73 status_t getVersion();
74 status_t initDecoder();
75 bool setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
76 ivd_video_decode_op_t *ps_decode_op,
77 C2ReadView *inBuffer,
78 C2GraphicView *outBuffer,
79 size_t inOffset,
80 size_t inSize,
81 uint32_t tsMarker);
82 bool getVuiParams();
83 // TODO:This is not the right place for colorAspects functions. These should
84 // be part of c2-vndk so that they can be accessed by all video plugins
85 // until then, make them feel at home
86 bool colorAspectsDiffer(const ColorAspects &a, const ColorAspects &b);
87 void updateFinalColorAspects(
88 const ColorAspects &otherAspects, const ColorAspects &preferredAspects);
89 status_t handleColorAspectsChange();
90 c2_status_t ensureDecoderState(const std::shared_ptr<C2BlockPool> &pool);
91 void finishWork(uint64_t index, const std::unique_ptr<C2Work> &work);
92 status_t setFlushMode();
93 c2_status_t drainInternal(
94 uint32_t drainMode,
95 const std::shared_ptr<C2BlockPool> &pool,
96 const std::unique_ptr<C2Work> &work);
97 status_t resetDecoder();
98 void resetPlugin();
99 status_t deleteDecoder();
100
101 // TODO:This is not the right place for this enum. These should
102 // be part of c2-vndk so that they can be accessed by all video plugins
103 // until then, make them feel at home
104 enum {
105 kNotSupported,
106 kPreferBitstream,
107 kPreferContainer,
108 };
109
110 std::shared_ptr<IntfImpl> mIntf;
111 iv_obj_t *mDecHandle;
112 std::shared_ptr<C2GraphicBlock> mOutBlock;
113 uint8_t *mOutBufferFlush;
114
115 size_t mNumCores;
116 IV_COLOR_FORMAT_T mIvColorformat;
117
118 uint32_t mWidth;
119 uint32_t mHeight;
120 uint32_t mStride;
121 bool mSignalledOutputEos;
122 bool mSignalledError;
123 bool mHeaderDecoded;
124
125 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
126 // converting them to C2 values for each frame
127 struct VuiColorAspects {
128 uint8_t primaries;
129 uint8_t transfer;
130 uint8_t coeffs;
131 uint8_t fullRange;
132
133 // default color aspects
134 VuiColorAspects()
135 : primaries(2), transfer(2), coeffs(2), fullRange(0) { }
136
137 bool operator==(const VuiColorAspects &o) {
138 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs
139 && fullRange == o.fullRange;
140 }
141 } mBitstreamColorAspects;
142
143 // profile
144 struct timeval mTimeStart;
145 struct timeval mTimeEnd;
146
147 C2_DO_NOT_COPY(C2SoftHevcDec);
148};
149
150} // namespace android
151
152#endif // ANDROID_C2_SOFT_HEVC_DEC_H_