blob: 528ee3b01743f39ff5ad80c110557d669655ac5a [file] [log] [blame]
Chong Zhangea280cb2017-08-02 11:10:10 -07001/*
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 Zhang0c1407f2018-05-02 17:09:05 -070022#include <utils/Condition.h>
23#include <utils/Mutex.h>
Chong Zhangea280cb2017-08-02 11:10:10 -070024#include <utils/RefBase.h>
25
26namespace android {
27
28class IDataSource;
29class IMemory;
30class MediaMetadataRetriever;
31
32/*
33 * An implementation of HeifDecoder based on Android's MediaMetadataRetriever.
34 */
35class HeifDecoderImpl : public HeifDecoder {
36public:
37
38 HeifDecoderImpl();
39 ~HeifDecoderImpl() override;
40
41 bool init(HeifStream* stream, HeifFrameInfo* frameInfo) override;
42
43 bool getEncodedColor(HeifEncodedColor* outColor) const override;
44
45 bool setOutputColor(HeifColorFormat heifColor) override;
46
47 bool decode(HeifFrameInfo* frameInfo) override;
48
49 bool getScanline(uint8_t* dst) override;
50
51 size_t skipScanlines(size_t count) override;
52
53private:
Chong Zhang0c1407f2018-05-02 17:09:05 -070054 struct DecodeThread;
55
Chong Zhangea280cb2017-08-02 11:10:10 -070056 sp<IDataSource> mDataSource;
57 sp<MediaMetadataRetriever> mRetriever;
58 sp<IMemory> mFrameMemory;
59 android_pixel_format_t mOutputColor;
60 size_t mCurScanline;
Chong Zhang0c1407f2018-05-02 17:09:05 -070061 uint32_t mWidth;
62 uint32_t mHeight;
Chong Zhang3f3ffab2017-08-23 13:51:59 -070063 bool mFrameDecoded;
Chong Zhangd3e0d862017-10-03 13:17:13 -070064 bool mHasImage;
65 bool mHasVideo;
Chong Zhang0c1407f2018-05-02 17:09:05 -070066
67 // Slice decoding only
68 Mutex mLock;
69 Condition mScanlineReady;
70 sp<DecodeThread> mThread;
71 size_t mAvailableLines;
72 size_t mNumSlices;
73 uint32_t mSliceHeight;
74 bool mAsyncDecodeDone;
75
76 bool decodeAsync();
77 bool getScanlineInner(uint8_t* dst);
Chong Zhangea280cb2017-08-02 11:10:10 -070078};
79
80} // namespace android
81
82#endif // _HEIF_DECODER_IMPL_