1 /*
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 
20 #include <SimpleC2Component.h>
21 #include "libgav1/src/decoder.h"
22 #include "libgav1/src/decoder_settings.h"
23 
24 #define GETTIME(a, b) gettimeofday(a, b);
25 #define TIME_DIFF(start, end, diff)     \
26     diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
27             ((end).tv_usec - (start).tv_usec);
28 
29 namespace android {
30 
31 struct C2SoftGav1Dec : public SimpleC2Component {
32   class IntfImpl;
33 
34   C2SoftGav1Dec(const char* name, c2_node_id_t id,
35                 const std::shared_ptr<IntfImpl>& intfImpl);
36   ~C2SoftGav1Dec();
37 
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;
52   std::unique_ptr<libgav1::Decoder> mCodecCtx;
53 
54   uint32_t mWidth;
55   uint32_t mHeight;
56   bool mSignalledOutputEos;
57   bool mSignalledError;
58 
59   struct timeval mTimeStart;  // Time at the start of decode()
60   struct timeval mTimeEnd;    // Time at the end of decode()
61 
62   bool initDecoder();
63   void destroyDecoder();
64   void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
65                   const std::shared_ptr<C2GraphicBlock>& block);
66   bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
67                     const std::unique_ptr<C2Work>& work);
68   c2_status_t drainInternal(uint32_t drainMode,
69                             const std::shared_ptr<C2BlockPool>& pool,
70                             const std::unique_ptr<C2Work>& work);
71 
72   C2_DO_NOT_COPY(C2SoftGav1Dec);
73 };
74 
75 }  // namespace android
76 
77 #endif  // ANDROID_C2_SOFT_GAV1_DEC_H_
78