| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2017 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 _HEIF_DECODER_IMPL_ | 
 | 18 | #define _HEIF_DECODER_IMPL_ | 
 | 19 |  | 
 | 20 | #include "include/HeifDecoderAPI.h" | 
 | 21 | #include <system/graphics.h> | 
| Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 22 | #include <utils/Condition.h> | 
 | 23 | #include <utils/Mutex.h> | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> | 
 | 25 |  | 
 | 26 | namespace android { | 
 | 27 |  | 
 | 28 | class IDataSource; | 
 | 29 | class IMemory; | 
 | 30 | class MediaMetadataRetriever; | 
 | 31 |  | 
 | 32 | /* | 
 | 33 |  * An implementation of HeifDecoder based on Android's MediaMetadataRetriever. | 
 | 34 |  */ | 
 | 35 | class HeifDecoderImpl : public HeifDecoder { | 
 | 36 | public: | 
 | 37 |  | 
 | 38 |     HeifDecoderImpl(); | 
 | 39 |     ~HeifDecoderImpl() override; | 
 | 40 |  | 
 | 41 |     bool init(HeifStream* stream, HeifFrameInfo* frameInfo) override; | 
 | 42 |  | 
| Chong Zhang | 8541d30 | 2019-07-12 11:19:47 -0700 | [diff] [blame] | 43 |     bool getSequenceInfo(HeifFrameInfo* frameInfo, size_t *frameCount) override; | 
 | 44 |  | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 45 |     bool getEncodedColor(HeifEncodedColor* outColor) const override; | 
 | 46 |  | 
 | 47 |     bool setOutputColor(HeifColorFormat heifColor) override; | 
 | 48 |  | 
 | 49 |     bool decode(HeifFrameInfo* frameInfo) override; | 
 | 50 |  | 
| Chong Zhang | 8541d30 | 2019-07-12 11:19:47 -0700 | [diff] [blame] | 51 |     bool decodeSequence(int frameIndex, HeifFrameInfo* frameInfo) override; | 
 | 52 |  | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 53 |     bool getScanline(uint8_t* dst) override; | 
 | 54 |  | 
 | 55 |     size_t skipScanlines(size_t count) override; | 
 | 56 |  | 
 | 57 | private: | 
| Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 58 |     struct DecodeThread; | 
 | 59 |  | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 60 |     sp<IDataSource> mDataSource; | 
 | 61 |     sp<MediaMetadataRetriever> mRetriever; | 
 | 62 |     sp<IMemory> mFrameMemory; | 
| Chong Zhang | 8541d30 | 2019-07-12 11:19:47 -0700 | [diff] [blame] | 63 |     HeifFrameInfo mImageInfo; | 
 | 64 |     HeifFrameInfo mSequenceInfo; | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 65 |     android_pixel_format_t mOutputColor; | 
 | 66 |     size_t mCurScanline; | 
| Chong Zhang | 8541d30 | 2019-07-12 11:19:47 -0700 | [diff] [blame] | 67 |     size_t mTotalScanline; | 
| Chong Zhang | 3f3ffab | 2017-08-23 13:51:59 -0700 | [diff] [blame] | 68 |     bool mFrameDecoded; | 
| Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 69 |     bool mHasImage; | 
 | 70 |     bool mHasVideo; | 
| Chong Zhang | 8541d30 | 2019-07-12 11:19:47 -0700 | [diff] [blame] | 71 |     size_t mSequenceLength; | 
| Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 72 |  | 
 | 73 |     // Slice decoding only | 
 | 74 |     Mutex mLock; | 
 | 75 |     Condition mScanlineReady; | 
 | 76 |     sp<DecodeThread> mThread; | 
 | 77 |     size_t mAvailableLines; | 
 | 78 |     size_t mNumSlices; | 
 | 79 |     uint32_t mSliceHeight; | 
 | 80 |     bool mAsyncDecodeDone; | 
 | 81 |  | 
 | 82 |     bool decodeAsync(); | 
 | 83 |     bool getScanlineInner(uint8_t* dst); | 
| Leon Scroggins III | 7ca678b | 2020-01-22 14:09:55 -0500 | [diff] [blame] | 84 |     bool reinit(HeifFrameInfo* frameInfo); | 
| Chong Zhang | ea280cb | 2017-08-02 11:10:10 -0700 | [diff] [blame] | 85 | }; | 
 | 86 |  | 
 | 87 | } // namespace android | 
 | 88 |  | 
 | 89 | #endif // _HEIF_DECODER_IMPL_ |