• 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 <SimpleC2Component.h>
21 #include "aom/aom_decoder.h"
22 #include "aom/aomdx.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 C2SoftAomDec : public SimpleC2Component {
32     class IntfImpl;
33 
34     C2SoftAomDec(const char* name, c2_node_id_t id,
35                  const std::shared_ptr<IntfImpl>& 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     struct timeval mTimeStart;   // Time at the start of decode()
64     struct timeval mTimeEnd;     // 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         GETTIME(&mTimeStart, NULL);                                           \
89         strcpy(mInFile, "");                                                  \
90         ALOGD("GENERATE_FILE_NAMES");                                         \
91         sprintf(mInFile, "%s_%ld.%ld.%s", INPUT_DUMP_PATH, mTimeStart.tv_sec, \
92                 mTimeStart.tv_usec, INPUT_DUMP_EXT);                          \
93         strcpy(mOutFile, "");                                                 \
94         sprintf(mOutFile, "%s_%ld.%ld.%s", OUTPUT_DUMP_PATH,                  \
95                 mTimeStart.tv_sec, mTimeStart.tv_usec, OUTPUT_DUMP_EXT);      \
96     }
97 
98 #define CREATE_DUMP_FILE(m_filename)                     \
99     {                                                    \
100         FILE* fp = fopen(m_filename, "wb");              \
101         if (fp != NULL) {                                \
102             ALOGD("Opened file %s", m_filename);         \
103             fclose(fp);                                  \
104         } else {                                         \
105             ALOGD("Could not open file %s", m_filename); \
106         }                                                \
107     }
108 #define DUMP_TO_FILE(m_filename, m_buf, m_size)              \
109     {                                                        \
110         FILE* fp = fopen(m_filename, "ab");                  \
111         if (fp != NULL && m_buf != NULL) {                   \
112             int i;                                           \
113             ALOGD("Dump to file!");                          \
114             i = fwrite(m_buf, 1, m_size, fp);                \
115             if (i != (int)m_size) {                          \
116                 ALOGD("Error in fwrite, returned %d", i);    \
117                 perror("Error in write to file");            \
118             }                                                \
119             fclose(fp);                                      \
120         } else {                                             \
121             ALOGD("Could not write to file %s", m_filename); \
122             if (fp != NULL) fclose(fp);                      \
123         }                                                    \
124     }
125 #else /* FILE_DUMP_ENABLE */
126 #define INPUT_DUMP_PATH
127 #define INPUT_DUMP_EXT
128 #define OUTPUT_DUMP_PATH
129 #define OUTPUT_DUMP_EXT
130 #define GENERATE_FILE_NAMES()
131 #define CREATE_DUMP_FILE(m_filename)
132 #define DUMP_TO_FILE(m_filename, m_buf, m_size)
133 #endif /* FILE_DUMP_ENABLE */
134 
135 }  // namespace android
136 
137 #endif  // ANDROID_C2_SOFT_AV1_DEC_H_
138