blob: 134fa0d703e1fc6926a57e524c8905420c698264 [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
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053020#include <media/stagefright/foundation/ColorUtils.h>
21
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070022#include <SimpleC2Component.h>
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053023#include <C2Config.h>
James Zernb7aee6e2020-06-26 13:49:53 -070024#include "libgav1/src/gav1/decoder.h"
25#include "libgav1/src/gav1/decoder_settings.h"
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070026
27#define GETTIME(a, b) gettimeofday(a, b);
28#define TIME_DIFF(start, end, diff) \
29 diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
30 ((end).tv_usec - (start).tv_usec);
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070031
32namespace android {
33
34struct C2SoftGav1Dec : public SimpleC2Component {
35 class IntfImpl;
36
37 C2SoftGav1Dec(const char* name, c2_node_id_t id,
38 const std::shared_ptr<IntfImpl>& intfImpl);
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070039 ~C2SoftGav1Dec();
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070040
41 // Begin SimpleC2Component overrides.
42 c2_status_t onInit() override;
43 c2_status_t onStop() override;
44 void onReset() override;
45 void onRelease() override;
46 c2_status_t onFlush_sm() override;
47 void process(const std::unique_ptr<C2Work>& work,
48 const std::shared_ptr<C2BlockPool>& pool) override;
49 c2_status_t drain(uint32_t drainMode,
50 const std::shared_ptr<C2BlockPool>& pool) override;
51 // End SimpleC2Component overrides.
52
53 private:
54 std::shared_ptr<IntfImpl> mIntf;
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070055 std::unique_ptr<libgav1::Decoder> mCodecCtx;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070056
57 uint32_t mWidth;
58 uint32_t mHeight;
59 bool mSignalledOutputEos;
60 bool mSignalledError;
61
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053062 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
63 // converting them to C2 values for each frame
64 struct VuiColorAspects {
65 uint8_t primaries;
66 uint8_t transfer;
67 uint8_t coeffs;
68 uint8_t fullRange;
69
70 // default color aspects
71 VuiColorAspects()
72 : primaries(C2Color::PRIMARIES_UNSPECIFIED),
73 transfer(C2Color::TRANSFER_UNSPECIFIED),
74 coeffs(C2Color::MATRIX_UNSPECIFIED),
75 fullRange(C2Color::RANGE_UNSPECIFIED) { }
76
77 bool operator==(const VuiColorAspects &o) {
78 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs
79 && fullRange == o.fullRange;
80 }
81 } mBitstreamColorAspects;
82
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070083 struct timeval mTimeStart; // Time at the start of decode()
84 struct timeval mTimeEnd; // Time at the end of decode()
85
86 bool initDecoder();
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053087 void getVuiParams(const libgav1::DecoderBuffer *buffer);
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070088 void destroyDecoder();
89 void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
90 const std::shared_ptr<C2GraphicBlock>& block);
91 bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
92 const std::unique_ptr<C2Work>& work);
93 c2_status_t drainInternal(uint32_t drainMode,
94 const std::shared_ptr<C2BlockPool>& pool,
95 const std::unique_ptr<C2Work>& work);
96
97 C2_DO_NOT_COPY(C2SoftGav1Dec);
98};
99
100} // namespace android
101
102#endif // ANDROID_C2_SOFT_GAV1_DEC_H_