• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_AV1_DEC_H_
18 #define ANDROID_C2_SOFT_AV1_DEC_H_
19 
20 #include <inttypes.h>
21 
22 #include <SimpleC2Component.h>
23 #include <util/C2InterfaceHelper.h>
24 #include "aom/aom_decoder.h"
25 #include "aom/aomdx.h"
26 
27 namespace android {
28 
29 struct C2SoftAomDec : public SimpleC2Component {
30     class IntfImpl;
31 
32     C2SoftAomDec(const char* name, c2_node_id_t id,
33                  const std::shared_ptr<IntfImpl>& intfImpl);
34     C2SoftAomDec(const char* name, c2_node_id_t id,
35                  const std::shared_ptr<C2ReflectorHelper>& intfImpl);
36     virtual ~C2SoftAomDec();
37 
38     // From SimpleC2Component
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 
49    private:
50     std::shared_ptr<IntfImpl> mIntf;
51     aom_codec_ctx_t* mCodecCtx;
52 
53     uint32_t mWidth;
54     uint32_t mHeight;
55     bool mSignalledOutputEos;
56     bool mSignalledError;
57 
58     #ifdef FILE_DUMP_ENABLE
59     char mInFile[200];
60     char mOutFile[200];
61     #endif /* FILE_DUMP_ENABLE */
62 
63     nsecs_t mTimeStart = 0;   // Time at the start of decode()
64     nsecs_t mTimeEnd = 0;     // Time at the end of decode()
65 
66     status_t initDecoder();
67     status_t destroyDecoder();
68     void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
69                     const std::shared_ptr<C2GraphicBlock>& block);
70     bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
71                       const std::unique_ptr<C2Work>& work);
72 
73     c2_status_t drainInternal(uint32_t drainMode,
74                               const std::shared_ptr<C2BlockPool>& pool,
75                               const std::unique_ptr<C2Work>& work);
76 
77     C2_DO_NOT_COPY(C2SoftAomDec);
78 };
79 
80 #ifdef FILE_DUMP_ENABLE
81 
82 #define INPUT_DUMP_PATH "/data/local/tmp/temp/av1"
83 #define INPUT_DUMP_EXT "webm"
84 #define OUTPUT_DUMP_PATH "/data/local/tmp/temp/av1"
85 #define OUTPUT_DUMP_EXT "av1"
86 #define GENERATE_FILE_NAMES()                                                 \
87     {                                                                         \
88         nsecs_t now = systemTime();                                           \
89         ALOGD("GENERATE_FILE_NAMES");                                         \
90         sprintf(mInFile, "%s_%" PRId64 ".%s", INPUT_DUMP_PATH,                \
91                 now, INPUT_DUMP_EXT);                                         \
92         strcpy(mOutFile, "");                                                 \
93         sprintf(mOutFile, "%s_%" PRId64 ".%s", OUTPUT_DUMP_PATH,              \
94                 now, OUTPUT_DUMP_EXT);                                        \
95     }
96 
97 #define CREATE_DUMP_FILE(m_filename)                     \
98     {                                                    \
99         FILE* fp = fopen(m_filename, "wb");              \
100         if (fp != NULL) {                                \
101             ALOGD("Opened file %s", m_filename);         \
102             fclose(fp);                                  \
103         } else {                                         \
104             ALOGD("Could not open file %s", m_filename); \
105         }                                                \
106     }
107 #define DUMP_TO_FILE(m_filename, m_buf, m_size)              \
108     {                                                        \
109         FILE* fp = fopen(m_filename, "ab");                  \
110         if (fp != NULL && m_buf != NULL) {                   \
111             int i;                                           \
112             ALOGD("Dump to file!");                          \
113             i = fwrite(m_buf, 1, m_size, fp);                \
114             if (i != (int)m_size) {                          \
115                 ALOGD("Error in fwrite, returned %d", i);    \
116                 perror("Error in write to file");            \
117             }                                                \
118             fclose(fp);                                      \
119         } else {                                             \
120             ALOGD("Could not write to file %s", m_filename); \
121             if (fp != NULL) fclose(fp);                      \
122         }                                                    \
123     }
124 #else /* FILE_DUMP_ENABLE */
125 #define INPUT_DUMP_PATH
126 #define INPUT_DUMP_EXT
127 #define OUTPUT_DUMP_PATH
128 #define OUTPUT_DUMP_EXT
129 #define GENERATE_FILE_NAMES()
130 #define CREATE_DUMP_FILE(m_filename)
131 #define DUMP_TO_FILE(m_filename, m_buf, m_size)
132 #endif /* FILE_DUMP_ENABLE */
133 
134 }  // namespace android
135 
136 #endif  // ANDROID_C2_SOFT_AV1_DEC_H_
137