blob: 4b13feff58aaf1893aee5912186bc965cf30e014 [file] [log] [blame]
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -07001/*
2 * Copyright (C) 2019 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_GAV1_DEC_H_
18#define ANDROID_C2_SOFT_GAV1_DEC_H_
19
Ray Essick24754942022-04-16 09:50:35 -070020#include <inttypes.h>
21
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053022#include <media/stagefright/foundation/ColorUtils.h>
23
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070024#include <SimpleC2Component.h>
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053025#include <C2Config.h>
James Zernb7aee6e2020-06-26 13:49:53 -070026#include "libgav1/src/gav1/decoder.h"
27#include "libgav1/src/gav1/decoder_settings.h"
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070028
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070029namespace android {
30
31struct C2SoftGav1Dec : public SimpleC2Component {
32 class IntfImpl;
33
34 C2SoftGav1Dec(const char* name, c2_node_id_t id,
35 const std::shared_ptr<IntfImpl>& intfImpl);
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070036 ~C2SoftGav1Dec();
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070037
38 // Begin SimpleC2Component overrides.
39 c2_status_t onInit() override;
40 c2_status_t onStop() override;
41 void onReset() override;
42 void onRelease() override;
43 c2_status_t onFlush_sm() override;
44 void process(const std::unique_ptr<C2Work>& work,
45 const std::shared_ptr<C2BlockPool>& pool) override;
46 c2_status_t drain(uint32_t drainMode,
47 const std::shared_ptr<C2BlockPool>& pool) override;
48 // End SimpleC2Component overrides.
49
50 private:
51 std::shared_ptr<IntfImpl> mIntf;
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070052 std::unique_ptr<libgav1::Decoder> mCodecCtx;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070053
Harish Mahendrakard4bbb762022-03-29 11:53:23 -070054 uint32_t mHalPixelFormat;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070055 uint32_t mWidth;
56 uint32_t mHeight;
57 bool mSignalledOutputEos;
58 bool mSignalledError;
59
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053060 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
61 // converting them to C2 values for each frame
62 struct VuiColorAspects {
63 uint8_t primaries;
64 uint8_t transfer;
65 uint8_t coeffs;
66 uint8_t fullRange;
67
68 // default color aspects
69 VuiColorAspects()
70 : primaries(C2Color::PRIMARIES_UNSPECIFIED),
71 transfer(C2Color::TRANSFER_UNSPECIFIED),
72 coeffs(C2Color::MATRIX_UNSPECIFIED),
73 fullRange(C2Color::RANGE_UNSPECIFIED) { }
74
75 bool operator==(const VuiColorAspects &o) {
76 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs
77 && fullRange == o.fullRange;
78 }
79 } mBitstreamColorAspects;
80
Ray Essick24754942022-04-16 09:50:35 -070081 nsecs_t mTimeStart = 0; // Time at the start of decode()
82 nsecs_t mTimeEnd = 0; // Time at the end of decode()
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070083
84 bool initDecoder();
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053085 void getVuiParams(const libgav1::DecoderBuffer *buffer);
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070086 void destroyDecoder();
87 void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
88 const std::shared_ptr<C2GraphicBlock>& block);
89 bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
90 const std::unique_ptr<C2Work>& work);
91 c2_status_t drainInternal(uint32_t drainMode,
92 const std::shared_ptr<C2BlockPool>& pool,
93 const std::unique_ptr<C2Work>& work);
94
95 C2_DO_NOT_COPY(C2SoftGav1Dec);
96};
97
98} // namespace android
99
100#endif // ANDROID_C2_SOFT_GAV1_DEC_H_